Skip to content

Commit

Permalink
Merge pull request #59 from hktalent/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hktalent committed Aug 1, 2022
2 parents 861136d + 2de0a7b commit a99e9ba
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 50 deletions.
6 changes: 2 additions & 4 deletions lib/util/Const.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ var PocCheck_pipe = make(chan *PocCheck, 64)
// 1、需要认证
// 2、shiro
func CheckHeader(header *http.Header, szUrl string) {
Wg.Add(1)
go func() {
defer Wg.Done()
DoSyncFunc(func() {
if nil != header {
a1 := []string{}
if v := (*header)["www-Authenticate"]; 0 < len(v) {
Expand All @@ -111,5 +109,5 @@ func CheckHeader(header *http.Header, szUrl string) {
PocCheck_pipe <- &PocCheck{Wappalyzertechnologies: &a1, URL: szUrl, FinalURL: szUrl, Checklog4j: false}
}
}
}()
})
}
21 changes: 10 additions & 11 deletions lib/util/kvDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"encoding/json"
"github.com/dgraph-io/badger"
"log"
"sync"
)

var Cache1 *KvDbOp
var DoOnce sync.Once

// https://colobu.com/2017/10/11/badger-a-performant-k-v-store/
// https://juejin.cn/post/6844903814571491335
Expand All @@ -17,15 +15,16 @@ type KvDbOp struct {
}

func NewKvDbOp() *KvDbOp {
DoOnce.Do(func() {
Cache1 = &KvDbOp{}
CacheName11 := ".DbCache"
s1 := GetVal(CacheName)
if "" != s1 {
CacheName11 = s1
}
Cache1.Init(CacheName11)
})
if nil != Cache1 {
return Cache1
}
Cache1 = &KvDbOp{}
CacheName11 := ".DbCache"
s1 := GetVal(CacheName)
if "" != s1 {
CacheName11 = s1
}
Cache1.Init(CacheName11)
return Cache1
}
func (r *KvDbOp) SetExpiresAt(ExpiresAt uint64) {
Expand Down
8 changes: 3 additions & 5 deletions lib/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"reflect"
"runtime"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -285,9 +283,9 @@ func CloseAll() {
Cache1 = nil
}

if runtime.GOOS == "windows" || GetValAsBool("autoRmCache") {
os.RemoveAll(GetVal(CacheName))
}
//if runtime.GOOS == "windows" || GetValAsBool("autoRmCache") {
// os.RemoveAll(GetVal(CacheName))
//}
Close()
CloseCache()
}
2 changes: 0 additions & 2 deletions pkg/httpx/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,6 @@ retry:
}
return nn
}
util.Wg.Add(1)
//通过wFingerprint获取到的指纹进行检测gopoc check
poctechnologies1 = pocs_go.POCcheck(technologies, ul, finalURL, false)
Vullist = append(Vullist, poctechnologies1...)
Expand All @@ -1337,7 +1336,6 @@ retry:
filefuzzTechnologies = SliceRemoveDuplicates(filefuzzTechnologies)
// 取差集合
filefuzzTechnologies = difference(filefuzzTechnologies, technologies)
util.Wg.Add(1)
poctechnologies2 = pocs_go.POCcheck(filefuzzTechnologies, ul, finalURL, true) //通过敏感文件扫描获取到的指纹进行检测gopoc check
Vullist = append(Vullist, poctechnologies2...)
for _, technology := range filefuzzTechnologies {
Expand Down
6 changes: 2 additions & 4 deletions pkg/hydra/doNmapResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ func DoParseXml(s string, bf *bytes.Buffer) {
// 处理使用者自己扫描的结果
func DoNmapWithFile(s string, bf *bytes.Buffer) bool {
if strings.HasSuffix(strings.ToLower(s), ".xml") {
util.Wg.Add(1)
go func() {
defer util.Wg.Done()
util.DoSyncFunc(func() {
b, err := ioutil.ReadFile(s)
if nil == err && 0 < len(b) {
DoParseXml(string(b), bf)
} else {
log.Println("DoNmapWithFile: ", err)
}
}()
})
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion pkg/naabu/v2/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (r *Runner) RunEnumeration() error {
}

if r.options.Stream {
go r.Load() //nolint
r.Load() //nolint
} else {
err := r.Load()
if err != nil {
Expand Down
44 changes: 21 additions & 23 deletions pocs_go/go_poc_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ import (
"net/url"
"os"
"strings"
"time"
)

// 需优化:相同都目标,相同都检测只做一次
func POCcheck(wappalyzertechnologies []string, URL string, finalURL string, checklog4j bool) []string {
if nil != util.Wg {
defer util.Wg.Done()
}
if util.TestRepeat(wappalyzertechnologies, URL, finalURL, checklog4j) {
return []string{}
}
Expand Down Expand Up @@ -271,39 +267,41 @@ func POCcheck(wappalyzertechnologies []string, URL string, finalURL string, chec
}

func init() {
if os.Getenv("NoPOC") == "true" {
//close(util.PocCheck_pipe) // 这行会在 NoPOC该标志开启时,其他进程无法传递过来而出错
return
}
util.RegInitFunc(func() {
// 异步启动一个线程处理检测,避免
util.Wg.Add(1)
go func() {
defer util.Wg.Done()
nMax := 120 // 等xxx秒都没有消息进入就退出
nCnt := 0
//nMax := 120 // 等xxx秒都没有消息进入就退出
//nCnt := 0
for {
select {
case <-util.Ctx_global.Done():
close(util.PocCheck_pipe)
return
case x1, ok := <-util.PocCheck_pipe:
if nil == x1 || !ok {
log.Println("go_poc_checkout is over")
return
}
nCnt = 0
//nCnt = 0
log.Printf("<-lib.PocCheck_pipe: %+v %s", *x1.Wappalyzertechnologies, x1.URL)
util.Wg.Add(1)
go POCcheck(*x1.Wappalyzertechnologies, x1.URL, x1.FinalURL, x1.Checklog4j)
util.DoSyncFunc(func() {
func(x99 *util.PocCheck) {
POCcheck(*x99.Wappalyzertechnologies, x99.URL, x99.FinalURL, x99.Checklog4j)
}(x1)
})
default:
if os.Getenv("NoPOC") == "true" {
//close(util.PocCheck_pipe) // 这行会在 NoPOC该标志开启时,其他进程无法传递过来而出错
return
}
var f01 float32 = float32(nCnt) / float32(nMax) * float32(100)
fmt.Printf(" Asynchronous go PoCs detection task %%%0.2f ....\r", f01)
<-time.After(time.Duration(1) * time.Second)
nCnt += 1
if nMax <= nCnt {
close(util.PocCheck_pipe)
return
}
//var f01 float32 = float32(nCnt) / float32(nMax) * float32(100)
//fmt.Printf(" Asynchronous go PoCs detection task %%%0.2f ....\r", f01)
//<-time.After(time.Duration(1) * time.Second)
//nCnt += 1
//if nMax <= nCnt {
// close(util.PocCheck_pipe)
// return
//}
}
}
}()
Expand Down

0 comments on commit a99e9ba

Please sign in to comment.