leonjza/php-nessus-ng

此软件包已被废弃,不再维护。未建议替代软件包。

PHP包装函数,用于与Nessus V6.x API接口

1.0.8 2017-02-14 09:08 UTC

This package is auto-updated.

Last update: 2023-09-14 00:51:37 UTC


README

Build Status Code Climate Latest Stable Version Total Downloads Latest Unstable Version License

PHP包装函数,用于与Nessus V6.x API接口。

如果您正在寻找支持Nessus V5.x的XMLRPC API类,请参阅这里的n5分支

信息

Nessus 6漏洞扫描器提供了一个RESTful API接口。这个库旨在成为这个API的包装器,允许您直接查询它,如API文档中详细说明。

此库的一个主要优势是,当新的端点可用时,它不一定需要更新。它只是一个包装器。可以像在本地扫描器的/api资源中找到的API参考中一样调用API。例如,如果API端点定义为

DELETE /scans/{scan_id}

然后您可以通过以下方式调用它

$client->scans($id)->via('delete');

此包装器的最新版本仅在Nessus 6.1扫描器上进行了测试。

概念

使用此库有很多方法。所有方法都以相同的方式开始;实例化一个新的实例。库将自动内部处理认证cookie。

一些调用API的示例

<?php

include 'vendor/autoload.php';

$t = new Nessus\Client('username', 'password', 'hostname.local');

现在,您可以通过方法链或通过call()方法调用API方法。
方法链示例(假设$scan_id == 5)将是

// Get a file ID for a new report export
$file_id = $t->scans($scan_id)->export()->setFields(array('format' => 'nessus'))->via('post');

使用call()方法相同

// Get a file ID for a new report export
$t->setFields(array('format' => 'nessus'));
$t->call('scans/5/export/');
$file_id = $t->via('post');

注意:所有调用都应该以via($method)结束,其中$method是要使用的HTTP方法。via()接受第二个参数,指定如果为true,则应返回原始响应,如果未设置(false),则返回解析后的JSON对象。

安装

最简单的方法是通过composer安装库。将以下行添加到您的composer.json

"leonjza/php-nessus-ng": "~1.0"

运行php composer.phar update。现在,您应该可以使用\Nessus类。

这将为您提供与Nessus V6兼容的库。如前所述,如果您需要V5兼容版本,其详细信息可在n5分支中找到。

使用示例

包含Composer自动加载器,实例化一个新的实例,并开始使用它。以下是一个示例脚本,它将下载第一个可用的.nessus格式报告

<?php

include 'vendor/autoload.php';

$t = new Nessus\Client('username', 'password', 'hostname.local');

// Get a scan_id to export a report for.
$scan_id = $t->scans()->via('get')->scans[0]->id;

// Request the export, taking note of the returned file_id that we need.
$file_id = $t->scans($scan_id)->export()->setFields(array('format' => 'nessus'))->via('post')->file;

// Set a status that will update as we poll for a status
$export_status = 'waiting';

// If the export status is ready, break.
while ($export_status != 'ready') {

    // Poll for a status update
    $export_status = $t->scans($scan_id)->export($file_id)->status()->via('get')->status;

    // Wait 1 second before another poll
    sleep(1);
}

// Get the .nessus report export, specifying that we want it via a raw get
$file = $t->scans($scan_id)->export($file_id)->download()->via('get', true);

联系

Twitter: @leonjza