Skip to content

Instantly share code, notes, and snippets.

@sprout42
sprout42 / stm32duino-reset.py
Created June 12, 2020 16:11
Resets STM32F103C8 "bluepill" board into the bootloader
#!/usr/bin/env python
#
# Adapted from
# https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/2363e7bf8821067b78571ed16fbe397a541968a0/tools/macosx/src/upload-reset/upload-reset.c#L132
import time
import argparse
import serial
@sprout42
sprout42 / micocorruption_binary.py
Last active April 19, 2022 20:23 — forked from joshwatson/micocorruption_binary.py
Generate a Microcorruption Memory Dump (py3 compatible)
import os
import sys
import struct
import tempfile
import subprocess
from argparse import ArgumentParser
def decode_binary(input_file):
next_addr = 0
@sprout42
sprout42 / 3PO_challenge1.md
Last active August 12, 2021 16:00
GRIMM's 3PO Challenge 1

CAN Bus Reverse Engineering Challenge #1: Send the “Brake Fluid Low” Message

Prove it! Send the “brake fluid low” message to cause a spurious driver alert.

Background:

Automated embedded software is integrated from multiple sources, using a variety of code languages and practices - even in a single ECU. This creates major security risks where content comes together.

Setup:

These setup steps are only necessary if you are doing this on your own computer

@sprout42
sprout42 / 3PO_challenge2.md
Last active August 12, 2021 16:00
GRIMM's 3PO Challenge 2

CAN Bus Reverse Engineering Challenge #2: Find the Door Unlock Message

Prove it! Find the “unlock” message to gain access to the car!

Background:

Unlocking the doors through CAN message injection is the "hello world" of car hacking. Different vehicles have varying numbers of CAN buses, and send different messages on those buses. The number of messages sent on the vehicle bus make it seem overwhelming to identify which message will help you achieve your goal, but if you have physical access to a vehicle you can find the right message by:

@sprout42
sprout42 / install_binwalk.sh
Created October 19, 2021 15:50
Easy(est) Binwalk Install
#!/bin/bash
#
# requires git and docker to be installed
git clone https://github.com/ReFirmLabs.git -b v2.3.2 $HOME/.local/src
cd $HOME/.local/src/binwalk
docker build -t binwalk:latest .
alias binwalk &> /dev/null
if [ $? -eq 0 ]; then
@sprout42
sprout42 / floatstuff.py
Created October 22, 2021 18:41
Exploring floating point values
import struct
def single_info(val):
iee1754_val = struct.unpack('>I', struct.pack('>f', val))[0]
exp = (iee1754_val & 0x7F80_0000) >> 23
frac = iee1754_val & 0x007F_FFFF
result = (2**(exp-127)) * (1+(frac/(2**23)))
print('Single Precision:')
@sprout42
sprout42 / import_test.py
Last active November 12, 2021 15:27
import fun with python!
import builtins
_old_import = builtins.__import__
def _test_import(*args, **kwargs):
print('yo!', args, kwargs)
return _old_import(*args, **kwargs)
builtins.__import__ = _test_import
import os
print('done')
@sprout42
sprout42 / ubuntu_pipewire_install.md
Created December 6, 2021 16:13
Instructions to replace pulseaudio with pipewire
@sprout42
sprout42 / run_tests.py
Created June 2, 2022 14:46
Python unittest runner and debug tool
#!/usr/bin/env python
import gc
import os
import sys
import glob
import time
import os.path
import unittest
import unittest.case
@sprout42
sprout42 / python_crimes.py
Created September 3, 2022 01:55
fun with python
import builtins
_old_import = builtins.__import__
def _test_import(*args, **kwargs):
print('before!', args, kwargs)
# args 2 and 3 are dictionaries that have the namespace in them, remove
# evidence of our python crimes
for a in args:
if isinstance(a, dict) and '_old_import' in a:
del a['_old_import']
if isinstance(a, dict) and '_test_import' in a: