Live data from Hacker News

It's All About Time – Remote timing attacks in PHP

blog.ircmaxell.com

21–30 of 52 posts

Re: It's All About Time – Remote timing attacks in PHP

#21
post #3
post #2

I've looked into timing attacks in the past but failed to exploit one. Even running php locally from the command line, eliminating any possibility of network randomness, I couldn't get even a few bytes with any amount of certainty. Not saying it's not an issue, but I'm not so sure it's a big deal either.

I wrote a tool a while ago for testing network based timing attacks. Getting the measurement right is really hard, just taking the average doesn't generally work while the 10th percentile measurement is much better. I did find PHP fairly hard to exploit though, but I was trying over a network which much more difficult than locally. The code for the tool (and a presentation pdf) is here if you're interested: https://g…

> just taking the average doesn't generally work

Oh, well yeah that's what I did. Guess I'll have to look further.

> the 10th percentile measurement is much better

That sounds like something to try, thanks!

Re: It's All About Time – Remote timing attacks in PHP

#22
post #10
post #7

Earlier quoted context omitted.

I don't know how to do [code] tags

At this time, these few options are available: https://news.ycombinator.com/formatdoc >Text after a blank line that is indented by two or more spaces is reproduced verbatim. (This is intended for code.)

I've been on this site for something like five years, but...

  I never knew that this
  functionality existed

Re: It's All About Time – Remote timing attacks in PHP

#23
post #20

How viable is this in the real world? I could imagine it working on a lone, quiet server at 4am with no other people on it. The average server with 100s of accounts, 1000s of users all doing various stuff, that's going to introduce enough random delay to throw off your analysis. Maybe you could try to calculate averages but that's going to increase the number of requests. Would a good hosting company block an attack…

> How viable is this in the real world? Not really viable against a native code memcmp. Potentially viable against a comparison implemented in PHP or Java. Here's a video looking at actually implementing such attacks over LAN and internet: http://rdist.root.org/2010/11/09/blackhat-2010-video-on-remo... > Would a good hosting company block an attack like this at the hardware level? No, there's no generic way to defeat…

Shared hosting might actually add more noise, since all the traffic to the other sites on the server will affect timings too.

Re: It's All About Time – Remote timing attacks in PHP

#24
I think the title on HN is a bit misleading. This issue applies to ALL languages and PHP has specific functions (since version 5.6) to avoid timing issues for you: hash_equals and password_verify. PHP is specifically trying to address poor authentication mechanisms by adding the (ingenious) password module to PHP's core.

Re: It's All About Time – Remote timing attacks in PHP

#25
post #6

Interesting article, I never took the time to really think about this. For optimal security, OP mentions that we should fix the underlying code, but I kind of disagree. Understanding all the underlying code is a lot of work and, except for extremely secure application, is not really needed. Also, hindering performance for security is not always the way to go (he mentions returning only at the end). If you have ultra-…

I'm not quite sure I understand what you are saying here. I don't think anyone is saying that you need to understand all the underlying code, but this is just something you should be aware of as you are building network-connected applications. Just like a web developer needs to be aware of CSRF, XSS, etc. Every language that I know of short-circuits string comparisons like this. You should know that you need to seek out a constant-time compare though when comparing hashes or other secrets.

Your sleep hack is probably less secure. I remember reading somewhere that doing random sleep() calls is flawed and doesn't completely mitigate the attack, but does increase the number of requests needed to get a good statistical analysis.

Re: It's All About Time – Remote timing attacks in PHP

#26
post #6

Interesting article, I never took the time to really think about this. For optimal security, OP mentions that we should fix the underlying code, but I kind of disagree. Understanding all the underlying code is a lot of work and, except for extremely secure application, is not really needed. Also, hindering performance for security is not always the way to go (he mentions returning only at the end). If you have ultra-…

OP here. Seeing as this question is getting asked a lot, I'll edit something into the post, but I wanted to answer you here as well.

So, there are a few problems with this technique.

1. It ignores the local timing leak

An attacker who can get code running on the server (shared hosts for example), can carefully monitor the CPU usage to see when the process is actually doing work, vs when it sleeps. So really, its not hiding anything.

2. The resolution of the sleep call is WAY too high. We're talking about detecting differences down to 15 nanoseconds. Sleeping for blocks of microseconds or even milliseconds will be far to granular. It will introduce block-like patterns in the requests that should be pretty easy to detect with statistical means.

3. It's basically identical to a random delay. Considering it depends on the system clock, and the original request comes in at a random point, it's functionally identical to calling sleep(random(1, 100)). And over time (many requests), that will average out.

Now, what if we took a different approach. What if we made the operation fixed-time?

    execstart = utime()
    // whatever code
    // clamp to always take 500 microseconds
    sleep( 500 - utime() - execduration)
That might work (assuming you have a high enough resolution sleep function). Again, it suffers the local attacker problem (which may or may not matter in your case).

However, there are two reasons I wouldn't recommend it: It requires guesswork and idle CPU.

You would either need to actively guess every single operation (and remember to clamp it) or clamp the overall application.

If you do it for every operation, that sleep time can become expensive (if you have a lot of them).

If you do it on the application level, and if you do too little, an attacker can use other expensive control (like larger input introducing memory allocation latency) to increase the runtime past the sleep clamp (hence allowing them to attack the vulnerability anyway). If you do too much, the attacker can leverage it to DOS your site (since even a sleeping process is non-trivially expensive).

There are two valid ways of protection IMHO:

1. Make sensitive operations actually constant time.

2. Implement strong IP based protections to prevent the large amount of requests that would be needed to collect enough data to analyze noisy environments. (I need to add this to the post now that I write it).

Personally, you should be doing #2 anyway. But since I also believe in defense-in-depth, I'd do #1 as well.

Re: It's All About Time – Remote timing attacks in PHP

#27

How viable is this in the real world? I could imagine it working on a lone, quiet server at 4am with no other people on it. The average server with 100s of accounts, 1000s of users all doing various stuff, that's going to introduce enough random delay to throw off your analysis. Maybe you could try to calculate averages but that's going to increase the number of requests. Would a good hosting company block an attack…

Pretty viable when you do statistical analysis across a large number of requests:

http://matasano.com/research/TimeTrial.pdf

https://github.com/dmayer/time_trial

Re: It's All About Time – Remote timing attacks in PHP

#28

I think the title on HN is a bit misleading. This issue applies to ALL languages and PHP has specific functions (since version 5.6) to avoid timing issues for you: hash_equals and password_verify. PHP is specifically trying to address poor authentication mechanisms by adding the (ingenious) password module to PHP's core.

I don't really find it misleading. It's about all sorts of remote timing attacks (including cache-timing attacks), not just passwords.

I'm the author of the pull request that prompted the discussion, though, so I'm probably biased. :)

Re: It's All About Time – Remote timing attacks in PHP

#29
post #6

Interesting article, I never took the time to really think about this. For optimal security, OP mentions that we should fix the underlying code, but I kind of disagree. Understanding all the underlying code is a lot of work and, except for extremely secure application, is not really needed. Also, hindering performance for security is not always the way to go (he mentions returning only at the end). If you have ultra-…

OP here. Seeing as this question is getting asked a lot , I'll edit something into the post, but I wanted to answer you here as well. So, there are a few problems with this technique. 1. It ignores the local timing leak An attacker who can get code running on the server (shared hosts for example), can carefully monitor the CPU usage to see when the process is actually doing work, vs when it sleeps. So really, its not…

Thank you for answering, it is true that if someone has access to the server you might be in trouble, but if he has access to a cpu monitor, he might also have access to RAM and could just get the data from there.

For the precision of sleep, http://php.net/manual/en/function.time-nanosleep.php might be more appropriate

Also, you would only need to slightly clamp very important functions, so DoS attacks aren't that likely on it (and a constant timed function would also take the same time).

Post reply on HN