Skip to content

Commit

Permalink
增加http异常处理,设置CGO_ENABLE为0,兼容低版本Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
JKme committed Dec 4, 2023
1 parent e562741 commit 3779d4b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
28 changes: 24 additions & 4 deletions core/crackmodule/httpbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"cube/config"
"cube/gologger"
"log"
"net/http"
"strings"
)
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 10 additions & 2 deletions core/crackmodule/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"cube/config"
"cube/gologger"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 25 additions & 6 deletions core/crackmodule/phpmyadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"cube/config"
"cube/gologger"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions core/crackmodule/zabbix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"cube/config"
"cube/gologger"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3779d4b

Please sign in to comment.