Skip to content

Commit 50f1e90

Browse files
committed
新增了对snmp服务弱口令的扫描
1 parent 550ce79 commit 50f1e90

File tree

7 files changed

+112
-7
lines changed

7 files changed

+112
-7
lines changed

iplist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
127.0.0.1:3306|mysql
22
8.8.8.8:2222|ssh
33
9.9.9.9:6379
4+
127.0.0.1:161

plugins/plugins.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ func init() {
4545
ScanFuncMap["REDIS"] = ScanRedis
4646
ScanFuncMap["ELASTICSEARCH"] = ScanElastic
4747
ScanFuncMap["MONGODB"] = ScanMongodb
48+
ScanFuncMap["SNMP"] = ScanSNMP
4849
}

plugins/snmp.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
3+
Copyright (c) 2018 sec.lu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEq
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
package plugins
26+
27+
import (
28+
"github.com/soniah/gosnmp"
29+
30+
"x-crack/models"
31+
"x-crack/vars"
32+
)
33+
34+
func ScanSNMP(s models.Service) (err error, result models.ScanResult) {
35+
result.Service = s
36+
result.Service.Username = "public"
37+
result.Service.Password = "public"
38+
gosnmp.Default.Target = s.Ip
39+
gosnmp.Default.Port = uint16(s.Port)
40+
gosnmp.Default.Community = result.Service.Password
41+
gosnmp.Default.Timeout = vars.TimeOut
42+
43+
err = gosnmp.Default.Connect()
44+
if err == nil {
45+
oids := []string{"1.3.6.1.2.1.1.4.0", "1.3.6.1.2.1.1.7.0"}
46+
_, err := gosnmp.Default.Get(oids)
47+
if err == nil {
48+
result.Result = true
49+
}
50+
}
51+
52+
return err, result
53+
}

plugins/snmp_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
3+
Copyright (c) 2018 sec.lu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEq
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
*/
24+
25+
package plugins_test
26+
27+
import (
28+
"x-crack/models"
29+
"x-crack/plugins"
30+
31+
"testing"
32+
)
33+
34+
func TestScanSNMP(t *testing.T) {
35+
s := models.Service{Ip: "127.0.0.1", Port: 161, Username: "public", Password: "123456", Protocol: "snmp"}
36+
t.Log(plugins.ScanSNMP(s))
37+
}

util/task.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ func DistributionTask(tasks []models.Service) () {
6565
vars.ProgressBar.SetTemplate(`{{ rndcolor "Scanning progress: " }} {{ percent . "[%.02f%%]" "[?]"| rndcolor}} {{ counters . "[%s/%s]" "[%s/?]" | rndcolor}} {{ bar . "「" "-" (rnd "ᗧ" "◔" "◕" "◷" ) "•" "」" | rndcolor }} {{rtime . | rndcolor}} `)
6666

6767
for i := 0; i < scanBatch; i++ {
68-
curTasks := tasks[vars.ScanNum*i:vars.ScanNum*(i+1)]
68+
curTasks := tasks[vars.ScanNum*i : vars.ScanNum*(i+1)]
6969
ExecuteTask(curTasks)
7070
}
7171

7272
if totalTask%vars.ScanNum > 0 {
73-
lastTask := tasks[vars.ScanNum*scanBatch:totalTask]
73+
lastTask := tasks[vars.ScanNum*scanBatch : totalTask]
7474
ExecuteTask(lastTask)
7575
}
7676

@@ -91,7 +91,7 @@ func ExecuteTask(tasks []models.Service) () {
9191
var k string
9292
protocol := strings.ToUpper(task.Protocol)
9393

94-
if protocol == "REDIS" || protocol == "FTP" {
94+
if protocol == "REDIS" || protocol == "FTP" || protocol == "SNMP" {
9595
k = fmt.Sprintf("%v-%v-%v", task.Ip, task.Port, task.Protocol)
9696
} else {
9797
k = fmt.Sprintf("%v-%v-%v", task.Ip, task.Port, task.Username)

util/util.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"x-crack/logger"
3232
"x-crack/vars"
3333

34-
"net"
3534
"sync"
35+
"net"
3636
"fmt"
3737
)
3838

@@ -67,10 +67,18 @@ func CheckAlive(ipList []models.IpAddr) ([]models.IpAddr) {
6767

6868
func check(ipAddr models.IpAddr) (bool, models.IpAddr) {
6969
alive := false
70-
_, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%v", ipAddr.Ip, ipAddr.Port), vars.TimeOut)
71-
if err == nil {
72-
alive = true
70+
if vars.UdpProtocols[ipAddr.Protocol] {
71+
_, err := net.DialTimeout("udp", fmt.Sprintf("%v:%v", ipAddr.Ip, ipAddr.Port), vars.TimeOut)
72+
if err == nil {
73+
alive = true
74+
}
75+
} else {
76+
_, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%v", ipAddr.Ip, ipAddr.Port), vars.TimeOut)
77+
if err == nil {
78+
alive = true
79+
}
7380
}
81+
7482
vars.ProcessBarActive.Increment()
7583
return alive, ipAddr
7684
}

vars/vars.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var (
5959
PortNames = map[int]string{
6060
21: "FTP",
6161
22: "SSH",
62+
161: "SNMP",
6263
445: "SMB",
6364
1433: "MSSQL",
6465
3306: "MYSQL",
@@ -68,6 +69,10 @@ var (
6869
27017: "MONGODB",
6970
}
7071

72+
UdpProtocols = map[string]bool{
73+
"SNMP": true,
74+
}
75+
7176
// 标记特定服务的特定用户是否破解成功,成功的话不再尝试破解该用户
7277
SuccessHash map[string]bool
7378

0 commit comments

Comments
 (0)