Coder Social home page Coder Social logo

jonasalfredsson / gateway_jumper Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 15 KB

An Expect script that can complete the interactive process of entering passoword and TOTP code when setting up a SSH connection.

expect sshuttle totp oathtool jumphost 2fa

gateway_jumper's Introduction

gateway_jumper

An Expect script used to automate the otherwise interactive process of entering passwords and a TOTP code, when setting up a sshuttle connection to a destination host via a jumphost, if no other authentication options are available.

Example of command and prompts which will be filled in for you:

sshuttle -r <destination_host>

[local sudo] Password: <GWJ_LOCAL_PASS>
Password: <GWJ_JUMP_PASS>
Enter Your Microsoft verification code <totp_response>
Password: <GWJ_DEST_PASS>

โš ๏ธ Passwords need to be defined in plain text in their corresponding environment variables, so be a little bit careful with this.

Requirements

You will need to have Expect, oathtool and sshuttle installed in order for this script to work. Here is a one-liner to install them on Debian 10 Buster:

apt install expect oathtool sshuttle

Usage

In its properly configured form this script is invoked like this:

./gateway_jumper <destination_host>

where <destination_host> is the address of the host machine you want to connect to. It will "spawn" a sshuttle process which tries to connect to the address given, and it expects that this connection goes through a jumphost which require a password and a TOTP code as authentication. However, there are some setup steps which needs to be completed before this is possible to fully automate.

Configure SSH

For the easiest use of this script I suggest you populate your ~/.ssh/config with something like this:

host jump_host
 hostname jumphost.org
 user username

host destination_host
 hostname destination.org
 user username
 proxycommand ssh jump_host -W %h:%p

host *
 ForwardX11 no
 Compression yes

Here you need to change at least the username, jumphost.org and destination.org directives to what is correct for you. The jump_host and destination_host names can also be changed to something that you fancy better.

Configure this Script

At the top of the gateway_jumper script there are four variables which needs to be properly configured. This can either be done by setting the environment variables mentioned below, or by just replacing the $env(*) reader functions inside the file with the correct values directly.

  1. GWJ_LOCAL_PASS
    The password for invoking sudo on the local computer.
    Set to empty string ("") if no password is needed for local sudo.
  2. GWJ_JUMP_PASS
    This need to be set to a non-empty string, since the jumphost should require a password.
  3. GWJ_TOTP_SECRET
    This is the Base32 secret key used to create the TOTP challenge response code.
    Example: "ABCDE12FG3HIJ45K"
  4. GWJ_DEST_PASS
    The password on the final destination host.
    Set to empty string ("") if no password is needed (e.g. key-based authentication is used).

Test the Connection

Before running this automatic script I strongly suggest manually connecting to the destination host at least once so you know that the SSH command actually works.

ssh <destination_host>

If you the destination host has password authentication you should run into the following prompts:

Password:
Enter Your Microsoft verification code
Password:

Make sure what you type into these correspond to what the variables 2, 3 and 4 in the list above would have returned. To generate a TOTP response you can run the following command:

oathtool --base32 --totp "${GWJ_TOTP_SECRET}"

(Optional) Edit the sshuttle Command

You can do quite a lot with sshuttle, so if you have any personal settings you want to use it should be easy to add this on the "spawn" line in the script.

You are also not limited to only running sshuttle, you could change the command after the "spawn" to any command which would cause the same prompts as mentioned in the beginning to appear and still use this script. Or you can use this script as a start to automate you own special case.

(Optional) Add this Script to $PATH

If you want to be able to call this script from anywhere on your system you can add this folder to your $PATH. This can be done by including the following line at the bottom of your ~/.bashrc or ~/.zshrc file:

PATH="/path/to/gateway_jumper:${PATH}"

By sourcing the edited file again, or just opening a new terminal, it should now be possible to use gateway_jumper without having to provide the full path.

gateway_jumper's People

Contributors

enniomara avatar jonasalfredsson avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

enniomara

gateway_jumper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.