Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More
Get access to immediate incident response assistance.
Get access to immediate incident response assistance.
Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More
In Mexico, it’s possible to receive your monthly bank statement via email.
Mexico's banking and securities regulator (CNBV) says that security mechanisms must be applied to the bank statement to avoid an unauthorized third party.
CitiBanamex sends two types of Bank Statements via email:
The Smart Statement is an HTML file that requests a password to decrypt the content of your monthly credit card statement.
After some analysis of the HTML, here’s what it contains:
Clearly, we must dig in the JavaScript code to understand what’s going on.
Figure 1. Logic diagram for decryption
The ‘desenc’ function is quite simple. It makes mainly two things:
We can see the code in the following image:
Figure 2. Code of the “desenc” function
Here’s the decrypt function:
Figure 3. Code of the “decrypt” function (RC4)
After some analysis, we can conclude it looks like RC4.
RC4 (Rivest Cipher 4) is a stream cipher, also known as ARC4 or ARCFOUR. It’s more than 20 years old (Leaked in 1994 & designed in 1987). It’s not considered a strong encryption algorithm.
The only difference with the original RC4 algorithm is line 18, since it’s not adding 1.
There are some attacks on the RC4 algorithm like “Fluhrer, Mantin and Shamir attack”, “Royal Holloway attack”, “NOMORE attack”, amongst others, but they are not simple to execute.
You should never use the same key to encrypt more than one message in any stream cipher. However, in this case, they use the same key to encrypt 30 different messages. We can take advantage of this.
The desired output is HTML, and we can perform a Known-plaintext attack since the first part of the HTML will be the same for every bank statement (it includes some CSS & JS code).
Here is a simple diagram of how the encryption works:
Figure 4. Simplified diagram of a stream cipher
Since we have the Encrypted Text (it’s in the HTML) and we have the Plain Text (the first block is always the same, and we can obtain it from any Bank Statement we have access to) we can use them to obtain the keystream. Finally, we will use the keystream to decrypt the rest of the encrypted blocks.
The attack will use the following logic:
Figure 5. Idea behind the attack
After the vendor notified us that they had fixed the issue, we verified that it was indeed fixed. They stopped using RC4, and the decrypt function now uses AES:
Figure 6. Code of the new “decrypt” function
The use CryptoJS v3.1.2 for all the cryptographic functions and that’s a good idea.
This issue was disclosed to the vendor in a timely manner, and this blog post was held until the problem was fixed. Here’s the disclosure timeline:
To conclude this post, I would like to share some recommendations & thoughts:
Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.
Copyright © 2024 Trustwave Holdings, Inc. All rights reserved.