首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >网络空间安全之一个WH的超前沿全栈技术深入学习之路(13-1)白帽必经之路——Metasploit 渗透测试框架

网络空间安全之一个WH的超前沿全栈技术深入学习之路(13-1)白帽必经之路——Metasploit 渗透测试框架

作者头像
盛透侧视攻城狮
发布2025-05-19 18:44:00
发布2025-05-19 18:44:00
21900
代码可运行
举报
运行总次数:0
代码可运行

1.Metasploit 渗透测试框架介绍

1.2Metasploit 体系框架

  • 1、基础库:metasploit 基础库文件位于源码根目录路径下的 libraries 目录中,包括Rex,framework-core 和 framework-base 三部分。
  • Rex 是整个框架所依赖的最基础的一些组件,如包装的网络套接字、网络应用协议客户端与服务端实现、日志子系统、渗透攻击支持例程、PostgreSQL 以及 MySQL 数据库支持等;
  • framework-core 库负责实现所有与各种类型的上层模块及插件的交互接口;
  • framework-base 库扩展了 framework-core,提供更加简单的包装例程,并为处理框架各个方面的功能提供了一些功能类,用于支持用户接口与功能程序调用框架本身功能及框架集成模块;
  • 2、模块:模块组织按照不同的用途分为 6 种类型的模块(Modules): 分为辅助模块(Aux)、渗透攻击模块(Exploits)、后渗透攻击模块(Post)、攻击载荷模块(payloads)、编码器模块(Encoders)、空指令模块(Nops)。
  • 注:payload 又称为攻击载荷,主要是用来建立目标机与攻击机稳定连接的,可返回 shell,也可以进行程序注入等。
  • 3、插件:插件能够扩充框架的功能,或者组装已有功能构成高级特性的组件。插件可以集成现有的一些外部安全工具,如 Nessus、OpenVAS 漏洞扫描器等,为用户接口提供一些新的功能。
  • 4、接口:包括 msfconsole 控制终端、msfcli 命令行、msfgui 图形化界面、armitage 图形化界面以及 msfapi 远程调用接口。
  • 5、功能程序: metasploit 还提供了一系列可直接运行的功能程序,支持渗透测试者与安全人员快速地利用 metasploit 框架内部能力完成一些特定任务。比如 msfpayload、msfencode 和msfvenom 可以将攻击载荷封装为可执行文件、C 语言、JavaScript 语言等多种形式,并可以进行各种类型的编码。

2 Metasploitable2-Linux 靶机系统介绍

2.2 Metasploitable2 安装

使用 VMware 打开新的虚拟机
选择解压出来的.vmx 文件
修改靶机的网络配置
选择桥接模式
开启虚拟机

使用普通用户:msfadmin 密码: msfadmin 进行登录

修改 root 用户密码
代码语言:javascript
代码运行次数:0
运行
复制
msfadmin@metasploitable:~$ sudo passwd root
[sudo] password for msfadmin:msfadmin #注:需要提权输入 msfadmin 用户的密码
设置新密码
代码语言:javascript
代码运行次数:0
运行
复制
Enter new UNIX password: 123456
Retype new UNIX password: 123456
passwd: password updated successfully
切换到 root 用户
代码语言:javascript
代码运行次数:0
运行
复制
msfadmin@metasploitable:~$ su root
Password:123456

注:靶机中直接使用 vim 命令对文件修改即可
代码语言:javascript
代码运行次数:0
运行
复制
root@metasploitable:/home/msfadmin# vim /etc/network/interfaces #修改 eth0 配置
如下
auto eth0
iface eth0 inet static
address 192.168.1.180
netmask 255.255.255.0
gateway 192.168.1.1
:wq 保存退出
root@metasploitable:/home/msfadmin# /etc/init.d/networking restart
* Reconfiguring network interfaces...
root@metasploitable:/home/msfadmin# ifconfig
修改完成后创建一个快照以便我们后期对操作系统造成破坏。

3 Metasploit 基本使用方法

  • Metasploit 基本命令
  • Metasploit 程序需要使用 Postgresql 数据库。
  • 注:PostgreSQL:世界上最先进的开源关系数据库
手动启动数据库

代码语言:javascript
代码运行次数:0
运行
复制
root@xuegod53:~# systemctl start postgresql
root@xuegod53:~# systemctl enable postgresql #设置成开机启动数据库,我们要经常用

启动 Metasploit,启动方式有两种。

第一种点击图标
注意:

  • 每次弹出的欢迎信息都是随机的。这次我弹出的提示欢迎是一只兔子。
第二种使用终端命令
注意:

  • 第一次启动程序会是初始化应用程序。
代码语言:javascript
代码运行次数:0
运行
复制
┌──(root㉿kali-2024)-[/home/ljs/Desktop]
└─# msfconsole                       
Metasploit tip: Use the resource command to run commands from a file
                                                  

      .:okOOOkdc'           'cdkOOOko:.
    .xOOOOOOOOOOOOc       cOOOOOOOOOOOOx.
   :OOOOOOOOOOOOOOOk,   ,kOOOOOOOOOOOOOOO:
  'OOOOOOOOOkkkkOOOOO: :OOOOOOOOOOOOOOOOOO'
  oOOOOOOOO.    .oOOOOoOOOOl.    ,OOOOOOOOo
  dOOOOOOOO.      .cOOOOOc.      ,OOOOOOOOx
  lOOOOOOOO.         ;d;         ,OOOOOOOOl
  .OOOOOOOO.   .;           ;    ,OOOOOOOO.
   cOOOOOOO.   .OOc.     'oOO.   ,OOOOOOOc
    oOOOOOO.   .OOOO.   :OOOO.   ,OOOOOOo
     lOOOOO.   .OOOO.   :OOOO.   ,OOOOOl
      ;OOOO'   .OOOO.   :OOOO.   ;OOOO;
       .dOOo   .OOOOocccxOOOO.   xOOd.
         ,kOl  .OOOOOOOOOOOOO. .dOk,
           :kk;.OOOOOOOOOOOOO.cOk:
             ;kOOOOOOOOOOOOOOOk:
               ,xOOOOOOOOOOOx,
                 .lOOOOOOOl.
                    ,dOd,
                      .                                                      

       =[ metasploit v6.3.55-dev                          ]
+ -- --=[ 2397 exploits - 1232 auxiliary - 422 post       ]
+ -- --=[ 1391 payloads - 46 encoders - 11 nops           ]
+ -- --=[ 9 evasion                                       ]

Metasploit Documentation: https://docs.metasploit.com/

  • 启动完成后会有一些统计信息,比如说版本号,有多少个 exploits,多少个 payloads 等。
查看帮助信息。
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > help 
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > help                                                                            
                                                                                       
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                                              
    debug         Display information useful for debugging                             
    exit          Exit the console                                                     
    features      Display the list of not yet released features that can be opted in to    
    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                                                     
    load          Load a framework plugin
    quit          Exit the console
    repeat        Repeat a list of commands
    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
    tips          Show a list of useful productivity tips
    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
    clearm        Clear the module stack
    favorite      Add module(s) to the list of favorite modules
    favorites     Print the list of favorite modules (alias for `show favorites`)
    info          Displays information about one or more modules
    listm         List the module stack
    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           Interact with a module by name or search term/index


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
    -------       -----------
    analyze       Analyze database information about a specific address or address range
    db_connect    Connect to an existing data service
    db_disconnec  Disconnect from the current data service
    t
    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_c  Rebuilds the database-stored module cache (deprecated)
    ache
    db_remove     Remove the saved data service entry
    db_save       Save the current data service connection as the default to reconnect on
                   startup
    db_stats      Show statistics for the database
    db_status     Show the current data service status
    hosts         List all hosts in the database
    klist         List Kerberos tickets 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


Developer Commands
==================

    Command       Description
    -------       -----------
    edit          Edit the current module or a file with the preferred editor
    irb           Open an interactive Ruby shell in the current context
    log           Display framework.log paged to the end if possible
    pry           Open the Pry debugger on the current module or Framework
    reload_lib    Reload Ruby library files from specified paths
    time          Time how long it takes to run a particular command


msfconsole
==========

`msfconsole` is the primary interface to Metasploit Framework. There is quite a
lot that needs go here, please be patient and keep an eye on this space!

Building ranges and lists
-------------------------

Many commands and options that take a list of things can use ranges to avoid
having to manually list each desired thing. All ranges are inclusive.

### Ranges of IDs

Commands that take a list of IDs can use ranges to help. Individual IDs must be
separated by a `,` (no space allowed) and ranges can be expressed with either
`-` or `..`.

### Ranges of IPs

There are several ways to specify ranges of IP addresses that can be mixed
together. The first way is a list of IPs separated by just a ` ` (ASCII space),
with an optional `,`. The next way is two complete IP addresses in the form of
`BEGINNING_ADDRESS-END_ADDRESS` like `127.0.1.44-127.0.2.33`. CIDR
specifications may also be used, however the whole address must be given to
Metasploit like `127.0.0.0/8` and not `127/8`, contrary to the RFC.
Additionally, a netmask can be used in conjunction with a domain name to
dynamically resolve which block to target. All these methods work for both IPv4
and IPv6 addresses. IPv4 addresses can also be specified with special octet
ranges from the [NMAP target
specification](https://nmap.org/book/man-target-specification.html)

### Examples

Terminate the first sessions:

    sessions -k 1

Stop some extra running jobs:

    jobs -k 2-6,7,8,11..15

Check a set of IP addresses:

    check 127.168.0.0/16, 127.0.0-2.1-4,15 127.0.0.255

Target a set of IPv6 hosts:

    set RHOSTS fe80::3990:0000/110, ::1-::f0f0

Target a block from a resolved domain name:

    set RHOSTS www.example.test/24
msf6 > 
注意:

  • Core Commands #核心命令
  • Module Commands #模块命令
  • Job Commands #后台任务命令
  • Resource Script Commands #资源脚本命令
  • Database Backend Commands #数据库后端命令
  • Credentials Backend Commands #证书/凭证后端命令
  • Developer Commands #开发人员命令

3.2MS常用的命令详解

核心命令中的 connect 命令

  • connect 命令主要用于远程连接主机。一般用于内网渗透。比较常用的命令就是“connect
  • 192.168.1.1 80”
  • 192.168.1.1 是 IP 地址 80 是端口号。
  • 查看 connect 命令参数:
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > connect 
Usage: connect [options] <host> <port>

Communicate with a host, similar to interacting via netcat, taking advantage of
any configured session pivoting.

OPTIONS:

    -c, --comm <comm>               Specify which Comm to use.
    -C, --crlf                      Try to use CRLF for EOL sequence.
    -h, --help                      Help banner.
    -i, --send-contents <file>      Send the contents of a file.
    -p, --proxies <proxies>         List of proxies to use.
    -P, --source-port <port>        Specify source port.
    -S, --source-address <address>  Specify source address.
    -s, --ssl                       Connect with SSL.
    -u, --udp                       Switch to a UDP socket.
    -w, --timeout <seconds>         Specify connect timeout.
    -z, --try-connection            Just try to connect, then return.
msf6 > 
连接目标端口
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > connect  www.huawei.com 80   #连接上后在另一行,直接输入 get /
[*] Connected to www.huawei.com:80 (via: 192.168.79.135:33673)



/get   #提交一个 get 请求,可以查看到服务器版本号
HTTP/1.1 400 Bad Request
Server: openresty
Date: Wed, 27 Nov 2024 14:17:46 GMT
Content-Type: text/html
Content-Length: 154
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>
msf6 > 
MS模块中show 使用方法

  • show 命令用的很多。
  • “show”命令的有效参数是:all, encoders, nops, exploits, payloads, auxiliary, post, plugins, info, options
示例1:列出 metasploit 框架中的所有渗透攻击模块 exploits。
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > show exploits   #列出 metasploit 框架中的所有渗透攻击模块。该命令列出数据较多,较为耗费时间。
示例2:列出 metasploit 框架中的所有攻击载荷。
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > show payloads 
示例3:列出 metasploit 框架中的所有辅助攻击载荷。
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > show auxiliary 

4.MS模块命令 之search 搜索的使用方法

  • 当你使用 msfconsole 的时候,你会用到各种漏洞模块、各种插件等等。
  • 所以 search 搜索命令就很重要。
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > show auxiliary 

Usage: search [ options ] <keywords> #search 后主要加选项和关键字

示例1:通过 name 关键字进行查找

代码语言:javascript
代码运行次数:0
运行
复制
msf6 > search  mysql

  • search 后直接跟要查找内容,查得很广泛。只有当你对漏洞名字很描述很清楚时,使用这个方法
比如说想找ms08_067 漏洞模块
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > search  ms08_067
或者说我想找 mysql 数据库的漏洞
语法:
代码语言:javascript
代码运行次数:0
运行
复制
Search Keywords 参数:关键字

  • 每列的含意是:
  • Name Disclosure Date Rank Check Description
  • 名称 披露 日期 排名 检查 说明

示例2:通过路径进行查找

  • 有时候,我们只记得模块的路径,但是却忘记了模块的名称。
  • 那么就可以用 path:命令查找在该路径下的所有模块。如果我要 mysql 路径下的所有 mysql 利用模块,那么就可以输入如下示例命令
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > search path:mysql

示例3:缩小查询范围
代码语言:javascript
代码运行次数:0
运行
复制
msf6 > search platform:mysql

  • 关键字:platform [ˈplætfɔːm] 平台
  • 作用: Modules affecting this platform 即:列出可以影响此平台的模块,也就是比较好的漏洞有时候我们会搜索到大量的模块
  • 那么可以用 platform:命令来缩小查询范围。使用 platform 命令后,所查询的结果会列出 rank 比较高的模块。
  • 如果我要查找 mysql 的漏洞,那么可以输入如下示例命令:

注意:

  • 可以对比一下上面的截图,发现所有 rank 为 normal 的模块全部都屏蔽了,只剩下几个比较高级的利用模块。
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-11-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.Metasploit 渗透测试框架介绍
    • 1.2Metasploit 体系框架
  • 2 Metasploitable2-Linux 靶机系统介绍
    • 2.2 Metasploitable2 安装
      • 使用 VMware 打开新的虚拟机
      • 选择解压出来的.vmx 文件
      • 修改靶机的网络配置
      • 选择桥接模式
      • 开启虚拟机
      • 修改 root 用户密码
      • 设置新密码
      • 切换到 root 用户
      • 注:靶机中直接使用 vim 命令对文件修改即可
      • 修改完成后创建一个快照以便我们后期对操作系统造成破坏。
  • 3 Metasploit 基本使用方法
    • 手动启动数据库
    • 启动 Metasploit,启动方式有两种。
      • 第一种点击图标
      • 注意:
      • 第二种使用终端命令
      • 注意:
      • 查看帮助信息。
      • 注意:
    • 3.2MS常用的命令详解
      • 核心命令中的 connect 命令
      • 连接目标端口
      • MS模块中show 使用方法
      • 示例2:列出 metasploit 框架中的所有攻击载荷。
      • 示例3:列出 metasploit 框架中的所有辅助攻击载荷。
  • 4.MS模块命令 之search 搜索的使用方法
    • 示例1:通过 name 关键字进行查找
      • 比如说想找ms08_067 漏洞模块
      • 或者说我想找 mysql 数据库的漏洞
    • 示例2:通过路径进行查找
      • 示例3:缩小查询范围
      • 注意:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档