[40] | 1 | #!/usr/bin/env python3 |
---|
[20] | 2 | |
---|
[40] | 3 | # Requires Python 3+ |
---|
[20] | 4 | |
---|
| 5 | ''' |
---|
| 6 | Simple decoder script; useful in shell scripts |
---|
| 7 | |
---|
| 8 | Copyright (C) 2011-2012 Virtual Security Research, LLC |
---|
| 9 | Author: Timothy D. Morgan |
---|
| 10 | |
---|
| 11 | This program is free software: you can redistribute it and/or modify |
---|
| 12 | it under the terms of the GNU Lesser General Public License, version 3, |
---|
| 13 | as published by the Free Software Foundation. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License |
---|
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 22 | ''' |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | import sys |
---|
| 26 | import argparse |
---|
| 27 | from bletchley import blobtools |
---|
| 28 | |
---|
| 29 | |
---|
[28] | 30 | parser = argparse.ArgumentParser( |
---|
| 31 | description='A simple encoder script that is useful in shell scripts.' |
---|
| 32 | ' For more information, see: http://code.google.com/p/bletchley/wiki/Overview') |
---|
| 33 | parser.add_argument( |
---|
| 34 | 'input_file', nargs='?', default=None, |
---|
| 35 | help='File containing encrypted blobs to analyze, one per line. ' |
---|
| 36 | 'Omit to read from stdin.') |
---|
| 37 | parser.add_argument( |
---|
| 38 | '-e', dest='encoding_chain', type=str, required=True, |
---|
| 39 | help='Comma-separated sequence of encoding formats used to encode the' |
---|
| 40 | ' token, starting with the last encoding to apply.' |
---|
| 41 | ' (Use "?" for a listing of supported encodings.)') |
---|
[20] | 42 | options = parser.parse_args() |
---|
| 43 | |
---|
[28] | 44 | if options.encoding_chain == '?': |
---|
| 45 | print('\n\t'.join(['Supported encodings:']+blobtools.supportedEncodings())) |
---|
| 46 | sys.exit(0) |
---|
| 47 | |
---|
[40] | 48 | input_file = sys.stdin.buffer |
---|
[20] | 49 | if options.input_file is not None: |
---|
[138] | 50 | input_file = open(options.input_file, 'rb') |
---|
[20] | 51 | |
---|
| 52 | blob = input_file.read() |
---|
| 53 | |
---|
| 54 | specified_encodings = options.encoding_chain.split(',') |
---|
| 55 | specified_encodings.reverse() |
---|
[28] | 56 | # XXX: report invalid encodings |
---|
[40] | 57 | sys.stdout.buffer.write(blobtools.encodeChain(specified_encodings, blob)) |
---|
| 58 | sys.stdout.buffer.write(b'\n') |
---|