|
-
November 19th, 2007, 01:13 AM
#1
printf hacking
Hi
I have a function as below
void print(char* str)
{
printf(str);
}
now the user of the function can pass anything as the argument for print(). I am looking got major security issues with this fucntion. I mean can this fucntion be hacked somehow or can we give some input so that we can crash the program. Its a kind of urgent so please help me out with this.
raghu
-
November 19th, 2007, 01:20 AM
#2
Re: printf hacking
printf() function only display the string onto the console. If you allow input from user, the most, it will display random bits on the stack.
However, if you use function like sprintf(), memory can be overwritten that may lead your program to run spurious code injected from the user's input.
quoted from C++ Coding Standards:
KISS (Keep It Simple Software):
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
Avoid magic number:
Programming isn't magic, so don't incant it.
-
November 19th, 2007, 01:23 AM
#3
Re: printf hacking
Methinks it should be:
Code:
void print(char* str)
{
printf("%s", str);
}
I mean can this fucntion be hacked somehow or can we give some input so that we can crash the program.
I am not an expert, but I would think that this is perfectly safe as the problem would be on input, not output.
-
November 19th, 2007, 01:39 AM
#4
-
November 19th, 2007, 01:53 AM
#5
Re: printf hacking
It's very easy for a user to crash the program. All the user has to do is pass something like "%s". If the stack happens to contain zeros or something that translates into an address that the process cannot access, then it is very easy to get a core dump or a memory access violation. To make the attack have a higher chance of success, all he/she would have do is pass "%s%s%s%s%s%s%s%s%s" to the function (or something even longer).
The correct way to deal with the problem was suggested by laserlight. Try "printf("%s", str);
- Kevin
Kevin Hall
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|