SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Initial work on database back-end for storing results and config.
Steve Micallef870e06cebb40
diff --git a/sflib.py b/sflib.pyindex c8aaad70..91103af4 100644--- a/sflib.py+++ b/sflib.py@@ -13,6 +13,7 @@import inspectimport randomimport re+import sqlite3import sysimport timeimport urllib@@ -30,6 +31,23 @@ class SpiderFoot:self.handle = handleself.opts = options+ # connect() will create the database file if it doesn't exist, but+ # at least we can use this opportunity to ensure we have permissions to+ # read and write to such a file.+ dbh = sqlite3.connect(options['_database'])+ if dbh == None:+ self.fatal("Could not connect to internal database. Check that " \+ "spiderfoot.db exists and is readable and writable.")+ self.dbh = dbh.cursor()++ # Now we actually check to ensure the database file has the schema set+ # up correctly.+ try:+ self.dbh.execute('SELECT COUNT(*) FROM tbl_scan_config')+ except sqlite3.Error:+ self.fatal("Found spiderfoot.db but it doesn't appear to be in " \+ "the expected state - ensure the schema is created.")+# initialize database handler for storing resultsreturndiff --git a/spiderfoot.schema b/spiderfoot.schemanew file mode 100644index 00000000..e860ca58--- /dev/null+++ b/spiderfoot.schema@@ -0,0 +1,54 @@+-------------------------------------------------------------------------------+-- Name: spiderfoot.schema+-- Purpose: Database schema for SpiderFoot+--+-- Author: Steve Micallef <[email protected]>+--+-- Created: 10/05/2012+-- Copyright: (c) Steve Micallef 2012+-- Licence: GPL+-------------------------------------------------------------------------------++--+-- Schema is for SQLite but has been left very generic in order to be compatible+-- with any SQL-compliant RDBMS.+--++--+-- Scan instances: Each scan run by the user against a target.+--+DROP TABLE tbl_scan_instance;+CREATE TABLE tbl_scan_instance (+ id INT PRIMARY KEY,+ name VARCHAR NOT NULL,+ seed_target VARCHAR NOT NULL,+ started INT DEFAULT 0,+ ended INT DEFAULT 0,+ status VARCHAR NOT NULL+);++--+-- Scan configs: The configuration used for a scan run.+--+DROP TABLE tbl_scan_config;+CREATE TABLE tbl_scan_config (+ scan_instance_id INT NOT NULL REFERENCES tbl_scan_instance(id),+ component VARCHAR NOT NULL,+ opt VARCHAR NOT NULL,+ val VARCHAR NOT NULL+);++--+-- Scan results: A collection of events stored in a semi-optimized way.+--+DROP TABLE tbl_scan_results;+CREATE TABLE tbl_scan_results (+ scan_instance_id INT NOT NULL REFERENCES tbl_scan_instance(id),+ generated INT NOT NULL,+ event VARCHAR NOT NULL,+ event_source VARCHAR NOT NULL,+ event_data VARCHAR NOT NULL,+ event_data_source VARCHAR NOT NULL+);++CREATE INDEX idx_scan_results_event ON tbl_scan_results (scan_instance_id, event);\ No newline at end of file