Skip to content

Instantly share code, notes, and snippets.

View DavidBuchanan314's full-sized avatar
🌍
Hack the planet!

David Buchanan DavidBuchanan314

🌍
Hack the planet!
View GitHub Profile
"""
31-round sha256 collision.
Not my research, just a PoC script I put together with numbers plugged in from the slide at
https://twitter.com/jedisct1/status/1772647350554464448 from FSE2024
SHA256 impl follows FIPS 180-4
https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
"""
@DavidBuchanan314
DavidBuchanan314 / widevine_fixup.py
Last active March 20, 2024 11:56
Patch aarch64 widevine blobs from ChromeOS to work on non-ChromeOS linux, including platforms with 16K page size like Apple Silicon / Asahi Linux
"""
MIT License
Copyright (c) 2023 David Buchanan
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
/*
Decompiled from GetMeIn: https://forum.xda-developers.com/web-os/general/getmein-one-time-rooting-jailbreaking-t3887904
tl;dr it scans memory for its own `struct cred` in memory, changes its uid/gids to root.
*/
int __fastcall do_the_patching(uint8_t *a1, unsigned __int8 *creds, int a3, unsigned int a4)
{
int i; // [sp+20h] [bp-Ch]
uint8_t *memptr; // [sp+24h] [bp-8h]

MD5 Collision with CRC32 Preimage

Here's the scenario: We want to craft two different messages with the same MD5 hash, and a specific CRC32 checksum, simultaneously.

In other words, we want an MD5 collision attack and a CRC32 preimage attack.

This might seem like a contrived scenario, but it's exactly the one I faced while producing my PNG hashquine (Yes OK maybe that's also a contrived scenario, cut me some slack).

On its own, a CRC32 preimage attack is trivial. You can craft a 4-byte suffix that gives any message a specific checksum, calculated using a closed-form expression (which I am too lazy to derive, not even with assistance from Z3). It's not an attack per-se, since CRC32 was never meant to be cryptograpically secure in the first place.

@DavidBuchanan314
DavidBuchanan314 / json_no_dupes.py
Last active February 23, 2024 11:03
How to ensure JSON has no duplicate map keys in Python 3.1+
from typing import List, Tuple, Any
import json
def ensure_no_duplicate_keys(object_pairs: List[Tuple[str, Any]]) -> dict:
value = dict(object_pairs)
if len(value) != len(object_pairs):
raise ValueError("Duplicate JSON map keys")
return value
if __name__ == "__main__":
import hashlib
from functools import reduce
inputs = """\
4194f2d3111228a07aeb0a54684fa4de21164109c4c789cd6b890771dbb3fff6
273853d452aec0d82d7599c043ec4bb55bf1f473a8d02302992f032e0804c02b
f4b264de9e84cd80c356712b686d9faff35dabb4221fd33966a18c9ddbe8a371
5f15dfdc4f1916427eb126f65d0b49ceba89db4653215fae7683b7c93ac733f7
78036761ae5ce55a3646baf06b0caf7301f7b060034c59bb097566c511f2c91d
7cb072d0b4be5eee1b115882d5655a588ad5ada350cfffb635216fa6cf871e91
@DavidBuchanan314
DavidBuchanan314 / README.md
Last active January 21, 2024 04:03
Classic iPod software reinstall/restore without iTunes, on Linux

iTunes-less Classic iPod Restore Guide

I have tested this on a classic 4th-gen monochrome "clickwheel" iPod. I imagine this process works similarly for iPods of the same era. I'm not the first person to do this, but a lot of documentation is on dead wikis and is generally hard to come by.

Extract your firmware image from an .ipsw file, set the IPOD and FW_IMAGE variables in the bash script, and run it as root. Then cross your fingers.

If everything worked, the partition layout should look something like this:

Disk /dev/sdc: 119.08 GiB, 127865454080 bytes, 249737215 sectors
@DavidBuchanan314
DavidBuchanan314 / Makefile
Last active January 16, 2024 12:40
simdutf incremental utf8 validation (proof-of-concept, not rigorously tested, see https://github.com/simdutf/simdutf/issues/361 )
CFLAGS := -Wall -Wextra -Wpedantic -O3
CXXFLAGS := ${CFLAGS}
LDFLAGS := -lsimdutf
main: main.o utf8_incremental.o

This is my best attempt at generating complete test vectors for the ML-KEM compress() and decompress() functions described by the FIPS 203 IPD.

This is has not (yet) been subject to cross-referencing against any other implementation. It may be incorrect!!!

If your implementation doesn't match up, please let me know.

["compress"][d][x] holds the result of compress_d(x)

["decompress"][d][y] holds the result of decompress_d(y)

"""
This pure-python ChaCha20 implementation reaches 32MiB/sec on my machine (M1 Pro)
otoh, cryptography.io's impl reaches about 1700MiB/s. Way faster, of course, but only about 50x faster.
This is code is a proof-of-concept and should not be used in a security context.
"""
CONST_MAGIC = b"expand 32-byte k"
CONST_WORDS = [int.from_bytes(CONST_MAGIC[i:i+4], "little") for i in range(0, 16, 4)]