Forgot password?
 Create new account
View 204|Reply 5

墙和netcat

[Copy link]

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2024-9-21 01:14:23 |Read mode
墙怎样知道一个 HTTP 请求是发到哪里的?为探索这个问题(我在Windows上)安装MingGW(可通过安装Git自带MingGW),再下载netcat放在/usr/bin/下。

然后在墙外建立echo server用来测试,也可以用 echo.free.beeceptor.com 它是一个免费的echo server

第一次测试:标头的Host为echo.free.beeceptor.com,发送请求至echo.free.beeceptor.com
  1. printf 'GET / HTTP/1.1\r\nHost: echo.free.beeceptor.com\r\nConnection: close\r\n\r\n' | ncat echo.free.beeceptor.com 80
Copy the Code

在墙内和墙外的结果相同,都是
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Fri, 20 Sep 2024 16:52:07 GMT
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked

f3
{
  "method": "GET",
  "protocol": "http",
  "host": "echo.free.beeceptor.com",
  "path": "/",
  "ip": "36.143.132.146:14234",
  "headers": {
    "Host": "echo.free.beeceptor.com",
    "Accept-Encoding": "gzip"
  },
  "parsedQueryParams": {}
}
0

第二次测试:标头的Host为example.com,发送请求至echo.free.beeceptor.com
  1. HTTP/1.1 308 Permanent Redirect
  2. Connection: close
  3. Location: https://example.com/
  4. Server: Caddy
  5. Date: Fri, 20 Sep 2024 16:52:37 GMT
  6. Content-Length: 0
Copy the Code

在墙内和墙外的结果相同,都是
HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://example.com/
Server: Caddy
Date: Fri, 20 Sep 2024 16:52:37 GMT
Content-Length: 0

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 01:20:23
可见,发送请求至echo server(如echo.free.beeceptor.com)分两种情况:
  • 如果标头的Host与目标主机 相匹配,它将响应 200 状态码,并发送一些内容回来。
  • 如果标头的Host与目标主机 不匹配,它将响应 308 状态码,并将客户端重定向到目标 host.

以上是墙外的所有情况。

如果在墙内,还有第三种情况:如果 host 被封锁,墙将强制关闭现有连接。

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 01:29:14
hbghlyj 发表于 2024-9-20 17:20
如果 host 被封锁,墙将强制关闭现有连接。

注意,不是发送请求到被封锁的主机:我们发送请求到不被封锁的主机,仅是标头的 host 被封锁,墙就会关闭连接。

下面探索一下这种情况:先测试一个色情网站,以 www.youporn.com 为例。

墙外:正常重定向墙内:强制关闭了现有连接。
Screenshot 2024-09-21 012812.png Screenshot 2024-09-21 012841.png

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 01:42:28
hbghlyj 发表于 2024-9-20 17:20
如果 host 被封锁,墙将强制关闭现有连接。
再测试维基百科的英文版 en.wikipedia.org、中文版 zh.wikipedia.org

墙外:正常重定向。墙内:两次都被强制关闭连接。
Screenshot 2024-09-21 014354.png Screenshot 2024-09-21 013853.png


再测试
维基百科主站 www.wikipedia.org:墙内和墙外均正常重定向。

Screenshot 2024-09-21 013753.png

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 02:27:43

继续探索netcat

运行ncat -l 2000 --keep-open --exec "/bin/echo 234"将在您的电脑上设置一个始终返回相同响应的简单服务器

如果想测试它,请运行ncat localhost 2000,您将收到响应234

Screenshot 2024-09-21 022346.png

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

 Author| hbghlyj Posted at 2024-9-21 02:47:59
hbghlyj 发表于 2024-9-20 17:29
我们发送请求到不被封锁的主机,仅是标头的 host 被封锁,墙就会关闭连接。
这是否意味着,墙不仅检查了包裹是发给谁的,而且还打开了包裹进行检查,否则它不会知道host的值

手机版Mobile version|Leisure Math Forum

2025-4-20 22:28 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list