-
Notifications
You must be signed in to change notification settings - Fork 324
/
mongoWeakPass.go
86 lines (83 loc) · 2.02 KB
/
mongoWeakPass.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package goplugin
import (
"fmt"
. "github.com/opensec-cn/kunpeng/config"
"github.com/opensec-cn/kunpeng/plugin"
"gopkg.in/mgo.v2"
"strings"
"time"
)
type mongoWeakPass struct {
info plugin.Plugin
result []plugin.Plugin
}
func init() {
plugin.Regist("mongodb", &mongoWeakPass{})
}
func (d *mongoWeakPass) Init() plugin.Plugin {
d.info = plugin.Plugin{
Name: "MongoDB 未授权访问/弱口令",
Remarks: "导致数据库敏感信息泄露,严重可导致服务器直接被入侵控制。",
Level: 1,
Type: "WEAKPWD",
Author: "wolf",
References: plugin.References{
KPID: "KP-0007",
},
}
return d.info
}
func (d *mongoWeakPass) GetResult() []plugin.Plugin {
var result = d.result
d.result = []plugin.Plugin{}
return result
}
func (d *mongoWeakPass) Check(netloc string, meta plugin.TaskMeta) (b bool) {
if strings.IndexAny(netloc, "http") == 0 {
return
}
userList := []string{
"admin",
}
session, err := mgo.Dial(netloc)
if err == nil && session.Run("serverStatus", nil) == nil {
result := d.info
result.Request = fmt.Sprintf("mgo://%s/admin", netloc)
result.Remarks = "未授权访问," + result.Remarks
d.result = append(d.result, result)
return true
}
for _, user := range userList {
for _, pass := range meta.PassList {
pass = strings.Replace(pass, "{user}", user, -1)
dialInfo := &mgo.DialInfo{
Addrs: []string{netloc},
Direct: false,
Timeout: time.Second * time.Duration(Config.Timeout),
Database: "admin",
Source: "admin",
Username: user,
Password: pass,
PoolLimit: 4096,
}
session, err := mgo.DialWithInfo(dialInfo)
if err != nil {
return
}
res, err := session.DatabaseNames()
if err != nil {
return
}
if res != nil {
session.Close()
result := d.info
result.Request = fmt.Sprintf("mgo://%s:%s@%s/admin", user, pass, netloc)
result.Remarks = fmt.Sprintf("弱口令:%s,%s,%s", user, pass, result.Remarks)
d.result = append(d.result, result)
b = true
break
}
}
}
return b
}