General

  • Target

    https://github.com/Smug246/Luna-Grabber

  • Sample

    240225-m7khqsab64

Malware Config

Extracted

Path

C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\Cryptodome\Cipher\PKCS1_OAEP.py

Ransom Note
# -*- coding: utf-8 -*- # # Cipher/PKCS1_OAEP.py : PKCS#1 OAEP # # =================================================================== # The contents of this file are dedicated to the public domain. To # the extent that dedication to the public domain is not available, # everyone is granted a worldwide, perpetual, royalty-free, # non-exclusive license to exercise all rights associated with the # contents of this file for any purpose whatsoever. # No rights are reserved. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # =================================================================== from Cryptodome.Signature.pss import MGF1 import Cryptodome.Hash.SHA1 from Cryptodome.Util.py3compat import _copy_bytes import Cryptodome.Util.number from Cryptodome.Util.number import ceil_div, bytes_to_long, long_to_bytes from Cryptodome.Util.strxor import strxor from Cryptodome import Random from ._pkcs1_oaep_decode import oaep_decode class PKCS1OAEP_Cipher: """Cipher object for PKCS#1 v1.5 OAEP. Do not create directly: use :func:`new` instead.""" def __init__(self, key, hashAlgo, mgfunc, label, randfunc): """Initialize this PKCS#1 OAEP cipher object. :Parameters: key : an RSA key object If a private half is given, both encryption and decryption are possible. If a public half is given, only encryption is possible. hashAlgo : hash object The hash function to use. This can be a module under `Cryptodome.Hash` or an existing hash object created from any of such modules. If not specified, `Cryptodome.Hash.SHA1` is used. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. If not specified, the standard MGF1 consistent with ``hashAlgo`` is used (a safe choice). label : bytes/bytearray/memoryview A label to apply to this particular encryption. If not specified, an empty string is used. Specifying a label does not improve security. randfunc : callable A function that returns random bytes. :attention: Modify the mask generation function only if you know what you are doing. Sender and receiver must use the same one. """ self._key = key if hashAlgo: self._hashObj = hashAlgo else: self._hashObj = Cryptodome.Hash.SHA1 if mgfunc: self._mgf = mgfunc else: self._mgf = lambda x, y: MGF1(x, y, self._hashObj) self._label = _copy_bytes(None, None, label) self._randfunc = randfunc def can_encrypt(self): """Legacy function to check if you can call :meth:`encrypt`. .. deprecated:: 3.0""" return self._key.can_encrypt() def can_decrypt(self): """Legacy function to check if you can call :meth:`decrypt`. .. deprecated:: 3.0""" return self._key.can_decrypt() def encrypt(self, message): """Encrypt a message with PKCS#1 OAEP. :param message: The message to encrypt, also known as plaintext. It can be of variable length, but not longer than the RSA modulus (in bytes) minus 2, minus twice the hash output size. For instance, if you use RSA 2048 and SHA-256, the longest message you can encrypt is 190 byte long. :type message: bytes/bytearray/memoryview :returns: The ciphertext, as large as the RSA modulus. :rtype: bytes :raises ValueError: if the message is too long. """ # See 7.1.1 in RFC3447 modBits = Cryptodome.Util.number.size(self._key.n) k = ceil_div(modBits, 8) # Convert from bits to bytes hLen = self._hashObj.digest_size mLen = len(message) # Step 1b ps_len = k - mLen - 2 * hLen - 2 if ps_len < 0: raise ValueError("Plaintext is too long.") # Step 2a lHash = self._hashObj.new(self._label).digest() # Step 2b ps = b'\x00' * ps_len # Step 2c db = lHash + ps + b'\x01' + _copy_bytes(None, None, message) # Step 2d ros = self._randfunc(hLen) # Step 2e dbMask = self._mgf(ros, k-hLen-1) # Step 2f maskedDB = strxor(db, dbMask) # Step 2g seedMask = self._mgf(maskedDB, hLen) # Step 2h maskedSeed = strxor(ros, seedMask) # Step 2i em = b'\x00' + maskedSeed + maskedDB # Step 3a (OS2IP) em_int = bytes_to_long(em) # Step 3b (RSAEP) m_int = self._key._encrypt(em_int) # Step 3c (I2OSP) c = long_to_bytes(m_int, k) return c def decrypt(self, ciphertext): """Decrypt a message with PKCS#1 OAEP. :param ciphertext: The encrypted message. :type ciphertext: bytes/bytearray/memoryview :returns: The original message (plaintext). :rtype: bytes :raises ValueError: if the ciphertext has the wrong length, or if decryption fails the integrity check (in which case, the decryption key is probably wrong). :raises TypeError: if the RSA key has no private half (i.e. you are trying to decrypt using a public key). """ # See 7.1.2 in RFC3447 modBits = Cryptodome.Util.number.size(self._key.n) k = ceil_div(modBits, 8) # Convert from bits to bytes hLen = self._hashObj.digest_size # Step 1b and 1c if len(ciphertext) != k or k < hLen+2: raise ValueError("Ciphertext with incorrect length.") # Step 2a (O2SIP) ct_int = bytes_to_long(ciphertext) # Step 2b (RSADP) and step 2c (I2OSP) em = self._key._decrypt_to_bytes(ct_int) # Step 3a lHash = self._hashObj.new(self._label).digest() # y must be 0, but we MUST NOT check it here in order not to # allow attacks like Manger's (http://dl.acm.org/citation.cfm?id=704143) maskedSeed = em[1:hLen+1] maskedDB = em[hLen+1:] # Step 3c seedMask = self._mgf(maskedDB, hLen) # Step 3d seed = strxor(maskedSeed, seedMask) # Step 3e dbMask = self._mgf(seed, k-hLen-1) # Step 3f db = strxor(maskedDB, dbMask) # Step 3b + 3g res = oaep_decode(em, lHash, db) if res <= 0: raise ValueError("Incorrect decryption.") # Step 4 return db[res:] def new(key, hashAlgo=None, mgfunc=None, label=b'', randfunc=None): """Return a cipher object :class:`PKCS1OAEP_Cipher` that can be used to perform PKCS#1 OAEP encryption or decryption. :param key: The key object to use to encrypt or decrypt the message. Decryption is only possible with a private RSA key. :type key: RSA key object :param hashAlgo: The hash function to use. This can be a module under `Cryptodome.Hash` or an existing hash object created from any of such modules. If not specified, `Cryptodome.Hash.SHA1` is used. :type hashAlgo: hash object :param mgfunc: A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. If not specified, the standard MGF1 consistent with ``hashAlgo`` is used (a safe choice). :type mgfunc: callable :param label: A label to apply to this particular encryption. If not specified, an empty string is used. Specifying a label does not improve security. :type label: bytes/bytearray/memoryview :param randfunc: A function that returns random bytes. The default is `Random.get_random_bytes`. :type randfunc: callable """ if randfunc is None: randfunc = Random.get_random_bytes return PKCS1OAEP_Cipher(key, hashAlgo, mgfunc, label, randfunc)
URLs

http://dl.acm.org/citation.cfm?id=704143

Extracted

Path

C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\Cryptodome\Cipher\_mode_siv.py

Ransom Note
# =================================================================== # # Copyright (c) 2014, Legrandin <[email protected]> # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # =================================================================== """ Synthetic Initialization Vector (SIV) mode. """ __all__ = ['SivMode'] from binascii import hexlify, unhexlify from Cryptodome.Util.py3compat import bord, _copy_bytes from Cryptodome.Util._raw_api import is_buffer from Cryptodome.Util.number import long_to_bytes, bytes_to_long from Cryptodome.Protocol.KDF import _S2V from Cryptodome.Hash import BLAKE2s from Cryptodome.Random import get_random_bytes class SivMode(object): """Synthetic Initialization Vector (SIV). This is an Authenticated Encryption with Associated Data (`AEAD`_) mode. It provides both confidentiality and authenticity. The header of the message may be left in the clear, if needed, and it will still be subject to authentication. The decryption step tells the receiver if the message comes from a source that really knowns the secret key. Additionally, decryption detects if any part of the message - including the header - has been modified or corrupted. Unlike other AEAD modes such as CCM, EAX or GCM, accidental reuse of a nonce is not catastrophic for the confidentiality of the message. The only effect is that an attacker can tell when the same plaintext (and same associated data) is protected with the same key. The length of the MAC is fixed to the block size of the underlying cipher. The key size is twice the length of the key of the underlying cipher. This mode is only available for AES ciphers. +--------------------+---------------+-------------------+ | Cipher | SIV MAC size | SIV key length | | | (bytes) | (bytes) | +====================+===============+===================+ | AES-128 | 16 | 32 | +--------------------+---------------+-------------------+ | AES-192 | 16 | 48 | +--------------------+---------------+-------------------+ | AES-256 | 16 | 64 | +--------------------+---------------+-------------------+ See `RFC5297`_ and the `original paper`__. .. _RFC5297: https://tools.ietf.org/html/rfc5297 .. _AEAD: http://blog.cryptographyengineering.com/2012/05/how-to-choose-authenticated-encryption.html .. __: http://www.cs.ucdavis.edu/~rogaway/papers/keywrap.pdf :undocumented: __init__ """ def __init__(self, factory, key, nonce, kwargs): self.block_size = factory.block_size """The block size of the underlying cipher, in bytes.""" self._factory = factory self._cipher_params = kwargs if len(key) not in (32, 48, 64): raise ValueError("Incorrect key length (%d bytes)" % len(key)) if nonce is not None: if not is_buffer(nonce): raise TypeError("When provided, the nonce must be bytes, bytearray or memoryview") if len(nonce) == 0: raise ValueError("When provided, the nonce must be non-empty") self.nonce = _copy_bytes(None, None, nonce) """Public attribute is only available in case of non-deterministic encryption.""" subkey_size = len(key) // 2 self._mac_tag = None # Cache for MAC tag self._kdf = _S2V(key[:subkey_size], ciphermod=factory, cipher_params=self._cipher_params) self._subkey_cipher = key[subkey_size:] # Purely for the purpose of verifying that cipher_params are OK factory.new(key[:subkey_size], factory.MODE_ECB, **kwargs) # Allowed transitions after initialization self._next = ["update", "encrypt", "decrypt", "digest", "verify"] def _create_ctr_cipher(self, v): """Create a new CTR cipher from V in SIV mode""" v_int = bytes_to_long(v) q = v_int & 0xFFFFFFFFFFFFFFFF7FFFFFFF7FFFFFFF return self._factory.new( self._subkey_cipher, self._factory.MODE_CTR, initial_value=q, nonce=b"", **self._cipher_params) def update(self, component): """Protect one associated data component For SIV, the associated data is a sequence (*vector*) of non-empty byte strings (*components*). This method consumes the next component. It must be called once for each of the components that constitue the associated data. Note that the components have clear boundaries, so that: >>> cipher.update(b"builtin") >>> cipher.update(b"securely") is not equivalent to: >>> cipher.update(b"built") >>> cipher.update(b"insecurely") If there is no associated data, this method must not be called. :Parameters: component : bytes/bytearray/memoryview The next associated data component. """ if "update" not in self._next: raise TypeError("update() can only be called" " immediately after initialization") self._next = ["update", "encrypt", "decrypt", "digest", "verify"] return self._kdf.update(component) def encrypt(self, plaintext): """ For SIV, encryption and MAC authentication must take place at the same point. This method shall not be used. Use `encrypt_and_digest` instead. """ raise TypeError("encrypt() not allowed for SIV mode." " Use encrypt_and_digest() instead.") def decrypt(self, ciphertext): """ For SIV, decryption and verification must take place at the same point. This method shall not be used. Use `decrypt_and_verify` instead. """ raise TypeError("decrypt() not allowed for SIV mode." " Use decrypt_and_verify() instead.") def digest(self): """Compute the *binary* MAC tag. The caller invokes this function at the very end. This method returns the MAC that shall be sent to the receiver, together with the ciphertext. :Return: the MAC, as a byte string. """ if "digest" not in self._next: raise TypeError("digest() cannot be called when decrypting" " or validating a message") self._next = ["digest"] if self._mac_tag is None: self._mac_tag = self._kdf.derive() return self._mac_tag def hexdigest(self): """Compute the *printable* MAC tag. This method is like `digest`. :Return: the MAC, as a hexadecimal string. """ return "".join(["%02x" % bord(x) for x in self.digest()]) def verify(self, received_mac_tag): """Validate the *binary* MAC tag. The caller invokes this function at the very end. This method checks if the decrypted message is indeed valid (that is, if the key is correct) and it has not been tampered with while in transit. :Parameters: received_mac_tag : bytes/bytearray/memoryview This is the *binary* MAC, as received from the sender. :Raises ValueError: if the MAC does not match. The message has been tampered with or the key is incorrect. """ if "verify" not in self._next: raise TypeError("verify() cannot be called" " when encrypting a message") self._next = ["verify"] if self._mac_tag is None: self._mac_tag = self._kdf.derive() secret = get_random_bytes(16) mac1 = BLAKE2s.new(digest_bits=160, key=secret, data=self._mac_tag) mac2 = BLAKE2s.new(digest_bits=160, key=secret, data=received_mac_tag) if mac1.digest() != mac2.digest(): raise ValueError("MAC check failed") def hexverify(self, hex_mac_tag): """Validate the *printable* MAC tag. This method is like `verify`. :Parameters: hex_mac_tag : string This is the *printable* MAC, as received from the sender. :Raises ValueError: if the MAC does not match. The message has been tampered with or the key is incorrect. """ self.verify(unhexlify(hex_mac_tag)) def encrypt_and_digest(self, plaintext, output=None): """Perform encrypt() and digest() in one step. :Parameters: plaintext : bytes/bytearray/memoryview The piece of data to encrypt. :Keywords: output : bytearray/memoryview The location where the ciphertext must be written to. If ``None``, the ciphertext is returned. :Return: a tuple with two items: - the ciphertext, as ``bytes`` - the MAC tag, as ``bytes`` The first item becomes ``None`` when the ``output`` parameter specified a location for the result. """ if "encrypt" not in self._next: raise TypeError("encrypt() can only be called after" " initialization or an update()") self._next = ["digest"] # Compute V (MAC) if hasattr(self, 'nonce'): self._kdf.update(self.nonce) self._kdf.update(plaintext) self._mac_tag = self._kdf.derive() cipher = self._create_ctr_cipher(self._mac_tag) return cipher.encrypt(plaintext, output=output), self._mac_tag def decrypt_and_verify(self, ciphertext, mac_tag, output=None): """Perform decryption and verification in one step. A cipher object is stateful: once you have decrypted a message you cannot decrypt (or encrypt) another message with the same object. You cannot reuse an object for encrypting or decrypting other data with the same key. This function does not remove any padding from the plaintext. :Parameters: ciphertext : bytes/bytearray/memoryview The piece of data to decrypt. It can be of any length. mac_tag : bytes/bytearray/memoryview This is the *binary* MAC, as received from the sender. :Keywords: output : bytearray/memoryview The location where the plaintext must be written to. If ``None``, the plaintext is returned. :Return: the plaintext as ``bytes`` or ``None`` when the ``output`` parameter specified a location for the result. :Raises ValueError: if the MAC does not match. The message has been tampered with or the key is incorrect. """ if "decrypt" not in self._next: raise TypeError("decrypt() can only be called" " after initialization or an update()") self._next = ["verify"] # Take the MAC and start the cipher for decryption self._cipher = self._create_ctr_cipher(mac_tag) plaintext = self._cipher.decrypt(ciphertext, output=output) if hasattr(self, 'nonce'): self._kdf.update(self.nonce) self._kdf.update(plaintext if output is None else output) self.verify(mac_tag) return plaintext def _create_siv_cipher(factory, **kwargs): """Create a new block cipher, configured in Synthetic Initializaton Vector (SIV) mode. :Parameters: factory : object A symmetric cipher module from `Cryptodome.Cipher` (like `Cryptodome.Cipher.AES`). :Keywords: key : bytes/bytearray/memoryview The secret key to use in the symmetric cipher. It must be 32, 48 or 64 bytes long. If AES is the chosen cipher, the variants *AES-128*, *AES-192* and or *AES-256* will be used internally. nonce : bytes/bytearray/memoryview For deterministic encryption, it is not present. Otherwise, it is a value that must never be reused for encrypting message under this key. There are no restrictions on its length, but it is recommended to use at least 16 bytes. """ try: key = kwargs.pop("key") except KeyError as e: raise TypeError("Missing parameter: " + str(e)) nonce = kwargs.pop("nonce", None) return SivMode(factory, key, nonce, kwargs)
URLs

https://tools.ietf.org/html/rfc5297

http://blog.cryptographyengineering.com/2012/05/how-to-choose-authenticated-encryption.html

http://www.cs.ucdavis.edu/~rogaway/papers/keywrap.pdf

Targets

    • Target

      https://github.com/Smug246/Luna-Grabber

    • Downloads MZ/PE file

    • Checks computer location settings

      Looks up country code configured in the registry, likely geofence.

    • Drops startup file

    • Executes dropped EXE

    • Loads dropped DLL

    • Reads user/profile data of web browsers

      Infostealers often target stored browser data, which can include saved credentials etc.

    • Registers COM server for autorun

    • UPX packed file

      Detects executables packed with UPX/modified UPX open source packer.

    • Adds Run key to start application

    • Checks installed software on the system

      Looks up Uninstall key entries in the registry to enumerate software on the system.

    • Enumerates connected drives

      Attempts to read the root path of hard drives other than the default C: drive.

    • Legitimate hosting services abused for malware hosting/C2

    • Looks up external IP address via web service

      Uses a legitimate IP lookup service to find the infected system's external IP.

MITRE ATT&CK Enterprise v15

Tasks