From e2c14584b662ec43ce4909dc566b166420a39842 Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 9 Aug 2017 12:21:34 +0900 Subject: [PATCH] fixed test --- .../activedirectory/activedirectory_test.go | 56 +-- matcher/dhcp/dhcp.go | 374 +++++++++--------- matcher/dhcp/dhcp_test.go | 20 +- matcher/dns/dns_test.go | 62 +-- matcher/http/http_test.go | 94 ++--- matcher/http/https_test.go | 106 ++--- matcher/mysql/mysql_test.go | 2 +- matcher/rmi/rmi_test.go | 96 ++--- matcher/smb/smb_test.go | 75 ++-- matcher/ssh/ssh_test.go | 64 +-- matcher/telnet/telnet_test.go | 62 +-- matcher/wmi/wmi_test.go | 98 ++--- 12 files changed, 562 insertions(+), 547 deletions(-) diff --git a/matcher/activedirectory/activedirectory_test.go b/matcher/activedirectory/activedirectory_test.go index db318a1..afb100e 100644 --- a/matcher/activedirectory/activedirectory_test.go +++ b/matcher/activedirectory/activedirectory_test.go @@ -4,10 +4,12 @@ import ( "crypto/tls" "net" "testing" + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" ) func TestADNor(t *testing.T) { - client, err := net.Dial("tcp", "192.168.1.1:389") + client, err := net.Dial("tcp", "192.168.1.15:389") if err != nil { t.Log(err) @@ -40,8 +42,8 @@ func TestADTLS(t *testing.T) { func dDRun(client net.Conn, t *testing.T) { - //lm := NewActiveDirectoryMatcher() - // + lm := NewActiveDirectoryMatcher() + //port := types.NewPort("389", types.NewHost("192.168.1.1"), types.TYPE_TCP) // //var ipport string @@ -50,28 +52,28 @@ func dDRun(client net.Conn, t *testing.T) { //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, packet.NewPacket(bytes, read), scanInfo) - // - // if b { - // fmt.Println("Good") - // } - // - //} - // - //t.Log(scanInfo) + + 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, packet.NewPacket(bytes, read), nil) + + if b { + fmt.Println("Good") + } + + } + + } diff --git a/matcher/dhcp/dhcp.go b/matcher/dhcp/dhcp.go index d3cdbf3..cb9c607 100644 --- a/matcher/dhcp/dhcp.go +++ b/matcher/dhcp/dhcp.go @@ -1,188 +1,190 @@ package dhcp -// -//import ( -// "bytes" -// "encoding/binary" -// "fmt" -// log "github.com/cihub/seelog" -// "git.loafle.net/overflow/overflow_probe/matcher" -// "net" -// "time" -//) -// -//const ( -// MAGIC_COOKIE uint32 = 0x63825363 -// OPT_CODE_SERVER_IDENTIFIER uint8 = 54 -// OPT_CODE_SUBNET_MASK uint8 = 1 -// OPT_CODE_ROUTER uint8 = 3 -// OPT_CODE_DNS uint8 = 6 -//) -// -//type dhcpDiscover struct { -// MsgType byte -// HwType byte -// HwAddrLen byte -// Hops byte -// Xid uint32 -// Secs uint16 -// BootpFlags uint16 -// ClientIp uint32 -// YourIp uint32 -// NextServerIp uint32 -// RelayAgentIp uint32 -// ClientMacAddr [6]byte -// ClientHwAddrPadding [10]byte -// ServerHostName [64]byte -// BootFileName [128]byte -// MagicCookie uint32 -// Mtype byte -// MtypeLen byte -// MtypeVal byte -// Opts [200]byte -// End byte -// Padding [16]byte -//} -// -//func DiscoverDHCP(zone *types.DiscoveryZone) { -// err := sendDHCPDiscovery() -// if err != nil { -// log.Error(err) -// return -// } -// recvDHCPOffer(zone) -//} -// -//func sendDHCPDiscovery() error { -// dhcp := dhcpDiscover{ -// MsgType: 0x01, -// HwType: 0x01, -// HwAddrLen: 0x06, -// Hops: 0x00, -// Xid: 0x00000000, -// Secs: 0x0000, -// ClientIp: 0x00000000, -// YourIp: 0x00000000, -// NextServerIp: 0x00000000, -// RelayAgentIp: 0x00000000, -// MagicCookie: MAGIC_COOKIE, -// Mtype: 0x35, -// MtypeLen: 0x01, -// MtypeVal: 0x01, -// End: 0xff, -// } -// -// var flag uint16 = 0 -// dhcp.BootpFlags = ^flag // flag = unicast , ^flag = broadcast -// -// //TODO : getting mac addr from zone -// dhcp.ClientMacAddr[0] = 0x50 -// dhcp.ClientMacAddr[1] = 0xe5 -// dhcp.ClientMacAddr[2] = 0x49 -// dhcp.ClientMacAddr[3] = 0x46 -// dhcp.ClientMacAddr[4] = 0x93 -// dhcp.ClientMacAddr[5] = 0x28 -// -// writer := new(bytes.Buffer) -// binary.Write(writer, binary.BigEndian, dhcp) -// conn, err := net.Dial("udp", "255.255.255.255:67") -// if err != nil { -// return err -// } -// conn.Write(writer.Bytes()) -// defer conn.Close() -// -// return nil -//} -// -//func recvDHCPOffer(zone *types.DiscoveryZone) { -// -// socket, err := net.ListenUDP("udp4", &net.UDPAddr{ -// IP: net.IPv4(255, 255, 255, 255), -// Port: 68, -// }) -// if err != nil { -// log.Error(err) -// return -// } -// err = socket.SetDeadline(time.Now().Add(3 * time.Second)) -// if err != nil { -// log.Error(err) -// return -// } -// -// buf := make([]byte, 4096) -// n, _, err := socket.ReadFromUDP(buf) -// if err != nil { -// log.Error(err) -// return -// } -// if n <= 0 { -// log.Error("No DHCP offer.") -// return -// } -// -// offer := dhcpDiscover{} -// -// reader := new(bytes.Buffer) -// reader.Write(buf) -// if err := binary.Read(reader, binary.BigEndian, &offer); err != nil { -// log.Error(err) -// return -// } -// if offer.MagicCookie != MAGIC_COOKIE { -// log.Error("Not a DHCP packet.") -// return -// } -// -// //option searching -// r := new(bytes.Buffer) -// r.Write(offer.Opts[:]) -// -// for i := 0; i < r.Len(); i++ { -// v := r.Next(1)[0] -// -// if v == OPT_CODE_SUBNET_MASK && r.Next(1)[0] == 4 { -// ipStr := byteToIpString(r.Next(4)) -// log.Infof("SUBNET MASK: %s", ipStr) -// } -// -// if v == OPT_CODE_ROUTER && r.Next(1)[0] == 4 { -// ipStr := byteToIpString(r.Next(4)) -// log.Infof("ROUTER: %s", ipStr) -// } -// -// if v == OPT_CODE_DNS { -// len := r.Next(1)[0] -// var dns []string = make([]string, 0) -// var ipStr string -// ipStr = byteToIpString(r.Next(4)) -// dns = append(dns, ipStr) -// if len == 8 { -// ipStr = byteToIpString(r.Next(4)) -// dns = append(dns, ipStr) -// } -// log.Infof("DNS", dns) -// } -// -// if v == OPT_CODE_SERVER_IDENTIFIER && r.Next(1)[0] == 4 { -// ipStr := byteToIpString(r.Next(4)) -// log.Infof("DHCP SERVER: %s", ipStr) -// } -// } -// -//} -// -//func byteToIpString(b []byte) string { -// var ipStr string -// len := len(b) -// for i := 0; i < len; i++ { -// v := b[i] -// ipStr += fmt.Sprintf("%d", v) -// if i < len-1 { -// ipStr += "." -// } -// } -// -// return ipStr -//} + +import ( + "bytes" + "encoding/binary" + "fmt" + log "github.com/cihub/seelog" + //"git.loafle.net/overflow/overflow_probe/matcher" + "net" + "time" + + "git.loafle.net/overflow/overflow_probe/discovery/discovery/types" +) + +const ( + MAGIC_COOKIE uint32 = 0x63825363 + OPT_CODE_SERVER_IDENTIFIER uint8 = 54 + OPT_CODE_SUBNET_MASK uint8 = 1 + OPT_CODE_ROUTER uint8 = 3 + OPT_CODE_DNS uint8 = 6 +) + +type dhcpDiscover struct { + MsgType byte + HwType byte + HwAddrLen byte + Hops byte + Xid uint32 + Secs uint16 + BootpFlags uint16 + ClientIp uint32 + YourIp uint32 + NextServerIp uint32 + RelayAgentIp uint32 + ClientMacAddr [6]byte + ClientHwAddrPadding [10]byte + ServerHostName [64]byte + BootFileName [128]byte + MagicCookie uint32 + Mtype byte + MtypeLen byte + MtypeVal byte + Opts [200]byte + End byte + Padding [16]byte +} + +func DiscoverDHCP(zone *types.DiscoveryZone) { + err := sendDHCPDiscovery() + if err != nil { + log.Error(err) + return + } + recvDHCPOffer(zone) +} + +func sendDHCPDiscovery() error { + dhcp := dhcpDiscover{ + MsgType: 0x01, + HwType: 0x01, + HwAddrLen: 0x06, + Hops: 0x00, + Xid: 0x00000000, + Secs: 0x0000, + ClientIp: 0x00000000, + YourIp: 0x00000000, + NextServerIp: 0x00000000, + RelayAgentIp: 0x00000000, + MagicCookie: MAGIC_COOKIE, + Mtype: 0x35, + MtypeLen: 0x01, + MtypeVal: 0x01, + End: 0xff, + } + + var flag uint16 = 0 + dhcp.BootpFlags = ^flag // flag = unicast , ^flag = broadcast + + //TODO : getting mac addr from zone + dhcp.ClientMacAddr[0] = 0x50 + dhcp.ClientMacAddr[1] = 0xe5 + dhcp.ClientMacAddr[2] = 0x49 + dhcp.ClientMacAddr[3] = 0x46 + dhcp.ClientMacAddr[4] = 0x93 + dhcp.ClientMacAddr[5] = 0x28 + + writer := new(bytes.Buffer) + binary.Write(writer, binary.BigEndian, dhcp) + conn, err := net.Dial("udp", "255.255.255.255:67") + if err != nil { + return err + } + conn.Write(writer.Bytes()) + defer conn.Close() + + return nil +} + +func recvDHCPOffer(zone *types.DiscoveryZone) { + + socket, err := net.ListenUDP("udp4", &net.UDPAddr{ + IP: net.IPv4(255, 255, 255, 255), + Port: 68, + }) + if err != nil { + log.Error(err) + return + } + err = socket.SetDeadline(time.Now().Add(3 * time.Second)) + if err != nil { + log.Error(err) + return + } + + buf := make([]byte, 4096) + n, _, err := socket.ReadFromUDP(buf) + if err != nil { + log.Error(err) + return + } + if n <= 0 { + log.Error("No DHCP offer.") + return + } + + offer := dhcpDiscover{} + + reader := new(bytes.Buffer) + reader.Write(buf) + if err := binary.Read(reader, binary.BigEndian, &offer); err != nil { + log.Error(err) + return + } + if offer.MagicCookie != MAGIC_COOKIE { + log.Error("Not a DHCP packet.") + return + } + + //option searching + r := new(bytes.Buffer) + r.Write(offer.Opts[:]) + + for i := 0; i < r.Len(); i++ { + v := r.Next(1)[0] + + if v == OPT_CODE_SUBNET_MASK && r.Next(1)[0] == 4 { + ipStr := byteToIpString(r.Next(4)) + log.Infof("SUBNET MASK: %s", ipStr) + } + + if v == OPT_CODE_ROUTER && r.Next(1)[0] == 4 { + ipStr := byteToIpString(r.Next(4)) + log.Infof("ROUTER: %s", ipStr) + } + + if v == OPT_CODE_DNS { + len := r.Next(1)[0] + var dns []string = make([]string, 0) + var ipStr string + ipStr = byteToIpString(r.Next(4)) + dns = append(dns, ipStr) + if len == 8 { + ipStr = byteToIpString(r.Next(4)) + dns = append(dns, ipStr) + } + log.Infof("DNS", dns) + } + + if v == OPT_CODE_SERVER_IDENTIFIER && r.Next(1)[0] == 4 { + ipStr := byteToIpString(r.Next(4)) + log.Infof("DHCP SERVER: %s", ipStr) + } + } + +} + +func byteToIpString(b []byte) string { + var ipStr string + len := len(b) + for i := 0; i < len; i++ { + v := b[i] + ipStr += fmt.Sprintf("%d", v) + if i < len-1 { + ipStr += "." + } + } + + return ipStr +} diff --git a/matcher/dhcp/dhcp_test.go b/matcher/dhcp/dhcp_test.go index 5299852..0fd2ef5 100644 --- a/matcher/dhcp/dhcp_test.go +++ b/matcher/dhcp/dhcp_test.go @@ -1,12 +1,12 @@ package dhcp -// -//import ( -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/zone" -// "testing" -//) -// -//func TestDHCP(t *testing.T) { -// zone := zone.NewZone() -// DiscoverDHCP(zone) -//} + +import ( + "git.loafle.net/overflow/overflow_probe/discovery/core/scan/zone" + "testing" +) + +func TestDHCP(t *testing.T) { + zone := zone.NewZone() + DiscoverDHCP(zone) +} diff --git a/matcher/dns/dns_test.go b/matcher/dns/dns_test.go index ee3d755..a9c9de4 100644 --- a/matcher/dns/dns_test.go +++ b/matcher/dns/dns_test.go @@ -1,33 +1,33 @@ package dns -//import ( -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "net" -// "testing" -//) -// -//func TestDns(t *testing.T) { -// m := NewDnsMatcher() -// -// conn, _ := net.Dial("udp", "192.168.1.215: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 := packet.NewPacket(bytes, n) -// -// if m.Match(i, p, nil) { -// t.Log("dns found") -// return -// } -// -// t.Error("dns not found") -// } -//} +import ( + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "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 := packet.NewPacket(bytes, n) + + if m.Match(i, p, nil) { + t.Log("dns found") + return + } + + t.Error("dns not found") + } +} diff --git a/matcher/http/http_test.go b/matcher/http/http_test.go index c3b7fcd..50191ea 100644 --- a/matcher/http/http_test.go +++ b/matcher/http/http_test.go @@ -1,49 +1,49 @@ package http -//import ( -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "git.loafle.net/overflow/overflow_probe/collector/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", ipport) -// -// 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, packet.NewPacket(bytes, l), nil) -// -//} +import ( + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + //"git.loafle.net/overflow/overflow_probe/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, packet.NewPacket(bytes, l), nil) + +} diff --git a/matcher/http/https_test.go b/matcher/http/https_test.go index c176173..2647541 100644 --- a/matcher/http/https_test.go +++ b/matcher/http/https_test.go @@ -1,55 +1,55 @@ package http -//import ( -// "crypto/tls" -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/packet" -// "log" -// "net" -// "testing" -// "time" -//) -// -//func TestHTTPSMatcher_Match(t *testing.T) { -// netinfo := "192.168.1.1:443" -// 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, packet.NewPacket(buf, l), nil) -// fmt.Println(is) -// -//} +import ( + "crypto/tls" + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "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, packet.NewPacket(buf, l), nil) + fmt.Println(is) + +} diff --git a/matcher/mysql/mysql_test.go b/matcher/mysql/mysql_test.go index cd0d798..6cfd1d2 100644 --- a/matcher/mysql/mysql_test.go +++ b/matcher/mysql/mysql_test.go @@ -17,7 +17,7 @@ func TestMySql(t *testing.T) { 192.168.1.105:8306 - ssl 192.168.1.203:3306 - mysql with error code */ - conn, _ := net.Dial("tcp", "192.168.1.15:3306") + conn, _ := net.Dial("tcp", "192.168.1.15:33068") defer conn.Close() diff --git a/matcher/rmi/rmi_test.go b/matcher/rmi/rmi_test.go index 537df9e..8b6a472 100644 --- a/matcher/rmi/rmi_test.go +++ b/matcher/rmi/rmi_test.go @@ -1,48 +1,52 @@ package rmi -//import ( -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "git.loafle.net/overflow/overflow_probe/collector/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, _ := net.Dial("tcp", ipport) -// -// 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, packet.NewPacket(bytes, l), nil) -// -// fmt.Println(t1) -//} +import ( + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + //"git.loafle.net/overflow/overflow_probe/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, packet.NewPacket(bytes, l), nil) + + fmt.Println(t1) +} diff --git a/matcher/smb/smb_test.go b/matcher/smb/smb_test.go index 0c88da8..df394df 100644 --- a/matcher/smb/smb_test.go +++ b/matcher/smb/smb_test.go @@ -1,37 +1,42 @@ package smb -//import ( -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "net" -// "testing" -//) -// -//const ( -// ADDR string = "192.168.1.104:139" -//) -// -//func TestSMBMatcher(t *testing.T) { -// -// m := NewSMBMatcher() -// -// 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 := packet.NewPacket(bytes, n) -// -// if m.Match(i, p, nil) { -// t.Log("SMB found.") -// return -// } -// -// t.Error("SMB not found") -// } -// -//} +import ( + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "net" + "testing" +) + +const ( + ADDR string = "192.168.1.106:139" +) + +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 := packet.NewPacket(bytes, n) + + if m.Match(i, p, nil) { + t.Log("SMB found.") + return + } + + t.Error("SMB not found") + } + +} diff --git a/matcher/ssh/ssh_test.go b/matcher/ssh/ssh_test.go index f580495..24d76c0 100644 --- a/matcher/ssh/ssh_test.go +++ b/matcher/ssh/ssh_test.go @@ -1,33 +1,35 @@ package ssh -//import ( -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "git.loafle.net/overflow/overflow_probe/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", ipport) -// -// defer client.Close() -// -// bytes := make([]byte, 512) -// -// l, _ := client.Read(bytes) -// -// fmt.Println(bytes) -// -// b := ssh.Match(0, packet.NewPacket(bytes, l), nil) -// -// fmt.Println(b) -// -//} +import ( + "fmt" + //"git.loafle.net/overflow/overflow_probe/matcher/ssh" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + //"git.loafle.net/overflow/overflow_probe/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) + +} diff --git a/matcher/telnet/telnet_test.go b/matcher/telnet/telnet_test.go index 99564ca..f061f38 100644 --- a/matcher/telnet/telnet_test.go +++ b/matcher/telnet/telnet_test.go @@ -1,33 +1,33 @@ package telnet -//import ( -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/core/scan/service/matcher/packet" -// "git.loafle.net/overflow/overflow_probe/collector/discovery/types" -// "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", ipport) -// -// defer client.Close() -// -// bytes := make([]byte, 512) -// -// l, _ := client.Read(bytes) -// -// fmt.Println("length :", l) -// fmt.Println(bytes) -// -// b := telnet.Match(0, packet.NewPacket(bytes, l), nil) -// -// fmt.Println(b) -//} +import ( + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + + "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, packet.NewPacket(bytes, l), nil) + + fmt.Println(b) +} diff --git a/matcher/wmi/wmi_test.go b/matcher/wmi/wmi_test.go index 9f0ff13..6113f5d 100644 --- a/matcher/wmi/wmi_test.go +++ b/matcher/wmi/wmi_test.go @@ -1,51 +1,51 @@ package wmi -//import ( -// "fmt" -// "git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/packet" -// "git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/scaninfo" -// "git.loafle.net/overflow/overflow_probe/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", ipport) -// -// 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, packet.NewPacket(bytes, read), scanInfo) -// -// if b { -// fmt.Println("Good") -// } -// -// } -// -// t.Log(scanInfo) -//} +import ( + "fmt" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + //"git.loafle.net/overflow/overflow_probe/collector/discovery/scan/matcher/scaninfo" + //"git.loafle.net/overflow/overflow_probe/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, packet.NewPacket(bytes, read), nil) + + if b { + fmt.Println("Good") + } + + } + + +}