12 - Attacking Crypto
12 - Attacking Crypto
Penetration Testing
eXtreme
Attacking Crypto
S e c t i o n 0 1 | M o d u l e 1 2
© Caendra Inc. 2020
All Rights Reserved
Table of Contents
Encryption
Fundamentals
Image credits: https://twitter.com/beingsecure WAPTXv2: Section 01, Module 12 - Caendra Inc. © 2020 11
12.1.3 Attacks Against Crypto
It is about time we start talking about identifying and exploiting insecure
crypto implementations. The attacks against crypto implementations can
be divided as follows.
Insecure Password
Reset
Padding Oracle
Attack
To put that in English: each block of ciphertext decrypts to an unknown value, then is XOR’d with the previous
block of ciphertext. By carefully selecting the previous block, we can control what the next block decrypts to.
Even if the next block decrypts to a bunch of garbage, it’s still being XOR’d to a value that we control, and can
therefore be set to anything we want.”
First:
git clone https://github.com/apache/shiro.git
cd shiro
git checkout shiro-root-1.4.1
mvn install
Then,
cd samples/web
mvn install
Finally copy the samples-web-1.4.1.war package (samples / target /) obtained after compilation
to the Tomcat webapps directory, and start tomcat.
Hash Length
Extension Attack
Request:
stock_quantity=20&price=1000
Hash:
[secretpass|stock_quantity=20&price=1000|padding] => Hash1/State1
Final Request:
stock_quantity=20&price=1000&hash=Hash1
Attack Hash:
[secretpass|stock_quantity=20&price=1000|padding|&price=100]
Attack Hash:
[State1|&price=10] => Hash2/State2
Final Request:
stock_quantity=20&price=1000+padding&price=100&hash=Hash2
Leveraging
machineKey
If you read the above, you will conclude to the below logic (pseudocode).
MAC_HASH = MD5(serialized_data_binary + validation_key +
0x00000000 )
VIEWSTATE = Base64_Encode(serialized_data_binary + MAC_HASH)
https://referencesource.microsoft.com/#system.web/UI/ObjectStateFormatter.cs
https://referencesource.microsoft.com/#System.Web/Configuration/MachineKeySection.cs
WAPTXv2: Section 01, Module 12 - Caendra Inc. © 2020 52
12.5.2 Leveraging a leaked machineKey for
RCE
part, we will need # Get machine key by uploading .shtml file (Server Side Include)
validation_key = bytes.fromhex('b07b0f97365416288cf0247cffdf135d25f6be87')
Credits to [email protected] for the exploit WAPTXv2: Section 01, Module 12 - Caendra Inc. © 2020 54
12.5.2 Leveraging a leaked machineKey for
RCE
Remote code
execution was
achieved!
Subverting HMAC
in Node.js
Not So Secure
https://www.notsosecure.com/
Class CookieRememberMeManager
https://shiro.apache.org/static/1.2.2/apidocs/org/apache/shiro/web/mgt/CookieRemember
MeManager.html
wuppp/shiro_rce_exp
https://github.com/wuppp/shiro_rce_exp/blob/master/shiro_exp.py
SpiderLabs/CryptOMG
https://github.com/SpiderLabs/CryptOMG
iagox86/hash_extender
https://github.com/iagox86/hash_extender
MachineKeySection.cs
https://referencesource.microsoft.com/#System.Web/Configuration/MachineKeySection.cs
HMAC
https://en.wikipedia.org/wiki/HMAC
*Labs are only available in Full or Elite Editions of the course. To access, go to the course in your
members area and click the labs drop-down in the appropriate module line or to the virtual labs
tabs on the left navigation. To UPGRADE, click LINK.
WAPTXv2: Section 01, Module 12 - Caendra Inc. © 2020 | p.64