Skip to content

Commit 261e095

Browse files
committed
Handle exceptions in mysql_login
1 parent 268de94 commit 261e095

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

lib/msf/core/exploit/mysql.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,32 @@ def mysql_login(user='root', pass='', db=nil)
4040
disconnect if self.sock
4141
connect
4242

43-
@mysql_handle = ::RbMysql.connect({
44-
:host => rhost,
45-
:port => rport,
46-
:read_timeout => 300,
47-
:write_timeout => 300,
48-
:socket => sock,
49-
:user => user,
50-
:password => pass,
51-
:db => db
52-
})
43+
begin
44+
@mysql_handle = ::RbMysql.connect({
45+
:host => rhost,
46+
:port => rport,
47+
:read_timeout => 300,
48+
:write_timeout => 300,
49+
:socket => sock,
50+
:user => user,
51+
:password => pass,
52+
:db => db
53+
})
54+
rescue Errno::ECONNREFUSED
55+
vprint_error("Connection refused")
56+
return false
57+
rescue RbMysql::ClientError
58+
vprint_error("Connection timedout")
59+
return false
60+
rescue Errno::ETIMEDOUT
61+
vprint_error("Operation timedout")
62+
return false
63+
rescue RbMysql::AccessDeniedError
64+
vprint_error("Access denied")
65+
return false
66+
end
67+
68+
return true
5369
end
5470

5571
def mysql_logoff

0 commit comments

Comments
 (0)