-
-
Save sudhackar/6242356dfd8b8752b2401effa12fab06 to your computer and use it in GitHub Desktop.
BBCTF 2018 ROP crazy
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
/* | |
* gg.c | |
* | |
* Copyright 2018 Sudhakar Verma <[email protected]> | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
* MA 02110-1301, USA. | |
* | |
* | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <signal.h> | |
#include <unistd.h> | |
#include <assert.h> | |
int main(int argc, char **argv){ | |
int fd, i; | |
char *psc; | |
void (*f)(); | |
psc = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
assert(psc != NULL); | |
printf("%p\n", psc); | |
fflush(stdout); | |
while(1){ | |
fd = open("/dev/urandom", O_RDONLY); | |
read(fd, psc, 0x1000); | |
write(1, psc, 0x1000); | |
for(i=0; i< 0x1000 ;i+= sizeof(int)){ | |
psc[i] = '\xc3'; | |
} | |
read(0, &f, 8); | |
read(0, psc,8); | |
f(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment