├── .gitignore ├── LICENSE ├── README.md ├── decoder ├── __init__.py └── decoder.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | decoder.egg-info/ 2 | dist/ 3 | 4 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Syed Umar Arfeen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Decoder 2 | > Automating the Manual :) 3 | 4 | [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) 5 | ![GitHub](https://img.shields.io/github/license/Anon-Exploiter/decoder) 6 | [![Contributors][contributors-shield]][contributors-url] 7 | ![GitHub closed issues](https://img.shields.io/github/issues-closed/Anon-Exploiter/decoder) 8 | [![GitHub pull requests](https://img.shields.io/github/issues-pr/Anon-Exploiter/decoder.svg?style=flat)]() 9 | [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=%40syed_umar)](https://twitter.com/syed__umar) 10 | 11 | [contributors-shield]: https://img.shields.io/github/contributors/Anon-Exploiter/decoder.svg?style=flat-square 12 | [contributors-url]: https://github.com/Anon-Exploiter/decoder/graphs/contributors 13 | [issues-shield]: https://img.shields.io/github/issues/Anon-Exploiter/decoder.svg?style=flat-square 14 | [issues-url]: https://github.com/Anon-Exploiter/decoder/issues 15 | 16 | ![image](https://user-images.githubusercontent.com/18597330/114323816-7484bb00-9b40-11eb-9f97-4d1ea6cc4c18.png) 17 | 18 | A simple script to try and decode a string in various encoding mechanisms regardless of it's (original) type. 19 | 20 | The one-liner doesn't make much sense right? Don't worry, I gotcha! 21 | 22 | Let's say you've a string _(you obtained from somewhere, maybe a boot2root machine, ctf, etc.)_, you know it's encoded _(isn't a hash and is not encrypted)_ but just can't figure out the encoding mechanism used? No worries, this script will try and decode it in most used encoding mechanisms (i.e. base64, rot47, atbash, etc.) 23 | 24 | Once the results come back, make sure to go through each and every line! That's all manual :3 25 | 26 | The script for now only supports: 27 | 28 | - Base16 29 | - Base32 30 | - Base64 31 | - Base85 32 | - Atbash 33 | - Baconian 34 | - Caesar 35 | - Morse 36 | - Rot13 37 | - Rot47 38 | 39 | ### Tested On (OS & Python version) 40 | - Ubuntu 20.04 LTS -- Python 3.8.5 41 | - Arch Linux -- Python 3.9.2 42 | 43 | ### Downloading & Installation 44 | ```csharp 45 | pip3 install decoder 46 | ``` 47 | 48 | OR 49 | 50 | ```csharp 51 | git clone https://github.com/Anon-Exploiter/decoder/ 52 | cd decoder/ 53 | python3 setup.py build 54 | python3 setup.py install 55 | ``` 56 | 57 | ### Usage 58 | 59 | Decoding a string from directly from argument: 60 | ```bash 61 | decoder -s 'uryyb' 62 | ``` 63 | 64 | Decoding a string from a file: 65 | ```bash 66 | decoder -f rot47-encoded.txt 67 | ``` 68 | 69 | ### Todos 70 | - Add Colors 71 | - Utilize internal libraries to add all the decoding (rather than custom written code) 72 | 73 | ### Filing Bugs/Contribution 74 | Feel free to file a issue or create a PR for that issue if you come across any. 75 | 76 | ### Screenshots 77 | ![image](https://user-images.githubusercontent.com/18597330/114323608-6a15f180-9b3f-11eb-8eb8-0455cddcf08b.png) 78 | 79 | ![image](https://user-images.githubusercontent.com/18597330/114323624-7dc15800-9b3f-11eb-95e7-185c363361b7.png) 80 | 81 | ![image](https://user-images.githubusercontent.com/18597330/114323651-992c6300-9b3f-11eb-9191-3ecb7a353976.png) 82 | 83 | ### Contributors 84 | - [@thehackersbrain](https://twitter.com/thehackersbrain) - [#2](https://github.com/Anon-Exploiter/decoder/pull/2) - Coloring output and refactoring whole code base! 85 | 86 | ### Credits 87 | - Big thanks to [autodecoder](https://github.com/oreosES/autodecoder) (was a lot of help while writing this) 88 | - Thanks to [@thehackersbrain](https://twitter.com/thehackersbrain)'s [Blogger](https://www.vulnhub.com/series/blogger,462/) machine which made me write this 89 | 90 | #### Well this is shit work, any other tools which have the same functionality and actually work? Yes! 91 | - https://github.com/oreosES/autodecoder 92 | - https://github.com/Ciphey/Ciphey 93 | -------------------------------------------------------------------------------- /decoder/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anon-Exploiter/decoder/fe41c1804c068c98433de4cd7f22fa31a568a8a1/decoder/__init__.py -------------------------------------------------------------------------------- /decoder/decoder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | from termcolor import colored 4 | from codecs import encode 5 | 6 | import argparse 7 | import base64 8 | import pycipher 9 | 10 | """ 11 | Supported Encodings (for now -- add a request through issues!) 12 | - base16 13 | - base32 14 | - base64 15 | - base85 16 | - atbash 17 | - baconian 18 | - caesar 19 | - morse 20 | - rot13 21 | - rot47 22 | """ 23 | 24 | def addArguments(): 25 | # -------------------------------------------------\n\tStrings Decoder\n-------------------------------------------------\n\n 26 | parser = argparse.ArgumentParser(description='', usage=f'\r[#] Usage: python3 decoder.py --file file.txt') 27 | parser._optionals.title = "Basic Help" 28 | 29 | opts = parser.add_argument_group(f'Arguments') 30 | opts.add_argument('-s', '--string', action="store", dest="string", default=False, help='String to decode!') 31 | opts.add_argument('-f', '--file', action="store", dest="file", default=False, help='File to decode!') 32 | 33 | args = parser.parse_args() 34 | return(args, parser) 35 | 36 | def getFileContents(file): 37 | with open(file, 'r') as f: return( f.read().strip() ) 38 | 39 | def banner(): 40 | title = """________ .___ 41 | \\______ \\ ____ ____ ____ __| _/___________ 42 | | | \\_/ __ \\_/ ___\\/ _ \\ / __ |/ __ \\_ __ \\ 43 | | ` \\ ___/\\ \\__( <_> ) /_/ \\ ___/| | \\/ 44 | /_______ /\\___ >\\___ >____/\\____ |\\___ >__| 45 | \\/ \\/ \\/ \\/ \\/ 46 | 47 | Automate the Manual :) 48 | """ 49 | 50 | print(colored(title, "green")) 51 | 52 | def basetitle(): 53 | print(f"[{colored('%', 'yellow')}] Base Encodings (16 - 85)") 54 | 55 | def ceasertitle(): 56 | print(f"[{colored('%', 'yellow')}] Ceaser Cipher (with shifts 0 - 9)") 57 | 58 | def commonEncodingTitle(): 59 | print(f"[{colored('%', 'yellow')}] Common Encodings") 60 | 61 | def rotTitle(): 62 | print() 63 | print(f"[{colored('%', 'yellow')}] Rot Encodings (13 - 47)") 64 | print() 65 | 66 | def divider(): 67 | print("-------------------------------------------------------") 68 | 69 | def base16Decode(string): 70 | try: 71 | return base64.b16decode(string).decode() 72 | 73 | except Exception as e: 74 | return f"Exception: {e}" 75 | 76 | def base32Decode(string): 77 | try: 78 | return base64.b32decode(string).decode() 79 | 80 | except Exception as e: 81 | return f"Exception: {e}" 82 | 83 | def base64Decode(string): 84 | try: 85 | return base64.b64decode(string).decode() 86 | 87 | except Exception as e: 88 | return f"Exception: {e}" 89 | 90 | def base85Decode(string): 91 | try: 92 | return base64.b85decode(string).decode() 93 | 94 | except Exception as e: 95 | return f"Exception: {e}" 96 | 97 | def atbashDecode(string): 98 | try: 99 | return pycipher.Atbash().decipher(string) 100 | 101 | except Exception as e: 102 | return f"Exception: {e}" 103 | 104 | def baconianDecode(string): 105 | try: 106 | lookup = {'A':'aaaaa', 'B':'aaaab', 'C':'aaaba', 'D':'aaabb', 'E':'aabaa', 107 | 'F':'aabab', 'G':'aabba', 'H':'aabbb', 'I':'abaaa', 'J':'abaab', 108 | 'K':'ababa', 'L':'ababb', 'M':'abbaa', 'N':'abbab', 'O':'abbba', 109 | 'P':'abbbb', 'Q':'baaaa', 'R':'baaab', 'S':'baaba', 'T':'baabb', 110 | 'U':'babaa', 'V':'babab', 'W':'babba', 'X':'babbb', 'Y':'bbaaa', 'Z':'bbaab'} 111 | 112 | decipher = '' 113 | i = 0 114 | 115 | string = string.lower() 116 | 117 | while True: 118 | if(i < len(string)-4): 119 | substr = string[i:i + 5] 120 | 121 | if(substr[0] != ' '): 122 | decipher += list(lookup.keys())[list(lookup.values()).index(substr)] 123 | i += 5 124 | 125 | else: 126 | decipher += ' ' 127 | i += 1 128 | 129 | else: 130 | break 131 | 132 | return decipher 133 | 134 | except Exception as e: 135 | return f"Exception: {e}" 136 | 137 | def cipherDecrypt(string, key): 138 | decrypted = "" 139 | 140 | for c in string: 141 | if c.isupper(): 142 | c_index = ord(c) - ord('A') 143 | c_og_pos = (c_index - key) % 26 + ord('A') 144 | c_og = chr(c_og_pos) 145 | decrypted += c_og 146 | 147 | elif c.islower(): 148 | c_index = ord(c) - ord('a') 149 | c_og_pos = (c_index - key) % 26 + ord('a') 150 | c_og = chr(c_og_pos) 151 | decrypted += c_og 152 | 153 | elif c.isdigit(): 154 | c_og = (int(c) - key) % 10 155 | decrypted += str(c_og) 156 | 157 | else: 158 | decrypted += c 159 | 160 | return decrypted 161 | 162 | def morseDecode(string): 163 | dictionary = { 164 | '.-...': '&', '--..--': ',', '....-': '4', '.....': '5', 165 | '...---...': 'SOS', '-...': 'B', '-..-': 'X', '.-.': 'R', 166 | '.--': 'W', '..---': '2', '.-': 'A', '..': 'I', '..-.': 'F', 167 | '.': 'E', '.-..': 'L', '...': 'S', '..-': 'U', '..--..': '?', 168 | '.----': '1', '-.-': 'K', '-..': 'D', '-....': '6', '-...-': '=', 169 | '---': 'O', '.--.': 'P', '.-.-.-': '.', '--': 'M', '-.': 'N', 170 | '....': 'H', '.----.': "'", '...-': 'V', '--...': '7', '-.-.-.': ';', 171 | '-....-': '-', '..--.-': '_', '-.--.-': ')', '-.-.--': '!', '--.': 'G', 172 | '--.-': 'Q', '--..': 'Z', '-..-.': '/', '.-.-.': '+', '-.-.': 'C', '---...': ':', 173 | '-.--': 'Y', '-': 'T', '.--.-.': '@', '...-..-': '$', '.---': 'J', '-----': '0', 174 | '----.': '9', '.-..-.': '"', '-.--.': '(', '---..': '8', '...--': '3' 175 | } 176 | 177 | translated = [] 178 | 179 | for item in string.split(' '): 180 | if dictionary.get(item) != None: 181 | translated.append(dictionary.get(item)) 182 | 183 | else: 184 | translated.append(' ') 185 | 186 | translated = ''.join(translated).rstrip('\n') 187 | return(translated) 188 | 189 | def rot13Decode(string): 190 | return encode(string, 'rot13').rstrip('\n') 191 | 192 | def rot47Decode(string): 193 | try: 194 | x = [] 195 | for i in range(len(string)): 196 | j = ord(string[i]) 197 | if j >= 33 and j <= 126: 198 | x.append(chr(33 + ((j + 14) % 94))) 199 | else: 200 | x.append(string[i]) 201 | return ''.join(x) 202 | 203 | except Exception as e: 204 | return f"Exception: {e}" 205 | 206 | def main(): 207 | banner() 208 | 209 | args, parser = addArguments() 210 | 211 | if args.file: 212 | string = args.file 213 | string = getFileContents(string) 214 | 215 | elif args.string: 216 | string = args.string 217 | 218 | else: 219 | parser.print_help() 220 | exit() 221 | 222 | print("---") 223 | print(f"[{colored('#', 'cyan')}] Provided string: {colored(string, 'green')}") 224 | print("---") 225 | print() 226 | 227 | if ("Exception" not in base16Decode(string)): 228 | divider() 229 | print() 230 | basetitle() 231 | print(f"[{colored('+', 'green')}] Base16 decoded: {colored(base16Decode(string), 'green')}") 232 | 233 | elif ("Exception" not in base32Decode(string)): 234 | divider() 235 | print() 236 | basetitle() 237 | print(f"[{colored('+', 'green')}] Base32 decoded: {colored(base32Decode(string), 'green')}") 238 | 239 | elif ("Exception" not in base64Decode(string)): 240 | divider() 241 | print() 242 | basetitle() 243 | print(f"[{colored('+', 'green')}] Base64 decoded: {colored(base64Decode(string), 'green')}") 244 | 245 | elif ("Exception" not in base85Decode(string)): 246 | divider() 247 | print() 248 | basetitle() 249 | print(f"[{colored('+', 'green')}] Base85 decoded: {colored(base85Decode(string), 'green')}") 250 | 251 | divider() 252 | print() 253 | commonEncodingTitle() 254 | 255 | print(f"[{colored('+', 'green')}] AtBash decoded: {colored(atbashDecode(string), 'green')}") 256 | 257 | if ("Exception" not in baconianDecode(string)): 258 | print(f"[{colored('+', 'green')}] Baconian decoded: {colored(baconianDecode(string), 'green')}") 259 | 260 | if (morseDecode(string) != " "): 261 | print(f"[{colored('+', 'green')}] Morse decoded: {colored(morseDecode(string), 'green')}") 262 | 263 | print() 264 | divider() 265 | 266 | rotTitle() 267 | print(f"[{colored('+', 'green')}] ROT13 decoded: {colored(rot13Decode(string), 'green')}") 268 | print(f"[{colored('+', 'green')}] ROT47 decoded: {colored(rot47Decode(string), 'green')}") 269 | print() 270 | 271 | divider() 272 | print() 273 | ceasertitle() 274 | print() 275 | 276 | for shift in range(0, 10): 277 | print(f"[{colored('&', 'green')}] Shift: {shift} Decoded: {colored(cipherDecrypt(string, shift), 'green')}") 278 | print() 279 | divider() 280 | 281 | if __name__ == '__main__': 282 | main() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pycipher 2 | termcolor 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open('README.md') as f: 4 | long_description = f.read().strip() 5 | 6 | setup(name='decoder', 7 | version='0.5', 8 | description='A simple script to try and decode a string in various encoding mechanisms regardless of it\'s (original) type.', 9 | long_description=long_description, 10 | long_description_content_type='text/markdown', # This is important! 11 | url='https://github.com/Anon-Exploiter/decoder', 12 | author='Syed Umar Arfeen', 13 | author_email='18597330+Anon-Exploiter@users.noreply.github.com', 14 | license='MIT', 15 | packages=find_packages(), 16 | install_requires=[ 17 | 'pycipher', 18 | 'termcolor', 19 | ], 20 | entry_points={ 21 | 'console_scripts': [ 22 | 'decoder = decoder.decoder:main' 23 | ], 24 | }, 25 | zip_safe=False 26 | ) 27 | --------------------------------------------------------------------------------