Created
January 15, 2022 23:06
-
-
Save klecko/cb8e04c1ec1c147fce87a206067676c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <fcntl.h> | |
#include <string.h> | |
void vuln(const char* content, int size) { | |
if (size < 12) | |
return; | |
if (content[0] == 'G' && content[1] == 'O' && content[2] == 'T' && | |
content[3] == 'T' && content[4] == 'A' && content[5] == 'G' && | |
content[6] == 'O' && content[7] == 'F' && content[8] == 'A' && | |
content[9] == 'S' && content[10] == 'T' && content[11] == '!') | |
{ | |
*(int*)(0xDEADBEEF) = 0x41414141; | |
} | |
} | |
int main(int argc, char** argv) { | |
if (argc < 2) { | |
printf("usage: %s filename\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
int fd = open(argv[1], O_RDONLY); | |
if (fd == -1) { | |
perror("error opening file"); | |
exit(EXIT_FAILURE); | |
} | |
char data[1024]; | |
size_t bytes_read = read(fd, data, sizeof(data)); | |
if (bytes_read == -1) { | |
perror("error reading file"); | |
exit(EXIT_FAILURE); | |
} | |
close(fd); | |
vuln(data, bytes_read); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment