Bypassare Microsoft ISA Proxy Server


ISA (Internet Security & Acceleration Server) e' la soluzione firewall e web cache di mamma Microsoft.
In pochi passi vedremo come sia possibile uscire (ed entrare) via ssh attraverso il suddetto proxy.
Lo scenario e' una lan aziendale nella quale l'unico traffico permesso in uscita e' quello http/https.
Tutto quello di cui avremo bisogno e' una macchina, all' esterno della lan protetta da ISA, e alcuni tool liberamente downloadabili dalla rete.

Step 1:

Poiche' l'autenticazione degli utenti in ISA avviene per mezzo del "celebre" protocollo proprietario NTLM, nessun browser che non sia IE6 su Windows puo' accedere al web attraverso il proxy (complimenti a Microsoft anche per questo... ;))

Fortunatamente, un'anima pia che risponde al nome di Dmitry Rozmanov ha creato questo:

http://ntlmaps.sourceforge.net/

"NTLM Authorization Proxy Server (APS) is a proxy software that allows you to authenticate via an MS Proxy Server using the proprietary NTLM protocol. Since version 0.9.5 APS has an ability to behave as a standalone proxy server and authenticate http clients at web servers using NTLM method. It can change arbitrary values in your client's request header so that those requests will look like they were created by MS IE. It is written in Python v1.5.2 language."

Scompattiamo il targz, entriamo nella directory appena creata e modifichiamo alcuni campi del file di conf "server.cfg":

PARENT_PROXY: ipaddress del proxy isa server

PARENT_PROXY_PORT: porta del proxy isa server

NT_DOMAIN: dominio *NT* al quale apparteniamo

USER: nostro username per l'autenticazione sul proxy

PASSWORD: password per l'autenticazione sul proxy

 

Lanciamo aps con il comando:

[root@pocketcoffee][~/aps098]# python main.py
NTLM authorization Proxy Server v0.9.8 at "pocketcoffee:5865".
2001-2002 (C) by Dmitry Rozmanov

Per testare il corretto funzionamento di aps, modifichiamo alcuni parametri nel wgetrc:

http_proxy = http://127.0.0.1:5865/
use_proxy = on

E cerchiamo di "uscire su internet"...

[caff@pocketcoffee][~]$ wget http://www.google.it/
--16:19:22-- http://www.google.it/
=> `index.html'
Connecting to 127.0.0.1:5865... connected.
Proxy request sent, awaiting response... 200 OK
Length: 4,262 [text/html]

100%[==============================================================>] 4,262 84.94K/s ETA 00:00

16:19:22 (84.94 KB/s) - `index.html' saved [4262/4262]


Ok, aps fa il suo dovere egregiamente.


Step 2:


Verifichiamo se il CONNECT HTTP e' permesso dall'ISA:

[root@pocketcoffee][~]# telnet 127.0.0.1 5865
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
CONNECT caff.homeip.net:22 HTTP/1.0

HTTP/1.1 502 Proxy Error ( The specified Secure Sockets Layer (SSL) port is not allowed. ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. )
Via: 1.1 XXXXXXXX
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 3821

Ok, il metodo CONNECT e' limitato alla sola porta 443 (serve ad isa per proxare https).

[root@pocketcoffee][~]# telnet 127.0.0.1 5865
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
CONNECT caff.homeip.net:443 HTTP/1.0

HTTP/1.1 502 Proxy Error ( Connection refused )
Via: 1.1 XXXXXXXX
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 3533

A questo punto, siamo a cavallo!

Scarichiamo il secondo e ultimo tool del nostro "arsenale del perfetto proxy piercier" :)

http://www.agroman.net/corkscrew/

"Corkscrew is a tool for tunneling SSH through HTTP proxies."

Dopo averlo compilato e installato, aggiungiamo la seguente riga nello ssh_config:

ProxyCommand /usr/local/bin/corkscrew 127.0.0.1 5865 %h %p

Telefoniamo ad un amico fidato e facciamoci tirare su un sshd in ascolto sulla porta 443 nella nostra macchina a casa...

E voila'! Les jeux son fait:

[caff@pocketcoffee][~]$ ssh -v -p 443 caff@caff.homeip.net
OpenSSH_3.7p1, SSH protocols 1.5/2.0, OpenSSL 0.9.7b 10 Apr 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Executing proxy command: exec /usr/local/bin/corkscrew 127.0.0.1 5865 caff.homeip.net 443
debug1: identity file /home/caff/.ssh/identity type -1
debug1: identity file /home/caff/.ssh/id_rsa type 1
debug1: identity file /home/caff/.ssh/id_dsa type 2
debug1: Remote protocol version 2.0, remote software version OpenSSH_3.7.1
debug1: match: OpenSSH_3.7.1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.7p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'caff.homeip.net' is known and matches the RSA host key.
debug1: Found key in /home/caff/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /home/caff/.ssh/identity
debug1: Offering public key: /home/caff/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Offering public key: /home/caff/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
caff@caff.homeip.net's password:

Ora possiamo fare ssh fino a casa e da li' andarcene in giro dove ci pare.
Ma possiamo fare di piu'. Possiamo far entrare nella lan aziendale protetta chiunque abbia accesso alla nostra macchina a casa.

Basta creare quello che si chiama "reverse ssh tunnel":

[caff@pocketcoffee][~]$ ssh -p 443 -R 12345:ipaddress_macchina_lan_interna:22 caff@caff.homeip.net

Ora, chi si collega a 127.0.0.1:12345 su caff.homeip.net, sara' rediretto sulla porta 22 della macchina nella lan aziendale.


Nota:
Vi consiglio di applicare ad openssh la patch presente all'url:

http://www.sc.isc.tohoku.ac.jp/~hgot/sources/openssh-watchdog.html


e aggiungere l'opzione "Heartbeat N" (dove N e' il numero di secondi) allo ssh_config:
le connessioni SSH over HTTP tendono a cadere se lasciate idle per troppo tempo.


Cheers a tutti!