コード例 #1
0
def verify(message,signature):
	#message = base92.encode(message)
	signature = base92.decode(signature)
	publicfile = FileUtil.open(common.CONFIG_PUBKEY,'r')
	keydata = publicfile.read()
	pubkey = rsa.PublicKey.load_pkcs1(keydata)
	try:
		rsa.verify(message,signature, pubkey)
		return True
	except rsa.pkcs1.VerificationError:
		return False
コード例 #2
0
    def decode_base(self, encoded_base):
        def contains_replacement_char(res):
            return True if u'\ufffd' in res else False

        encoding_type = []

        results = []

        if len(encoded_base) != 0:
            try:
                base16_decode = base64.b16decode(encoded_base,
                                                 casefold=False).decode(
                                                     'utf-8', 'replace')
                if not contains_replacement_char(base16_decode):
                    encoding_type.append('Base16')
                    results.append(base16_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base16: ', 'blue') +
                            colored(base16_decode, 'green'))
            except:
                pass

            try:
                base32_decode = base64.b32decode(encoded_base,
                                                 casefold=False,
                                                 map01=None).decode(
                                                     'utf-8', 'replace')
                if not contains_replacement_char(base32_decode):
                    encoding_type.append('Base32')
                    results.append(base32_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base32: ', 'blue') +
                            colored(base32_decode, 'green'))
            except:
                pass

            try:
                base36_decode = base36.dumps(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base36_decode):
                    encoding_type.append('Base36')
                    results.append(base36_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base36: ', 'blue') +
                            colored(base36_decode, 'green'))
            except:
                pass

            try:
                base58_decode = base58.b58decode(encoded_base.encode()).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base58_decode):
                    encoding_type.append('Base58')
                    results.append(base58_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base58: ', 'blue') +
                            colored(base58_decode, 'green'))
            except:
                pass

            try:
                base62_decode = base62.decodebytes(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base62_decode):
                    encoding_type.append('Base62')
                    results.append(base62_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base62: ', 'blue') +
                            colored(base62_decode, 'green'))
            except:
                pass

            try:
                base64_decode = base64.b64decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base64_decode):
                    encoding_type.append('Base64')
                    results.append(base64_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base64: ', 'blue') +
                            colored(base64_decode, 'green'))
            except:
                pass

            try:
                base64url_decode = base64.urlsafe_b64decode(
                    encoded_base + '=' * (4 - len(encoded_base) % 4)).decode(
                        'utf-8', 'replace')
                if not contains_replacement_char(base64url_decode):
                    encoding_type.append('Base64URL')
                    results.append(base64url_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base64URL: ', 'blue') +
                            colored(base64url_decode, 'green'))
            except:
                pass

            try:
                base85_decode = base64.b85decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base85_decode):
                    encoding_type.append('Base85')
                    results.append(base85_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base85: ', 'blue') +
                            colored(base85_decode, 'green'))
            except:
                pass

            try:
                ascii85_decode = base64.a85decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(ascii85_decode):
                    encoding_type.append('Ascii85')
                    results.append(ascii85_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Ascii85: ', 'blue') +
                            colored(ascii85_decode, 'green'))
            except:
                pass

            try:
                base91_decode = base91.decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base91_decode):
                    encoding_type.append('Base91')
                    results.append(base91_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base91: ', 'blue') +
                            colored(base91_decode, 'green'))
            except:
                pass

            try:
                base92_decode = base92.decode(encoded_base)
                if not contains_replacement_char(base92_decode):
                    encoding_type.append('Base92')
                    results.append(base92_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base92: ', 'blue') +
                            colored(base92_decode, 'green'))
            except:
                pass

            if not results and not self.api_call:
                quit(colored('\n[!] Not a valid encoding.\n', 'red'))

            for x in range(len(results)):
                """
                It runs through all the results and compares them
                with a regex pattern of 'alphabets, numbers, and special characters'
                thus ending up with the right result as false results will
                contain invalid characters.
                """
                if re.match('[A-Za-z0-9$&+,:;=?@#|\'<>.^*()%!_-]', results[x]):
                    if not self.api_call:

                        print(
                            colored('\n[-] The Encoding Scheme Is ', 'blue') +
                            colored(encoding_type[x], 'green'))

                        if self.output != None:
                            open(self.output, 'a').write(results[x] + '\n')
                    else:

                        return (results[x], encoding_type[x])
コード例 #3
0
ファイル: basecrack.py プロジェクト: Ayana-nair/basecr4ck
	def decode_base(self):
		# declaring the encoding type array to store encoding types which haven't caused errors
		encoding_type = []

		# declaring the results array to store results which haven't caused errors
		results = []

		# checking if input is not empty
		if len(self.encoded_base) > 1:
			# decoding as base16
			try:
				base16_decode = base64.b16decode(self.encoded_base, casefold=False)
				encoding_type.append("Base16")
				results.append(base16_decode)
				print(colored("\n[>] Decoding as Base16: ", "blue")+colored(str(base16_decode), "green"))
			except:
				pass

			# decoding as base32
			try:
				base32_decode = base64.b32decode(self.encoded_base, casefold=False, map01=None)
				encoding_type.append("Base32")
				results.append(base32_decode)
				print(colored("\n[>] Decoding as Base32: ", "blue")+colored(str(base32_decode), "green"))
			except:
				pass

			# decoding as base36
			try:
				base36_decode = base36.dumps(self.encoded_base)
				encoding_type.append("Base36")
				results.append(base36_decode)
				print(colored("\n[>] Decoding as Base36: ", "blue")+colored(str(base36_decode), "green"))
			except:
				pass

			# decoding as base58
			try:
				base58_decode = base58.b58decode(self.encoded_base)
				encoding_type.append("Base58")
				results.append(base58_decode)
				print(colored("\n[>] Decoding as Base58: ", "blue")+colored(str(base58_decode), "green"))
			except:
				pass

			# decoding as base62
			try:
				base62_decode = base62.encode(int(self.encoded_base))
				encoding_type.append("Base62")
				results.append(base62_decode)
				print(colored("\n[>] Decoding as Base62: ", "blue")+colored(str(base62_decode), "green"))
			except:
				pass

			# decoding as base64
			try:
				base64_decode = base64.b64decode(self.encoded_base)
				encoding_type.append("Base64")
				results.append(base64_decode)
				print(colored("\n[>] Decoding as Base64: ", "blue")+colored(str(base64_decode), "green"))
			except:
				pass

			# decoding as base64url
			try:
				base64url_decode = base64.urlsafe_b64decode(self.encoded_base + '=' * (4 - len(self.encoded_base) % 4))
				encoding_type.append("Base64Url")
				results.append(base64url_decode)
				print(colored("\n[>] Decoding as Base64Url: ", "blue")+colored(str(base64url_decode), "green"))
			except:
				pass

			# decoding as base85
			try:
				base85_decode = base64.b85decode(self.encoded_base)
				encoding_type.append("Base85")
				results.append(base85_decode)
				print(colored("\n[>] Decoding as Base85: ", "blue")+colored(str(base85_decode), "green"))
			except:
				pass

			# decoding as base91
			try:
				base91_decode = base91.decode(self.encoded_base)
				encoding_type.append("Base91")
				results.append(base91_decode)
				print(colored("\n[>] Decoding as Base91: ", "blue")+colored(str(base91_decode), "green"))
			except:
				pass

			# decoding as base92
			try:
				base92_decode = base92.decode(self.encoded_base)
				encoding_type.append("Base92")
				results.append(base92_decode)
				print(colored("\n[>] Decoding as Base92: ", "blue")+colored(str(base92_decode), "green"))
			except:
				pass

			# algorithm to identify which type of base encoding the input is
			for x in range(len(results)):
				# identifying the encoding type with regex pattern matching
				if re.match("^[A-Za-z0-9_ ]*$", results[x]):
					# printing the predicted encoding type
					print(colored("\nThe accurate base encoding type is probably ", "red")+colored(encoding_type[x], "green"))
コード例 #4
0
ファイル: basecrack.py プロジェクト: jermainlaforce/basecrack
    def decode_base(self, encoded_base):
        """
		contains_replacement_char() checks whether the decoded base
		contains an unknown unicode, ie: invalid character.
		these are replaced with 'replacement character',
		which is '�' and 'U+FFFD' in unicode.
		"""
        def contains_replacement_char(res):
            return True if u'\ufffd' in res else False

        # to store the encoding schemes which haven't caused errors
        encoding_type = []

        # to store the decoded results which haven't caused errors
        results = []

        # checking if input is not empty
        if len(encoded_base) != 0:
            # decoding as base16
            try:
                base16_decode = base64.b16decode(encoded_base,
                                                 casefold=False).decode(
                                                     'utf-8', 'replace')
                if not contains_replacement_char(base16_decode):
                    encoding_type.append('Base16')
                    results.append(base16_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base16: ', 'blue') +
                            colored(base16_decode, 'green'))
            except:
                pass

            # decoding as base32
            try:
                base32_decode = base64.b32decode(encoded_base,
                                                 casefold=False,
                                                 map01=None).decode(
                                                     'utf-8', 'replace')
                if not contains_replacement_char(base32_decode):
                    encoding_type.append('Base32')
                    results.append(base32_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base32: ', 'blue') +
                            colored(base32_decode, 'green'))
            except:
                pass

            # decoding as base36
            try:
                base36_decode = base36.dumps(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base36_decode):
                    encoding_type.append('Base36')
                    results.append(base36_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base36: ', 'blue') +
                            colored(base36_decode, 'green'))
            except:
                pass

            # decoding as base58
            try:
                base58_decode = base58.b58decode(encoded_base.encode()).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base58_decode):
                    encoding_type.append('Base58')
                    results.append(base58_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base58: ', 'blue') +
                            colored(base58_decode, 'green'))
            except:
                pass

            # decoding as base62
            try:
                base62_decode = base62.encode(int(encoded_base)).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base62_decode):
                    encoding_type.append('Base62')
                    results.append(base62_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base62: ', 'blue') +
                            colored(base62_decode, 'green'))
            except:
                pass

            # decoding as base64
            try:
                base64_decode = base64.b64decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base64_decode):
                    encoding_type.append('Base64')
                    results.append(base64_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base64: ', 'blue') +
                            colored(base64_decode, 'green'))
            except:
                pass

            # decoding as base64url
            try:
                base64url_decode = base64.urlsafe_b64decode(
                    encoded_base + '=' * (4 - len(encoded_base) % 4)).decode(
                        'utf-8', 'replace')
                if not contains_replacement_char(base64url_decode):
                    encoding_type.append('Base64URL')
                    results.append(base64url_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base64URL: ', 'blue') +
                            colored(base64url_decode, 'green'))
            except:
                pass

            # decoding as base85
            try:
                base85_decode = base64.b85decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base85_decode):
                    encoding_type.append('Base85')
                    results.append(base85_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base85: ', 'blue') +
                            colored(base85_decode, 'green'))
            except:
                pass

            # decoding as base91
            try:
                base91_decode = base91.decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base91_decode):
                    encoding_type.append('Base91')
                    results.append(base91_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base91: ', 'blue') +
                            colored(base91_decode, 'green'))
            except:
                pass

            # decoding as base92
            try:
                base92_decode = base92.decode(encoded_base).decode(
                    'utf-8', 'replace')
                if not contains_replacement_char(base92_decode):
                    encoding_type.append('Base92')
                    results.append(base92_decode)
                    if not self.api_call:
                        print(
                            colored('\n[>] Decoding as Base92: ', 'blue') +
                            colored(base92_decode, 'green'))
            except:
                pass

            if not results and not self.api_call:
                quit(colored('\n[!] Not a valid encoding.\n', 'red'))

            # algorithm to identify which type of base encoding the input is
            for x in range(len(results)):
                """
				It runs through all the results and compares them
				with a regex pattern of 'alphabets, numbers, and special characters'
				thus ending up with the right result as false results will
				contain invalid characters.
				"""
                if re.match('[A-Za-z0-9$&+,:;=?@#|\'<>.^*()%!_-]', results[x]):
                    if not self.api_call:
                        # printing the predicted encoding type
                        print(
                            colored('\n[-] The Encoding Scheme Is ', 'blue') +
                            colored(encoding_type[x], 'green'))
                        # generating the wordlist/output file with the decoded bases
                        if self.output != None:
                            open(self.output, 'a').write(results[x] + '\n')
                    else:
                        # return a tuple with the decoded base and encoding scheme if it's an api call
                        return (results[x], encoding_type[x])
コード例 #5
0
def base_decode(n):
    m = ''
    flag = False

    try:
        if re.search('[a-e]', n):
            m = base64.b16decode(n, True)
        else:
            m = base64.b16decode(n)
    except binascii.Error:
        pass
    else:
        flag = True
        print("base16deocde:", m)
        return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base64.b32decode(n)
    except binascii.Error:
        pass
    else:
        flag = True
        print("base32deocde:", m)
        return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base58.b58decode(n)
    except ValueError:
        pass
    else:
        m = str(m)[2:-1]
        if '\\x' in m:
            pass
        else:
            flag = True
            print("base58deocde:", m)
            mm = str(base91.decode(n))
            if '\\x' not in mm:
                print("maybe base91decode:", mm)
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base62.decodebytes(n)
    except ValueError:
        pass
    else:
        m = str(m)
        if '\\x' in m:
            pass
        else:
            flag = True
            print("base62deocde:", m)
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base64.b64decode(n)
    except binascii.Error:
        pass
    else:
        m = str(m)
        if '\\x' in m:
            pass
        else:
            flag = True
            print("base64deocde:", m)
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base64.b85decode(n)
    except ValueError:
        pass
    else:
        m = str(m)
        if '\\x' in m:
            pass
        else:
            print("base_b85deocde:", m)
            flag = True
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base64.a85decode(n)
    except ValueError:
        pass
    else:
        m = str(m)
        if '\\x' in m:
            pass
        else:
            print("base_a85deocde:", m)
            flag = True
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base91.decode(n)
    except ValueError:
        pass
    else:
        m = str(m)
        if '\\x' in m:
            pass
        else:
            print("base91deocde:", m)
            flag = True
            return flag
    #'''''''''''''''''''''''''''''''''
    try:
        m = base92.decode(n)
    except ValueError:
        pass
    else:
        flag = True
        print("base92deocde:", m)
        return flag
    #'''''''''''''''''''''''''''''''''
    try:
        c = base36.loads(n)
        assert type(c) == int
        m = base36.dumps(c)
    except ValueError:
        pass
    else:
        flag = True
        print("base36deocde:", m)
        return flag
    # '''''''''''''''''''''''''''''''''
    try:
        b128 = base128.base128(chars=None, chunksize=7)
        n_str = bytes(n, encoding="utf8")
        c = list(b128.encode(n_str))
        m = b''.join(b128.decode(c))
    except ValueError:
        pass
    else:
        flag = True
        print("base128deocde:", m)
        return flag
    return flag
コード例 #6
0
    def decode_base(self, encoded_base):
        def contains_replacement_char(res):
            """
            `contains_replacement_char()` checks whether the decoded base
            contains an unknown unicode, ie: invalid character.
            these are replaced with 'replacement character',
            which is '�' and 'U+FFFD' in unicode and
            also checks for unicode chars after `127`.
            """
            if u'\ufffd' in res: return True
            else:
                count = 0
                for char in res:
                    if ord(char) > 127: count += 1
                return True if count > 0 else False

        # to store the encoding schemes which haven't caused errors
        encoding_type = []

        # to store the decoded results which haven't caused errors
        results = []

        def process_decode(decode_string, scheme):
            """
            `process_decode()` stores the result if the encoding is valid
            after checks from `contains_replacement_char()` and
            prints the output if it isn't an API call
            """
            if len(decode_string) < 3: return
            if not contains_replacement_char(decode_string):
                # don't repeat `base64url` when `base64` has already passed and it's not a URL
                if scheme == 'Base64' and '://' not in decode_string: self.b64_once = True
                if self.b64_once and (scheme == 'Base64URL'): return
                
                # append results to the respective lists
                encoding_type.append(scheme)
                results.append(decode_string)

                if not self.api_call:
                    if self.image_mode_call:
                        print(colored('\n[-] Attempting Base: ', 'yellow')+colored(self.current_iter_base, 'red'))
                    print(colored('\n[>] Decoding as {}: '.format(scheme), 'blue')+colored(decode_string, 'green'))


        # checking if input is valid in length
        if len(encoded_base) > 3:
            # decoding as base16
            try:
                process_decode(
                    base64.b16decode(encoded_base, casefold=False).decode('utf-8', 'replace'),
                    'Base16'
                )
            except: pass
            # decoding as base32
            try:
                process_decode(
                    base64.b32decode(encoded_base, casefold=False, map01=None).decode('utf-8', 'replace'),
                    'Base32'
                )
            except: pass
            # decoding as base36
            try:
                process_decode(
                    base36.dumps(int(encoded_base)),
                    'Base36'
                )
            except: pass
            # decoding as base58
            try:
                process_decode(
                    base58.b58decode(encoded_base.encode()).decode('utf-8', 'replace'),
                    'Base58'
                )
            except: pass
            # decoding as base62
            try:
                process_decode(
                    base62.decodebytes(encoded_base).decode('utf-8', 'replace'),
                    'Base62'
                )
            except: pass
            # decoding as base64
            try:
                process_decode(
                    base64.b64decode(encoded_base).decode('utf-8', 'replace'),
                    'Base64'
                )
            except: pass            
            # decoding as base64url
            try:
                process_decode(
                    base64.urlsafe_b64decode(encoded_base + '=' * (4 - len(encoded_base) % 4)).decode('utf-8', 'replace'),
                    'Base64URL'
                )
            except: pass
            # decoding as base85
            try:
                process_decode(
                    base64.b85decode(encoded_base).decode('utf-8', 'replace'),
                    'Base85'
                )
            except: pass
            # decoding as ascii85
            try:
                process_decode(
                    base64.a85decode(encoded_base).decode('utf-8', 'replace'),
                    'Ascii85'
                )
            except: pass
            # decoding as base91
            try:
                process_decode(
                    base91.decode(encoded_base).decode('utf-8', 'replace'),
                    'Base91'
                )
            except: pass
            # decoding as base92
            try:
                process_decode(
                    base92.decode(encoded_base),
                    'Base92'
                )
            except: pass

            if not results and not self.api_call:
                if not self.image_mode_call:
                    print(colored('\n[!] Not a valid encoding.\n', 'red'))
                if self.quit_after_fail: quit()

            # print/return the results
            for x in range(len(results)):          
                if not self.api_call:
                    print(colored('\n[-] The Encoding Scheme Is ', 'blue')+colored(encoding_type[x], 'green'))
                    # generating the wordlist/output file with the decoded base
                    if self.output != None:
                        open(self.output, 'a').write(results[x]+'\n')
                else:
                    return results[x], encoding_type[x]

            if self.image_mode_call and results:
                print(colored('\n{{<<', 'red')+colored('='*70, 'yellow')+colored('>>}}', 'red'))