ing
This commit is contained in:
66
matcher/ssh/ssh.go
Normal file
66
matcher/ssh/ssh.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"git.loafle.net/overflow/overflow_discovery/match/packet"
|
||||
"git.loafle.net/overflow/overflow_discovery/model/scaninfo"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SSHMatcher struct {
|
||||
sendPackets []*packet.Packet
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) Match(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
|
||||
result := false
|
||||
|
||||
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
str := string(packet.Buffer)
|
||||
|
||||
//fmt.Println(str)
|
||||
temps := strings.Split(str, " ")
|
||||
protocol := strings.Split(temps[0], "-")
|
||||
//osType := temps[1]
|
||||
|
||||
if 0 == strings.Compare(protocol[0], "SSH") {
|
||||
majorVersion := protocol[1]
|
||||
//fmt.Println(majorVersion)
|
||||
if 0 == strings.Compare(majorVersion, "2.0") || 0 == strings.Compare(majorVersion, "1.0") {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) PacketCount() int {
|
||||
return len(ssh.sendPackets)
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) Packet(index int) *packet.Packet {
|
||||
return ssh.sendPackets[index]
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) ServiceName() string {
|
||||
return "SSH"
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) IsError(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) HasResponse(index int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ssh *SSHMatcher) IsPrePacket() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func NewSSHMatcher() *SSHMatcher {
|
||||
r := SSHMatcher{}
|
||||
|
||||
return &r
|
||||
}
|
||||
35
matcher/ssh/ssh_test.go
Normal file
35
matcher/ssh/ssh_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//"git.loafle.net/overflow/overflow_discovery/match/ssh"
|
||||
"git.loafle.net/overflow/overflow_discovery/match/packet"
|
||||
//"git.loafle.net/overflow/overflow_discovery/collector/discovery/types"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
)
|
||||
|
||||
func TestSSHMatcher_Match(t *testing.T) {
|
||||
|
||||
//port := types.NewPort("22", types.NewHost("192.168.1.103"), types.TYPE_TCP)
|
||||
//ssh := NewSSHMatcher()
|
||||
//
|
||||
//var ipport string
|
||||
//ipport = port.Host.Ip + ":" + string(port.Port)
|
||||
|
||||
client, _ := net.Dial("tcp", "192.168.1.10:22")
|
||||
|
||||
defer client.Close()
|
||||
|
||||
bytes := make([]byte, 512)
|
||||
|
||||
l, _ := client.Read(bytes)
|
||||
|
||||
fmt.Println(bytes)
|
||||
|
||||
b := NewSSHMatcher().Match(0, packet.NewPacket(bytes, l), nil)
|
||||
|
||||
fmt.Println(b)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user