Skip to content

Instantly share code, notes, and snippets.

@matthw
Created September 4, 2023 14:17
Show Gist options
  • Save matthw/6d720c5ebd4e7279b9de23a60053ef4a to your computer and use it in GitHub Desktop.
Save matthw/6d720c5ebd4e7279b9de23a60053ef4a to your computer and use it in GitHub Desktop.
sideways - downunder CTF 2023
from capstone import *
from unicorn import *
from unicorn.x86_const import *
import string
# opcodes for hash from 0x001089be to 0x01094cf
# ain't no time to rewrite big ass hash alg and hope for it to be correct :)
code = b'\x89\xc8\xf6\xe2\x84\xc0\x74\xba\x48\x89\xb4\x24\xd0\x00\x00\x00\x89\xcd\xc1\xe5\x08\x44\x8d\x04\x29\x41\x89\xd2\x41\xc1\xe2\x10\x45\x09\xd0\x41\x89\xd1\x41\xc1\xe1\x18\x89\xce\xc1\xe6\x10\x45\x8d\x24\x31\x45\x8d\x1c\x2c\x41\x89\xcf\x41\xc1\xe7\x18\x44\x09\xfe\x44\x8d\x2c\x2e\x45\x09\xd7\x45\x8d\x34\x2f\x89\xd7\xc1\xe7\x08\x09\xfe\x45\x09\xca\x44\x09\xd5\x41\x09\xfa\x41\x09\xff\x44\x09\xe7\x43\x8d\x1c\x01\x81\xc3\x5b\x39\xae\x4d\x48\x89\x9c\x24\xd8\x01\x00\x00\x43\x8d\x9c\x01\xf3\xa9\x5a\x86\x48\x89\x9c\x24\xd0\x01\x00\x00\x43\x8d\x9c\x01\x5e\x26\x54\x36\x89\x9c\x24\xa4\x00\x00\x00\x43\x8d\x9c\x01\xdc\x63\xe7\x52\x48\x89\x9c\x24\xc8\x01\x00\x00\x41\x8d\x1c\x13\x48\x89\x9c\x24\xc0\x01\x00\x00\x42\x8d\x9c\x1a\x1b\xf5\xca\x22\x48\x89\x9c\x24\xb8\x01\x00\x00\x42\x8d\x9c\x1a\x5f\xb9\xd2\x17\x89\x9c\x24\xa0\x00\x00\x00\x42\x8d\x9c\x1a\x5d\xc7\xc3\x04\x89\x9c\x24\x9c\x00\x00\x00\x41\x8d\x5c\x15\x00\x48\x89\x9c\x24\xb0\x01\x00\x00\x42\x8d\x9c\x2a\x69\x39\x93\x47\x89\x9c\x24\x98\x00\x00\x00\x42\x8d\x9c\x2a\xec\x3d\x88\xaf\x89\x9c\x24\x94\x00\x00\x00\x42\x8d\x9c\x2a\xa5\xec\xed\x90\x48\x89\x9c\x24\xa8\x01\x00\x00\x42\x8d\x9c\x2a\x54\x17\xe6\x9e\x48\x89\x9c\x24\xa0\x01\x00\x00\x42\x8d\x9c\x2a\xfa\xff\x4d\xae\x48\x89\x9c\x24\x98\x01\x00\x00\x42\x8d\x9c\x2a\x32\x4d\x7e\x33\x48\x89\x9c\x24\x90\x01\x00\x00\x42\x8d\x9c\x2a\x54\xaf\xe5\x06\x89\x9c\x24\x90\x00\x00\x00\x42\x8d\x9c\x2a\x09\xcd\xa4\xce\x89\x9c\x24\x8c\x00\x00\x00\x42\x8d\x9c\x2a\x87\x47\x5c\x7d\x48\x89\x9c\x24\x88\x01\x00\x00\x42\x8d\x9c\x2a\x32\x59\x63\xd6\x48\x89\x9c\x24\x80\x01\x00\x00\x42\x8d\x9c\x2a\x3e\x3e\x89\xe6\x48\x89\x9c\x24\x78\x01\x00\x00\x8d\x5c\x15\x00\x89\x9c\x24\x88\x00\x00\x00\x8d\x9c\x2a\x79\xc3\x7b\x72\x89\x9c\x24\x84\x00\x00\x00\x8d\x9c\x2a\x8d\x72\xb2\x8e\x48\x89\x9c\x24\x70\x01\x00\x00\x8d\x9c\x2a\x6c\xbb\xf0\xe9\x48\x89\x9c\x24\x68\x01\x00\x00\x8d\x9c\x2a\x39\xd2\x65\x30\x89\x9c\x24\x80\x00\x00\x00\x8d\x9c\x2a\xea\x65\xce\x5c\x89\x5c\x24\x7c\x8d\x9c\x2a\xd8\x9a\xcd\xc3\x48\x89\x9c\x24\x60\x01\x00\x00\x8d\xac\x2a\xd8\x29\xf6\x68\x48\x89\xac\x24\x58\x01\x00\x00\x41\x8d\x2c\x16\x48\x89\xac\x24\x50\x01\x00\x00\x42\x8d\xac\x32\x10\xc0\x6c\xd1\x89\x6c\x24\x78\x42\x8d\xac\x32\x26\x12\x54\x60\x48\x89\xac\x24\x48\x01\x00\x00\x42\x8d\xac\x32\x87\x67\xa1\x6e\x48\x89\xac\x24\x40\x01\x00\x00\x42\x8d\xac\x32\xb2\xca\x7b\x95\x89\x6c\x24\x74\x42\x8d\xac\x32\xa9\x05\x32\x01\x89\x6c\x24\x70\x42\x8d\xac\x32\x3b\x61\x11\x3e\x48\x89\xac\x24\x38\x01\x00\x00\x42\x8d\xac\x32\x27\x54\xd7\xb1\x48\x89\xac\x24\x30\x01\x00\x00\x8d\xac\x32\xba\x5d\x52\xc4\x89\x6c\x24\x6c\x8d\xac\x32\x63\x3c\xed\x29\x89\x6c\x24\x68\x8d\xac\x32\x56\xc6\xc8\xad\x89\x6c\x24\x64\x8d\xac\x32\xe4\x14\x3b\xdb\x48\x89\xac\x24\x28\x01\x00\x00\x8d\xac\x32\x03\xa2\x29\x14\x89\x6c\x24\x60\x8d\xac\x32\xd5\x76\x81\x2b\x89\x6c\x24\x5c\x8d\xac\x32\xd8\x19\xa7\x1c\x48\x89\xac\x24\x20\x01\x00\x00\x8d\x94\x32\xc8\xca\xbd\xf8\x48\x89\x94\x24\x18\x01\x00\x00\x8d\x94\x31\x7f\xd3\x52\x9d\x48\x89\x94\x24\x10\x01\x00\x00\x8d\x94\x31\xa3\x3c\xe6\x50\x89\x54\x24\x58\x8d\x14\x31\x81\xc2\x97\x89\x5f\x30\x48\x89\x94\x24\x08\x01\x00\x00\x09\xce\x42\x8d\x14\x39\x81\xc2\xb8\xfc\x33\x97\x89\x54\x24\x54\x42\x8d\x94\x39\xc3\x35\xc5\x18\x48\x89\x94\x24\x00\x01\x00\x00\x42\x8d\x94\x39\x31\x51\x30\x9c\x89\x54\x24\x50\x42\x8d\x94\x39\x5a\xb6\x11\x41\x48\x89\x94\x24\xf8\x00\x00\x00\x8d\x94\x39\xf5\x2a\x4a\xa6\x89\x54\x24\x4c\x8d\x94\x39\xe0\x1e\xae\x70\x89\x54\x24\x48\x8d\x94\x39\xfd\xab\xc0\xe0\x89\x54\x24\x44\x8d\x94\x39\x96\xeb\xd8\x75\x48\x89\x94\x24\xf0\x00\x00\x00\x8d\x94\x39\x08\xbc\x4e\xe2\x89\x54\x24\x40\x8d\x94\x39\xd6\x92\xe7\x7f\x89\x54\x24\x3c\x8d\x94\x39\xff\x72\xd7\xb9\x48\x89\x94\x24\xe8\x00\x00\x00\x8d\x94\x39\x9c\x8c\x57\xa1\x48\x89\x94\x24\xe0\x00\x00\x00\x42\x8d\x94\x11\xca\x21\x3a\x4b\x89\x54\x24\x38\x42\x8d\x94\x11\xc8\x8d\x82\x6c\x48\x89\x94\x24\xd8\x00\x00\x00\x46\x8d\x8c\x11\xeb\xe0\xdf\x9e\x46\x8d\x94\x11\xb2\xa3\xd1\x53\x41\xbb\xdc\xdc\x84\xb4\x41\xbf\xbf\xd5\xe4\x3b\x41\xb8\x1f\x22\x5f\x7e\xbd\xf4\x3f\xde\x81\x66\x66\x66\x2e\x0f\x1f\x84\x00\x00\x00\x00\x00\x45\x89\xdd\x45\x89\xfe\x41\x89\xec\x44\x89\xc2\x44\x21\xfa\x44\x89\xc7\xf7\xd7\x44\x21\xdf\x01\xea\x01\xfa\x48\x8b\x8c\x24\xc0\x01\x00\x00\x8d\x2c\x11\x81\xc5\xc4\x2e\xcb\x3b\xc1\xc5\x07\x44\x01\xc5\x89\xea\x44\x21\xc2\x89\xef\xf7\xd7\x44\x21\xff\x48\x8b\x8c\x24\xb0\x01\x00\x00\x44\x01\xef\x01\xcf\x01\xd7\x81\xc7\xad\x7d\xdc\x97\xc1\xc7\x0c\x01\xef\x89\xfa\x21\xea\x89\xfb\xf7\xd3\x44\x21\xc3\x48\x8b\x8c\x24\x50\x01\x00\x00\x44\x01\xf1\x01\xcb\x44\x8d\x1c\x1a\x41\x81\xc3\xd8\x88\xbf\x7f\x41\xc1\xc3\x11\x41\x01\xfb\x44\x89\xd9\x21\xf9\x44\x89\xda\xf7\xd2\x21\xea\x44\x01\xc2\x01\xf2\x01\xca\x81\xc2\x9e\x12\x7f\x57\xc1\xc2\x16\x44\x01\xda\x89\xd1\x44\x21\xd9\x89\xd3\xf7\xd3\x21\xfb\x03\xac\x24\x88\x00\x00\x00\x01\xdd\x01\xcd\x81\xc5\x31\xbb\xd9\x91\xc1\xc5\x07\x01\xd5\x89\xe9\x21\xd1\x89\xeb\xf7\xd3\x44\x21\xdb\x03\xbc\x24\x98\x00\x00\x00\x01\xdf\x01\xcf\xc1\xc7\x0c\x01\xef\x89\xf9\x21\xe9\x89\xfb\xf7\xd3\x21\xd3\x44\x03\x5c\x24\x6c\x41\x01\xdb\x41\x01\xcb\x41\xc1\xc3\x11\x41\x01\xfb\x44\x89\xd9\x21\xf9\x44\x89\xdb\xf7\xd3\x21\xeb\x03\x94\x24\x94\x00\x00\x00\x01\xda\x01\xca\xc1\xc2\x16\x44\x01\xda\x89\xd1\x44\x21\xd9\x89\xd3\xf7\xd3\x21\xfb\x03\x6c\x24\x78\x01\xdd\x01\xcd\xc1\xc5\x07\x01\xd5\x89\xe9\x21\xd1\x89\xeb\xf7\xd3\x44\x21\xdb\x03\x7c\x24\x38\x01\xdf\x01\xcf\xc1\xc7\x0c\x01\xef\x89\xf9\x21\xe9\x89\xfb\xf7\xd3\x21\xd3\x44\x03\x5c\x24\x54\x41\x01\xdb\x41\x01\xcb\x41\xc1\xc3\x11\x41\x01\xfb\x44\x89\xd9\x21\xf9\x44\x89\xdb\xf7\xd3\x21\xeb\x03\x54\x24\x4c\x01\xda\x01\xca\xc1\xc2\x16\x44\x01\xda\x89\xd1\x44\x21\xd9\x89\xd3\xf7\xd3\x21\xfb\x03\x6c\x24\x68\x01\xdd\x01\xcd\xc1\xc5\x07\x01\xd5\x89\xe9\x21\xd1\x89\xeb\xf7\xd3\x44\x21\xdb\x03\x7c\x24\x48\x01\xdf\x01\xcf\xc1\xc7\x0c\x01\xef\x89\xf9\x21\xe9\x41\x89\xff\x41\xf7\xd7\x48\x8b\x9c\x24\xd8\x01\x00\x00\x01\xd3\x44\x21\xfa\x44\x03\x9c\x24\x84\x00\x00\x00\x41\x01\xd3\x41\x01\xcb\x41\xc1\xc3\x11\x41\x01\xfb\x44\x89\xda\xf7\xd2\x48\x8b\x8c\x24\xa8\x01\x00\x00\x01\xe9\x21\xd5\x01\xdd\x44\x89\xdb\x21\xfb\x01\xdd\xc1\xc5\x16\x44\x01\xdd\x45\x21\xdf\x41\x01\xcf\x89\xe9\x21\xf9\x41\x01\xcf\x41\xc1\xc7\x05\x41\x01\xef\x44\x89\xf9\x44\x21\xd9\x21\xea\x03\x7c\x24\x64\x01\xd7\x01\xcf\xc1\xc7\x09\x44\x01\xff\x89\xf9\x21\xe9\x48\x8b\x94\x24\xb8\x01\x00\x00\x01\xea\xf7\xd5\x44\x21\xfd\x44\x03\x5c\x24\x44\x41\x01\xeb\x41\x01\xcb\x41\xc1\xc3\x0e\x41\x01\xfb\x44\x89\xd9\x44\x21\xf9\x48\x8b\x9c\x24\xa0\x01\x00\x00\x44\x01\xfb\x41\xf7\xd7\x41\x21\xff\x41\x01\xd7\x41\x01\xcf\x41\xc1\xc7\x14\x45\x01\xdf\x44\x89\xf9\x21\xf9\x48\x8b\x94\x24\x00\x01\x00\x00\x01\xfa\xf7\xd7\x44\x21\xdf\x01\xdf\x01\xcf\xc1\xc7\x05\x44\x01\xff\x89\xf9\x44\x21\xd9\x48\x8b\x9c\x24\xd0\x01\x00\x00\x44\x01\xdb\x41\xf7\xd3\x45\x21\xfb\x41\x01\xd3\x41\x01\xcb\x41\xc1\xc3\x09\x41\x01\xfb\x44\x89\xd9\x44\x21\xf9\x48\x8b\x94\x24\x70\x01\x00\x00\x44\x01\xfa\x41\xf7\xd7\x41\x21\xff\x41\x01\xdf\x41\x01\xcf\x41\xc1\xc7\x0e\x45\x01\xdf\x44\x89\xf9\x21\xf9\x48\x8b\x9c\x24\xd8\x00\x00\x00\x01\xfb\xf7\xd7\x44\x21\xdf\x01\xd7\x01\xcf\xc1\xc7\x14\x44\x01\xff\x89\xf9\x44\x21\xd9\x48\x8b\x94\x24\x68\x01\x00\x00\x44\x01\xda\x41\xf7\xd3\x45\x21\xfb\x41\x01\xdb\x41\x01\xcb\x41\xc1\xc3\x05\x41\x01\xfb\x44\x89\xd9\x44\x21\xf9\x48\x8b\x9c\x24\x10\x01\x00\x00\x44\x01\xfb\x41\xf7\xd7\x41\x21\xff\x41\x01\xd7\x41\x01\xcf\x41\xc1\xc7\x09\x45\x01\xdf\x44\x89\xf9\x21\xf9\x48\x8b\x94\x24\x48\x01\x00\x00\x01\xfa\xf7\xd7\x44\x21\xdf\x01\xdf\x01\xcf\xc1\xc7\x0e\x44\x01\xff\x89\xf9\x44\x21\xd9\x48\x8b\x9c\x24\xf0\x00\x00\x00\x44\x01\xdb\x41\xf7\xd3\x45\x21\xfb\x41\x01\xd3\x41\x01\xcb\x41\xc1\xc3\x14\x41\x01\xfb\x44\x89\xd9\x44\x21\xf9\x48\x8b\x94\x24\x40\x01\x00\x00\x44\x01\xfa\x41\xf7\xd7\x41\x21\xff\x41\x01\xdf\x41\x01\xcf\x41\xc1\xc7\x05\x45\x01\xdf\x44\x89\xf9\x21\xf9\x48\x8b\x9c\x24\x98\x01\x00\x00\x01\xfb\xf7\xd7\x44\x21\xdf\x01\xd7\x01\xcf\xc1\xc7\x09\x44\x01\xff\x89\xf9\x44\x21\xd9\x48\x8b\x94\x24\x28\x01\x00\x00\x44\x01\xda\x41\xf7\xd3\x45\x21\xfb\x41\x01\xdb\x41\x01\xcb\x41\xc1\xc3\x0e\x41\x01\xfb\x44\x89\xd9\x44\x21\xf9\x48\x8b\x9c\x24\x90\x01\x00\x00\x44\x01\xfb\x41\xf7\xd7\x41\x21\xff\x41\x01\xd7\x41\x01\xcf\x41\xc1\xc7\x14\x45\x01\xdf\x44\x89\xf9\x44\x31\xd9\x89\xcd\x31\xfd\x01\xdd\xc1\xc5\x04\x44\x01\xfd\x31\xe9\x03\x7c\x24\x74\x01\xcf\xc1\xc7\x0b\x01\xef\x89\xf9\x31\xe9\x89\xca\x44\x31\xfa\x44\x03\x5c\x24\x40\x41\x01\xd3\x41\xc1\xc3\x10\x41\x01\xfb\x44\x31\xd9\x44\x03\xbc\x24\x80\x00\x00\x00\x41\x01\xcf\x41\xc1\xc7\x17\x45\x01\xdf\x44\x89\xf9\x44\x31\xd9\x89\xca\x31\xfa\x03\xac\x24\x90\x00\x00\x00\x01\xd5\xc1\xc5\x04\x44\x01\xfd\x31\xe9\x03\x7c\x24\x7c\x01\xcf\xc1\xc7\x0b\x01\xef\x89\xf9\x31\xe9\x89\xca\x44\x31\xfa\x44\x03\x9c\x24\x8c\x00\x00\x00\x41\x01\xd3\x41\xc1\xc3\x10\x41\x01\xfb\x44\x31\xd9\x44\x03\x7c\x24\x50\x41\x01\xcf\x41\xc1\xc7\x17\x45\x01\xdf\x44\x89\xf9\x44\x31\xd9\x89\xca\x31\xfa\x03\x6c\x24\x3c\x01\xd5\xc1\xc5\x04\x44\x01\xfd\x31\xe9\x03\xbc\x24\xa0\x00\x00\x00\x01\xcf\xc1\xc7\x0b\x01\xef\x89\xe9\x44\x31\xf9\x31\xf9\x44\x03\x5c\x24\x58\x41\x01\xcb\x41\xc1\xc3\x10\x41\x01\xfb\x89\xf9\x31\xe9\x44\x31\xd9\x44\x03\x7c\x24\x60\x41\x01\xcf\x41\xc1\xc7\x17\x45\x01\xdf\x44\x89\xd9\x31\xf9\x44\x31\xf9\x44\x01\xcd\x01\xcd\xc1\xc5\x04\x44\x01\xfd\x44\x89\xf9\x44\x31\xd9\x31\xe9\x03\x7c\x24\x5c\x01\xcf\xc1\xc7\x0b\x01\xef\x89\xe9\x44\x31\xf9\x31\xf9\x44\x03\x9c\x24\xa4\x00\x00\x00\x41\x01\xcb\x41\xc1\xc3\x10\x41\x01\xfb\x89\xf9\x31\xe9\x44\x31\xd9\x44\x03\x7c\x24\x70\x41\x01\xcf\x41\xc1\xc7\x17\x45\x01\xdf\x48\x8b\x8c\x24\x88\x01\x00\x00\x01\xf9\xf7\xd7\x44\x09\xff\x44\x31\xdf\x03\xac\x24\x9c\x00\x00\x00\x01\xfd\xc1\xc5\x06\x44\x01\xfd\x48\x8b\x94\x24\x60\x01\x00\x00\x44\x01\xda\x41\xf7\xd3\x41\x09\xeb\x45\x31\xfb\x41\x01\xcb\x41\xc1\xc3\x0a\x41\x01\xeb\x48\x8b\x8c\x24\x80\x01\x00\x00\x44\x01\xf9\x41\xf7\xd7\x45\x09\xdf\x41\x31\xef\x41\x01\xd7\x41\xc1\xc7\x0f\x45\x01\xdf\x48\x8b\x94\x24\x20\x01\x00\x00\x01\xea\xf7\xd5\x44\x09\xfd\x44\x31\xdd\x01\xcd\xc1\xc5\x15\x44\x01\xfd\x48\x8b\x8c\x24\x08\x01\x00\x00\x44\x01\xd9\x41\xf7\xd3\x41\x09\xeb\x45\x31\xfb\x41\x01\xd3\x41\xc1\xc3\x06\x41\x01\xeb\x48\x8b\x94\x24\xf8\x00\x00\x00\x44\x01\xfa\x41\xf7\xd7\x45\x09\xdf\x41\x31\xef\x41\x01\xcf\x41\xc1\xc7\x0a\x45\x01\xdf\x48\x8b\x8c\x24\x78\x01\x00\x00\x01\xe9\xf7\xd5\x44\x09\xfd\x44\x31\xdd\x01\xd5\xc1\xc5\x0f\x44\x01\xfd\x48\x8b\x94\x24\x38\x01\x00\x00\x44\x01\xda\x41\xf7\xd3\x41\x09\xeb\x45\x31\xfb\x41\x01\xcb\x41\xc1\xc3\x15\x41\x01\xeb\x48\x8b\x8c\x24\xc8\x01\x00\x00\x44\x01\xf9\x41\xf7\xd7\x45\x09\xdf\x41\x31\xef\x41\x01\xd7\x41\xc1\xc7\x06\x45\x01\xdf\x48\x8b\x94\x24\x18\x01\x00\x00\x01\xea\xf7\xd5\x44\x09\xfd\x44\x31\xdd\x01\xcd\xc1\xc5\x0a\x44\x01\xfd\x48\x8b\x8c\x24\xe8\x00\x00\x00\x44\x01\xd9\x41\xf7\xd3\x41\x09\xeb\x45\x31\xfb\x41\x01\xd3\x41\xc1\xc3\x0f\x41\x01\xeb\x48\x8b\x94\x24\x58\x01\x00\x00\x44\x01\xfa\x41\xf7\xd7\x45\x09\xdf\x41\x31\xef\x41\x01\xcf\x41\xc1\xc7\x15\x45\x01\xdf\x48\x8b\x8c\x24\xe0\x00\x00\x00\x01\xe9\xf7\xd5\x44\x09\xfd\x44\x31\xdd\x01\xd5\xc1\xc5\x06\x44\x01\xfd\x48\x8b\x94\x24\x30\x01\x00\x00\x44\x01\xda\x41\xf7\xd3\x41\x09\xeb\x45\x31\xfb\x41\x01\xcb\x41\xc1\xc3\x0a\x41\x01\xeb\x43\x8d\x0c\x3a\x41\xf7\xd7\x45\x09\xdf\x41\x31\xef\x41\x01\xd7\x41\xc1\xc7\x0f\x45\x01\xdf\x89\xea\xf7\xd2\x44\x09\xfa\x44\x31\xda\x01\xca\x44\x01\xe5\xc1\xc2\x15\x45\x01\xf8\x41\x01\xd0\x45\x01\xf7\x45\x01\xeb\xfe\xc8\x0f\x85\xe7\xf8\xff\xff\x41\x31\xeb\x45\x31\xfb\x45\x31\xc3'
def disas_single(code, addr):
md = Cs(CS_ARCH_X86, CS_MODE_64)
for i in md.disasm(code, addr):
return (i.address, i.mnemonic, i.op_str)
def hook_code(mu, addr, size, user_data):
mem = mu.mem_read(addr, size)
dis = disas_single(mem, addr)
addr, mnemonic, op_str = dis
print("0x%x\t%s\t%s"%(addr, mnemonic, op_str))
#print(hex(mu.reg_read(UC_X86_REG_R8D)))
#print(hex(mu.reg_read(UC_X86_REG_RBP)))
def hash_calc(a, b):
ADDR_TEXT = 0x400000
ADDR_STACK = 0xa00000
mu = Uc(UC_ARCH_X86, UC_MODE_64)
mu.mem_map(ADDR_TEXT, 0x300000)
mu.mem_map(ADDR_STACK, 0x10000)
mu.mem_write(ADDR_TEXT, code)
rsp = ADDR_STACK + 0x400
rbp = ADDR_STACK + 0x1000
mu.reg_write(UC_X86_REG_RBP, rbp)
mu.reg_write(UC_X86_REG_RSP, rsp)
# setup register with input chars
mu.reg_write(UC_X86_REG_ECX, ord(a))
mu.reg_write(UC_X86_REG_EDX, ord(b))
# good to debug but slow things down
#mu.hook_add(UC_HOOK_CODE, hook_code)
mu.emu_start(ADDR_TEXT, ADDR_TEXT+len(code))
# result hash is in r11d
return mu.reg_read(UC_X86_REG_R11D)
target_hashes = [3684424461, 266244018, 3392641979, 2896963000, 1179637477, 1381517329, 3799892737, 1441041400, 194527636, 2990190055, 463283761, 4256548044, 2748753331]
all_hashes = {}
# build rainbow table of hashes for all char pairs
rg = string.printable[:-6]
for a in rg:
for b in rg:
try:
h = hash_calc(a, b)
all_hashes[h] = [a, b]
except:
# sometime it fails but whatever :)
h = -1
# lookup to get flag
start = ""
end = ""
for h in target_hashes:
s, e = all_hashes[h]
start += s
end += e
print(start + end[::-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment