@@ -25,33 +25,71 @@ def usernames_and_passwords(users_file="users.txt", password_file="pass.txt")
25
25
end
26
26
27
27
# Attempts to bruteforce a login to supplied url.
28
- def brute_by_force ( url )
28
+ def brute_by_force ( url , dcreds )
29
29
login_agent = Mechanize . new { |agent | agent . user_agent_alias = 'Mac Safari' }
30
30
login_agent . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
31
31
login_agent . follow_meta_refresh = true
32
+ #login_agent.set_proxy("localhost", 8080) #To send login request through a proxy. Mostly for debugging.
32
33
33
34
login_form = login_agent . get ( url ) . form ( :name => /login/ )
34
35
35
36
# login_form could be nil in case of an exception or if the login form does
36
37
# not exist. The checks in Yasuo.rb are weak.
37
38
if not login_form
38
39
$logboth. info ( "Login page not found. Looks like this instance maybe unauthenticated" )
39
- return "" , ""
40
+ return "<None> " , "<None> "
40
41
end
41
42
42
43
username_field = login_form . field_with ( name : /user|email|login|REGEMAIL|name/i )
43
44
password_field = login_form . field_with ( name : /pass|pwd|REGCODE/i )
45
+ if not username_field
46
+ $logboth. warn ( "[+] Could not enumerate the username field, moving on. You should check it manually" )
47
+ puts ( "[+] Could not enumerate the username field, moving on. You should check it manually" ) . red
48
+ username = "<Check Manually>"
49
+ password = "<Check Manually>"
50
+ return username , password
51
+ end
44
52
45
- usernames_and_passwords . each do |user , pass |
46
- username = user . chomp
47
- password = pass . chomp
53
+ #Smart brute-force code starts here
54
+ username = dcreds . split ( ':' ) [ 0 ] . chomp
55
+ password = dcreds . split ( ':' ) [ 1 ] . chomp
56
+ username_field . value = username
57
+ password_field . value = password
58
+
59
+ begin
60
+ $logfile. info ( "Trying app-specific default creds first -> #{ dcreds } " )
61
+ puts ( "[+] Trying app-specific default creds first -> #{ dcreds } \n " ) . green
62
+
63
+ login_request = login_form . submit
64
+ #puts login_request.body #To print server response. Mostly for debugging.
65
+
66
+ sleep 0.5
48
67
49
- if not username_field
50
- $logboth. warn ( "[+] Could not enumerate the username field, moving on. You should check it manually" )
51
- username = "<Check Manually>"
52
- password = "<Check Manually>"
68
+ # we determine if we have logged in by looking to see if we are on
69
+ # a page with the login form.
70
+ if ( !login_request . form_with ( :name => 'login' ) and
71
+ login_request . body . scan ( /"#{ username_field . name } "/i ) . empty? and
72
+ login_request . body . scan ( /"#{ username_field . name } "/i ) . empty? )
73
+ puts "[+] Yatta, found default login credentials for #{ url } - #{ username } :#{ password } \n " . green
74
+ $logfile. info ( "[+] Yatta, found default login credentials for #{ url } - #{ username } / #{ password } " )
53
75
return username , password
54
76
end
77
+ rescue Mechanize ::ResponseCodeError => exception
78
+ if ( exception . response_code != '200' or
79
+ exception . response_code != '301' or
80
+ exception . response_code != '302' )
81
+ # These response codes are handled by Mechanize
82
+ login_request = exception . page
83
+ $logfile. warn ( "Invalid credentials or user does not have sufficient privileges" )
84
+ else
85
+ $logboth. info ( "Unknown server error" )
86
+ end
87
+ end
88
+ #Smart brute-force code ends here
89
+
90
+ usernames_and_passwords . each do |user , pass |
91
+ username = user . chomp
92
+ password = pass . chomp
55
93
56
94
username_field . value = username
57
95
password_field . value = password
@@ -65,7 +103,7 @@ def brute_by_force(url)
65
103
66
104
# we determine if we have logged in by looking to see if we are on
67
105
# a page with the login form.
68
- if ( login_request . body . scan ( /" #{ login_form . name } "/i ) . empty? and
106
+ if ( ! login_request . form_with ( : name => 'login' ) and
69
107
login_request . body . scan ( /"#{ username_field . name } "/i ) . empty? and
70
108
login_request . body . scan ( /"#{ username_field . name } "/i ) . empty? )
71
109
puts "[+] Yatta, found default login credentials for #{ url } - #{ username } / #{ password } \n " . green
@@ -78,7 +116,7 @@ def brute_by_force(url)
78
116
exception . response_code != '302' )
79
117
# These response codes are handled by Mechanize
80
118
login_request = exception . page
81
- $logboth . warn ( "Invalid credentials or user does not have sufficient privileges" )
119
+ $logfile . warn ( "Invalid credentials or user does not have sufficient privileges" )
82
120
else
83
121
$logboth. info ( "Unknown server error" )
84
122
end
@@ -89,5 +127,4 @@ def brute_by_force(url)
89
127
puts "Could not find default login credentials, sucks" . red
90
128
return "Not Found" , "Not Found"
91
129
end
92
- end
93
-
130
+ end
0 commit comments