robertdavidgraham / masscan

TCP port scanner, spews SYN packets asynchronously, scanning entire Internet in under 5 minutes.
GNU Affero General Public License v3.0
23.66k stars 3.07k forks source link

JSON produced is not valid due to trailing comma in last element. #493

Open ajsween opened 4 years ago

ajsween commented 4 years ago

When attempting to use jq to extract fields from the JSON results of a masscan jq throws and error. Using a JSON validator plugin in Visual Studio Code it quickly became apparent what the issue was.

The last element in the array has a comma at the end when it should not as there are no following elements and the next line closes the array with a bracket.

aaronsdevera commented 4 years ago

Seeing this as well.

Cloufish commented 3 years ago

Same, does anyone know how to fix this? Edit: I don't get this attitude for this project from the author. The project is huge, it has almost 15000 stars. It looks like there were pull requests fixing this issue from 2016 and it still is not fixed in the master branch even though it would be so easy.

paalbra commented 3 years ago

Seeing the same (v1.0.4). Looks like it's mentioned in this older issue as well #314

mzpqnxow commented 3 years ago

I recommend you use the line-based NDJSON format (-oD) as it's both simpler to parse with tools like jq and can be processed in chunks. One large JSON blob is really not the best way to work with data like this

(I realize this doesn't fix whatever issue you're having with -oJ, but if there is in fact a bug in master, it's probably gone unnoticed because most users have switched to -oD)

mzpqnxow commented 3 years ago

@paalbra, I'm not able to reproduce this on the current master

18:39:00 › sudo bin/masscan x.x.x.x -p 22,53,443,65535,65534 --rate 100 -oJ test.json        
Starting masscan 1.3.2 (http://bit.ly/14GZzcT) at 2021-05-10 22:39:23 GMT
Initiating SYN Stealth Scan
Scanning 1 hosts [5 ports/host]
...
18:39:35 › cat test.json | jq '.[]' -c
{"ip":"x.x.x.x","timestamp":"1620686363","ports":[{"port":53,"proto":"tcp","status":"open","reason":"syn-ack","ttl":63}]}
{"ip":"x.x.x.x","timestamp":"1620686363","ports":[{"port":443,"proto":"tcp","status":"open","reason":"syn-ack","ttl":53}]}
{"ip":"x.x.x.x","timestamp":"1620686363","ports":[{"port":65535,"proto":"tcp","status":"open","reason":"syn-ack","ttl":53}]}
18:39:36 ›

Seems to me like you're building an old version

EDIT: I see this issue is very old, if you're having this problem @paalbra it's because you have an old version checked out