Skip to content

Commit c09a4f1

Browse files
committed
Added -s option to search for ASNs matching a given name
1 parent dfaaa92 commit c09a4f1

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Features:
1515
* **Announced prefixes** aggregated to the most relevant less-specific `INET(6)NUM` object (actual [LIR allocation](https://www.ripe.net/manage-ips-and-asns/db/support/documentation/ripe-database-documentation/rpsl-object-types/4-2-descriptions-of-primary-objects/4-2-4-description-of-the-inetnum-object)).
1616

1717
- It will perform an **AS path trace** (using [mtr](https://github.com/traviscross/mtr) in raw mode and retrieving AS data from the results) for single IPs or DNS results, optionally reporting detailed data for each hop, such as RPKI ROA validity, organization/network name, geographic location, etc.
18-
- It will also detect **IXPs** (Internet Exchange Points) traversed during the trace, and highlight them for clarity.
18+
- It will detect **IXPs** (Internet Exchange Points) traversed during the trace, and highlight them for clarity.
1919
- It will attempt to lookup all relevant **abuse contacts** for any given IP or prefix.
2020
- It will perform **RPKI validity** lookups for every possible IP. Data is validated against [RIPE RPKI Validator](https://rpki-validator.ripe.net/). For path traces, the tool will match each hop's ASN/Prefix pair (retrieved from the Prefix Whois public server) with relevant published RPKI ROAs. In case of origin AS mismatch or unallowed more-specific prefixes, it will warn the user of a potential **route leak / BGP hijack** along with the offending AS in the path (requires `-d` option, see below for usage info).
2121
- *Read more about BGP hijkacking [here](https://en.wikipedia.org/wiki/BGP_hijacking).*
2222
- *Read more about RPKI [here](https://en.wikipedia.org/wiki/Resource_Public_Key_Infrastructure), [here](https://blog.cloudflare.com/rpki/), or [here](https://www.ripe.net/manage-ips-and-asns/resource-management/certification).*
23-
- It will also perform **IP reputation** lookups (especially useful when investigating foreign IPs from log files).
24-
- It is also possible to search by **organization name** in order to retrieve a list of IPv4/6 network ranges related to a given company. A multiple choice menu will be presented if more than one organization matches the search query.
23+
- It will perform **IP reputation** lookups (especially useful when investigating foreign IPs from log files).
24+
- It is possible to search by **organization name** in order to retrieve a list of IPv4/6 network ranges related to a given company. A multiple choice menu will be presented if more than one organization matches the search query.
25+
- It is possible to search for **ASNs matching a given name**, in order to map the ASNs for a given organization.
2526

2627
Screenshots for every lookup option are below.
2728

@@ -90,6 +91,12 @@ Requires Bash v4.2+. Tested on:
9091

9192
![search_by_org](https://user-images.githubusercontent.com/24555810/96520260-f7eae100-126e-11eb-8987-52b97c75faaf.png)
9293

94+
### Suggested ASNs search ###
95+
96+
* _Suggested ASNs for "google"_
97+
98+
![asnsuggest](https://user-images.githubusercontent.com/24555810/98309344-7e6f2480-1fca-11eb-9ec6-df2cb63a62ce.png)
99+
93100
---
94101

95102
## Installation
@@ -149,6 +156,7 @@ In order to do so, you can use the following command:
149156
* `asn [-n|-d] <host.name.tld>` -- _to lookup matching IP(v4/v6), route and ASN data (supports multiple IPs - e.g. DNS RR)_
150157
* `asn <Route>` -- _to lookup matching ASN data for the given prefix_
151158
* `asn [-o] <Organization Name>` -- _to search by company name and lookup network ranges exported by (or related to) the company_
159+
* `asn [-s] <Name>` -- _to search for all ASNs matching a given name. Can be used to map all ASNs related to a given company_
152160

153161
##### *Path tracing and reputation*
154162

@@ -167,6 +175,10 @@ In order to do so, you can use the following command:
167175
- The script will try to figure out if the input is an Organization name (i.e. if it doesn't look like an IP address, an AS number or a hostname).
168176
In order to force an organization search (for example for Orgs containing `.` in their name), pass the `[-o|--organization]` command line switch.
169177

178+
##### *ASN suggest (-s)*
179+
180+
- The script will try to find ASNs matching the given search string, using the RIPEStat API.
181+
170182
##### *IXP detection and unannounced prefixes*
171183

172184
- The script will detect [IXPs](https://en.wikipedia.org/wiki/Internet_exchange_point) traversed during path traces by matching them with [PeeringDB](https://www.peeringdb.com/)'s comprehensive dataset of IXP prefixes.

asn

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,42 @@ QueryRipestat(){
128128
StatusbarMessage ""
129129
}
130130

131+
RIPESuggestASN(){
132+
TRIM_WHITESPACES=false
133+
input="$1"
134+
while true; do
135+
StatusbarMessage "Retrieving suggested ASNs for ${bluebg}${input}${lightgreybg}"
136+
ripe_suggest_output=$(curl -s "https://stat.ripe.net/data/searchcomplete/data.json?resource=${input}&sourceapp=nitefood-asn" | \
137+
jq -r '.data.categories | .[] | select ( .category == "ASNs" ) | .suggestions[]')
138+
StatusbarMessage ""
139+
if [ -n "$ripe_suggest_output" ]; then
140+
found_suggestions=$(echo -e "$ripe_suggest_output" | jq -r '.description' | sort -u)
141+
for suggestion in $found_suggestions; do
142+
echo -e "\n${green}$suggestion${default}"
143+
for suggestion_asn in $(echo -e "$ripe_suggest_output" | jq -r 'select (.description=="'"$suggestion"'") | .value'); do
144+
echo -e "\t${yellow}$suggestion_asn${default}"
145+
done
146+
done
147+
echo ""
148+
return
149+
elif [ "$TRIM_WHITESPACES" = false ]; then
150+
TRIM_WHITESPACES=true
151+
oldinput="$input"
152+
# shellcheck disable=SC2001
153+
input=$(echo "$oldinput" | sed 's/[ \t]*//g')
154+
if [ "$input" = "$oldinput" ]; then
155+
echo -e "\n${redbg}No suggestions found${default}\n"
156+
return
157+
else
158+
continue
159+
fi
160+
else
161+
echo -e "\n${redbg}No suggestions found${default}\n"
162+
return
163+
fi
164+
done
165+
}
166+
131167
WhoisIP(){
132168
full_whois_data=$(whois "$1")
133169
network_whois_data=$(echo -e "$full_whois_data" | grep -i -E "^netname:|^orgname:|^org-name:|^owner:|^descr:|^country:")
@@ -222,6 +258,7 @@ PrintUsage(){
222258
"\n\n ${green}-d, --detailed\n\t${default}Output detailed hop info during the AS path trace to the ${blue}TARGET${default}" \
223259
"\n\t(This option also enables RPKI validation/BGP hijacking detection for every hop)" \
224260
"\n\n ${green}-n, --notrace\n\t${default}Disable tracing the AS path to the ${blue}TARGET${default}" \
261+
"\n\n ${green}-s, --suggest\n\t${default}Lookup AS names and numbers matching ${blue}TARGET${default}" \
225262
"\n\n ${green}-o, --organization\n\t${default}Force ${blue}TARGET${default} to be treated as an Organization Name" \
226263
"\n\nSupported targets:" \
227264
"\n\n ${blue}<AS Number>${default}\n\tLookup matching and BGP announcements/neighbours data." \
@@ -1024,7 +1061,7 @@ CheckPrerequisites() {
10241061
disabled_features=""
10251062
HARD_FAIL=false
10261063

1027-
BGPSTAT_LOOKUP=true
1064+
RIPESTAT_LOOKUP=true
10281065
RPKI_LOOKUP=true
10291066
REPUTATION_LOOKUP=true
10301067
HAVE_IPCALC=true
@@ -1048,8 +1085,8 @@ CheckPrerequisites() {
10481085
TRACEASNPATH=false
10491086
;;
10501087
"jq")
1051-
disabled_feat="IP reputation, RIPEstat BGP info and RPKI ROA lookups"
1052-
BGPSTAT_LOOKUP=false
1088+
disabled_feat="IP reputation, RIPEstat BGP info / ASN suggestions, and RPKI ROA lookups"
1089+
RIPESTAT_LOOKUP=false
10531090
RPKI_LOOKUP=false
10541091
REPUTATION_LOOKUP=false
10551092
;;
@@ -1153,6 +1190,7 @@ if [[ $# -lt 1 ]]; then
11531190
fi
11541191

11551192
FORCE_ORGSEARCH=false
1193+
SUGGEST_SEARCH=false
11561194

11571195
case "$1" in
11581196
"-n"|"--notrace")
@@ -1185,6 +1223,16 @@ case "$1" in
11851223
userinput=$(echo "$@" | cut -d ' ' -f 2- | sed -e 's/^[ \t]*//')
11861224
fi
11871225
;;
1226+
"-s"|"--suggest")
1227+
if [[ $# -lt 2 ]]; then
1228+
PrintUsage
1229+
echo -e "Error: missing ${red}TARGET${default}\n"
1230+
exit 1
1231+
else
1232+
SUGGEST_SEARCH=true
1233+
userinput=$(echo "$@" | cut -d ' ' -f 2- | sed -e 's/^[ \t]*//')
1234+
fi
1235+
;;
11881236
*)
11891237
if [ "${1:0:1}" = "-" ]; then
11901238
PrintUsage
@@ -1217,6 +1265,14 @@ if [ "$FORCE_ORGSEARCH" = true ]; then
12171265
exit 0
12181266
fi
12191267

1268+
if [ "$SUGGEST_SEARCH" = true ]; then
1269+
# user passed the "-s|--suggest" switch
1270+
[[ "$RIPESTAT_LOOKUP" = false ]] && PrintErrorAndExit "Please install the necessary prerequisite tool!"
1271+
RIPESuggestASN "$userinput"
1272+
exit 0
1273+
fi
1274+
1275+
12201276
input=$(echo "$userinput" | sed 's/\/.*//g' | grep -Eo "$ipv4v6regex")
12211277

12221278
if [ -z "$input" ]; then
@@ -1289,7 +1345,7 @@ if [ -z "$input" ]; then
12891345
echo -e "${bluebg} AS Name ────────>${default} ${green}${found_asname}"
12901346
echo -e "${bluebg} Organization ───>${default} ${yellow}${found_org}"
12911347
echo -e "${bluebg} AS Reg. date ───>${default} ${white}${found_createdate}"
1292-
if [ "$BGPSTAT_LOOKUP" = true ]; then
1348+
if [ "$RIPESTAT_LOOKUP" = true ]; then
12931349
BoxHeader "BGP informations for AS${asn} (${found_asname})"
12941350
echo ""
12951351
QueryRipestat "${asn}"

0 commit comments

Comments
 (0)