News for hackers. Stuff that matters.
Re:Best of show – abuse of libc by tomjakubowski on Friday January 08, 2021 @05:55PM (#25691598)
GNU's printf specifier language is Turing complete, I believe.
Re:Best of show – abuse of libc by alisonkisk on Friday January 08, 2021 @05:57PM (#25691615)
Theres a great example of what you can do with this, submitted and discussed on HN here: https://news.ycombinator.com/item?id=25690319
Re:Best of show – abuse of libc by notretarded on Friday January 08, 2021 @06:58PM (#25692763)
>Format specifiers can take extra “arguments”. - "%hhn": store the number of bytes written mod 256 to the char pointer ...

Oh boy. I'll put that down for my "thing I don't think I wanted to know" of the day.

Re:Best of show – abuse of libc by snerp on Friday January 08, 2021 @08:51PM (#25695075)
There is some innocent beauty in the twistedness of printf - especially with GNU extensions.
Re:Best of show – abuse of libc by dfcowell on Friday January 08, 2021 @08:59PM (#25695217)
So I can port doom to gnu printf?
Re:Best of show – abuse of libc by kortilla on Friday January 08, 2021 @09:14PM (#25695434)
GNU's printf specifier language is Turing complete, I believe.
Re:Best of show – abuse of libc by a1369209993 on Friday January 08, 2021 @09:35PM (#25695651)
GNU's printf is Turing complete[0]... so "yes."

[0] Mentioned (but not directly linked) by TFA:

https://www.usenix.org/conference/usenixsecurity15/technical...

Re:Best of show – abuse of libc by SahAssar on Friday January 08, 2021 @09:40PM (#25695704)
GNU's printf specifier language is Turing complete, I believe.
Re:Best of show – abuse of libc by gu5 on Friday January 08, 2021 @11:51PM (#25697199)
What is up with this thread? These comments are duplicated from the top thread...
Re:Best of show – abuse of libc by dang on Saturday January 09, 2021 @12:00AM (#25697278)
Is it possible that it's a joke based on the material of the OP? Maybe we're trapped in some sort of International Obfuscated Internet Thread Contest...

Edit: ok, I'm guessing it's a joke about Turing completeness. Loops, you know.

Re:Best of show – abuse of libc by saagarjha on Saturday January 09, 2021 @01:28AM (#25697973)
It’s a joke about the recursion introduced here: https://news.ycombinator.com/item?id=25691615.
Re:Best of show – abuse of libc by Bootvis on Saturday January 09, 2021 @05:27AM (#25699199)
Well executed jokes on HN. 2021 already is a crazy year.
Re:Best of show – abuse of libc by gu5 on Saturday January 09, 2021 @12:07AM (#25697337)
Ohhhh... Now I get it.
Re:Best of show – abuse of libc by exikyut on Friday January 08, 2021 @11:59PM (#25697266)
(The usernames are different)
Re:Best of show – abuse of libc by FartyMcFarter on Friday January 08, 2021 @08:15PM (#25694365)
Presumably it needs a loop around it, so it's not Turing-complete by itself?
Re:Best of show – abuse of libc by npongratz on Friday January 08, 2021 @10:46PM (#25696547)
No need to use a loop around it, printf can take care of that pesky detail for you! To quote [0] (my emphasis):

> To achieve full Turing-complete computation, we need a way to loop a format string. This is possible by overwriting the pointer inside printf() that tracks which character in the format string is currently being executed. The attacker is unlucky in that at the time the “%n” format specifier is used, this value is saved in a register on our 64-bit system. However, we identify one point in time in which the attacker can always mount the attack. The printf() function makes calls to puts() for the static components of the string. When this function call is made, all registers are saved to the stack. It turns out that an attacker can overwrite this pointer from within the puts() function. By doing this, the format string can be looped.

> An attacker can cause puts() to overwrite the desired pointer. Prior to printf() calling puts(), the attacker uses “%n” format specifiers to overwrite the stdout FILE object so that the temporary buffer is placed directly on top of the stack where the index pointer will be saved. Then, we print the eight bytes corresponding to the new value we want the pointer to have. Finally, we use more “%n” format specifiers to move the buffer back to some other location so that more unintended data will not be overwritten.

[0] https://www.usenix.org/system/files/conference/usenixsecurit..., Appendix B "Printf is Turing-complete".

Re:Best of show – abuse of libc by saagarjha on Saturday January 09, 2021 @01:27AM (#25697969)
Or, you know, you can just use printf to overwrite the return address and ROP your way to a shell.
Re:Best of show – abuse of libc by xyproto on Saturday January 09, 2021 @04:50AM (#25699013)
Herein lies madness
Re:Best of show – abuse of libc by moonchild on Friday January 08, 2021 @09:24PM (#25695536)
Not portable, but if you can get the address of the stack you can force printf to overwrite the return address, obviating the loop.
Re:Best of show – abuse of libc by shakna on Friday January 08, 2021 @10:04PM (#25695942)
It does not need the loop. It might be easier to understand by looking at something like this. [0] That printf allows for this kind of Turing complete control flow is well known [1].

[0] https://github.com/HexHive/printbf

[1] http://nebelwelt.net/publications/files/15SEC.pdf

Re:Best of show – abuse of libc by moonchild on Friday January 08, 2021 @10:19PM (#25696138)
Re:Best of show – abuse of libc by fulafel on Saturday January 09, 2021 @09:56AM (#25700821)
The implementation is accidentalyl turing-complete because you can exploit it to get arbitrary memory writes. But the language as specified is not Turing-complete.