Newer
Older
BLE_CTF_V2 / lvl_09.py
root on 13 Mar 2022 1 KB completed level 09
  1. #! /usr/bin/python
  2. from __future__ import print_function # import print from python3: end=""
  3. import time
  4. import re
  5. import subprocess
  6. import pexpect # sudo apt-get install python-pexpect
  7. import random
  8. import binascii
  9. import struct
  10. import sys, os, time
  11. import bluepy.btle as btle
  12. '''
  13. 42 0x2A READ Im advertising the flag
  14.  
  15. MD5OFLOL
  16. '''
  17. deviceMAC = open('ctf_mac.txt').read()
  18. p = btle.Peripheral(deviceMAC)
  19. svc=p.getServiceByUUID(0x00FF)
  20. print ("Attached to peripheral")
  21.  
  22. print("Loading level 09")
  23. hex1 = binascii.unhexlify(str('%0*x' % (4,9)))
  24. p.writeCharacteristic(0x30, hex1, withResponse=False)
  25.  
  26. p.disconnect()
  27.  
  28. print("Starting advertisement listner")
  29. ps = subprocess.Popen(["btmon"], shell=False, stdout=subprocess.PIPE)
  30. gp = subprocess.Popen(["grep", "Name"], shell=False, stdin=ps.stdout)
  31. ps.stdout.close()
  32. #output = gp.communicate()[0]
  33. #ps.wait()
  34.  
  35. print("Please wait 5s...")
  36. time.sleep(5)
  37.  
  38. print("Starting hcitool")
  39. ps2 = subprocess.Popen(['hcitool', 'lescan'], shell=False)
  40.  
  41. print("Please wait 5s...")
  42. time.sleep(5)
  43. ps2.terminate()
  44. ps.terminate()
Buy Me A Coffee