diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb5e9a2..372835d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.arch }} - CGO_ENABLED: 1 + CGO_ENABLED: 0 - uses: svenstaro/upx-action@v2 with: args: ${{ matrix.args }} diff --git a/core/crackmodule/httpbasic.go b/core/crackmodule/httpbasic.go index 7ee54cf..0037d11 100644 --- a/core/crackmodule/httpbasic.go +++ b/core/crackmodule/httpbasic.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "cube/config" "cube/gologger" + "log" "net/http" "strings" ) @@ -51,13 +52,32 @@ func (h HttpBasic) Exec() CrackResult { req.Header.Add("Connection", "close") req.SetBasicAuth(h.Auth.User, h.Auth.Password) res, err := clt.Do(req) + if err != nil { - gologger.Error(err) + // 处理请求错误 + log.Printf("Error making request: %v", err) + // 应该在这里返回或处理错误 + return result } - defer res.Body.Close() - if res.StatusCode != 401 { - result.Result = true + if res != nil { + defer func() { + // 使用 defer 调用匿名函数来处理 Close 的错误 + if err := res.Body.Close(); err != nil { + // 处理关闭 resp.Body 时的错误 + log.Printf("Error closing response body: %v", err) + } + }() + if res.StatusCode != 401 { + result.Result = true + } + } else { + // 如果到这里,说明有严重的错误发生,resp2 应该不为 nil。 + log.Printf("Response is nil without a preceding error.") } + + //if res.StatusCode != 401 { + // result.Result = true + //} return result } diff --git a/core/crackmodule/jenkins.go b/core/crackmodule/jenkins.go index 6f59074..c987053 100644 --- a/core/crackmodule/jenkins.go +++ b/core/crackmodule/jenkins.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "cube/config" "cube/gologger" + "log" "net/http" "net/http/cookiejar" "net/url" @@ -57,7 +58,10 @@ func (j Jenkins) Exec() CrackResult { req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") resp, err := clt.Do(req) if err != nil { - panic(err) + // 处理请求错误 + log.Printf("Error making request: %v", err) + // 应该在这里返回或处理错误 + return result } data := make([]byte, 20250) @@ -100,8 +104,12 @@ func (j Jenkins) Exec() CrackResult { r2, err := clt2.Do(req2) if err != nil { - panic(err) + // 处理请求错误 + log.Printf("Error making request: %v", err) + // 应该在这里返回或处理错误 + return result } + defer r2.Body.Close() data2 := make([]byte, 10480) c2 := bufio.NewReader(r2.Body) diff --git a/core/crackmodule/phpmyadmin.go b/core/crackmodule/phpmyadmin.go index 3cba777..d5ef418 100644 --- a/core/crackmodule/phpmyadmin.go +++ b/core/crackmodule/phpmyadmin.go @@ -5,6 +5,7 @@ import ( "crypto/tls" "cube/config" "cube/gologger" + "log" "net/http" "net/http/cookiejar" "net/url" @@ -57,6 +58,7 @@ func (p Phpmyadmin) Exec() CrackResult { req.Header.Add("Accept-Charset", "utf-8") resp, err := clt.Do(req) if err != nil { + log.Printf("Error making request: %v", err) return result } @@ -97,12 +99,29 @@ func (p Phpmyadmin) Exec() CrackResult { req2.Header.Add("Connection", "close") req2.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp2, _ := crackClt.Do(req2) - //resp2, _ := crackClt.PostForm(task.Ip, urlValues) - //resp2, _ := crackClt.Post(task.Ip, urlValues) - defer resp2.Body.Close() - if resp2.StatusCode == 302 { - result.Result = true + resp2, err := crackClt.Do(req2) + if err != nil { + // 处理请求错误 + log.Printf("Error making request: %v", err) + // 应该在这里返回或处理错误 + return result + } + + if resp2 != nil { + defer func() { + // 使用 defer 调用匿名函数来处理 Close 的错误 + if err := resp2.Body.Close(); err != nil { + // 处理关闭 resp.Body 时的错误 + log.Printf("Error closing response body: %v", err) + } + }() + + if resp2.StatusCode == 302 { + result.Result = true + } + } else { + // 如果到这里,说明有严重的错误发生,resp2 应该不为 nil。 + log.Printf("Response is nil without a preceding error.") } return result diff --git a/core/crackmodule/zabbix.go b/core/crackmodule/zabbix.go index 7d88303..7685eb7 100644 --- a/core/crackmodule/zabbix.go +++ b/core/crackmodule/zabbix.go @@ -4,6 +4,7 @@ import ( "bufio" "cube/config" "cube/gologger" + "log" "net/http" "net/http/cookiejar" "net/url" @@ -92,6 +93,13 @@ func (z Zabbix) Exec() CrackResult { req2.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp2, _ := crackClt.Do(req2) + if err != nil { + // 处理请求错误 + log.Printf("Error making request: %v", err) + // 应该在这里返回或处理错误 + return result + } + defer resp2.Body.Close() if resp2.StatusCode == 302 { result.Result = true