Last active
March 26, 2024 16:24
-
-
Save miketweaver/6ffb74f0d52e6f2078f0b144408e3def to your computer and use it in GitHub Desktop.
Solve the Serial communication for the BsidesSLC 2019 Badge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#License | |
#Copyright 2019 Mike Weaver | |
# | |
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
# This software requires some sort of serial UART device | |
import serial, time | |
ser = serial.Serial() | |
# !!!!!!! | |
# REPLACE THIS WITH YOUR SERIAL PORT DEVICE | |
# !!!!!!! | |
ser.port = "/dev/tty.usbserial-A900adej" | |
ser.baudrate = 19200 | |
ser.bytesize = serial.EIGHTBITS #number of bits per bytes | |
ser.parity = serial.PARITY_NONE #set parity check: no parity | |
ser.stopbits = serial.STOPBITS_ONE #number of stop bits | |
#ser.timeout = None #block read | |
ser.timeout = 1 #non-block read | |
#ser.timeout = 2 #timeout block read | |
ser.xonxoff = False #disable software flow control | |
ser.rtscts = False #disable hardware (RTS/CTS) flow control | |
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control | |
ser.writeTimeout = 2 #timeout for write | |
try: | |
ser.open() | |
except Exception, e: | |
print "error open serial port: " + str(e) | |
exit() | |
if ser.isOpen(): | |
try: | |
ser.flushInput() #flush input buffer, discarding all its contents | |
ser.flushOutput()#flush output buffer, aborting current output | |
#and discard all that is in buffer | |
while(True): | |
raw_input("Press Enter to send unlock code...") | |
print("") | |
#write data | |
ser.write("1-AGILE") | |
print("Unlocking U") | |
time.sleep(0.5) #give the serial port sometime to receive the data | |
ser.write("2-DRIVE") | |
print("Unlocking N") | |
time.sleep(0.5) #give the serial port sometime to receive the data | |
ser.write("3-MIGHT") | |
print("Unlocking I") | |
time.sleep(0.5) #give the serial port sometime to receive the data | |
ser.write("4-HEART") | |
print("Unlocking T") | |
time.sleep(0.5) #give the serial port sometime to receive the data | |
ser.write("5-VIGOR") | |
print("Unlocking E") | |
time.sleep(0.5) #give the serial port sometime to receive the data | |
print("") | |
ser.close() | |
except Exception, e1: | |
print "error communicating...: " + str(e1) | |
else: | |
print "cannot open serial port " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment