From 2e81139374c24db03d6f7d9f4a07a1b5e89dbc6e Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 22 Nov 2017 14:55:40 +0900 Subject: [PATCH] ing --- api/module/discovery/model/discovery.go | 5 + api/module/discovery/model/zone.go | 24 ++ commons/pcap/packet.go | 1 - discovery/discovery.go | 1 + discovery/ipv4/host.go | 5 +- discovery/ipv4/port_tcp.go | 24 +- discovery/ipv4/port_udp.go | 144 +++++------ .../activedirectory/activedirectory_test.go | 79 ------ .../service/match/cassandra/cassandra_test.go | 73 ------ discovery/service/match/dns/dns_test.go | 33 --- discovery/service/match/ftp/ftp_test.go | 234 ------------------ discovery/service/match/http/http_test.go | 49 ---- discovery/service/match/http/https_test.go | 55 ---- discovery/service/match/imap/imap_test.go | 153 ------------ .../service/match/mongodb/mongodb_test.go | 54 ---- discovery/service/match/mssql/mssql_test.go | 63 ----- discovery/service/match/mysql/mysql_test.go | 71 ------ .../service/match/netbios/netbios_test.go | 34 --- discovery/service/match/oracle/oracle_test.go | 53 ---- discovery/service/match/pgsql/pgsql_test.go | 70 ------ discovery/service/match/pop/pop_test.go | 86 ------- .../match/redis/redisProtected_test.go | 33 --- discovery/service/match/redis/redis_test.go | 37 --- discovery/service/match/rmi/rmi_test.go | 52 ---- discovery/service/match/smb/smb_test.go | 42 ---- discovery/service/match/snmp/snmpv2_test.go | 37 --- discovery/service/match/snmp/snmpv3_test.go | 37 --- discovery/service/match/ssh/ssh_test.go | 35 --- discovery/service/match/telnet/telnet_test.go | 33 --- discovery/service/match/wmi/wmi_test.go | 51 ---- service/matcher/dns/dns.go | 4 +- service/matcher/matcher.go | 2 +- service/matcher/snmp/v2/snmpv2.go | 4 +- service/matcher/snmp/v3/snmpv3.go | 4 +- service/service.go | 2 +- 35 files changed, 117 insertions(+), 1567 deletions(-) delete mode 100644 discovery/service/match/activedirectory/activedirectory_test.go delete mode 100644 discovery/service/match/cassandra/cassandra_test.go delete mode 100644 discovery/service/match/dns/dns_test.go delete mode 100644 discovery/service/match/ftp/ftp_test.go delete mode 100644 discovery/service/match/http/http_test.go delete mode 100644 discovery/service/match/http/https_test.go delete mode 100644 discovery/service/match/imap/imap_test.go delete mode 100644 discovery/service/match/mongodb/mongodb_test.go delete mode 100644 discovery/service/match/mssql/mssql_test.go delete mode 100644 discovery/service/match/mysql/mysql_test.go delete mode 100644 discovery/service/match/netbios/netbios_test.go delete mode 100644 discovery/service/match/oracle/oracle_test.go delete mode 100644 discovery/service/match/pgsql/pgsql_test.go delete mode 100644 discovery/service/match/pop/pop_test.go delete mode 100644 discovery/service/match/redis/redisProtected_test.go delete mode 100644 discovery/service/match/redis/redis_test.go delete mode 100644 discovery/service/match/rmi/rmi_test.go delete mode 100644 discovery/service/match/smb/smb_test.go delete mode 100644 discovery/service/match/snmp/snmpv2_test.go delete mode 100644 discovery/service/match/snmp/snmpv3_test.go delete mode 100644 discovery/service/match/ssh/ssh_test.go delete mode 100644 discovery/service/match/telnet/telnet_test.go delete mode 100644 discovery/service/match/wmi/wmi_test.go diff --git a/api/module/discovery/model/discovery.go b/api/module/discovery/model/discovery.go index dcb69fa..810305d 100644 --- a/api/module/discovery/model/discovery.go +++ b/api/module/discovery/model/discovery.go @@ -10,10 +10,15 @@ type DiscoveryHost struct { FirstScanRange string `json:"firstScanRange"` LastScanRange string `json:"lastScanRange"` ExcludeHosts []string `json:"excludeHosts"` + IncludeHosts []string `json:"includeHosts"` DiscoveryPort *DiscoveryPort `json:"discoveryPort"` } +func (dh *DiscoveryHost) Contains(ip string) bool { + +} + type DiscoveryPort struct { FirstScanRange int `json:"firstScanRange"` LastScanRange int `json:"lastScanRange"` diff --git a/api/module/discovery/model/zone.go b/api/module/discovery/model/zone.go index 1cabc98..ae41803 100644 --- a/api/module/discovery/model/zone.go +++ b/api/module/discovery/model/zone.go @@ -1,9 +1,33 @@ package model +import "sync" + type Zone struct { ID int `json:"id,omitempty"` Network string `json:"network"` IP string `json:"ip"` Iface string `json:"iface"` Mac string `json:"mac"` + + hosts map[string]*Host + mtx sync.RWMutex +} + +func (z *Zone) AddHost(h *Host) { + z.mtx.Lock() + defer z.mtx.Unlock() + if nil == z.hosts { + z.hosts = make(map[string]*Host) + } + z.hosts[h.IP] = h +} + +func (z *Zone) GetHost(ip string) *Host { + z.mtx.RLock() + defer z.mtx.RUnlock() + + if nil == z.hosts { + return nil + } + return z.hosts[ip] } diff --git a/commons/pcap/packet.go b/commons/pcap/packet.go index 343c0e9..03d7675 100644 --- a/commons/pcap/packet.go +++ b/commons/pcap/packet.go @@ -99,7 +99,6 @@ func handlePacketUDP(ps *pCapScan, packet gopacket.Packet) { chs, ok := ps.udpListenerChans[ip] if ok { - for _, ch := range chs { ch <- packet } diff --git a/discovery/discovery.go b/discovery/discovery.go index 7ef4c99..3c1ef01 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -100,6 +100,7 @@ func (d *discovery) discoverHost(zone *model.Zone, dh *model.DiscoveryHost) { }, func(result interface{}) { h := result.(*model.Host) + zone.AddHost(h) logging.Logger().Info(fmt.Sprintf("host: %v", h)) if nil != dh.DiscoveryPort { d.discoverPort(h, dh.DiscoveryPort) diff --git a/discovery/ipv4/host.go b/discovery/ipv4/host.go index 4453ee3..a0f896f 100644 --- a/discovery/ipv4/host.go +++ b/discovery/ipv4/host.go @@ -99,13 +99,14 @@ func sendARP(ps pcap.PCapScanner, zone *model.Zone, hostRanges []net.IP, stopCha return err } + timer := time.NewTimer(time.Microsecond * 100) + select { case <-stopChan: return nil - default: + case <-timer.C: } - time.Sleep(time.Microsecond * 100) } return nil } diff --git a/discovery/ipv4/port_tcp.go b/discovery/ipv4/port_tcp.go index d65c3af..83e8e40 100644 --- a/discovery/ipv4/port_tcp.go +++ b/discovery/ipv4/port_tcp.go @@ -33,6 +33,8 @@ func scanPortTCP(host *model.Host, dp *model.DiscoveryPort, resultChan chan inte }() go func() { + ports := make(map[int]*model.Port) + for { select { case packet, ok := <-tcpChan: @@ -40,7 +42,7 @@ func scanPortTCP(host *model.Host, dp *model.DiscoveryPort, resultChan chan inte logging.Logger().Debug(fmt.Sprintf("Discovery: tcp channel is closed")) return } - if p := handlePacketTCP(host, packet); nil != p { + if p := handlePacketTCP(host, ports, packet); nil != p { resultChan <- p } case <-stopChan: @@ -94,20 +96,19 @@ Loop: return err } + timer := time.NewTimer(time.Microsecond * 100) + select { case <-stopChan: return nil - default: + case <-timer.C: } - - time.Sleep(time.Microsecond * 100) - } return nil } -func handlePacketTCP(host *model.Host, packet *layers.TCP) *model.Port { +func handlePacketTCP(host *model.Host, ports map[int]*model.Port, packet *layers.TCP) *model.Port { if nil == packet || packet.DstPort != 60000 { return nil } @@ -117,6 +118,17 @@ func handlePacketTCP(host *model.Host, packet *layers.TCP) *model.Port { } portNumber := int(packet.SrcPort) + + if _, ok := ports[portNumber]; ok || !cr.Contains(ip) { + return nil + } + h := &model.Host{} + h.IP = ip.String() + h.Mac = net.HardwareAddr(packet.SourceHwAddress).String() + h.Zone = zone + + hosts[ip.String()] = h + p := &model.Port{ PortType: model.PortTypeTCP, PortNumber: portNumber, diff --git a/discovery/ipv4/port_udp.go b/discovery/ipv4/port_udp.go index b6a9600..4bfc9b8 100644 --- a/discovery/ipv4/port_udp.go +++ b/discovery/ipv4/port_udp.go @@ -9,6 +9,7 @@ import ( "git.loafle.net/commons_go/logging" "git.loafle.net/overflow/overflow_discovery/api/module/discovery/model" "git.loafle.net/overflow/overflow_discovery/commons/pcap" + "git.loafle.net/overflow/overflow_discovery/service" "github.com/google/gopacket" "github.com/google/gopacket/layers" ) @@ -37,7 +38,7 @@ func scanPortUDP(host *model.Host, dp *model.DiscoveryPort, resultChan chan inte select { case packet, ok := <-udpChan: if !ok { - logging.Logger().Debug(fmt.Sprintf("Discovery: tcp channel is closed")) + logging.Logger().Debug(fmt.Sprintf("Discovery: udp channel is closed")) return } if p := handlePacketUDP(host, packet); nil != p { @@ -65,110 +66,81 @@ func scanPortUDP(host *model.Host, dp *model.DiscoveryPort, resultChan chan inte } func sendUDP(host *model.Host, dp *model.DiscoveryPort, stopChan chan struct{}) error { - tcpPacket, err := makePacketPortTCP(host) - if nil != err { + ip := net.ParseIP(host.IP) + if nil == ip { + return fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP) + } + + ms := service.GetUDPMatchers() + + conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0}) + if err != nil { return err } defer func() { - tcpPacket.PacketConn.Close() + conn.Close() }() - buf := gopacket.NewSerializeBuffer() + for indexI := 0; indexI < len(ms); indexI++ { + m := ms[indexI] -Loop: - for portNumber := dp.FirstScanRange; portNumber < dp.LastScanRange; portNumber++ { - if nil != dp.ExcludePorts { - for _, exPortNumber := range dp.ExcludePorts { - if portNumber == exPortNumber { - continue Loop + Loop: + for portNumber := dp.FirstScanRange; portNumber < dp.LastScanRange; portNumber++ { + if nil != dp.ExcludePorts { + for _, exPortNumber := range dp.ExcludePorts { + if portNumber == exPortNumber { + continue Loop + } } } - } - tcpPacket.TCP.DstPort = layers.TCPPort(portNumber) - tcpPacket.TCP.SetNetworkLayerForChecksum(tcpPacket.IP) - if err := gopacket.SerializeLayers(buf, tcpPacket.Opts, tcpPacket.TCP); err != nil { - return err - } - if _, err := tcpPacket.PacketConn.WriteTo(buf.Bytes(), &net.IPAddr{IP: tcpPacket.IP.DstIP}); err != nil { - return err - } + if !m.IsSend(portNumber) { + continue + } - select { - case <-stopChan: - return nil - default: + addr := &net.UDPAddr{IP: ip.To4(), Port: portNumber} + for i := 0; i < m.PacketCount(); i++ { + p := m.Packet(i) + if _, err := conn.WriteToUDP(p.Buffer, addr); err != nil { + logging.Logger().Error(fmt.Sprintf("Discovery: UDP write error %v", err)) + } + } + + timer := time.NewTimer(time.Microsecond * 200) + + select { + case <-stopChan: + return nil + case <-timer.C: + } } - - time.Sleep(time.Microsecond * 100) - } return nil } -func handlePacketUDP(host *model.Host, packet *layers.TCP) *model.Port { - if nil == packet || packet.DstPort != 60000 { +func handlePacketUDP(host *model.Host, packet gopacket.Packet) *model.Port { + ipLayer := packet.Layer(layers.LayerTypeIPv4) + + if ipLayer.(*layers.IPv4).SrcIP.String() == host.Zone.IP { return nil } - if packet.RST { - return nil + if net := packet.NetworkLayer(); net == nil { + } else if udpLayer := packet.Layer(layers.LayerTypeUDP); udpLayer == nil { + } else if udp, ok := udpLayer.(*layers.UDP); ok { + + srcIP := ipLayer.(*layers.IPv4).SrcIP + port := int(udp.SrcPort) + logging.Logger().Debug(fmt.Sprintf("Discovery: IP of UPD(%d) src %v", port, srcIP)) + + p := &model.Port{ + PortType: model.PortTypeUDP, + PortNumber: port, + } + p.Host = host + return p } - portNumber := int(packet.SrcPort) - p := &model.Port{ - PortType: model.PortTypeTCP, - PortNumber: portNumber, - } - p.Host = host - - return p -} - -type PortPacketTCP struct { - IP *layers.IPv4 - TCP *layers.TCP - Opts gopacket.SerializeOptions - PacketConn net.PacketConn -} - -func makePacketPortTCP(host *model.Host) (*PortPacketTCP, error) { - packetTCP := &PortPacketTCP{} - - srcIP := net.ParseIP(host.Zone.IP) - if nil == srcIP { - return nil, fmt.Errorf("Discovery: IP(%s) of zone is not valid", host.Zone.IP) - } - dstIP := net.ParseIP(host.IP) - if nil == dstIP { - return nil, fmt.Errorf("Discovery: IP(%s) of host is not valid", host.IP) - } - - packetTCP.IP = &layers.IPv4{ - SrcIP: srcIP.To4(), - DstIP: dstIP.To4(), - Version: 4, - TTL: 64, - Protocol: layers.IPProtocolTCP, - } - packetTCP.TCP = &layers.TCP{ - SrcPort: 60000, - DstPort: 0, // will be incremented during the scan - SYN: true, - Seq: 0, - } - packetTCP.Opts = gopacket.SerializeOptions{ - ComputeChecksums: true, - FixLengths: true, - } - - conn, err := net.ListenPacket("ip4:tcp", "0.0.0.0") - if err != nil { - return nil, fmt.Errorf("Discovery: SYN create socket error %v", err) - } - - packetTCP.PacketConn = conn - - return packetTCP, nil + return nil } diff --git a/discovery/service/match/activedirectory/activedirectory_test.go b/discovery/service/match/activedirectory/activedirectory_test.go deleted file mode 100644 index 083b546..0000000 --- a/discovery/service/match/activedirectory/activedirectory_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package activedirectory - -import ( - "crypto/tls" - "net" - "testing" - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" -) - -func TestADNor(t *testing.T) { - client, err := net.Dial("tcp", "192.168.1.15:389") - - if err != nil { - t.Log(err) - } - - defer client.Close() - - dDRun(client, t) -} - -func TestADTLS(t *testing.T) { - conn, err := tls.Dial( - "tcp", - "192.168.1.1:636", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.1", - }, - ) - - if err != nil { - t.Log(err) - return - } - - defer conn.Close() - - dDRun(conn, t) -} - -func dDRun(client net.Conn, t *testing.T) { - - lm := NewActiveDirectoryMatcher() - - //port := types.NewPort("389", types.NewHost("192.168.1.1"), types.TYPE_TCP) - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - // - //fmt.Println(ipport) - // - //fmt.Println(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - fmt.Println(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - read, _ := client.Read(bytes) - - fmt.Println(bytes) - - b := lm.Match(ii, matcher.NewPacket(bytes, read), nil) - - if b { - fmt.Println("Good") - } - - } - - -} diff --git a/discovery/service/match/cassandra/cassandra_test.go b/discovery/service/match/cassandra/cassandra_test.go deleted file mode 100644 index 7f71306..0000000 --- a/discovery/service/match/cassandra/cassandra_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package cassandra - -import ( - "crypto/tls" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestCassandra(t *testing.T) { - - m := NewCassandraMatcher() - - conn, err := net.Dial("tcp", "192.168.1.16:19042") - if err != nil { - t.Error(err) - return - } - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("Cassandra found") - return - } - - t.Error("Cassandra not found") - } - -} - -func TestCassandraTLS(t *testing.T) { - - m := NewCassandraMatcher() - - conn, err := tls.Dial( - "tcp", - "192.168.1.16:19042", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.16", - }, - ) - if err != nil { - t.Fatal(err) - } - - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("Cassandra found") - return - } - - t.Error("Cassandra not found") - } - -} diff --git a/discovery/service/match/dns/dns_test.go b/discovery/service/match/dns/dns_test.go deleted file mode 100644 index 0e869b0..0000000 --- a/discovery/service/match/dns/dns_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package dns - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestDns(t *testing.T) { - m := NewDnsMatcher() - - conn, _ := net.Dial("udp", "168.126.63.1:53") - - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - if m.IsSend(53) != true { - t.Error("not port") - } - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("dns found") - return - } - - t.Error("dns not found") - } -} diff --git a/discovery/service/match/ftp/ftp_test.go b/discovery/service/match/ftp/ftp_test.go deleted file mode 100644 index 9a28a00..0000000 --- a/discovery/service/match/ftp/ftp_test.go +++ /dev/null @@ -1,234 +0,0 @@ -package ftp - -import ( - "fmt" - "testing" - "git.loafle.net/overflow/overflow_discovery/model/scaninfo" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - - "net" -) - -//type FTP struct { -// conn net.Conn -// addr string -// -// reader *bufio.Reader -// writer *bufio.Writer -//} -// -//func (ftp *FTP) Close() { -// ftp.conn.Close() -//} -// -//func Connect(addr string) (*FTP, error) { -// var err error -// var conn net.Conn -// -// if conn, err = net.Dial("tcp", addr); err != nil { -// return nil, err -// } -// -// writer := bufio.NewWriter(conn) -// reader := bufio.NewReader(conn) -// -// obj := &FTP{ -// conn:conn, -// addr:addr, -// reader:reader, -// writer:writer, -// } -// recv, _ := obj.receive() -// -// fmt.Println(recv) -// -// return obj, nil -// -//} -// -//func (ftp *FTP) receive() (string, error) { -// line, err := ftp.receiveLine() -// -// if err != nil { -// return line, err -// } -// -// fmt.Println("len : ", len(line)) -// fmt.Println("line[3] :", line[3]) -// // -// //if (len(line) >= 4) && (line[3] == '-') { -// // closingCode := line[:3] + " " -// // -// // for { -// // str, err := ftp.receiveLine() -// // fmt.Println("str pre: ", str) -// // line = line + str -// // fmt.Println("str after: ", line) -// // if err != nil { -// // return line, err -// // } -// // -// // if len(str) < 4 { -// // fmt.Println("Uncorrectly terminated response") -// // }else { -// // if str[:4] == closingCode { -// // break -// // } -// // } -// // } -// //} -// -// ftp.ReadAndDiscard() -// -// fmt.Println("receive line: ", line) -// return line, err -//} -// -//func (ftp *FTP) ReadAndDiscard() (int, error) { -// var i int -// bufferSize := ftp.reader.Buffered() -// -// for i = 0; i < bufferSize ; i++ { -// if _, err := ftp.reader.ReadByte(); err != nil { -// return i, err -// } -// } -// -// return i, nil -//} -// -//func (ftp *FTP) send(command string, arguments ...interface{}) error { -// -// command = fmt.Sprintf(command) -// command += "\r\n" -// -// if _, err := ftp.writer.WriteString(command); err != nil { -// return err -// } -// -// if err := ftp.writer.Flush(); err != nil { -// return err -// } -// -// return nil -//} -// -//func (ftp *FTP) cmd(expects string, command string, args ...interface{}) (line string, err error) { -// -// if err = ftp.send(command, args); err != nil { -// return -// } -// -// if line, err = ftp.receive(); err != nil { -// return -// } -// -// -// if !strings.HasPrefix(line, expects) { -// err = errors.New(line) -// return -// } -// -// return -//} -// -//func (ftp *FTP) receiveLine() (string, error) { -// line, err := ftp.reader.ReadString('\n') -// -// log.Printf("< %s", line) -// -// return line, err -//} -// -//func (ftp *FTP) Syst() (line string, err error) { -// if err := ftp.send("SYST"); err != nil { -// return "", err -// } -// -// if line, err = ftp.receive(); err != nil { -// return -// } -// -// if !strings.HasPrefix(line, "215") { -// err = errors.New(line) -// return -// } -// -// return strings.SplitN(strings.TrimSpace(line), " ", 2)[1], nil -//} - -//func TestFtp(t *testing.T) { -// var err error -// var ftp *FTP -// //var f *FTPMatcher -// -// if ftp, err = Connect("192.168.1.202:21"); err != nil { -// panic(err) -// } -// -// //f.Match(0, nil,nil) -// ftp.Syst() -// ftp.cmd("503","PASS ") -// ftp.cmd("221","QUIT") -// defer ftp.Close() -//} - -func TestMatchFTP(t *testing.T) { - ftm := NewFTPMatcher() - //fmt.Println(ftm) - //fmt.Println(ftm.sendPackets[0]) - - //log.LoadLogConfig("../../../../../../../../bin/log.xml") - //defer log.Flush() - - //port := types.NewPort("21", types.NewHost("192.168.1.202"), types.TYPE_TCP) - - info := scaninfo.NewScanInfoImpl("192.168.1.15","21") - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - // - //log.Debug(ipport) - - client, _ := net.Dial("tcp", "192.168.1.15:21") - - defer client.Close() - - //reader := bufio.NewReader(client) - //writer := bufio.NewWriter(client) - - fmt.Println(ftm.PacketCount()) - //fmt.Println(reader.ReadString('\n')) - - bytes := make([]byte, 512) - - le, _ := client.Read(bytes) - - fmt.Println(bytes) - - b := ftm.Match(0, matcher.NewPacket(bytes, le), nil) - - fmt.Println(b) - - for ii := 0; ii < ftm.PacketCount(); ii++ { - pack := ftm.Packet(ii) - - fmt.Println(pack) - - //writer.WriteString(pack) - client.Write(pack.Buffer) - //fmt.Println(reader.ReadString('\n')) - bytes := make([]byte, 512) - - l, _ := client.Read(bytes) - - //fmt.Println(bytes) - - b := ftm.Match(ii+1, matcher.NewPacket(bytes, l), info) - - fmt.Println(b) - - } - - fmt.Println("Service Name : ", ftm.ServiceName()) -} diff --git a/discovery/service/match/http/http_test.go b/discovery/service/match/http/http_test.go deleted file mode 100644 index dc3ddd0..0000000 --- a/discovery/service/match/http/http_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package http - -import ( - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - //"git.loafle.net/overflow/overflow_discovery/discovery/discovery/types" - "net" - "testing" -) - -func TestHTTPMatcher_Packet(t *testing.T) { - hm := NewHTTPMatcher() - fmt.Println(hm) - fmt.Println(hm.sendPackets[0]) - -} - -func TestHTTPMatcher_Match(t *testing.T) { - fmt.Println("Match") - - hm := NewHTTPMatcher() - - //port := types.NewPort("80", types.NewHost("192.168.1.103"), types.TYPE_TCP) - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - //fmt.Println(ipport) - - client, _ := net.Dial("tcp", "192.168.1.15:38980") - - defer client.Close() - - pack := hm.Packet(0) - - //fmt.Println(pack) - - //writer.WriteString(pack) - client.Write(pack.Buffer) - - bytes := make([]byte, 512) - - l, _ := client.Read(bytes) - - //fmt.Println(bytes) - - hm.Match(0, matcher.NewPacket(bytes, l), nil) - -} diff --git a/discovery/service/match/http/https_test.go b/discovery/service/match/http/https_test.go deleted file mode 100644 index 2b07dd0..0000000 --- a/discovery/service/match/http/https_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package http - -import ( - "crypto/tls" - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "log" - "net" - "testing" - "time" -) - -func TestHTTPSMatcher_Match(t *testing.T) { - netinfo := "192.168.1.10:10443" - dialer := &net.Dialer{ - Timeout: 5 * time.Second, - } - - conn, err := tls.DialWithDialer( - dialer, - "tcp", - netinfo, - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.103", - }, - ) - - if err != nil { - log.Println(err) - return - } - defer conn.Close() - - //fmt.Println(conn) - h := NewHTTPMatcher() - - pac := h.Packet(0) - - //fmt.Println(pac) - //fmt.Println(pac.Buffer) - - //bytes := make([]byte, 1024) - - l, _ := conn.Write(pac.Buffer) - - buf := make([]byte, 1024) - l, _ = conn.Read(buf) - - fmt.Println(string(buf)) - fmt.Println(l) - is := h.Match(0, matcher.NewPacket(buf, l), nil) - fmt.Println(is) - -} diff --git a/discovery/service/match/imap/imap_test.go b/discovery/service/match/imap/imap_test.go deleted file mode 100644 index d47953b..0000000 --- a/discovery/service/match/imap/imap_test.go +++ /dev/null @@ -1,153 +0,0 @@ -package imap - - -import ( - "crypto/tls" - "fmt" - //"git.loafle.net/overflow/overflow_discovery/collector/core/scan/port" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - //"git.loafle.net/overflow/overflow_discovery/collector/core/scan/service/matcher/scaninfo" - //"git.loafle.net/overflow/overflow_discovery/collector/discovery/types" - "net" - "testing" -) - -func ImapRun(client net.Conn, t *testing.T) { - - lm := NewIMAPMatcher() - - //port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP) - // - //scanInfo := types.NewServiceScanInfo(port) - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - // - //fmt.Println(ipport) - //client, _ := net.Dial("tcp", ipport) - - //defer client.Close() - - bytett := make([]byte, 1024) - - rr, _ := client.Read(bytett) - - bb := lm.Match(0, matcher.NewPacket(bytett, rr), nil) - - if bb { - t.Log("good!") - } - - fmt.Println(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - //fmt.Println(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - read, _ := client.Read(bytes) - - fmt.Println(cap(bytes)) - - //fmt.Println(bytes) - - b := lm.Match(ii+1, matcher.NewPacket(bytes, read), nil) - - if b { - t.Log("send Good!") - } - - } - - -} - -func TestIMapTls(t *testing.T) { - - conn, _ := tls.Dial( - "tcp", - "192.168.1.15:993", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.15", - }, - ) - - defer conn.Close() - - ImapRun(conn, t) - -} - -func TestIMapNormal(t *testing.T) { - - client, err := net.Dial("tcp", "192.168.1.15:143") - if err != nil { - t.Fatal(err) - } - - defer client.Close() - - ImapRun(client, t) - -} - -func TestImap(t *testing.T) { - - lm := NewIMAPMatcher() - - //port := types.NewPort("143", types.NewHost("192.168.1.215"), types.TYPE_TCP) - - //scanInfo := scaninfo.NewServiceScanInfo(port) - - var ipport string - //ipport = port.Host.Ip + ":" + port.Port_ - - fmt.Println(ipport) - client, _ := net.Dial("tcp", ipport) - - defer client.Close() - - bytett := make([]byte, 1024) - - rr, _ := client.Read(bytett) - - //bb := lm.Match(0, matcher.NewPacket(bytett, rr), scanInfo) - bb := lm.Match(0, matcher.NewPacket(bytett, rr), nil) - - if bb { - t.Log("good!") - } - - fmt.Println(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - //fmt.Println(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - read, _ := client.Read(bytes) - - fmt.Println(cap(bytes)) - - //fmt.Println(bytes) - - b := lm.Match(ii+1, matcher.NewPacket(bytes, read), nil) - - if b { - t.Log("send Good!") - } - - } - //t.Log(scanInfo) -} diff --git a/discovery/service/match/mongodb/mongodb_test.go b/discovery/service/match/mongodb/mongodb_test.go deleted file mode 100644 index 8958765..0000000 --- a/discovery/service/match/mongodb/mongodb_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package mongodb - -import ( - "crypto/tls" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestMongoNor(t *testing.T) { - - conn, _ := net.Dial("tcp", "192.168.1.16:37017") - - defer conn.Close() - - MongoRun(conn, t) - -} -func TestMongoTLS(t *testing.T) { - conn, _ := tls.Dial( - "tcp", - "192.168.1.16:47017", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.16", - }, - ) - - defer conn.Close() - - MongoRun(conn, t) -} - -func MongoRun(conn net.Conn, t *testing.T) { - - m := NewMongoDBMatcher() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("MongoDB found") - return - } - - t.Error("MongoDB not found") - } - -} diff --git a/discovery/service/match/mssql/mssql_test.go b/discovery/service/match/mssql/mssql_test.go deleted file mode 100644 index 214ca7a..0000000 --- a/discovery/service/match/mssql/mssql_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package mssql - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -/* -192.168.1.106:1433 - normal -192.168.1.103:1433 - ssl -*/ -func TestSqlNor(t *testing.T) { - - conn, _ := net.Dial("tcp", "192.168.1.16:11433") - - defer conn.Close() - - sqlServerRun(conn, t) - -} - -//func TestSqlTLS(t *testing.T) { -// conn, err := tls.Dial( -// "tcp", -// "192.168.1.103:7680", -// &tls.Config{ -// InsecureSkipVerify: true, -// ServerName: "192.168.1.103", -// }, -// ) -// -// if err != nil { -// t.Log(err) -// return -// } -// -// defer conn.Close() -// -// sqlServerRun(conn, t) -//} - -func sqlServerRun(conn net.Conn, t *testing.T) { - - m := NewMSSqlMatcher() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log(m.ServiceName()) - return - } - - t.Error("MSSQL not found") - } - -} diff --git a/discovery/service/match/mysql/mysql_test.go b/discovery/service/match/mysql/mysql_test.go deleted file mode 100644 index 2f325d3..0000000 --- a/discovery/service/match/mysql/mysql_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package mysql - - -import ( - "crypto/tls" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestMySql(t *testing.T) { - - m := NewMySqlMatcher() - - /* - 192.168.1.103:3306 - normal - 192.168.1.105:8306 - ssl - 192.168.1.203:3306 - mysql with error code - */ - conn, _ := net.Dial("tcp", "192.168.1.15:33068") - - defer conn.Close() - - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(0, p, nil) { - t.Log(m.ServiceName()) - return - } - - t.Error("MySQL not found") - -} - -func TestCassandraTLS(t *testing.T) { - - m := NewMySqlMatcher() - - conn, err := tls.Dial( - "tcp", - "192.168.1.105:8306", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.105", - }, - ) - if err != nil { - t.Fatal(err) - } - - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log(m.ServiceName()) - return - } - - t.Error("MySQL not found") - } - -} diff --git a/discovery/service/match/netbios/netbios_test.go b/discovery/service/match/netbios/netbios_test.go deleted file mode 100644 index 44be41d..0000000 --- a/discovery/service/match/netbios/netbios_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package netbios - - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestNBSS(t *testing.T) { - - m := NewNetBiosMatcher() - - conn, _ := net.Dial("tcp", "192.168.1.106:139") - - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("NBSS found") - return - } - - t.Error("NBSS not found") - } - -} diff --git a/discovery/service/match/oracle/oracle_test.go b/discovery/service/match/oracle/oracle_test.go deleted file mode 100644 index 7556782..0000000 --- a/discovery/service/match/oracle/oracle_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package oracle - - -import ( - - "git.loafle.net/overflow/overflow_discovery/service/matcher" - - - "net" - "testing" -) - -func TestOracle(t *testing.T) { - - lm := NewOracleMatcher() - - //port := types.NewPort("1521", types.NewHost("192.168.1.30"), types.TYPE_TCP) - //scanInfo := scaninfo.NewServiceScanInfo(port) - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - - client, _ := net.Dial("tcp", "192.168.1.15:1521") - - defer client.Close() - - t.Log(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - t.Log(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - read, _ := client.Read(bytes) - - t.Log(bytes) - - b := lm.Match(ii, matcher.NewPacket(bytes, read), nil) - - if b { - t.Log("Good") - } - - } - - - -} diff --git a/discovery/service/match/pgsql/pgsql_test.go b/discovery/service/match/pgsql/pgsql_test.go deleted file mode 100644 index 70e30cd..0000000 --- a/discovery/service/match/pgsql/pgsql_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package pgsql - -import ( - "crypto/tls" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestPG(t *testing.T) { - m := NewPostgreSQLMatcher() - - conn, err := net.Dial("tcp", "192.168.1.106:5432") //107 - if err != nil { - t.Error(err) - return - } - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("PostgreSQL found") - return - } - - t.Error("PostgreSQL not found") - } -} - -func TestSqlTLS(t *testing.T) { - conn, err := tls.Dial( - "tcp", - "192.168.1.107:5432", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.107", - }, - ) - - if err != nil { - t.Error(err) - return - } - - defer conn.Close() - - m := NewPostgreSQLMatcher() - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("PostgreSQL found") - return - } - - t.Error("PostgreSQL not found") - } -} diff --git a/discovery/service/match/pop/pop_test.go b/discovery/service/match/pop/pop_test.go deleted file mode 100644 index fbc9850..0000000 --- a/discovery/service/match/pop/pop_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package pop - - -import ( - "crypto/tls" - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - - - "net" - "testing" -) - -func TestPopTLS(t *testing.T) { - conn, _ := tls.Dial( - "tcp", - "192.168.1.15:995", - &tls.Config{ - InsecureSkipVerify: true, - ServerName: "192.168.1.15", - }, - ) - - defer conn.Close() - - pop3Run(conn, t) -} - -func TestPopNor(t *testing.T) { - - client, _ := net.Dial("tcp", "192.168.1.15:110") - - defer client.Close() - - pop3Run(client, t) - -} - -func pop3Run(client net.Conn, t *testing.T) { - - lm := NewPOPMatcher() - - //port := types.NewPort("110", types.NewHost("192.168.1.215"), types.TYPE_TCP) - //scanInfo := scaninfo.NewServiceScanInfo(port) - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - // - //fmt.Println(ipport) - - bytett := make([]byte, 1024) - - read, _ := client.Read(bytett) - - bb := lm.Match(0, matcher.NewPacket(bytett, read), nil) - - if bb { - t.Log("good!") - } - - fmt.Println(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - //fmt.Println(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - rr, _ := client.Read(bytes) - - //fmt.Println(bytes) - - b := lm.Match(ii+1, matcher.NewPacket(bytes, rr), nil) - - if b { - t.Log("send Good!") - } - - } - - - -} diff --git a/discovery/service/match/redis/redisProtected_test.go b/discovery/service/match/redis/redisProtected_test.go deleted file mode 100644 index 8f4e78e..0000000 --- a/discovery/service/match/redis/redisProtected_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package redis - -//import ( -// "git.loafle.net/overflow/overflow_discovery/collector/core/scan/service/matcher/packet" -// "net" -// "testing" -//) -// -//func TestRedisProtected(t *testing.T) { -// -// m := NewRedisProtectedMatcher() -// -// conn, err := net.Dial("tcp", "192.168.1.215:8379") -// -// if err != nil { -// t.Log(err) -// return -// } -// -// defer conn.Close() -// -// bytes := make([]byte, 1024) -// n, _ := conn.Read(bytes) -// -// //fmt.Println(string(bytes[:n])) -// -// b := m.Match(0, matcher.NewPacket(bytes, n), nil) -// -// if b { -// t.Log("good!") -// } -// -//} diff --git a/discovery/service/match/redis/redis_test.go b/discovery/service/match/redis/redis_test.go deleted file mode 100644 index f0d2e9d..0000000 --- a/discovery/service/match/redis/redis_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package redis - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -const ( - ADDR string = "192.168.1.16:26379" -) - -func TestRedisMatcher(t *testing.T) { - - m := NewRedisMatcher() - - conn, _ := net.Dial("tcp", ADDR) - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("Redis found.") - return - } - - t.Error("Redis not found") - } - -} diff --git a/discovery/service/match/rmi/rmi_test.go b/discovery/service/match/rmi/rmi_test.go deleted file mode 100644 index f579c8c..0000000 --- a/discovery/service/match/rmi/rmi_test.go +++ /dev/null @@ -1,52 +0,0 @@ -package rmi - -import ( - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - //"git.loafle.net/overflow/overflow_discovery/discovery/discovery/types" - "net" - "testing" -) - -func TestNew(t *testing.T) { - r := NewRMIMatcher() - fmt.Println("TestNew: ", r) -} -func TestRMIMatcher_Match(t *testing.T) { - - fmt.Println("Match") - - hm := NewRMIMatcher() - - //port := types.NewPort("9840", types.NewHost("192.168.1.101"), types.TYPE_TCP) - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - //fmt.Println(ipport) - - client, err := net.Dial("tcp", "192.168.1.101:9840") - - if err != nil { - t.Fatal(err) - } - - defer client.Close() - - pack := hm.Packet(0) - - fmt.Println(pack.Buffer) - - //writer.WriteString(pack) - client.Write(pack.Buffer) - - bytes := make([]byte, 512) - - l, _ := client.Read(bytes) - - //fmt.Println(bytes) - - t1 := hm.Match(0, matcher.NewPacket(bytes, l), nil) - - fmt.Println(t1) -} diff --git a/discovery/service/match/smb/smb_test.go b/discovery/service/match/smb/smb_test.go deleted file mode 100644 index 58ff870..0000000 --- a/discovery/service/match/smb/smb_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package smb - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -const ( - ADDR string = "192.168.1.106:445" -) - -func TestSMBMatcher(t *testing.T) { - - m := NewSMBMatcher() - - conn, err := net.Dial("tcp", ADDR) - - if err != nil { - t.Fatal(err) - } - - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("SMB found.") - return - } - - t.Error("SMB not found") - } - -} diff --git a/discovery/service/match/snmp/snmpv2_test.go b/discovery/service/match/snmp/snmpv2_test.go deleted file mode 100644 index 00742a7..0000000 --- a/discovery/service/match/snmp/snmpv2_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package snmp - - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestSNMP2(t *testing.T) { - - m := NewSNMPv2Matcher() - - conn, err := net.Dial("udp", "192.168.1.15:161") - if err != nil { - t.Error(err) - return - } - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("SNMP found") - return - } - - t.Error("SNMP not found") - } - -} diff --git a/discovery/service/match/snmp/snmpv3_test.go b/discovery/service/match/snmp/snmpv3_test.go deleted file mode 100644 index 0f7f545..0000000 --- a/discovery/service/match/snmp/snmpv3_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package snmp - - -import ( - "git.loafle.net/overflow/overflow_discovery/service/matcher" - "net" - "testing" -) - -func TestSNMP3(t *testing.T) { - - m := NewSNMPv3Matcher() - - conn, err := net.Dial("udp", "192.168.1.15:161") - if err != nil { - t.Error(err) - return - } - defer conn.Close() - - for i := 0; i < m.PacketCount(); i++ { - - pack := m.Packet(i) - conn.Write(pack.Buffer) - bytes := make([]byte, 1024) - n, _ := conn.Read(bytes) - p := matcher.NewPacket(bytes, n) - - if m.Match(i, p, nil) { - t.Log("SNMP found") - return - } - - t.Error("SNMP not found") - } - -} diff --git a/discovery/service/match/ssh/ssh_test.go b/discovery/service/match/ssh/ssh_test.go deleted file mode 100644 index 5fd72fc..0000000 --- a/discovery/service/match/ssh/ssh_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package ssh - -import ( - "fmt" - //"git.loafle.net/overflow/overflow_discovery/match/ssh" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - //"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, matcher.NewPacket(bytes, l), nil) - - fmt.Println(b) - -} diff --git a/discovery/service/match/telnet/telnet_test.go b/discovery/service/match/telnet/telnet_test.go deleted file mode 100644 index d7ca223..0000000 --- a/discovery/service/match/telnet/telnet_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package telnet - -import ( - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - - "net" - "testing" -) - -func TestTelnetMatcher_Match(t *testing.T) { - - //port := types.NewPort("23", types.NewHost("192.168.1.210"), types.TYPE_TCP) - //telnet := NewTelnetMatcher() - // - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - client, _ := net.Dial("tcp", "192.168.1.105:23") - - defer client.Close() - - bytes := make([]byte, 512) - - l, _ := client.Read(bytes) - - fmt.Println("length :", l) - fmt.Println(bytes) - - b := NewTelnetMatcher().Match(0, matcher.NewPacket(bytes, l), nil) - - fmt.Println(b) -} diff --git a/discovery/service/match/wmi/wmi_test.go b/discovery/service/match/wmi/wmi_test.go deleted file mode 100644 index ecadd53..0000000 --- a/discovery/service/match/wmi/wmi_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package wmi - -import ( - "fmt" - "git.loafle.net/overflow/overflow_discovery/service/matcher" - //"git.loafle.net/overflow/overflow_discovery/collector/discovery/scan/matcher/scaninfo" - //"git.loafle.net/overflow/overflow_discovery/collector/discovery/types" - "net" - "testing" -) - -func TestWMI(t *testing.T) { - - lm := NewWMIMatcher() - - //port := types.NewPort("135", types.NewHost("192.168.1.1"), types.TYPE_TCP) - //scanInfo := scaninfo.NewServiceScanInfo(port) - //var ipport string - //ipport = port.Host.Ip + ":" + string(port.Port) - - //fmt.Println(ipport) - client, _ := net.Dial("tcp", "192.168.1.106:135") - - defer client.Close() - - fmt.Println(lm.PacketCount()) - - for ii := 0; ii < lm.PacketCount(); ii++ { - - pack := lm.Packet(ii) - - fmt.Println(pack) - - client.Write(pack.Buffer) - - bytes := make([]byte, 1024) - - read, _ := client.Read(bytes) - - //fmt.Println(bytes) - - b := lm.Match(ii, matcher.NewPacket(bytes, read), nil) - - if b { - fmt.Println("Good") - } - - } - - -} diff --git a/service/matcher/dns/dns.go b/service/matcher/dns/dns.go index d33ccff..a6569df 100644 --- a/service/matcher/dns/dns.go +++ b/service/matcher/dns/dns.go @@ -109,8 +109,8 @@ func (t *DNSMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.Pa return true } -func (t *DNSMatcher) IsSend(info matcher.MatchInfo) bool { - if 53 == info.Port() { +func (t *DNSMatcher) IsSend(port int) bool { + if 53 == port { return true } return false diff --git a/service/matcher/matcher.go b/service/matcher/matcher.go index e97af3e..943f65c 100644 --- a/service/matcher/matcher.go +++ b/service/matcher/matcher.go @@ -14,7 +14,7 @@ type Matcher interface { type UDPMatcher interface { Matcher - IsSend(info MatchInfo) bool + IsSend(port int) bool } type Matchers struct { diff --git a/service/matcher/snmp/v2/snmpv2.go b/service/matcher/snmp/v2/snmpv2.go index 3f2164f..b7aca74 100644 --- a/service/matcher/snmp/v2/snmpv2.go +++ b/service/matcher/snmp/v2/snmpv2.go @@ -118,8 +118,8 @@ func (t *SNMPMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.P } -func (t *SNMPMatcher) IsSend(info matcher.MatchInfo) bool { - if info.Port() == 161 { +func (t *SNMPMatcher) IsSend(port int) bool { + if 161 == port { return true } return false diff --git a/service/matcher/snmp/v3/snmpv3.go b/service/matcher/snmp/v3/snmpv3.go index 8b8809f..5bd5435 100644 --- a/service/matcher/snmp/v3/snmpv3.go +++ b/service/matcher/snmp/v3/snmpv3.go @@ -130,8 +130,8 @@ func (t *SNMPMatcher) Match(info matcher.MatchInfo, index int, packet *matcher.P } -func (t *SNMPMatcher) IsSend(info matcher.MatchInfo) bool { - if info.Port() == 161 { +func (t *SNMPMatcher) IsSend(port int) bool { + if 161 == port { return true } return false diff --git a/service/service.go b/service/service.go index 32108e5..4d1bc33 100644 --- a/service/service.go +++ b/service/service.go @@ -94,7 +94,7 @@ func GetUDPMatchers() []matcher.UDPMatcher { return UDPMatchers } -func GetMatcherByName(serName string) Matcher { +func GetMatcherByName(serName string) matcher.Matcher { for _, m := range AllMatchers { if m.ServiceName() == serName { return m