aglavas/shodan-php-rest-api

该软件包最新版本(dev-master)没有可用的许可证信息。

Shodan的PHP SDK(API包装器)

dev-master 2024-05-05 18:35 UTC

This package is auto-updated.

Last update: 2024-09-05 19:19:54 UTC


README

Shodan

Shodan.io的轻量级且易于扩展的PHP API,支持免费API和付费API。请求由定义API协议的结构自动生成。

作者和许可证

Shodan-PHP-REST-API在GNU GPL v3下授权,由ISGroup SRL赞助并由Alex Salvetti和Francesco Ongaro(ascii)共同开发。该软件目前被ScadaExposure使用,ScadaExposure是一个对ICS和SCADA设备在互联网上暴露情况的永久性观测站,用于生成其数据集。

功能

  • 搜索Shodan。
  • 支持流API以实时消费Shodan数据。
  • 完全实现利用搜索API。

说明

  • Shodan.php是API类:定义常量、Shodan方法和HTTP请求的生成。
  • 该脚本使用PHP魔法方法(https://php.ac.cn/manual/en/language.oop5.magic.php)。
  • shodan-api.php是CLI接口,允许运行不同的命令;它还提供了一个如何操作的功能。
  • 我们的API实现使用3个不同的基本URL:Shodan API、流API和漏洞API。
  • 测试文件夹提供了一些如何编写自己的搜索查询、使用CLI -r标志运行所有查询或使用-t标志调用一个查询的示例。
  • 如果您需要更好的更详尽的文档,请参阅Shodan的REST API文档(https://developer.shodan.io/api)。
  • 有关Shodan EXPLOITS API的文档,请参阅文档(https://developer.shodan.io/api/exploits/rest)。
  • 有关Shodan STREAM API的文档,请参阅文档(https://developer.shodan.io/api/stream)。

用法

您可以直接在代码中实现类API或通过CLI进行实验。在两种情况下,您都需要更改shodan-api.php中的API密钥或任何实例化API对象的任何地方。

https://github.com/ScadaExposure/Shodan-PHP-REST-API/blob/master/src/shodan-api.php#L7

$key = 'Insert your API key here';

以下是一些选项

一些CLI运行示例

显示使用选项

Shodan-usage

在Facebook IP上的Shodan主机方法

Shodan-ip

在某些IP上的Shodan扫描请求

Shodan-scan

Shodan扫描请求状态

Shodan-scan-id

处理重叠方法

使用PHP魔法方法,我们通过其名称调用方法并使用它来生成请求的URL。为此,我们使用preg_replace在发现大写字母时插入/,并将该字符转换为小写。

但我们发现Shodan API中的两个方法与其他两个方法重叠,即:"ShodanScan"和"ShodanPorts"。因此,我们将"ShodanScan"重命名为"ShodanScan_Id",其中包含"id"参数,并将"ShodanPorts"重命名为流API中的"ShodanPorts_Stream"。

但URL必须不包含这些重命名,因此我们删除_及其后面的所有内容以完成任务。

您可以在以下位置找到它:https://github.com/ScadaExposure/Shodan-PHP-REST-API/blob/master/src/Shodan.php#L471

测试类 - REST API

Shodan主机(《/tests/ip.php》)

返回在给定的主机IP上找到的所有服务。

var_dump($client->ShodanHost(array(
	'ip' => '69.171.230.68', // https://#/
)));

Shodan 主机数量 (/tests/count.php)

返回与查询匹配的总结果数以及请求的任何面信息。

var_dump($client->ShodanHostCount(array(
  'query' => 'Niagara Web Server',
)));

Shodan 主机搜索 (/tests/search.php)

使用与网站相同的查询语法进行 Shodan 搜索,并使用面来获取不同属性的摘要信息。 - 此方法可能会根据使用情况使用 API 查询信用。

var_dump($client->ShodanHostSearch(array(
	'query' => 'Niagara Web Server',
)));

Shodan 主机搜索令牌 (/tests/search.php)

此方法让您确定查询字符串正在使用哪些过滤器以及提供给过滤器的参数。

var_dump($client->ShodanHostSearchTokens(array(
	'query' => 'Niagara Web Server country:"IT"',
)));

Shodan 端口 (/tests/ports.php)

此方法返回爬虫正在寻找的端口号列表。

var_dump($client->ShodanPorts());

Shodan 协议 (/tests/protocols.php)

此方法返回一个对象,包含在启动网络扫描时可以使用的所有协议。

var_dump($client->ShodanProtocols());

Shodan 扫描 (/tests/crawl.php)

使用此方法请求 Shodan 扫描网络。- 需要付费 API 密钥。

var_dump($client->ShodanScan(array(
	'ips' => '69.171.230.0/24',
)));

Shodan 扫描互联网 (/tests/crawl.php)

使用此方法请求 Shodan 扫描特定端口。 - 需要付费 API 密钥和 Shodan 许可。

var_dump($client->ShodanScanInternet(array(
	'port' => '80',
	'protocol' => 'dns-tcp',
)));

Shodan 扫描 ID (/tests/crawl.php)

检查之前提交的扫描请求的进度。

var_dump($client->ShodanScan_Id(array(
	'id' => 'R2XRT5HH6X67PFAB',
)));

Shodan 服务 (/tests/crawl.php)

此方法返回一个对象,包含 Shodan 爬虫查看的所有服务。它还可以用作快速实用的方法,将端口号解析为服务的名称。

var_dump($client->ShodanServices());

Shodan 查询 (/tests/saved_query.php)

使用此方法获取用户在 Shodan 中保存的搜索查询列表。

var_dump($client->ShodanQuery(array(
	'page' => '1', 
)));

Shodan 查询 (/tests/saved_query.php)

使用此方法搜索用户在 Shodan 中保存的搜索查询目录。

var_dump($client->ShodanQuery(array(
	'query' => 'fax',
)));

Shodan 查询标签 (/tests/query_tags.php)

使用此方法获取 Shodan 中保存的搜索查询的流行标签列表。

var_dump($client->ShodanQueryTags(array(
	'size' => '30',
)));

测试类 - 实验方法

Labs Honeyscore (/tests/honeypot.php)

计算范围从 0(不是蜜罐)到 1.0(是蜜罐)的蜜罐概率分数。

var_dump($client->LabsHoneyscore(array(
	'ip' => '54.231.184.227', // http://mushmush.org/
)));

测试类 - 利用 REST API

搜索漏洞 (/tests/exploits.php)

在多种数据源中搜索漏洞,并使用面来获取摘要信息。

var_dump($client->Search(array(
	'query' => 'cve',
)));

计数漏洞 (/tests/exploits.php)

此方法与 "/search" 方法的行为相同,不同之处在于它不返回任何结果。

var_dump($client->Count(array(
	'query' => 'cve',
)));

账户信息

此方法允许您获取 Shodan 的账户信息结果。

var_dump($client->AccountProfile());

{
    "member": true,
    "credits": 0,
    "display_name": null,
    "created": "2020-06-15T10:44:43.148000"
}

DNS 解析

查找提供的域名列表的 IP 地址,接受以逗号分隔的域名列表。

var_dump($client->DnsResolve(array(
	'hostnames' => 'google.com,bing.com', 
)));

{
    "google.com": "172.217.6.46",
    "facebook.com": "157.240.22.35"
}

DNS 反向

查找为给定以逗号分隔的 IP 地址列表定义的域名。

var_dump($client->DnsReverse(array(
	'ips' => '8.8.8.8,1.1.1.1', 
)));

{
    "8.8.8.8": [
        "dns.google"
    ],
    "1.1.1.1": [
        "one.one.one.one"
    ]
}