Skip to content

Instantly share code, notes, and snippets.

@nullenc0de
Created August 15, 2024 18:52
Show Gist options
  • Select an option

  • Save nullenc0de/672e16e010ed8613513681eb7e0604dc to your computer and use it in GitHub Desktop.

Select an option

Save nullenc0de/672e16e010ed8613513681eb7e0604dc to your computer and use it in GitHub Desktop.
need access to an internal host for nessus.
#!/bin/bash
# Configuration
LOCAL_PORT=8834
JUMP_SERVER="ubuntu@blah.compute-1.amazonaws.com"
JUMP_KEY="./ssh.pem"
NESSUS_SERVER="kali@x.x.x.x"
NESSUS_KEY="./ssh.pem"
NESSUS_PORT=8834
# Function to clean up on exit
cleanup() {
echo "Cleaning up..."
[[ ! -z $TUNNEL_PID ]] && kill $TUNNEL_PID
exit
}
# Set up trap to call cleanup function on exit
trap cleanup EXIT
# Ensure key files have correct permissions
chmod 600 "$JUMP_KEY"
# Create SSH tunnel
ssh -i "$JUMP_KEY" -L "$LOCAL_PORT:localhost:$LOCAL_PORT" -o StrictHostKeyChecking=no "$JUMP_SERVER" -t \
"chmod 600 $NESSUS_KEY && ssh -i $NESSUS_KEY -L $LOCAL_PORT:localhost:$NESSUS_PORT -o StrictHostKeyChecking=no $NESSUS_SERVER -N" &
TUNNEL_PID=$!
echo "Tunnel established. PID: $TUNNEL_PID"
echo "You can now access Nessus at https://localhost:$LOCAL_PORT"
echo "Press Ctrl+C to close the tunnel and exit"
# Wait for user to press Ctrl+C
wait $TUNNEL_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment