forked from p15670423/monkey
parent
87a742186a
commit
ed5e686b04
|
@ -44,7 +44,6 @@ class Monkey(Document):
|
||||||
ip_addresses = ListField(StringField())
|
ip_addresses = ListField(StringField())
|
||||||
networks = ListField()
|
networks = ListField()
|
||||||
launch_time = FloatField()
|
launch_time = FloatField()
|
||||||
keepalive = DateTimeField()
|
|
||||||
modifytime = DateTimeField()
|
modifytime = DateTimeField()
|
||||||
# TODO make "parent" an embedded document, so this can be removed and the schema explained (
|
# TODO make "parent" an embedded document, so this can be removed and the schema explained (
|
||||||
# and validated) verbosely.
|
# and validated) verbosely.
|
||||||
|
|
|
@ -15,7 +15,6 @@ class ClientRun(flask_restful.Resource):
|
||||||
monkey = NodeService.get_monkey_island_monkey()
|
monkey = NodeService.get_monkey_island_monkey()
|
||||||
else:
|
else:
|
||||||
monkey = NodeService.get_monkey_by_ip(client_ip)
|
monkey = NodeService.get_monkey_by_ip(client_ip)
|
||||||
NodeService.update_dead_monkeys()
|
|
||||||
if monkey is not None:
|
if monkey is not None:
|
||||||
is_monkey_running = not monkey["dead"]
|
is_monkey_running = not monkey["dead"]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -12,7 +12,6 @@ from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService
|
||||||
class LocalRun(flask_restful.Resource):
|
class LocalRun(flask_restful.Resource):
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def get(self):
|
def get(self):
|
||||||
NodeService.update_dead_monkeys()
|
|
||||||
island_monkey = NodeService.get_monkey_island_monkey()
|
island_monkey = NodeService.get_monkey_island_monkey()
|
||||||
if island_monkey is not None:
|
if island_monkey is not None:
|
||||||
is_monkey_running = not Monkey.get_single_monkey_by_id(island_monkey["_id"]).is_dead()
|
is_monkey_running = not Monkey.get_single_monkey_by_id(island_monkey["_id"]).is_dead()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import dateutil.parser
|
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ class Monkey(flask_restful.Resource):
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
# Used by monkey. can't secure.
|
||||||
def get(self, guid=None, config_format=None, **kw):
|
def get(self, guid=None, config_format=None, **kw):
|
||||||
NodeService.update_dead_monkeys() # refresh monkeys status
|
|
||||||
if not guid:
|
if not guid:
|
||||||
guid = request.args.get("guid")
|
guid = request.args.get("guid")
|
||||||
|
|
||||||
|
@ -45,10 +43,6 @@ class Monkey(flask_restful.Resource):
|
||||||
monkey_json = json.loads(request.data)
|
monkey_json = json.loads(request.data)
|
||||||
update = {"$set": {"modifytime": datetime.now()}}
|
update = {"$set": {"modifytime": datetime.now()}}
|
||||||
monkey = NodeService.get_monkey_by_guid(guid)
|
monkey = NodeService.get_monkey_by_guid(guid)
|
||||||
if "keepalive" in monkey_json:
|
|
||||||
update["$set"]["keepalive"] = dateutil.parser.parse(monkey_json["keepalive"])
|
|
||||||
else:
|
|
||||||
update["$set"]["keepalive"] = datetime.now()
|
|
||||||
if "config" in monkey_json:
|
if "config" in monkey_json:
|
||||||
update["$set"]["config"] = monkey_json["config"]
|
update["$set"]["config"] = monkey_json["config"]
|
||||||
if "config_error" in monkey_json:
|
if "config_error" in monkey_json:
|
||||||
|
@ -70,10 +64,6 @@ class Monkey(flask_restful.Resource):
|
||||||
with agent_killing_mutex:
|
with agent_killing_mutex:
|
||||||
monkey_json = json.loads(request.data)
|
monkey_json = json.loads(request.data)
|
||||||
monkey_json["dead"] = False
|
monkey_json["dead"] = False
|
||||||
if "keepalive" in monkey_json:
|
|
||||||
monkey_json["keepalive"] = dateutil.parser.parse(monkey_json["keepalive"])
|
|
||||||
else:
|
|
||||||
monkey_json["keepalive"] = datetime.now()
|
|
||||||
|
|
||||||
monkey_json["modifytime"] = datetime.now()
|
monkey_json["modifytime"] = datetime.now()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import socket
|
import socket
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
|
@ -295,22 +295,6 @@ class NodeService:
|
||||||
def set_node_propagated(node_id):
|
def set_node_propagated(node_id):
|
||||||
mongo.db.node.update({"_id": node_id}, {"$set": {"propagated": True}})
|
mongo.db.node.update({"_id": node_id}, {"$set": {"propagated": True}})
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def update_dead_monkeys():
|
|
||||||
# Update dead monkeys only if no living monkey transmitted keepalive in the last 10 minutes
|
|
||||||
if mongo.db.monkey.find_one(
|
|
||||||
{"dead": {"$ne": True}, "keepalive": {"$gte": datetime.now() - timedelta(minutes=10)}}
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
# config.alive is changed to true to cancel the force kill of dead monkeys
|
|
||||||
mongo.db.monkey.update(
|
|
||||||
{"keepalive": {"$lte": datetime.now() - timedelta(minutes=10)}, "dead": {"$ne": True}},
|
|
||||||
{"$set": {"dead": True, "config.alive": True, "modifytime": datetime.now()}},
|
|
||||||
upsert=False,
|
|
||||||
multi=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_any_monkey_alive():
|
def is_any_monkey_alive():
|
||||||
all_monkeys = models.Monkey.objects()
|
all_monkeys = models.Monkey.objects()
|
||||||
|
|
Loading…
Reference in New Issue