基于 Laravel 5 的网络拓扑映射器。

v1.2 2017-11-14 10:20 UTC

This package is not auto-updated.

Last update: 2024-09-27 10:48:17 UTC


README

基于 Laravel 5 的网络拓扑映射器。此包对输入的主机和网络运行 Nmap 扫描,解析并使用提取的值填充数据库。首先,您必须将服务提供者添加到您的 app.php 配置文件中。

'providers' => [
    ...
    Ntcm\Ntm\NtmServiceProvider::class
    ...
]

然后,您必须发布配置文件。这将把 ntm.php 配置文件复制到您的配置目录中。

$ php artisan vendor:publish

在执行迁移之前,您可以在配置目录中的 ntm.php 文件中自定义您的表名。如果没有配置文件,默认情况下所有表都以前缀 mapper_ 开头。之后进行数据库迁移。

$ php artisan migrate

现在您可以运行以下扫描

use Ntcm\Ntm\Ntm;

$targets = 'scanme.nmap.org';

Ntm::create()
   ->setTimeout(60) // in seconds...
   ->scan($targets)
   ->parseOutputFile();

这将扫描 1.xml 文件内的主机,并将解析的信息存储到数据库中,其中 scan_id = 1。您也可以输入如下所示的数组形式的目标

$targets = ['scanme.nmap.org', '192.168.101.0/24'];

Ntm::create()
   ->setTimeout(60)
   ->scan($targets)
   ->parseOutputFile();

此外,您还可以启用/禁用不同的扫描属性。以下是属性的默认值。

$targets = ['scanme.nmap.org', '192.168.101.0/24'];

Ntm::create()
   ->setTimeout(60)
   ->scan($targets)
   ->setTraceroute(true)
   ->setReverseDns(true)
   ->setPortScan(true)
   ->setOsDetection(true)
   ->setServiceInfo(true)
   ->setVerbose(false)
   ->setTreatHostsAsOnline(true)
   ->parseOutputFile();

扫描命令

您可以使用 ScanCommand 类运行扫描,如下所示

$targets = ['scanme.nmap.org', '192.168.101.0/24'];

// call scan artisan command...
Artisan::call('scan', [
  'targets'     => $targets,
  '--os'        => true, // to enable operating system scan...
  '--ports'     => true, // to enable well-known TCP ports...
  '--scheduled' => '0 1,13 * * * *' // you can use this to schedule the scan...
]);

计划扫描

您可以通过将以下代码添加到您的 App\Console\Kernel 类的 schedule 方法中来安排扫描。

    /**
     * Define the application's command schedule.
     *
     * @param Schedule $schedule
     *
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        foreach(Target::scheduled()->get() as $target) {
            $schedule
                ->command('scan', [
                    'ranges'  => $target->range,
                    '--os'    => $target->ports,
                    '--ports' => $target->os,
                ])
                ->cron($target->scheduled);
        }
    }