Skip to content

Commit b4101d9

Browse files
committed
is_http_accessible hard condition leading to false negative, fixes #56
1 parent fa61825 commit b4101d9

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

apachetomcatscanner/utils/network.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121

2222

2323
def is_target_a_windows_machine(target) -> bool:
24+
"""
25+
Check if the target is a Windows machine.
26+
27+
Args:
28+
target: The target to check.
29+
30+
Returns:
31+
True if the target is a Windows machine, False otherwise.
32+
"""
2433
# if port 135 and 445 open
2534
if is_port_open(target, 135) and is_port_open(target, 445):
2635
return True
@@ -29,6 +38,15 @@ def is_target_a_windows_machine(target) -> bool:
2938

3039

3140
def is_target_a_windows_domain_controller(target) -> bool:
41+
"""
42+
Check if the target is a Windows domain controller.
43+
44+
Args:
45+
target: The target to check.
46+
47+
Returns:
48+
True if the target is a Windows domain controller, False otherwise.
49+
"""
3250
# if port 135 and 445 and 88 open
3351
if is_target_a_windows_machine(target) and is_port_open(target, 88):
3452
return True
@@ -37,6 +55,19 @@ def is_target_a_windows_domain_controller(target) -> bool:
3755

3856

3957
def is_port_open(target, port) -> bool:
58+
"""
59+
Check if the port is open on the target.
60+
61+
Args:
62+
target: The target to check.
63+
port: The port to check.
64+
65+
Returns:
66+
True if the port is open on the target, False otherwise.
67+
68+
Raises:
69+
Exception: If an error occurs while checking if the port is open on the target.
70+
"""
4071
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
4172
s.settimeout(0.1)
4273
# Non-existant domains cause a lot of errors, added error handling
@@ -47,6 +78,21 @@ def is_port_open(target, port) -> bool:
4778

4879

4980
def is_http_accessible(target, port, config, scheme="http"):
81+
"""
82+
Check if the target is accessible via HTTP.
83+
84+
Args:
85+
target: The target to check.
86+
port: The port to check.
87+
config: The config object.
88+
scheme: The scheme to use.
89+
90+
Returns:
91+
True if the target is accessible via HTTP, False otherwise.
92+
93+
Raises:
94+
Exception: If an error occurs while checking if the target is accessible via HTTP.
95+
"""
5096
url = "%s://%s:%d/" % (scheme, target, port)
5197
try:
5298
r = requests.get(
@@ -56,7 +102,7 @@ def is_http_accessible(target, port, config, scheme="http"):
56102
headers=config.request_http_headers,
57103
verify=(not (config.request_no_check_certificate)),
58104
)
59-
return r.status_code == 200
105+
return True
60106
except Exception as e:
61107
config.debug(
62108
"Error in is_http_accessible('%s', %d, '%s'): %s "

apachetomcatscanner/utils/scan.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828

2929

3030
def is_tomcat_manager_accessible(url_manager, config):
31+
"""
32+
Check if the Tomcat manager is accessible.
33+
34+
Args:
35+
url_manager: The URL to check.
36+
config: The config object.
37+
38+
Returns:
39+
True if the Tomcat manager is accessible, False otherwise.
40+
Raises:
41+
Exception: If an error occurs while checking if the Tomcat manager is accessible.
42+
"""
3143
try:
3244
r = requests.get(
3345
url_manager,
@@ -48,6 +60,18 @@ def is_tomcat_manager_accessible(url_manager, config):
4860

4961

5062
def get_version_from_malformed_http_request(url, config):
63+
"""
64+
Get the version of the Apache Tomcat server from a malformed HTTP request.
65+
66+
Args:
67+
url: The URL to check.
68+
config: The config object.
69+
70+
Returns:
71+
The version of the Apache Tomcat server, None if not found.
72+
Raises:
73+
Exception: If an error occurs while getting the version of the Apache Tomcat server from a malformed HTTP request.
74+
"""
5175
version = None
5276
url_depth = len(url.split("/")[3:])
5377
test_urls = [
@@ -106,6 +130,18 @@ def get_version_from_malformed_http_request(url, config):
106130

107131

108132
def try_credentials(url_manager, config):
133+
"""
134+
Try to authenticate to the Tomcat manager.
135+
136+
Args:
137+
url_manager: The URL to check.
138+
config: The config object.
139+
140+
Returns:
141+
A list of found credentials, None if not found.
142+
Raises:
143+
Exception: If an error occurs while trying to authenticate to the Tomcat manager.
144+
"""
109145
found_credentials = []
110146
try:
111147
for credentials in config.credentials:
@@ -143,6 +179,7 @@ def process_url(scheme, target, port, url, config, reporter):
143179
url,
144180
url + "/manager/html",
145181
url + "/..;/manager/html",
182+
url + "..%09/manager/text",
146183
baseurl + "/manager/html",
147184
baseurl + "/..;/manager/html",
148185
url + "/" + "..;/" * url_depth + "manager/html",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "apachetomcatscanner"
3-
version = "3.8.0"
3+
version = "3.8.1"
44
description = ""
55
dynamic = ["scripts"]
66
readme = "README.md"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sectools>=1.5.0
1+
sectools>=1.5.1
22
xlsxwriter
33
urllib3<2
44
requests==2.29.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setuptools.setup(
1616
name="apachetomcatscanner",
17-
version="3.8.0",
17+
version="3.8.1",
1818
description="",
1919
url="https://github.com/p0dalirius/ApacheTomcatScanner",
2020
author="Podalirius",

0 commit comments

Comments
 (0)