Skip to content

Commit 9aaa703

Browse files
authored
Correct the issue with port scanner output (#978)
The issue caused the program to erroneously run a regex pattern on HTML content instead of the request data. This was because the port number wasn't displayed in the HTML's body content. The commit rectifies this problem, ensuring that regex operates on the correct data.
1 parent f65f9bc commit 9aaa703

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

nettacker/core/lib/socket.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def response_conditions_matched(self, sub_step, response):
233233
return response
234234
if sub_step["method"] == "tcp_connect_send_and_receive":
235235
if response:
236-
received_content = response["response"]
237236
for condition in conditions:
238237
regex = re.findall(
239-
re.compile(conditions[condition]["regex"]), received_content
238+
re.compile(conditions[condition]["regex"]),
239+
response["response"]
240+
if condition != "open_port"
241+
else str(response["peer_name"][1]),
240242
)
241243
reverse = conditions[condition]["reverse"]
242244
condition_results[condition] = reverse_and_regex_condition(regex, reverse)

nettacker/modules/scan/port.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ payloads:
10281028
condition_type: or
10291029
conditions:
10301030
open_port:
1031-
regex: ""
1031+
regex: \d{{1,5}}
10321032
reverse: false
10331033

10341034
ftp: &ftp

tests/core/lib/test_socket.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Responses:
99

1010
tcp_connect_send_and_receive = {
1111
"response": 'HTTP/1.1 400 Bad Request\r\nServer: Apache/2.4.62 (Debian)\r\nContent-Length: 302\r\nConnection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>400 Bad Request</title>\n</head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n<hr>\n<address>Apache/2.4.62 (Debian)</address>\n</body></html>\n',
12+
"peer_name": (
13+
"127.0.0.1",
14+
80,
15+
),
1216
"ssl_flag": True,
1317
}
1418

0 commit comments

Comments
 (0)