mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-07-13 21:02:44 +08:00
feat: 增加Modbus扫描和测试环境
This commit is contained in:
parent
fa1d787c84
commit
94121a796f
@ -22,7 +22,7 @@ var pluginGroups = map[string][]string{
|
|||||||
"web", "fcgi", // web类
|
"web", "fcgi", // web类
|
||||||
"mysql", "mssql", "redis", "mongodb", "postgres", // 数据库类
|
"mysql", "mssql", "redis", "mongodb", "postgres", // 数据库类
|
||||||
"oracle", "memcached", "elasticsearch", "rabbitmq", "kafka", "activemq", // 数据库类
|
"oracle", "memcached", "elasticsearch", "rabbitmq", "kafka", "activemq", // 数据库类
|
||||||
"ftp", "ssh", "telnet", "smb", "rdp", "vnc", "netbios", "ldap", "smtp", "imap", "pop3", "snmp", "zabbix", // 服务类
|
"ftp", "ssh", "telnet", "smb", "rdp", "vnc", "netbios", "ldap", "smtp", "imap", "pop3", "snmp", "zabbix", "modbus", // 服务类
|
||||||
"ms17010", "smbghost", "smb2", // 漏洞类
|
"ms17010", "smbghost", "smb2", // 漏洞类
|
||||||
"findnet", // 其他
|
"findnet", // 其他
|
||||||
},
|
},
|
||||||
@ -37,7 +37,7 @@ var pluginGroups = map[string][]string{
|
|||||||
"web", "fcgi",
|
"web", "fcgi",
|
||||||
},
|
},
|
||||||
ModeService: {
|
ModeService: {
|
||||||
"ftp", "ssh", "telnet", "smb", "rdp", "vnc", "netbios", "ldap", "smtp", "imap", "pop3", "zabbix",
|
"ftp", "ssh", "telnet", "smb", "rdp", "vnc", "netbios", "ldap", "smtp", "imap", "pop3", "zabbix", "modbus",
|
||||||
},
|
},
|
||||||
ModeVul: {
|
ModeVul: {
|
||||||
"ms17010", "smbghost", "smb2",
|
"ms17010", "smbghost", "smb2",
|
||||||
|
@ -5,12 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ServicePorts = "21,22,23,25,110,135,139,143,161,162,389,445,465,587,636,993,995,1433,1521,2222,3306,3389,5432,5672,5671,6379,8161,8443,9000,9092,9093,9200,10051,11211,15672,15671,27017,61616,61613"
|
var ServicePorts = "21,22,23,25,110,135,139,143,161,162,389,445,465,502,587,636,993,995,1433,1521,2222,3306,3389,5020,5432,5672,5671,6379,8161,8443,9000,9092,9093,9200,10051,11211,15672,15671,27017,61616,61613"
|
||||||
var DbPorts = "1433,1521,3306,5432,5672,6379,9093,9200,11211,27017,61616"
|
var DbPorts = "1433,1521,3306,5432,5672,6379,9093,9200,11211,27017,61616"
|
||||||
var WebPorts = "80,81,82,83,84,85,86,87,88,89,90,91,92,98,99,443,800,801,808,880,888,889,1000,1010,1080,1081,1082,1099,1118,1888,2008,2020,2100,2375,2379,3000,3008,3128,3505,5555,6080,6648,6868,7000,7001,7002,7003,7004,7005,7007,7008,7070,7071,7074,7078,7080,7088,7200,7680,7687,7688,7777,7890,8000,8001,8002,8003,8004,8005,8006,8008,8009,8010,8011,8012,8016,8018,8020,8028,8030,8038,8042,8044,8046,8048,8053,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,8118,8161,8172,8180,8181,8200,8222,8244,8258,8280,8288,8300,8360,8443,8448,8484,8800,8834,8838,8848,8858,8868,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999,10000,10001,10002,10004,10008,10010,10051,10250,12018,12443,14000,15672,15671,16080,18000,18001,18002,18004,18008,18080,18082,18088,18090,18098,19001,20000,20720,20880,21000,21501,21502,28018"
|
var WebPorts = "80,81,82,83,84,85,86,87,88,89,90,91,92,98,99,443,800,801,808,880,888,889,1000,1010,1080,1081,1082,1099,1118,1888,2008,2020,2100,2375,2379,3000,3008,3128,3505,5555,6080,6648,6868,7000,7001,7002,7003,7004,7005,7007,7008,7070,7071,7074,7078,7080,7088,7200,7680,7687,7688,7777,7890,8000,8001,8002,8003,8004,8005,8006,8008,8009,8010,8011,8012,8016,8018,8020,8028,8030,8038,8042,8044,8046,8048,8053,8060,8069,8070,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8091,8092,8093,8094,8095,8096,8097,8098,8099,8100,8101,8108,8118,8161,8172,8180,8181,8200,8222,8244,8258,8280,8288,8300,8360,8443,8448,8484,8800,8834,8838,8848,8858,8868,8879,8880,8881,8888,8899,8983,8989,9000,9001,9002,9008,9010,9043,9060,9080,9081,9082,9083,9084,9085,9086,9087,9088,9089,9090,9091,9092,9093,9094,9095,9096,9097,9098,9099,9100,9200,9443,9448,9800,9981,9986,9988,9998,9999,10000,10001,10002,10004,10008,10010,10051,10250,12018,12443,14000,15672,15671,16080,18000,18001,18002,18004,18008,18080,18082,18088,18090,18098,19001,20000,20720,20880,21000,21501,21502,28018"
|
||||||
var UDPPorts = "161"
|
var UDPPorts = "161"
|
||||||
var AllPorts = "1-65535"
|
var AllPorts = "1-65535"
|
||||||
var MainPorts = "21,22,23,80,81,110,135,139,143,161,389,443,445,993,995,1433,1521,3306,5432,5672,6379,7001,8000,8005,8009,8080,8089,8443,9000,9200,9092,10051,11211,15672,27017,61616"
|
var MainPorts = "21,22,23,80,81,110,135,139,143,161,389,443,445,502,993,995,1433,1521,3306,5432,5672,6379,7001,8000,8005,8009,8080,8089,8443,9000,9200,9092,10051,11211,15672,27017,61616"
|
||||||
|
|
||||||
func ParsePortsFromString(portsStr string) []int {
|
func ParsePortsFromString(portsStr string) []int {
|
||||||
var ports []int
|
var ports []int
|
||||||
|
@ -121,6 +121,12 @@ func init() {
|
|||||||
ScanFunc: Plugins.ZabbixScan,
|
ScanFunc: Plugins.ZabbixScan,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Common.RegisterPlugin("modbus", Common.ScanPlugin{
|
||||||
|
Name: "Modbus",
|
||||||
|
Ports: []int{502, 5020}, // Modbus 默认端口
|
||||||
|
ScanFunc: Plugins.ModbusScan,
|
||||||
|
})
|
||||||
|
|
||||||
Common.RegisterPlugin("rdp", Common.ScanPlugin{
|
Common.RegisterPlugin("rdp", Common.ScanPlugin{
|
||||||
Name: "RDP",
|
Name: "RDP",
|
||||||
Ports: []int{3389},
|
Ports: []int{3389},
|
||||||
|
105
Plugins/Modbus.go
Normal file
105
Plugins/Modbus.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package Plugins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"github.com/shadow1ng/fscan/Common"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ModbusScan 执行 Modbus 服务扫描
|
||||||
|
func ModbusScan(info *Common.HostInfo) error {
|
||||||
|
host, port := info.Host, info.Ports
|
||||||
|
timeout := time.Duration(Common.Timeout) * time.Second
|
||||||
|
|
||||||
|
// 尝试建立连接
|
||||||
|
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", host, port), timeout)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// 构造Modbus TCP请求包 - 读取设备ID
|
||||||
|
request := buildModbusRequest()
|
||||||
|
|
||||||
|
// 设置读写超时
|
||||||
|
conn.SetDeadline(time.Now().Add(timeout))
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
_, err = conn.Write(request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("发送Modbus请求失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取响应
|
||||||
|
response := make([]byte, 256)
|
||||||
|
n, err := conn.Read(response)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("读取Modbus响应失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证响应
|
||||||
|
if isValidModbusResponse(response[:n]) {
|
||||||
|
result := fmt.Sprintf("[+] Modbus服务 %v:%v 无认证访问", host, port)
|
||||||
|
Common.LogSuccess(result)
|
||||||
|
|
||||||
|
// 尝试读取更多设备信息
|
||||||
|
deviceInfo := parseModbusResponse(response[:n])
|
||||||
|
if deviceInfo != "" {
|
||||||
|
Common.LogSuccess(fmt.Sprintf("[+] 设备信息: %s", deviceInfo))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("非Modbus服务或访问被拒绝")
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildModbusRequest 构建Modbus TCP请求包
|
||||||
|
func buildModbusRequest() []byte {
|
||||||
|
request := make([]byte, 12)
|
||||||
|
|
||||||
|
// Modbus TCP头部
|
||||||
|
binary.BigEndian.PutUint16(request[0:], 0x0001) // 事务标识符
|
||||||
|
binary.BigEndian.PutUint16(request[2:], 0x0000) // 协议标识符
|
||||||
|
binary.BigEndian.PutUint16(request[4:], 0x0006) // 长度
|
||||||
|
request[6] = 0x01 // 单元标识符
|
||||||
|
|
||||||
|
// Modbus 请求
|
||||||
|
request[7] = 0x01 // 功能码: Read Coils
|
||||||
|
binary.BigEndian.PutUint16(request[8:], 0x0000) // 起始地址
|
||||||
|
binary.BigEndian.PutUint16(request[10:], 0x0001) // 读取数量
|
||||||
|
|
||||||
|
return request
|
||||||
|
}
|
||||||
|
|
||||||
|
// isValidModbusResponse 验证Modbus响应是否有效
|
||||||
|
func isValidModbusResponse(response []byte) bool {
|
||||||
|
if len(response) < 9 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查协议标识符
|
||||||
|
protocolID := binary.BigEndian.Uint16(response[2:])
|
||||||
|
if protocolID != 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查功能码
|
||||||
|
funcCode := response[7]
|
||||||
|
if funcCode == 0x81 { // 错误响应
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseModbusResponse 解析Modbus响应获取设备信息
|
||||||
|
func parseModbusResponse(response []byte) string {
|
||||||
|
if len(response) < 9 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
unitID := response[6]
|
||||||
|
return fmt.Sprintf("Unit ID: %d", unitID)
|
||||||
|
}
|
1
TestDocker/Modbus/README.txt
Normal file
1
TestDocker/Modbus/README.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
docker run --rm -p 5020:5020 oitc/modbus-server:latest
|
Loading…
Reference in New Issue
Block a user