How can i append a program to another and then run it?
I have a little program in mind:
void main(void)
{
printf("Password");
gets(pass);
if(!strcmp(pass,"Something"))
//execute program in the same binary
else
printf("Wrong password");
}
I ne开发者_StackOverflow社区ed a password to run a program, the program must be in the same executable, and considering that i don't have the source code the idea is to append the second program to the first.
I take some action in my own program and then i run the second program.
¿How can I do this?
I'm not sure it's going to be that easy to stitch binaries together. Do they have to be a single executable?
If not, then a very close approimxation is to use one of the exec functions, assuming you're working under *nix.
You can't do this in (anything close) to the way you seem to want. You can manage to do it, but it's a fair amount of work. Basically, you have to concatenate the two programs together, with yours first so it's the one that will execute. Your program will then have to extract the other to a temporary file, execute it, and then delete that temporary file after it's done (or, if available, use OS functions to ensure it's deleted automatically).
Also note that this is extremely fragile on a number of levels -- a hacker who knows what he's doing will probably break your attempt at security in less time than it took you to do it to start with.
Use the system
code like this
system("binary_code.exe")
It might be preferrable to specify the path to the binary_code.exe
but .... what happens if the external program is removed... you need to handle that and take it into account.
Also, you are asking for trouble by using the obsolete gets
code which is buffer exploitable... use fgets
instead!
精彩评论