278 | 279 | Some packages are required for full functionality: 280 | 281 | * **Debian 10 / Ubuntu 20.04 (or newer):** 282 | 283 | ``` 284 | apt -y install curl whois bind9-host mtr-tiny jq ipcalc grepcidr nmap ncat aha 285 | ``` 286 | 287 | * **Debian 9 / Ubuntu 18.04 (or older):** 288 | 289 | ``` 290 | apt -y install curl whois bind9-host mtr-tiny jq ipcalc grepcidr nmap git gcc make && \ 291 | git clone https://github.com/theZiz/aha.git && \ 292 | make install -C aha/ 293 | ``` 294 | 295 | * **CentOS / RHEL / Rocky Linux 9:** 296 | 297 | ``` 298 | dnf -y install epel-release && \ 299 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 300 | ``` 301 | 302 | * **CentOS / RHEL / Rocky Linux 8:** *(thanks [Robert Scheck](https://github.com/robert-scheck))* 303 | 304 | ``` 305 | dnf -y install epel-release 'dnf-command(copr)' && \ 306 | dnf -y copr enable robert/ipcalc && \ 307 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 308 | ``` 309 | 310 | * **CentOS / RHEL 7:** *(thanks [Robert Scheck](https://github.com/robert-scheck))* 311 | 312 | ``` 313 | yum -y install epel-release yum-plugin-copr && \ 314 | yum -y copr enable robert/ipcalc && \ 315 | yum -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr && \ 316 | hash -d ipcalc 317 | ``` 318 | 319 | * **Fedora:** 320 | 321 | ``` 322 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 323 | ``` 324 | 325 | * **openSUSE Leap 15.5 (or newer), openSUSE Tumbleweed** 326 | 327 | ``` 328 | zypper in -y curl whois bind-utils mtr jq nmap ncat ipcalc aha grepcidr 329 | ``` 330 | 331 | * **FreeBSD**: 332 | 333 | ``` 334 | env ASSUME_ALWAYS_YES=YES pkg install bash coreutils curl whois mtr jq ipcalc grepcidr nmap aha 335 | ``` 336 | 337 | * **Windows**: 338 | 339 | * **using [WSL2](https://docs.microsoft.com/en-us/windows/wsl/about) (recommended):** 340 | Install Windows Subsystem for Linux (v2) by following Microsoft's [guide](https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps). On step 6, choose one of the Linux distributions listed above (Ubuntu 20.04 LTS is recommended). 341 | Once your WSL2 system is up and running, open a Linux terminal and follow the prerequisite installation instructions above for your distribution of choice. 342 | 343 | > *Note for WSL2 users: Check [this](https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/) page for details on how to activate **systemd** if you plan to install the [asn service](#optional-installing-the-asn-server-as-a-system-service).* 344 | 345 | * **using [Cygwin](https://cygwin.com/index.html):** 346 | Most of the prerequisite packages listed above for *Debian 10 / Ubuntu 20.04 (or newer)* are obtainable directly with Cygwin's own Setup wizard (or through scripts like *apt-cyg*). You will still have to manually compile (or find a suitable third-party precompiled binary) the *mtr*, *grepcidr* and *aha* tools. Instructions on how to do so can be found directly on the respective projects homepages. 347 |
350 | 351 | Afterwards, to install the **asn** script from your shell to **/usr/bin**: 352 | 353 | `curl "https://raw.githubusercontent.com/nitefood/asn/master/asn" > /usr/bin/asn && chmod 0755 /usr/bin/asn` 354 | 355 |
364 | 365 | * **Debian-based:** *(thanks [Marcos Rodrigues de Carvalho](https://github.com/odaydebian))* 366 | > *Debian 13 / Sid*\ 367 | > *Ubuntu 24.04 (or newer)*\ 368 | > *Kali (rolling)*\ 369 | > *Raspbian (testing)* 370 | 371 | ``` 372 | sudo apt update && sudo apt install asn 373 | ``` 374 | * **Manjaro / Arch Linux:** *(thanks [Worty](https://github.com/worty))* 375 | 376 | ``` 377 | yay -S asn-git 378 | ``` 379 | 380 | * **Alpine Linux 3.18 (or newer)** *(thanks [Francesco Colista](https://github.com/fcolista))* 381 | 382 | ``` 383 | apk add -X https://dl-cdn.alpinelinux.org/alpine/v3.19/community asn 384 | ``` 385 | 386 | * **NixOS** *(thanks [devhell](https://github.com/devhell))* 387 | 388 | * Package [here](https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name/as/asn) 389 | 390 | * **MacOS** *(using [Homebrew](https://formulae.brew.sh/formula/asn), thanks [filippovitale](https://github.com/filippovitale))* 391 | 392 | ``` 393 | brew install asn 394 | ``` 395 | 396 | >*Note for MacOS users:* 397 | > 398 | > *Homebrew has a [policy](https://github.com/Homebrew/homebrew-core/issues/35085#issuecomment-447184214) not to install any binary with the **setuid** bit, and mtr (or actually, the mtr-packet helper binary that comes with it) requires to elevate to root to perform traces (good explanations for this can be found [here](https://github.com/traviscross/mtr/issues/204#issuecomment-723961118) and [here](https://github.com/traviscross/mtr/blob/master/SECURITY)). If mtr (and therefore `asn`) traces are not working on your system, you should either run `asn` as root using **sudo**, or set the proper SUID permission bit on the mtr (or better, on the mtr-packet) binary.* 399 | 400 |
447 |
448 | The geolocation provider of choice for single lookups (i.e. when not running bulk geolocation queries with the `-g` option) is **ipinfo.io**.
449 |
450 | By default, the script uses the free (no API key) tier that supports up to **1,000** geolocation requests per day. In order to boost this limit (for free) to **50,000** requests per month, an API key token is required.
451 |
452 | In order to obtain an API token, after [signing up](https://ipinfo.io/signup), the API token can be found in the [token section](https://ipinfo.io/account/token) of your reserved area. Once copied, the token should be written to one of the following files (parsed in that order):
453 |
454 | `$HOME/.asn/ipinfo_token` or
455 | `/etc/asn/ipinfo_token`
456 |
457 | The `/etc`-based file should be used when running asn in **server mode**. The `$HOME`-based file takes precedence if both files exist, and is ideal for **user mode** (that is, running `asn` interactively from the command line).
458 |
459 | In order to do so, you can use the following command:
460 |
461 | ***User mode:***
462 |
463 | `TOKEN="
476 |
477 | The script will perform first-level IPv4/v6 reputation lookups using [StopForumSpam](https://www.stopforumspam.com/), and in case of a match it will perform a second-level, in-depth threat analysis for targets and trace hops using the [IPQualityScore](https://www.ipqualityscore.com/) API. The StopForumSpam API is free and requires no sign-up, and the service aggregates a [huge](https://www.stopforumspam.com/contributors) amount of blacklist feeds.
478 |
479 | Still, in order to use the IPQualityScore API for in-depth threat reporting, it's necessary to [sign up](https://www.ipqualityscore.com/create-account) for their service (it's free) and get an API token (it will be emailed to you on sign-up), which will entitle you to 5000 free lookups per month.
480 |
481 | Once obtained, the api token should be written to one of the following files (parsed in that order):
482 |
483 | `$HOME/.asn/iqs_token` or
484 | `/etc/asn/iqs_token`
485 |
486 | The `/etc`-based file should be used when running asn in **server mode**. The `$HOME`-based file takes precedence if both files exist, and is ideal for **user mode** (that is, running `asn` interactively from the command line).
487 |
488 | In order to do so, you can use the following command:
489 |
490 | ***User mode:***
491 |
492 | `TOKEN="
508 |
509 | When this token is available, an additional lookup will be enabled for **autonomous system** targets, in order to enumerate the BGP incidents (both **BGP hijacks** and **BGP route leaks**) involving the target ASN.
510 |
511 | The script will use the [Cloudfare Radar](https://radar.cloudflare.com/) API to retrieve the amount of incidents involving the target ASN in the past 12 months. Additionally, it will report how many incidents saw the target ASN as a **hijacker** or as a **victim**.
512 |
513 | The Cloudflare Radar API is **free** to use, but requires a registration. The steps are:
514 |
515 | 1. [Sign up](https://dash.cloudflare.com/sign-up) for a free Cloudflare account and **validate your email**
516 | 2. From the [Cloudflare dashboard](https://dash.cloudflare.com/profile/api-tokens/), go to **My Profile > API Tokens**.
517 | 3. Select **Create Token**
518 | 4. Choose the "*Read Cloudflare Radar data*" template
519 | 5. Click **Continue to summary** (the default values are fine)
520 | 6. Click **Create token**
521 |
522 | Once obtained, the api token should be written to one of the following files (parsed in that order):
523 |
524 | `$HOME/.asn/cloudflare_token` or
525 | `/etc/asn/cloudflare_token`
526 |
527 | The `/etc`-based file should be used when running asn in **server mode**. The `$HOME`-based file takes precedence if both files exist, and is ideal for **user mode** (that is, running `asn` interactively from the command line).
528 |
529 | In order to do so, you can use the following command:
530 |
531 | ***User mode:***
532 |
533 | `TOKEN="
981 | 982 | ##### Command: 983 | 984 | `asn -J 8.8.8.8` 985 | 986 | ##### Output: 987 | 988 | ```json 989 | { 990 | "target": "8.8.8.8", 991 | "target_type": "ipv4", 992 | "result": "ok", 993 | "reason": "success", 994 | "version": "0.78.0", 995 | "request_time": "2024-08-20T02:50:28", 996 | "request_duration": 5, 997 | "api_tokens": { 998 | "ipqualityscore": true, 999 | "ipinfo": true, 1000 | "cloudflare": true 1001 | }, 1002 | "result_count": 1, 1003 | "results": [ 1004 | { 1005 | "ip": "8.8.8.8", 1006 | "ip_version": "4", 1007 | "reverse": "dns.google", 1008 | "org_name": "Google LLC", 1009 | "net_range": "8.8.8.0/24", 1010 | "net_name": "GOGL", 1011 | "abuse_contacts": [ 1012 | "network-abuse@google.com" 1013 | ], 1014 | "routing": { 1015 | "is_announced": true, 1016 | "as_number": "15169", 1017 | "as_name": "GOOGLE, US", 1018 | "as_rank": "1788", 1019 | "route": "8.8.8.0/24", 1020 | "route_name": "", 1021 | "roa_count": "1", 1022 | "roa_validity": "valid" 1023 | }, 1024 | "type": { 1025 | "is_bogon": false, 1026 | "is_anycast": true, 1027 | "is_mobile": false, 1028 | "is_proxy": false, 1029 | "is_dc": true, 1030 | "dc_details": { 1031 | "dc_name": "Google LLC" 1032 | }, 1033 | "is_ixp": false 1034 | }, 1035 | "geolocation": { 1036 | "city": "Mountain View", 1037 | "region": "California", 1038 | "country": "United States", 1039 | "cc": "US" 1040 | }, 1041 | "reputation": { 1042 | "status": "good", 1043 | "is_known_good": true, 1044 | "known_as": "Google Public DNS" 1045 | }, 1046 | "fingerprinting": { 1047 | "ports": [ 1048 | 53, 1049 | 443 1050 | ] 1051 | } 1052 | } 1053 | ] 1054 | } 1055 | ``` 1056 |
1058 | 1059 | ##### Command: 1060 | 1061 | `asn -J 5505` 1062 | 1063 | ##### Output: 1064 | 1065 | ```json 1066 | { 1067 | "target": "5505", 1068 | "target_type": "asn", 1069 | "result": "ok", 1070 | "reason": "success", 1071 | "version": "0.78.0", 1072 | "request_time": "2024-08-20T02:50:46", 1073 | "request_duration": 17, 1074 | "api_tokens": { 1075 | "ipqualityscore": true, 1076 | "ipinfo": true, 1077 | "cloudflare": true 1078 | }, 1079 | "result_count": 1, 1080 | "results": [ 1081 | { 1082 | "asn": "5505", 1083 | "asname": "VADAVO, ES", 1084 | "asrank": 4448, 1085 | "org": "VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM", 1086 | "holder": "VADAVO SOLUCIONES SL", 1087 | "abuse_contacts": [ 1088 | "abuse@vadavo.com" 1089 | ], 1090 | "registration_date": "2016-12-13T08:28:07", 1091 | "ixp_presence": [ 1092 | "DE-CIX Madrid: DE-CIX Madrid Peering LAN", 1093 | "ESpanix Madrid Lower LAN" 1094 | ], 1095 | "prefix_count_v4": 8, 1096 | "prefix_count_v6": 1, 1097 | "bgp_peer_count": 36, 1098 | "bgp_hijack_incidents": { 1099 | "total": 0, 1100 | "as_hijacker": 0, 1101 | "as_victim": 0 1102 | }, 1103 | "bgp_leak_incidents": { 1104 | "total": 0 1105 | }, 1106 | "bgp_peers": { 1107 | "upstream": [ 1108 | "1299", 1109 | "6939", 1110 | "59432", 1111 | "174", 1112 | "34549", 1113 | "25091", 1114 | "35625", 1115 | "33891", 1116 | "48348", 1117 | "13030", 1118 | "8218", 1119 | "41327", 1120 | "3303", 1121 | "4455", 1122 | "6424", 1123 | "6057", 1124 | "34927", 1125 | "9498", 1126 | "35280", 1127 | "1239" 1128 | ], 1129 | "downstream": [ 1130 | "48952", 1131 | "208248", 1132 | "205086", 1133 | "202054" 1134 | ], 1135 | "uncertain": [ 1136 | "24482", 1137 | "51185", 1138 | "41047", 1139 | "29680", 1140 | "212483", 1141 | "198150", 1142 | "14840", 1143 | "49544", 1144 | "39384", 1145 | "37721", 1146 | "36236", 1147 | "25160" 1148 | ] 1149 | }, 1150 | "announced_prefixes": { 1151 | "v4": [ 1152 | "185.210.225.0/24", 1153 | "188.130.247.0/24", 1154 | "185.210.227.0/24", 1155 | "185.123.205.0/24", 1156 | "185.123.207.0/24", 1157 | "185.210.226.0/24", 1158 | "185.123.206.0/24", 1159 | "185.123.204.0/24" 1160 | ], 1161 | "v6": [ 1162 | "2a03:9320::/32" 1163 | ] 1164 | }, 1165 | "inetnums": { 1166 | "v4": [ 1167 | "185.123.204.0/22", 1168 | "185.210.225.0/24", 1169 | "185.210.226.0/24", 1170 | "185.210.227.0/24", 1171 | "188.130.247.0/24" 1172 | ], 1173 | "v6": [ 1174 | "2a03:9320::/32" 1175 | ] 1176 | }, 1177 | "inetnums_announced_by_other_as": { 1178 | "v4": [ 1179 | { 1180 | "prefix": "188.130.254.0/24", 1181 | "origin_asn": "", 1182 | "origin_org": "", 1183 | "is_announced": false 1184 | } 1185 | ], 1186 | "v6": [] 1187 | } 1188 | } 1189 | ] 1190 | } 1191 | ``` 1192 | 1193 |
1195 | 1196 | ##### Command: 1197 | 1198 | `asn -j www.google.com | jq '[.results[].abuse_contacts[]] | unique[]'` 1199 | 1200 | ##### Output: 1201 | 1202 | ``` 1203 | "network-abuse@google.com" 1204 | "ripe-contact@google.com" 1205 | ``` 1206 | 1207 |
1209 | 1210 | ##### Command: 1211 | 1212 | `asn -j 45.67.34.100 | jq '.results[].fingerprinting.vulns[]'` 1213 | 1214 | ##### Output: 1215 | ``` 1216 | "CVE-2017-15906" 1217 | "CVE-2018-15919" 1218 | ``` 1219 | 1220 |
1222 | 1223 | ##### Command: 1224 | 1225 | `asn -Ju 72.17.119.201` 1226 | 1227 | ##### Output: 1228 | 1229 | ```json 1230 | { 1231 | "target": "72.17.119.201", 1232 | "target_type": "ipv4", 1233 | "result": "ok", 1234 | "reason": "success", 1235 | "version": "0.78.0", 1236 | "request_time": "2024-08-20T02:54:03", 1237 | "request_duration": 4, 1238 | "api_tokens": { 1239 | "ipqualityscore": true, 1240 | "ipinfo": true, 1241 | "cloudflare": true 1242 | }, 1243 | "result_count": 1, 1244 | "results": [ 1245 | { 1246 | "prefix": "72.17.0.0/17", 1247 | "origin_as": "33363", 1248 | "origin_as_name": "BHN-33363, US", 1249 | "origin_as_rank": 441, 1250 | "upstreams_count": 1, 1251 | "upstreams": [ 1252 | { 1253 | "asn": "7843", 1254 | "asname": "TWC-7843-BB, US", 1255 | "probability": 100, 1256 | "is_tier1": false 1257 | } 1258 | ], 1259 | "multiple_upstreams": false 1260 | } 1261 | ] 1262 | } 1263 | ``` 1264 | 1265 |
1267 | 1268 | ##### Command: 1269 | 1270 | `asn -j AS5505 | jq -r '.results[].inetnums_announced_by_other_as.v4[] | select(.is_announced==false) | .prefix'` 1271 | 1272 | ##### Output: 1273 | 1274 | ``` 1275 | 188.130.254.0/24 1276 | ``` 1277 | 1278 |
1280 | 1281 | ##### Command: 1282 | 1283 | `asn -j AS8860 | jq '.results[].bgp_hijack_incidents'` 1284 | 1285 | ##### Output: 1286 | 1287 | ``` 1288 | { 1289 | "total": 18, 1290 | "as_hijacker": 11, 1291 | "as_victim": 7 1292 | } 1293 | ``` 1294 | 1295 |