403Webshell
Server IP : 123.56.80.60  /  Your IP : 216.73.216.78
Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev
System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586
User : SYSTEM ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party/aegis_checker/common/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party/aegis_checker/common/network_util.py
# -*- coding: utf-8 -*-
import httplib
import json
import socket
import logging
import urllib
from urlparse import urlparse
import requests
from platform_info import is_windows


def get_local_ip_from_connection():
    s = None
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 80))
        ip = s.getsockname()[0]
    finally:
        if s:
            s.close()

    return ip


def get_local_ip():
    ip = get_local_ip_from_connection()
    if ip:
        return ip

    return socket.gethostbyname(socket.gethostname())


def parse_domain_ip(domain):
    """

    :param domain:
    :return: [], all ip for domain
    """
    ip_list = []
    try:
        addrs = socket.getaddrinfo(domain, None)
        for item in addrs:
            if item[4][0] not in ip_list:
                ip_list.append(item[4][0])
    except Exception as e:
        logging.exception("parse %s error" % domain)
    return ip_list


def connect_with_tcp(ip, port):
    """

    :param ip:
    :param port:
    :return: if success, return 0
    """
    s = socket.socket()
    s.settimeout(1)
    ret = s.connect_ex((ip, port))
    s.close()
    # logging.debug("connect %s:%d result %d", str(ip), port, ret)

    return ret


def check_sls_version():
    "if open ssl version less then 1.0.1f, return false"
    if not is_windows():
        try:
            import ssl
            logging.info("open ssl version is %s" % ssl.OPENSSL_VERSION)
            if ssl.OPENSSL_VERSION >= "OpenSSL 1.0.1":
                return True
            else:
                return False
        except:
            logging.exception("get open ssl version error")

    return True


def https_to_http(url):
    if url.startswith("https"):
        return "http" + url[5:]
    return url


def http_post(url, data, cert_file=False):
    """

    :param url:
    :param data: post data, it could be string or dict
    :return: string, http response data, if fail, return none
    """
    if isinstance(data, dict):
        data = json.dumps(data)

    # if open ssl is not ok for https, replace https as http
    if not check_sls_version():
        logging.warning("open ssl version is less then 1.0.1, replace https as http to post")
        url = https_to_http(url)
        cert_file = False

    try:
        r = requests.post(url, data=data, timeout=10, verify=cert_file)
        if r.status_code == 200:
            return r.text
        else:
            logging.error("response error, status code is %d" % r.status_code)
    except Exception as e:
        logging.exception("post %s error" % url)


def test():
    logging.basicConfig(format='%(asctime)s [%(filename)s][%(levelname)s] %(message)s', level=logging.DEBUG)
    print(get_local_ip())

    post_url = "https://update.aegis.aliyun.com/update"
    print https_to_http(post_url)
    post_dict = {
        "version": 1,
        "data": "test data"
    }
    response = http_post(post_url, post_dict)
    print str(response)


if __name__ == '__main__':
    test()

Youez - 2016 - github.com/yon3zu
LinuXploit