Skip to content

Commit

Permalink
fix a couple api endpoints that were throwing 500s when they should'v…
Browse files Browse the repository at this point in the history
…e been 404 (#145)
  • Loading branch information
vinnybod committed Jun 11, 2021
1 parent ffffce9 commit 7e889e0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions empire/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,16 +641,15 @@ def get_listener_name(listener_name):
"""
active_listener = Session().query(models.Listener).filter(models.Listener.name == listener_name).first()

listeners = []
if active_listener.name == listener_name:
listeners.append({'ID': active_listener.id, 'name': active_listener.name, 'module': active_listener.module,
'listener_type': active_listener.listener_type,
'listener_category': active_listener.listener_category,
'options': active_listener.options})
return jsonify({'listeners': listeners})
else:
if not active_listener:
return make_response(jsonify({'error': 'listener name %s not found' % listener_name}), 404)

listeners = [{'ID': active_listener.id, 'name': active_listener.name, 'module': active_listener.module,
'listener_type': active_listener.listener_type,
'listener_category': active_listener.listener_category,
'options': active_listener.options}]
return jsonify({'listeners': listeners})

@app.route('/api/listeners/<string:listener_name>', methods=['DELETE'])
def kill_listener(listener_name):
"""
Expand Down Expand Up @@ -829,7 +828,7 @@ def remove_agent(agent_name):
agent = Session().query(models.Agent).filter(models.Agent.name == agent_name).first()

if not agent:
return make_response(jsonify({'error': 'agent name %s not found' % agent_name}), 404)
return make_response(jsonify({'error': 'agent %s not found' % agent_name}), 404)

agent.killed = True
Session().commit()
Expand All @@ -842,6 +841,10 @@ def get_agents_name(agent_name):
Returns JSON describing the agent specified by agent_name.
"""
agent = Session().query(models.Agent).filter(models.Agent.name == agent_name).first()

if not agent:
return make_response(jsonify({'error': 'agent %s not found' % agent_name}), 404)

active_agent = []
active_agent.append(
{"ID": agent.id, "session_id": agent.session_id, "listener": agent.listener, "name": agent.name,
Expand Down Expand Up @@ -1758,7 +1761,7 @@ def get_user(uid):
user = Session().query(models.User).filter(models.User.id == uid).first()

if user is None:
make_response(jsonify({'error': 'user %s not found' % uid}), 404)
return make_response(jsonify({'error': 'user %s not found' % uid}), 404)

return jsonify(
{"ID": user.id, "username": user.username, "last_logon_time": user.last_logon_time, "enabled": user.enabled,
Expand Down

0 comments on commit 7e889e0

Please sign in to comment.