New upstream version 0.0.41.0
Sophie Brun
5 years ago
9 | 9 |
# Interrupt received
|
10 | 10 |
INTERRUPTED = 2
|
11 | 11 |
|
12 | |
# Exceptions
|
13 | |
ERROR = 3
|
|
12 |
# Unhandled/unexpected Exception occured
|
|
13 |
EXCEPTION = 3
|
|
14 |
|
|
15 |
# Error, scan did not finish
|
|
16 |
ERROR = 4
|
14 | 17 |
|
15 | 18 |
# The target has at least one vulnerability.
|
16 | 19 |
# Currently, the interesting findings do not count as vulnerable things
|
17 | |
VULNERABLE = 4
|
|
20 |
VULNERABLE = 5
|
18 | 21 |
end
|
19 | 22 |
end
|
14 | 14 |
# rubocop:disable all
|
15 | 15 |
def attack(users, passwords, opts = {})
|
16 | 16 |
create_progress_bar(total: users.size * passwords.size, show_progression: opts[:show_progression])
|
17 | |
queue_count = 0
|
18 | 17 |
|
19 | |
passwords.each_with_index do |password, password_index|
|
|
18 |
queue_count = 0
|
|
19 |
# Keep the number of requests sent for each users
|
|
20 |
# to be able to correctly update the progress when a password is found
|
|
21 |
user_requests_count = {}
|
|
22 |
|
|
23 |
users.each { |u| user_requests_count[u.username] = 0 }
|
|
24 |
|
|
25 |
passwords.each do |password|
|
20 | 26 |
remaining_users = users.select { |u| u.password.nil? }
|
21 | 27 |
|
22 | 28 |
break if remaining_users.empty?
|
23 | 29 |
|
24 | 30 |
remaining_users.each do |user|
|
25 | 31 |
request = login_request(user.username, password)
|
|
32 |
|
|
33 |
user_requests_count[user.username] += 1
|
26 | 34 |
|
27 | 35 |
request.on_complete do |res|
|
28 | 36 |
progress_bar.title = "Trying #{user.username} / #{password}"
|
|
33 | 41 |
|
34 | 42 |
yield user
|
35 | 43 |
|
36 | |
offset = progress_bar.total - progress_bar.progress < hydra.max_concurrency ? 2 : 1
|
37 | |
|
38 | |
progress_bar.total -= passwords.size - password_index - offset
|
|
44 |
progress_bar.total -= passwords.size - user_requests_count[user.username]
|
39 | 45 |
elsif errored_response?(res)
|
40 | 46 |
output_error(res)
|
41 | 47 |
end
|
1 | 1 |
def redirect_output_to_file(file)
|
2 | 2 |
$stdout.reopen(file, 'w')
|
3 | 3 |
$stdout.sync = true
|
4 | |
$stderr.reopen($stdout) # Not sure if this is needed
|
5 | 4 |
end
|
6 | 5 |
|
7 | 6 |
# @return [ Integer ] The memory of the current process in Bytes
|
0 | 0 |
# Version
|
1 | 1 |
module CMSScanner
|
2 | |
VERSION = '0.0.40.3'.freeze
|
|
2 |
VERSION = '0.0.41.0'.freeze
|
3 | 3 |
end
|
144 | 144 |
formatter.output('@scan_aborted',
|
145 | 145 |
reason: e.is_a?(Interrupt) ? 'Canceled by User' : e.message,
|
146 | 146 |
trace: e.backtrace,
|
147 | |
verbose: controllers.first.parsed_options[:verbose])
|
|
147 |
verbose: controllers.first.parsed_options[:verbose] ||
|
|
148 |
run_error_exit_code == NS::ExitCode::EXCEPTION)
|
148 | 149 |
ensure
|
149 | 150 |
Browser.instance.hydra.abort
|
150 | 151 |
|
|
183 | 184 |
|
184 | 185 |
return NS::ExitCode::INTERRUPTED if run_error.is_a?(Interrupt)
|
185 | 186 |
|
186 | |
NS::ExitCode::ERROR
|
|
187 |
return NS::ExitCode::ERROR if run_error.is_a?(NS::Error)
|
|
188 |
|
|
189 |
NS::ExitCode::EXCEPTION
|
187 | 190 |
end
|
188 | 191 |
end
|
189 | 192 |
end
|
97 | 97 |
.and_raise(Interrupt)
|
98 | 98 |
|
99 | 99 |
expect(scanner.formatter).to receive(:output)
|
100 | |
.with('@scan_aborted', hash_including(reason: 'Canceled by User', trace: anything, verbose: nil))
|
|
100 |
.with('@scan_aborted', hash_including(reason: 'Canceled by User', trace: anything, verbose: false))
|
101 | 101 |
end
|
102 | 102 |
end
|
103 | 103 |
|
104 | |
[RuntimeError.new('error spotted'), SignalException.new('SIGTERM')].each do |error|
|
|
104 |
[RuntimeError.new('error spotted'),
|
|
105 |
CMSScanner::Error.new('aa'),
|
|
106 |
SignalException.new('SIGTERM'),
|
|
107 |
Interrupt.new('Canceled by User')].each do |error|
|
105 | 108 |
context "when an/a #{error.class} is raised during the scan" do
|
106 | 109 |
let(:run_error) { error }
|
107 | 110 |
|
|
113 | 116 |
.and_raise(run_error.class, run_error.message)
|
114 | 117 |
|
115 | 118 |
expect(scanner.formatter).to receive(:output)
|
116 | |
.with('@scan_aborted', hash_including(reason: run_error.message, trace: anything, verbose: nil))
|
|
119 |
.with('@scan_aborted', hash_including(reason: run_error.message,
|
|
120 |
trace: anything,
|
|
121 |
verbose: [RuntimeError, SignalException].include?(error.class)))
|
117 | 122 |
end
|
118 | 123 |
end
|
119 | 124 |
end
|