Fixed various issues for agent profile setting/handling

'DefaultProfile' option in listener menu is now tab-completable and can take a path to a profile.txt
1.6
Harmj0y 2015-12-29 15:57:01 -05:00
parent d152e71949
commit 82fed97485
2 changed files with 38 additions and 13 deletions

View File

@ -123,14 +123,14 @@ class Agents:
if len(parts) == 2: if len(parts) == 2:
requestUris = parts[0] requestUris = parts[0]
userAgent = parts[1] userAgent = parts[1]
elif len(parts) == 3: elif len(parts) > 2:
requestUris = parts[0] requestUris = parts[0]
userAgent = parts[1] userAgent = parts[1]
additionalHeaders = parts[2] additionalHeaders = "|".join(parts[2:])
cur.execute("INSERT INTO agents (name,session_id,delay,jitter,external_ip,session_key,checkin_time,lastseen_time,uris,user_agent,headers,kill_date,working_hours,lost_limit) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (sessionID,sessionID,delay,jitter,externalIP,sessionKey,checkinTime,lastSeenTime,requestUris,userAgent,additionalHeaders,killDate,workingHours,lostLimit)) cur.execute("INSERT INTO agents (name,session_id,delay,jitter,external_ip,session_key,checkin_time,lastseen_time,uris,user_agent,headers,kill_date,working_hours,lost_limit) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (sessionID,sessionID,delay,jitter,externalIP,sessionKey,checkinTime,lastSeenTime,requestUris,userAgent,additionalHeaders,killDate,workingHours,lostLimit))
cur.close() cur.close()
# initialize the tasking/result buffers along with the client session key # initialize the tasking/result buffers along with the client session key
sessionKey = self.get_agent_session_key(sessionID) sessionKey = self.get_agent_session_key(sessionID)
self.agents[sessionID] = [sessionKey, [],[],[], requestUris, ""] self.agents[sessionID] = [sessionKey, [],[],[], requestUris, ""]

View File

@ -9,7 +9,7 @@ menu loops.
""" """
# make version for Empire # make version for Empire
VERSION = "1.3.9" VERSION = "1.3.10"
from pydispatch import dispatcher from pydispatch import dispatcher
@ -475,18 +475,24 @@ class MainMenu(cmd.Cmd):
else: else:
if parts[0].lower() == "ip_whitelist": if parts[0].lower() == "ip_whitelist":
if parts[1] != "" and os.path.exists(parts[1]): if parts[1] != "" and os.path.exists(parts[1]):
f = open(parts[1], 'r') try:
ipData = f.read() f = open(parts[1], 'r')
f.close() ipData = f.read()
self.agents.ipWhiteList = helpers.generate_ip_list(ipData) f.close()
self.agents.ipWhiteList = helpers.generate_ip_list(ipData)
except:
print helpers.color("[!] Error opening ip file %s" %(parts[1]))
else: else:
self.agents.ipWhiteList = helpers.generate_ip_list(",".join(parts[1:])) self.agents.ipWhiteList = helpers.generate_ip_list(",".join(parts[1:]))
elif parts[0].lower() == "ip_blacklist": elif parts[0].lower() == "ip_blacklist":
if parts[1] != "" and os.path.exists(parts[1]): if parts[1] != "" and os.path.exists(parts[1]):
f = open(parts[1], 'r') try:
ipData = f.read() f = open(parts[1], 'r')
f.close() ipData = f.read()
self.agents.ipBlackList = helpers.generate_ip_list(ipData) f.close()
self.agents.ipBlackList = helpers.generate_ip_list(ipData)
except:
print helpers.color("[!] Error opening ip file %s" %(parts[1]))
else: else:
self.agents.ipBlackList = helpers.generate_ip_list(",".join(parts[1:])) self.agents.ipBlackList = helpers.generate_ip_list(",".join(parts[1:]))
else: else:
@ -1614,6 +1620,7 @@ class AgentMenu(cmd.Cmd):
# strip out profile comments and blank lines # strip out profile comments and blank lines
profile = [l for l in profile if (not l.startswith("#") and l.strip() != "")] profile = [l for l in profile if (not l.startswith("#") and l.strip() != "")]
profile = profile[0] profile = profile[0]
if not profile.strip().startswith("\"/"): if not profile.strip().startswith("\"/"):
print helpers.color("[!] Task URIs in profiles must start with / and be enclosed in quotes!") print helpers.color("[!] Task URIs in profiles must start with / and be enclosed in quotes!")
else: else:
@ -1998,7 +2005,22 @@ class ListenerMenu(cmd.Cmd):
"Set a listener option." "Set a listener option."
parts = line.split(" ") parts = line.split(" ")
if len(parts) > 1: if len(parts) > 1:
self.mainMenu.listeners.set_listener_option(parts[0], " ".join(parts[1:]))
if parts[0].lower() == "defaultprofile" and os.path.exists(parts[1]):
try:
f = open(parts[1], 'r')
profileDataRaw = f.readlines()
profileData = [l for l in profileDataRaw if (not l.startswith("#") and l.strip() != "")]
profileData = profileData[0].strip("\"")
f.close()
self.mainMenu.listeners.set_listener_option(parts[0], profileData)
except:
print helpers.color("[!] Error opening profile file %s" %(parts[1]))
else:
self.mainMenu.listeners.set_listener_option(parts[0], " ".join(parts[1:]))
else: else:
print helpers.color("[!] Please enter a value to set for the option") print helpers.color("[!] Please enter a value to set for the option")
@ -2143,6 +2165,9 @@ class ListenerMenu(cmd.Cmd):
elif line.split(" ")[1].lower() == "certpath": elif line.split(" ")[1].lower() == "certpath":
return helpers.complete_path(text,line,arg=True) return helpers.complete_path(text,line,arg=True)
elif line.split(" ")[1].lower() == "defaultprofile":
return helpers.complete_path(text,line,arg=True)
mline = line.partition(' ')[2] mline = line.partition(' ')[2]
offs = len(mline) - len(text) offs = len(mline) - len(text)