Manual
Manual
c
==============================
How to Use
----------
Get Source
~~~~~~~~~~
----
$ cp connect /usr/local/bin
----
----
Host remote.outside.net
ProxyCommand connect -S socks.local.net %h %p
----
`%h` and `%p` will be replaced on invoking proxy command with target
hostname and port specified to SSH command.
----
## Outside of the firewall, use connect command with SOCKS conenction.
Host *
ProxyCommand connect -S socks.local.net %h %p
If you want to use http proxy, use `-H` option instead of `-S` option
in examle above, like this:
----
## Outside of the firewall, with HTTP proxy
Host *
ProxyCommand connect -H proxy.local.net:8080 %h %p
After editing your `~/.ssh/config` file, you are ready to use ssh. You
can execute ssh without any special options as if remote host is IP
reachable host. Following is an example to execute hostname command on
host `remote.outside.net`.
----
local$ ssh remote.outside.net hostname
Hello, this is remote.outside.net
remote$
----
Have trouble?
~~~~~~~~~~~~~
If you have trouble, execute connect command from command line with `-d`
option to see what is happened. Some debug message may appear and
reports progress. This information may tell you what is wrong. In this
example, error has occurred on authentication stage of SOCKS5
protocol.
----
$ connect -d -S socks.local.net unknown.remote.outside.net 110
DEBUG: relay_method = SOCKS (2)
DEBUG: relay_host=socks.local.net
DEBUG: relay_port=1080
DEBUG: relay_user=gotoh
DEBUG: socks_version=5
DEBUG: socks_resolve=REMOTE (2)
DEBUG: local_type=stdio
DEBUG: dest_host=unknown.remote.outside.net
DEBUG: dest_port=110
DEBUG: Program is $Revision: 1.20 $
DEBUG: connecting to xxx.xxx.xxx.xxx:1080
DEBUG: begin_socks_relay()
DEBUG: atomic_out() [4 bytes]
DEBUG: >>> 05 02 00 02
DEBUG: atomic_in() [2 bytes]
DEBUG: <<< 05 02
DEBUG: auth method: USERPASS
DEBUG: atomic_out() [some bytes]
DEBUG: >>> xx xx xx xx ...
DEBUG: atomic_in() [2 bytes]
DEBUG: <<< 01 01
ERROR: Authentication faield.
FATAL: failed to begin relaying via SOCKS.
----
More Detail
-----------
`-H` [user@]server[:port]::
Specify hostname and port number of http proxy server to
relay. If port is omitted, 80 is used.
`-h`::
Use HTTP proxy via proxy server sepcified by environment variable
`HTTP_PROXY`.
`-S` \[_user_@]_server_\[:_port_]::
Specify hostname and port number of SOCKS server to
relay. Like `-H` option, port number can be omit and default is 1080.
`-s`::
Use SOCKS proxy via SOCKS server sepcified by environment variable
`SOCKS5_SERVER`.
`-p` _port_:: Accept on local TCP port and relay it instead of standard input
and output. With this option, program will terminate when remote or
local TCP session is closed.
`-d`: Run with debug message output. If you fail to connect, use this
option to see what is done.
As additional feature,
you can omit port argument when program name is special format
containing port number itself like "connect-25". For example:
----
$ ln -s connect connect-25
$ ./connect-25 smtphost.outside.net
220 smtphost.outside.net ESMTP Sendmail
QUIT
221 2.0.0 smtphost.remote.net closing connection
$
----
This example means that the command name "connect-25" indicates port
number 25 so you can omit 2nd argument (and used if specified
explicitly).
This is usefull for the application which invokes only with hostname
argument.
`SOCKS5_USER`::
Used for SOCKS v5 access.
`SOCKS4_USER`::
Used for SOCKS v4 access.
`SOCKS_USER`::
Used for SOCKS v5 or v4 access and varaibles above are not defined.
`HTTP_PROXY_USER`::
Used for HTTP proxy access.
`CONNECT_USER`::
Used for all type of access if all above are not defined.
Following table describes how user name is determined. Left most number is order to
check. If variable is not defined, check next variable, and so on.
[width="50%"]
|====
| | SOCKS v5 | SOCKS v4 | HTTP proxy
| 1 | `SOCKS5_USER` | `SOCKS4_USER` .2+^| `HTTP_PROXY_USER`
| 2 2+^| `SOCKS_USER`
| 3 3+^| `CONNECT_USER`
| 4 3+^| (query user name to system)
|====
`SOCKS5_PASSWD`::
Used for SOCKS v5 access. This variables is compatible with NEC SOCKS
implementation.
`SOCKS5_PASSWORD`::
Used for SOCKS v5 access if `SOCKS5_PASSWD` is not defined.
`SOCKS_PASSWORD`::
Used for SOCKS v5 (or v4) access all above is not defined.
`HTTP_PROXY_PASSWORD`::
Used for HTTP proxy access.
`CONNECT_PASSWORD`::
Used for all type of access if all above are not defined.
[width="50%"]
|====
| | SOCKS v5 | HTTP proxy
| 1 | `SOCKS5_PASSWD` .2+^| `HTTP_PROXY_PASSWORD`
| 2 | `SOCKS_PASSWORD`
| 3 2+^| `CONNECT_PASSWORD`
| 4 2+^| (ask to user interactively)
|====
Limitations
-----------
SOCKS5 authentication
~~~~~~~~~~~~~~~~~~~~~
HTTP authentication
~~~~~~~~~~~~~~~~~~~
----
#!/bin/sh
## ~/bin/myconnect --- Proxy server switching wrapper
if ifconfig eth0 |grep "inet addr:192\.168\.1" >/dev/null; then
opts="-S 192.168.1.1:1080"
elif ifconfig eth0 |grep "inet addr:10\." >/dev/null; then
opts="-H 10.1.1.1:80"
else
opts="-s"
fi
exec /usr/local/bin/connect $opts $@
----
Tips
----
This feature may be useful for the program which is hard to SOCKSify.
Remote resolver
~~~~~~~~~~~~~~~
If you are SOCKS4 user on UNIX environment, you might want specify
nameserver to resolve remote hostname. You can do it specifying `-R`
option followed by IP address of resolver.
----
$ ssh host1 connect host2 port
----
* You want to use some service which is allowed only from some limited hosts.
----
$ ssh host1 connect news 119
200 news.my-office.com InterNetNews NNRP server INN 2.3.2 ready (posting ok).
quit
205 .
$
----
----
|
External (internet) | Internal (office)
|
+------+ +----------+ +-------+ +-----------+
| HOME | | firewall | | host1 | | NNTP host |
+------+ +----------+ +-------+ +-----------+
emacs <-------------- ssh ---------------> sshd <-- connect --> nntpd
<-- connect --> socksd <-- SOCKS -->
----
As an advanced example, you can use SSH hopping as fetchmail's plug-in
program to access via secure tunnel. This method requires that connect
program is insatalled on remote host. There's example of .fetchmailrc
bellow. When fetchmail access to mail-server, you will login to remote
host using SSH then execute connect program on remote host to relay
conversation with pop server. Thus fetchmail can retrieve mails in
secure.
----
poll mail-server
protocol pop3
plugin "ssh %h connect localhost %p"
username "username"
password "password"
----
If firewall does not provide SOCKS nor HTTPS other than port 443, you
cannot break the wall in usual way. But if you have you own host which
is accessible from internet, you can make ssh connection to your own
host by configuring sshd as waiting at port 443 instead of standard
22. By this, you can login to your own host via port 443. Once you
have logged-in to extenal home machine, you can execute connect as
second hop to make connection from your own host to final target host,
like this:
----
internal$ cat ~/.ssh/config
Host home
ProxyCommand connect -H firewall:8080 %h 443
----
|
Internal (office) | External (internet)
|
+--------+ +----------+ +------+ +--------+
| office | | firewall | | home | | server |
+--------+ +----------+ +------+ +--------+
<------------------ ssh --------------------->sshd:443
<-- connect --> http-proxy <-- https:443 --> any
connect <-- tcp --> port
----
NOTE: If you wanna use this, you should give up hosting https
service at port 443 on you external host 'home'.
F.Y.I.
------
----
delegated -Pxxxx ...... REMITTABLE='+,https' ...
----
For the case of Squid, you should allow target ports via https by ACL,
and so on.
SOCKS5 Servers
~~~~~~~~~~~~~~
http://www.inet.no/dante/index.html[Dante]::
Dante is free implementation of SOKCS server and library. Many
enhancements and modulalized.
http://www.delegate.org/delegate/[DeleGate]::
DeleGate is multi function proxy service provider. DeleGate 5.x.x
or earlier can be SOCKS4 server, and 6.x.x can be SOCKS5 and
SOCKS4 server. and 7.7.0 or later can be SOCKS5 and SOCKS4a
server.
Specifications
~~~~~~~~~~~~~~
http://www.socks.nec.com/protocol/socks4.protocol[socks4.protocol.txt]::
SOCKS: A protocol for TCP proxy across firewalls
http://www.socks.nec.com/protocol/socks4a.protocol[socks4a.protocol.txt]::
SOCKS 4A: A Simple Extension to SOCKS 4 Protocol
http://www.socks.nec.com/rfc/rfc1928.txt[RFC 1928]::
SOCKS Protocol Version 5
http://www.socks.nec.com/rfc/rfc1929.txt[RFC 1929]::
Username/Password Authentication for SOCKS V5
http://www.ietf.org/rfc/rfc2616.txt[RFC 2616]::
Hypertext Transfer Protocol -- HTTP/1.1
http://www.ietf.org/rfc/rfc2617.txt[RFC 2617]::
HTTP Authentication: Basic and Digest Access Authentication
Related Links
~~~~~~~~~~~~~
* http://www.openssh.org/[OpenSSH Home]
* http://www.ssh.com/[Proprietary SSH]
* http://www.taiyo.co.jp/~gotoh/ssh/openssh-socks.html[Using OpenSSH through a
SOCKS compatible PROXY on your LAN] (J. Grant)
Similars
~~~~~~~~