Skip to content

Commit 83ecf17

Browse files
committed
一个正确可编译的版本 2022-10-04
1 parent bee8155 commit 83ecf17

File tree

24 files changed

+232
-158
lines changed

24 files changed

+232
-158
lines changed

README_CN.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,5 @@ more see: <a href=https://github.com/hktalent/scan4all/discussions>discussions</
250250
export GOPRIVATE=github.com/hktalent
251251
go env |grep GOPRIVATE
252252
253-
go env -w GOPRIVATE=github.com/hktalent/goSqlite_gorm/[email protected]
254-
go get -v github.com/hktalent/goSqlite_gorm/[email protected]
255-
256-
257253
https://github.com/heartshare/go-wafw00f
258254
-->

config/scan4all_db.db

0 Bytes
Binary file not shown.

engine/dispather.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"github.com/hktalent/goSqlite_gorm/lib"
55
"github.com/hktalent/goSqlite_gorm/lib/scan/Const"
66
"github.com/hktalent/goSqlite_gorm/pkg/models"
7+
"github.com/hktalent/scan4all/lib/util"
78
"github.com/hktalent/scan4all/pkg/portScan"
89
)
910

1011
var (
11-
CaseScanFunc = map[int]interface{}{
12+
CaseScanFunc = map[int]util.EngineFuncType{
1213
Const.ScanType_SSLInfo: nil, // 01- SSL信息分析,并对域名信息进行收集、进入下一步流程
1314
Const.ScanType_SubDomain: nil, // 02- 子域名爆破,新域名回归 到: 1 <-- -> 2,做去重处理
1415
Const.ScanType_MergeIps: nil, // 03- 默认自动合并ip,记录ip与域名的关联关系,再发送payload时考虑:相同ip不同域名,相同payload分别发送 合并相同目标 若干域名的ip,避免扫描时重复
1516
Const.ScanType_Pswd4hydra: nil, // 04- 密码破解,隐含包含了: 端口扫描(05-masscan + 06-nmap)
1617
Const.ScanType_Masscan: portScan.MassScanTarget, // 05- 合并后的ip 进行快速端口扫描
17-
Const.ScanType_Nmap: nil, // 06、精准 端口指纹,排除masscan已经识别的几种指纹
18+
Const.ScanType_Nmap: portScan.DoNmap, // 06、精准 端口指纹,排除masscan已经识别的几种指纹
1819
Const.ScanType_IpInfo: nil, // 07- 获取ip info
1920
Const.ScanType_GoPoc: nil, // 08- go-poc 检测, 隐含包含了: 端口扫描(05-masscan + 06-nmap)
2021
Const.ScanType_PortsWeb: nil, // 09- web端口识别,Naabu,识别 https,识别存活的web端口,再进入下一流程
@@ -32,7 +33,7 @@ var (
3233
func Dispather(task *models.Target4Chan) {
3334
for k, _ := range CaseScanFunc {
3435
if lib.HasScanType(task.ScanType, k) {
35-
x1 := &models.EventData{EventType: k}
36+
x1 := &models.EventData{EventType: k, Task: task}
3637
switch k {
3738
case Const.ScanType_SSLInfo: // 01- SSL信息分析,并对域名信息进行收集、进入下一步流程
3839
G_Engine.EventData <- x1
@@ -41,11 +42,12 @@ func Dispather(task *models.Target4Chan) {
4142
case Const.ScanType_MergeIps: // 03- 默认自动合并ip,记录ip与域名的关联关系,再发送payload时考虑:相同ip不同域名,相同payload分别发送 合并相同目标 若干域名的ip,避免扫描时重复
4243
G_Engine.EventData <- x1
4344
case Const.ScanType_Pswd4hydra: // 04- 密码破解,隐含包含了: 端口扫描(05-masscan + 06-nmap)
44-
x1.EventData = []interface{}{x1, []interface{}{portScan.TargetStr(task.ScanWeb)}}
4545
G_Engine.EventData <- x1
46-
case Const.ScanType_Masscan: // 05- 合并后的ip 进行快速端口扫描
46+
case Const.ScanType_Masscan: // 05- 合并后的ip 进行快速端口扫描; // 06、精准 端口指纹,排除masscan已经识别的几种指纹
47+
x1.EventData = []interface{}{[]interface{}{portScan.TargetStr(task.ScanWeb)}}
4748
G_Engine.EventData <- x1
48-
case Const.ScanType_Nmap: // 06、精准 端口指纹,排除masscan已经识别的几种指纹
49+
case Const.ScanType_Nmap: // 05- 合并后的ip 进行快速端口扫描; // 06、精准 端口指纹,排除masscan已经识别的几种指纹
50+
x1.EventData = []interface{}{x1.Target2Ip(), []string{"0-65535"}}
4951
G_Engine.EventData <- x1
5052
case Const.ScanType_IpInfo: // 07- 获取ip info
5153
G_Engine.EventData <- x1

engine/engine.go

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package engine
22

33
import (
44
"context"
5-
"github.com/codegangsta/inject"
65
"github.com/hktalent/goSqlite_gorm/pkg/models"
76
"github.com/hktalent/scan4all/lib/util"
87
"github.com/hktalent/scan4all/pocs_go"
@@ -53,7 +52,7 @@ func (e *Engine) Close() {
5352
}
5453

5554
// case 扫描使用的函数
56-
func (e *Engine) DoCase(ed *models.EventData) interface{} {
55+
func (e *Engine) DoCase(ed *models.EventData) util.EngineFuncType {
5756
if i, ok := CaseScanFunc[ed.EventType]; ok {
5857
return i
5958
}
@@ -65,24 +64,12 @@ func (e *Engine) DoCase(ed *models.EventData) interface{} {
6564
// 每个事件异步执行
6665
// 每种事件类型可以独立控制并发数
6766
func (e *Engine) DoEvent(ed *models.EventData) {
68-
var x01 = &models.EventData{}
69-
if nil != x01 {
70-
}
71-
if nil != ed {
67+
if nil != ed && nil != ed.EventData && 0 < len(ed.EventData) {
7268
fnCall := e.DoCase(ed)
7369
if nil != fnCall {
74-
in := inject.New()
75-
for _, i := range ed.EventData {
76-
in.Map(i)
77-
}
78-
v, err := in.Invoke(fnCall)
79-
if nil != err {
80-
log.Printf("DoEvent %d is error: %v %+v \n", ed.EventType, err, ed.EventData)
81-
} else if nil != v {
82-
log.Printf("DoEvent result %s %v\n", ed.EventType, v)
83-
}
70+
fnCall(ed, ed.EventData...)
8471
} else {
85-
log.Printf("can case func %v\n", ed)
72+
log.Printf("can not find fnCall case func %v\n", ed)
8673
}
8774
}
8875
}
@@ -106,7 +93,7 @@ func init() {
10693
close(util.PocCheck_pipe)
10794
return
10895
case x2 := <-G_Engine.EventData: // 各种扫描的控制
109-
if nil != x2 {
96+
if nil != x2 && nil != x2.EventData {
11097
G_Engine.Wg.Add(1)
11198
G_Engine.PoolFunc.Invoke(x2)
11299
}
@@ -126,14 +113,6 @@ func init() {
126113
default:
127114
util.DoDelayClear()
128115
util.DoSleep()
129-
//var f01 float32 = float32(nCnt) / float32(nMax) * float32(100)
130-
//fmt.Printf(" Asynchronous go PoCs detection task %%%0.2f ....\r", f01)
131-
//<-time.After(time.Duration(1) * time.Second)
132-
//nCnt += 1
133-
//if nMax <= nCnt {
134-
// close(util.PocCheck_pipe)
135-
// return
136-
//}
137116
}
138117
}
139118
}()

fixMod.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ go build
1515
git add vendor
1616
rm -rf vendor/github.com/hktalent/goSqlite_gorm
1717
ln -s $HOME/MyWork/goSqlite_gorm $PWD/vendor/github.com/hktalent/goSqlite_gorm
18-
19-

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,16 @@ require (
9393
github.com/dgraph-io/badger v1.6.2
9494
github.com/dlclark/regexp2 v1.7.0
9595
github.com/emersion/go-message v0.16.0
96+
github.com/fsnotify/fsnotify v1.5.4
9697
github.com/go-playground/validator/v10 v10.11.1
9798
github.com/go-routeros/routeros v0.0.0-20210123142807-2a44d57c6730
9899
github.com/go-sql-driver/mysql v1.6.0
99100
github.com/google/cel-go v0.12.5
100101
github.com/google/go-github v17.0.0+incompatible
101102
github.com/gorilla/websocket v1.5.0
102103
github.com/gosnmp/gosnmp v1.35.0
103-
github.com/hktalent/PipelineHttp v0.0.0-20221003131356-bf29cf889d54
104-
github.com/hktalent/goSqlite_gorm v1.1.0
104+
github.com/hktalent/PipelineHttp v0.0.0-20221004080931-279351b9fb96
105+
github.com/hktalent/goSqlite_gorm v1.1.1
105106
github.com/hktalent/jarm-go v0.0.0-20220918133110-7801447b6267
106107
github.com/huin/asn1ber v0.0.0-20120622192748-af09f62e6358
107108
github.com/icodeface/tls v0.0.0-20190904083142-17aec93c60e5
@@ -180,7 +181,6 @@ require (
180181
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 // indirect
181182
github.com/fatih/structs v1.1.0 // indirect
182183
github.com/fortytw2/leaktest v1.3.0 // indirect
183-
github.com/fsnotify/fsnotify v1.5.4 // indirect
184184
github.com/getsentry/sentry-go v0.13.0 // indirect
185185
github.com/gin-contrib/sse v0.1.0 // indirect
186186
github.com/gin-gonic/gin v1.8.1 // indirect
@@ -217,7 +217,7 @@ require (
217217
github.com/hashicorp/go-version v1.6.0 // indirect
218218
github.com/hashicorp/golang-lru v0.5.4 // indirect
219219
github.com/hashicorp/hcl v1.0.0 // indirect
220-
github.com/hktalent/go-utils v0.0.0-20221002030334-91cfbdd4fc1e // indirect
220+
github.com/hktalent/go-utils v0.0.0-20221004021941-7e10e0fb13ea // indirect
221221
github.com/hktalent/websocket v0.0.0-20220908204337-b4a81b861976 // indirect
222222
github.com/iancoleman/orderedmap v0.2.0 // indirect
223223
github.com/itchyny/gojq v0.12.9 // indirect

go.sum

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,12 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
506506
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
507507
github.com/hbakhtiyor/strsim v0.0.0-20190107154042-4d2bbb273edf h1:umfGUaWdFP2s6457fz1+xXYIWDxdGc7HdkLS9aJ1skk=
508508
github.com/hbakhtiyor/strsim v0.0.0-20190107154042-4d2bbb273edf/go.mod h1:V99KdStnMHZsvVOwIvhfcUzYgYkRZeQWUtumtL+SKxA=
509-
github.com/hktalent/PipelineHttp v0.0.0-20221003065227-47b8e1bf6b2c h1:SumSJIcYmdvftnqaGHN9sjWg4FufAWW3AHsrX9zD3is=
510-
github.com/hktalent/PipelineHttp v0.0.0-20221003065227-47b8e1bf6b2c/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
511-
github.com/hktalent/PipelineHttp v0.0.0-20221003100935-ac8d037291a8 h1:Oy9ix3oj16YIqULObNe2CPdMacNB+ItR5A+QJrqIGaU=
512-
github.com/hktalent/PipelineHttp v0.0.0-20221003100935-ac8d037291a8/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
513-
github.com/hktalent/PipelineHttp v0.0.0-20221003105410-f88daa49bf60 h1:VRK4cbbq8NhMNIdkncvaMFjSOgOLgSoBQIFQiXS9XwI=
514-
github.com/hktalent/PipelineHttp v0.0.0-20221003105410-f88daa49bf60/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
515-
github.com/hktalent/PipelineHttp v0.0.0-20221003123809-b0d3282c95f6 h1:bFumO4bwgE7Cg8QNYsY9Dbw3IbRTFJft3Km8+6DvM9s=
516-
github.com/hktalent/PipelineHttp v0.0.0-20221003123809-b0d3282c95f6/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
517-
github.com/hktalent/PipelineHttp v0.0.0-20221003130924-55bd365e6be8 h1:MGFdu14hisPVOJ/wclrO7tDYzGkB9glmCSUi2Z65UgI=
518-
github.com/hktalent/PipelineHttp v0.0.0-20221003130924-55bd365e6be8/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
519-
github.com/hktalent/PipelineHttp v0.0.0-20221003131356-bf29cf889d54 h1:OrDjIFq070O7HZOw3TKk9FYvqOsm8IyxBJc1EK0bsGQ=
520-
github.com/hktalent/PipelineHttp v0.0.0-20221003131356-bf29cf889d54/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
521-
github.com/hktalent/go-utils v0.0.0-20221002030334-91cfbdd4fc1e h1:jXfIB19HIJ2FeHQDakwbE+TwTegZa6SG3BfFfO72w7g=
522-
github.com/hktalent/go-utils v0.0.0-20221002030334-91cfbdd4fc1e/go.mod h1:9E0C0K+/zzyJ+VqFx1llC3y7+mGgW3toLoyMQnlNXhw=
523-
github.com/hktalent/goSqlite_gorm v1.1.0 h1:hiSQJBLz8zZqgnfVCk33Xo5SBPrdp6qrvNeNbl8AEgc=
524-
github.com/hktalent/goSqlite_gorm v1.1.0/go.mod h1:Fz2du07SQytifuV2p/ibyUFTXaE+8vhR/OZUcdHZCRs=
509+
github.com/hktalent/PipelineHttp v0.0.0-20221004080931-279351b9fb96 h1:8++Z/n334CvPHN6PWXby+lMx5MO5tosHYCwmHPA6Zgg=
510+
github.com/hktalent/PipelineHttp v0.0.0-20221004080931-279351b9fb96/go.mod h1:ob6ATP4M9FiqTRzyALSDox3kc6+xnTgzKuIT+rmKyeE=
511+
github.com/hktalent/go-utils v0.0.0-20221004021941-7e10e0fb13ea h1:vuxZbB9vAwBi0Uj4F5GOfVtsi5E9MFX07EkCKypVu9M=
512+
github.com/hktalent/go-utils v0.0.0-20221004021941-7e10e0fb13ea/go.mod h1:9E0C0K+/zzyJ+VqFx1llC3y7+mGgW3toLoyMQnlNXhw=
513+
github.com/hktalent/goSqlite_gorm v1.1.1 h1:kRqNFqAOtECWsUu5nBftCYFJ8MAhEHgjj2A2JOydXp0=
514+
github.com/hktalent/goSqlite_gorm v1.1.1/go.mod h1:KbxDn4W3dakhiX9eFzZ/sEAuJwKS7h42Xi3aaqU1IjE=
525515
github.com/hktalent/jarm-go v0.0.0-20220918133110-7801447b6267 h1:eH9QDUO5zwn34BLweSdpTdNcxHD/GXxxLDEG7gaR4OQ=
526516
github.com/hktalent/jarm-go v0.0.0-20220918133110-7801447b6267/go.mod h1:4r72GiZnJx4nyoKOHbzu0/5NCuY01Yekue5zueaYUcs=
527517
github.com/hktalent/websocket v0.0.0-20220908204337-b4a81b861976 h1:oGE7u0adRuzpamtAkkOy65hevwyEtrszTAVz+USJz/k=

lib/util/Const.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package util
33
import (
44
"context"
55
"fmt"
6+
"github.com/hktalent/goSqlite_gorm/pkg/models"
67
"net/http"
78
"os"
89
"regexp"
@@ -132,3 +133,13 @@ func CheckHeader(header *http.Header, szUrl string) {
132133
}
133134
})
134135
}
136+
137+
type EngineFuncType func(evt *models.EventData, args ...interface{})
138+
139+
// 工厂方法
140+
// 便于同一、规范引擎调用的方法、参数约束
141+
func EngineFuncFactory(fnCbk EngineFuncType) EngineFuncType {
142+
return func(evt *models.EventData, args ...interface{}) {
143+
fnCbk(evt, args...)
144+
}
145+
}

lib/util/config.go

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"embed"
77
"encoding/json"
88
"fmt"
9+
"github.com/fsnotify/fsnotify"
910
"github.com/karlseguin/ccache"
1011
"github.com/spf13/viper"
1112
"io/fs"
1213
"io/ioutil"
1314
"log"
1415
"math/rand"
16+
"net/http"
1517
"os"
1618
"os/exec"
1719
"reflect"
@@ -192,28 +194,30 @@ func RandStringRunes(n int) string {
192194
return string(b)
193195
}
194196

195-
// 初始化配置文件信息,这个必须先执行
196-
func Init2() {
197+
// 加载配置文件
198+
func LoadCoinfig(config *viper.Viper) {
199+
if nil == config {
200+
config = viper.New()
201+
}
202+
viper.Set("Verbose", true)
197203
pwd, _ := os.Getwd()
198204
SzPwd = pwd
199-
var ConfigName = "config/config.json"
200-
config := viper.New()
201-
config.AddConfigPath("./")
205+
//var ConfigName = "config/config.json"
206+
config.SetConfigName("config") //name of config file (without extension)
202207
config.AddConfigPath("./config/")
208+
config.AddConfigPath("./")
203209
config.AddConfigPath("$HOME")
210+
config.AddConfigPath("$HOME/config/")
211+
config.AddConfigPath("$HOME/.config/")
204212
config.AddConfigPath("/etc/")
205-
nT, err := strconv.Atoi(GetVal4File("Fuzzthreads", "32"))
206-
if nil != err {
207-
nT = 32
208-
}
209-
Fuzzthreads = nT
213+
210214
// 显示调用
211215
config.SetConfigType("json")
212-
if "" != ConfigName {
213-
config.SetConfigFile(ConfigName)
214-
}
215-
err = config.ReadInConfig() // 查找并读取配置文件
216-
if err != nil { // 处理读取配置文件的错误
216+
//if "" != ConfigName {
217+
// config.SetConfigFile(ConfigName)
218+
//}
219+
err := config.ReadInConfig() // 查找并读取配置文件
220+
if err != nil { // 处理读取配置文件的错误
217221
log.Println("config.ReadInConfig ", err)
218222
return
219223
}
@@ -223,13 +227,22 @@ func Init2() {
223227
return
224228
}
225229
config.Unmarshal(&mData)
226-
viper.Set("Verbose", false)
227-
initEs()
230+
config.OnConfigChange(func(e fsnotify.Event) {
231+
log.Println("Config file changed, now reLoad it: ", e.Name)
232+
LoadCoinfig(config)
233+
})
234+
// 避免 hold
235+
go config.WatchConfig()
236+
}
237+
238+
// 初始化配置文件信息,这个必须先执行
239+
func Init2() {
240+
LoadCoinfig(nil)
241+
Fuzzthreads = GetValAsInt("Fuzzthreads", 32)
228242
EnableHoneyportDetection = GetValAsBool("EnableHoneyportDetection")
243+
initEs()
229244

230-
configure := ccache.Configure()
231-
configure = configure.MaxSize(5000)
232-
noRpt = ccache.New(configure)
245+
noRpt = GetMemoryCache(5000, noRpt)
233246
}
234247

235248
var G_Options interface{}
@@ -425,10 +438,23 @@ func TestIs404(szUrl string) (r01 *Response, err error, ok bool) {
425438
return r01, err, ok
426439
}
427440
}
441+
sz404 := szUrl + Abs404
442+
client := GetClient(sz404)
443+
if nil != client {
444+
client.Client.Timeout = 5
445+
//log.Printf("%v %s \n", client, sz404)
446+
var x05 *http.Transport = client.Client.Transport.(*http.Transport)
447+
if nil != x05 {
448+
x05.DisableKeepAlives = true
449+
}
450+
}
428451

429-
r01, err = HttpRequset(szUrl+Abs404, "GET", "", false, map[string]string{"Connection": "close"})
452+
log.Println("start test ", sz404)
453+
r01, err = HttpRequset(sz404, "GET", "", false, map[string]string{"Connection": "close"})
430454
ok = err == nil && nil != r01 && 404 == r01.StatusCode
431455
noRpt.Set(key, []interface{}{r01, err, ok}, defaultInteractionDuration)
456+
//client.Client.Timeout = 10
457+
log.Println("end test ", sz404)
432458
return r01, err, ok
433459
}
434460
func TestIs404Page(szUrl string) (page *Page, r01 *Response, err error, ok bool) {
@@ -454,6 +480,8 @@ var fnInit []func()
454480
func RegInitFunc(cbk func()) {
455481
fnInit = append(fnInit, cbk)
456482
}
483+
484+
// 所有初始化的总入口
457485
func DoInit(config *embed.FS) {
458486
Init1(config)
459487
rand.Seed(time.Now().UnixNano())

lib/util/kvDb.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ func NewKvDbOp() *KvDbOp {
3030
os.RemoveAll(CacheName11)
3131
}
3232
Mkdirs(CacheName11)
33-
Cache1.Init(CacheName11)
33+
if nil != Cache1.Init(CacheName11) {
34+
os.RemoveAll(CacheName11)
35+
NewKvDbOp()
36+
}
3437
return Cache1
3538
}
3639
func (r *KvDbOp) SetExpiresAt(ExpiresAt uint64) {
@@ -46,6 +49,7 @@ func (r *KvDbOp) Init(szDb string) error {
4649
opts.LevelSizeMultiplier = 20
4750
db, err := badger.Open(opts)
4851
if nil != err {
52+
4953
log.Printf("Init2 k-v db cannot open multiple processes at the same time, or please delete the %s directory and try again: %v", szDb, err)
5054
return err
5155
}
@@ -78,7 +82,7 @@ func (r *KvDbOp) GetKeyForData(key string) (szRst []byte) {
7882

7983
// https://www.modb.pro/db/87317
8084
func (r *KvDbOp) Get(key string) (szRst []byte, err error) {
81-
err = r.DbConn.View(func(txn *badger.Txn) error {
85+
err = NewKvDbOp().DbConn.View(func(txn *badger.Txn) error {
8286
item, err := txn.Get([]byte(key))
8387
if err != nil {
8488
return err

0 commit comments

Comments
 (0)