Skip to content

Commit 842d391

Browse files
committed
fix fuzz正则表达式消耗资源bug 2022-07-13 09:17:1657675058
1 parent c83b543 commit 842d391

File tree

10 files changed

+75
-45
lines changed

10 files changed

+75
-45
lines changed

brute/filefuzz.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/url"
99
"regexp"
1010
"strings"
11-
"time"
1211
)
1312

1413
type page struct {
@@ -71,8 +70,10 @@ func reqPage(u string) (*page, *pkg.Response, error) {
7170
if x0, ok := req.Header["Content-Type"]; ok && 0 < len(x0) {
7271
x0B := []byte(x0[0])
7372
for _, reg := range regs {
74-
if matched, _ := regexp.Match(reg, x0B); matched {
75-
page.isBackUpPage = true
73+
if r1, ok := regsMap[reg]; ok {
74+
if r1.Match(x0B) {
75+
page.isBackUpPage = true
76+
}
7677
}
7778
}
7879
}
@@ -91,6 +92,7 @@ var fuzz404 string
9192
//go:embed dicts/page404Content.txt
9293
var page404Content1 string
9394
var regs []string
95+
var regsMap = make(map[string]*regexp.Regexp)
9496

9597
func init() {
9698
bakSuffix = pkg.GetVal4File("bakSuffix", bakSuffix)
@@ -99,7 +101,14 @@ func init() {
99101
page404Content1 = pkg.GetVal4File("page404Content1", page404Content1)
100102
InitGeneral()
101103
regs = strings.Split(strings.TrimSpace(fuzzct), "\n")
102-
regs = append(regs, ret...)
104+
var err error
105+
for _, reg := range regs {
106+
regsMap[reg], err = regexp.Compile(reg)
107+
if nil != err {
108+
log.Println(reg, " regexp.Compile error: ", err)
109+
}
110+
}
111+
//regs = append(regs, ret...)
103112
}
104113

105114
// 文件fuzz
@@ -161,6 +170,9 @@ func FileFuzz(u string, indexStatusCode int, indexContentLength int, indexbody s
161170
//log.Println(u, " ", payload)
162171
endP := u[len(u)-1:] == "/"
163172
go func(payload string) {
173+
defer func() {
174+
<-ch
175+
}()
164176
szUrl := u + payload
165177
if strings.HasPrefix(payload, "/") && endP {
166178
szUrl = u + payload[1:]
@@ -242,8 +254,8 @@ func FileFuzz(u string, indexStatusCode int, indexContentLength int, indexbody s
242254
} else {
243255
errorTimes += 1
244256
}
245-
<-time.After(time.Duration(500) * time.Millisecond)
246-
<-ch
257+
//<-time.After(time.Duration(500) * time.Millisecond)
258+
247259
}(payload)
248260
}
249261
close(ch)

brute/fuzzfingerprints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func addfingerprintsnormal(payload string, technologies []string, req *pkg.Respo
4343
if req.StatusCode == 200 && pkg.StrContains(req.Body, "Oracle") {
4444
technologies = append(technologies, "Weblogic")
4545
}
46-
case "/wls-wsat", "/wls-wsat/CoordinatorPortType", "/wls-wsat/CoordinatorPortType11", "/_async/AsyncResponseService", "/_async/AsyncResponseServiceSoap12", "/uddiexplorer/SearchPublicRegistries.jsp", "/ws_utc/config.do":
46+
case "/wls-wsat", "/wls-wsat/CoordinatorPortType", "/wls-wsat/CoordinatorPortType11", "/_async/AsyncResponseService", "/_async/AsyncResponseServiceSoap12", "/uddiexplorer/SearchPublicRegistries.jsp", "/ws_utc/config.do", "/bea_wls_internal/classes/mejb@/org/omg/stub/javax/management/j2ee/_ManagementHome_Stub.class":
4747
if req.StatusCode == 200 && (pkg.StrContains(req.Body, "weblogic") || strings.Contains(req.Body, "www.bea.com")) {
4848
technologies = append(technologies, "Weblogic")
4949
}

config/config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@
5454
"EnableKsubdomain": true,
5555
"KsubdomainRegxp": "([0-9a-zA-Z\\-]+\\.[0-9a-zA-Z\\-]+)$",
5656
"naabu_dns": {},
57-
"naabu": {"TopPorts": "1000","ScanAllIPS": true,"Threads": 64},
57+
"naabu": {"TopPorts": "1000","ScanAllIPS": true,"Threads": 25},
5858
"priorityNmap": true,
5959
"nuclei": {},
6060
"enablEmbedYaml": true,
6161
"httpx": {},
6262
"enableEsSv": false,
6363
"esthread": 8,
64+
"hydrathread": 8,
65+
"Fuzzthreads": 32,
6466
"esUrl": "http://127.0.0.1:9200/%s_index/_doc/%s"
6567
}

pkg/config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os/exec"
1414
"regexp"
1515
"runtime"
16+
"strconv"
1617
"strings"
1718
)
1819

@@ -137,13 +138,18 @@ func Init() {
137138
config.AddConfigPath("./config/")
138139
config.AddConfigPath("$HOME")
139140
config.AddConfigPath("/etc/")
141+
nT, err := strconv.Atoi(GetVal4File("Fuzzthreads", "32"))
142+
if nil != err {
143+
nT = 32
144+
}
145+
Fuzzthreads = nT
140146
// 显示调用
141147
config.SetConfigType("json")
142148
if "" != ConfigName {
143149
config.SetConfigFile(ConfigName)
144150
}
145-
err := config.ReadInConfig() // 查找并读取配置文件
146-
if err != nil { // 处理读取配置文件的错误
151+
err = config.ReadInConfig() // 查找并读取配置文件
152+
if err != nil { // 处理读取配置文件的错误
147153
log.Println("config.ReadInConfig ", err)
148154
return
149155
}

pkg/fingerprint/fgConst.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fingerprint
2+
3+
import (
4+
_ "embed"
5+
"encoding/json"
6+
)
7+
8+
type IdMethod int
9+
10+
const (
11+
Reg_idMethod IdMethod = 11515 // 识别方式:正则表达式
12+
Text_idMethod IdMethod = 11516 // 识别方式:文本
13+
Bin_idMethod IdMethod = 11517 // 识别方式:bin,二进制
14+
Base64_idMethod IdMethod = 11518 // 识别方式:base64
15+
Md5_idMethod IdMethod = 11519 // 识别方式:md5
16+
Header_idPart IdMethod = 11520 // 识别区域:header
17+
Body_idPart IdMethod = 11521 // 识别区域:body
18+
Raw_idPart IdMethod = 11522 // 识别区域:raw
19+
Status_code_idPart IdMethod = 8998 // 识别区域:状态吗
20+
)
21+
22+
//go:embed db/fg.json
23+
var FgData string
24+
var FGDataMap = make(map[string]interface{})
25+
26+
func init() {
27+
json.Unmarshal([]byte(FgData), &FGDataMap)
28+
}

pkg/hydra/runner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/hktalent/scan4all/pkg"
77
"github.com/logrusorgru/aurora"
88
"log"
9+
"strconv"
910
"strings"
1011
)
1112

@@ -28,7 +29,11 @@ func init() {
2829
// 密码破解
2930
func Start(IPAddr string, Port int, Protocol string) {
3031
authInfo := NewAuthInfo(IPAddr, Port, Protocol)
31-
crack := NewCracker(authInfo, true, 8)
32+
nT, err := strconv.Atoi(pkg.GetVal4File("hydrathread", "8"))
33+
if nil != err {
34+
nT = 8
35+
}
36+
crack := NewCracker(authInfo, true, nT)
3237
fmt.Printf("\n[hydra]->开始对%v:%v[%v]进行暴力破解,字典长度为:%d\n", IPAddr, Port, Protocol, crack.Length())
3338
go crack.Run()
3439
//爆破结果获取

pkg/naabu/v2/pkg/runner/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func ParseOptions() *Options {
103103
)
104104

105105
flagSet.CreateGroup("rate-limit", "Rate-limit",
106-
flagSet.IntVar(&options.Threads, "c", 64, "general internal worker threads"),
106+
flagSet.IntVar(&options.Threads, "c", 25, "general internal worker threads"),
107107
flagSet.IntVar(&options.Rate, "rate", DefaultRateSynScan, "packets to send per second"),
108108
)
109109

pkg/naabu/v2/pkg/runner/targets.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func Add2Naabubuffer(target string) {
244244
Naabubuffer.Write([]byte(target))
245245
}
246246

247+
var r1, _ = regexp.Compile(`[^\/]`)
248+
247249
func (r *Runner) AddTarget(target string) error {
248250
target = strings.TrimSpace(target)
249251
if "" == target {
@@ -287,17 +289,15 @@ func (r *Runner) AddTarget(target string) error {
287289
////UrlPrecise bool // 精准url扫描,不去除url清单上下文 2022-06-08
288290
UrlPrecise := pkg.GetVal(pkg.UrlPrecise)
289291
if "true" == UrlPrecise && len(target) > len(s1) {
290-
r1, err := regexp.Compile(`[^\/]`)
291-
if nil == err {
292-
s2 := r1.ReplaceAllString(target[len(s1):], "")
293-
// 包含1个以上/表示有上下文
294-
if 1 < len(s2) {
295-
if r.options.Verbose {
296-
log.Println("Precise scan: ", target)
297-
}
298-
Add2Naabubuffer(fmt.Sprintf("%s\n", target))
292+
s2 := r1.ReplaceAllString(target[len(s1):], "")
293+
// 包含1个以上/表示有上下文
294+
if 1 < len(s2) {
295+
if r.options.Verbose {
296+
log.Println("Precise scan: ", target)
299297
}
298+
Add2Naabubuffer(fmt.Sprintf("%s\n", target))
300299
}
300+
301301
}
302302
return nil
303303
}

test/getUrlHash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func favicohashMd5(host string) string {
103103
return "0"
104104
}
105105
}
106-
func main1() {
106+
func main() {
107107
url := os.Args[1]
108108
s1 := favicohashMd5(url)
109109
fmt.Println(s1)

test/test.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)