From 23b0def882a2af9efaab93c2424bdcbdb3e42a9c Mon Sep 17 00:00:00 2001 From: DavidBrosnan Date: Tue, 18 Apr 2023 16:46:56 -0400 Subject: [PATCH 1/4] Allow easy adjustments of threshold_validity for more control --- xortool/args.py | 1 + xortool/tool_main.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) 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..b74df33 100755 --- a/xortool/tool_main.py +++ b/xortool/tool_main.py @@ -7,9 +7,9 @@ - guess the key (base on knowledge of most frequent char) 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] [-r PERCENT] [-m MAX-LEN] [-f] [-t CHARSET] [FILE] + xortool [-x] [-r PERCENT] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] + xortool [-x] [-r PERCENT] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [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: @@ -47,10 +48,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 +366,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): From 84431c7f4627c88e2a240e6cfe950d5a85df0c10 Mon Sep 17 00:00:00 2001 From: DavidBrosnan Date: Tue, 18 Apr 2023 17:08:51 -0400 Subject: [PATCH 2/4] Adjust README and add example --- README.md | 2 ++ xortool/tool_main.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78c51c1..a2b649b 100644 --- a/README.md +++ b/README.md @@ -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/tool_main.py b/xortool/tool_main.py index b74df33..dc43519 100755 --- a/xortool/tool_main.py +++ b/xortool/tool_main.py @@ -41,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 @@ -48,10 +49,10 @@ import string import sys -from xortool.args import( +from xortools.args import( parse_parameters, ArgError, - ) +) from xortool.charset import CharsetError from xortool.colors import ( From 30782d9251ce6043134ffaed23a7739aee8906d8 Mon Sep 17 00:00:00 2001 From: DavidBrosnan Date: Tue, 18 Apr 2023 17:17:01 -0400 Subject: [PATCH 3/4] Usage adjustments --- xortool/tool_main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xortool/tool_main.py b/xortool/tool_main.py index dc43519..e891224 100755 --- a/xortool/tool_main.py +++ b/xortool/tool_main.py @@ -7,9 +7,9 @@ - guess the key (base on knowledge of most frequent char) Usage: - xortool [-x] [-r PERCENT] [-m MAX-LEN] [-f] [-t CHARSET] [FILE] - xortool [-x] [-r PERCENT] [-l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] - xortool [-x] [-r PERCENT] [-m MAX-LEN| -l LEN] [-c CHAR | -b | -o] [-f] [-t CHARSET] [-p PLAIN] [FILE] + xortool [-x] [-m MAX-LEN] [-f] [-t CHARSET] [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 @@ -49,7 +49,7 @@ import string import sys -from xortools.args import( +from xortool.args import( parse_parameters, ArgError, ) From ad8de4b69da1b5dd9822f44d90a4215567fcdbc1 Mon Sep 17 00:00:00 2001 From: DavidBrosnan Date: Tue, 18 Apr 2023 17:17:36 -0400 Subject: [PATCH 4/4] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2b649b..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