Skip to content

Commit ffe223f

Browse files
authored
Merge pull request #1807 from tosticated/custom_http_headers
Custom HTTP request headers support added. Addresses #1770
2 parents 2682d03 + 351f36c commit ffe223f

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Added --overwrite argument to support overwriting output files without warning
2929
* Headerflag X-XSS-Protection is now labeled as INFO
3030
* Client simulation runs in wide mode which is even better readable
31+
* Added --reqheader to support custom headers in HTTP requests
3132

3233
### Features implemented / improvements in 3.0
3334

CREDITS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Full contribution, see git log.
4242
* Jim Blankendaal
4343
- maximum certificate lifespan of 398 days
4444
- ssl renegotiation amount variable
45+
- custom http request headers
4546

4647
* Frank Breedijk
4748
- Detection of insecure redirects
@@ -181,4 +182,3 @@ Probably more I forgot to mention which did give me feedback, bug reports and he
181182
* Ivan Ristic/Qualys for the liberal license which made it possible to make partly use of the client data
182183

183184
* My family for supporting me doing this work
184-

doc/testssl.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ Please note that \fBfname\fR has to be in Unix format\. DOS carriage returns won
136136
.P
137137
\fB\-\-basicauth <user:pass>\fR This can be set to provide HTTP basic auth credentials which are used during checks for security headers\. BASICAUTH is the ENV variable you can use instead\.
138138
.
139+
.P
140+
\fB\-\-reqheader <header>\fR This can be used to add additional HTTP request headers in the correct format \fBHeadername: headercontent\fR\. This parameter can be called multiple times if required\. For example: \fB\-\-reqheader \'Proxy\-Authorization: Basic dGVzdHNzbDpydWxlcw==\' \-\-reqheader \'ClientID: 0xDEADBEAF\'\fR\. REQHEADER is the corresponding environment variable\.
141+
.
139142
.SS "SPECIAL INVOCATIONS"
140143
\fB\-t <protocol>, \-\-starttls <protocol>\fR does a default run against a STARTTLS enabled \fBprotocol\fR\. \fBprotocol\fR must be one of \fBftp\fR, \fBsmtp\fR, \fBpop3\fR, \fBimap\fR, \fBxmpp\fR, \fBxmpp-server\fR, \fBtelnet\fR, \fBldap\fR, \fBirc\fR, \fBlmtp\fR, \fBnntp\fR, \fBpostgres\fR, \fBmysql\fR\. For the latter four you need e\.g\. the supplied OpenSSL or OpenSSL version 1\.1\.1\. Please note: MongoDB doesn\'t offer a STARTTLS connection, LDAP currently only works with \fB\-\-ssl\-native\fR\. \fBtelnet\fR and \fBirc\fR is WIP\.
141144
.

doc/testssl.1.html

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/testssl.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ The same can be achieved by setting the environment variable `WARNINGS`.
110110

111111
`--basicauth <user:pass>` This can be set to provide HTTP basic auth credentials which are used during checks for security headers. BASICAUTH is the ENV variable you can use instead.
112112

113+
`--reqheader <header>` This can be used to add additional HTTP request headers in the correct format `Headername: headercontent`. This parameter can be called multiple times if required. For example: `--reqheader 'Proxy-Authorization: Basic dGVzdHNzbDpydWxlcw==' --reqheader 'ClientID: 0xDEADBEAF'`. REQHEADER is the corresponding environment variable.
114+
113115

114116
### SPECIAL INVOCATIONS
115117

testssl.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ QUIET=${QUIET:-false} # don't output the banner. By doing this
162162
SSL_NATIVE=${SSL_NATIVE:-false} # we do per default bash sockets where possible "true": switch back to "openssl native"
163163
ASSUME_HTTP=${ASSUME_HTTP:-false} # in seldom cases (WAF, old servers, grumpy SSL) service detection fails. "True" enforces HTTP checks
164164
BASICAUTH=${BASICAUTH:-""} # HTTP basic auth credentials can be set here like user:pass
165+
REQHEADER=${REQHEADER:-""} # HTTP custom request header can be set here like Header: content. Can be used multiple times.
165166
BUGS=${BUGS:-""} # -bugs option from openssl, needed for some BIG IP F5
166167
WARNINGS=${WARNINGS:-""} # can be either off or batch
167168
DEBUG=${DEBUG:-0} # 1: normal output the files in /tmp/ are kept for further debugging purposes
@@ -373,6 +374,7 @@ TLS_NOW="" # Similar
373374
TLS_DIFFTIME_SET=false # Tells TLS functions to measure the TLS difftime or not
374375
NOW_TIME=""
375376
HTTP_TIME=""
377+
REQHEADERS=()
376378
GET_REQ11=""
377379
START_TIME=0 # time in epoch when the action started
378380
END_TIME=0 # .. ended
@@ -886,6 +888,15 @@ is_ipv6addr() {
886888
return 1
887889
}
888890

891+
join_by() {
892+
# joins an array using a custom delimiter https://web.archive.org/web/20201222183540/https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash/17841619#17841619
893+
local d=$1
894+
shift
895+
local f=$1
896+
shift
897+
printf %s "$f" "${@/#/$d}";
898+
}
899+
889900
###### END universal helper function definitions ######
890901

891902
###### START ServerHello/OpenSSL/F5 function definitions ######
@@ -19239,6 +19250,7 @@ tuning / connect options (most also can be preset via environment variables):
1923919250
--phone-out allow to contact external servers for CRL download and querying OCSP responder
1924019251
--add-ca <CA files|CA dir> path to <CAdir> with *.pem or a comma separated list of CA files to include in trust check
1924119252
--basicauth <user:pass> provide HTTP basic auth information.
19253+
--reqheader <header> add custom http request headers
1924219254

1924319255
output options (can also be preset via environment variables):
1924419256
--quiet don't output the banner. By doing this you acknowledge usage terms normally appearing in the banner
@@ -19391,6 +19403,7 @@ SHOW_EACH_C: $SHOW_EACH_C
1939119403
SSL_NATIVE: $SSL_NATIVE
1939219404
ASSUME_HTTP $ASSUME_HTTP
1939319405
BASICAUTH: $BASICAUTH
19406+
REQHEADER: $REQHEADER
1939419407
SNEAKY: $SNEAKY
1939519408
OFFENSIVE: $OFFENSIVE
1939619409
PHONE_OUT: $PHONE_OUT
@@ -20514,6 +20527,7 @@ determine_service() {
2051420527
local ua
2051520528
local protocol
2051620529
local basicauth_header=""
20530+
local reqheader=""
2051720531

2051820532
# Check if we can connect to $NODEIP:$PORT. Attention: This ALWAYS uses sockets. Thus timeouts for --ssl-=native do not apply
2051920533
if ! fd_socket 5; then
@@ -20541,7 +20555,10 @@ determine_service() {
2054120555
if [[ -n "$BASICAUTH" ]]; then
2054220556
basicauth_header="Authorization: Basic $(safe_echo "$BASICAUTH" | $OPENSSL base64 2>/dev/null)\r\n"
2054320557
fi
20544-
GET_REQ11="GET $URL_PATH HTTP/1.1\r\nHost: $NODE\r\nUser-Agent: $ua\r\n${basicauth_header}Accept-Encoding: identity\r\nAccept: text/*\r\nConnection: Close\r\n\r\n"
20558+
if [[ -n "$REQHEADERS" ]]; then
20559+
reqheader="$(join_by "\r\n" "${REQHEADERS[@]}")\r\n" #Add all required custom http headers to one string with newlines
20560+
fi
20561+
GET_REQ11="GET $URL_PATH HTTP/1.1\r\nHost: $NODE\r\nUser-Agent: $ua\r\n${basicauth_header}${reqheader}Accept-Encoding: identity\r\nAccept: text/*\r\nConnection: Close\r\n\r\n"
2054520562
# returns always 0:
2054620563
service_detection $OPTIMAL_PROTO
2054720564
else # STARTTLS
@@ -22193,6 +22210,11 @@ parse_cmd_line() {
2219322210
BASICAUTH="$(parse_opt_equal_sign "$1" "$2")"
2219422211
[[ $? -eq 0 ]] && shift
2219522212
;;
22213+
--reqheader|--reqheader=*)
22214+
REQHEADER="$(parse_opt_equal_sign "$1" "$2")"
22215+
[[ $? -eq 0 ]] && shift
22216+
REQHEADERS+=("$REQHEADER")
22217+
;;
2219622218
(--) shift
2219722219
break
2219822220
;;

0 commit comments

Comments
 (0)