Skip to content
DoS Disclosed report Beginner

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.

finb Follow

Originally disclosed on HackerOne

Informational View original
  • 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

The original report as published on HackerOne, by finb. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Create a new cipher object for encryption.
  2. Call pkcs5_keyivgen with a negative iterations value.
  3. 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.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.