Skip to content

Commit

Permalink
added support to pull binaries from the last N number of days
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason McFarland committed Mar 22, 2019
1 parent 46ba2ce commit 23a5e73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
g_num_binaries_analyzed = 0

g_disable_rescan = False

g_num_days_binaries = 365
17 changes: 12 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import humanfriendly
import psycopg2
import json
from datetime import datetime
from datetime import datetime, timedelta
from peewee import SqliteDatabase
from tasks import analyze_binary, update_yara_rules_remote, generate_rule_map, app
import globals
Expand Down Expand Up @@ -57,10 +57,10 @@ def generate_feed_from_db():

feedinfo = CbFeedInfo(**feedinfo)
feed = CbFeed(feedinfo, reports)
logger.debug("dumping feed...")
#logger.debug("dumping feed...")
created_feed = feed.dump()

logger.debug("Writing out feed to disk")
#logger.debug("Writing out feed to disk")
with open(globals.output_file, 'w') as fp:
fp.write(created_feed)

Expand Down Expand Up @@ -179,7 +179,11 @@ def perform(yara_rule_dir):
password=globals.g_postgres_password,
port=globals.g_postgres_port)
cur = conn.cursor()
cur.execute("SELECT md5hash FROM storefiles WHERE present_locally = TRUE ORDER BY timestamp DESC")

start_date_binaries = datetime.now() - timedelta(days=globals.g_num_days_binaries)
cur.execute("SELECT md5hash FROM storefiles WHERE present_locally = TRUE AND timestamp >= '{0}' "
"ORDER BY timestamp DESC".format(start_date_binaries))

except:
logger.error("Failed to connect to Postgres database")
logger.error(traceback.format_exc())
Expand Down Expand Up @@ -317,8 +321,12 @@ def verify_config(config_file, output_file):
if 'disable_rescan' in config['general']:
globals.g_disable_rescan = bool(config['general']['disable_rescan'])

if 'num_days_binaries' in config['general']:
globals.g_num_days_binaries = int(config['general']['num_days_binaries'])

return True


def main():
global logger

Expand Down Expand Up @@ -383,4 +391,3 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit 23a5e73

Please sign in to comment.