-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathempireController.py
161 lines (152 loc) · 5.04 KB
/
empireController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import json
import base64
import requests
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
from config import empire_conf as config
HEADERS = {'Content-Type': 'application/json',}
def getEmpireToken():
args = config()
data = {
"username":args['username'],
"password":args['password']
}
payload = json.dumps(data)
baseEndPoint = "/api/admin/login"
url = args['server'] + baseEndPoint
response = requests.post(url, headers=HEADERS, data=payload, verify=False)
result = response.json()
try:
if result['token']:
token = result['token']
except(KeyError):
token = ''
finally:
return(token)
def createHTTPListener(token, listener, port):
args = config()
params = (('token', token),)
data = {
"Name":listener,
"Port":port
}
payload = json.dumps(data)
baseEndPoint = "/api/listeners/http"
url = args['server'] + baseEndPoint
response = requests.post(url, headers=HEADERS, params=params, data=payload, verify=False)
result = response.json()
try:
if result['success']:
value = 1
except(KeyError):
if result['error']:
value = 0
finally:
return(value)
def getAllStager(token):
args = config()
params = (('token', token),)
baseEndPoint = "/api/stagers"
url = args['server'] + baseEndPoint
response = requests.get(url, params=params, verify=False)
result = response.json()
stagerlists = []
try:
if result['stagers']:
for stager in result['stagers']:
stagerlists.append([stager['Name'],stager['Description']])
except(KeyError):
stagerlists.append(['',''])
finally:
return(stagerlists)
def getCurrentListeners(token,listener):
args = config()
params = (('token', token),)
baseEndPoint = "/api/listeners/" + listener
url = args['server'] + baseEndPoint
response = requests.get(url, params=params, verify=False)
result = response.json()
listenrers = []
try:
if result['listeners']:
for listener in result['listeners']:
module = listener['module']
name = listener['name']
host = listener['options']['Host']['Value']
launcher = listener['options']['Launcher']['Value']
except(KeyError):
module, name, host, launcher = '', '', '', ''
finally:
listenrers.append([name,module,host,launcher])
return(listenrers)
def killListener(token, listener):
args = config()
params = (('token', token),)
baseEndPoint = "/api/listeners/" + listener
url = args['server'] + baseEndPoint
response = requests.delete(url, params=params, verify=False)
result = response.json()
try:
if result['success']:
value = 1
except(KeyError):
if result['error']:
value = 0
finally:
return(value)
def generateStager(token, stagerName, listener):
args = config()
params = (('token', token),)
baseEndPoint = "/api/stagers"
url = args['server'] + baseEndPoint
data = {
"StagerName":stagerName,
"Listener":listener
}
payload = json.dumps(data)
response = requests.post(url, headers=HEADERS, params=params, data=payload, verify=False)
result = response.json()
stagers = []
try:
if result[stagerName]:
try:
outstr = base64.b64decode(result[stagerName]['Output']).decode()
except:
outstr = result[stagerName]['Output']
outfile = result[stagerName]['OutFile']['Value']
except(KeyError):
outstr, outfile = '',''
finally:
stagers.append([outstr,outfile])
return(stagers)
def getCurrentAgents(token):
args = config()
params = (('token', token),)
baseEndPoint = "/api/agents"
url = args['server'] + baseEndPoint
response = requests.get(url, params=params, verify=False)
result = response.json()
agents = []
if result['agents']:
for agent in result['agents']:
try:
id = agent['ID']
name = agent['session_id']
language = agent['language']
internal_ip = agent['internal_ip']
username = agent['username']
process_name = agent['process_name']
process_id = agent['process_id']
lastseen_time = agent['lastseen_time']
listener = agent['listener']
except(KeyError):
id, name, language, internal_ip, username, process_name, process_id, lastseen_time, listener = '','','','','','','','',''
try:
os_details = agent['os_details']
except(KeyError):
os_details = ''
agents.append([id,name,language,internal_ip,username,process_name,process_id,lastseen_time,listener,os_details])
else:
agents.append(['','','','','','','','','',''])
return(agents)