This file is indexed.

/usr/bin/sslh is in libnet-proxy-perl 0.12-6.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/perl -w

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
    if 0; # not running under some shell
use strict;
use Getopt::Long;
use Net::Proxy;

use vars qw( %CONF $VERSION );

$VERSION = 0.04;

# default values
%CONF = (
    port    => 'localhost:443',
    timeout => 2,
    ssh     => 'localhost:22',
    ssl     => 'localhost:443',
    verbose => 0,
);

# get the options
Getopt::Long::Configure("bundling");
GetOptions( \%CONF, "help|h", "port|p=s", "timeout|t=i", "verbose|v+",
    "version|V", "ssh|s=s", "ssl|https|l=s", )
    or die << 'USAGE';
Usage: sslh [-v] [-p host:port] [-t timeout] [--ssh host:port] [--ssl host:port]
USAGE

# set up the verbosity level
Net::Proxy->set_verbosity( $CONF{verbose} );

# check the options
die "--timeout <seconds> must be a positive number (possibly fractional)\n"
  unless $CONF{timeout} > 0;
die "--ssh and -ssl must point to different servers\n"
  if $CONF{ssh} eq $CONF{ssl};

# create the proxy listening socket
die "--port <port> option required\n"
  unless exists $CONF{port};

# compute host / port
{
    my %hostport;
    for (qw( ssl ssh port )) {
        $CONF{$_} = "localhost:$CONF{$_}"
            if index( $CONF{$_}, ':' ) < 0;
        $CONF{$_} = [ split /:/, $CONF{$_} ];
        push @{
            $hostport{
                join ':', ( gethostbyname( $CONF{$_}[0] ) )[0],
                $CONF{$_}[1]
                }
            },
            $_;
    }

    # check for duplicates
    for( keys %hostport ) {
        if( @{$hostport{$_}} != 1 ) {
            die "Options "
                . join( " and ", map {"--$_"} @{ $hostport{$_} } )
                . " are identical! ($_)\n";
        }
    }
}

# create the proxy
my $proxy = Net::Proxy->new( {
    in => {
        type => 'dual',
        host => $CONF{port}[0],
        port => $CONF{port}[1],
        timeout => $CONF{timeout},
        server_first => {
            type => 'tcp',
            host => $CONF{ssh}[0],
            port => $CONF{ssh}[1],
        },
        client_first => {
            type => 'tcp',
            host => $CONF{ssl}[0],
            port => $CONF{ssl}[1],
        },
    },
    out => { type => 'dummy'},
});

$proxy->register();

Net::Proxy->mainloop();

__END__

=head1 NAME

sslh - Switch incoming connection between SSH and SSL/HTTPS servers

=head1 SYNOPSIS

B<sslh> S<[ B<-v> ]> S<[ B<-p> I<[host:]port> ]> S<[ B<-t> I<timeout> ]>
     S<[ B<--ssh> I<[host:]port> ]> S<[ B<--ssl> I<[host:]port> ]>

=head1 DESCRIPTION

B<sslh> is a simple script that lets you switch an incoming connection
on a single port between distinct SSH and SSL/HTTPS servers.

B<sslh> listens for connections on a port and is able to redirect
them either to an HTTPS web server or a SSH server.

This lets one setup both a HTTPS web server and a SSH server
and access them through the same host+port.

=head1 OPTIONS

The program follows the usual GNU command line syntax, with long
options starting with two dashes.

=over 4

=item B<-p>, B<--port> I<[host:]port>

The port the proxy will listen to.
If no port is given, 443 is used by default.
If no host is given, C<localhost> is used by default.

=item B<-s>, B<--ssh> I<[host:]port>

The SSH server which the SSH connections must be forwarded to.
If omitted, the default is I<localhost:22>.

=item B<-l>, B<--ssl>, B<--https> I<[host:]port>

The HTTPS server which the HTTPS connections must be forwarded to.
If omitted, the default is I<localhost:443>.

=item B<-t>, B<--timeout> I<delay>

Timeout in seconds before a silent incoming connection is considered
as a SSH connection. The number can be fractional.

The default is I<2>seconds.

=item B<-v>, B<--verbose>

Verbose output.
This option can be used several times for more verbose output.

=back

=head1 EXAMPLE OF USE
 
Is this tool actually useful? Yes.

For example one can use it to access both a SSH server and a secure
web server via a corporate proxy that only accepts to relay connections
to port 443. Creating a tunnel that passes SSH connection through a
CONNECT-enabled web proxy is easy with B<connect-tunnel> (also
included in the C<Net::Proxy> distribution).

The proxy will let both SSH and HTTPS connections out (since they
all point to port 443), and the home server will connect those incoming
connections to the appropriate server. This only requires to run the
HTTPS server on a non standard port (not 443).

=head1 TECHNICAL NOTE

How can this proxy find out what kind of protocol is using a TCP
connection to port 443, without being connected (yet) to the server?
We actually rely on a slight difference between the SSL and SSH
protocols (found thanks to B<ethereal>):

=over 4

=item SSH

Once the TCP connection is established, the server speaks first,
presenting itself by saying something like:

    SSH-2.0-OpenSSH_3.6.1p2 Debian 1:3.6.1p2-1

=item SSL

With SSL, it's always the client that speaks first.

=back

This means that B<sslh> can be used with any pair of protocols/services
that share this property (the client speaks first for one and the server
speaks first for the other).

=head1 AUTHORS

=over 4

=item Original idea and C version

Frédéric Plé C<< <sslh@wattoo.org> >>.

=item Perl versions

Philippe 'BooK' Bruhat C<< <book@cpan.org> >>.

=back

=head1 SCRIPT HISTORY

Version 0.01 of the script was a quick hack designed in 2003 as a proof
of concept.

Version 0.02 (and higher) are based on C<Net::Proxy>, and included with
the C<Net::Proxy> distribution. Version 0.02 didn't work, though.

Version 0.03 correctly initialised the C<in> connector.

Version 0.04 lets the proxy listen on any address (instead of C<localhost>,
which is still the default). Thanks to Dieter Voegtli for spotting this.

=head1 SEE ALSO

L<Net::Proxy>, L<Net::Proxy::Connector::dual>.

=head1 COPYRIGHT

Copyright 2003-2006, Philippe Bruhat. All rights reserved.

=head1 LICENSE

This module is free software; you can redistribute it or modify it under
the same terms as Perl itself.

=cut