It looks like you're new here. If you want to get involved, click one of these buttons!
_____ _______ _____
/ ____|__ __/ ____|
| (___ | | | (___
\___ \ | | \___ \
____) | | | ____) |
|_____/ |_| |_____/
`smash the stack` [C programming] n. On many C implementations
it is possible to corrupt the execution stack by writing past
the end of an array declared auto in a routine. Code that does
this is said to smash the stack, and can cause return from the
routine to jump to a random address. This can produce some of
the most insidious data-dependent bugs known to mankind.
Variants include trash the stack, scribble the stack, mangle
the stack; the term mung the stack is not used, as this is
never done intentionally.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
/* if theres no argument, exit */
if(!argv[1]) {
return 0;
}
/* copy the first argument into a 256 byte buffer */
char buffer[256];
strcpy(buffer, argv[1]);
return 0;
}
char buffer[256];
./vulnerable `perl -e 'print \"A\"x300'`
\x31\xc9\x83\xe9\xee\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x5e
level7@blowfish:~$ cat /levels/level7.c
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int i;
char buffer[32];
//char *key1 = \"/\";
char *p1, *p2, *p3, *p4, *p5;
char key2[2], key3[2], key4[2], key5[2];
// if(argc != 2)
// return -1;
for(i = 1; i < argc; i++) {
memset(argv[i], 0, strlen(argv[i]));
}
sprintf(key2, \"%c\", 0x90); // nop
sprintf(key3, \"%c\", 0xeb); // jmp
sprintf(key4, \"%c\", 0xcd); // int
sprintf(key5, \"%c\", 0xff); // still easy
//p1 = strstr(argv[0], key1);
p2 = strstr(argv[0], key2);
p3 = strstr(argv[0], key3);
p4 = strstr(argv[0], key4);
p5 = strstr(argv[0], key5);
if (p2 != NULL || p3 != NULL || p4 != NULL || p5 != NULL) {
printf(\"Access denied.\n\");
return -1;
}
else {
printf(\"Access granted.\n\");
}
strcpy(buffer, argv[0]);
return 0;
}