Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

Cleaner JSON output.

smicallefa9761d68ce8f
diff --git a/modules/sfp__stor_stdout.py b/modules/sfp__stor_stdout.py
index b3443a95..77323048 100644
--- a/modules/sfp__stor_stdout.py
+++ b/modules/sfp__stor_stdout.py
@@ -17,6 +17,7 @@ import json
class sfp__stor_stdout(SpiderFootPlugin):
"""Command-line output::::Dumps output to standard out. Used for when a SpiderFoot scan is run via the command-line."""
_priority = 0
+ firstEvent = True
# Default options
opts = {
@@ -90,7 +91,11 @@ class sfp__stor_stdout(SpiderFootPlugin):
if self.opts['_format'] == "json":
d = event.asDict()
d['type'] = self.opts['_eventtypes'][event.eventType]
- print(json.dumps(d))
+ if self.firstEvent:
+ self.firstEvent = False
+ else:
+ print(",")
+ print(json.dumps(d), end='')
# Handle events sent to this module
def handleEvent(self, sfEvent):
diff --git a/sf.py b/sf.py
index 0e101829..4fedae70 100755
--- a/sf.py
+++ b/sf.py
@@ -103,7 +103,7 @@ if __name__ == '__main__':
p.add_argument("-s", metavar="TARGET", help="Target for the scan.")
p.add_argument("-t", metavar="type1,type2,...", type=str, help="Event types to collect.")
p.add_argument("-T", "--types", action='store_true', help="List available event types.")
- p.add_argument("-o", metavar="tab|csv|json", type=str, help="Output format. Tab is default.")
+ p.add_argument("-o", metavar="tab|csv|json", type=str, help="Output format. Tab is default. If using json, -q is enforced.")
p.add_argument("-H", action='store_true', help="Don't print field headers, just data.")
p.add_argument("-n", action='store_true', help="Strip newlines from data.")
p.add_argument("-r", action='store_true', help="Include the source data field in tab/csv output.")
@@ -120,7 +120,7 @@ if __name__ == '__main__':
else:
sfConfig['_debug'] = False
- if args.q:
+ if args.q or args.o == "json":
sfConfig['__logging'] = False
if args.l:
@@ -306,7 +306,7 @@ if __name__ == '__main__':
modlist += ["sfp__stor_db", "sfp__stor_stdout"]
# Run the scan
- if not args.q:
+ if sfConfig['__logging']:
print(("[*] Modules enabled (" + str(len(modlist)) + "): " + ",".join(modlist)))
cfg = sf.configUnserialize(dbh.configGet(), sfConfig)
scanId = sf.genScanInstanceGUID(target)
@@ -348,17 +348,21 @@ if __name__ == '__main__':
else:
print('{0:30}{1}{2:45}{3}{4}{5}{6}'.format("Source", delim, "Type", delim, "Source Data", delim, "Data"))
+ if args.o == "json":
+ print("[", end='')
+
while True:
info = dbh.scanInstanceGet(scanId)
if not info:
time.sleep(1)
continue
if info[5] in [ "ERROR-FAILED", "ABORT-REQUESTED", "ABORTED", "FINISHED" ]:
- if not args.q:
+ if sfConfig['__logging']:
print("[*] Scan completed with status " + info[5])
+ if args.o == "json":
+ print("]")
sys.exit(0)
time.sleep(1)
-
sys.exit(0)
# Start the web server so you can start looking at results