Class: Rex::Parser::NetSarang::NetSarangCrypto
- Inherits:
-
Object
- Object
- Rex::Parser::NetSarang::NetSarangCrypto
- Defined in:
- lib/rex/parser/net_sarang.rb
Overview
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#master_password ⇒ Object
Returns the value of attribute master_password.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#username ⇒ Object
Returns the value of attribute username.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#decrypt_string(string) ⇒ String
Decrypt.
-
#encrypt_string(string) ⇒ String
Encrypt.
-
#initialize(type, version, username, sid, master_password = nil) ⇒ Rex::Parser::NetSarang::NetSarangCrypto
constructor
This class implements encryption and decryption of NetSarang.
Constructor Details
#initialize(type, version, username, sid, master_password = nil) ⇒ Rex::Parser::NetSarang::NetSarangCrypto
This class implements encryption and decryption of NetSarang
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rex/parser/net_sarang.rb', line 22 def initialize(type, version, username, sid, master_password = nil) self.version = version.to_f self.username = username self.sid = sid self.master_password = master_password md5 = OpenSSL::Digest.new('MD5') sha256 = OpenSSL::Digest.new('SHA256') if (self.version > 0) && (self.version < 5.1) self.key = (type == 'Xshell') ? md5.digest('!X@s#h$e%l^l&') : md5.digest('!X@s#c$e%l^l&') elsif (self.version >= 5.1) && (self.version <= 5.2) self.key = sha256.digest(self.sid) elsif (self.version > 5.2) if self.master_password.nil? self.key = sha256.digest(self.username + self.sid) else self.key = sha256.digest(self.master_password) end else raise 'Invalid argument: version' end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
11 12 13 |
# File 'lib/rex/parser/net_sarang.rb', line 11 def key @key end |
#master_password ⇒ Object
Returns the value of attribute master_password.
10 11 12 |
# File 'lib/rex/parser/net_sarang.rb', line 10 def master_password @master_password end |
#sid ⇒ Object
Returns the value of attribute sid.
9 10 11 |
# File 'lib/rex/parser/net_sarang.rb', line 9 def sid @sid end |
#username ⇒ Object
Returns the value of attribute username.
8 9 10 |
# File 'lib/rex/parser/net_sarang.rb', line 8 def username @username end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/rex/parser/net_sarang.rb', line 7 def version @version end |
Instance Method Details
#decrypt_string(string) ⇒ String
Decrypt
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rex/parser/net_sarang.rb', line 64 def decrypt_string(string) if (version < 5.1) return Rex::Crypto.rc4(key, Rex::Text.decode_base64(string)) else data = Rex::Text.decode_base64(string) ciphertext = data[0, data.length - 0x20] plaintext = Rex::Crypto.rc4(key, ciphertext) if plaintext.is_utf8? return plaintext else return nil end end end |
#encrypt_string(string) ⇒ String
Encrypt
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rex/parser/net_sarang.rb', line 48 def encrypt_string(string) cipher = Rex::Crypto.rc4(key, string) if (version < 5.1) return Rex::Text.encode_base64(cipher) else sha256 = OpenSSL::Digest.new('SHA256') checksum = sha256.digest(string) ciphertext = cipher return Rex::Text.encode_base64(ciphertext + checksum) end end |