Projects STRLCPY SharPyShell Commits 9e0ceb75
🤬
  • AES128 and AES256 encryption fixes

    Now using bytes for both XOR and AES encrypt methods.
    
    Decrypt now returns str. This allows both encryption methods to use the _encrypt_request successfully without encoding issues.
  • Loading...
  • NuHarborMartin committed 3 years ago
    9e0ceb75
    1 parent 39e931ff
  • ■ ■ ■ ■ ■
    core/ChannelAES.py
    skipped 7 lines
    8 8   BS = 16
    9 9   
    10 10   def __init__(self, password):
    11  - self.hashed_password = password.decode('hex')
     11 + self.hashed_password = bytes.fromhex(password)
    12 12   self.IV = self.hashed_password[0:self.BS]
    13 13   
    14 14   def encrypt(self, plain_data):
    skipped 7 lines
    22 22   aes = AES.new(self.hashed_password, AES.MODE_CBC, self.IV)
    23 23   unpad = lambda s: s[:-ord(s[len(s) - 1:])]
    24 24   decrypted_data = aes.decrypt(encrypted_data)
    25  - return unpad(decrypted_data)
     25 + return unpad(decrypted_data).decode()
     26 + 
  • ■ ■ ■ ■ ■ ■
    core/ChannelXOR.py
    skipped 9 lines
    10 10   def encrypt(self, plain_data):
    11 11   key = self.password
    12 12   xored = ''.join(chr(ord(x) ^ ord(y)) for (x, y) in list(zip(plain_data, cycle(key))))
    13  - return xored
     13 + return bytes(xored, 'utf-8')
    14 14   
    15 15   def decrypt(self, encrypted_data):
    16  - return str(self.encrypt(encrypted_data.decode('utf-8')))
     16 + return self.encrypt(encrypted_data.decode('utf-8')).decode()
    17 17   
  • ■ ■ ■ ■ ■ ■
    core/Module.py
    skipped 56 lines
    57 57   
    58 58   def _encrypt_request(self, request_clear):
    59 59   request_encrypted = self._channel_enc_obj.encrypt(request_clear)
    60  - request_encrypted_encoded = base64.b64encode(bytes(request_encrypted, 'utf-8'))
     60 + request_encrypted_encoded = base64.b64encode(request_encrypted)
    61 61   return request_encrypted_encoded
    62 62   
    63 63   def _post_request(self, request_encrypted_encoded):
    64 64   response_status_code, response_headers, response_text = \
    65 65   self._request_object.send_request(request_encrypted_encoded)
    66 66   if response_status_code != 200:
    67  - raise self._exception_class('{{{' + self._exception_class.__name__ + '}}}\n' +
     67 + raise self._exception_class('{{{' + str(self._exception_class.__name__) + '}}}\n' +
    68 68   str(response_headers) + '\n\n' +
    69 69   str(response_text))
    70 70   return response_text
    skipped 27 lines
  • ■ ■ ■ ■ ■
    utils/gzip_utils.py
    skipped 3 lines
    4 4   
    5 5   
    6 6  def get_compressed_base64_from_file(path):
     7 + 
    7 8   with open(path, 'rb') as f:
    8 9   read_data = f.read()
    9 10   return base64.b64encode(gzip.compress(read_data)).decode()
    skipped 6 lines
Please wait...
Page is in error, reload to recover