I am new to CTFs and I was asked to solve this:
#include <cstdio>
// g++ pwn2.cpp -o pwn2 -static
void ilocamp() {
char flaga[1024] = {0};
FILE *f = fopen("flag2.txt", "r");
fread(flaga, 1, 1024, f);
fclose(f);
printf("flaga: ILOCAMP{%s}\n", flaga);
}
int main() {
int tab[100] = {0};
int dwa = 2;
int n,i,min,x;
scanf("%d",&n);
for (i=0;i<n;i++) {
scanf("%d", &x);
scanf("%d", &tab[x]);
}
min = 1000000000;
for (i=0;i<n;i++) {
if (tab[i] && tab[i] < min) {
min = tab[i];
}
}
printf("najmniejsza liczba: %d a dwa wynosi: %d\n", min, dwa);
}
I know, that the point is to overwrite return address of main function with ilocamp() entry address, and to do this I am supposed to use that simple vuln in the loop, but I just have no clue how to do this. I have binary also, tried to do something with gdb but I dont know in true how to. Can you give me some tips? There is binary: http://www48.zippyshare.com/v/b7OaWQeW/file.html (File "flag2.txt" is on local server)