2018-05-25 11:34:40 +00:00
# SSLproxy - transparent SSL/TLS proxy for decrypting and diverting network traffic to other programs for deep SSL inspection [![Build Status](https://travis-ci.org/sonertari/SSLproxy.svg?branch=master)](https://travis-ci.org/sonertari/SSLproxy)
2017-08-22 23:15:31 +00:00
2021-02-10 21:22:40 +00:00
Copyright (C) 2017-2021, [Soner Tari ](mailto:sonertari@gmail.com ).
2017-08-22 23:15:31 +00:00
https://github.com/sonertari/SSLproxy
2020-04-14 15:12:16 +00:00
Copyright (C) 2009-2019, [Daniel Roethlisberger ](//daniel.roe.ch/ ).
2018-02-27 19:20:58 +00:00
https://www.roe.ch/SSLsplit
2012-04-13 12:47:30 +00:00
## Overview
2020-12-20 12:40:28 +00:00
SSLproxy is a proxy for SSL/TLS encrypted network connections. It is intended
2017-08-23 11:48:39 +00:00
to be used for decrypting and diverting network traffic to other programs, such
2020-12-20 12:40:28 +00:00
as UTM services, for deep SSL inspection.
[The UTMFW project ](https://github.com/sonertari/UTMFW ) uses SSLproxy to
decyrpt and feed network traffic into its UTM services: Web Filter, POP3
Proxy, SMTP Proxy, and Inline IPS; and also indirectly into Virus Scanner and
Spam Filter through those UTM software. Given that most of the Internet
traffic is encrypted now, it wouldn't be possible without SSLproxy to deeply
inspect most of the network traffic passing through UTMFW.
See [this presentation ](https://drive.google.com/open?id=12YaGIGs0-xfpqMNAY3rzUbIyed-Tso8W )
for a summary of SSL interception and potential issues with middleboxes that
support it.
### Mode of operation
2017-08-22 23:15:31 +00:00
2018-11-03 15:23:31 +00:00
SSLproxy is designed to transparently terminate connections that are redirected
2020-12-20 12:40:28 +00:00
to it using a network address translation engine. SSLproxy then terminates
2018-11-03 15:23:31 +00:00
SSL/TLS and initiates a new SSL/TLS connection to the original destination
address. Packets received on the client side are decrypted and sent to the
program listening on a port given in the proxy specification. SSLproxy inserts
in the first packet the address and port it is expecting to receive the packets
back from the program. Upon receiving the packets back, SSLproxy re-encrypts
and sends them to their original destination. The return traffic follows the
2018-05-12 21:49:21 +00:00
same path back to the client in reverse order.
2017-08-22 23:15:31 +00:00
2020-12-21 21:56:34 +00:00
![Mode of Operation Diagram ](https://drive.google.com/uc?id=1N_Yy5nMPDSvY8YaNFd4sHvipyLWq5zDy )
2018-03-19 14:44:07 +00:00
2017-08-23 00:27:53 +00:00
This is similar in principle to [divert
sockets](https://man.openbsd.org/divert.4), where the packet filter diverts the
packets to a program listening on a divert socket, and after processing the
packets the program reinjects them into the kernel. If there is no program
2017-08-23 01:48:37 +00:00
listening on that divert socket or the program does not reinject the packets
into the kernel, the connection is effectively blocked. In the case of
SSLproxy, SSLproxy acts as both the packet filter and the kernel, and the
communication occurs over networking sockets.
2017-08-23 00:27:53 +00:00
2021-08-28 18:54:15 +00:00
SSLproxy supports split mode of operation similar to SSLsplit as well. In
split mode, packets are not diverted to listening programs, effectively making
SSLproxy behave similar to SSLsplit, but not exactly like it, because SSLproxy
has certain features non-existent in SSLsplit, such as user authentication and
protocol validation. Also, note that the implementation of proxy core in
SSLproxy is different from the one in SSLsplit, for example the proxy core in
SSLproxy runs lockless, whereas SSLsplit implementation uses thread manager
level locks (which does not necessarily make sslproxy run faster than
sslsplit). In SSLproxy, split mode can be defined globally or per-proxyspec.
2021-05-08 08:17:27 +00:00
SSLproxy does not automagically redirect any network traffic. To actually
implement a proxy, you also need to redirect the traffic to the system running
sslproxy. Your options include running sslproxy on a legitimate router, ARP
spoofing, ND spoofing, DNS poisoning, deploying a rogue access point (e.g.
using hostap mode), physical recabling, malicious VLAN reconfiguration or
route injection, /etc/hosts modification and so on.
2020-12-20 12:40:28 +00:00
#### Proxy specification
2017-08-22 23:15:31 +00:00
For example, given the following proxy specification:
https 127.0.0.1 8443 up:8080
2020-12-21 21:56:34 +00:00
- SSLproxy listens for HTTPS connections on 127.0.0.1:8443.
- Upon receiving a connection from the Client, it decrypts and diverts the
2020-12-23 08:01:31 +00:00
packets to a Program listening on 127.0.0.1:8080. The default divert address
2020-12-21 21:56:34 +00:00
is 127.0.0.1, which can be configured by the `ua` option.
- After processing the packets, the Program gives them back to SSLproxy
listening on a dynamically assigned address, which the Program obtains from
the SSLproxy line in the first packet in the connection.
- Then SSLproxy re-encrypts and sends the packets to the Server.
The response from the Server follows the same path back to the Client in
reverse order.
2017-08-22 23:15:31 +00:00
2021-08-28 18:54:15 +00:00
See the SSLsplit documentation for split style proxyspecs.
2020-12-20 12:40:28 +00:00
#### SSLproxy line
2017-08-22 23:15:31 +00:00
2017-09-02 19:45:01 +00:00
A sample line SSLproxy inserts into the first packet in the connection is the
following:
SSLproxy: [127.0.0.1]:34649,[192.168.3.24]:47286,[192.168.111.130]:443,s
2020-12-21 21:56:34 +00:00
- The first IP:port pair is a dynamically assigned address that SSLproxy
expects the program send the packets back to it.
- The second and third IP:port pairs are the actual source and destination
addresses of the connection respectively. Since the program receives the
packets from SSLproxy, it cannot determine the source and destination
addresses of the packets by itself, e.g by asking the NAT engine, hence must
rely on the information in the SSLproxy line.
- The last letter is either s or p, for SSL/TLS encrypted or plain traffic
respectively. This information is also important for the program, because it
cannot reliably determine if the actual network traffic it is processing was
encrypted or not before being diverted to it.
2017-09-02 19:45:01 +00:00
2020-12-20 12:40:28 +00:00
#### Listening program
The program that packets are diverted to should support this mode of operation.
Specifically, it should be able to recognize the SSLproxy address in the first
packet, and give the first and subsequent packets back to SSLproxy listening
on that address, instead of sending them to the original destination as it
normally would.
You can use any software as a listening program as long as it supports this
mode of operation. So existing or new software developed in any programming
language can be modified to be used with SSLproxy to inspect and/or modify any
or all parts of the packets diverted to it.
You can offload the system SSLproxy is running on by diverting packets to
remote listening programs too. For example, given the following proxy
specification:
2019-01-06 22:05:48 +00:00
https 127.0.0.1 8443 up:8080 ua:192.168.0.1 ra:192.168.1.1
2020-12-21 21:56:34 +00:00
- The `ua` option instructs SSLproxy to divert packets to 192.168.0.1:8080,
instead of 127.0.0.1:8080 as in the previous proxyspec example.
- The `ra` option instructs SSLproxy to listen for returned packets from the
program on 192.168.1.1, instead of 127.0.0.1 as in the previous SSLproxy line.
Accordingly, the SSLproxy line now becomes:
2019-01-06 22:05:48 +00:00
SSLproxy: [192.168.1.1]:34649,[192.168.3.24]:47286,[192.168.111.130]:443,s
So, the listening program can be running on a machine anywhere in the world.
2020-12-20 12:40:28 +00:00
Since the packets between SSLproxy and the listening program are always
unencrypted, you should be careful while using such a setup.
### Protocols
#### Supported protocols
2019-01-06 22:05:48 +00:00
2017-08-22 23:15:31 +00:00
SSLproxy supports plain TCP, plain SSL, HTTP, HTTPS, POP3, POP3S, SMTP, and
2020-12-20 12:40:28 +00:00
SMTPS connections over both IPv4 and IPv6. It also has the ability to
2018-02-27 19:20:58 +00:00
dynamically upgrade plain TCP to SSL in order to generically support SMTP
2020-12-20 12:40:28 +00:00
STARTTLS and similar upgrade mechanisms. Depending on the version of OpenSSL,
SSLproxy supports SSL 3.0, TLS 1.0, TLS 1.1, TLS 1.2, and TLS 1.3, and
optionally SSL 2.0 as well. SSLproxy supports Server Name Indication (SNI),
but not Encrypted SNI in TLS 1.3. It is able to work with RSA, DSA and ECDSA
keys and DHE and ECDHE cipher suites.
2017-08-22 23:15:31 +00:00
2020-12-24 14:19:51 +00:00
The following features of SSLproxy are IPv4 only:
- Divert addresses for listening programs in proxyspecs
- SSLproxy return addresses dynamically assigned to connections
- IP addresses in the ua and ra options
- IP and ethernet addresses of clients in user authentication
- Target IP and ethernet addresses in mirror logging
2020-12-20 12:40:28 +00:00
#### OCSP, HPKP, HSTS, Upgrade et al.
2015-05-01 09:54:20 +00:00
2018-11-03 15:23:31 +00:00
SSLproxy implements a number of defences against mechanisms which would
2020-12-20 12:40:28 +00:00
normally prevent MitM attacks or make them more difficult. SSLproxy can deny
OCSP requests in a generic way. For HTTP and HTTPS connections, SSLproxy
2018-11-03 15:23:31 +00:00
mangles headers to prevent server-instructed public key pinning (HPKP), avoid
2018-09-14 23:51:26 +00:00
strict transport security restrictions (HSTS), avoid Certificate Transparency
enforcement (Expect-CT) and prevent switching to QUIC/SPDY, HTTP/2 or
2020-12-20 12:40:28 +00:00
WebSockets (Upgrade, Alternate Protocols). HTTP compression, encodings and
2018-09-14 23:51:26 +00:00
keep-alive are disabled to make the logs more readable.
2012-04-13 12:47:30 +00:00
2017-08-22 23:15:31 +00:00
Another reason to disable persistent connections is to reduce file descriptor
usage. Accordingly, connections are closed if they remain idle for a certain
2020-12-20 12:40:28 +00:00
period of time. The default timeout is 120 seconds, which can be configured by
the ConnIdleTimeout option.
#### Protocol validation
Protocol validation makes sure the traffic handled by a proxyspec is using the
protocol specified in that proxyspec. The ValidateProto option can be used to
enable global and/or per-proxyspec protocol validation. This feature currently
supports HTTP, POP3, and SMTP protocols. If a connection cannot pass protocol
validation, then it is terminated.
SSLproxy uses only client requests for protocol validation. However, it also
validates SMTP responses until it starts processing the packets from the
client. If there is no excessive fragmentation, the first couple of packets in
the connection should be enough for validating protocols.
### Certificates
#### Certificate forging
For SSL and HTTPS connections, SSLproxy generates and signs forged X509v3
certificates on-the-fly, mimicking the original server certificate's subject
DN, subjectAltName extension and other characteristics. SSLproxy has the
ability to use existing certificates of which the private key is available,
instead of generating forged ones. SSLproxy supports NULL-prefix CN
certificates but otherwise does not implement exploits against specific
certificate verification vulnerabilities in SSL/TLS stacks.
#### Certificate verification
2017-08-22 23:15:31 +00:00
2018-11-03 15:23:31 +00:00
SSLproxy verifies upstream certificates by default. If the verification fails,
the connection is terminated immediately. This is in contrast to SSLsplit,
because in order to maximize the chances that a connection can be successfully
split, SSLsplit accepts all certificates by default, including self-signed
2018-11-06 18:44:25 +00:00
ones. See [The Risks of SSL Inspection ](https://insights.sei.cmu.edu/cert/2015/03/the-risks-of-ssl-inspection.html )
2020-12-21 21:56:34 +00:00
for the reasons of this difference. You can disable this feature by the
VerifyPeer option.
2017-08-22 23:15:31 +00:00
2020-12-20 12:40:28 +00:00
#### Client certificates
SSLproxy uses the certificate and key from the pemfiles configured by the
ClientCert and ClientKey options when the destination requests client
certificates. These options can be defined globally and/or per-proxyspec.
Alternatively, you can use the PassSite option to pass through certain
destinations requesting client certificates.
### User authentication
If the UserAuth option is enabled, SSLproxy requires network users to log in
to the system to establish connections to the external network.
SSLproxy determines the user owner of a connection using a `users` table in an
SQLite3 database configured by the UserDBPath option. The users table should
be created using the following SQL statement:
2019-03-06 19:43:43 +00:00
CREATE TABLE USERS(
IP CHAR(45) PRIMARY KEY NOT NULL,
USER CHAR(31) NOT NULL,
ETHER CHAR(17) NOT NULL,
ATIME INT NOT NULL,
DESC CHAR(50)
);
2020-12-20 12:40:28 +00:00
SSLproxy does not create this users table or the database file by itself, nor
2020-12-21 21:56:34 +00:00
does it log users in or out. So the database file and the users table should
2020-12-20 12:40:28 +00:00
already exist at the location pointed to by the UserDBPath option. An external
program should log users in and out on the users table. The external program
should fill out all the fields in user records, except perhaps for the DESC
field, which can be left blank.
2021-06-22 08:49:41 +00:00
When SSLproxy accepts a connection,
- It searches the client IP address of the connection in the users table. If
the client IP address is not in the users table, the connection is redirected
to a login page configured by the UserAuthURL option.
- If SSLproxy finds a user record for the client IP address in the users
table, it obtains the ethernet address of the client IP address from the arp
cache of the system, and compares it with the value in the user record for
that IP address. If the ethernet addresses do not match, the connection is
redirected to the login page.
- If the ethernet addresses match, SSLproxy compares the atime value in the
user record with the current system time. If the difference is greater than
the value configured by the UserTimeout option, the connection is redirected
to the login page.
If the connection passes all these checks, SSLproxy proceeds with establishing
the connection.
2020-12-20 12:40:28 +00:00
The atime of the IP address in the users table is updated with the system time
while the connection is being terminated. Since this atime update is executed
using a privsep command, it is expensive. So, to reduce the frequency of such
updates, it is deferred until after the user idle time is more than half of
the timeout period.
If a description text is provided in the DESC field, it can be used with the
PassSite option to treat the user logged in from different locations, i.e.
from different client IP addresses, separately.
2020-12-17 21:04:23 +00:00
2019-03-28 14:06:07 +00:00
If the UserAuth option is enabled, the user owner of the connection is
appended at the end of the SSLproxy line, so that the listening program can
parse and use this information in its logic and/or logging:
SSLproxy: [127.0.0.1]:34649,[192.168.3.24]:47286,[192.168.111.130]:443,s,soner
2020-12-20 12:40:28 +00:00
The user authentication feature is currently available on OpenBSD and Linux only.
#### User control lists
DivertUsers and PassUsers options can be used to divert, pass through, or
block users.
- If neither DivertUsers nor PassUsers is defined, all users are diverted to
listening programs.
- Connections from users in DivertUsers, if defined, are diverted to listening
programs.
- Connections from users in PassUsers, if defined, are simply passed through
2020-12-21 21:56:34 +00:00
to their original destinations. SSLproxy engages the Passthrough mode for that
purpose.
2021-05-08 08:17:27 +00:00
- If both DivertUsers and PassUsers are defined, users not listed in either of
2020-12-21 21:56:34 +00:00
the lists are blocked. SSLproxy simply terminates their connections.
- If *no* DivertUsers list is defined, only users *not* listed in PassUsers
are diverted to listening programs.
2020-12-20 12:40:28 +00:00
These user control lists can be defined globally or per-proxyspec.
2020-12-21 21:56:34 +00:00
### Excluding sites from SSL inspection
2019-03-07 20:14:53 +00:00
2019-04-19 22:13:06 +00:00
PassSite option allows certain SSL sites to be excluded from SSL inspection.
2020-12-21 21:56:34 +00:00
If a PassSite matches the SNI or common names in the SSL certificate of a
connection, that connection is passed through the proxy without being diverted
to the listening program. SSLproxy engages the Passthrough mode for that
purpose. For example, sites requiring client authentication can be added as
2020-12-20 12:40:28 +00:00
PassSite.
Per-site filters can be defined using client IP addresses, users, and
description keywords. If the UserAuth option is disabled, only client IP
addresses can be used in PassSite filters. Multiple sites can be defined, one
Add support for passsite substring match
Now the site field in PassSite option can have an '*' suffix to search
for a match anywhere in sni or common names. Note that this is not a
regex or wildcard search.
Previously, we only supported exact matches in sni and between slashes
in common names. This change makes it possible to cover multiple sites
in one PassSite option. In fact, without this change, certain sites
could not be added as passsite, because it was impossible to know their
subdomain names beforehand, for example *.fbcdn.net, which may have many
subdomain names in place of asterisk.
So to use substring match, append an '*' to a site name in PassSite
option (the asterisk is removed before substring search). For example,
use ".fbcdn.net*" to match all subdomains of fbcdn.net, notice the
asterisk at the end.
We also add a warning log starting with "Closing on ssl error without
passsite match" to report sites that can be added as passsite, which is
expected to help in writing PassSite rules.
Also, we now set dstaddr_str earlier in conn handling, so we can print
it in debug logs. This also helps in IDLE and EXPIRED conn logs.
2021-09-04 20:28:23 +00:00
on each line. PassSite rules can search for exact or substring matches.
2020-12-20 12:40:28 +00:00
### Logging
2019-04-19 22:13:06 +00:00
2018-11-03 15:23:31 +00:00
Logging options include traditional SSLproxy connect and content log files as
well as PCAP files and mirroring decrypted traffic to a network interface.
Additionally, certificates, master secrets and local process information can be
logged.
2019-07-22 08:24:53 +00:00
See the manual pages sslproxy(1) and sslproxy.conf(5) for details on using
2020-12-20 12:40:28 +00:00
SSLproxy, setting up the various NAT engines, and for examples.
2012-04-13 12:47:30 +00:00
## Requirements
2019-07-22 08:24:53 +00:00
SSLproxy depends on the OpenSSL, libevent 2.x, libpcap, libnet 1.1.x, and
2020-12-20 12:40:28 +00:00
sqlite3 libraries by default. Libpcap and libnet are not needed if the
mirroring feature is omitted. Sqlite3 is not needed if the user authentication
feature is omitted. The build depends on GNU make and a POSIX.2 environment
in `PATH` . If available, pkg-config is used to locate and configure the
dependencies. The optional unit tests depend on the check library. The
optional end-to-end tests depend on the [TestProxy ](https://github.com/sonertari/TestProxy )
tool, and are supported only on Linux.
2012-04-13 12:47:30 +00:00
2017-08-22 23:15:31 +00:00
SSLproxy currently supports the following operating systems and NAT mechanisms:
2014-11-04 19:39:20 +00:00
2020-12-20 12:40:28 +00:00
- FreeBSD: pf rdr and divert-to, ipfw fwd, ipfilter rdr
- OpenBSD: pf rdr-to and divert-to
- Linux: netfilter REDIRECT and TPROXY
- Mac OS X: pf rdr and ipfw fwd
2012-04-13 12:47:30 +00:00
2014-11-28 11:09:40 +00:00
Support for local process information (`-i`) is currently available on Mac OS X
and FreeBSD.
SSL/TLS features and compatibility greatly depend on the version of OpenSSL
2020-12-20 12:40:28 +00:00
linked against. For optimal results, use a recent release of OpenSSL or
2018-11-03 15:23:31 +00:00
LibreSSL.
2014-11-28 11:09:40 +00:00
2012-04-13 12:47:30 +00:00
## Installation
2018-11-03 15:23:31 +00:00
With the requirements above available, run:
2015-05-02 10:52:37 +00:00
2012-05-13 16:22:23 +00:00
make
2020-12-21 21:56:34 +00:00
make test # optional unit and e2e tests
2018-08-03 20:36:51 +00:00
make sudotest # optional unit tests requiring privileges
2012-05-13 16:22:23 +00:00
make install # optional install
2012-04-13 12:47:30 +00:00
2020-12-20 12:40:28 +00:00
Dependencies are autoconfigured using pkg-config. If dependencies are not
2012-05-13 16:22:23 +00:00
picked up and fixing `PKG_CONFIG_PATH` does not help, you can specify their
2018-11-03 15:23:31 +00:00
respective locations manually by setting `OPENSSL_BASE` , `LIBEVENT_BASE` ,
2020-12-20 15:04:43 +00:00
`LIBPCAP_BASE` , `LIBNET_BASE` , `SQLITE_BASE` and/or `CHECK_BASE` to the
respective prefixes.
2012-04-13 12:47:30 +00:00
2012-05-13 16:22:23 +00:00
You can override the default install prefix (`/usr/local`) by setting `PREFIX` .
2018-11-03 15:23:31 +00:00
For more build options and build-time defaults see [`GNUmakefile` ](GNUmakefile )
and [`defaults.h` ](defaults.h ).
2012-04-13 12:47:30 +00:00
2014-11-28 11:09:40 +00:00
## Documentation
2012-04-13 12:47:30 +00:00
2018-11-03 15:23:31 +00:00
See the manual pages `sslproxy(1)` and `sslproxy.conf(5)` for user
2020-12-20 12:40:28 +00:00
documentation. See [`NEWS.md` ](NEWS.md ) for release notes listing significant
2018-11-03 15:23:31 +00:00
changes between releases and [`SECURITY.md` ](SECURITY.md ) for information on
security vulnerability disclosure.
2012-04-13 12:47:30 +00:00
## License
2020-12-20 12:40:28 +00:00
SSLproxy is provided under a 2-clause BSD license.
SSLproxy contains components licensed under the MIT and APSL licenses.
2018-11-03 15:23:31 +00:00
See [`LICENSE` ](LICENSE ), [`LICENSE.contrib` ](LICENSE.contrib ) and
[`LICENSE.third` ](LICENSE.third ) as well as the respective source file headers
for details.
2019-07-22 08:24:53 +00:00
2018-01-18 00:18:53 +00:00
## Credits
2018-11-03 15:23:31 +00:00
See [`AUTHORS.md` ](AUTHORS.md ) for the list of contributors.
2018-02-27 19:20:58 +00:00
2020-12-20 12:40:28 +00:00
SSLproxy was inspired by and has been developed based on [SSLsplit ](https://www.roe.ch/SSLsplit )
by Daniel Roethlisberger.