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.33k stars 161 forks source link

IP version assumptions and conflict in server mode #13

Closed ScrumpyJack closed 3 years ago

ScrumpyJack commented 3 years ago

When running in server mode, compare if you will

/asn_lookup&bbc.co.uk

and

/asn_lookup&www.bbc.co.uk

The error is:

host: '....origin.asn.cymru.com' is not a legal name (empty label) host: '' is not in legal name syntax (unexpected end of input)

Looks like $rev doesn't get a value. I'll take a closer when i get some time

./asn www.bbc.co.uk works fine on the command line.

ScrumpyJack commented 3 years ago

I think the problem is here

https://github.com/nitefood/asn/blob/d280c0aeaa1edb032e3f5c1fae88cbf42282d637/asn#L2300-L2304

If ipify returns an IPv6 address for the host it's run from, then HAVE_IPV6 is set to true, but if a host passed to /asn_lookup& resolves to A records (and no AAAA records, thus populating $ip with a list of IPv4 addresses), then the grep on 2301 fails and $ip_to_trace doesn't get assigned anything.

Not sure why it works on the command line mode yet, it's possibly due to the fact that this bit gets skipped.

nitefood commented 3 years ago

Great catch! Again good analysis, this check gets indeed skipped when running from command line since its only purpose is to grab the first relevant IP when running web lookups, in order to speed up execution. The use case you describe (IPv6 on the server, IPv4-only target) is one that I missed while testing.

Can you please try changing line 2300 from:

            if [ "$HAVE_IPV6" = true ]; then

to:

            if [ "$HAVE_IPV6" = true ] && grep -q ':' <<<"$ip"; then

and confirm it fixes it?

Thanks again for your feedback!

ScrumpyJack commented 3 years ago

That'll do it. Thanks.