Newer
Older
BLE_CTF_V2 / submit_flag.py
#! /usr/bin/python
import binascii
import struct
import sys, os, time
import bluepy.btle as btle
  
'''

'''

if len(sys.argv) != 2:
   print "submit password\n eg.", sys.argv[0], "<flag>"
   quit()

deviceMAC = open('ctf_mac.txt').read()  
p = btle.Peripheral(deviceMAC)
print ("Attached to peripheral")

flag = sys.argv[1]

print("Submitting Password")
p.writeCharacteristic(0x2E, flag, withResponse=False)

scoreboard = p.getServiceByUUID(0xFF)
q = scoreboard.getCharacteristics()
for characteristic in q:
  hex1 = int(format(characteristic.getHandle(),'02X'), 16)
  if (characteristic.supportsRead()):
       hexlif2 = characteristic.read()
       print (str(hex1)+"  0x"+ format(characteristic.getHandle(),'02X')  +"   "+ characteristic.propertiesToString() + " " + hexlif2)
  else:
     print (str(hex1)+"  0x"+ format(characteristic.getHandle(),'02X')  +"   "+ characteristic.propertiesToString() )

p.disconnect()