Skip to content

Instantly share code, notes, and snippets.

@kaworu
Created December 10, 2013 14:17
Show Gist options
  • Save kaworu/7891248 to your computer and use it in GitHub Desktop.
Save kaworu/7891248 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void target(void) __attribute__ ((section (".attack")));
void target(void) {
system("/bin/cat secret");
}
void vuln(char *arg) {
char len = 0;
char hello[108] = "Hello, ";
len = strlen(arg);
if (len > 100) {
printf("Sorry, name too long !\n");
exit(1);
}
strcat(hello, arg);
printf("%s.\n",hello);
}
int main(int argc, char **argv) {
setregid(getegid(), getegid());
printf("Hint: %p\n", target);
if (argc != 2) {
printf("Usage: ./program2 <argument>\n");
exit(2);
}
vuln(argv[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment