Skip to content

Commit bdc39bd

Browse files
committed
clear pending on startup and options to clear all
1 parent edc496c commit bdc39bd

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

beeswarm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
except ImportError:
55
pass
66

7-
version = '0.4.15'
7+
version = '0.4.16'
88

beeswarm/drones/client/models/dispatcher.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ def _run(self):
5858
gevent.sleep(5)
5959
while self.time_in_range():
6060
if self.activation_probability >= random.random():
61-
# TODO: sessions whould be moved from here, too many has knowledge of the sessions list
62-
bait = self.bait_type(self.sessions, self.options)
63-
gevent.spawn(bait.start)
61+
if not self.options['server']:
62+
logging.debug('Discarding bait session because the honeypot has not announced '
63+
'the ip address yet')
64+
else:
65+
# TODO: sessions whould be moved from here, too many has knowledge of the sessions list
66+
bait = self.bait_type(self.sessions, self.options)
67+
gevent.spawn(bait.start)
6468
gevent.sleep(self.sleep_interval)
6569

6670
def time_in_range(self):

beeswarm/server/db/session_persister.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@
3333

3434

3535
class SessionPersister(gevent.Greenlet):
36-
def __init__(self):
36+
def __init__(self, clear_sessions=False):
3737
Greenlet.__init__(self)
38+
db_session = database_setup.get_session()
39+
# clear all pending sessions on startup, pending sessions on startup
40+
pending_classification = db_session.query(Classification).filter(Classification.type == 'pending').one()
41+
pending_deleted = db_session.query(Session).filter(Session.classification == pending_classification).delete()
42+
db_session.commit()
43+
logging.info('Cleaned {0} pending sessions on startup'.format(pending_deleted))
44+
if clear_sessions:
45+
count = db_session.query(Session).delete()
46+
logging.info('Deleting {0} sessions on startup.'.format(count))
47+
db_session.commit()
3848
ctx = beeswarm.zmq_context
3949
self.subscriber_sessions = ctx.socket(zmq.SUB)
4050
self.subscriber_sessions.connect('inproc://sessionPublisher')

bin/beeswarm

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ if __name__ == '__main__':
9191
parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Logs debug messages.')
9292
parser.add_argument('--customize', action='store_true', default=False,
9393
help='Asks for specific network and certificate information on the first run.')
94+
parser.add_argument('--clearsessions', action='store_true', default=False,
95+
help='Deletes all sessions on startup.')
9496
args = parser.parse_args()
9597

9698
setuplogging(args.logfile, args.verbose)
@@ -128,7 +130,7 @@ if __name__ == '__main__':
128130
sys.exit(1)
129131

130132
try:
131-
m = mode(args.workdir, config, customize=args.customize)
133+
m = mode(args.workdir, config, customize=args.customize, clear_db=args.clearsessions)
132134
except ConfigNotFound as ex:
133135
logger.error(ex)
134136
sys.exit(ex)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--allow-unverified pyDes
22
--allow-external pyDes
3-
pyzmq>=14.1.1
3+
pyzmq==14.3.0
44
fs
55
pycrypto
66
Crypto

0 commit comments

Comments
 (0)