I am trying to get around a situation where I need to log into the server system without being able to use ssh keys. As a result, I wording "this is bad practice" -expect script:
set arg1 [lindex $argv 0]
spawn ssh $arg1 -l user "hostname; env x='() { :;}; echo vulnerable' bash -c \"echo this is a test\"; echo"
expect " password:"
send "my_supersecret_password\n"
interact
The launch works fine:
$ ./ssh.expect server
spawn ssh server -l user hostname; env x='() { :;}; echo vulnerable' bash -c "echo this is a test"; echo
user@server password:
server
this is a test
$
But I need a better formatted list when working on multiple systems, so I'm trying to reformat perl data:
$ ./ssh.expect server | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1:$line2\n";'
:this is a test
The server name is printed as if it ends with the \ r character. I do not think that it should be so. Do you agree? How can I make the system not return to column 0 after printing the server name?
I can verify that both variables contain data by adding a new line to my print:
$ ./ssh.expect server | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1\n:$line2\n";'
server
:this is a test
EDIT:
As commented, the following works.
./ssh.expect server | tr -d '\r' | perl -e '$dump = <>; $dump = <>; chomp($line1 = <>); chomp($line2 = <>); $dump = <>; print "$line1:$line2\n";'
server:this is a test
Should tr be redundant?