I'm new to reverse engineering C binaries but have been working on an old ctf and thought to ask for explanation of specific assembly commands and how a buffer overflow might force a function to be called.
I have taken apart a binary using ghidra and IDA. Its a pretty standard C program with a main() function and methods:
int main(void)
{
body();
return 0;
}
void body(void)
{
char buffer [500];
int size;
/* gather input and print to the console */
size = read(0,buffer,700);
printf("\nUser provided %d bytes. Buffer content is: %s\n",size,buffer);
return;
}
(Note functions listed are reconstructed from assembly code and therefore may not be exactly correct.) It was at this point that I considered a buffer overflow must be the target of the attack.
Further searching the program found this function, which I concluded I wanted to call:
void success(void)
{
system("cat file_you_cant_access.txt");
return;
}
This function is never called but it clearly is the answer to the challenge. So my question is how I can modify the main/body to call this side function.
Unfortunately I don't really understand assembly code so haven't been able to make sense of where addresses are stored and functions are called. Potentially here are some lines that could be significant (they are the lines in the helper method):
/* gather input and print to the console */
08048491 55 PUSH EBP
08048492 89 e5 MOV EBP,ESP
08048494 81 ec 18 SUB ESP,0x218
02 00 00
0804849a c7 44 24 MOV dword ptr [ESP + local_214],0x2bc
08 bc 02
00 00
080484a2 8d 85 00 LEA EAX=>local_204,[EBP + 0xfffffe00]
fe ff ff
080484a8 89 44 24 04 MOV dword ptr [ESP + local_218],EAX
080484ac c7 04 24 MOV dword ptr [ESP]=>local_21c,0x0
00 00 00 00
080484b3 e8 78 fe CALL read ssize_t read(int __fd, void * __
ff ff
080484b8 89 45 f4 MOV dword ptr [EBP + local_10],EAX
080484bb 8d 85 00 LEA EAX=>local_204,[EBP + 0xfffffe00]
fe ff ff
080484c1 89 44 24 08 MOV dword ptr [ESP + local_214],EAX
080484c5 8b 45 f4 MOV EAX,dword ptr [EBP + local_10]
080484c8 89 44 24 04 MOV dword ptr [ESP + local_218],EAX
080484cc c7 04 24 MOV dword ptr [ESP]=>local_21c,s__User_provided_%d = "\nUser provided %d bytes. Buf
a0 85 04 08
The issue is that it appears to not be possible to overflow the buffer into anything meaningful. If the answer isn't obvious, perhaps you can walk me through what approach you would take?