From a0a42f910b95f38948ad2302fcb48c1319d817af Mon Sep 17 00:00:00 2001 From: 4ra1n <2023503307@qq.com> Date: Wed, 11 Sep 2024 00:41:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=85=B6=E4=BB=96]=20=E6=B5=8B=E8=AF=95=20`fo?= =?UTF-8?q?llow=20redirect`=20=E6=98=AF=E5=90=A6=E6=9C=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.MD | 1 + rawhttp/client_test.go | 14 ------ rawhttp/redirect_test.go | 94 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 rawhttp/redirect_test.go diff --git a/CHANGELOG.MD b/CHANGELOG.MD index ed08256..0b354da 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -6,6 +6,7 @@ - [优化] 使用 `interactsh` 反连随机选择可用的服务器 - [优化] 开启 `debug` 时仅详细打印来自 `poc` 的请求 - [优化] 开启 `debug` 时请求响应限制打印长度 +- [其他] 测试 `follow redirect` 是否有效 感谢以下用户的贡献: diff --git a/rawhttp/client_test.go b/rawhttp/client_test.go index 85bdf30..26ccfab 100644 --- a/rawhttp/client_test.go +++ b/rawhttp/client_test.go @@ -82,17 +82,3 @@ func TestRawHttpsProxy(t *testing.T) { fmt.Println("HTTP Response:\n", string(response.RawResponse)) } } - -func TestRawHttpTE(t *testing.T) { - client, _ := NewHTTPClient(5*time.Second, DefaultNoProxy) - req, err := NewRequest("http://127.0.0.1:8081", MethodGet) - if err != nil { - panic(err) - } - response, err := client.DoReq(req) - if err != nil { - panic(err) - } else { - fmt.Println("HTTP Response:\n", string(response.RawResponse)) - } -} diff --git a/rawhttp/redirect_test.go b/rawhttp/redirect_test.go new file mode 100644 index 0000000..510e9f6 --- /dev/null +++ b/rawhttp/redirect_test.go @@ -0,0 +1,94 @@ +/* + * poc-runner project + * Copyright (C) 2024 4ra1n + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package rawhttp + +import ( + "fmt" + "net/http" + "testing" + "time" +) + +func TestHTTPClientRedirectTrue(t *testing.T) { + go func() { + http.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/test", http.StatusFound) + }) + http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "https://example.com", http.StatusFound) + }) + err := http.ListenAndServe(":10302", nil) + if err != nil { + panic(err) + } + }() + + time.Sleep(time.Second) + + client, _ := NewHTTPClient(5*time.Second, DefaultNoProxy) + req, err := NewRequest("http://127.0.0.1:10302/redirect", MethodGet) + if err != nil { + panic(err) + } + req.SetFollowRedirect(true) + response, err := client.DoReq(req) + if err != nil { + panic(err) + } else { + fmt.Println("HTTP Response:\n", string(response.RawResponse)) + } + + if response.StatusCode != 200 { + panic("test error") + } +} + +func TestHTTPClientRedirectFalse(t *testing.T) { + go func() { + http.HandleFunc("/redirect", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/test", http.StatusFound) + }) + http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "https://example.com", http.StatusFound) + }) + err := http.ListenAndServe(":10302", nil) + if err != nil { + panic(err) + } + }() + + time.Sleep(time.Second) + + client, _ := NewHTTPClient(5*time.Second, DefaultNoProxy) + req, err := NewRequest("http://127.0.0.1:10302/redirect", MethodGet) + if err != nil { + panic(err) + } + req.SetFollowRedirect(false) + response, err := client.DoReq(req) + if err != nil { + panic(err) + } else { + fmt.Println("HTTP Response:\n", string(response.RawResponse)) + } + + if response.StatusCode != 302 { + panic("test error") + } +}