Skip to content

Commit 5ae1768

Browse files
committed
Improved SSL/TLS portdetection in nmap greppable files (3.0)
As mentioned in #1931 the port detection for nmap greppable files leaves space for improvements. Ths PR adds a pattern detection of ssl and https in the forth or fifth parameter of an open port, so those ports will be added to a scan when a nmap greppable output file is supplied as input to testssl.sh . Also it does minor code adjustments to utils/gmap2testssl.sh . Same as #1938, only for 3.0.
1 parent f4800f8 commit 5ae1768

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

testssl.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18988,7 +18988,7 @@ nmap_to_plain_file() {
1898818988
local target_fname=""
1898918989
local oneline=""
1899018990
local ip hostdontcare round_brackets ports_specs starttls
18991-
local tmp port host_spec protocol dontcare dontcare1
18991+
local tmp port host_spec protocol ssl_hint dontcare dontcare1
1899218992
#FIXME: IPv6 is missing here
1899318993

1899418994
# Ok, since we are here we are sure to have an nmap file. To avoid questions we make sure it's the right format too
@@ -19029,11 +19029,15 @@ nmap_to_plain_file() {
1902919029
while read -r oneline; do
1903019030
# 25/open/tcp//smtp//<banner>/,
1903119031
[[ "$oneline" =~ '/open/tcp/' ]] || continue # no open tcp for this port on this IP --> move on
19032-
IFS=/ read -r port dontcare protocol dontcare1 <<< "$oneline"
19033-
starttls="$(ports2starttls $port)"
19034-
[[ $? -eq 1 ]] && continue # nmap got a port but we don't know how to speak to
19035-
[[ "$DEBUG" -ge 1 ]] && echo "${starttls}$host_spec:$port"
19036-
echo "${starttls}${host_spec}:${port}" >>"$target_fname"
19032+
IFS=/ read -r port dontcare protocol ssl_hint dontcare1 <<< "$oneline"
19033+
if [[ "$ssl_hint" =~ ^(ssl|https) ]] || [[ "$dontcare1" =~ ^(ssl|https) ]]; then
19034+
echo "${host_spec}:${port}" >>"$target_fname"
19035+
else
19036+
starttls="$(ports2starttls $port)"
19037+
[[ $? -eq 1 ]] && continue # nmap got a port but we don't know how to speak to
19038+
[[ "$DEBUG" -ge 1 ]] && echo "${starttls}$host_spec:$port"
19039+
echo "${starttls}${host_spec}:${port}" >>"$target_fname"
19040+
fi
1903719041
done < <(tr ',' '\n' <<< "$ports_specs")
1903819042
done < "$FNAME"
1903919043
[[ "$DEBUG" -ge 1 ]] && echo

utils/gmap2testssl.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
#set -e
4-
53
# Utility which converts grepable nmap outout to testssl's file input
64
# It is just borrowed from testssl.sh
75
# License see testssl.sh
@@ -105,7 +103,7 @@ nmap_to_plain_file () {
105103
local target_fname=""
106104
local oneline=""
107105
local ip hostdontcare round_brackets ports_specs starttls
108-
local tmp port host_spec protocol dontcare dontcare1
106+
local tmp port host_spec protocol ssl_hint dontcare dontcare1
109107

110108
# Ok, since we are here we are sure to have an nmap file. To avoid questions we make sure it's the right format too
111109
if [[ "$(head -1 "$fname")" =~ ( -oG )(.*) ]] || [[ "$(head -1 "$fname")" =~ ( -oA )(.*) ]] ; then
@@ -162,7 +160,7 @@ nmap_to_plain_file () {
162160
FNAME="$1"
163161
[[ ! -e $FNAME ]] && echo "$FNAME not readable" && exit 2
164162

165-
nmap_to_plain_file $FNAME
163+
nmap_to_plain_file "$FNAME"
166164

167165
exit $?
168166

0 commit comments

Comments
 (0)