From dd0739be430a1e694479e95c2f1dfe5a18351f0f Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Fri, 8 Aug 2014 11:42:51 +0200 Subject: [PATCH 01/11] README fixed for bare bone install --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5883c3b..b81a29c9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ sudo apt-get install g++ sudo apt-get install python-dev sudo apt-get install python-tk sudo apt-get install screen +sudo apt-get install libssl-dev +sudo apt-get install libfreetype6-dev +sudo apt-get install python-numpy ``` Then these modules need to be install with pip inside the virtual environment: @@ -54,17 +57,18 @@ That's all the packages you can install with pip: ``` pip install redis +pip install logbook pip install networkx pip install crcmod pip install mmh3 pip install dnspython pip install pyzmq -pip install texttable ----- Queues Monitoring (Optional) +pip install texttable pip install -U textblob python -m textblob.download_corpora pip install python-magic pip install numpy -pip install flask ----- (Optional) +pip install flask pip install nltk pip install matplotlib ----- (sudo ln -s freetype2/ft2build.h in /usr/include/) pip install pybloomfiltermmap ----- (you may need to sudo apt-get install libssl-dev) @@ -115,6 +119,22 @@ cd bin ./LAUNCH.sh ``` +To start with the web interface, you need to fetch the required Javascript/CSS files: + +``` +cd $AILENV +cd var/www/ +bash update_thirdparty.sh +``` + +and then you can start the web interface: + +``` +cd $AILENV +cd var/www/ +Flask_server.py +``` + Then you can browse the status of the AIL framework at the following URL: ``http://localhost:7000/`` From af827a3402a0f6a9eca1bc38dfbbde6236a87931 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 13:49:38 +0200 Subject: [PATCH 02/11] Removing the hardcoded IP adress --- var/www/Flask_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index e363c609..38649590 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -63,4 +63,4 @@ def wordstrending(): if __name__ == "__main__": - app.run(host='172.16.100.123' ,port=7000, threaded=True) + app.run(host='0.0.0.0' ,port=7000, threaded=True) From 81ea9cfb3c8d50e1fbbd19b391a1a05120c2e81a Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Fri, 8 Aug 2014 14:03:00 +0200 Subject: [PATCH 03/11] Clarification for the env variable --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b81a29c9..66b3dd77 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,16 @@ sudo apt-get install screen You need to create a variable AILENV that will be the installation path: -``export AILENV="/home/user/ail"`` +``export AILENV="/home/user/AIL-framework"`` + +Usually the installation path is where the project is cloned. Then create a Python virtual environment: -``virtualenv AILENV`` +``` +cd $AILENV +virtualenv AILENV +``` And install these few more packets: ``` From 44addf1afef798bfd4d6ce351029f9fa68cb2db5 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 16:48:02 +0200 Subject: [PATCH 04/11] Redis cache added fix #5 The paste will be add in Redis during 5min and also saved on disk. Now if a module want to get the paste for further processing, it will first try to get it in the cache instead of getting it directly on the disk and wasting I/O. --- bin/packages/Paste.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index eb953e78..1d59f917 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -16,7 +16,7 @@ Conditions to fulfill to be able to use this class correctly: """ -import os, magic, gzip, langid, pprint, redis, operator, string, re, json +import os, magic, gzip, langid, pprint, redis, operator, string, re, json, ConfigParser from Date import Date from Hash import Hash @@ -30,6 +30,10 @@ from lib_refine import * clean = lambda dirty: ''.join(filter(string.printable.__contains__, dirty)) """It filters out non-printable characters from the string it receives.""" +configfile = './config.cfg' +cfg = ConfigParser.ConfigParser() +cfg.read(configfile) + class Paste(object): """ This class representing a Paste as an object. @@ -72,6 +76,11 @@ class Paste(object): self.p_source = var[-5] + self.cache = redis.StrictRedis( + host = cfg.get("Redis_Queues", "host"), + port = cfg.getint("Redis_Queues", "port"), + db = cfg.getint("Redis_Queues", "db")) + def get_p_content(self): """ @@ -82,8 +91,15 @@ class Paste(object): PST.get_p_content() """ - with gzip.open(self.p_path, 'rb') as F: - return F.read() + r_serv = self.cache + + if r_serv.exist(self.p_path): + paste = r_serv.get(self.p_path) + else: + with gzip.open(self.p_path, 'rb') as F: + paste = r_serv.getset(self.p_path, F.read()) + r_serv.expire(self.p_path, 300) + return paste def get_lines_info(self): """ From c9e1eaf1821f628ebd59d1895bad1d3af0b207c0 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:04:25 +0200 Subject: [PATCH 05/11] Improving cache code --- bin/packages/Paste.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index 1d59f917..795cfd22 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -56,6 +56,11 @@ class Paste(object): self.p_size = round(os.path.getsize(self.p_path)/1024.0,2) + self.cache = redis.StrictRedis( + host = cfg.get("Redis_Queues", "host"), + port = cfg.getint("Redis_Queues", "port"), + db = cfg.getint("Redis_Queues", "db")) + self.p_mime = magic.from_buffer(self.get_p_content(), mime = True) self.p_encoding = None @@ -76,11 +81,6 @@ class Paste(object): self.p_source = var[-5] - self.cache = redis.StrictRedis( - host = cfg.get("Redis_Queues", "host"), - port = cfg.getint("Redis_Queues", "port"), - db = cfg.getint("Redis_Queues", "db")) - def get_p_content(self): """ From 503c23ca3b8c396115f11a4b875036856dc69890 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:08:41 +0200 Subject: [PATCH 06/11] Fixing last commit --- bin/packages/Paste.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index 795cfd22..56c8356a 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -30,10 +30,6 @@ from lib_refine import * clean = lambda dirty: ''.join(filter(string.printable.__contains__, dirty)) """It filters out non-printable characters from the string it receives.""" -configfile = './config.cfg' -cfg = ConfigParser.ConfigParser() -cfg.read(configfile) - class Paste(object): """ This class representing a Paste as an object. @@ -50,6 +46,11 @@ class Paste(object): """ def __init__(self, p_path): + + configfile = './config.cfg' + cfg = ConfigParser.ConfigParser() + cfg.read(configfile) + self.p_path = p_path self.p_name = self.p_path.split('/')[-1] From bf682c4b44d3c805c6ed0b069223aa4346461d3c Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:13:18 +0200 Subject: [PATCH 07/11] Fixing last commit ... --- bin/packages/Paste.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index 56c8356a..be981f58 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -47,7 +47,7 @@ class Paste(object): def __init__(self, p_path): - configfile = './config.cfg' + configfile = '../packages/config.cfg' cfg = ConfigParser.ConfigParser() cfg.read(configfile) From 043800287add9c13cbc455b9f9eccada75161204 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:18:03 +0200 Subject: [PATCH 08/11] adding a . --- bin/packages/Paste.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index be981f58..1ac5395a 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -47,7 +47,7 @@ class Paste(object): def __init__(self, p_path): - configfile = '../packages/config.cfg' + configfile = './packages/config.cfg' cfg = ConfigParser.ConfigParser() cfg.read(configfile) From 7a1db94f9ed6b3130496161657bb6208aca0ce97 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:19:42 +0200 Subject: [PATCH 09/11] Adding a letter (s) --- bin/packages/Paste.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index 1ac5395a..437405c0 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -94,7 +94,7 @@ class Paste(object): """ r_serv = self.cache - if r_serv.exist(self.p_path): + if r_serv.exists(self.p_path): paste = r_serv.get(self.p_path) else: with gzip.open(self.p_path, 'rb') as F: From eb603e87623d626ab896eb1ca48e18854477f3d7 Mon Sep 17 00:00:00 2001 From: Starow Date: Fri, 8 Aug 2014 17:23:51 +0200 Subject: [PATCH 10/11] Fixing a bug about caching paste inside Redis :) --- bin/packages/Paste.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index 437405c0..4e5d809c 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -94,11 +94,11 @@ class Paste(object): """ r_serv = self.cache - if r_serv.exists(self.p_path): - paste = r_serv.get(self.p_path) - else: + paste = r_serv.get(self.p_path) + if paste is None: with gzip.open(self.p_path, 'rb') as F: - paste = r_serv.getset(self.p_path, F.read()) + paste = F.read() + r_serv.set(self.p_path, paste) r_serv.expire(self.p_path, 300) return paste From 54091a2174b5191c3bce65b26ff816f0defe1402 Mon Sep 17 00:00:00 2001 From: Starow Date: Mon, 11 Aug 2014 09:08:28 +0200 Subject: [PATCH 11/11] Catching the exception dns.exception.Timeout fix #4 --- bin/ZMQ_Sub_Urls.py | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/bin/ZMQ_Sub_Urls.py b/bin/ZMQ_Sub_Urls.py index e64f6d2b..a957196d 100755 --- a/bin/ZMQ_Sub_Urls.py +++ b/bin/ZMQ_Sub_Urls.py @@ -59,44 +59,47 @@ def main(): url_regex = "(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*" while True: - if message != None: - channel, filename, word, score = message.split() + try: + if message != None: + channel, filename, word, score = message.split() - if prec_filename == None or filename != prec_filename: - domains_list = [] - PST = P.Paste(filename) + if prec_filename == None or filename != prec_filename: + domains_list = [] + PST = P.Paste(filename) - for x in PST.get_regex(url_regex): - scheme, credential, subdomain, domain, host, tld, port, resource_path, query_string, f1, f2, f3, f4 = x - domains_list.append(domain) - msg = pubchannel + " " + str(x) - Pub.send_message(msg) - publisher.debug('{0} Published'.format(x)) + for x in PST.get_regex(url_regex): + scheme, credential, subdomain, domain, host, tld, port, resource_path, query_string, f1, f2, f3, f4 = x + domains_list.append(domain) + msg = pubchannel + " " + str(x) + Pub.send_message(msg) + publisher.debug('{0} Published'.format(x)) - if f1 == "onion": - print domain + if f1 == "onion": + print domain - A_values = lib_refine.checking_A_record(r_serv2, domains_list) + A_values = lib_refine.checking_A_record(r_serv2, domains_list) - if A_values[0] >= 1: - PST.__setattr__(channel, A_values) - PST.save_attribute_redis(r_serv1, channel, (A_values[0],list(A_values[1]))) + if A_values[0] >= 1: + PST.__setattr__(channel, A_values) + PST.save_attribute_redis(r_serv1, channel, (A_values[0],list(A_values[1]))) - pprint.pprint(A_values) - publisher.info('{0};{1};{2};{3};{4}'.format("Url", PST.p_source, PST.p_date, PST.p_name, str(A_values[0])+" Valid url detected" )) - prec_filename = filename + pprint.pprint(A_values) + publisher.info('{0};{1};{2};{3};{4}'.format("Url", PST.p_source, PST.p_date, PST.p_name, str(A_values[0])+" Valid url detected" )) + prec_filename = filename - else: - if r_serv.sismember("SHUTDOWN_FLAGS", "Urls"): - r_serv.srem("SHUTDOWN_FLAGS", "Urls") - print "Shutdown Flag Up: Terminating" - publisher.warning("Shutdown Flag Up: Terminating.") - break - publisher.debug("Script url is Idling 10s") - time.sleep(10) - - message = Sub.get_msg_from_queue(r_serv) + else: + if r_serv.sismember("SHUTDOWN_FLAGS", "Urls"): + r_serv.srem("SHUTDOWN_FLAGS", "Urls") + print "Shutdown Flag Up: Terminating" + publisher.warning("Shutdown Flag Up: Terminating.") + break + publisher.debug("Script url is Idling 10s") + time.sleep(10) + message = Sub.get_msg_from_queue(r_serv) + except dns.exception.Timeout: + print "dns.exception.Timeout" + pass if __name__ == "__main__": main()