nitefood / asn

ASN / RPKI validity / BGP stats / IPv4v6 / Prefix / URL / ASPath / Organization / IP reputation / IP geolocation / IP fingerprinting / Network recon / lookup API server / Web traceroute server
MIT License
1.31k stars 159 forks source link

Bulk geolocation incorrect results #64

Closed Strykar closed 5 months ago

Strykar commented 5 months ago

Bulk geolocation feature may need some more testing.

It defaults every IP to : Ranong, Ranong, TH (Thailand) here:

$ echo "169.150.243.18 143.244.33.95 143.244.33.79 143.244.33.78 143.244.33.56 169.150.243.20 169.150.243.17" | asn -g

────────────────────────────────────────────────────────────
            WARNING 

No IPQualityScore token found, so disabling in-depth threat 
analysis and IP reputation lookups. Please visit 
https://github.com/nitefood/asn#ip-reputation-api-token 
for instructions on how to enable it. 
────────────────────────────────────────────────────────────

╭─────────────────────────────────────────╮
│ Geolocation lookup for multiple targets │
╰─────────────────────────────────────────╯
143.244.33.56   : Ranong, Ranong, TH (Thailand)                                                                                                                                                                                         
143.244.33.78   : Ranong, Ranong, TH (Thailand) 
143.244.33.79   : Ranong, Ranong, TH (Thailand) 
143.244.33.95   : Ranong, Ranong, TH (Thailand) 
169.150.243.17  : Ranong, Ranong, TH (Thailand) 
169.150.243.18  : Ranong, Ranong, TH (Thailand) 
169.150.243.20  : Ranong, Ranong, TH (Thailand) 

Adding an IPQuality API improves it a bit, but it still mention Ranong:

$ echo "169.150.243.18 143.244.33.95 143.244.33.79 143.244.33.78 143.244.33.56 169.150.243.20 169.150.243.17" | asn -g

╭─────────────────────────────────────────╮
│ Geolocation lookup for multiple targets │
╰─────────────────────────────────────────╯
143.244.33.56   : Singapore, Central Singapore, SG (Singapore)                                                                                                                                                                          
143.244.33.78   : Ranong, Ranong, TH (Thailand) 
143.244.33.79   : Singapore, Central Singapore, SG (Singapore) 
143.244.33.95   : Singapore, Central Singapore, SG (Singapore) 
169.150.243.17  : Singapore, Central Singapore, SG (Singapore) 
169.150.243.18  : Singapore, Central Singapore, SG (Singapore) 
169.150.243.20  : Singapore, Central Singapore, SG (Singapore) 

Similar issue trying with a known list from the UK:

$ echo "84.17.50.99 185.59.221.179 84.17.50.98 89.187.88.237" | asn -g

╭─────────────────────────────────────────╮
│ Geolocation lookup for multiple targets │
╰─────────────────────────────────────────╯
185.59.221.179  : Ranong, Ranong, TH (Thailand)                                                                                                                                                                                         
84.17.50.98     : Ranong, Ranong, TH (Thailand) 
84.17.50.99     : Ranong, Ranong, TH (Thailand) 
89.187.88.237   : London, England, GB (United Kingdom) 
nitefood commented 5 months ago

Hey @Strykar,

so there's a bit to unpack here, let me try to explain what happened.

First of all: IpQualityScore API key has nothing to do with bulk geolocation performed in the asn script. The "better" results from your second run are not a result of adding that API key, but rather of exactly how RIPE IPMap works.

When you first ran your asn -g commands, RIPE IPMap (the primary geolocation service the script uses when doing bulk lookups) had a location of Ranong, Ranong, TH (Thailand) associated with the IPs you were looking up. This is because IPMap had the following geofeed associated with most of these IPs:

➜ curl -s "https://ipmap.ripe.net/api/v1/locate/143.244.33.78/best" | jq '.location.geofeed'
"143.244.33.78,TH,TH-85,Ranong,"

So your first asn run reported this (allegedly wrong) geolocation information in its results. Now what IPMap does, is when you query its API and the geolocation it finds is old/stale, it triggers a new measurement using a batch of RIPE Atlas probes for your target. The probes start the measurement (basically ping the target and report back the RTT and reachability), and when it finishes, IPMap updates its geolocation information for the target(s) with fresh data ingested by its latency engine.

You can double check this is exactly what happened, because RIPE Atlas measurements and their results are public. Let's take your targets in the 143.244.33.0/24 range: your first lookup triggered measurements 68197612, 68197610, 68197616 and 68197617 (1 IP -> 1 measurement).

If you open those measurements, and select the Latest Results tab, you will notice they could all reach the target, except in the case of IP 143.244.33.78: infact measurement 68197610 reports destination unreachable from all the probes.

This in turn triggered the IPMap update that you saw later on: All IPs are now correctly geolocated in Singapore (based on the low latency from the Atlas probes based in SG to the targets) instead of Ranong - all of which happened because your lookups triggered the measurements that made this update possible.

This alone is the reason why, in your next run (after adding the IpQualityScore token) the data is now more accurate (and explains why only 143.244.33.78 is still geolocated in Ranong).

Regarding the UK IP addresses: same sequence of events happened, you can look up the measurements you triggered by yourself here (just search by IP). You kept seeing wrong geolocation results because the measurements weren't finished yet (except for 89.187.88.237). If you try it again now, I bet you'll get consistent UK results on all targets.

There's only one question I cannot answer for sure: why were those IPs geolocated in Thailand in the first place? I have verified using the excellent geofeed-finder that the geofeed IPMap refers to does not exist, so it's either a bug or maybe a stale leftover from the past. I don't know. The only person who may have a clue is @massimocandela (the original IPMap author).

Hope that clarifies things a bit. Thanks for the feeback!