목록전체 글 (243)
CIDY

문제가 너무 간단해서 그냥 풀이 적지 말까 하다가 그래도 차근차근 해나가고 싶어서 적고 감 // Name: rtl.c // Compile: gcc -o rtl rtl.c -fno-PIE -no-pie // 64-bit, canary, nx, partial relro #include #include const char* binsh = "/bin/sh"; int main() { char buf[0x30]; setvbuf(stdin, 0, _IONBF, 0); setvbuf(stdout, 0, _IONBF, 0); // Add system function to plt's entry system("echo 'system@plt"); // Leak canary printf("[1] Leak Canary\n"); ..

#include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } void get_shell() { system("/bin/sh"); } void print_box(unsigned char *box, int idx) { printf("Element of index %d is : %02x\n", idx, box[idx]); } void menu() { puts("[F]ill the ..

// Name: r2s.c // Compile: gcc -o r2s r2s.c -zexecstack // 64-bit, canary, pie, full relro #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } int main() { char buf[0x50]; init(); printf("Address of the buf: %p\n", buf); printf("Distance between buf and $rbp: %ld\n", (char*)__builtin_frame_address(0) - buf); printf("[1] Leak the canary\n"); printf("Input: "); ffl..

// 32-bit, nx #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } void read_flag() { system("cat /flag"); } int main(int argc, char *argv[]) { char buf[0x80]; initialize(); gets(buf); return 0; } nx걸려있음 -> 스택에 쉘코드 올려쓰는 방법은 안 됨. 근..

//32-bit #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void initialize() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM, alarm_handler); alarm(30); } int main(int argc, char *argv[]) { char buf[0x80]; initialize(); printf("buf = (%p)\n", buf); scanf("%141s", buf); return 0; } 보호기법이 싹 안걸려있다. (주석 참고) -> nx안걸려있으니 쉘코드 쓰자..

// Name: rao.c // Compile: gcc -o rao rao.c -fno-stack-protector -no-pie // 64-bit, nx, partial relro #include #include void init() { setvbuf(stdin, 0, 2, 0); setvbuf(stdout, 0, 2, 0); } void get_shell() { char *cmd = "/bin/sh"; char *args[] = {cmd, NULL}; execve(cmd, args, NULL); } int main() { char buf[0x28]; init(); printf("Input: "); scanf("%s", buf); return 0; } 어디서 많이 본 코드다. buf는 scanf호출 시..

보통 segmentation fault가 뜨면 core dumped도 같이 된다. segmentation fault는 잘못된 메모리 영역에 접근했다는 뜻인데... 암튼 이렇게 프로그램이 비정상적으로 종료되면 운영체제에서 친절하게도 core파일을 자동 생성해준다. 근데 왜 난 안해줌? -> 코어파일이 너무 크면 생성안됨 그럴땐 이걸 입력해주자 ↓ ulimit -c unlimited 코어파일 분석 : gdb -c core

한학기동안 많은 문제를 풀었는데 (그때 써둔 write-up보면 가관이다ㅋㅋ) 당시에는 gdb로 하는 일이라고는 plt, got주소 찾기나 checksec, elfheader정도가 전부였던 것 같다. (심지어 스택을 보는 방법도 제대로 몰랐으니 말 다했음) 암튼 디버깅이라는 gdb의 근본적인 기능을 통으로 놓치고 있던 느낌이라 종강하면 디버깅하는 방법부터 공부해야지..생각하다가 어셈블리 공부에 빠져버려서 결국 종강 1주일이 지나서야 디버깅 공부중이다...ㅎ (근데 어차피 어셈블리를 잘 봐야 디버깅도 쉽다.) 그런데 마침 드림핵 코스에서 간단한 코드로 디버깅하는게 있어서 관찰할 겸 데려와봤다. #define ull unsigned long long ull callee(ull a1, int a2, int a..