从NTLM代理后面的客户端连接到SSH服务器


9

我正在尝试从公司网络访问Internet上的SSH服务器。必须通过服务器代理与外部Internet的所有连接,该服务器在每个请求中检查每个客户端的NTLM哈希。我正在为此使用Cntlm,而且仅工作了一半。对于基于HTTP的连接,它工作正常,但对于SSH样式的连接,则行不通。我知道这是因为,我可以连接到Sublime TextPackage Control插件来获取和更新插件。但是,我无法使用Cntlm的隧道配置将其用于SSH进入服务器。

查看Cntlm的日志,可以看到以下内容...

cntlm: PID 1460: 127.0.0.1 TUNNEL ts.io:443
Tunneling to ts.io:443 for client 6...
Starting authentication...
NTLM Request:
       Domain: domain.tld
     Hostname: D-HOSTNAME
        Flags: 0xA208B205

NTLM握手(类型1)

Sending PROXY auth request...
Proxy-Connection               => keep-alive
Proxy-Authorization            => NTLM [REDACTED]
Content-Length                 => 0

读取PROXY身份验证响应...

HEAD: HTTP/1.1 407 Proxy Authentication Required ( Access is denied.  )
Via                            => 1.1 FOLLICLE
Proxy-Authenticate             => NTLM [REDACTED]
Connection                     => Keep-Alive
Proxy-Connection               => Keep-Alive
Pragma                         => no-cache
Cache-Control                  => no-cache
Content-Type                   => text/html
Content-Length                 => 0
NTLM Challenge:
    Challenge: 4AC9211DC2875FFF (len: 178)
        Flags: 0xA2898205
    NT domain: NTDOMAIN
       Server: PROXY
       Domain: domain.tld
         FQDN: proxy.domain.tld
          TLD: domain.tld
        TBofs: 64
        TBlen: 114
        ttype: 0
NTLMv2:
        Nonce: CB4E6617ABF19C24
    Timestamp: -1581153408
NTLM Response:
     Hostname: 'D-HOSTNAME'
       Domain: 'domain.tld'
     Username: 'username'
     Response: '[REDACTED]' (162)
     Response: '[REDACTED]' (24)
Sending real request:
Proxy-Connection               => keep-alive
Proxy-Authorization            => NTLM [REDACTED]

最后我得到了...

Reading real response:
HEAD: HTTP/1.1 200 Connection established
Via                            => 1.1 PROXY
Connection                     => Keep-Alive
Proxy-Connection               => Keep-Alive
Ok CONNECT response. Tunneling...
tunnel: select cli: 6, srv: 7
Joining thread 537272664; rc: 0

因为防火墙仅允许通过代理服务器从端口80和端口443连接到外部Internet,所以我将SSH服务器重新配置为接受来自端口443的连接。

我看到的问题是,当我尝试进行SSH连接时,使用SFTP插件时,连接会从Sublime Text中报告为连接超时。使用PuTTY可立即产生效果PuTTY Fatal Error: Server unexpectedly closed network connection。Google Chrome扩展程序安全外壳为我提供了以下更详细的错误ssh_exchange_identification: Connection closed by remote host NaCl plugin exited with status code 255.


Cntlm配置

# The username of the client you wish to masquerade as.
#
Username    username

# The domain name of the network you are connected too.
# 
Domain      domain.tld

# The Password, LM, NTLM, or NTLMv2 Password.
# You should leave this blank and then start cntlm
# with the -M arg to get the hash information, then
# place that information here.
#
PassNTLMv2  [REDACTED]

# Specify the netbios hostname cntlm will send to the parent
# proxies. Normally the value is auto-guessed.
#
Workstation D-HOSTNAME

# List of parent proxies to use. More proxies can be defined
# one per line in format <proxy_ip>:<proxy_port>
#
Proxy       PROXY:8080

# Specify the port cntlm will listen on
# You can bind cntlm to specific interface by specifying
# the appropriate IP address also in format <local_ip>:<local_port>
# Cntlm listens on 127.0.0.1:3128 by default
#
Listen      3128

# Use -M first to detect the best NTLM settings for your proxy.
# Default is to use the only secure hash, NTLMv2, but it is not
# as available as the older stuff.
#
# This example is the most universal setup known to man, but it
# uses the weakest hash ever. I won't have it's usage on my
# conscience. :) Really, try -M first.
#
Auth        NTLMv2

# Tunnels mapping local port to a machine behind the proxy.
# The format is <local_port>:<remote_host>:<remote_port>
# 
Tunnel      1443:ts.io:443

这是我用于Cntlm中的隧道的配置部分。

腻子配置

IP:PORT     localhost:1443

这就是我用于PuTTY连接的内容。

崇高文字

"http_proxy": "http://localhost:3128",

有什么想法可以解决这个问题吗?我想通过SSH进入我的服务器,必须有一种方法仅使用Cntlm的隧道功能来做到这一点,我只是不知道自己在做什么错。

我可以告诉您,我可以从公司网络外部使用端口443连接到我的SSH服务器。

Answers:


1

尝试通过具有Putty的CNTLM连接到SSH服务器时,我得到407响应。Forefront TMG代理反对通过PuTTY进行DNS查找,而不是SSH流量本身。您需要在“ PuTTY配置” 的“ 代理”页面中关闭“在代理端进行DNS名称查找”。“ 否”设置有效,“ 自动”或“ 是”将产生407响应。


0

您可以使用-v选项调用cntlm,而不是读取日志,该选项将其保留在前台,并在生成日志的那一刻在终端上发出诊断输出。

身份验证和隧道设置都可以正常工作。因此,我也没有解释您的连接为什么不起作用的原因(除了“ localhost”可能未正确解析为127.0.0.1)。

我刚刚测试了SSH转发(对于一个简单的例子,实际上不需要用户身份验证)-这是发出命令后我可以比较的内容

$ cntlm -L 443:远程主机:22 -v

section: global, Username = ...
section: global, Domain = ...
section: global, PassNTLMv2 = ...
section: global, Proxy = '139.23.33.27:81'
section: global, NoProxy = 'localhost, 127.0.0.*, 10.*, 192.168.*'
Default config file opened successfully
Adding no-proxy for: 'localhost'
Adding no-proxy for: '127.0.0.*'
Adding no-proxy for: '10.*'
Adding no-proxy for: '192.168.*'
cntlm: Workstation name used: mchn256c
cntlm: Using following NTLM hashes: NTLMv2(1) NT(0) LM(0)
cntlm[27413]: Cntlm ready, staying in the foreground

(在其他终端上发出“ ssh -p 443 localhost”时):

   NO: remotehost (localhost)
   NO: remotehost (127.0.0.*)
   NO: remotehost (10.*)
   NO: remotehost (192.168.*)
cntlm[27413]: Using proxy 139.23.33.27:81
cntlm[27413]: Resolving proxy 139.23.33.27...
Resolve 139.23.33.27:
  -> 139.23.33.27
cntlm[27413]: 127.0.0.1 TUNNEL remotehost:22
Tunneling to remotehost:22 for client 6...
Starting authentication...
NTLM Request:
           Domain: ...
         Hostname: ...
            Flags: 0xA208B205

Sending PROXY auth request...
Proxy-Connection               => keep-alive
Proxy-Authorization            => NTLM ...
Content-Length                 => 0

Reading PROXY auth response...
HEAD: HTTP/1.1 200 Connection established
Via                            => 1.1 MCHP941X
Connection                     => Keep-Alive
Proxy-Connection               => Keep-Alive
Ok CONNECT response. Tunneling...
tunnel: select cli: 6, srv: 7

一旦我回到他们的代理人后面,我会给这个机会。应该是几天(星期一)。
马克·汤姆林

不幸的是,这没有效果。它给了我与以前相同的信息,但是在日志文件中……这样,我无法使用此标志连接到外部服务器。
马克汤姆林
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.