Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decryption of openssl packets with static certificates

I am working on an ethical hacking project to monitor all the encrypted packets through OpenSSL. I do have both the public and private keys (cert files). My application code snippet for regular packet decryption is as follows:

 SSL_library_init();
 ctx = InitCTX();
 server = OpenConnection(hostname, atoi(portnum));
 ssl = SSL_new(ctx);      /* create new SSL connection state */
 SSL_set_fd(ssl, server);    /* attach the socket descriptor */
 ShowCerts(ssl);        /* get any certs */
 SSL_write(ssl,acClientRequest, strlen(acClientRequest));   /* encrypt & send message */
 bytes = SSL_read(ssl, buf, sizeof(buf)); /* get reply & decrypt */
 SSL_free(ssl);        /* release connection state */

SSL_read basically gets the certificate at the time of handshaking and utilizes it for decrypting the data. Is there any way to provide the same certificate offline for decryption of data.

Any help/pointers would be highly appreciable.

like image 315
Anshul Avatar asked Jan 16 '18 14:01

Anshul


1 Answers

Generally TLS is gravitating to ephemeral key exchange, DHE or ECDHE. With ephemeral key exchange the session key (pre-master secret and master secret) are calculated using key agreement with temporary Diffie Hellman keys rather than the RSA or ECDSA key pair that is part of the certificate. So often you cannot do this.

You can however explicitly select one of the older RSA_ ciphersuites. In this case the pre-master secret is encrypted on the client side using the server's public key. The private key of the server can then decrypt this pre-master secret, calculate the session keys using the PRF (HMAC based key derivation) and then verify / decrypt all the packets.

It should be possible to do this using Wireshark, yes.


Note that TLS 1.3 will not support the RSA_ ciphersuites anymore. You would have to capture a public key of the client and private key of the server, the public key of the server and a private key of the client, or indeed the session keys directly to decrypt the traffic. Actually, that was one of the common complaints for TLS 1.3; that decrypting the traffic afterwards is not possible. That's however by design; the NSA cannot do this either.

like image 68
Maarten Bodewes Avatar answered Oct 02 '22 05:10

Maarten Bodewes