0x01 问题 - SSH via Squid - 403 Forbidden

如何排查 403 Forbidden 问题

在此例,我欲ssh from my laptop to 13.228.168.169:22 (a EC2 server) via HTTP Proxy 35.174.208.142:3128 (Squid listening on port 3128)
在这里插入图片描述
在这里插入图片描述

0x02 - 排查

  1. tail -f /var/log/squid/access.log line #10, #11
    CONNECT 13.228.168.169:22 (TCP_DENIED).
[root@ip-172-31-55-111 ec2-user]# tail -f   /var/log/squid/access.log
1599364932.853 171860 112.199.148.226 TCP_TUNNEL/200 22517 CONNECT www.google-analytics.com:443 - HIER_DIRECT/172.217.2.110 -
1599364933.864 207353 112.199.148.226 TCP_TUNNEL/200 398104 CONNECT www.google.com:443 - HIER_DIRECT/172.253.63.106 -
1599364933.864 171453 112.199.148.226 TCP_TUNNEL/200 3643 CONNECT stats.g.doubleclick.net:443 - HIER_DIRECT/172.217.197.155 -
1599364935.881 171964 112.199.148.226 TCP_TUNNEL/200 4101 CONNECT px.ads.linkedin.com:443 - HIER_DIRECT/108.174.10.14 -
1599364960.904 116222 112.199.148.226 TCP_TUNNEL/200 4748 CONNECT firefox.settings.services.mozilla.com:443 - HIER_DIRECT/52.85.144.53 -
1599364995.637  61537 112.199.148.226 TCP_TUNNEL/200 3792 CONNECT incoming.telemetry.mozilla.org:443 - HIER_DIRECT/34.210.106.102 -
1599364995.638  61538 112.199.148.226 TCP_TUNNEL/200 3792 CONNECT incoming.telemetry.mozilla.org:443 - HIER_DIRECT/34.210.106.102 -
1599365365.628     19 112.199.148.226 TCP_MISS/200 893 POST http://ocsp.pki.goog/gts1o1core - HIER_DIRECT/172.217.13.227 application/ocsp-response
1599365444.156      0 112.199.148.226 TCP_DENIED/403 3904 CONNECT 13.228.168.169:22 - HIER_NONE/- text/html
1599365547.623      0 112.199.148.226 TCP_DENIED/403 3904 CONNECT 13.228.168.169:22 - HIER_NONE/- text/html
  1. sudo vi /etc/squid/squid.conf
    发现 Port 22 并不在 SSL_Ports 默认值之内 (line #1 只有443) 
    last line http_access deny CONNECT !SSL_ports, 非443, 都被denied
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
# Recommended minimum Access Permission configuration:
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

0x03 更改配置

  1. 加入 acl SSL_Ports port 22
acl SSL_ports port 443
acl SSL_Ports port 22  		# 加入此行
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
  1. restart squid
    systemctl restart squid

0x04 从新用 Putty SSH

在这里插入图片描述
ssh 成功 !!!

Squid access.log 如下

[root@ip-172-31-55-111 ec2-user]# systemctl restart squid
[root@ip-172-31-55-111 ec2-user]# tail -f   /var/log/squid/access.log
1599369354.379    101 112.199.148.226 TCP_MISS/200 551 GET http://detectportal.firefox.com/success.txt? - HIER_DIRECT/23.40.62.19 text/plain
1599369354.379    100 112.199.148.226 TCP_MISS/200 551 GET http://detectportal.firefox.com/success.txt? - HIER_DIRECT/23.40.62.19 text/plain
1599369354.615      2 112.199.148.226 TCP_MISS/200 551 GET http://detectportal.firefox.com/success.txt? - HIER_DIRECT/23.40.62.19 text/plain
1599369354.615      2 112.199.148.226 TCP_MISS/200 551 GET http://detectportal.firefox.com/success.txt? - HIER_DIRECT/23.40.62.19 text/plain
1599369359.708  86630 112.199.148.226 TCP_TUNNEL/200 3865 CONNECT push.services.mozilla.com:443 - HIER_DIRECT/34.218.33.223 -
1599369478.298 203775 112.199.148.226 TCP_TUNNEL/200 5476 CONNECT firefox.settings.services.mozilla.com:443 - HIER_DIRECT/52.85.144.53 -
1599370050.123      0 112.199.148.226 TCP_DENIED/403 3904 CONNECT 13.228.168.169:22 - HIER_NONE/- text/html
1599370176.808  94936 112.199.148.226 TCP_TUNNEL/200 3680 CONNECT 13.228.168.169:22 - HIER_DIRECT/13.228.168.169 -
1599370193.031 116848 112.199.148.226 TCP_TUNNEL/200 4748 CONNECT firefox.settings.services.mozilla.com:443 - HIER_DIRECT/52.85.144.53 -
1599370356.215     50 112.199.148.226 TCP_MISS/200 893 POST http://ocsp.pki.goog/gts1o1core - HIER_DIRECT/172.217.8.3 application/ocsp-response

0x04 - 用 Mobaxterm & cockscrew

  1. Install cockscrew
  06/09/2020   13:51.14   /home/mobaxterm  apt-get install corkscrew
DISCLAIMER:
This will download and install third-party software packages, distributed by
the Cygwin Project, from online Cygwin repositories.
These software packages are distributed under their own terms available here:
http://mirrors.kernel.org/sourceware/cygwin/x86/release
Third-party software packages are neither developed nor distributed by Mobatek.
In no event shall Mobatek be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services, loss of data or profits, computer
virus infection, or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of these third-party software
packages, even if advised of the possibility of such damage.
By typing "y", you agree to use these third-party programs at your own risks.
Type "y" to continue or any other key to exit: y
The following packages will be installed:
- corkscrew v2.0-1 (16 kB): Tunnel TCP connections through HTTP proxies
- cygwin v3.0.4-1 (1949 kB): The UNIX emulation engine
➤ Type "y" to download and install these packages (1.92 MB): y
- Downloading package rebase-4.4.4-1.tar.xz                                 [OK]
- Installing package rebase-4.4.4-1.tar.xz                                  [OK]
- Downloading package cygwin-3.0.4-1.tar.xz                                 [OK]
- Installing package cygwin-3.0.4-1.tar.xz                                  [OK]
- Downloading package corkscrew-2.0-1.tar.bz2                               [OK]
- Installing package corkscrew-2.0-1.tar.bz2                                [OK]
- Executing postinstall scripts                                             [OK]
  06/09/2020   13:52.11   /home/mobaxterm  corkscrew
corkscrew 2.0 (agroman@agroman.net)
usage: corkscrew <proxyhost> <proxyport> <desthost> <destport> [authfile]
  06/09/2020   13:52.16   /home/mobaxterm  vi ~/.ssh/config
  1. 创建 ~/.ssh/config 如下 。
    在这里插入图片描述
  2. ssh 成功 !!

cockscrew

@Squid欢迎使用Markdown编辑器你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。新的改变我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:全新的界面设计 ,将会带来全新的写作体验;在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示
0: 代理服务器简介 代理服务器是建立在TCP/IP协议应用层上的一种服务软件,是以HTTP协议为基础的。工作过程简单来说分为4步:客户端向服务器发送的请求到达代理服务器;代理服务器把请求转发给客户端真正需要联系的服务器;服务器向代理服务器返回响应;代理服务器把响应返回给客户端。 启动代理服务器,此时代理服务器主进程会一直监听某个绑定的端口,同时会初始化代理服务器缓存。 客户端A向代理服
出现“Squid did not receive any data for this request”,查看日志(/var/log/squid/access.log)发现报“TCP_DENIED/403"错误 2、解决办法 修改配置文件/etc/squid/squid.conf,注释原本的2条配置,并新增1条配置,如下 #http_access deny !Safe_ports #http_access deny CONNECT !SSL_ports http_access allow
今天拿公司一台服务器做代理服务器,遇到几个坑,目前虽然开起来了,但是还有些问题,简单纪录一下: 1、有个需要使用代理的20433一直无法访问,访问这个url一直报TCP 403 配置那里acl Safe_ports port 443 # https 把端口改成20443就可以了;2、配置用户名密码; 这个密码的生成文件用的是原来Linux下生成的,直接在Windows使用报无法找到ddl文件; Squid/lib/squid/basic_ncsa_auth.exe: error while l
在 server 段中,注释掉上面一行,或者去掉,添加下面的一行, proxy_set_header Host $host:80; #proxy_set_header Host $host; proxy_set_header Host $host:80;
几年以前,我是对TCP in TCP毫无信心的,因为理论上一旦发生重传叠加,这个连接就会崩溃,但在实践中,这几乎不可能发生,我转而成了TCP in TCP的信徒。 TCP隧道形成了长距离传输加速的一个技术基底。来看个究竟: 事事有代价,按照以上玩法,高丢包率路径段的TCP隧道相当于一个大buffer,处理丢包重传需要时间,TCP隧道端点也存在固有buffer用来排队突发数据,这部分时间会叠加在Host的端到端RTT上,因此,代价就是RTT会变长。 分段感知MTU明显提高了带宽利用率。 少即是多,小即是
要安装,请运行脚本 wget https://raw.githubusercontent.com/serverok/squid-proxy-installer/master/squid3-install.sh sudo bash squid3-install.sh 建立使用者 要创建用户,请运行 squid-add-user 或运行以下命令 sudo /usr/bin/htpasswd -b -c /etc/squid/passwd USERNAME_HERE PASSWORD_HERE 要更新现有用户的密码,请运行 sudo /usr/bin/htpasswd /etc/squid/ 简单用法: squid-exporter -squid-hostname "localhost" -squid-port 3128 为从localhost:9301/metrics抓取localhost:9301/metrics - job_name: squid # squid-exporter is installed, grab stats about the local # squid instance. target_groups: - targets: ['localhost:9301'] 要获取所有参数,命令行参数始终会覆盖默认值
Squid Windows安装程序 Squid是Web的缓存代理,支持HTTPHTTPS,FTP等。 通过缓存和重用经常请求的网页,它减少了带宽并缩短了响应时间。 Squid具有广泛的访问控制,是一个出色的服务器加速器。 它可以在大多数可用的操作系统(包括Windows)上运行,并且已获得GNU GPL的许可。 该项目提供了用于Squid代理服务器的MSI Windows Installer。 只需单击几下,即可启用Squid安装。 当前版本基于适用于Cygwin Windows 64位的最新Squid 3.5版本。 运行它,然后单击“下一步”按钮,直到安装了该产品 请看一下描述 的教程。 在Windows上使用Squid和ICAP进行HTTPHTTPS过滤 如果您需要Windows上高质量的HTTP流量过滤解决方案,我们建议在Docker中运行Diladele Web
单位一直在用Squid结合AD做Proxy业务. 最近有需求使用企业微信,桌面版本的可以设定Proxy,但奇怪的登录不上. 检查access.log发现全是tcp deny 407,要求验证. 设定里明明有填写账号密码为什么还会要求验证呢? 检查确认acl不会有问题之后,无奈请出wireshark. 抓包显示明明有送账号密码过去,squid就是装瞎看不到. 再一看,回应的 ...