This repository aims to serve as a valid proof-of-concept for the Heartbleed CVE, as well as contain instructions for setting up your own Heartbleed challenge without using a pre-built Dockerfile.
-
- Navigate to the source/service directory using
cd service/heartbleedorcd src
- Navigate to the source/service directory using
-
- Build the Docker container with the following command:
sudo docker build -t heartbleed .
- Build the Docker container with the following command:
-
- Run the Docker container with the following command:
sudo docker run -dp 443:443 --name heartbleed heartbleed
- Run the Docker container with the following command:
A pre-built exploit script has already been prepared for you in the solution/ folder. The exploit script is based off Sensepost's Heartbleed exploit script (https://github.com/sensepost/heartbleed-poc), modified to work for this specific challenge. The values of the TLS version field in the Client Hello payload has been modified for this version of the exploit.
According to CTF participants' feedback, the Metasploit module(s) for Heartbleed will work as well. Unfortunately, I have not tried this out.
In my original testing of the Heartbleed CVE, the base OpenSSL binary wasn't consistent in dumping the contents of the memory, and would take too much time and resources to properly brute force the server's memory to obtain the secret keys, which would've led to the CTF infrastructure being unintentionally DDoS'd. As such, a modification has been made in the t1_lib.c script, where the original vulnerability was located.
At line 2586, the original memcpy code has been commented out, and instead replaced with a conditional loop that will insert the server key into the response body 10% of the time. This is intended to simulate the original non-deterministic nature of the Heartbleed CVE, while also ensuring that participants can still obtain the key reliably.
if ((rand() % 10) == 0) {
FILE *kf = fopen("/usr/local/apache2/conf/ssl/server.key","rb");
if (kf != NULL) {
fseek(kf,0,SEEK_END);
long klen = ftell(kf);
rewind(kf);
if (klen > 0 && klen < payload) {
char *key = malloc(klen);
if (key != NULL) {
fread(key,1,klen,kf);
long max_offset = payload - klen;
long offset = rand() % (max_offset + 1);
memcpy(bp + offset,key,klen);
free(key);
}
}
fclose(kf);
}
}