-
-
Save shaiguitar/97b420482ad02fa9d4313b08c1a2f14b to your computer and use it in GitHub Desktop.
odrive-decrypt.py
This file contains 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
import sys | |
import pdb | |
import os | |
import base64 | |
import hashlib | |
from Crypto.Cipher import AES | |
def cp_trim_headers_to(filedst, filesrc, bytes_to_trim): | |
command = "dd bs=%s skip=1 if=%s of=%s" % (bytes_to_trim, filesrc, filedst) | |
print("Running: %s" % command) | |
os.system(command) | |
def print_variable(var, name): | |
print "Derived %s, len:" % name | |
print var | |
print len(var) | |
HEADER_SIZE_BYTES = 25 | |
SOURCE_PATH = "/Users/shai/Downloads/McFbqdhP_Ti8rM8a9lO7td1fP1_yf0uPkrOmHjrM_6hVBzIzO8CWfafrAzcuZPbxJdaxl1AtQeL-" | |
# | |
# START DO DECRYPTING WORK... | |
# | |
# get basic vars from crypto info from file header | |
with open(SOURCE_PATH, 'rb') as infile: | |
v = infile.read(1) | |
s = infile.read(8) | |
iv = infile.read(16) | |
print_variable(v, "v") | |
print_variable(s, "s") | |
print_variable(iv, "iv") | |
password = os.environ['ODRIVE_PASS'] | |
# Calculate a 256-bit key (K) using PBKDF2 with S and the user's passphrase (P) using HMAC-SHA256 for PRF | |
# Derive k using s & p | |
k = hashlib.pbkdf2_hmac('sha256', password, s, 1) | |
print_variable(k, "k") | |
# get crypto text. | |
# create file with just crypted text first | |
dest = "/tmp/%s.txt" % os.path.basename(SOURCE_PATH) | |
cp_trim_headers_to(dest, SOURCE_PATH, 25) | |
# CT | |
file = open(dest, 'rb') | |
cipher_text = file.read() | |
file.close() | |
# decrypt CT using K and IV | |
# enc = base64.b64decode(enc) | |
decryption_suite = AES.new(k, AES.MODE_CBC, iv) | |
decrypted = decryption_suite.decrypt(cipher_text) | |
print decrypted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment