xs/README.md

170 lines
8.3 KiB
Markdown
Raw Permalink Normal View History

2018-12-09 05:35:13 +00:00
[![GoDoc](https://godoc.org/blitter.com/go/hkexsh?status.svg)](https://godoc.org/blitter.com/go/hkexsh)
HKExSh
--
2018-11-14 08:11:12 +00:00
HKExSh (**H**erradura**K**yber**Ex** **Sh**ell) is a golang implementation of a simple
remote shell client and server, similar in role to ssh, offering
2018-12-09 05:35:13 +00:00
encrypted interactive and non-interactive sessions, file copying and tunnels with traffic obfuscation ('chaffing').
2018-11-14 08:11:12 +00:00
***
2019-04-09 05:24:01 +00:00
**NOTE: Due to the experimental nature of the KEX/KEM algorithms used, and the novelty of the overall codebase, this package SHOULD BE CONSIDERED EXTREMELY EXPERIMENTAL and USED WITH CAUTION. It DEFINITELY SHOULD NOT be used for any sensitive applications. USE AT YOUR OWN RISK. NEITHER WARRANTY NOR CLAIM OF FITNESS FOR PURPOSE IS EXPRESSED OR IMPLIED.**
2018-11-14 08:11:12 +00:00
***
The client and server programs (hkexsh and hkexshd) use a mostly drop-in
replacement for golang's standard golang/pkg/net facilities (net.Dial(), net.Listen(), net.Accept()
and the net.Conn type), which automatically negotiate keying material for
2018-11-14 07:29:28 +00:00
secure sockets using one of a selectable set of experimental key exchange (KEX) or
2018-10-11 05:08:57 +00:00
key encapsulation mechanisms (KEM).
Currently supported exchanges are:
* The HerraduraKEx key exchange algorithm first released at
[Omar Elejandro Herrera Reyna's HerraduraKEx project](http://github.com/Caume/HerraduraKEx);
* The KYBER IND-CCA-2 secure key encapsulation mechanism, [pq-crystals Kyber](https://pq-crystals.org/kyber/) :: [Yawning/kyber golang implementation](https://git.schwanenlied.me/yawning/kyber)
2019-04-09 05:24:01 +00:00
* The NEWHOPE algorithm [newhopecrypto.org](https://www.newhopecrypto.org/) :: [Yawning/go-newhope golang implementation](https://git.schwanenlied.me/yawning/newhope)
2018-10-11 05:08:57 +00:00
2018-11-14 08:11:12 +00:00
Currently supported session algorithms:
2018-10-11 05:08:57 +00:00
2018-11-14 08:11:12 +00:00
[Encryption]
2018-10-11 05:08:57 +00:00
* AES-256
* Twofish-128
* Blowfish-64
2018-12-09 05:35:13 +00:00
* CryptMTv1 (64bit) (https://eprint.iacr.org/2005/165.pdf)
2018-11-14 08:11:12 +00:00
[HMAC]
2018-10-11 05:08:57 +00:00
* HMAC-SHA256
* HMAC-SHA512
2018-11-14 07:29:28 +00:00
Calls to hkexnet.Dial() and hkexnet.Listen()/Accept() are generally the same as calls to the equivalents within the _net_ package; however upon connection a key exchange automatically occurs whereby client and server independently derive the same keying material, and all following traffic is secured by a symmetric encryption algorithm.
2018-12-09 05:35:13 +00:00
Above the hkexnet.Conn layer, the server and client apps in this repository (hkexshd/ and hkexsh/ respectively) negotiate session settings (cipher/hmac algorithms, interactive/non-interactive, tunnels, if any, etc.) to be used for communication.
2018-11-14 07:29:28 +00:00
Packets are subject to random padding (size, prefix/postfix), and (optionally) the client and server
channels can both send _chaff_ packets at random defineable intervals to help thwart analysis of session activity (applicable to interactive and non-interactive command sessions, file copies and tunnels).
2018-06-27 22:40:48 +00:00
2018-12-09 05:35:13 +00:00
Tunnels, if specified, are set up during initial client->server connection. Packets from the client local port(s) are sent through the main secured connection to the server's remote port(s), and vice versa, tagged with a tunnel specifier so that they can be de-multiplexed and delivered to the proper tunnel endpoints.
2018-11-14 07:29:28 +00:00
Finally, within the hkexpasswd/ directory is a password-setting utility. HKExSh uses its own passwd file distinct from the system /etc/passwd to authenticate clients, using standard bcrypt+salt storage.
2018-10-11 05:08:57 +00:00
HERRADURA KEX
2018-10-11 05:08:57 +00:00
As of this time (Oct 2018) no verdict by acknowledged 'crypto experts' as to
the level of security of the HerraduraKEx algorithm for purposes of session
key exchange over an insecure channel has been rendered.
It is hoped that experts in the field will analyze the algorithm and
determine if it is indeed a suitable one for use in situations where
Diffie-Hellman or other key exchange algorithms are currently utilized.
2018-10-11 05:08:57 +00:00
KYBER IND-CCA-2 KEM
2018-11-14 07:29:28 +00:00
As of this time (Oct 2018) Kyber is one of the candidate algorithms submitted to the [NIST post-quantum cryptography project](https://csrc.nist.gov/Projects/Post-Quantum-Cryptography). The authors recommend using it in "... so-called hybrid mode in combination with established "pre-quantum" security; for example in combination with elliptic-curve Diffie-Hellman." THIS PROJECT DOES NOT DO THIS (in case you didn't notice yet, THIS PROJECT IS EXPERIMENTAL.)
Dependencies:
--
2018-10-11 05:08:57 +00:00
* Recent version of go (tested, at various times, with go-1.9 to go-1.11.1)
* [github.com/mattn/go-isatty](http://github.com/mattn/go-isatty) //terminal tty detection
* [github.com/kr/pty](http://github.com/kr/pty) //unix pty control (server pty connections)
* [github.com/jameskeane/bcrypt](http://github.com/jameskeane/bcrypt) //password storage/auth
2019-01-12 21:21:45 +00:00
* [blitter.com/go/goutmp](https://gogs.blitter.com/RLabs/goutmp) // wtmp/lastlog C bindings
2018-10-11 05:08:57 +00:00
* [https://git.schwanenlied.me/yawning/kyber](https://git.schwanenlied.me/yawning/kyber) // golang Kyber KEM
2019-04-09 05:24:01 +00:00
* [https://git.schwanenlied.me/yawning/newhope](https://git.schwanenlied.me/yawning/newhope) // golang NEWHOPE,NEWHOPE-SIMPLE KEX
2019-01-12 21:20:49 +00:00
* [blitter.com/go/mtwist](https://gogs.blitter.com/RLabs/mtwist) // 64-bit Mersenne Twister PRNG
* [blitter.com/go/cryptmt](https://gogs.blitter.com/RLabs/cryptmt) // CryptMTv1 stream cipher
Get source code
--
2018-06-27 22:40:48 +00:00
* $ go get -u blitter.com/go/hkexsh
* $ cd $GOPATH/src/blitter.com/go/hkexsh
* $ go build ./... # install all dependent go pkgs
2018-11-14 07:57:36 +00:00
To build
--
2018-06-27 22:40:48 +00:00
* $ cd $GOPATH/src/blitter.com/go/hkexsh
* $ make clean all
2018-12-09 05:35:13 +00:00
To install, uninstall, re-install
--
* $ sudo make [install | uninstall | reinstall]
2018-11-14 07:57:36 +00:00
2018-12-09 05:35:13 +00:00
To manage service (assuming openrc init)
2018-11-14 07:57:36 +00:00
--
2018-12-09 05:35:13 +00:00
* $ sudo rc-config [start | restart | stop] hkexshd
2018-11-14 07:57:36 +00:00
An example init script (hkexshd.initrc) is provided. Consult your Linux distribution documentation for proper service/daemon installation. Default assumes installation in /usr/local/sbin (hkexshd, hkexpasswd) and /usr/local/bin (hkexsh/hkexcp symlink).
To set accounts & passwords:
--
2018-10-04 05:44:27 +00:00
* $ sudo touch /etc/hkexsh.passwd
* $ sudo hkexpasswd/hkexpasswd -u joebloggs
2018-06-07 05:43:46 +00:00
* $ <enter a password, enter again to confirm>
2018-11-14 07:57:36 +00:00
2018-12-09 05:35:13 +00:00
Testing Client and Server from $GOPATH dev tree (w/o 'make install')
--
In separate shells A and B:
* [A]$ cd hkexshd && sudo ./hkexshd & # add -d for debugging
Interactive shell
* [B]$ cd hkexsh && ./hkexsh joebloggs@host-or-ip # add -d for debugging
One-shot command
* [B]$ cd hkexsh && ./hkexsh -x "ls /tmp" joebloggs@host-or-ip
2018-06-27 22:40:48 +00:00
2018-10-04 05:44:27 +00:00
WARNING WARNING WARNING: the -d debug flag will echo passwords to the log/console!
Logging on Linux usually goes to /var/log/syslog and/or /var/log/debug, /var/log/daemon.log.
2018-10-04 05:44:27 +00:00
2018-07-14 20:54:44 +00:00
NOTE if running client (hkexsh) with -d, one will likely need to run 'reset' afterwards
2018-10-04 05:44:27 +00:00
to fix up the shell tty afterwards, as stty echo may not be restored if client crashes
2018-07-14 20:54:44 +00:00
or is interrupted.
2018-06-27 22:40:48 +00:00
2018-10-04 05:44:27 +00:00
Setting up an 'authtoken' for scripted (password-free) logins
--
2018-10-04 05:44:27 +00:00
Use the -g option of hkexsh to request a token from the remote server, which will return a
hostname:token string. Place this string into $HOME/.hkexsh_id to allow logins without
2018-11-14 07:57:36 +00:00
entering a password (obviously, $HOME/.hkexsh_id on both server and client for the user
2018-10-04 05:44:27 +00:00
should *not* be world-readable.)
File Copying using hkexcp
--
hkexcp is a symlink to hkexsh, and the binary checks its own filename to determine whether
it is being invoked in 'shell' or 'copy' mode. Refer to the '-h' output for differences in
accepted options.
General remote syntax is: user@server:[/]src-or-dest-path
2018-10-04 05:44:27 +00:00
If no leading / is specified in src-or-dest-path, it is assumed to be relative to $HOME of the
remote user. File operations are all performed as the remote user, so account permissions apply
as expected.
Local (client) to remote (server) copy:
2018-11-14 07:57:36 +00:00
* hkexcp fileA /some/where/fileB /some/where/else/dirC joebloggs@host-or-ip:remoteDir
Remote (server) to local (client) copy:
2018-11-14 07:57:36 +00:00
* hkexcp joebloggs@host-or-ip:/remoteDirOrFile /some/where/local/Dir
2018-11-14 08:11:12 +00:00
NOTE: Renaming while copying (eg., 'cp /foo/bar/fileA ./fileB') is NOT supported. Put another way, the destination (whether local or remote) must ALWAYS be a directory.
2018-11-14 08:11:12 +00:00
hkexcp uses tar (a 'tarpipe') with gzip compression, sending tar data over the hkex encrypted channel. Use the -d flag on client or server to see the generated tar commands if you're curious.
Tunnels
--
2018-11-14 08:11:12 +00:00
Simple tunnels (client -> server, no reverse tunnels for now) are supported.
2018-11-13 20:57:52 +00:00
Syntax: hkexsh -T=<tunspec>{,<tunspec>...}
2018-11-14 08:11:12 +00:00
.. where <tunspec> is <localport:remoteport>
2018-12-09 05:35:13 +00:00
Example, tunnelling ssh through hkexsh (NOTE [issue #15](https://blitter.com:3000/RLabs/hkexsh/issues/15))
* [server side] $ sudo /usr/sbin/sshd -p 7002
2018-11-14 07:57:36 +00:00
* [client side, term A] $ hkexsh -T=6002:7002 user@server
* [client side, term B] $ ssh user@localhost -p 6002