0

I have to write the c program that executes terminal commands which are in this order :

  1. cd ../../etc

  2. chmod a+x file

  3. cd alice/password

  4. 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.

3
  • "that implements" do you want to say "that executes"? Commented Oct 14, 2018 at 10:39
  • Possible duplicate of How do I execute a Shell built-in command with a C function? Commented Oct 14, 2018 at 10:39
  • Question is kind of similar but the solution is not working.I just want like a conversion of these four commands Commented Oct 14, 2018 at 10:43

1 Answer 1

4

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;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Bonus: figure out why this doesn't do what I think you want.
@stolenmoment Check the modified version please

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.