cloudflare / flan

A pretty sweet vulnerability scanner
BSD 3-Clause "New" or "Revised" License
4.07k stars 287 forks source link

shared/ips.txt - last IP requires a endline character inorder to be scanned πŸ‡ΊπŸ‡¦ #21

Open vincentclee opened 4 years ago

vincentclee commented 4 years ago

Scenario 1: File with endline character shared/ips.txt

$ hexdump -C shared/ips.txt
00000000  31 2e 31 2e 31 2e 31 0a  38 2e 38 2e 38 2e 38 0a  |1.1.1.1.8.8.8.8.|
00000010

Scenario 2: File without endline character shared/ips.txt

$ hexdump -C shared/ips.txt
00000000  31 2e 31 2e 31 2e 31 0a  38 2e 38 2e 38 2e 38     |1.1.1.1.8.8.8.8|
0000000f

run

$ make start
docker run --name flan_1574459039 -v /Users/vincentclee/git/flan/shared:/shared flan_scan
# Nmap 7.70 scan initiated Fri Nov 22 21:44:00 2019 as: nmap -sV -oX /shared/xml_files/2019.11.22-21.44/1.1.1.1.xml -oN - -v1 --script=vulners/vulners.nse 1.1.1.1
Nmap scan report for one.one.one.one (1.1.1.1)
Host is up (0.00042s latency).
All 1000 scanned ports on one.one.one.one (1.1.1.1) are filtered

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Fri Nov 22 21:44:12 2019 -- 1 IP address (1 host up) scanned in 11.93 seconds
ghost commented 4 years ago

This problem also occurs with python 2.7 on the latest version of Raspbian

root360-AndreasUlm commented 4 years ago

The problem is not in python but in the run.sh logic:

$ echo -ne "a\nb" > shared/ips.txt
$ (while IFS='' read -r line;do echo "$line";done < shared/ips.txt)
a
$ cat -A shared/ips.txt
a$
b

Because 'read' by default uses newline as delimiter it only reads lines that have a newline at the end of the line. A possible solution is to use a command that adds a newline to every printed line, e.g. $ while read -r line;do echo "$line";done < <(grep "" shared/ips.txt) (source: https://stackoverflow.com/a/31397871/7888054)

If this solution is ok for @Cloudflare I could create a PR.