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.37k stars 163 forks source link

TERM value is set in headless mode when run with ./asn -l #12

Closed ScrumpyJack closed 3 years ago

ScrumpyJack commented 3 years ago

When listening in server mode, I don't get any output from asn.

[2021-04-11 18:15:45] INFO ASN Lookup Server listening on 192.168.3.21:49200 [2021-04-11 18:15:47] INFO Incoming connection by client 172.18.0.7 [2021-04-11 18:15:47] STARTED Lookup request by client 172.18.0.7 for target github.com (Request ID: 817759845)

──────────────────────────────────────────────────────────── 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. ──────────────────────────────────────────────────────────── ./asn: line 1389: $max_msg_size: substring expression < 0 [2021-04-11 18:15:48] COMPLETED Lookup request by client 172.18.0.7 for target github.com (Request ID: 817759845)

Screenshot 2021-04-11 at 18 19 26

./asn: line 1389: $max_msg_size: substring expression < 0

https://github.com/nitefood/asn/blob/d280c0aeaa1edb032e3f5c1fae88cbf42282d637/asn#L1387

It looks like terminal_width is 0 at this point and thus max_msg_size = -23

ScrumpyJack commented 3 years ago

The problem is with running asn -l in the foreground. It picks up the $TERM, and thus IS_HEADLESS=false Perhaps -l should set IS_HEADLESS=true, instead of looking for TERM=dumb?

nitefood commented 3 years ago

Thanks for the analysis, this was broken in commit 7a920ad, when I changed the subshell detecting logic. What is happening is the subshell spawned by the ncat connection handler isn't getting it's $TERM variable set to "dumb" - which it instead does when launched through systemd.

In order to fix it, can you confirm that by manually setting the terminal on line 1907 from this:

        INTERNAL_CONNHANDLER_CHILD=true INTERNAL_ASNSERVER_CONNHANDLER=false "$0" "$host" |

to this:

        INTERNAL_CONNHANDLER_CHILD=true INTERNAL_ASNSERVER_CONNHANDLER=false TERM=dumb "$0" "$host" |

fixes the issue?

Thanks.

ScrumpyJack commented 3 years ago

Awesome thanks. that worked