nitefood/asn
GitHub: nitefood/asn
一款集 ASN/BGP 分析、IP 信誉评估、威胁情报和可视化 Traceroute 于一体的 Bash 综合网络侦察工具。
Stars: 1859 | Forks: 194
步骤 1. 安装先决条件包
完整功能需要一些软件包: * **Debian 10 / Ubuntu 20.04(或更新版本):** apt -y install curl whois bind9-host mtr-tiny jq ipcalc grepcidr nmap ncat aha * **Debian 9 / Ubuntu 18.04(或更早版本):** apt -y install curl whois bind9-host mtr-tiny jq ipcalc grepcidr nmap git gcc make && \ git clone https://github.com/theZiz/aha.git && \ make install -C aha/ * **Alpine 3.19(或更新版本):** apk update && apk add bash ncurses nmap nmap-ncat mtr aha curl whois grepcidr3 coreutils ipcalc bind-tools jq * **Alpine 3.18(或更早版本):** apk update && apk add bash ncurses nmap nmap-ncat mtr aha curl whois coreutils ipcalc bind-tools jq && apk add -X https://dl-cdn.alpinelinux.org/alpine/v3.19/community grepcidr3 * **CentOS / RHEL / Rocky Linux 9:** dnf -y install epel-release && \ dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr * **CentOS / RHEL / Rocky Linux 8:** *(感谢 [Robert Scheck](https://github.com/robert-scheck))* dnf -y install epel-release 'dnf-command(copr)' && \ dnf -y copr enable robert/ipcalc && \ dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr * **CentOS / RHEL 7:** *(感谢 [Robert Scheck](https://github.com/robert-scheck))* yum -y install epel-release yum-plugin-copr && \ yum -y copr enable robert/ipcalc && \ yum -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr && \ hash -d ipcalc * **Fedora:** dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr * **openSUSE Leap 15.5(或更新版本),openSUSE Tumbleweed** zypper in -y curl whois bind-utils mtr jq nmap ncat ipcalc aha grepcidr * **FreeBSD**: env ASSUME_ALWAYS_YES=YES pkg install bash coreutils curl whois mtr jq ipcalc grepcidr nmap aha * **Windows**: * **使用 [WSL2](https://docs.microsoft.com/en-us/windows/wsl/about)(推荐):** 按照 Microsoft 的 [指南](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps) 安装 Linux 子系统(v2)。在步骤 6 中,选择上面列出的 Linux 发行版之一(推荐 Ubuntu 20.04 LTS)。 一旦您的 WSL2 系统启动并运行,请打开 Linux 终端并按照上面针对您选择的发行版的先决条件安装说明进行操作。 * **使用 [Cygwin](https://cygwin.com/index.html):** 上面列出的用于 *Debian 10 / Ubuntu 20.04(或更新版本)* 的大多数先决条件软件包可以直接通过 Cygwin 自己的安装向导(或通过 *apt-cyg* 等脚本)获得。您仍然必须手动编译(或找到合适的第三方预编译二进制文件)*mtr*、*grepcidr* 和 *aha* 工具。有关如何执行此操作的说明可以直接在各自的项目主页上找到。
步骤 2. 脚本下载和安装
之后,要将 **asn** 脚本从您的 shell 安装到 **/usr/bin**: `curl "https://raw.githubusercontent.com/nitefood/asn/master/asn" > /usr/bin/asn && chmod 0755 /usr/bin/asn`
发行版列表
* **基于 Debian 的系统:** *(感谢 [Marcos Rodrigues de Carvalho](https://github.com/odaydebian))* sudo apt update && sudo apt install asn * **Manjaro / Arch Linux:** *(感谢 [Worty](https://github.com/worty))* yay -S asn-git * **Alpine Linux:** *(感谢 [Francesco Colista](https://github.com/fcolista))* apk update && apk add asn * **NixOS** *(感谢 [devhell](https://github.com/devhell))* * 软件包位于 [此处](https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name/as/asn) * **MacOS** *(使用 [Homebrew](https://formulae.brew.sh/formula/asn),感谢 [filippovitale](https://github.com/filippovitale))* brew install asn
地理定位 API token 详细信息
单次查询(即,当不使用 `-g` 选项运行批量地理定位查询时)的首选地理定位提供商是 **ipinfo.io**。
默认情况下,该脚本使用免费(无 API key)层,每天支持多达 **1,000** 次地理定位请求。为了将此限制免费)提升到每月 **50,000** 次请求,需要一个 API key token。
要获取 API token,请先 [注册](https://ipinfo.io/signup),然后可以在您预留区域的 [token 部分](https://ipinfo.io/account/token) 找到 API token。复制后,token 应写入以下文件之一(按该顺序解析):
`$HOME/.asn/ipinfo_token` 或
`/etc/asn/ipinfo_token`
在 **服务器模式** 下运行 asn 时应使用基于 `/etc` 的文件。如果两个文件都存在,则基于 `$HOME` 的文件优先,并且非常适合 **用户模式**(即,从命令行交互式运行 `asn`)。
为此,您可以使用以下命令:
***用户模式:***
`TOKEN="
IP 信誉 API token 详细信息
该脚本将使用 [StopForumSpam](https://www.stopforumspam.com/) 执行第一级 IPv4/v6 信誉查找,如果匹配,则使用 [IPQualityScore](https://www.ipqualityscore.com/) API 对目标和追踪跃点执行第二级深度威胁分析。StopForumSpam API 是免费的,无需注册,并且该服务聚合了 [大量](https://www.stopforumspam.com/contributors) 黑名单源。
尽管如此,为了使用 IPQualityScore API 进行深度威胁报告,有必要为他们的服务 [注册](https://www.ipqualityscore.com/create-account)(这是免费的)并获取一个 API token(注册时将通过电子邮件发送给您),这将使您每月有权获得 5000 次免费查找。
获取后,api token 应写入以下文件之一(按该顺序解析):
`$HOME/.asn/iqs_token` 或
`/etc/asn/iqs_token`
在 **服务器模式** 下运行 asn 时应使用基于 `/etc` 的文件。如果两个文件都存在,则基于 `$HOME` 的文件优先,并且非常适合 **用户模式**(即,从命令行交互式运行 `asn`)。
为此,您可以使用以下命令:
***用户模式:***
`TOKEN="
Cloudflare token 详细信息
当此 token 可用时,将为 **自治系统** 目标启用额外的查找,以枚举涉及目标 ASN 的 BGP 事件(包括 **BGP 劫持** 和 **BGP 路由泄漏**)。
该脚本将使用 [Cloudflare Radar](https://radar.cloudflare.com/) API 来检索过去 12 个月内涉及目标 ASN 的事件数量。此外,它还将报告有多少事件将目标 ASN 视为 **劫持者** 或 **受害者**。
Cloudflare Radar API 是 **免费** 使用的,但需要注册。步骤如下:
1. [注册](https://dash.cloudflare.com/sign-up) 免费的 Cloudflare 帐户并 **验证您的电子邮件**
2. 从 [Cloudflare 仪表板](https://dash.cloudflare.com/profile/api-tokens/),转到 **我的个人资料 > API Tokens**。
3. 选择 **Create Token**
4. 选择 "*读取 Cloudflare Radar 数据*" 模板
5. 单击 **继续到摘要**(默认值即可)
6. 单击 **创建 token**
获取后,api token 应写入以下文件之一(按该顺序解析):
`$HOME/.asn/cloudflare_token` 或
`/etc/asn/cloudflare_token`
在 **服务器模式** 下运行 asn 时应使用基于 `/etc` 的文件。如果两个文件都存在,则基于 `$HOME` 的文件优先,并且非常适合 **用户模式**(即,从命令行交互式运行 `asn`)。
为此,您可以使用以下命令:
***用户模式:***
`TOKEN="
示例 1 - IPv4 查找
##### 命令: `asn -J 8.8.8.8` ##### 输出: ``` { "target": "8.8.8.8", "target_type": "ipv4", "result": "ok", "reason": "success", "version": "0.78.0", "request_time": "2024-08-20T02:50:28", "request_duration": 5, "api_tokens": { "ipqualityscore": true, "ipinfo": true, "cloudflare": true }, "result_count": 1, "results": [ { "ip": "8.8.8.8", "ip_version": "4", "reverse": "dns.google", "org_name": "Google LLC", "net_range": "8.8.8.0/24", "net_name": "GOGL", "abuse_contacts": [ "network-abuse@google.com" ], "routing": { "is_announced": true, "as_number": "15169", "as_name": "GOOGLE, US", "as_rank": "1788", "route": "8.8.8.0/24", "route_name": "", "roa_count": "1", "roa_validity": "valid" }, "type": { "is_bogon": false, "is_anycast": true, "is_mobile": false, "is_proxy": false, "is_dc": true, "dc_details": { "dc_name": "Google LLC" }, "is_ixp": false }, "geolocation": { "city": "Mountain View", "region": "California", "country": "United States", "cc": "US" }, "reputation": { "status": "good", "is_known_good": true, "known_as": "Google Public DNS" }, "fingerprinting": { "ports": [ 53, 443 ] } } ] } ```
示例 2 - ASN 查找
##### 命令: `asn -J 5505` ##### 输出: ``` { "target": "5505", "target_type": "asn", "result": "ok", "reason": "success", "version": "0.78.0", "request_time": "2024-08-20T02:50:46", "request_duration": 17, "api_tokens": { "ipqualityscore": true, "ipinfo": true, "cloudflare": true }, "result_count": 1, "results": [ { "asn": "5505", "asname": "VADAVO, ES", "asrank": 4448, "org": "VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM", "holder": "VADAVO SOLUCIONES SL", "abuse_contacts": [ "abuse@vadavo.com" ], "registration_date": "2016-12-13T08:28:07", "ixp_presence": [ "DE-CIX Madrid: DE-CIX Madrid Peering LAN", "ESpanix Madrid Lower LAN" ], "prefix_count_v4": 8, "prefix_count_v6": 1, "bgp_peer_count": 36, "bgp_hijack_incidents": { "total": 0, "as_hijacker": 0, "as_victim": 0 }, "bgp_leak_incidents": { "total": 0 }, "bgp_peers": { "upstream": [ "1299", "6939", "59432", "174", "34549", "25091", "35625", "33891", "48348", "13030", "8218", "41327", "3303", "4455", "6424", "6057", "34927", "9498", "35280", "1239" ], "downstream": [ "48952", "208248", "205086", "202054" ], "uncertain": [ "24482", "51185", "41047", "29680", "212483", "198150", "14840", "49544", "39384", "37721", "36236", "25160" ] }, "announced_prefixes": { "v4": [ "185.210.225.0/24", "188.130.247.0/24", "185.210.227.0/24", "185.123.205.0/24", "185.123.207.0/24", "185.210.226.0/24", "185.123.206.0/24", "185.123.204.0/24" ], "v6": [ "2a03:9320::/32" ] }, "inetnums": { "v4": [ "185.123.204.0/22", "185.210.225.0/24", "185.210.226.0/24", "185.210.227.0/24", "188.130.247.0/24" ], "v6": [ "2a03:9320::/32" ] }, "inetnums_announced_by_other_as": { "v4": [ { "prefix": "188.130.254.0/24", "origin_asn": "", "origin_org": "", "is_announced": false } ], "v6": [] } } ] } ```
示例 3 - 枚举主机名解析到的每个 IP 的滥用联系人
##### 命令: `asn -j www.google.com | jq '[.results[].abuse_contacts[]] | unique[]'` ##### 输出: ``` "network-abuse@google.com" "ripe-contact@google.com" ```
示例 4 - 枚举目标的已知漏洞
##### 命令: `asn -j 45.67.34.100 | jq '.results[].fingerprinting.vulns[]'` ##### 输出: ``` "CVE-2017-15906" "CVE-2018-15919" ```
示例 5 - 给定 IP 的上游/中转 AS 查找
##### 命令: `asn -Ju 72.17.119.201` ##### 输出: ``` { "target": "72.17.119.201", "target_type": "ipv4", "result": "ok", "reason": "success", "version": "0.78.0", "request_time": "2024-08-20T02:54:03", "request_duration": 4, "api_tokens": { "ipqualityscore": true, "ipinfo": true, "cloudflare": true }, "result_count": 1, "results": [ { "prefix": "72.17.0.0/17", "origin_as": "33363", "origin_as_name": "BHN-33363, US", "origin_as_rank": 441, "upstreams_count": 1, "upstreams": [ { "asn": "7843", "asname": "TWC-7843-BB, US", "probability": 100, "is_tier1": false } ], "multiple_upstreams": false } ] } ```
示例 6 - 枚举给定 AS 的未公告地址块
##### 命令: `asn -j AS5505 | jq -r '.results[].inetnums_announced_by_other_as.v4[] | select(.is_announced==false) | .prefix'` ##### 输出: ``` 188.130.254.0/24 ```
示例 7 - 枚举涉及给定 AS 的 BGP 劫持事件数量
##### 命令: `asn -j AS8860 | jq '.results[].bgp_hijack_incidents'` ##### 输出: ``` { "total": 18, "as_hijacker": 11, "as_victim": 7 } ```