This repository contains artifacts for the paper "Terrapin Attack: Breaking SSH Channel Integrity By Sequence Number Manipulation", accepted at 33rd USENIX Security Symposium.
The code in this repository contains, among other artifacts, proof-of-concept attack proxies for the following CVEs:
All PoCs and scripts contained within these artifacts are designed to be run inside of Docker containers. As such, ensure that you have a recent
Linux (tested) or MacOS / Windows (untested) operating system with Docker installed. For easy reproduction of the paper results refer to the
scripts contained in the scripts
folder (see repository structure above).
All scripts will run the containers in --network host
to allow for easy capturing using Wireshark on the lo interface. By default, SSH servers
will bind to port 2200/tcp while PoC scripts will bind to 2201/tcp. As PoC scripts and SSH servers are binding to 0.0.0.0 it is advised to disconnect
your system from the network or configure your firewall properly to avoid disclosing insecure SSH services to your local network.
You may also build and run individual Docker containers (PoC and SSH implementations) at your own discretion.
You may run impl/build.sh
and pocs/build.sh
to check your setup. The output should indicate that the evaluation images are being built using Docker. If there is no output, all docker images are already built.
$ impl/build.sh
[+] Building 2.0s (15/15) FINISHED
[...]
=> => naming to docker.io/terrapin-artifacts/openssh-server:9.4p1
[...]
$ pocs/build.sh
[...]
Attack | PuTTY 0.79 | OpenSSH 9.4p1 | OpenSSH 9.5p1 | Dropbear 2022.83 | AsyncSSH 2.13.2 | libssh 0.10.5 |
---|---|---|---|---|---|---|
C1 RcvIncrease | ✅ | - | ✅ | ✅ | ✅ | ✅ |
C1 RcvDecrease | ✅ | - | R | ✅ | T | T |
C1 SndIncrease | ✅ | - | R | U | T | T |
C1 SndDecrease | ✅ | - | R | U | T | T |
C2 ChaCha20-Poly1305 | ✅ | ✅ | ✅ | - | - | - |
C2 CBC-EtM | 0.0300 (UNKNOWN) 0.8383 (PING) |
0.0003 (UNKNOWN) | 0.0003 (UNKNOWN) 0.0074 (PING) |
- | - | - |
C3 Rogue Extension | - | - | - | - | ✅ | - |
C4 Rogue Session | - | - | - | - | ✅ | - |
Legend:
(E1): scripts/test-sqn-manipulation.sh
- Run one of the four sequence number manipulation attacks to prove (C1).
(E2a): scripts/test-ext-downgrade.sh
- Run the extension downgrade attack to prove (C2) for ChaCha20-Poly1305.
Expected Runtime: About 1 minute.
Execution: After starting the script, choose an arbitrary client and server combination. Afterward, choose attack variant 1 to select ChaCha20-Poly1305.
Results: The script will conclude by opening the following files simultaneously in less
:
diff
of files 3 and 4diff
of files 5 and 6Navigate to the second file. The file compares the output of the selected SSH client in the case of an extension downgrade attack to the output of an unmodified connection. The diff will indicate the presence of SSH_MSG_EXT_INFO and absence of SSH_MSG_IGNORE in the unmodified connection only, thus proving (C2) for ChaCha20-Poly1305.
(E2b): scripts/bench-ext-downgrade.sh
- Run the extension downgrade attack 10,000 times to prove (C2) for CBC-EtM (UNKNOWN and PING).
(E3): scripts/test-asyncssh-rogue-ext-negotiation.sh
less
. Refer to the results of (E2a) for a list of files opened. Navigate to the second file. The diff will indicate the presence of the server-sig-algs extension with an attacker-chosen value in the tampered connection, thus proving (C3).(E4): scripts/test-asyncssh-rogue-session-attack.sh
less
. Refer to the results of (E2a) for a list of files opened. Navigate to the first file. The diff will indicate successful authentication for the victim (unmodified connection) and attacker (tampered connection), respectively. Afterward, navigate to the second file and examine the output of each client connection at the end of the file. In the unmodified connection, the server will respond with the username victim, while in the attacked connection, the server will respond with the username attacker. This proves (C4).To use scan_util.py, build the docker container by running the following command inside the scan
folder:
docker build . -t terrapin-artifacts/scan-util
Evaluation of a zgrab2 results file:
docker run --rm -v ./sample:/files terrapin-artifacts/scan-util evaluate -i /files/sample.json -o /files/sample.acc.json
Removal of blocked IP addresses from a list of IP addresses returned by zmap:
docker run --rm -v ./sample:/files terrapin-artifacts/scan-util filter-blocked-ips -i /files/zmap.csv -o /files/zmap-filtered.csv -b /files/blocklist.txt
Tidying zgrab2 results file by removing entries with connection failures:
docker run --rm -v ./sample:/files terrapin-artifacts/scan-util tidy-zgrab2 -i /files/sample.json -o /files/sample-clean.json
scripts/cleanup-system.sh
which remove any intermediate results and terminate and remove any running container
related to these artifacts. To rebuild the images on next execution of a test script, specify the --full
flag..
├── impl
│ ├── asyncssh # AsyncSSH 2.13.2 (client / server) Dockerfile and additional files
│ ├── dropbear # Dropbear 2022.83 (client / server) Dockerfile and additional files
│ ├── libssh # libssh 0.10.5 (client / server) Dockerfile and additional files
│ ├── openssh # OpenSSH 9.4p1 / 9.5p1 (client / server) Dockerfile and additional files
│ ├── putty # PuTTY 0.79 (client only) Dockerfile and additional files
│ └── build.sh # Script to build all required implementation Docker images for reproducing our results
├── pocs # Proof of concept scripts
│ ├── sqn-manipulations # Scripts related to sequence number manipulation (section 4.1)
│ ├── ext-downgrade # Scripts related to the extension downgrade attack (section 5.2)
│ ├── asyncssh # Scripts related to AsyncSSH vulnerabilities (section 6)
│ ├── Dockerfile # Multistage Dockerfile to build PoC docker images
│ └── build.sh # Script to build all required PoC Docker images for reproducing our results
├── scan # Files related to the internet-wide scan conducted
│ ├── paper # Directory containing the aggregated scan data referenced in the final version of the paper
│ ├── sample # Directory containing an anonymized zgrab2 ssh results sample to use with scan_util.py
│ ├── scan_util.py # Utility script for aggregating zgrab2 ssh results
│ ├── requirements.txt # pip requirements file for scan_util.py
│ └── Dockerfile # Dockerfile to build a docker image running scan_util.py
├── scripts # Scripts for easier reproduction of our results presented in the paper
│ ├── bench-ext-downgrade.sh # Benchmark script to evaluate the success rate of the CBC-EtM variant of the extension downgrade attack
│ ├── cleanup-system.sh # A cleanup script which can be used to containers and images related to these artifacts
│ ├── start-wireshark.sh # A convenience script to start Wireshark capturing on lo interface with SSH decoding and display filter
│ ├── test-asyncssh-rogue-ext-negotiation.sh
│ │ # Test script for the AsyncSSH-specific rogue extension negotiation attack (section 6.1 / figure 6)
│ ├── test-asnycssh-rogue-session-attack.sh
│ │ # Test script for the AsyncSSH-specific rogue session attack (section 6.2 / figure 7)
│ ├── test-ext-downgrade.sh # Test script for the extension downgrade attack (section 5.2 / figure 5)
│ └── test-sqn-manipulation.sh # Test script for sequence number manipulation (section 4.1)
├── traces # PCAP traces of the PoC scripts
├── LICENSE
└── README.md
The following third party libraries are used: