Skip to content

Instantly share code, notes, and snippets.

@murx-

murx-/test2.c Secret

Created November 26, 2020 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save murx-/98adcbf98806dbe237dc0bff6e03ce6c to your computer and use it in GitHub Desktop.
Save murx-/98adcbf98806dbe237dc0bff6e03ce6c to your computer and use it in GitHub Desktop.
Example of a vulnerable program for a blogpost.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void vuln(char *buf) {
free(buf);
}
int main() {
char buf[100];
int len = read(0, &buf, 99);
buf[len] = '\x00';
char *buf2 = malloc(128);
if (buf[0] == '0')
vuln(buf2);
if (buf[0] == '1')
vuln(buf2);
if (buf[0] == '2')
vuln(buf2);
if (buf[0] == '3')
vuln(buf2);
if (buf[0] == '4')
vuln(buf2);
if (buf[0] == '5')
vuln(buf2);
if (buf[0] == '6')
vuln(buf2);
if (buf[0] == '7')
vuln(buf2);
if (buf[0] == '8')
vuln(buf2);
if (buf[0] == '9')
vuln(buf2);
free(buf2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment