Das Ziel besteht also darin, call_me_twice ein zweites Mal aufzurufen, indem die Adresse in die Eingabezeichenfolge übergeben wird.
Code: Select all
$ cat bof.c
#include
#include
void return_input (char *s) {
char array[10];
strcpy(array,s);
printf("%s\n", array);
}
char call_me_twice () {
printf("Example\n");
}
int main (int argc, char *argv[]) {
call_me_twice();
return_input(argv[1]);
return 0;
}
Code: Select all
$ gcc -m32 -fno-stack-protector bof.c
Code: Select all
$ ./a.out HelloWorld
Example
HelloWorld
$ ./a.out HelloWorld##########
Example
HelloWorld##########
Segmentation fault (core dumped)
Code: Select all
$ coredumpctl list | tail -1
$ coredumpctl dump 15761 > core.15761
Code: Select all
$ gdb ./a.out core.15761
Code: Select all
(gdb) disassemble main
Dump of assembler code for function main:
0x66405201 : lea 0x4(%esp),%ecx
0x66405205 : and $0xfffffff0,%esp
0x66405208 : push -0x4(%ecx)
0x6640520b : push %ebp
0x6640520c : mov %esp,%ebp
0x6640520e : push %ebx
0x6640520f : push %ecx
0x66405210 : call 0x66405244
0x66405215 : add $0x2dbf,%eax
0x6640521a : mov %ecx,%ebx
0x6640521c : call 0x664051d6
0x66405221 : mov 0x4(%ebx),%eax
0x66405224 : add $0x4,%eax
0x66405227 : mov (%eax),%eax
0x66405229 : sub $0xc,%esp
0x6640522c : push %eax
0x6640522d : call 0x6640519d
0x66405232 : add $0x10,%esp
0x66405235 : mov $0x0,%eax
0x6640523a : lea -0x8(%ebp),%esp
=> 0x6640523d : pop %ecx
0x6640523e : pop %ebx
0x6640523f : pop %ebp
0x66405240 : lea -0x4(%ecx),%esp
0x66405243 : ret
End of assembler dump.
Ich habe es versucht Rufen Sie von 1 #-Symbol bis 100 #-Symbolen auf, aber jedes Mal erhalten Sie
Code: Select all
$ ./a.out #\x1c\x52\x40\x66
Example
Segmentation fault (core dumped)
...
$ ./a.out ####################################################################################################\x1c\x52\x40\x66
Example
Segmentation fault (core dumped)
Code: Select all
ExampleWas mache ich falsch? Wie rufe ich call_me_twice eigentlich zum zweiten Mal auf?
Ich habe Stack Smashing erkannt überprüft, aber wahrscheinlich habe ich etwas übersehen.
PS.
Code: Select all
$ gcc -v
Using built-in specs.
...
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)
Mobile version