2018-05-04 13:53:29 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-09-19 14:03:05 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# This file is part of AIL framework - Analysis Information Leak framework
|
|
|
|
#
|
|
|
|
# This a simple feeder script feeding data from pystemon to AIL.
|
|
|
|
#
|
|
|
|
# Don't forget to set your pystemonpath and ensure that the
|
|
|
|
# configuration matches this script. Default is Redis DB 10.
|
|
|
|
#
|
|
|
|
# https://github.com/cvandeplas/pystemon/blob/master/pystemon.yaml#L16
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2014 Alexandre Dulaunoy - a@foo.be
|
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2014-09-19 14:03:05 +02:00
|
|
|
|
|
|
|
import zmq
|
|
|
|
import random
|
|
|
|
import time
|
|
|
|
import redis
|
|
|
|
import base64
|
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
|
|
|
import ConfigLoader
|
2017-01-10 18:18:55 +01:00
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
config_loader = ConfigLoader.ConfigLoader()
|
2017-01-10 18:18:55 +01:00
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
if config_loader.has_option("ZMQ_Global", "bind"):
|
|
|
|
zmq_url = config_loader.get_config_str("ZMQ_Global", "bind")
|
2017-01-13 14:54:43 +01:00
|
|
|
else:
|
|
|
|
zmq_url = "tcp://127.0.0.1:5556"
|
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
pystemonpath = config_loader.get_config_str("Directories", "pystemonpath")
|
|
|
|
pastes_directory = config_loader.get_config_str("Directories", "pastes")
|
2018-10-02 16:02:59 +02:00
|
|
|
pastes_directory = os.path.join(os.environ['AIL_HOME'], pastes_directory)
|
2018-01-15 17:45:13 +01:00
|
|
|
base_sleeptime = 0.01
|
|
|
|
sleep_inc = 0
|
2014-09-19 14:03:05 +02:00
|
|
|
|
2019-11-05 15:18:03 +01:00
|
|
|
config_loader = None
|
|
|
|
|
2014-09-19 14:03:05 +02:00
|
|
|
context = zmq.Context()
|
|
|
|
socket = context.socket(zmq.PUB)
|
2017-01-10 18:18:55 +01:00
|
|
|
socket.bind(zmq_url)
|
2014-09-19 14:03:05 +02:00
|
|
|
|
|
|
|
# check https://github.com/cvandeplas/pystemon/blob/master/pystemon.yaml#L16
|
2018-05-04 13:53:29 +02:00
|
|
|
r = redis.StrictRedis(host='localhost', db=10, decode_responses=True)
|
2014-09-19 14:03:05 +02:00
|
|
|
|
|
|
|
# 101 pastes processed feed
|
|
|
|
# 102 raw pastes feed
|
2018-09-21 14:16:06 +02:00
|
|
|
topic = '102'
|
2014-09-19 14:03:05 +02:00
|
|
|
|
|
|
|
while True:
|
2018-01-15 17:45:13 +01:00
|
|
|
time.sleep(base_sleeptime + sleep_inc)
|
2014-09-19 14:03:05 +02:00
|
|
|
paste = r.lpop("pastes")
|
|
|
|
if paste is None:
|
|
|
|
continue
|
2018-01-15 17:10:03 +01:00
|
|
|
try:
|
2018-11-22 06:57:24 +01:00
|
|
|
print(paste)
|
2018-08-13 10:22:20 +02:00
|
|
|
with open(pystemonpath+paste, 'rb') as f: #.read()
|
|
|
|
messagedata = f.read()
|
2019-01-09 13:15:58 +01:00
|
|
|
path_to_send = os.path.join(pastes_directory,paste)
|
2018-09-21 14:16:06 +02:00
|
|
|
|
|
|
|
s = b' '.join( [ topic.encode(), path_to_send.encode(), base64.b64encode(messagedata) ] )
|
|
|
|
socket.send(s)
|
|
|
|
sleep_inc = sleep_inc-0.01 if sleep_inc-0.01 > 0 else 0
|
2018-01-15 17:10:03 +01:00
|
|
|
except IOError as e:
|
2018-01-15 17:45:13 +01:00
|
|
|
# file not found, could be a buffering issue -> increase sleeping time
|
|
|
|
print('IOError: Increasing sleep time')
|
|
|
|
sleep_inc += 0.5
|
2018-01-15 17:10:03 +01:00
|
|
|
continue
|