News for hackers. Stuff that matters.
Re:Don't run 'strings' on untrusted files by bjackman on Saturday October 25, 2014 @12:19PM (#8508582)
I'm probably going to sound painfully naive now... but why is that a security risk? So libbfd reads past the end of a buffer and segfaults.. so what? It's not writing or executing anything untoward, so who cares?
Re:Don't run 'strings' on untrusted files by jrockway on Saturday October 25, 2014 @03:31PM (#8509115)
The security risk is that input from the file that strings is run on ends up in places it shouldn't. One classic place is on the stack; after the random data your function puts on the stack is a bunch of bookkeeping information the compiler puts there, including the address to jump back to when the function returns. If you read user data onto the stack carelessly, you can overwrite the instruction pointer with attacker-controlled data, and the program will return from the function, jump there, and begin executing code.

In this case, he was just fuzzing with "AAAAAAAAAAA" and the program ended up at 0x41414141 ("AAAA"), which is alarming. The next step would to be to figure out where the input file is in memory, replace AAAA with that address, and replace the data there with code. Now "strings" is executing CPU instructions that were in the input file. That's bad.

Some compilers do workarounds, like putting a canary value between the user data and the compiler data, and checking the canary before returning. Some compilers also randomize the location where things go in memory, so it's harder for an attack to predict that address. Some OSes set certain pages to "not executable", so even if an attacker can jump to that memory address, the CPU won't run code from there. None of these are fixes; just barriers for the determined attacker. (W^X is easy to get around, just call code that's already in the binary legitimately, like execve()!)

The fix is to only write to memory you've actually allocated; something the C compiler will not help you with.

Re:Don't run 'strings' on untrusted files by Confusion on Sunday October 26, 2014 @07:32AM (#8510807)
> That's bad.

To emphasize to the casual reader: 'bad' is a bit of an understatement: it's 'game over'.

Re:Don't run 'strings' on untrusted files by JoshTriplett on Saturday October 25, 2014 @12:21PM (#8508588)
Segfaults frequently indicate exploitable security holes, and in particular, the fuzz test shown in the article shows a segfault at a user-controlled address (0x41414141 is AAAA).
Re:Don't run 'strings' on untrusted files by jsaxton86 on Saturday October 25, 2014 @12:58PM (#8508693)
Consider the case of a buffer overrun, a vulnerability that can often cause segfaults. A clever attacker could write a bunch of nasty code to that buffer, then use the buffer overrun to insert a jump statement back to that malicious code. Maybe they added the equivalent "rm -rf $HOME`" or something. Or maybe they decided to dial home with a reverse shell on your system. You have no idea, since you have no control over what code is being executed.
Re:Don't run 'strings' on untrusted files by panzi on Saturday October 25, 2014 @01:01PM (#8508705)
How will they do this if it's a read buffer overflow, not a writer overflow?
Re:Don't run 'strings' on untrusted files by zxcdw on Saturday October 25, 2014 @01:42PM (#8508803)
A "read buffer" overflow is still nothing but a program reading some form of input and then overwriting the buffer. The target program has to read to somewhere -- namely to the buffer -- and thus it has to write over the boundaries of the buffer.

Because the buffer is local to the function, and because the function return address happens to reside at a higher address than the buffer itself, you probably get to overwrite the return address. Thus, after the function is executed, the execution doesn't return to the call-site but to the address you specified. Place your payload code in the buffer you provided, and overwrite the function return address to be the address of your buffer and you might do all sorts of fun things. Spawn a root shell (if suid binary), spawn a reverse shell, execute a kernel exploit to get root etc.

Re:Don't run 'strings' on untrusted files by panzi on Saturday October 25, 2014 @10:07PM (#8510059)
> A "read buffer" overflow is still nothing but a program reading some form of input and then overwriting the buffer. The target program has to read to somewhere -- namely to the buffer -- and thus it has to write over the boundaries of the buffer.

Who says that? That would be a write buffer overflow. The place where they write to might be properly allocated, so no memory that shouldn't be written is ever written. At least that is how I read it. The OpenSSL bug (heart bleed) was a read overflow. You couldn't use it to inject code, but you could use it to read out private keys.

Re:Don't run 'strings' on untrusted files by eli on Saturday October 25, 2014 @01:13PM (#8508738)
Because you control a bunch of memory around that buffer anyway. It's reading a file that you have complete control over, after all. The fact that it crashed at address "41414141" strongly suggests its exploitable. That value is like the "hello world" of testing vulnerabilities.
Re:Don't run 'strings' on untrusted files by panzi on Saturday October 25, 2014 @10:10PM (#8510062)
If something that shouldn't be written is written then yes. But from all the reports it sounds like it just reads something that shouldn't be read and produces a segmentation fault because it reads an unallocated page. I could be wrong about what happens, I haven't looked at it in detail. That is how the news reports sound like to me, so I wonder how could one use that to execute code?
Re:Don't run 'strings' on untrusted files by eli on Sunday October 26, 2014 @07:27AM (#8510799)
To quote the linked article: "The 0x41414141 pointer being read and written by the code comes directly from that proof-of-concept file and can be freely modified by the attacker to try overwriting program control structures."
Re:Don't run 'strings' on untrusted files by panzi on Sunday October 26, 2014 @12:38PM (#8511478)
I seem to have overlooked the "and written".
Re:Don't run 'strings' on untrusted files by pumpkinross on Saturday October 25, 2014 @12:48PM (#8508668)
Having any segfault is historically a strong indicator that there are worse things you have yet to discover.
Re:Don't run 'strings' on untrusted files by jrockway on Saturday October 25, 2014 @08:17PM (#8509866)
Segfault: interesting. Segfault at 0x41414141 when your input is "AAAA": alarming.
Re:Don't run 'strings' on untrusted files by hueving on Saturday October 25, 2014 @01:44PM (#8508809)
I don't see the vulnerability here either. The current responses to your post don't actually point to any exploitable vulnerability either.