Reputation: 39
I have to write the c program that executes terminal commands which are in this order :
cd ../../etc
chmod a+x file
cd alice/password
more password
so if I have attack.c then by ./attack, all these should be implemented on the terminal.
I tried using execvp()
but its just not happening.
Upvotes: 0
Views: 7032
Reputation: 678
You can run shell commands in C using the system() command (works in linux)
#include <stdio.h>
#include <stdlib.h>
int main() {
system("cd ../../etc; chmod a + x file; cd alice/password; cat password");
return 0;
}
Upvotes: 4