Live data from Hacker News

Pulling JPEGs out of thin air

lcamtuf.blogspot.com

21–30 of 86 posts

Re: Pulling JPEGs out of thin air

#21
post #19

At the risk of sounding really stupid. Can someone ELI5 what's going on here and why everyone thinks its so amazing?

It starts with an invalid .jpg (literally a text file containing "hello"), and by trying over and over, changing random bytes and tracing the execution of the decoder program as it is fed the corrupted input, it will drill deeper and deeper into the program until it has gotten far enough that the input is actually a valid .jpg, without any human input.

Fuzzing like this is a very effective technique for finding (security) bugs in programs that parse input, because you will quickly end up with "impossible" input nobody thought to check for (but is close enough that it won't be rejected outright), and whoops there's your buffer overflow.

In this particular case, the fuzzer is going beyond just throwing random input, as it considers which changes to the input trigger new code paths in the target binary, and therefore should have a higher success rate in triggering bugs compared to just trying random stuff. And don't forget, this will work with any type of program and file type, not just .jpgs and the djpeg binary.

Re: Pulling JPEGs out of thin air

#22
post #6

Earlier quoted context omitted.

Why impossible? (Hint: 127/8 is a network, too.)

This is a no-fun zone :) I thought the comment author meant to release (the kraken) out in the open - to test publicly (or at least on LAN) available services. Or am I missing something?

If you find problems in a local Apache, it's a good bet those may also be problems with some remote Apaches somewhere on the Internet.

Re: Pulling JPEGs out of thin air

#23
post #19

At the risk of sounding really stupid. Can someone ELI5 what's going on here and why everyone thinks its so amazing?

This is how I understand it:

1) JPEG file structure is complex (much more so than a BMP file for example). 2) Imagine you didn't know what it looked, but had a tool that could "read" them. djpeg in this case 3) What the fuzzer does is "peek" at how the djpeg tool reacts to random "fuzzed" data. It's smart about it, understanding when a bit of data makes the tool do something new (code path) 4) After millions of iterations it "learns" how JPEG file structure works and can generate valid JPEGs.

This might not be very relevant for JPEGs, given that you can just Google their structure. This is cool because it shows how the tool could figure out (or find a weakness in) something where you don't know how it works.

Re: Pulling JPEGs out of thin air

#24
post #7

Earlier quoted context omitted.

Yeah, netcat would be fun. Although, it seems that it also straces (or similar?) the app it tests. > it triggers a slightly different internal code path in the tested app This would be impossible on the network.

>Yeah, netcat would be fun. Although, it seems that it also straces (or similar?) the app it tests. Ah yes, I forgot this little detail. I wonder if you can get it to work on the local machine first, but talking throught a socket instead of stdin. Then , pipe the result throught netcat !

Conceptually the output generation and the trace collection aren't coupled. As long as you can (a) instrument the target to collect traces and (b) programmatically feed it variant inputs, the same technique will work.

(This isn't a new concept, although afl is a particularly tight implementation of it; you can look up the paper for "autodafe" for a (much) earlier version).

Re: Pulling JPEGs out of thin air

#25
post #19

At the risk of sounding really stupid. Can someone ELI5 what's going on here and why everyone thinks its so amazing?

This describes a program (afl) which is given another program (djpeg, some kind of JPEG parser - takes arbitrary data and decides if its JPEG or not) to play with.

afl starts feeding it random inputs gradually gaining limited understanding about what it accepts and what it does not.

Eventually, it gathers enough info (based on strace'ing, google it, and its output) to start pulling JPEG images out of thin air like it's nothing.

The catch is, that this afl program learns this all by itself, and it can do so with any other parser program (like ELF parsers, GIF parsers, whatever). It is a general purpose tool.

Also, similar concept can be applied to things like web servers, or any other servers (since they parse what clients send them).

Re: Pulling JPEGs out of thin air

#27
post #13

This is totally amazing! Wondering if it would be possible to go the other way around: from generated JPG to a string. If yes, what a cool way to send your password as a... JPG over email.

Along similar lines, I wonder if this fuzzer can be used to bruteforce passwords for applications. Would it do any better than standard "try all the combinations" method?

Not really, because it depends on collecting traces from the target, and if you can do that you can usually just read the password out of memory.

Re: Pulling JPEGs out of thin air

#29
post #10

Regarding >if (strcmp(header.magic_password, "h4ck3d by p1gZ")) goto terminate_now; How impossible would it be to look at the branching instruction, perform a taint analysis on its input and see if there is any part of the input we can tweak to make it branch/not branch. Like, we jumped because the zero flag was set. And the zero flags was set because these two bytes were equal. Hmm that byte is hardcoded. This other…

...or just preload a special implementation of strcmp that makes notes of its inputs.

Re: Pulling JPEGs out of thin air

#30
post #27
post #13

Earlier quoted context omitted.

Along similar lines, I wonder if this fuzzer can be used to bruteforce passwords for applications. Would it do any better than standard "try all the combinations" method?

Not really, because it depends on collecting traces from the target, and if you can do that you can usually just read the password out of memory.

On the flip side, it could probably be used as a really slow universal keygen for naive license-key implementations :)
Post reply on HN