diff --git a/README.md b/README.md index 78c51c1..ab46c83 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ xortool Usage: xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE] - xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] - xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] + xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE] + xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE] xortool [-h | --help] xortool --version @@ -43,6 +43,7 @@ Options: -f --filter-output filter outputs based on the charset -t CHARSET --text-charset=CHARSET target text character set [default: printable] -p PLAIN --known-plaintext=PLAIN use known plaintext for decoding + -r PERCENT, --threshold=PERCENT threshold validity percentage [default: 95] -h --help show this help Notes: @@ -61,6 +62,7 @@ Examples: xortool -x -c ' ' file.hex xortool -b -f -l 23 -t base64 message.enc xortool -b -p "xctf{" message.enc + xortool -r 80 -p "flag{" -c ' ' message.enc ``` Example 1 diff --git a/xortool/args.py b/xortool/args.py index 78587d5..035cd23 100644 --- a/xortool/args.py +++ b/xortool/args.py @@ -47,6 +47,7 @@ def parse_parameters(doc, version): "most_frequent_char": parse_char(p["char"]), "text_charset": get_charset(p["text-charset"]), "known_plain": p["known-plaintext"].encode() if p["known-plaintext"] else False, + "threshold": parse_int(p["threshold"]), } except ValueError as err: raise ArgError(str(err)) diff --git a/xortool/tool_main.py b/xortool/tool_main.py index 5620d3d..e891224 100755 --- a/xortool/tool_main.py +++ b/xortool/tool_main.py @@ -8,8 +8,8 @@ Usage: xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [FILE] - xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] - xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] + xortool [-x] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE] + xortool [-x] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [-r PERCENT] [FILE] xortool [-h | --help] xortool --version @@ -23,6 +23,7 @@ -f --filter-output filter outputs based on the charset -t CHARSET --text-charset=CHARSET target text character set [default: printable] -p PLAIN --known-plaintext=PLAIN use known plaintext for decoding + -r PERCENT, --threshold=PERCENT threshold validity percentage [default: 95] -h --help show this help Notes: @@ -40,6 +41,7 @@ xortool -l 11 -c 20 file.bin xortool -x -c ' ' file.hex xortool -b -f -l 23 -t base64 message.enc + xortool -r 80 -p "flag{{" -c ' ' message.enc """ from operator import itemgetter @@ -47,10 +49,11 @@ import string import sys -from xortool.args import ( +from xortool.args import( parse_parameters, ArgError, ) + from xortool.charset import CharsetError from xortool.colors import ( COLORS, @@ -364,7 +367,12 @@ def produce_plaintexts(ciphertext, keys, key_char_used): key_mapping.write("file_name;key_repr\n") perc_mapping.write("file_name;char_used;perc_valid\n") - threshold_valid = 95 + + if PARAMETERS["threshold"]: + threshold_valid = PARAMETERS["threshold"] + else: + threshold_valid = 95 + count_valid = 0 for index, key in enumerate(keys):