by shakna · 6y ago · 0 comments
All of these are valid:
displayln("Hello, World!");
displayln(100);
displayln(1.8);
The point is, for simple things, to not have to specify how they appear.> Well... Because it should have been
> printf("Hello, World!\n");
No. You don't really want to do that. If you're doing that, use puts [0] . All this requires is a modification to one string in memory and you have an injection vulnerability.
I'm pathologically lazy.
Also as others point out typically the literal string will be in a ro segment so tampering with it won't be easy unless the code runs in a rather exotic environment.
This is not the case for RO strings, is it?
If we're being pedantic, it's _unspecified behaviour_. The implementation isn't required to document how it would behave.
By modifying the start of that string, you can begin reading and writing to various parts of the stack.
Whilst implementations may inline that string into a RO memory region - that's not defined behaviour, so you shouldn't depend on it.
[0] https://owasp.org/www-community/attacks/Format_string_attack
In order to modify that string, even in RW pages, the attacker already has to have access, at which point the point is moot. It's like saying "if you can change memory, then you can change memory"....
printf("Hello, World!\n");
really any safer than this? printf("%s\n", "Hello, World!");> Originally thought harmless, format string exploits can be used to crash a program or to execute harmful code.
They are not the same as puts. Puts can allow you to potentially read memory.
A format string attack can allow you to write to memory.
[0] https://en.wikipedia.org/wiki/Uncontrolled_format_string
Nothing.
Neither is more secure, all modern compilers put both “%s” and “Hello, world!” in rodata sections.
Your understanding of practical format string attacks is misguided.