Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

Reversing (and Recreating) Cryptographic Secrets Found in .NET Assemblies Using Python

Picture the scene - you’re on a penetration test, somehow you’ve got hold of a bunch of .NET assemblies for the application you’re assessing, be it a web application or thick client. On a thick client test, getting a hold of these files is somewhat trivial as they’re right there in front of you. On a web application test, however, things are not as easy - but it still is possible, depending on permissions and such. I won’t go into "the how-to" in order get these in this blog post, instead I will assume you’re sitting there, a cup of coffee in hand, staring at a bunch of .DLL files decompiled in something like dotPeek, ILSpy, etc.

Looking at the source code of decompiled assemblies relating to an application you’re assessing is an eye-opening experience. You’ll learn the inner workings of the application which will support the testing, and often, as a bonus, you’ll find hardcoded secrets, mostly in the form of user credentials – ranging from database connection strings to domain accounts. Sometimes this process can make you work a little bit harder for the rewards.

You may, for example, find no quick wins - no plaintext credentials, no advance to go and collect $200. Instead, you may find something like a reference in the source code to an external configuration file. The application may use this configuration file to look up some values and then utilise them. Imagine a reference in the source code to something like the below, we’ll call the file it references spiderconfig.xml.

Spiderxml

Let’s imagine this spiderconfig.xml file relates to a .NET web application, which utilises the domain account “SPIDER\SpideyAdmin” to carry out privileged functionality. The “==” padding right at the end of the password value should scream out right away that this is likely to be base64 encoded. Decode it and profit? Not quite! Mostly unprintables are returned – not a password in this form.

Base64decode

It is also worth stating at this point that the password may actually be the value in the config file as is, without any encoding and actually contains the characters “==” at the end. I wouldn’t rule this completely out!

Assuming that this is not actually the password, we must go back to the assembly in question and find some cryptographic references. After some browsing, a class called “crypto_component” is found, byte object names such as c_key (32 bytes) and c_iv (16 bytes), references to Rijndael, etc. I think we’re onto a winner here.

Spiderdll

We have the initialization vector (IV) and encryption key. The “Rijndael” reference reveals it to be using Advanced Encryption Standard (AES), a symmetric block cipher. We have everything we need to be able to decrypt the password value in the spiderconfig.xml file, we are just missing magical crypto stuff.

Enter Python. *faint trumpet noise can be heard in the background*

We import AES from Crypto.Cipher, together with a bunch of useful things from binascii.
[1] Both the encryption key (c_key) and iv (c_iv) are loaded into bytes objects.
We setup AES using our key and IV and configure AES in cipher block chaining (CBC) mode.
[2] We provide the base64 encoded value from the configuration file, call “a2b_base64” from binascii on it to turn it back into binary data.
[3] We then call AES decrypt on the ciphertext (which uses our key and IV).

Decryptannotations

We pull the magic crypto levers and something which more likely resembles a password is returned: Welcome1
(note: the \x08 at the end is just padding due to the block size of 16 and this being an 8 character password)

Just for fun, let’s reverse things around and encrypt this back, validating that our IV works.

[4] The plaintext “Welcome1” is passed back into AES but this time encrypting it (with our key and IV).
[5] The result of this is then passed into “b2a_base64” from binascii (but not a2b_ like last time), this converts a line of ASCII characters into base64 encoding, as per our configuration file.

Validateannotations

The final result matches the base64 encoded value in our configuration file from the start, so this confirms that both the key and IV we have work as intended.

One privileged domain account obtained. Time for a cup of tea and biscuits.

ABOUT TRUSTWAVE

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.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo