用ASM编写一个简单的Windows Shellcode思路总结

在这里插入图片描述

shellcode 是什么?

“代码也好数据也好只要是与位置无关的二进制就都是shellcode。”
为了写出位置无关的代码,需要注意以下几点:

  • 不能对字符串使用直接偏移,必须将字符串存储在堆栈中
  • dll中的函数寻址,由于 ASLR 不会每次都在同一个地址中加载,可以通过 PEB.PEB_LDR_DATA
    找到加载模块调用其导出的函数,或加载新 dll。
  • 避免空字节

NULL 字节的值为 0x00,在 C/C++ 代码中,NULL 字节被视为字符串的终止符。因此,shellcode 中这些字节的存在可能会干扰目标应用程序的功能,并且我们的 shellcode 可能无法正确复制到内存中。

mov ebx, 0x00
   xor ebx, ebx

用下面的语句代替上面的语句,结果是一样的。

此外,在某些特定情况下,shellcode 必须避免使用字符,例如 \r 或 \n,甚至只使用字母数字字符。

windows下dll加载的机制

在 Windows 中,应用程序不能直接访问系统调用,使用来自 Windows API ( WinAPI ) 的函数,Windows API函数都存储在 kernel32.dll、advapi32.dll、gdi32.dll 等中。ntdll.dll 和 kernel32.dll 非常重要,以至于每个进程都会导入它们:

这是我编写 nothing_to_do 程序,用 listdlls列出导入的 dll:
在这里插入图片描述

dll寻址

TEB(线程环境块)该结构包含用户模式中的线程信息,32位系统中我们可以使用 FS 寄存器在偏移0x30处找到进程环境块(PEB) 的地址。
在这里插入图片描述
PEB.ldr 指向PEB_LDR_DATA提供有关加载模块的信息的结构的指针,包含kernel32 和 ntdll 的基地址

typedef struct _PEB_LDR_DATA {
  BYTE       Reserved1[8];
  PVOID      Reserved2[3];
  LIST_ENTRY InMemoryOrderModuleList;
} PEB_LDR_DATA, *PPEB_LDR_DATA;

PEB_LDR_DATA.InMemoryOrderModuleList 包含进

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Shellcode Helper v1.62 Coded by TeLeMan (c) 2008-2013 Usage: schelper.exe [options] Options: -i [input file] input file (Default: stdin) -o [output file] output file (Default: stdout) -s input file format (Default: Auto-Detection) -sb input file format is Binary -sp the input file format's parameters -d output file format (Default: C format) -db output file format is Binary -dp the output file format's parameters -search get the start offset by the pattern: e.g. PK\x03\x04 -soff fix the match offset after searching (Default: 0) -off convert the input file from the offset (Default: 0) -len convert the input file with the length (Default: 0 - MAX) -en [encoder] encode shellcode (Default: XorDword) -de [encoder] decode shellcode (Default: Auto-Detection) -ex exclude characters: e.g. 0x00,0x01-0x1F,0xFF (Default: 0x00) -in incude characters only -ep the encoder's parameters -t [pid] execute or inject shellcode into process for testing -td [pid] execute or inject shellcode into process for debugging -stack put shellcode into stack and execute it (ESP is the shellcode start) -noinfo display no normal messages except error messages Available formats: 0 - C 1 - C(HexArray) 2 - Perl 3 - Python 4 - Ruby 5 - JavaScript(Escape) 6 - VBScript(Escape) 7 - Pascal 8 - MASM(Data) 9 - HexDump 10 - BitString 11 - HexString 12 - HexArray(C like) 13 - Base64 14 - Binary 15 - HexString(C like) 16 - HexString(Escape) 17 - HexString(JavaScript,UNICODE) 18 - URI(ISO-8859-1) 19 - XML(PCDATA) 20 - BigNumber 21 - BigNumber(Hex) 22 - BigNumber(BaseX) 23 - FloatPoint 24 - UnixTimestamp 25 - GUID 26 - MASM(ASM) 27 - NASM 28 - YASM(ASM) 29 - FASM(ASM) 30 - JWASM(ASM) 31 - POASM(ASM) 32 - GOASM(ASM) 33 - GNU ASM Available encoders:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值