FIX #846 -- add output filename prefix

This commit adds the possibility to supply a output
file name prefix via --outprefix or FNAME_PREFIX
This commit is contained in:
Dirk 2017-11-14 19:41:25 +01:00
parent 1a7b761f5b
commit e450eb34e4
3 changed files with 17 additions and 11 deletions

View File

@ -408,6 +408,9 @@ whole 9 yards
\fB\-\-append\fR If an output file exists it will append to this file, without a header\. The environment variable APPEND does the same\. If the file exists and you don\'t use \fB\-\-append\fR testssl\.sh will exit with an error\. Be careful using this switch/variable\. A complementary option which overwrites an existing file doesn\'t exist per design\. \fB\-\-append\fR If an output file exists it will append to this file, without a header\. The environment variable APPEND does the same\. If the file exists and you don\'t use \fB\-\-append\fR testssl\.sh will exit with an error\. Be careful using this switch/variable\. A complementary option which overwrites an existing file doesn\'t exist per design\.
. .
.P .P
\fB\-\-prefix <out_fname_prefix>\fR Prepend output filename prefix \fIout_fname_prefix\fR before \'\e${NODE}\.\'\. You can use as well the environment variable FNAME_PREFIX\.
.
.P
A few file output options can also be preset via environment variables\. A few file output options can also be preset via environment variables\.
. .
.SS "COLOR RATINGS" .SS "COLOR RATINGS"

View File

@ -276,6 +276,7 @@ The same can be achieved by setting the environment variable `WARNINGS`.
`--append` If an output file exists it will append to this file, without a header. The environment variable APPEND does the same. If the file exists and you don't use `--append` testssl.sh will exit with an error. Be careful using this switch/variable. A complementary option which overwrites an existing file doesn't exist per design. `--append` If an output file exists it will append to this file, without a header. The environment variable APPEND does the same. If the file exists and you don't use `--append` testssl.sh will exit with an error. Be careful using this switch/variable. A complementary option which overwrites an existing file doesn't exist per design.
`--prefix <out_fname_prefix>` Prepend output filename prefix <out_fname_prefix> before '\${NODE}.'. You can use as well the environment variable FNAME_PREFIX.
A few file output options can also be preset via environment variables. A few file output options can also be preset via environment variables.

View File

@ -192,6 +192,7 @@ JSONFILE="${JSONFILE:-""}" # jsonfile if used
CSVFILE="${CSVFILE:-""}" # csvfile if used CSVFILE="${CSVFILE:-""}" # csvfile if used
HTMLFILE="${HTMLFILE:-""}" # HTML if used HTMLFILE="${HTMLFILE:-""}" # HTML if used
FNAME=${FNAME:-""} # file name to read commands from FNAME=${FNAME:-""} # file name to read commands from
FNAME_PREFIX=${FNAME_PREFIX:-""}
APPEND=${APPEND:-false} # append to csv/json file instead of overwriting it APPEND=${APPEND:-false} # append to csv/json file instead of overwriting it
NODNS=${NODNS:-false} # always do DNS lookups per default. For some pentests it might save time to set this to true NODNS=${NODNS:-false} # always do DNS lookups per default. For some pentests it might save time to set this to true
HAS_IPv6=${HAS_IPv6:-false} # if you have OpenSSL with IPv6 support AND IPv6 networking set it to yes HAS_IPv6=${HAS_IPv6:-false} # if you have OpenSSL with IPv6 support AND IPv6 networking set it to yes
@ -848,16 +849,16 @@ json_header() {
elif "$do_mass_testing"; then elif "$do_mass_testing"; then
: :
elif "$do_mx_all_ips"; then elif "$do_mx_all_ips"; then
fname_prefix="mx-$URI" fname_prefix="${FNAME_PREFIX}.mx-${URI}"
else else
! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}" ! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}"
# NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place # NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place
fname_prefix="${NODE}"_p"${PORT}" fname_prefix="${FNAME_PREFIX}.${NODE}"_p"${PORT}"
fi fi
if [[ -z "$JSONFILE" ]]; then if [[ -z "$JSONFILE" ]]; then
JSONFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".json)" JSONFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".json)"
elif [[ -d "$JSONFILE" ]]; then elif [[ -d "$JSONFILE" ]]; then
JSONFILE="$JSONFILE/$fname_prefix-$(date +"%Y%m%d-%H%M".json)" JSONFILE="$JSONFILE/${fname_prefix}-$(date +"%Y%m%d-%H%M".json)"
fi fi
if "$APPEND"; then if "$APPEND"; then
JSONHEADER=false JSONHEADER=false
@ -887,17 +888,17 @@ csv_header() {
elif "$do_mass_testing"; then elif "$do_mass_testing"; then
: :
elif "$do_mx_all_ips"; then elif "$do_mx_all_ips"; then
fname_prefix="mx-$URI" fname_prefix="${FNAME_PREFIX}.mx-$URI"
else else
! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}" ! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}"
# NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place # NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place
fname_prefix="${NODE}"_p"${PORT}" fname_prefix="${FNAME_PREFIX}.${NODE}"_p"${PORT}"
fi fi
if [[ -z "$CSVFILE" ]]; then if [[ -z "$CSVFILE" ]]; then
CSVFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".csv)" CSVFILE="${fname_prefix}-$(date +"%Y%m%d-%H%M".csv)"
elif [[ -d "$CSVFILE" ]]; then elif [[ -d "$CSVFILE" ]]; then
CSVFILE="$CSVFILE/$fname_prefix-$(date +"%Y%m%d-%H%M".csv)" CSVFILE="$CSVFILE/${fname_prefix}-$(date +"%Y%m%d-%H%M".csv)"
fi fi
if "$APPEND"; then if "$APPEND"; then
CSVHEADER=false CSVHEADER=false
@ -930,11 +931,11 @@ html_header() {
elif "$do_mass_testing"; then elif "$do_mass_testing"; then
: :
elif "$do_mx_all_ips"; then elif "$do_mx_all_ips"; then
fname_prefix="mx-$URI" fname_prefix="${FNAME_PREFIX}.mx-$URI"
else else
! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}" ! "$filename_provided" && [[ -z "$NODE" ]] && parse_hn_port "${URI}"
# NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place # NODE, URL_PATH, PORT, IPADDR and IP46ADDR is set now --> wrong place
fname_prefix="${NODE}"_p"${PORT}" fname_prefix="${FNAME_PREFIX}.${NODE}"_p"${PORT}"
fi fi
if [[ -z "$HTMLFILE" ]]; then if [[ -z "$HTMLFILE" ]]; then
@ -12843,6 +12844,7 @@ file output options (can also be preset via environment variables)
--hints additional hints to findings --hints additional hints to findings
--severity <severity> severities with lower level will be filtered for CSV+JSON, possible values <LOW|MEDIUM|HIGH|CRITICAL> --severity <severity> severities with lower level will be filtered for CSV+JSON, possible values <LOW|MEDIUM|HIGH|CRITICAL>
--append if <logfile>, <csvfile>, <jsonfile> or <htmlfile> exists rather append then overwrite. Omits any header --append if <logfile>, <csvfile>, <jsonfile> or <htmlfile> exists rather append then overwrite. Omits any header
--prefix <out_fname_prefix> before '\${NODE}.' above prepend <out_fname_prefix>
Options requiring a value can also be called with '=' e.g. testssl.sh -t=smtp --wide --openssl=/usr/bin/openssl <URI>. Options requiring a value can also be called with '=' e.g. testssl.sh -t=smtp --wide --openssl=/usr/bin/openssl <URI>.
@ -13204,7 +13206,7 @@ prepare_logging() {
"$do_mass_testing" && ! "$filename_provided" && return 0 "$do_mass_testing" && ! "$filename_provided" && return 0
"$CHILD_MASS_TESTING" && "$filename_provided" && return 0 "$CHILD_MASS_TESTING" && "$filename_provided" && return 0
[[ -z "$fname_prefix" ]] && fname_prefix="${NODE}"_p"${PORT}" [[ -z "$fname_prefix" ]] && fname_prefix="${FNAME_PREFIX}.${NODE}"_p"${PORT}"
if [[ -z "$LOGFILE" ]]; then if [[ -z "$LOGFILE" ]]; then
LOGFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".log)" LOGFILE="$fname_prefix-$(date +"%Y%m%d-%H%M".log)"
@ -13843,7 +13845,7 @@ run_mx_all_ips() {
if [[ -n "$LOGFILE" ]]; then if [[ -n "$LOGFILE" ]]; then
prepare_logging prepare_logging
else else
prepare_logging "mx-$1" prepare_logging "${FNAME_PREFIX}.mx-$1"
fi fi
if [[ -n "$mxs" ]] && [[ "$mxs" != ' ' ]]; then if [[ -n "$mxs" ]] && [[ "$mxs" != ' ' ]]; then
[[ $mxport == "465" ]] && \ [[ $mxport == "465" ]] && \