fix: response body leaks in cms.go and sql.go

close response bodies immediately after reading instead of deferring
inside loops, which delays closure until function exit
This commit is contained in:
vmfunc
2026-01-02 23:37:45 -08:00
parent bad1af5fc6
commit 314783dba3
2 changed files with 6 additions and 3 deletions
+3 -2
View File
@@ -112,8 +112,9 @@ func detectWordPress(url string, client *http.Client, bodyString string) bool {
for _, file := range wpFiles {
resp, err := client.Get(url + file)
if err == nil {
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusFound {
found := resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusFound
resp.Body.Close()
if found {
return true
}
}
+3 -1
View File
@@ -171,12 +171,12 @@ func SQL(targetURL string, timeout time.Duration, threads int, logdir string) (*
log.Debugf("Error checking %s: %v", checkURL, err)
continue
}
defer resp.Body.Close()
// check for successful response (not 404)
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusUnauthorized {
// read body to check for common admin panel indicators
body, err := io.ReadAll(io.LimitReader(resp.Body, 1024*100)) // limit to 100KB
resp.Body.Close()
if err != nil {
continue
}
@@ -202,6 +202,8 @@ func SQL(targetURL string, timeout time.Duration, threads int, logdir string) (*
logger.Write(sanitizedURL, logdir, fmt.Sprintf("Found %s at [%s] (status: %d)\n", adminPath.panelType, checkURL, resp.StatusCode))
}
}
} else {
resp.Body.Close()
}
}
}()