[LOB] giant -> assassin

Posted by dw0rdptr
2015. 4. 14. 17:22 System/LOB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
        The Lord of the BOF : The Fellowship of the BOF
        - assassin
        - no stack, no RTL
*/
 
#include <stdio.h>
#include <stdlib.h>
 
main(int argc, char *argv[])
{
    char buffer[40];
 
    if(argc < 2){
        printf("argv error\n");
        exit(0);
    }
 
    if(argv[1][47== '\xbf')
    {
        printf("stack retbayed you!\n");
        exit(0);
    }
 
    if(argv[1][47== '\x40')
    {
        printf("library retbayed you, too!!\n");
        exit(0);
    }
 
    strcpy(buffer, argv[1]); 
    printf("%s\n", buffer);
 
    // buffer+sfp hunter
    memset(buffer, 044);
}
cs

no stack, no RTL로 ret에 스택과 공유라이브러리 주소를 쓰지 못하게 됐다


하지만 ret에 ret주소를 덮게되면 esp+4에 있는 주소를 실행해 우회할 수 있다.

[ret주소][system()주소][dummy]["/bin/sh"] 이렇게 페이로드를구성한다면


higher address

----------

   /bin/sh

----------

   dummy

----------

    system

------------

       ret

------------  <- esp

lower address

ret가 pop eip, jmp eip 명령을 수행한다는것은 알고 있을것이다.

pop eip를 할 때 eip에 ret주소가 들어가고 jmp eip를하면 ret로 돌아오지만 esp는 pop명령으로 인해 +4가 되어 있는 상태다


higher address

----------

   /bin/sh

----------

   dummy

----------

    system

------------ <- esp

       ret

------------  

lower address


현재 ret주소로 다시 돌아왔으니 ret명령이 또한번 수행된다

pop eip, jmp eip를 수행하면 eip에는 system함수의 주소가 들어가고, jmp로 system함수를 실행해 /bin/sh가 실행된다



gdb로 main함수에서 ret주소를 찾자

ret : 0x804851f

system() : 0x40058ae0

/bin/sh : 0x400fbff9

system함수와 /bin/sh를 구하는 방법은 전레벨에서 설명이 되어있으니 건너뛰겠다



페이로드와 Password


'System > LOB' 카테고리의 다른 글

[LOB] zombie_assassin -> succubus  (0) 2015.04.30
[LOB] assassin -> zombie_assassin  (0) 2015.04.18
[LOB] bugbear -> giant  (2) 2015.04.14
[LOB] darkknight -> bugbear  (0) 2015.04.12
[LOB] golem -> darkknight  (0) 2015.04.11