Integer Underflow @ ossl_cipher_pkcs5_keyivgen
The iterations parameter of the pkcs5_keyivgen method is not validated, so a negative value causes an infinite loop in the underlying OpenSSL function, leading to a hang and memory exhaustion. An attacker could use this to cause a denial of service.
- Disclosed after 42 days
Integer Underflow @ ossl_cipher_pkcs5_keyivgen file : ext/openssl/ossl_cipher.c affected parameter: iterations
INFO Generates and sets the key/IV based on a password. call-seq:
cipher.pkcs5_keyivgen(pass, salt = nil, iterations = 2048, digest = "MD5") -> nil
ANALYSIS iter(int) in ossl_cipher_pkcs5_keyivgen which holds iterations value is not validated before use. therefore passed on to openssl library function EVP_BytesToKey which loops over iter(iterations) using count
for (i = 1; i < (unsigned int)count; i++) {
if (!EVP_DigestInit_ex(c, md, NULL))
[code redacted]
]
if count aka iterations is negative this loop runs forever and therefore causing ruby to hang and eat up memory since allocation are performed during this loop and "i" can never be greater than count
POC
require 'digest'
require 'openssl'
require 'base64'
data = 'abc'
key = '1234567887654321'
iv = key[0..7]
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC') # or any other algorithm?
cipher.encrypt
cipher.pkcs5_keyivgen(key, iv, -1)
output = cipher.update(data)
output << cipher.final
CONFIGURATIONS ./ruby -v ruby 2.6.0dev (2018-01-11 trunk 61764) [x86_64-linux]
openssl version OpenSSL 1.0.1t 3 May 2016
Impact
This result in a DDOS Attack
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The iterations parameter is not validated before being passed to OpenSSL's EVP_BytesToKey, which uses it as an unsigned loop counter, so a negative value becomes a huge number and the loop never ends.
Impact
This could lead to a denial-of-service attack, causing the Ruby process to hang and exhaust memory.
What the attacker needed
Ability to call the vulnerable method with a negative…
How it was found
- Create a new cipher object for encryption.
- Call pkcs5_keyivgen with a negative iterations value.
- Observe that the program hangs and consumes memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a bug in a Ruby library that lets you encrypt data. When you give it a negative number for how many times to scramble the password, it gets stuck in an endless loop and keeps using more and more memory, which can crash the program.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.