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