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 | * **Alpine 3.19 (or newer):** 296 | 297 | ``` 298 | apk update && apk add bash ncurses nmap nmap-ncat mtr aha curl whois grepcidr3 coreutils ipcalc bind-tools jq 299 | ``` 300 | 301 | * **Alpine 3.18 (or older):** 302 | 303 | ``` 304 | 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 305 | ``` 306 | 307 | * **CentOS / RHEL / Rocky Linux 9:** 308 | 309 | ``` 310 | dnf -y install epel-release && \ 311 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 312 | ``` 313 | 314 | * **CentOS / RHEL / Rocky Linux 8:** *(thanks [Robert Scheck](https://github.com/robert-scheck))* 315 | 316 | ``` 317 | dnf -y install epel-release 'dnf-command(copr)' && \ 318 | dnf -y copr enable robert/ipcalc && \ 319 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 320 | ``` 321 | 322 | * **CentOS / RHEL 7:** *(thanks [Robert Scheck](https://github.com/robert-scheck))* 323 | 324 | ``` 325 | yum -y install epel-release yum-plugin-copr && \ 326 | yum -y copr enable robert/ipcalc && \ 327 | yum -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr && \ 328 | hash -d ipcalc 329 | ``` 330 | 331 | * **Fedora:** 332 | 333 | ``` 334 | dnf -y install curl whois bind-utils mtr jq nmap nmap-ncat ipcalc aha grepcidr 335 | ``` 336 | 337 | * **openSUSE Leap 15.5 (or newer), openSUSE Tumbleweed** 338 | 339 | ``` 340 | zypper in -y curl whois bind-utils mtr jq nmap ncat ipcalc aha grepcidr 341 | ``` 342 | 343 | * **FreeBSD**: 344 | 345 | ``` 346 | env ASSUME_ALWAYS_YES=YES pkg install bash coreutils curl whois mtr jq ipcalc grepcidr nmap aha 347 | ``` 348 | 349 | * **Windows**: 350 | 351 | * **using [WSL2](https://docs.microsoft.com/en-us/windows/wsl/about) (recommended):** 352 | 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). 353 | Once your WSL2 system is up and running, open a Linux terminal and follow the prerequisite installation instructions above for your distribution of choice. 354 | 355 | > *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).* 356 | 357 | * **using [Cygwin](https://cygwin.com/index.html):** 358 | 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. 359 |
362 | 363 | Afterwards, to install the **asn** script from your shell to **/usr/bin**: 364 | 365 | `curl "https://raw.githubusercontent.com/nitefood/asn/master/asn" > /usr/bin/asn && chmod 0755 /usr/bin/asn` 366 | 367 |
376 | 377 | * **Debian-based:** *(thanks [Marcos Rodrigues de Carvalho](https://github.com/odaydebian))* 378 | > *Debian 13 / Sid*\ 379 | > *Ubuntu 24.04 (or newer)*\ 380 | > *Kali (rolling)*\ 381 | > *Raspbian (testing)* 382 | 383 | ``` 384 | sudo apt update && sudo apt install asn 385 | ``` 386 | * **Manjaro / Arch Linux:** *(thanks [Worty](https://github.com/worty))* 387 | 388 | ``` 389 | yay -S asn-git 390 | ``` 391 | 392 | * **Alpine Linux:** *(thanks [Francesco Colista](https://github.com/fcolista))* 393 | 394 | ``` 395 | apk update && apk add asn 396 | ``` 397 | 398 | * **NixOS** *(thanks [devhell](https://github.com/devhell))* 399 | 400 | * Package [here](https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name/as/asn) 401 | 402 | * **MacOS** *(using [Homebrew](https://formulae.brew.sh/formula/asn), thanks [filippovitale](https://github.com/filippovitale))* 403 | 404 | ``` 405 | brew install asn 406 | ``` 407 | 408 | >*Note for MacOS users:* 409 | > 410 | > *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.* 411 | 412 |
459 |
460 | The geolocation provider of choice for single lookups (i.e. when not running bulk geolocation queries with the `-g` option) is **ipinfo.io**.
461 |
462 | 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.
463 |
464 | 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):
465 |
466 | `$HOME/.asn/ipinfo_token` or
467 | `/etc/asn/ipinfo_token`
468 |
469 | 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).
470 |
471 | In order to do so, you can use the following command:
472 |
473 | ***User mode:***
474 |
475 | `TOKEN="
488 |
489 | 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.
490 |
491 | 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.
492 |
493 | Once obtained, the api token should be written to one of the following files (parsed in that order):
494 |
495 | `$HOME/.asn/iqs_token` or
496 | `/etc/asn/iqs_token`
497 |
498 | 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).
499 |
500 | In order to do so, you can use the following command:
501 |
502 | ***User mode:***
503 |
504 | `TOKEN="
520 |
521 | 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.
522 |
523 | 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**.
524 |
525 | The Cloudflare Radar API is **free** to use, but requires a registration. The steps are:
526 |
527 | 1. [Sign up](https://dash.cloudflare.com/sign-up) for a free Cloudflare account and **validate your email**
528 | 2. From the [Cloudflare dashboard](https://dash.cloudflare.com/profile/api-tokens/), go to **My Profile > API Tokens**.
529 | 3. Select **Create Token**
530 | 4. Choose the "*Read Cloudflare Radar data*" template
531 | 5. Click **Continue to summary** (the default values are fine)
532 | 6. Click **Create token**
533 |
534 | Once obtained, the api token should be written to one of the following files (parsed in that order):
535 |
536 | `$HOME/.asn/cloudflare_token` or
537 | `/etc/asn/cloudflare_token`
538 |
539 | 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).
540 |
541 | In order to do so, you can use the following command:
542 |
543 | ***User mode:***
544 |
545 | `TOKEN="
1000 | 1001 | ##### Command: 1002 | 1003 | `asn -J 8.8.8.8` 1004 | 1005 | ##### Output: 1006 | 1007 | ```json 1008 | { 1009 | "target": "8.8.8.8", 1010 | "target_type": "ipv4", 1011 | "result": "ok", 1012 | "reason": "success", 1013 | "version": "0.78.0", 1014 | "request_time": "2024-08-20T02:50:28", 1015 | "request_duration": 5, 1016 | "api_tokens": { 1017 | "ipqualityscore": true, 1018 | "ipinfo": true, 1019 | "cloudflare": true 1020 | }, 1021 | "result_count": 1, 1022 | "results": [ 1023 | { 1024 | "ip": "8.8.8.8", 1025 | "ip_version": "4", 1026 | "reverse": "dns.google", 1027 | "org_name": "Google LLC", 1028 | "net_range": "8.8.8.0/24", 1029 | "net_name": "GOGL", 1030 | "abuse_contacts": [ 1031 | "network-abuse@google.com" 1032 | ], 1033 | "routing": { 1034 | "is_announced": true, 1035 | "as_number": "15169", 1036 | "as_name": "GOOGLE, US", 1037 | "as_rank": "1788", 1038 | "route": "8.8.8.0/24", 1039 | "route_name": "", 1040 | "roa_count": "1", 1041 | "roa_validity": "valid" 1042 | }, 1043 | "type": { 1044 | "is_bogon": false, 1045 | "is_anycast": true, 1046 | "is_mobile": false, 1047 | "is_proxy": false, 1048 | "is_dc": true, 1049 | "dc_details": { 1050 | "dc_name": "Google LLC" 1051 | }, 1052 | "is_ixp": false 1053 | }, 1054 | "geolocation": { 1055 | "city": "Mountain View", 1056 | "region": "California", 1057 | "country": "United States", 1058 | "cc": "US" 1059 | }, 1060 | "reputation": { 1061 | "status": "good", 1062 | "is_known_good": true, 1063 | "known_as": "Google Public DNS" 1064 | }, 1065 | "fingerprinting": { 1066 | "ports": [ 1067 | 53, 1068 | 443 1069 | ] 1070 | } 1071 | } 1072 | ] 1073 | } 1074 | ``` 1075 |
1077 | 1078 | ##### Command: 1079 | 1080 | `asn -J 5505` 1081 | 1082 | ##### Output: 1083 | 1084 | ```json 1085 | { 1086 | "target": "5505", 1087 | "target_type": "asn", 1088 | "result": "ok", 1089 | "reason": "success", 1090 | "version": "0.78.0", 1091 | "request_time": "2024-08-20T02:50:46", 1092 | "request_duration": 17, 1093 | "api_tokens": { 1094 | "ipqualityscore": true, 1095 | "ipinfo": true, 1096 | "cloudflare": true 1097 | }, 1098 | "result_count": 1, 1099 | "results": [ 1100 | { 1101 | "asn": "5505", 1102 | "asname": "VADAVO, ES", 1103 | "asrank": 4448, 1104 | "org": "VDV-VLC-RED06 VDV-VLC-RED06 - CLIENTES TELECOM", 1105 | "holder": "VADAVO SOLUCIONES SL", 1106 | "abuse_contacts": [ 1107 | "abuse@vadavo.com" 1108 | ], 1109 | "registration_date": "2016-12-13T08:28:07", 1110 | "ixp_presence": [ 1111 | "DE-CIX Madrid: DE-CIX Madrid Peering LAN", 1112 | "ESpanix Madrid Lower LAN" 1113 | ], 1114 | "prefix_count_v4": 8, 1115 | "prefix_count_v6": 1, 1116 | "bgp_peer_count": 36, 1117 | "bgp_hijack_incidents": { 1118 | "total": 0, 1119 | "as_hijacker": 0, 1120 | "as_victim": 0 1121 | }, 1122 | "bgp_leak_incidents": { 1123 | "total": 0 1124 | }, 1125 | "bgp_peers": { 1126 | "upstream": [ 1127 | "1299", 1128 | "6939", 1129 | "59432", 1130 | "174", 1131 | "34549", 1132 | "25091", 1133 | "35625", 1134 | "33891", 1135 | "48348", 1136 | "13030", 1137 | "8218", 1138 | "41327", 1139 | "3303", 1140 | "4455", 1141 | "6424", 1142 | "6057", 1143 | "34927", 1144 | "9498", 1145 | "35280", 1146 | "1239" 1147 | ], 1148 | "downstream": [ 1149 | "48952", 1150 | "208248", 1151 | "205086", 1152 | "202054" 1153 | ], 1154 | "uncertain": [ 1155 | "24482", 1156 | "51185", 1157 | "41047", 1158 | "29680", 1159 | "212483", 1160 | "198150", 1161 | "14840", 1162 | "49544", 1163 | "39384", 1164 | "37721", 1165 | "36236", 1166 | "25160" 1167 | ] 1168 | }, 1169 | "announced_prefixes": { 1170 | "v4": [ 1171 | "185.210.225.0/24", 1172 | "188.130.247.0/24", 1173 | "185.210.227.0/24", 1174 | "185.123.205.0/24", 1175 | "185.123.207.0/24", 1176 | "185.210.226.0/24", 1177 | "185.123.206.0/24", 1178 | "185.123.204.0/24" 1179 | ], 1180 | "v6": [ 1181 | "2a03:9320::/32" 1182 | ] 1183 | }, 1184 | "inetnums": { 1185 | "v4": [ 1186 | "185.123.204.0/22", 1187 | "185.210.225.0/24", 1188 | "185.210.226.0/24", 1189 | "185.210.227.0/24", 1190 | "188.130.247.0/24" 1191 | ], 1192 | "v6": [ 1193 | "2a03:9320::/32" 1194 | ] 1195 | }, 1196 | "inetnums_announced_by_other_as": { 1197 | "v4": [ 1198 | { 1199 | "prefix": "188.130.254.0/24", 1200 | "origin_asn": "", 1201 | "origin_org": "", 1202 | "is_announced": false 1203 | } 1204 | ], 1205 | "v6": [] 1206 | } 1207 | } 1208 | ] 1209 | } 1210 | ``` 1211 | 1212 |
1214 | 1215 | ##### Command: 1216 | 1217 | `asn -j www.google.com | jq '[.results[].abuse_contacts[]] | unique[]'` 1218 | 1219 | ##### Output: 1220 | 1221 | ``` 1222 | "network-abuse@google.com" 1223 | "ripe-contact@google.com" 1224 | ``` 1225 | 1226 |
1228 | 1229 | ##### Command: 1230 | 1231 | `asn -j 45.67.34.100 | jq '.results[].fingerprinting.vulns[]'` 1232 | 1233 | ##### Output: 1234 | ``` 1235 | "CVE-2017-15906" 1236 | "CVE-2018-15919" 1237 | ``` 1238 | 1239 |
1241 | 1242 | ##### Command: 1243 | 1244 | `asn -Ju 72.17.119.201` 1245 | 1246 | ##### Output: 1247 | 1248 | ```json 1249 | { 1250 | "target": "72.17.119.201", 1251 | "target_type": "ipv4", 1252 | "result": "ok", 1253 | "reason": "success", 1254 | "version": "0.78.0", 1255 | "request_time": "2024-08-20T02:54:03", 1256 | "request_duration": 4, 1257 | "api_tokens": { 1258 | "ipqualityscore": true, 1259 | "ipinfo": true, 1260 | "cloudflare": true 1261 | }, 1262 | "result_count": 1, 1263 | "results": [ 1264 | { 1265 | "prefix": "72.17.0.0/17", 1266 | "origin_as": "33363", 1267 | "origin_as_name": "BHN-33363, US", 1268 | "origin_as_rank": 441, 1269 | "upstreams_count": 1, 1270 | "upstreams": [ 1271 | { 1272 | "asn": "7843", 1273 | "asname": "TWC-7843-BB, US", 1274 | "probability": 100, 1275 | "is_tier1": false 1276 | } 1277 | ], 1278 | "multiple_upstreams": false 1279 | } 1280 | ] 1281 | } 1282 | ``` 1283 | 1284 |
1286 | 1287 | ##### Command: 1288 | 1289 | `asn -j AS5505 | jq -r '.results[].inetnums_announced_by_other_as.v4[] | select(.is_announced==false) | .prefix'` 1290 | 1291 | ##### Output: 1292 | 1293 | ``` 1294 | 188.130.254.0/24 1295 | ``` 1296 | 1297 |
1299 | 1300 | ##### Command: 1301 | 1302 | `asn -j AS8860 | jq '.results[].bgp_hijack_incidents'` 1303 | 1304 | ##### Output: 1305 | 1306 | ``` 1307 | { 1308 | "total": 18, 1309 | "as_hijacker": 11, 1310 | "as_victim": 7 1311 | } 1312 | ``` 1313 | 1314 |