Created
March 27, 2019 05:21
-
-
Save theoremoon/edb18da90ed1644c866c6731438f1d71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 subprocess | |
| import sys | |
| import os | |
| from itertools import product | |
| OUTPUT_DIR = 'decrypted_files' | |
| # list up all cipher methods and digest algorithms | |
| lines = subprocess.run(['openssl', 'help'], check=True, stderr=subprocess.PIPE).stderr.decode().splitlines() | |
| ciphers = [] | |
| digests = [''] | |
| mode = 0 | |
| for l in lines: | |
| if l.startswith('Message Digest commands'): | |
| mode = 1 | |
| elif l.startswith('Cipher commands'): | |
| mode = 2 | |
| elif mode == 1: | |
| digests.extend(l.split()) | |
| elif mode == 2: | |
| ciphers.extend(l.split()) | |
| # make output directory | |
| try: | |
| os.mkdir(OUTPUT_DIR) | |
| except FileExistsError: | |
| pass | |
| # try all cipher methods and digest algorithms for decrypt | |
| for pattern in product(ciphers, digests): | |
| cipher, digest = pattern | |
| out_name = os.path.join(OUTPUT_DIR, cipher+'_'+digest) | |
| base_cmd = ['openssl', cipher.lstrip('-'), '-d', '-out', out_name] | |
| digest_opt = ['-md', digest] if digest else [] | |
| # call openssl | |
| try: | |
| out = subprocess.run(base_cmd + digest_opt + sys.argv[1:], check=True, stderr=subprocess.PIPE).stderr.decode() | |
| except subprocess.CalledProcessError: | |
| try: | |
| os.remove(out_name) | |
| except OSError: | |
| pass |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 try-all-openssl.py -in flag.html.enc -pass file:./key