Difference between revisions of "sslh"

From wiki
m (Vincent moved page Sslh to sslh)
(Don't override system files)
Line 73: Line 73:
  
 
=== sslh ===
 
=== sslh ===
Edit file <code>/lib/systemd/system/sslh.service</code> and change <code>/usr/sbin/sslh</code> to <code>/usr/sbin/sslh-select</code>. Here is the file after modification<syntaxhighlight lang="ini">
+
Create file <code>/etc/systemd/system/sslh.service.d/override.conf</code><syntaxhighlight lang="ini">
[Unit]
 
Description=SSL/SSH multiplexer
 
After=network.target
 
 
 
 
[Service]
 
[Service]
EnvironmentFile=/etc/default/sslh
+
ExecStart=
 
ExecStart=/usr/sbin/sslh-select --foreground $DAEMON_OPTS
 
ExecStart=/usr/sbin/sslh-select --foreground $DAEMON_OPTS
KillMode=process
+
</syntaxhighlight>Next edit file <code>/etc/default/sslh</code><syntaxhighlight lang="shell">
 
 
[Install]
 
WantedBy=multi-user.target
 
</syntaxhighlight>Next edit file /etc/default/sslh<syntaxhighlight lang="shell">
 
 
# Default options for sslh initscript
 
# Default options for sslh initscript
 
# sourced by /etc/init.d/sslh
 
# sourced by /etc/init.d/sslh

Revision as of 17:15, 28 March 2016

Warning Warning: These instructions were only tested on Debian. It will probably work for other Linux distributions, but you might need to adapt the provided instructions.
Warning Warning: This page is a work in progress and is not completed. Important informations might be missing or wrong.

sslh is a program that allows you to run several programs on port 443. Mainly it allows your SSH server and web server to share the same port.


Warning Warning: Using SSH can be a violation of your corporate internet use policy. Please act responsibly. In particular, never ever create a reverse tunnel from your company network. Also this tool is not disguising SHH traffic as web but simply changing the port and can be easily detected by your network administrator.

Install

# apt install sslh

When it ask you how sslh should be run, choose standalone.

Configure

sslh has several modes of operation. In this tutorial, we will use transparent mode without forks.

OpenSSH

We will start by configuring OpenSSH to listen on a second port. We do that by modifying /etc/ssh/ssd_config

# What ports, IPs and protocols we listen for
Port 2200
# Use these options to restrict which interfaces/protocols sshd will bind to
ListenAddress 203.0.113.23:2200 # direct access
ListenAddress 203.0.113.23:2201 # access through sslh

You can now restart your SSH server.

Nginx

Now we will need to free port 443 so that it can be used by sslh. Edit file /etc/nginx/snippets/listen-https.conf and change the port for IPV4

listen [2001:db8:3:47d0::2e:7]:443 ssl spdy;
listen 203.0.113.23:4433 ssl spdy;

Do not restart Nginx yet.

Routing

Create file /usr/local/sbin/sslh_network.sh

#!/bin/sh

iptables -w -t mangle -N SSLH
iptables -w -t mangle -A  OUTPUT --protocol tcp --out-interface eth0 --sport 2201 --jump SSLH
iptables -w -t mangle -A OUTPUT --protocol tcp --out-interface eth0 --sport 4433 --jump SSLH
iptables -w -t mangle -A SSLH --jump MARK --set-mark 0x1
iptables -w -t mangle -A SSLH --jump ACCEPT
ip rule add fwmark 0x1 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100

Make it executable

# chmod +x /etc/sslh_network.sh

then create file /etc/systemd/system/sslh_network.service

[Unit]
Description=Set sslh network rules
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/sslh_network.sh

[Install]
WantedBy=multi-user.target

enable it using

# systemctl enable sslh_network.service
Created symlink from /etc/systemd/system/multi-user.target.wants/sslh_network.service to /etc/systemd/system/sslh_network.service.

and finally start it

# systemctl start sslh_network.service

sslh

Create file /etc/systemd/system/sslh.service.d/override.conf

[Service]
ExecStart=
ExecStart=/usr/sbin/sslh-select --foreground $DAEMON_OPTS

Next edit file /etc/default/sslh

# Default options for sslh initscript
# sourced by /etc/init.d/sslh

# Disabled by default, to force yourself
# to read the configuration:
# - /usr/share/doc/sslh/README.Debian (quick start)
# - /usr/share/doc/sslh/README, at "Configuration" section
# - sslh(8) via "man sslh" for more configuration details.
# Once configuration ready, you *must* set RUN to yes here
# and try to start sslh (standalone mode only)

RUN=yes

# binary to use: forked (sslh) or single-thread (sslh-select) version
# systemd users: don't forget to modify /lib/systemd/system/sslh.service
DAEMON=/usr/sbin/sslh-select

DAEMON_OPTS="--user sslh -n --transparent --listen 203.0.113.23:443 --tls 203.0.113.23:4433 --ssh 203.0.113.23:2201 --pidfile /var/run/sslh/sslh.pid"

Change done from the default are

  • RUN=yes Activate the daemon
  • DAEMON=/usr/sbin/sslh-select Use the no-fork version
  • -n Don't resolve domain name of connecting ip in logs. This allow to not loose time doing a DNS lookup for each new client
  • --transparent SSH and webserver will see connection as if it where coming directly from the outside. In particular, you will get the correct connecting IP address in the logs.
  • --listen 203.0.113.23:443 IP and port sslh listen to
  • --tls 203.0.113.23:4433 IP and port of Nginx
  • --ssh 203.0.113.23:2201 IP and port of OpenSSH

Start

You can now restart Nginx and start sslh

# systemctl reload nginx && systemctl start sslh