Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit f16742a

Browse files
committed
[Debug] fix target connect func
1 parent 4be32b0 commit f16742a

File tree

7 files changed

+76
-38
lines changed

7 files changed

+76
-38
lines changed

api/routers/v1/plugin/plugin.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ func Run(c *gin.Context) {
234234

235235
oreq, err := util.GenOriginalReq(run.Target)
236236
if err != nil {
237-
c.JSON(msg.ErrResp("原始请求生成失败"))
238-
return
239-
}
240-
verify := util.VerifyTargetConnection(oreq)
241-
if !verify {
242-
c.JSON(msg.ErrResp("测试目标连通性测试不通过"))
237+
c.JSON(msg.ErrResp("目标连通性不通过/原始请求生成失败"))
243238
return
244239
}
245240
poc, err := rule.ParseJsonPoc(run.JsonPoc)

pkg/conf/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const ConfigFileName = "config.yaml"
7777
const ServiceName = "pocassist"
7878
const Website = "https://pocassist.jweny.top/"
7979

80-
const Version = "1.0.2"
80+
const Version = "1.0.4"
8181
const Banner = `
8282
_ _
8383
_ __ ___ ___ __ _ ___ ___(_)___| |_

pkg/util/request.go

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/valyala/fasthttp"
1212
"golang.org/x/time/rate"
1313
"io/ioutil"
14+
"net"
1415
"net/http"
1516
"net/url"
1617
"regexp"
@@ -217,6 +218,8 @@ func ParseFasthttpResponse(originalResp *fasthttp.Response, req *fasthttp.Reques
217218
return resp, nil
218219
}
219220

221+
222+
220223
func DoFasthttpRequest(req *fasthttp.Request, redirect bool) (*proto.Response, error) {
221224
LimitWait()
222225
defer fasthttp.ReleaseRequest(req)
@@ -346,25 +349,12 @@ func UnzipResponseBody(response *fasthttp.Response) ([]byte, error) {
346349
return body, err
347350
}
348351

349-
func GenOriginalReq(url string) (*http.Request, error) {
350-
// 生成原始请求
351-
if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
352-
} else {
353-
url = "http://" + url
354-
}
355-
originalReq, err := http.NewRequest("GET", url, nil)
352+
func VerifyPortConnection(targetAddr string) bool {
353+
_, err := TcpSend(targetAddr, nil)
356354
if err != nil {
357-
log.Error("util/requests.go:GenOriginalReq original request gen error", url, err)
358-
return nil, err
355+
return false
359356
}
360-
originalReq.Header.Set("Host", originalReq.Host)
361-
originalReq.Header.Set("Accept-Encoding", "gzip, deflate")
362-
originalReq.Header.Set("Accept","*/*")
363-
originalReq.Header.Set("User-Agent", conf.GlobalConfig.HttpConfig.Headers.UserAgent)
364-
originalReq.Header.Set("Accept-Language","en")
365-
originalReq.Header.Set("Connection","close")
366-
367-
return originalReq, nil
357+
return true
368358
}
369359

370360
func VerifyTargetConnection(originalReq *http.Request) bool {
@@ -398,6 +388,67 @@ func VerifyTargetConnection(originalReq *http.Request) bool {
398388
return true
399389
}
400390

391+
func VerifyInputTarget(target string) (bool, string) {
392+
// 连通性校验改到这里
393+
// 1.不带https/http协议 && 不带端口:放弃检查(icmp限制太多)
394+
// 2.带端口:tcp 端口
395+
// 3.带https/http协议不带端口:tcp 80/443
396+
// 生成原始请求
397+
verify := true
398+
// 有端口
399+
if len(strings.Split(target,":")) > 1 {
400+
// 带端口
401+
if strings.HasPrefix(target, "http://") || strings.HasPrefix(target, "https://"){
402+
403+
}else {
404+
target = "http://" + target
405+
}
406+
} else {
407+
// 不带端口
408+
if strings.HasPrefix(target, "http://"){
409+
// 输入 http
410+
verify = VerifyPortConnection(net.JoinHostPort(target, "80"))
411+
} else if strings.HasPrefix(target, "https://") {
412+
// 输入 https
413+
verify = VerifyPortConnection(net.JoinHostPort(target, "443"))
414+
} else {
415+
// 不校验
416+
target = "http://" + target
417+
}
418+
}
419+
return verify, target
420+
}
421+
422+
func GenOriginalReq(target string) (*http.Request, error) {
423+
verify, fixTarget := VerifyInputTarget(target)
424+
if !verify {
425+
errMsg := fmt.Errorf("util/requests.go:GenOriginalReq %s can not connect", target)
426+
log.Error(errMsg)
427+
return nil, errMsg
428+
}
429+
originalReq, err := http.NewRequest("GET", fixTarget, nil)
430+
if err != nil {
431+
errMsg := fmt.Errorf("util/requests.go:GenOriginalReq %s original request gen error %v", target, err)
432+
log.Error(errMsg)
433+
return nil, errMsg
434+
}
435+
originalReq.Header.Set("Host", originalReq.Host)
436+
originalReq.Header.Set("Accept-Encoding", "gzip, deflate")
437+
originalReq.Header.Set("Accept","*/*")
438+
originalReq.Header.Set("User-Agent", conf.GlobalConfig.HttpConfig.Headers.UserAgent)
439+
originalReq.Header.Set("Accept-Language","en")
440+
originalReq.Header.Set("Connection","close")
441+
442+
// 检查fixUrl连通性
443+
verify = VerifyTargetConnection(originalReq)
444+
if !verify {
445+
errMsg := fmt.Errorf("util/requests.go:GenOriginalReq %s can not connect", fixTarget)
446+
log.Error(errMsg)
447+
return nil, errMsg
448+
}
449+
return originalReq, nil
450+
}
451+
401452
func GetOriginalReqBody(originalReq *http.Request) ([]byte, error){
402453
var data []byte
403454
if originalReq.Body != nil && originalReq.Body != http.NoBody {

pkg/util/request_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/tls"
66
"fmt"
77
"github.com/valyala/fasthttp"
8-
"net/http"
98
"strings"
109
"testing"
1110
"time"
@@ -21,8 +20,8 @@ func TestVerifyTargetConnection(t *testing.T) {
2120
// fmt.Println(0)
2221
//}
2322

24-
originalReq, _ := http.NewRequest("GET", "http://www.jweny.com/", nil)
25-
fmt.Println(VerifyTargetConnection(originalReq))
23+
//originalReq, _ := http.NewRequest("GET", "http://www.jweny.com/", nil)
24+
//fmt.Println(VerifyTargetConnection(originalReq))
2625

2726

2827
//req := fasthttp.AcquireRequest()

pkg/util/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
)
77

8-
// 版本对比方法
8+
// SingleVersionCompare 版本对比方法
99
// <=0没有漏洞 >0有漏洞
1010
func SingleVersionCompare(verCurrent string, verVul string) (int, error) {
1111
partsCurrent := strings.Split(verCurrent, ".")

poc/rule/parallel.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/jweny/pocassist/pkg/conf"
66
"github.com/jweny/pocassist/pkg/db"
77
log "github.com/jweny/pocassist/pkg/logging"
8-
"github.com/jweny/pocassist/pkg/util"
98
"github.com/panjf2000/ants/v2"
109
"gopkg.in/yaml.v2"
1110
"net/http"
@@ -129,13 +128,6 @@ func TaskConsumer(){
129128
db.ErrorTask(item.Task.Id)
130129
continue
131130
}
132-
// 检查可用性
133-
verify := util.VerifyTargetConnection(item.OriginalReq)
134-
if !verify {
135-
log.Error("[rule/parallel.go:TaskConsumer target can not connect]", item.OriginalReq.URL.String())
136-
db.ErrorTask(item.Task.Id)
137-
continue
138-
}
139131
RunPlugins(item)
140132
}
141133
}

poc/scripts/poc-go-shiro-unserialize-550.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func ShiroJavaUnserilize(args *ScriptScanArgs) (*util.ScanResult, error) {
8585
}
8686

8787
isShiro := false
88-
for key, _ := range resp.Headers {
89-
if key == "rememberMe" {
88+
if _, ok := resp.Headers["set-cookie"]; ok {
89+
v := resp.Headers["set-cookie"]
90+
if strings.Contains(v,"rememberMe") {
9091
isShiro = true
9192
}
9293
}

0 commit comments

Comments
 (0)