Commit Graph

2199 Commits

Author SHA1 Message Date
Dirk Wetter
fab42dd477 Backport HTTP 'Age' header field
See #2032 / #2067, kudos @Wahnes. This is a backport for 3.0

    Currently, when "HTTP clock skew" is calculated, this is taken to be the
    difference between the timestamp of the moment the HTTPS request was sent and
    the date given in the HTTP Date header. This does not yield valid results in
    case a HTTP cache is used, either on the client side or on the server side.
    According to the HTTP specs, the Date field will contain the timestamp the
    response was created, which may not be the timestamp the response was
    delivered.

    Consider the following example that queries the Varnish project's web server.
    Note that Varnish is a popular HTTP caching server, so HTTP caching will of
    course be used when serving HTTP responses from this project's web server.
    testssl.sh https://varnish-cache.org/ This will typically output a HTTP clock
    skew of some thousand seconds.

    The patch takes into account the HTTP Age header that caching servers add to
    the HTTP response to signal the response's freshness. As client-side caches
    normally do not cache HTTPS requests (except maybe for "enterprise" HTTP proxy
    caches that do MITM HTTPS proxying), this is mostly targeted to HTTPS websites
    that employ server side HTTP caching.

    Addtional polishing:

    * address my comments in #2032
    * add JSON field HTTP_headerAge if they exists
    * output HTTP_AGE if it was detected
    * do stripping of line feeds closer to where variables were set
2021-12-10 15:27:43 +01:00
David Cooper
9c0fac1790
Fix JSON header
This commit fixes an issue with the headers in the structured JSON output. If run_cipher_match() is performed the header that is used is "pretest" rather than "singleCipher".
2021-12-08 14:38:37 -05:00
David Cooper
bcc6178c57
Update reset_hostdepended_vars()
This commit adds several variables to reset_hostdepended_vars() that are not currently being reset for each host being tested, but that should be reset.
2021-12-08 09:16:55 -05:00
Dr. Matthias St. Pierre
468ade5163 Simplify check for git working tree in 3.0
Sending the entire log to /dev/null is a rather expensive way of checking whether
we are inside a git working tree. Use `git rev-parse --is-inside-work-tree` instead.

(cherry picked from commit 1e3f932932)
2021-12-06 22:20:07 +01:00
David Cooper
6888045bc8
Fix #2049 in 3.0
This commit fixes #2049 by converting newline characters to spaces in JSON and CSV findings.

fileout() calls newline_to_spaces() on any $finding that is to be written to a JSON or CSV file. However, this only affects actual newline characters in the string, not escaped newline characters (i.e., "\n"). Escaped newline characters pass through this function unchanged, but then get converted to newline characters when they are written to the JSON and/or CSV files. This commit fixes the problem by also converting escaped newline characters ("\n") to spaces.
2021-11-30 07:29:24 -05:00
Dirk
4a02dcb767 Fix for "Bad file descriptor" with --connect-timeout option (3.0)
This fixes #1834 and #1435 for branch 3.0. (3.1dev: #2047)

The --connect-timeout option had the problem that under certain circumstances
like parallel mass scanning didn't work. The culprit was that a subshell command
was used to connect to the target but the file descriptor wasn't exported.

The PR changes the logic so that the connect pre-check is still done in a subshell
If this fails it proceeds with error handling if NR_SOCKET_FAIL is above threshold.
Otherwise it just connects again.
2021-11-28 18:21:43 +01:00
David Cooper
f7c9030364 Fix sub_cipherlists()
This commit fixes a bug in sub_cipherlists() when using sockets to test whether a server supports a set of ciphers with SSLv2. Code that is supposed to extract the list of SSLv2 ciphers to test for is incorrectly reading from the list of non-SSLv2 ciphers.
2021-11-22 12:29:51 -05:00
David Cooper
bc2ea32c32
Support OpenSSL 3.0.1-dev and 3.1.0-dev
Same as #2040, but for the 3.0 branch.
2021-11-10 09:16:46 -05:00
David Cooper
1e4dd4d1bf
Improve cipher_pref_check()
Some servers are configured to prioritize ChaCha ciphers if those ciphers are preferred by the client, even if the server is generally configured to use the server's cipher preferences rather than the client's. As a result of this, if a ChaCha cipher appears in the ClientHello before a non-ChaCha cipher, the server may select the ChaCha cipher even if the server is configured to prefer the non-ChaCha cipher.

In a few cases, e.g., cloudflare.com for TLS 1.2, this affects the ordering of the ciphers presented by cipher_pref_check(). This PR fixes the problem by having cipher_pref_check() (and check_tls12_pref()) always place any ChaCha ciphers at the end of the cipher list in the ClientHello. This ensures that cipher_pref_check() presents the ciphers in the server's preference order.
2021-10-27 12:48:11 -04:00
Dirk Wetter
1b2903e7ac Improvement for testing curves with several openssl / libressl versions
As noted in #2016 the detection of curves in find_openssl_binary()
was not yet perfect.

This commit removes another connect call. Also it corrects the port statement
for LibreSSL-like pre-checks as port 0 generally seems to me better suited.
Inline documentation was added.

It worked so far with OpenSSL 1.0.2, 1.1.1 and 3.0 and LibreSSL 3.4.

This is for 3.0. Similar commit (a11bd1585e)
was for 3.1dev, see PR #2020 .
2021-10-24 22:01:08 +02:00
Dirk Wetter
a580c20434 Add browser requirement for the entropy of cert serial
see also https://github.com/drwetter/testssl.sh/issues/2013#issuecomment-947834789
2021-10-20 19:41:43 +02:00
Dirk Wetter
3e68dbd8ac
Merge pull request #2012 from drwetter/windows_dns_fix_3.0
Addressing lame DNS responses on WSL (3.0)
2021-10-20 08:59:20 +02:00
Dirk Wetter
36f6093ca9 Check cert serial len + fix output when too big (3.0)
Same as #2014, this is for 3.0 though.

OpenSSL shows certificate serial numbers >35 with a LF (0A). Testssl.sh
just output that which makes JSON invalid and displays the LF in the terminal
too.

This PR fixes that (#2010) by adding text filters so that the
serial number is not a multiline string.

Also this PR introduces a new function: a size check of the cert serial.
Below 8 bytes the CAB Forum's lower limit is hit which says the entropy
from a CSPRNG should be at least 64 bits. It is assumed that below 8 bytes
length this requirement isn't possible to meet (needs to be clarified with
Shannon, 8 bytes seems to low to me).
The high threshold is according to RFC 5280, Section-4.1.2.2 .

See also #2013.

The output has changed, so that on the terminal the serial has one line,
SHA1 and SHA256 each one line. The new json key is "cert_serialNumberLen".
2021-10-19 20:27:43 +02:00
Dirk Wetter
6c555f478b Addressing lame DNS responses on WSL (3.0)
This commit provides a global variable to the RFC 6761 use of "invalid."
which WSL clients don't seem to handle very well, see #1738, #1812.
"invalid."  is used as a target to find out in a couple of pre-checks what
is supported by the openssl version.

This PR reduces the number of ``openssl s_client -connect`` by a huge factor.
For the remaining invocations the OS used is being determined and if WSL is
assumed (the check is probably not 100% accurate) it uses ``127.0.0.1:0`` instead.
In (unfortunately only a few) pre-tests the response was immediate.

Also it is possible to use another target if needed by

     NXCONNECT=<mytargethere>:<myport> ./testssl.sh <URL>

This is for 3.0. For 3.1dev see #1988 .
2021-10-18 20:09:16 +02:00
Dirk
2e821b9f62 Fix invalid JSON when certificate issuer contains non-ASCII chars (3.0)
Changed printf %s to printf %b which cause now to output UTF-8 correctly.

See #1992.
2021-10-03 18:31:06 +02:00
Dirk Wetter
1732e9c919
Merge branch '3.0' into bump_version_3.0.6 2021-10-02 22:21:36 +02:00
Dirk Wetter
8a53039de6 Fix #1982: Newer openssl.cnf break openssl detection (3.0)
Newer configuration files from openssl may include statements
which aren't compatible with our supplied old openssl version.
This commit adds an autodetection of such a file and uses a
openssl.cnf provided by this project then.

The openssl.cnf is from a Debian Jessie package.

See also #1987
2021-09-15 11:25:10 +02:00
Dimitri Papadopoulos
ca1043bda5
Typos found by codespell
Run codespell in CI
2021-09-14 14:10:33 +02:00
Dirk
7be262f287 Fix minor inconsistency in description of cipher categories
A longer while back the section ~ "Testing standard ciphers" was
renamed to "Testing cipher categories". However the internal help
didn't reflect that.

This fixes that, including an addtion to the documentation.

Note: the help still lists "-s --std, --standard" as a cmd line
switch.
2021-09-09 21:50:03 +02:00
Andreas Perhab
f7b8f93fd0 Fix dig -r check to only run if dig is available 2021-09-06 10:24:51 +02:00
Dirk
80cbdf2748 Fix cases where dig -r wasn't working (3.0)
Similar to #1972.

* the ignore ~/.digrc option from dig is now parsed from the builtin help
* there was a potential DNS call which is now avoided
* the +noidnout check is now parsed from the builtin help
* the OPENSSL_CONF="" in check_resolver_bins() was moved a few lines higher to avoid other errors in the terminal
* redo check for noidnout by also using the help function of dig

See also #1949
2021-09-01 18:51:03 +02:00
David Cooper
00ffcb8c00 Fix #1961 in 3.0 branch
This commit is the same as #1962, but for the 3.0 branch.
2021-08-30 13:52:00 -04:00
Dirk Wetter
8b5f25a113
Merge pull request #1959 from dcooper16/use_all+_3.0
Use all+ in calls to tls_sockets() in 3.0
2021-08-07 16:07:22 +02:00
David Cooper
ff5b321d38 Use all+ in calls to tls_sockets() in 3.0
get_server_certificate() includes a few calls to tls_sockets() in which the response will be TLS 1.3 and in which the response will be useless if it cannot be decrypted (since the goal is to obtain the server's certificate). So, these calls to tls_sockets() should specify "all+" rather than "all".
2021-08-04 14:31:42 -04:00
Dirk Wetter
65d6c27551 Redirect debugme() outputs to stderr
... to address #1956 and other places.
2021-08-04 19:33:01 +02:00
Dirk Wetter
556208815a Merge remote-tracking branch 'origin/3.0' into digrc_3.0 2021-08-01 20:20:24 +02:00
Dirk Wetter
16c18789cd Legacy removals + housekeeping
* remove relics (CVS)
* add diff to HTML CI run
2021-08-01 18:25:13 +02:00
Dirk Wetter
2f398d3cd0
Merge pull request #1951 from drwetter/fix_1717_3.0
Look-ahead trick for -U --ids-friendly (3.0)
2021-08-01 17:46:58 +02:00
Dirk
e293b7d839 Look-ahead trick for -U --ids-friendly
If the order of the cmdline is '-U --ids-friendly' then we need to make sure we catch --ids-friendly. Normally we do not,
 see #1717. The following statement makes sure. In the do-while + case-esac loop  the check for --ids-friendly will be
executed again, but it does not hurt
2021-07-31 18:47:00 +02:00
Dirk
ac2b43170b Move dig down the row of DNS resolvers
... because there's a higher possibility for the stable branch
that people use $HOME/.digrc
2021-07-31 15:22:05 +02:00
Dirk
8d6609f1b9 Ignore $HOME/.digrc
Newer dig versions have an option to ignore $HOME/.digrc, older
don't.

This commit adds a patch checking for the availability of
such an option and uses it by default.

If doesn't exist then still dig is used and can still lead to
wrong output. Unfortunately Debian-based distros are not very
good at this. Debian 10, Ubuntu 18.04 still use dig 9.11, whereas
Opensuse 15.2 has 9.16.

Debian 11 and Ubuntu 20.04 use that too.

Thus to be considered for the stable 3.0-branch: move
dig in the resolver functions a couple of lines down.
2021-07-31 14:37:36 +02:00
Dirk
a67a0200c2 Bump version 3.0.6
There might be 1-2 PRs before 3.0.6 is being released.
2021-07-31 14:12:15 +02:00
Dirk
13303753ff Disable ANSI codes for italic when TERM == screen
... otherwise it is being printed in reverse, see #1928.
Same as #1946 but for the 3.0 branch.
2021-07-31 13:22:47 +02:00
Dirk Wetter
5ae17681f6 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.
2021-07-30 14:47:17 +02:00
Dirk
3544014fe3 Fix problem when nmap file has .txt extension (3.0)
This addresses a bug filed in #1935 in 3.1dev when the supplied file
has a .txt extension. In this scenario the input file was nulled
as from the input file in nmap format an internal input file was
generated which has a .txt extension, in the same directory.
The idea was to persist the file for the user.

Now, this internal input file is ephemeral and only written to $TEMPDIR.
2021-07-25 16:40:16 +02:00
Dirk Wetter
19feed169e Fix indentation and redundant message (BREACH) when client certificate required
... see #1915
2021-06-17 09:23:34 +02:00
Dirk Wetter
f6a9044315 Display time as suggested in utc (3.0)
This fixes #1895
2021-06-03 19:29:26 +02:00
David Cooper
7d5e24c62f
Print errors to stderr
Same as #1888, but for the 3.0 branch.
2021-05-13 11:21:48 -04:00
Geert Hendrickx
388f3aea19
hostname is not defined by POSIX, use portable uname -n instead. 2021-05-13 13:58:07 +02:00
Dirk Wetter
f5fde2a93b Bump version 2021-05-10 12:16:12 +02:00
Dirk Wetter
4976da43b0
Merge pull request #1883 from drwetter/epoch_180hsts_1879.branch_3.0
Fix "off by one" error in HSTS
2021-05-10 11:18:53 +02:00
Chad Brigance
ca4a0b23f7 fixed minor bug with json output for TLS1.1 #1884 2021-05-09 09:46:57 +00:00
Dirk Wetter
68cbdf8dc8 Fix "off by one" error in HSTS
There was by mistake a 179 days threshold and also the error message
was wrong when HSTS was exactly set to 179 days, see #1879.

This commit sets it to 180 days and corrects the error messages on
screen.
2021-05-08 14:55:30 +02:00
David Cooper
c0f29f6234
Improve compatibility with OpenSSL 3.0
This commit makes the same changes to the 3.0 branch as #1868 makes to the 3.1dev branch.
2021-04-08 12:10:29 -04:00
Dirk
c461702112 Ensure certain regex patterns work as expected and aren't localized (3.0)
Same as #1865.

This PR is trying to address an issue where probably newer bash versions treat
regexes differently in other locales. W is with a swedish locale just a variant
of V (#1860) see also e.g.

https://collation-charts.org/opensolaris/opensolaris.2008.05.sv_SE.UTF-8.html
https://www.sqlservercentral.com/forums/topic/order-by-name-not-works#post-1644177
2021-04-05 11:38:17 +02:00
Dirk
a1777cdd0e Fix file output formatting for heartbleed
Quotes were wrong for different results, which lead to some confusion
for finding, cve and cwe.

Fixes #1828
2021-01-20 09:04:11 +01:00
Dirk Wetter
b8e76a3861 Fixes trailing dot error in URL handling
For DNS queries a trailing dot in the variable $NODE is always fine. For
HTTP queries it is not. and causes the https request to fail.

Backport from 4f1da9b192

Also: removal of ancient CVS_REL relict in $TEMPDIR/environment.txt
2021-01-13 11:35:31 +01:00
Dirk Wetter
0de00f4322 Fix issuer check for Let's Encrypt (3.0)
Fixes #1816 for 3.0 by a proper halving of the dates
2021-01-07 10:29:08 +01:00
Dirk
ca89328ed4 Change version number
To avoid clashes with distributors it may be is smarter to stick
to three numbers and not intoducing another digit.

3.0.4 <-- 3.0.3.1
2020-11-20 11:09:17 +01:00
Dirk
e441357efe Fix reading SSLv2 socket (3.0 branch)
This fixes #1779. There was a problem introduced in
3c97412a61 which counted
the size of the file name rather than the size of the
socket reply.
2020-11-20 11:06:22 +01:00