A Comprehensive Guide to Encryption Algorithms in Modern Malware

July 22, 2024 News

Types of Encryption Algorithms:

Stream Ciphers

Stream ciphers encrypt data in a continuous flow, one bit or byte at a time, similar to water from a tap. This method is fast and efficient but typically less secure than block ciphers. Malware often uses stream ciphers for their simplicity, speed, and low computational demands. Understanding stream ciphers helps analysts detect, decrypt, and mitigate malware threats.

Examples of Stream Ciphers:

  • RC4: Once a widely used stream cipher, now less common due to discovered vulnerabilities.
  • Salsa20: Known for its speed and security.
  • ChaCha20: A variant of Salsa20, commonly used in protocols like TLS (Transport Layer Security).

Stream ciphers are suitable for applications requiring high speed and low complexity, but selecting a secure and modern stream cipher is crucial to maintaining data confidentiality and integrity.

XOR Cipher

XOR ciphers are frequently used in malware to obfuscate code, encrypt stolen data, and protect configuration information due to their simplicity and low computational overhead. Analysts can decrypt data by extracting the XOR key from the code or memory, aiding in understanding malware behavior. Despite weak security, XOR ciphers are effective against basic detection mechanisms in malware analysis.

Key Points:

  • The XOR (exclusive OR) operation is a simple binary function used in many stream ciphers, returning 1 if only one of the bits is 1, and 0 otherwise.
  • In XOR ciphers, each bit or byte of plaintext is XORed with a corresponding bit or byte from the key, making it reversible.
  • While easy to understand and implement, XOR ciphers are not secure for most purposes unless the key is as long as the message and truly random, as in a one-time pad.

The XOR cipher's simplicity makes it a popular choice in modern malware, providing a basic yet effective means of encryption.

How the XOR Cipher Works

XOR Operation

The XOR operation takes two binary inputs and returns true (1) if the inputs are different, and false (0) if they are the same. Here is the truth table for XOR:

A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0

Encryption and Decryption Process

The XOR cipher encrypts and decrypts data by applying the XOR operation between the plaintext and the key. Because XOR is a symmetric operation (i.e., A XOR B XOR B=AA \text{ XOR } B \text{ XOR } B = AA XOR B XOR B=A), the same operation is used for both encryption and decryption.

  • Encryption: Ciphertext = Plaintext XOR Key
  • Decryption: Plaintext = Ciphertext XOR Key

Block Ciphers

Block ciphers are used in malware to encrypt payloads, exfiltrate data, protect configuration files, and secure communication with command and control (C2) servers, often using AES due to its strong security.

Notable Examples:

  • WannaCry: Utilized AES-128 for encryption.
  • Petya: Used Salsa20 for encryption.

Characteristics of Block Ciphers

  • Fixed Block Size: Operate on data blocks of fixed size (e.g., 128 bits for AES).
  • Symmetric Key: The same key is used for both encryption and decryption.
  • Modes of Operation: Different modes (e.g., CBC, ECB, CTR) determine how plaintext blocks are processed and combined.
  • Security Structure: Employ substitution and permutation operations for secure transformation.

Modes of Operation:

  • CBC (Cipher Block Chaining): Uses an initialization vector (IV) to ensure that identical plaintext blocks produce different ciphertext blocks.
  • ECB (Electronic Codebook): Each block is encrypted independently, which can reveal patterns in the plaintext.
  • CTR (Counter): Converts a block cipher into a stream cipher.

Initialization Vector (IV): A random value used to initialize the encryption, ensuring that even if the same plaintext is encrypted multiple times with the same key, the result is different each time.

Common Block Ciphers in Malware

AES (Advanced Encryption Standard):

  • A symmetric block cipher and the standard for encrypting sensitive data.
  • Operates on fixed-size blocks of 128 bits with key sizes of 128, 192, or 256 bits.
  • Involves multiple steps such as SubBytes, ShiftRows, MixColumns, and AddRoundKey.
  • The number of iterations (rounds) depends on the key size: 10 rounds for 128-bit keys, 12 rounds for 192-bit keys, and 14 rounds for 256-bit keys.

DES (Data Encryption Standard):

  • A symmetric-key block cipher once widely used but largely replaced by AES.
  • Uses a 56-bit key and operates on 64-bit blocks through 16 rounds of transposition and substitution.
  • Considered insecure due to the small key size, making it vulnerable to brute-force attacks.

RSA (Rivest-Shamir-Adleman):

  • An asymmetric encryption algorithm using a pair of keys: a public key for encryption and a private key for decryption.
  • Relies on the difficulty of factoring large prime numbers, making it robust but slow.
  • Typically used to encrypt small chunks of high-value data, such as C2 addresses or keys.
  • Often combined with symmetric encryption, where RSA encrypts the symmetric key used for the actual data encryption.

Connect with Allianz i

Together we thrive.

Contact Us