File manageengine_adaudit_plus_authenticated_rce.rb
has 474 lines of code (exceeds 250 allowed). Consider refactoring. Open
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
Method exploit
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def exploit
if @exploit_method.nil? # this means the user has disabled autocheck so we should try the default exploit method
@exploit_method = 'default'
elsif @exploit_method == 'cve_2021_42847' && datastore['PAYLOAD'] =~ /meterpreter/
print_warning('Exploitation is possible only via CVE-2021-42847. This attack vector may fail in combination with a meterpreter payload.')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method exploit
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
def exploit
if @exploit_method.nil? # this means the user has disabled autocheck so we should try the default exploit method
@exploit_method = 'default'
elsif @exploit_method == 'cve_2021_42847' && datastore['PAYLOAD'] =~ /meterpreter/
print_warning('Exploitation is possible only via CVE-2021-42847. This attack vector may fail in combination with a meterpreter payload.')
Method create_alert_profile
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def create_alert_profile
if @exploit_method == 'cve_2021_42847'
print_status('Attempting to authenticate again in order to retrieve the required cookies.')
# We have to authenticate again in order to get the required cookie, so reset the cookie cache
cookie_jar.clear
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_alert_profile
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_alert_profile
if @exploit_method == 'cve_2021_42847'
print_status('Attempting to authenticate again in order to retrieve the required cookies.')
# We have to authenticate again in order to get the required cookie, so reset the cookie cache
cookie_jar.clear
Method initialize
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(info = {})
super(
update_info(
info,
'Name' => 'ManageEngine ADAudit Plus Authenticated File Write RCE',
Method check
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
def check
target_check_results = adaudit_plus_target_check
target_check_msg = target_check_results['message']
case target_check_results['status']
when adaudit_plus_status::CONNECTION_FAILED
Method check
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def check
target_check_results = adaudit_plus_target_check
target_check_msg = target_check_results['message']
case target_check_results['status']
when adaudit_plus_status::CONNECTION_FAILED
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method delete_alert
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def delete_alert(adapcsrf_cookie)
print_status("Attempting to delete alert profile #{@alert_name}")
# let's try and get the the ID of the alert we want to delete
res_get_alert = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'api', 'json', 'leftTrees', 'getLeftTreeList'),
Method alert_profile_info
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def alert_profile_info
script_location = @ps1_script_name || payload.encoded
alert_name = rand_text_alphanumeric(8..12)
alert_data = {
Method delete_alert
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def delete_alert(adapcsrf_cookie)
print_status("Attempting to delete alert profile #{@alert_name}")
# let's try and get the the ID of the alert we want to delete
res_get_alert = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'api', 'json', 'leftTrees', 'getLeftTreeList'),
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return CheckCode::Unknown(login_msg)
Avoid too many return
statements within this method. Open
return CheckCode::Safe('No Active Directory domains are configured on the target, so the module will not be able to trigger the payload.')
Avoid too many return
statements within this method. Open
return CheckCode::Appears("The target is ADAudit Plus #{build_version} and the endpoint for CVE-2021-42847 exists.")
Avoid too many return
statements within this method. Open
return CheckCode::Detected("The provided AUTH_DOMAIN #{auth_domain} does not match the configured authentication domain(s).")
Avoid too many return
statements within this method. Open
return CheckCode::Safe("The target is ADAudit Plus #{build_version} but the endpoint for CVE-2021-42847 is not accessible.")
Avoid too many return
statements within this method. Open
return
Avoid too many return
statements within this method. Open
return CheckCode::Safe(login_msg)
Avoid too many return
statements within this method. Open
return CheckCode::Unknown(build_msg)
Avoid too many return
statements within this method. Open
return CheckCode::Detected("The target is ADAudit Plus #{build_version} but the connection failed when checking for the CVE-2021-42847 endpoint")
Avoid too many return
statements within this method. Open
return CheckCode::Safe('Failed to verify if any Active Directory domains are configured on the target.')
Method create_alert_script
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def create_alert_script
ps1_script_name = "#{rand_text_alpha_lower(5..10)}.ps1"
print_status("Attempting to write the payload to /alert_scripts/#{ps1_script_name}")
if @domain.blank?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Identical blocks of code found in 2 locations. Consider refactoring. Open
case login_results['status']
when adaudit_plus_status::CONNECTION_FAILED
fail_with(Failure::Unreachable, login_msg)
when adaudit_plus_status::UNEXPECTED_REPLY
fail_with(Failure::UnexpectedReply, login_msg)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 36.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
case login_results['status']
when adaudit_plus_status::CONNECTION_FAILED
fail_with(Failure::Unreachable, login_msg)
when adaudit_plus_status::UNEXPECTED_REPLY
fail_with(Failure::UnexpectedReply, login_msg)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 36.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 17 locations. Consider refactoring. Open
register_options([
OptString.new('TARGETURI', [true, 'The base path to ManageEngine ADAudit Plus', '/']),
OptString.new('AUTH_DOMAIN', [true, 'ADAudit Plus authentication domain (default is ADAuditPlus Authentication)', 'ADAuditPlus Authentication']),
OptString.new('USERNAME', [true, 'Username to authenticate with', 'admin']),
OptString.new('PASSWORD', [true, 'Password to authenticate with', 'admin']),
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 30.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76