views:

21

answers:

2

I have been trying to write a simple brute force password cracker in C++ to open an old zip file that I locked a very long time ago.

I am trying to call pkunzip from the program. The only way I know to do this is using the system() command. As in system("astring");. The problem is that I need to dump a new password into the string each time over and over until I get a hit. That would require inserting a variable into to command that I am sending to DOS. That is where I get lost. So the code could look something like this...

 system("pkunzip lockedFile -s[the password variable here]")

Also, this entire idea may be horrible, so if there is a better way then please just say.

Also, can I use a cd\ command to get to the proper directory, or do you just have to dump the relevant files in the same directory as the C++ project itself. Any help or general pointers would be much appreciated. m.hatter

A: 

You could always use a sprintf to create the string. As in:

command = sprintf("pkunzip lockedFile -s%s", password);
system(command);

If you're sick of calling this external program, you might want to handle the Zip file internally with a library like the zip utils library.

amphetamachine
OK...both of these responses give me something to think about. I will investigate. Thanks!!!!
+1  A: 

Would this do?

char buf[120];
sprintf(buf, "cd\\; pkunzip %s -s[%s]", locked_file, password_var);
system(buf)

I used the double backslash to escape into a single backslash for the cd command to work.

Hope this helps, Best regards, Tom.

tommieb75