mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-22 03:10:42 +08:00
Harden scan robustness and tests
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -54,6 +55,9 @@ func (h *httpDialer) DialContext(ctx context.Context, network, address string) (
|
||||
|
||||
// sendConnectRequest 发送HTTP CONNECT请求
|
||||
func (h *httpDialer) sendConnectRequest(conn net.Conn, address string) error {
|
||||
if strings.ContainsAny(address, "\r\n") {
|
||||
return NewProxyError(ErrTypeProtocol, "invalid CONNECT target", ErrCodeHTTPReadRespFailed, nil)
|
||||
}
|
||||
// 构建CONNECT请求
|
||||
req := fmt.Sprintf(HTTPConnectRequestFormat, address, address)
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHTTPDialerRejectsConnectTargetWithLineBreak(t *testing.T) {
|
||||
client, server := net.Pipe()
|
||||
defer client.Close()
|
||||
defer server.Close()
|
||||
|
||||
dialer := &httpDialer{
|
||||
config: &ProxyConfig{Timeout: time.Second},
|
||||
stats: &ProxyStats{},
|
||||
}
|
||||
|
||||
err := dialer.sendConnectRequest(client, "example.com:80\r\nX-Injected: yes")
|
||||
if err == nil {
|
||||
t.Fatal("sendConnectRequest() error = nil, want invalid target error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user