Skip to content

Commit b2c7223

Browse files
author
jvazquez-r7
committed
Cleanup for mysql_file_enum.rb
1 parent 4d5a7a3 commit b2c7223

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

lib/msf/core/exploit/mysql.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ def mysql_login_datastore
8787
return res
8888
end
8989

90-
# This function does not handle any errors, if you use this
91-
# make sure you handle the errors yourself
92-
def mysql_query_no_handle(sql)
93-
res = @mysql_handle.query(sql)
94-
res
95-
end
96-
9790
def mysql_query(sql)
9891
begin
9992
res = @mysql_handle.query(sql)

modules/auxiliary/scanner/mysql/mysql_file_enum.rb

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,39 @@ def initialize
1818
super(
1919
'Name' => 'MYSQL File/Directory Enumerator',
2020
'Description' => %Q{
21-
Enumerate files and directories using the MySQL load_file feature, for more information see the URL in the references.
21+
Enumerate files and directories using the MySQL load_file feature, for more
22+
information see the URL in the references.
2223
},
2324
'Author' => [ 'Robin Wood <robin[at]digininja.org>' ],
2425
'References' => [
25-
[ 'URL', 'http://pauldotcom.com/2013/01/mysql-file-system-enumeration.html' ],
26-
[ 'URL', 'http://www.digininja.org/projects/mysql_file_enum.php' ]
27-
],
26+
[ 'URL', 'http://pauldotcom.com/2013/01/mysql-file-system-enumeration.html' ],
27+
[ 'URL', 'http://www.digininja.org/projects/mysql_file_enum.php' ]
28+
],
2829
'License' => MSF_LICENSE
2930
)
3031

3132
register_options([
3233
OptPath.new('FILE_LIST', [ true, "List of directories to enumerate", '' ]),
33-
OptString.new('DATABASE_NAME', [ true, "Name of database to use", 'test' ]),
34+
OptString.new('DATABASE_NAME', [ true, "Name of database to use", 'mysql' ]),
3435
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) ]),
3536
OptString.new('USERNAME', [ true, 'The username to authenticate as', "root" ])
36-
])
37+
])
3738

3839
end
3940

41+
# This function does not handle any errors, if you use this
42+
# make sure you handle the errors yourself
43+
def mysql_query_no_handle(sql)
44+
res = @mysql_handle.query(sql)
45+
res
46+
end
47+
48+
def peer
49+
"#{rhost}:#{rport}"
50+
end
51+
4052
def run_host(ip)
41-
print_status("Checking " + ip)
53+
vprint_status("#{peer} - Login...")
4254

4355
if (not mysql_login_datastore)
4456
return
@@ -47,28 +59,29 @@ def run_host(ip)
4759
begin
4860
mysql_query_no_handle("USE " + datastore['DATABASE_NAME'])
4961
rescue ::RbMysql::Error => e
50-
print_error("MySQL Error: #{e.class} #{e.to_s}")
62+
vprint_error("#{peer} - MySQL Error: #{e.class} #{e.to_s}")
5163
return
5264
rescue Rex::ConnectionTimeout => e
53-
print_error("Timeout: #{e.message}")
65+
vprint_error("#{peer} - Timeout: #{e.message}")
5466
return
5567
end
5668

5769
res = mysql_query("SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + datastore['DATABASE_NAME'] + "' AND TABLE_NAME = '" + datastore['TABLE_NAME'] + "';")
5870
table_exists = (res.size == 1)
5971

6072
if !table_exists
61-
print_status("Table doesn't exist so creating it")
73+
vprint_status("#{peer} - Table doesn't exist so creating it")
6274
mysql_query("CREATE TABLE " + datastore['TABLE_NAME'] + " (brute int);")
6375
end
6476

6577
file = File.new(datastore['FILE_LIST'], "r")
6678
file.each_line do |line|
6779
check_dir(line.chomp)
6880
end
81+
file.close
6982

7083
if !table_exists
71-
print_status("Cleaning up the temp table")
84+
vprint_status("#{peer} - Cleaning up the temp table")
7285
mysql_query("DROP TABLE " + datastore['TABLE_NAME'])
7386
end
7487
end
@@ -77,19 +90,34 @@ def check_dir dir
7790
begin
7891
res = mysql_query_no_handle("LOAD DATA INFILE '" + dir + "' INTO TABLE " + datastore['TABLE_NAME'])
7992
rescue ::RbMysql::TextfileNotReadable
80-
print_good(dir + " is a directory and exists")
93+
print_good("#{peer} - #{dir} is a directory and exists")
94+
report_note(
95+
:host => rhost,
96+
:type => "filesystem.dir",
97+
:data => "#{dir} is a directory and exists",
98+
:port => rport,
99+
:proto => 'tcp',
100+
:update => :unique_data
101+
)
81102
rescue ::RbMysql::ServerError
82-
print_warning(dir + " does not exist")
103+
vprint_warning("#{peer} - #{dir} does not exist")
83104
rescue ::RbMysql::Error => e
84-
print_error("MySQL Error: #{e.class} #{e.to_s}")
105+
vprint_error("#{peer} - MySQL Error: #{e.class} #{e.to_s}")
85106
return
86107
rescue Rex::ConnectionTimeout => e
87-
print_error("Timeout: #{e.message}")
108+
vprint_error("#{peer} - Timeout: #{e.message}")
88109
return
89110
else
90-
print_good(dir + " is a file and exists")
111+
print_good("#{peer} - #{dir} is a file and exists")
112+
report_note(
113+
:host => rhost,
114+
:type => "filesystem.file",
115+
:data => "#{dir} is a file and exists",
116+
:port => rport,
117+
:proto => 'tcp',
118+
:update => :unique_data
119+
)
91120
end
92-
#puts res.inspect
93121

94122
return
95123
end

0 commit comments

Comments
 (0)