1
What I'm trying to do is execute an ssh command that prints out the /etc/shadow
file. Obviously that file requires root or sudo
permission, and I don't have root creds, therefore I have to use sudo
.
Here is the command I've worked out:
expect -c 'spawn -noecho ssh -q -t -S /tmp/t2.ssh dummy "sudo cat /etc/shadow";expect "assword"; send "password99\r";interact'
It outputs exactly what I need, but it also outputs the prompt for the sudo password on the very first line:
[sudo] password for student99:
root:$x$xxx:18029:0:99999:7:::
daemon:*:17575:0:99999:7:::
bin:*:17575:0:99999:7:::
sys:*:17575:0:99999:7:::
sync:*:17575:0:99999:7:::
Without using other programs (like grep, awk, tail, etc) is there a way to modify the expect
command so that it prints only the output of the cat command and not the [sudo] password for student99:
prompt?
Solution:
Thanks to @larsks, my final working command is:
expect -c 'spawn -noecho ssh -q -t -S /tmp/t2.ssh dummy "sudo cat /etc/shadow";log_user 0;expect "assword"; send "password99\r";interact'
This is it! Thank you!
My final command is:
expect -c 'spawn -noecho ssh -q -t -S /tmp/t2.ssh dummy "sudo cat /etc/shadow";log_user 0;expect "assword"; send "password99\r";interact' – beechfuzz – 2019-05-22T02:27:02.077