Mar 21, 2023 | mobile

More security with mTLS: understand the differences compared to TLS, the importance, and vulnerabilities

B4kT3r14

Hacker

Preface

The use of the TLS (Transport Layer Security) protocol is essential to ensure the security of internet communications. However, this technology can still provide opportunities for malicious hackers. This is where mTLS (Mutual TLS) comes in, a more advanced approach that uses digital certificates to authenticate both sides of the communication.

Introduction

With the increasing number of cyber attacks and the implementation of strict data security laws such as LGPD (Brazil) and GDPR (Europe), it has become a top priority for any company that handles sensitive data or critical systems to ensure the security of such information.

In this regard, the use of security protocols such as Transport Layer Security (TLS) is essential to ensure the integrity of data in transit. However, in many situations, TLS alone is insufficient. When mutual authentication is required for the parties involved and mitigating API request analysis is necessary, Mutual TLS (mTLS) becomes an even more secure option.

In this article, we will explore what mTLS is, how it differs from TLS, its importance, and the vulnerabilities that can compromise its security.

What is mTLS?

As the name suggests, mTLS is a layer of mutual security, meaning a process in which both parties involved in a communication, usually a client and a server, authenticate each other.

Since the client is not prepared to authenticate the server locally, authentication is performed using digital certificates, which are issued by a trusted certification authority.

Both the client and server have their own digital certificates, which are verified to ensure that both are legitimate. If an mTLS connection is established correctly, the information exchanged between the parties will be encrypted and cannot be read by an attacker monitoring the connection.

This is because mTLS uses asymmetric encryption (public and private key) to authenticate and protect communication, making data interception very difficult. However, it is important to remember that the security of mTLS can be compromised if security policies are not properly implemented or if digital certificates are compromised. Therefore, it is essential to perform continuous vulnerability testing on the API and implement a WAF.

What is TLS?

Well, at this point, it is specific for people who are wondering "If this is mTLS, what is TLS and how does it work?" If you're that person, keep reading and I'll explain it to you!

Transport Layer Security (TLS) is a widely used encryption protocol on the internet. TLS, or its former version called SSL, verifies the authenticity of the server in a connection and encrypts the communication between client and server.

TLS is a security protocol used to encrypt communication between a client and a server on the internet. It uses a public key cryptography method, which relies on a pair of keys: a public key and a private key. The public key is shared with anyone who wants to communicate with the server, while the private key is kept secret by the server itself.

When a client connects to a server with TLS enabled, a negotiation process called handshake occurs, in which the client and server exchange information and establish a secure channel of communication. During this process, the server sends the client its digital certificate, which contains information about the public key and other important details for authentication.

A TLS certificate is a file that contains important information to verify the identity of a server or device, including the public key, a statement of who issued the certificate (certificate authority), and the expiration date of the certificate.

The typical TLS process works like this:

  1. The client connects to the server
  2. The server presents its TLS certificate
  3. The client verifies the server's certificate
  4. The client and server exchange information through an encrypted TLS connection.

Importance of mTLS

Although TLS is an effective security measure, in some applications it is necessary to ensure authentication of both parties involved in the communication and protect against attacks such as traffic analysis. In this way, communication only occurs when the certificates are verified.

This is where mTLS (Mutual TLS) comes in, adding an additional layer of authentication by requiring both sides to have certificates and verify each other's identity before establishing the encrypted connection. The use of mTLS is highly recommended in applications that traffic sensitive data or in critical systems.

This bilateral authentication is particularly useful in situations where the authenticity of both parties is critical to security, such as communications between different applications in a cloud environment. mTLS offers a high degree of security, but can also have vulnerabilities if digital certificates are compromised or if security policies are not properly implemented and monitored.

Compared to normal TLS, there are additional steps in mTLS to verify both parties (additional steps in bold):

  1. The client connects to the server.
  2. The server presents its TLS certificate.
  3. The client verifies the server's certificate.
  4. The client presents its TLS certificate.
  5. The server verifies the client's certificate.
  6. The server grants access.
  7. The client and the server exchange information through an encrypted TLS connection.

Vulnerabilities of mTLS

One common vulnerability in mTLS is the exposure of private keys: if a private key used for mTLS authentication is exposed, an attacker can use it to forge the identity of the server.

A second common vulnerability is a failure in certificate validation: if a client fails to verify whether the certificate presented by the server is valid, it may end up establishing an insecure connection.

For didactic purposes, let's consider the first case:

Let's imagine a hypothetical banking application that uses mTLS. It may store or receive the mTLS certificate and key insecurely.

Once an attacker has obtained a certificate and a key, they can bypass this authentication and access all traffic. For example, they can save this certificate to a .pem file and the key to a .key file.

Thus, they can generate a PKCS#12 file (.pfx). This file can be used by a proxy, such as Burp Suite, to establish this communication.

Creating a PKCS#12 file

How to generate a PKCS#12 file (.pfx extension) embedding the entire certificate chain.

To generate the .pfx file, it is essential to have all the required X.509 certificates (.cer) for the communication.

As there is only one certificate in this specific case, the command would be as follows:

Then, just choose a password for the final certificate.

Finally, once you have the certificate.pfx file, you can add it to Burp Suite as follows:

Mitigation of these vulnerabilities.

To mitigate the first vulnerability, it is necessary for the client to add the mTLS certificate to the client's trust store. This can be done through the command line or the certificate manager of the operating system.

Regarding the second vulnerability, it is necessary to configure the client application to use the mTLS certificate during authentication. The way this is done depends on the specific application, but it usually involves configuring a configuration file or a configuration object in the programming language used by the application.

References

https://www.cloudflare.com/pt-br/learning/access-management/what-is-mutual-tls/

Support us

Hacking Force is a community focused on spreading knowledge about technology and cyber security, offering a way for people to rise. We are grateful for being supported by people with the same point of view. If you indentify with it, then consider joining us.

contact@hackingforce.com.br

Principal Sponsors

nowcy

Blog Hacking Force © 2024