Skip to content

Commit 2b83f36

Browse files
committed
Fixed handling of TCP 'no such host' errors
1 parent 8261a1c commit 2b83f36

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

cmd/requests.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ func MakeRequest(client http.Client, method, target string, timeout int64, reqDa
142142
} else if err != nil && err != context.Canceled && err != io.EOF {
143143
if strings.Contains(fmt.Sprint(err), "tls") && !strings.Contains(fmt.Sprint(err), "user canceled") {
144144
log.Fatal("Try supplying the --insecure flag.")
145+
} else if strings.Contains(fmt.Sprint(err), "tcp") && strings.Contains(fmt.Sprint(err), "no such host") {
146+
log.Fatalf("The target '%s' is not reachable. Check the declared host(s) and supply a target manually using -T if needed.", u.Scheme+"://"+u.Host)
145147
} else if strings.Contains(fmt.Sprint(err), "user canceled") {
146148
return nil, "skipped", 1
147149
} else {
@@ -164,11 +166,13 @@ func MakeRequest(client http.Client, method, target string, timeout int64, reqDa
164166
return bodyBytes, bodyString, requestStatus
165167
}
166168

167-
func CheckContentType(client http.Client, url string) string {
169+
func CheckContentType(client http.Client, target string) string {
170+
u, _ := url.Parse(target)
171+
168172
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
169173
defer cancel()
170174

171-
req, err := http.NewRequest("GET", url, nil)
175+
req, err := http.NewRequest("GET", target, nil)
172176
if err != nil && err != context.Canceled && err != io.EOF {
173177
log.Fatal("Error: could not create HTTP request - ", err)
174178
}
@@ -178,9 +182,12 @@ func CheckContentType(client http.Client, url string) string {
178182
log.Printf("Error: %s - skipping request.", err)
179183
return ""
180184
} else if err != nil && err != context.Canceled && err != io.EOF {
181-
log.Error("Error: response not received.\n", err)
182185
if strings.Contains(fmt.Sprint(err), "tls") && !strings.Contains(fmt.Sprint(err), "user canceled") {
183186
log.Fatal("Try supplying the --insecure flag.")
187+
} else if strings.Contains(fmt.Sprint(err), "tcp") && strings.Contains(fmt.Sprint(err), "no such host") {
188+
log.Fatalf("The target '%s' is not reachable. Check the declared host(s) and supply a target manually using -T if needed.", u.Scheme+"://"+u.Host)
189+
} else {
190+
log.Error("Error: response not received.\n", err)
184191
}
185192
return ""
186193
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $ sj brute -u https://petstore.swagger.io`,
4646
log.Error("Command not specified. See the --help flag for usage.")
4747
}
4848
},
49-
Version: "1.5.1",
49+
Version: "1.5.2",
5050
}
5151

5252
func Execute() {

0 commit comments

Comments
 (0)