Skip to content

Commit f7e588c

Browse files
Initial commit of module.
1 parent 76124af commit f7e588c

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'yaml'
8+
9+
class MetasploitModule < Msf::Auxiliary
10+
11+
include Msf::Exploit::Remote::MYSQL
12+
include Msf::Auxiliary::Report
13+
include Msf::Auxiliary::Scanner
14+
15+
def initialize
16+
super(
17+
'Name' => 'MYSQL Directory Write Test',
18+
'Description' => %Q{
19+
Enumerate writeable directories using the MySQL SELECT INTO DUMPFILE feature, for more
20+
information see the URL in the references.
21+
},
22+
'Author' => [ 'AverageSecurityGuy <stephen[at]averagesecurityguy.info>' ],
23+
'References' => [
24+
[ 'URL', 'https://dev.mysql.com/doc/refman/5.7/en/select-into.html' ]
25+
],
26+
'License' => MSF_LICENSE
27+
)
28+
29+
register_options([
30+
OptPath.new('DIR_LIST', [ true, "List of directories to test", '' ]),
31+
OptString.new('FILE_NAME', [ true, "Name of file to write", Rex::Text.rand_text_alpha(8) ]),
32+
OptString.new('TABLE_NAME', [ true, "Name of table to use - Warning, if the table already exists its contents will be corrupted", Rex::Text.rand_text_alpha(8) ]),
33+
OptString.new('USERNAME', [ true, 'The username to authenticate as', "root" ])
34+
])
35+
36+
end
37+
38+
# This function does not handle any errors, if you use this
39+
# make sure you handle the errors yourself
40+
def mysql_query_no_handle(sql)
41+
res = @mysql_handle.query(sql)
42+
res
43+
end
44+
45+
def run_host(ip)
46+
vprint_status("Login...")
47+
48+
if (not mysql_login_datastore)
49+
return
50+
end
51+
52+
file = File.new(datastore['DIR_LIST'], "r")
53+
file.each_line do |line|
54+
check_dir(line.chomp)
55+
end
56+
file.close
57+
58+
end
59+
60+
def check_dir(dir)
61+
begin
62+
vprint_status("Checking #{dir}...")
63+
res = mysql_query_no_handle("SELECT _utf8'test' INTO DUMPFILE '#{dir}/" + datastore['FILE_NAME'] + "'")
64+
rescue ::RbMysql::ServerError => e
65+
vprint_warning("#{e.to_s}")
66+
return
67+
rescue Rex::ConnectionTimeout => e
68+
vprint_error("Timeout: #{e.message}")
69+
return
70+
else
71+
print_good("#{dir} is writeable")
72+
report_note(
73+
:host => rhost,
74+
:type => "filesystem.file",
75+
:data => "#{dir} is writeable",
76+
:port => rport,
77+
:proto => 'tcp',
78+
:update => :unique_data
79+
)
80+
end
81+
82+
return
83+
end
84+
85+
end

0 commit comments

Comments
 (0)