본문 바로가기

CTF/바이너리

picoCTF 2019 : slippery-shellcode

소스코드

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

#define BUFSIZE 512
#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 your shellcode:");
  vuln(buf);

  puts("Thanks! Executing from a random location now...");

  int offset = (rand() % 256) + 1;
  
  ((void (*)())(buf+offset))();


  puts("Finishing Executing Shellcode. Exiting now...");
  
  return 0;
}

 

handy-shellcode 문제와 같은데

256바이트 이하 크기의 랜덤한 offset만 추가됐다. 

 

기존 코드에 "\x90"*256 만 추가하니까 풀렸다

 

picoCTF{sl1pp3ry_sh311c0d3_ecc37b22}

'CTF > 바이너리' 카테고리의 다른 글

python 쓸만한 함수들  (0) 2020.09.26
picoCTF 2019 : CanaRy  (0) 2019.10.10
picoCTF 2019 : rop32  (0) 2019.10.10
picoCTF 2019 : OverFlow 1  (0) 2019.10.09
picoCTF 2019 : handy-shellcode  (0) 2019.10.09