自定义FTP扫描模块

一、代码实现

复制代码
class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::Ftp include Msf::Auxiliary::Scanner include Msf::Auxiliary::Report
  def initialize
    super(
      'Name' => 'FTP Version test Scanner',
      'Description' => 'Detect FTP Version.',
      'Author' => 'z9m8r8',
      'License' => MSF_LICENSE
    )
    register_options(
      [
        Opt::RPORT(21),
      ],self.class
    )
  end

  def run_host(target_host)
    connect(true,false)
    if(banner)
      print_status("#{rhost} is running #{banner}")
      report_service(:host => rhost,:port=>rport,:name=>"ftp",:info=>banner)
    end
    disconnect
  end
end
复制代码

二、代码解析

  • required 'msf/core'

语句required 'msf/core',引入core库。

该方法适用于metasploit 的早期版本,但最新的版本不需要单独定义引入core库

实践时反馈的问题,声明类类型为Metasploit3 时,总是报initialize未初始化,但实际已定义initialize并初始化了,将Metasploit3用MetasploitModule代替即可正常运行(备注,真正的问题出在哪里,自己并未解决)

  • 库文件介绍

  引入语句                             路 径                                             用 途

Msf:Exploit::Remote::Ftp /lib/msf/core/exploit/ftp.rb 包含了所有FTP操作相关的方法,比如建立FTP连接、 FTP服务登录、发送FTP命令等

Msf::Auxiliary::Scanner /lib/msf/core/auxiliary/scanner.rb 包含了各种扫描模块要使用的函数,提供了很多方法,例如模块运行、初始化以及进度扫描等

Msf::Auxiliary::Report /lib/msf/core/auxiliary/report.rb 包含了所有报告函数,这些函数可以将正在运行的模块中的数据存储到数据库中

  • 函数介绍

  函 数                            库 文 件            用 途

run_host /lib/msf/core/auxiliary/scanner.rb 对每台主机运行一次的主要方法

connect /lib/msf/core/exploit/ftp.rb 负责与主机建立一个连接并抓取banner,然后自动将这个banner保存到变量中

向connect函数提供两个参数: true和false。参数true定义了全局参数的使用,而false定义关闭模块的详细功能

函数connect的优点在于它能自动连接目标,以及自动将FTP服务的标识保存到名为banner的参数,

report_service /lib/msf/core/auxiliary/report.rb 专门用于将服务和相关细节添加到数据库中

函数report_service,将扫描数据保存在数据库中以供之后使用或者生成高级报告

  • 保存位置

/usr/share/metasploit-framework/modules/auxiliary/scanner/ftp/ftp_test.rb
  • 调试检查语法错误

使用msftidy调试方法

root@kali:/usr/share/metasploit-framework/modules/exploits/windows/wins# /usr/share/metasploit-framework/tools/dev/msftidy.rb test.rb

由于实践时msftidy总出错,故是直接通过msfconsole加载失败查看日志改正的,如下

root@promote:/usr/share/metasploit-framework/tools/dev# msfconsole
[!] The following modules could not be loaded!..|
[!] /usr/share/metasploit-framework/modules/auxiliary/scanner/ftp/ftp_test.rb
[!] Please see /root/.msf4/logs/framework.log for details.

打开日志,依据提示进行修改,并重新加载即可

三、msf 中测试

复制代码
msf6 > use auxiliary/scanner/ftp/ftp_test
msf6 auxiliary(scanner/ftp/ftp_test) > show options

Module options (auxiliary/scanner/ftp/ftp_test):
Name Current Setting Required Description
---- --------------- -------- -----------
FTPPASS mozilla@example.com no The password for the specified username
FTPUSER anonymous no The username to authenticate as
RHOSTS 10.10.10.134 yes The target host(s), range CIDR identifier
, or hosts file with syntax 'file:<path>'
RPORT 21 yes The target port (TCP)
THREADS 10 yes The number of concurrent threads (max one
per host)

msf6 auxiliary(scanner/ftp/ftp_test) > set rhosts 10.10.10.129
rhosts => 10.10.10.129
msf6 auxiliary(scanner/ftp/ftp_test) > run

[*] 10.10.10.129:21 - 10.10.10.129 is running 220 (vsFTPd 2.2.2)

[*] 10.10.10.129:21 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf6 auxiliary(scanner/ftp/ftp_test) > services
Services
========

host port proto name state info
---- ---- ----- ---- ----- ----
10.10.10.129 21 tcp ftp open 220 (vsFTPd 2.2.2)
复制代码

四、参考文献

《精通Metasploit渗透测试》

posted @   z9m8r8  阅读(40)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示