Skip to content

Commit d33c577

Browse files
committed
fix 1、集成Elasticsearch存储中间结果 2、嵌入整个config目录到程序中 2022-06-30 23:00:1656601220
1 parent 215c488 commit d33c577

File tree

13 files changed

+348
-8
lines changed

13 files changed

+348
-8
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- 轻量级、开源、跨平台使用
2323
- 支持多种类型的输入 - STDIN/HOST/IP/CIDR/URL/TXT
2424
- 支持多种输出类型 - JSON/TXT/CSV/STDOUT
25+
- 可配置将结果统一存储到Elasticsearch
2526

2627
## 由配置文件、环境变量控制的新特性
2728
- 带有上下文路径的url列表,启用精确扫描 UrlPrecise=true ./main -l xx.txt
@@ -93,7 +94,10 @@
9394
"naabu_dns": {}, // naabu工具对dns配置
9495
"naabu": {"TopPorts": "1000","ScanAllIPS": true}, // naabu配置
9596
"nuclei": {}, // nuclei配置,例如线程等
96-
"httpx": {} // httpx 配置
97+
"httpx": {} // httpx 配置,
98+
"enableEsSv": true, // 开启结果send 到es
99+
"esthread": 8 // 结果写入Elasticsearch的线程数,
100+
"esUrl": "http://127.0.0.1:9200/" // Elasticsearch url
97101
}
98102
```
99103

@@ -118,7 +122,22 @@ go install github.com/hktalent/[email protected]
118122
scan4all -h
119123
```
120124
# 如何使用
121-
使用前请自行安装nmap
125+
- 1、启动 Elasticsearch, 当然你可以使用传统方式输出、结果
126+
```bash
127+
mkdir -p logs data
128+
docker run --restart=always --ulimit nofile=65536:65536 -p 9200:9200 -p 9300:9300 -d --name es -v $PWD/logs:/usr/share/elasticsearch/logs -v $PWD/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v $PWD/config/jvm.options:/usr/share/elasticsearch/config/jvm.options -v $PWD/data:/usr/share/elasticsearch/data hktalent/elasticsearch:7.16.2
129+
# 初始化es 索引
130+
config/CreateEs.sh nmap
131+
config/CreateEs.sh naabu
132+
config/CreateEs.sh httpx
133+
config/CreateEs.sh nuclei
134+
135+
# 搜索语法,更多的查询方法,自己学 Elasticsearch
136+
http://127.0.0.1:9200/nmap_index/_doc/_search?q=92.168.0.111
137+
其中92.168.0.111 是要查询的目标
138+
139+
```
140+
- 使用前请自行安装nmap
122141
<a href=https://github.com/hktalent/scan4all/discussions>使用帮助</a>
123142
```bash
124143
go build

config/CreateEs.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
sed $'s/$/\r/' <<EOF | nc 127.0.0.1 9200
3+
DELETE /${1}_index* HTTP/1.1
4+
host:127.0.0.1:9200
5+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15
6+
Connection: keep-alive
7+
Content-Type: application/json;charset=UTF-8
8+
Content-Length: 0
9+
10+
PUT /${1}_index HTTP/1.1
11+
host:127.0.0.1:9200
12+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15
13+
Connection: keep-alive
14+
Content-Type: application/json;charset=UTF-8
15+
Content-Length: 405
16+
17+
{
18+
"settings": {
19+
"analysis": {
20+
"analyzer": {
21+
"default": {
22+
"type": "custom",
23+
"tokenizer": "ik_smart",
24+
"char_filter": [
25+
"html_strip"
26+
]
27+
},
28+
"default_search": {
29+
"type": "custom",
30+
"tokenizer": "ik_smart",
31+
"char_filter": [
32+
"html_strip"
33+
]
34+
}
35+
}
36+
}
37+
}
38+
}
39+
PUT /${1}_index/_settings HTTP/1.1
40+
host:127.0.0.1:9200
41+
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15
42+
Connection: close
43+
Content-Type: application/json;charset=UTF-8
44+
Content-Length: 171
45+
46+
{
47+
"index.translog.durability": "async",
48+
"index.translog.sync_interval": "5s",
49+
"index.translog.flush_threshold_size":"100m",
50+
"refresh_interval": "30s"
51+
}
52+
53+
EOF
54+
55+
xxx=$(/usr/bin/curl -s -k -q http://localhost:9200/${1}_index/_settings &2>/dev/null)
56+
echo $xxx|jq

config/config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,9 @@
5656
"naabu_dns": {},
5757
"naabu": {"TopPorts": "1000","ScanAllIPS": true},
5858
"nuclei": {},
59-
"httpx": {}
59+
"enablEmbedYaml": false,
60+
"httpx": {},
61+
"enableEsSv": true,
62+
"esthread": 8,
63+
"esUrl": "http://127.0.0.1:9200/"
6064
}

config/elasticsearch.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#集群名称
2+
cluster.name: my-application
3+
#节点名称
4+
node.name: node-1
5+
#数据和日志的存储目录
6+
path.data: /usr/share/elasticsearch/data
7+
path.logs: /usr/share/elasticsearch/logs
8+
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
9+
network.host: 0.0.0.0
10+
transport.host: 0.0.0.0
11+
network.publish_host: 192.168.0.107
12+
#端口
13+
http.port: 9200
14+
# 设置在集群中的所有节点名称,这个节点名称就是之前所修改的,当然你也可以采用默认的,目前是单机,放入一个节点即可
15+
discovery.seed_hosts: [ "192.168.0.112:9300","192.168.0.107:9301","192.168.0.107:9302", "192.168.0.107:9300"]
16+
cluster.initial_master_nodes: [ "192.168.0.112:9300","192.168.0.107:9301","192.168.0.107:9302", "192.168.0.107:9300"]
17+
cluster.routing.allocation.same_shard.host: true
18+
discovery.zen.fd.ping_timeout: 1m
19+
discovery.zen.fd.ping_retries: 5
20+
21+
# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
22+
# discovery.zen.minimum_master_nodes: 1
23+
# node.master: true
24+
# node.ingest: true
25+
# node.data: true
26+
27+
# cluster.routing.allocation.node_initial_primaries_recoveries: 8
28+
# cluster.routing.allocation.node_concurrent_recoveries: 2
29+
# discovery.zen.fd.ping_interval: 10s
30+
# discovery.zen.fd.ping_timeout: 120s
31+
# discovery.zen.fd.ping_retries: 6
32+
33+
# thread_pool.get.size: 16
34+
# # must be <= 5
35+
# thread_pool.write.size: 4
36+
# thread_pool.search.size: 8
37+
# thread_pool.get.queue_size: 8
38+
# thread_pool.write.queue_size: 4
39+
# thread_pool.search.queue_size: 4
40+
# thread_pool.listener.queue_size: 8
41+
# thread_pool.analyze.queue_size: 8
42+
# thread_pool.vectortile.queue_size: 4
43+
44+
45+
# threadpool.index.type: fixed
46+
# threadpool.index.size: 64
47+
# threadpool.index.queue_size: 1000
48+
# indices.memory.index_buffer_size: 20%
49+
50+
# threadpool.search.size: 64
51+
# threadpool.search.type: fixed
52+
# threadpool.search.queue_size: 1000
53+
# threadpool.get.type: fixed
54+
# threadpool.get.size: 32
55+
# threadpool.get.queue_size: 1000
56+
# threadpool.bulk.size: 32
57+
# threadpool.bulk.queue_size: 1000
58+
# threadpool.flush.type: fixed
59+
# threadpool.flush.size: 32
60+
# threadpool.flush.queue_size: 1000
61+
62+
# indices.store.throttle.max_bytes_per_sec: 100MB
63+
64+
65+
# index.analysis.analyzer.ik.type: "ik"
66+
# index.merge.scheduler.max_thread_count: 8
67+
# index.translog.flush_threshold_size: 200MB
68+
# index.translog.durability: async
69+
# index.translog.flush_threshold_ops: 500000
70+
71+
# node.max_local_storage_nodes: 2
72+
# discovery.zen.ping.unicast.hosts: ["192.168.0.100"]
73+
# discovery.zen.minimum_master_nodes: 1
74+
# discovery.zen.ping.multicast.enabled: false
75+
# discovery.zen.ping.multicast.group: 224.2.2.4
76+
# discovery.zen.ping.multicast.port : 54328
77+
# discovery.zen.ping.multicast.ttl: 3
78+
# discovery.zen.ping.multicast.address: 0.0.0.0
79+
# node.master: true
80+
# node.data: true
81+
# index.number_of_shards: 5
82+
# index.number_of_replicas: 2
83+
#indices.fielddata.cache.size: 50%
84+
#
85+
http.cors.enabled: true
86+
http.cors.allow-origin: "*"
87+
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
88+
http.cors.allow-headers : Authorization, X-Requested-With,X-Auth-Token,Content-Type, Content-Length
89+
90+
91+
transport.tcp.port: 9300
92+
# 设置节点之间交互的tcp端口,默认是9300。
93+
# transport.tcp.compress: true
94+
# 设置是否压缩tcp传输时的数据,默认为false,不压缩。
95+
96+
# reindex.remote.whitelist: "192.168.0.100:9300"
97+
98+
# https://docs.zammad.org/en/latest/install/elasticsearch.html#step-2-suggested-configuration
99+
# Performance may suffer if it is set too high.
100+
http.max_content_length: 400mb
101+
102+
# Allows the engine to generate larger (more complex) search queries.
103+
# Elasticsearch will raise an error or deprecation notice if this value is too low,
104+
# but setting it too high can overload system resources (Default: 1024).
105+
#
106+
# Available in version 6.6+ only.
107+
indices.query.bool.max_clause_count: 20000
108+
# indexing_pressure.memory.limit: 30
109+
cluster.routing.allocation.disk.threshold_enabled: false
110+
# 开启就无法启动
111+
# bootstrap.memory_lock: true

config/jvm.options

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
8-13:-XX:+UseConcMarkSweepGC
2+
8-13:-XX:CMSInitiatingOccupancyFraction=75
3+
8-13:-XX:+UseCMSInitiatingOccupancyOnly
4+
14-:-XX:+UseG1GC
5+
-Djava.io.tmpdir=${ES_TMPDIR}
6+
-XX:+HeapDumpOnOutOfMemoryError
7+
9-:-XX:+ExitOnOutOfMemoryError
8+
-XX:HeapDumpPath=data
9+
-XX:ErrorFile=logs/hs_err_pid%p.log
10+
8:-XX:+PrintGCDetails
11+
8:-XX:+PrintGCDateStamps
12+
8:-XX:+PrintTenuringDistribution
13+
8:-XX:+PrintGCApplicationStoppedTime
14+
8:-Xloggc:logs/gc.log
15+
8:-XX:+UseGCLogFileRotation
16+
8:-XX:NumberOfGCLogFiles=32
17+
8:-XX:GCLogFileSize=64m
18+
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
19+
20+
-Xms4g
21+
-Xmx4g

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"embed"
45
"github.com/hktalent/scan4all/pkg"
56
"github.com/hktalent/scan4all/pkg/hydra"
67
naaburunner "github.com/hktalent/scan4all/pkg/naabu/v2/pkg/runner"
@@ -9,6 +10,9 @@ import (
910
"runtime"
1011
)
1112

13+
//go:embed config/*
14+
var config embed.FS
15+
1216
func main() {
1317
defer func() {
1418
pkg.Cache1.Close()

nuclei_Yaml/nuclei_yaml.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ func RunNuclei(buf bytes.Buffer, xx chan bool) {
6868
}
6969
nucleiRunner.Close()
7070
}
71-
7271
func readConfig() {
7372
options.Targets = []string{}
7473
options.TargetsFilePath = ""
@@ -111,7 +110,12 @@ func readConfig() {
111110
options.FollowRedirects = false
112111
options.MaxRedirects = 10
113112
options.DisableRedirects = false
113+
114114
options.ReportingConfig = ""
115+
// 启动es记录
116+
if "true" == pkg.GetVal("enableEsSv") {
117+
options.ReportingConfig = "config/nuclei_esConfig.yaml"
118+
}
115119
options.CustomHeaders = []string{}
116120
options.Vars = goflags.RuntimeMap{}
117121
options.ResolversFile = ""
@@ -186,7 +190,7 @@ func readConfig() {
186190
// flagSet.BoolVarP(&options.FollowRedirects, "follow-redirects", "fr", false, "enable following redirects for http templates"),
187191
// flagSet.IntVarP(&options.MaxRedirects, "max-redirects", "mr", 10, "max number of redirects to follow for http templates"),
188192
// flagSet.BoolVarP(&options.DisableRedirects, "disable-redirects", "dr", false, "disable redirects for http templates"),
189-
// flagSet.StringVarP(&options.ReportingConfig, "report-config", "rc", "", "nuclei reporting module configuration file"), // TODO merge into the config file or rename to issue-tracking
193+
// flagSet.StringVarP(&options.ReportingConfigReportingConfig, "report-config", "rc", "", "nuclei reporting module configuration file"), // TODO merge into the config file or rename to issue-tracking
190194
// flagSet.FileStringSliceVarP(&options.CustomHeaders, "header", "H", []string{}, "custom header/cookie to include in all http request in header:value format (cli, file)"),
191195
// flagSet.RuntimeMapVarP(&options.Vars, "var", "V", []string{}, "custom vars in key=value format"),
192196
// flagSet.StringVarP(&options.ResolversFile, "resolvers", "r", "", "file containing resolver list for nuclei"),
@@ -289,8 +293,13 @@ func readConfig() {
289293
options.UpdateNuclei = false
290294
options.UpdateTemplates = false
291295
// 嵌入式集成私人版本nuclei-templates 共3744个YAML POC
292-
options.TemplatesDirectory = "config/nuclei-templates"
293-
options.NoUpdateTemplates = true
296+
if "true" == pkg.GetVal("enablEmbedYaml") {
297+
options.TemplatesDirectory = "config/nuclei-templates"
298+
options.NoUpdateTemplates = true
299+
} else {
300+
options.TemplatesDirectory = ""
301+
options.NoUpdateTemplates = false
302+
}
294303
options.EnableProgressBar = false
295304
options.StatsJSON = false
296305
options.StatsInterval = 5

pkg/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ func GetVal(key string) string {
3636
}
3737
return os.Getenv(key)
3838
}
39+
func GetValByDefault(key, dftvl string) string {
40+
s := GetVal(key)
41+
if "" == s {
42+
return dftvl
43+
}
44+
return s
45+
}
3946

4047
var (
4148
Naabu = "naabu"

pkg/domain.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func doAppends(a []string, s []string) []string {
3434
}
3535

3636
func doSub(s string) (aRst []string, err1 error) {
37+
bSend := false
3738
if "*." == s[:2] {
3839
EnableSubfinder := GetVal(EnableSubfinder)
3940
if "" != EnableSubfinder {
@@ -52,10 +53,14 @@ func doSub(s string) (aRst []string, err1 error) {
5253
}
5354
}
5455
}
56+
bSend = true
5557
} else {
5658
aRst = append(aRst, s[2:])
5759
}
5860
}
61+
if bSend {
62+
go SendAData[string](s[:2], aRst, "subfinder")
63+
}
5964
return aRst, nil
6065
}
6166

pkg/hydra/doNmapResult.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,38 @@ func DoParseXml(s string) {
3434
log.Println(err)
3535
return
3636
}
37+
var enableEsSv = pkg.GetVal("enableEsSv")
38+
m1 := make(map[string][][]string)
3739
for _, n := range xmlquery.Find(doc, "//host") {
3840
x1 := n.SelectElement("address").Attr[0].Value
3941
ps := n.SelectElements("ports/port")
4042
for _, x := range ps {
4143
if "open" == x.SelectElement("state").Attr[0].Value {
4244
ip := x1
43-
port, _ := strconv.Atoi(GetAttr(x.Attr, "portid"))
45+
szPort := GetAttr(x.Attr, "portid")
46+
port, _ := strconv.Atoi(szPort)
4447
service := GetAttr(x.SelectElement("service").Attr, "name")
4548
go CheckWeakPassword(ip, service, port)
4649
// 存储结果到其他地方
4750
//x9 := AuthInfo{IPAddr: ip, Port: port, Protocol: service}
51+
if "true" == enableEsSv {
52+
var xx09 = [][]string{}
53+
if a1, ok := m1[ip]; ok {
54+
xx09 = a1
55+
}
56+
m1[ip] = append(xx09, []string{szPort, service})
57+
}
4858
//fmt.Printf("%s\t%d\t%s\n", ip, port, service)
4959
}
5060
}
5161
}
62+
if "true" == enableEsSv {
63+
if 0 < len(m1) {
64+
for k, x := range m1 {
65+
pkg.SendAData[[]string](k, x, "nmap")
66+
}
67+
}
68+
}
5269
}
5370

5471
func DoNmapRst() {

0 commit comments

Comments
 (0)