0

Is there a way to do the below and spawn the second command as root?

 sudo whatever && /bin/sh

I tried it with the below but it still puts me as the original user.

sudo who && /bin/sh

I want to know if you can spawn a shell via running a second command once sudo was invoked ONCE. This is important, as I can't run a command like sudo x && sudo y for the testing I'm trying to create regarding (what I believe) is vulnerable coding in an app that (in the backend) executes a program as sudo. I just need to try and tag a command on the front of it to see if I can immediately just spawn a root shell.

1 Answers1

0

Something like:

sudo bash -c 'date && sleep 2 && echo $USER && date'

Note the $USER must be single-quoted to ensure it is evaluated within the sudo bash. If it is double-quoted, it gets evaluated by the regular user's bash before the sudo is actioned.

Paul_Pedant
  • 8,679