Suppose we are on a compromised computer (for example infested with trojans logging key presses or taking screenshots) and for some reason we have to generate a number that's supposed to be secret for the purpose of using in a script.

Using ruby, when I do something like Random.new.rand, the random number generator is seeded with the current time, process ID and a sequence number. Considering the characteristics of these kinds of malware, can you think of any better sources of entropy we can introduce to the seed which are harder to capture?

  • 3
    If the computer is compromised, do you have a reason to believe that the attacker can't simply read that number after it's been taken from the secure source of entropy? Or that approach/code that you implement will be faithfully executed instead of skipping your true_random and replacing it with an attacker-chosen value before it's used? – Peteris Feb 1 '18 at 0:12
  • As an extreme example: it's possible that a compromised computer is recording every possible input (including values from the network or hardware random number generators) and is running in a deterministic way such that the attacker can play back and debug any computation that was done and inspect any transient values. – Macil Feb 1 '18 at 0:32
  • @AgentME I'm not sure that would be possible for a modern IBM-type PC. There is too much not-totally-deterministic behavior (jitter in the PIC timer, etc) that would make it hard to calculate the state of the entropy pool just by recording inputs. You would have to run a flawless cycle-accurate emulator, and a cycle-accurate emulator for a modern x86 IBM-type PC is simply unheard of. – forest Feb 1 '18 at 3:14
  • 1
    if it's hacked, how do you know it's even ruby, and not something provided by the attacker? – dandavis Feb 1 '18 at 12:17
  • @forest See rr-project.org, which can deterministically record the inputs to and replay runs of many x86 programs, including the QEMU VM software, which a whole OS and any software could be run in. -- I'm actually surprised that my extreme example is as realistic as this; the point of my example wasn't that it's realistic exactly as described, but that it easily illustrates a large set of the things an intelligent attacker would be technically able to do with enough effort. The fact that it might actually be realistic now is neat though. – Macil Feb 2 '18 at 23:54

If the machine is compromised - there is nothing that you can introduce to make it harder to capture - they own the box, the memory and the OS.

From what little I understand of Ruby as well the choice of Random is wrong for anything to be secured as it is only a pseudo-random number generator and instead you should be using SecureRandom.

With SecureRandom you won't need to try and find other sources of entropy.

  • 1
    If the machine is compromised, the ruby you think are using may in fact be a ruby created/modified/hacked by the intruder such that SecureRandom generates a string the intruder can predict. – RedGrittyBrick Feb 1 '18 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.