Newer
Older
BLE_CTF_V2 / load_level.py
  1. #! /usr/bin/python
  2. import binascii
  3. import struct
  4. import sys, os, time
  5. import bluepy.btle as btle
  6. chall_uuid = 0x30
  7. board_uuid = 0x2e
  8. score_uuid = 0x00ff
  9.  
  10. if len(sys.argv) != 2:
  11. print "Requires level no.:", sys.argv[0], "<0-9 or \"s\" for scoreboard>"
  12. quit()
  13.  
  14. deviceMAC = open('ctf_mac.txt').read()
  15. p = btle.Peripheral(deviceMAC)
  16. #p.connect(deviceMAC, "public")
  17. if( sys.argv[1] == "s"):
  18. # load scroebaord... hopefully
  19. print("Loading scoreboard")
  20. #deviceMAC = open('ctf_mac.txt').read()
  21. #p = btle.Peripheral(deviceMAC)
  22. response = p.writeCharacteristic(board_uuid, "fuck you")
  23. else:
  24. level = int(sys.argv[1])
  25. level_hex = str('%0*x' % (4,level))
  26. print level_hex
  27.  
  28.  
  29. #print ("Attached to peripheral")
  30. #services = p.getServiceByUUID(score_uuid)
  31. #char = services.getCharacteristics(chall_uuid)[0]
  32.  
  33. print("Loading level")
  34. #char.write(level_hex)
  35. hex1 = binascii.unhexlify(level_hex)
  36. response = p.writeCharacteristic(chall_uuid, hex1)
  37.  
  38. print("If error try again...it takes a few attempts, BLE is a bit crap")
  39. p.disconnect()
  40. time.sleep(1)
  41. p = btle.Peripheral(deviceMAC)
  42.  
  43. scoreboard = p.getServiceByUUID(score_uuid)
  44. q = scoreboard.getCharacteristics()
  45. scoreboard = p.getServiceByUUID(score_uuid)
  46. q = scoreboard.getCharacteristics()
  47. for characteristic in q:
  48. hex1 = int(format(characteristic.getHandle(),'02X'), 16)
  49. if (characteristic.supportsRead()):
  50. #hex2 = binascii.b2a_hex(p.readCharacteristic(hex1))
  51. #hexlif2 = binascii.unhexlify(hex2)
  52. hexlif2 = characteristic.read()
  53. print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() + " " + hexlif2)
  54. else:
  55. print (str(hex1)+" 0x"+ format(characteristic.getHandle(),'02X') +" "+ characteristic.propertiesToString() )
  56. p.disconnect()
Buy Me A Coffee