From 4a0a6f7c45bd17eac96779be6a121c3b8eebe358 Mon Sep 17 00:00:00 2001 From: SageHack Date: Fri, 30 Mar 2018 10:58:46 -0400 Subject: [PATCH] close #22: Auto update ressources as needed --- .gitignore | 4 ---- README.md | 3 --- bust/__main__.py | 6 ++++++ bust/updater.py | 43 +++++++++++++++++++++++++++++++++++++++++++ lists/.gitignore | 2 ++ lists/last_updated | 1 + lists/update.py | 37 ------------------------------------- 7 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 bust/updater.py create mode 100644 lists/.gitignore create mode 100644 lists/last_updated delete mode 100644 lists/update.py diff --git a/.gitignore b/.gitignore index 1289d82..6531b07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,4 @@ -lists/x* -lists/ipout-hosts -lists/ipout-protected tmp/ - *.pyc *.txt *.log diff --git a/README.md b/README.md index 64b0704..0090b74 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,6 @@ A security tool that aim at doing the following * openssl # Usage instructions -* Install (see below) -* Download latest CloudFlare IPs and CrimeFlare DB -* `python3 lists/update.py` * Run the fast/simple scan * `python3 bust mydomain.com` * Run the slow/comprehensive scan diff --git a/bust/__main__.py b/bust/__main__.py index 53a4852..2fd0abd 100644 --- a/bust/__main__.py +++ b/bust/__main__.py @@ -1,3 +1,4 @@ +from updater import Updater from buster import CloudBuster from cli import args, parser from options import Options @@ -12,9 +13,14 @@ def main(args): + print(logo, flush=True) + if not args.target: parser.print_help() + return + + Updater.run() if os.path.isfile(args.target): scan_list(args) else: diff --git a/bust/updater.py b/bust/updater.py new file mode 100644 index 0000000..d0d5baf --- /dev/null +++ b/bust/updater.py @@ -0,0 +1,43 @@ +import urllib.request +import zipfile +import os +import sys +import time + +class Updater: + def run(): + if Updater.uptodate(): + return + + downloads = [ + ['https://www.cloudflare.com/ips-v4', 'lists/cloudflare_ipv4'], + ['https://www.cloudflare.com/ips-v6', 'lists/cloudflare_ipv6'], + ] + + for d in downloads: + Updater.download(d[0], d[1]) + + Updater.last_updated(Updater.today()) + print('') + + + def uptodate(): + last_updated = open('lists/last_updated', 'r').read() + if last_updated == Updater.today(): + return True + return False + + def last_updated(date): + file = open('lists/last_updated', 'w') + file.write(date) + file.close + + def today(): + return time.strftime("%Y-%m-%d") + + def download(url, file): + print('[download] %s' % url) + try: + urllib.request.urlretrieve(url, file) + except (OSError, HTTPError, http.client.BadStatusLine): + pass diff --git a/lists/.gitignore b/lists/.gitignore new file mode 100644 index 0000000..6c93e8b --- /dev/null +++ b/lists/.gitignore @@ -0,0 +1,2 @@ +last_updated +cloudflare_ip* diff --git a/lists/last_updated b/lists/last_updated new file mode 100644 index 0000000..80b49cc --- /dev/null +++ b/lists/last_updated @@ -0,0 +1 @@ +2018-03-29 diff --git a/lists/update.py b/lists/update.py deleted file mode 100644 index 80639a3..0000000 --- a/lists/update.py +++ /dev/null @@ -1,37 +0,0 @@ -import urllib.request -import zipfile -import os -import sys - - -def progressbar(blocknum, blocksize, totalsize): - readsofar = blocknum * blocksize - if totalsize > 0: - percent = readsofar * 1e2 / totalsize - s = "\r%5.1f%% %*d / %d" % ( - percent, len(str(totalsize)), readsofar, totalsize) - sys.stderr.write(s) - if readsofar >= totalsize: # near the end - sys.stderr.write("\n") - - -def download(url, file, progressbar=None): - print('Downloading %s' % url) - urllib.request.urlretrieve(url, file, progressbar) - - -def unzip(file): - with zipfile.ZipFile(file+'.zip', 'w') as myzip: - myzip.write(file) - os.remove(file+'.zip') - - -downloads = [ - ['https://www.cloudflare.com/ips-v4', 'lists/cloudflare_ipv4', None], - ['https://www.cloudflare.com/ips-v6', 'lists/cloudflare_ipv6', None], -] - -for d in downloads: - download(d[0], d[1], d[2]) - -print('Everything up to date!')