cralwers integrated

This commit is contained in:
insanity@loafle.com 2017-04-13 12:19:07 +09:00
parent 0f6b8b1883
commit e6acfde823
51 changed files with 5338 additions and 0 deletions

5
.gitignore vendored
View File

@ -59,3 +59,8 @@ fabric.properties
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/ .glide/
.gitignore
ad_protocol_crawler.go
ad_protocol_crawler_test.go
.idea/
health_crawler/redis_protocol_crawler_go/.idea/

View File

@ -0,0 +1,27 @@
package activedirectory_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/activedirectory"
"loafle.com/overflow/crawler_go"
)
type ActiveDirectoryHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *ActiveDirectoryHealthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewActiveDirectoryHealthCrawler() *ActiveDirectoryHealthCrawler {
ad := &ActiveDirectoryHealthCrawler{}
ad.SetInternal(ad)
ad.SetMatcher(activedirectory.NewActiveDirectoryMatcher())
return ad
}

View File

@ -0,0 +1,109 @@
package activedirectory_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.1", 389, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckSSL(t *testing.T) {
// b, _ := check("192.168.1.1", 636, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.1", Port: 389, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}
func setConfig() crawler.Crawler {
r := NewActiveDirectoryHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.1"
m["port"] = "389"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}

View File

@ -0,0 +1,27 @@
package cassandra_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/cassandra"
"loafle.com/overflow/crawler_go"
)
type CassandraHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *CassandraHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewCassandraHealthCrawler() *CassandraHealthCrawler {
r := &CassandraHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(cassandra.NewCassandraMatcher())
return r
}

View File

@ -0,0 +1,104 @@
package cassandra_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewCassandraHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.104"
m["port"] = "9042"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.104", 9042, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: true}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.104", Port: 9042, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HeahthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,27 @@
package dns_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/dns"
"loafle.com/overflow/crawler_go"
)
type DNSHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *DNSHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewDNSHealthCrawler() *DNSHealthCrawler {
r := &DNSHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(dns.NewDnsMatcher())
return r
}

View File

@ -0,0 +1,104 @@
package dns_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewDNSHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "53"
m["portType"] = "udp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 53, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 53, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,123 @@
package ftp_protocol_crawler_go
import (
"log"
"loafle.com/overflow/commons_go/matcher/packet"
"loafle.com/overflow/commons_go/model/scaninfo"
)
const (
statusReadyServer = "120"
statusOK = "200"
statusNewConnectOK = "220"
statusSystemNameOK = "215"
statusCloseConnect = "221"
statusUnkownCMD = "202"
statusTlsUseOK = "234"
statusCloseControlConnect = "421"
statusSyntaxErr = "500"
statusParamSyntaxErr = "501"
statusNotUseCMD = "502"
statusIncorrectCMD = "503"
statusUserLoginRequied = "530"
statusTlsNotUse = "534"
statusNeedUserId = "332"
)
type FTPMatcher struct {
sendPackets []*packet.Packet
isFtps bool
}
func NewFTPMatcher() *FTPMatcher {
ftm := FTPMatcher{}
sysStr := "SYST\r\n"
systByte := make([]byte, len(sysStr))
copy(systByte[:], sysStr)
ftm.sendPackets = append(ftm.sendPackets, packet.NewPacket(systByte, len(sysStr)))
passStr := "PASS \r\n"
passByte := make([]byte, len(passStr))
copy(passByte[:], passStr)
ftm.sendPackets = append(ftm.sendPackets, packet.NewPacket(passByte, len(passStr)))
quitStr := "QUIT\r\n"
quitByte := make([]byte, len(quitStr))
copy(quitByte[:], quitStr)
ftm.sendPackets = append(ftm.sendPackets, packet.NewPacket(quitByte, len(quitStr)))
return &ftm
}
func (r *FTPMatcher) Match(idx int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
result := false
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
log.Println("Packet nil")
return result
}
str := string(packet.Buffer)
code := str[:3]
if idx == 0 {
switch code {
case statusNewConnectOK, statusReadyServer:
//fmt.Println(code)
result = true
break
}
} else if idx == 1 {
switch code {
case statusSystemNameOK, statusSyntaxErr, statusParamSyntaxErr, statusNotUseCMD, statusUserLoginRequied:
//fmt.Println(code)
result = true
break
}
} else if idx == 2 {
switch code {
case statusIncorrectCMD, statusParamSyntaxErr, statusNotUseCMD, statusNeedUserId, statusUserLoginRequied:
//fmt.Println(code)
result = true
break
}
} else if idx == 3 {
switch code {
case statusCloseConnect, statusSyntaxErr:
//fmt.Println(code)
result = true
break
}
}
return result
}
func (ftp *FTPMatcher) PacketCount() int {
return len(ftp.sendPackets)
}
func (ftp *FTPMatcher) Packet(index int) *packet.Packet {
return ftp.sendPackets[index]
}
func (ftp *FTPMatcher) ServiceName() string {
return "FTP"
}
func (ftp *FTPMatcher) IsError(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
return false
}
func (ftp *FTPMatcher) IsNoResponse(index int) bool {
return false
}
func (ftp *FTPMatcher) IsPrePacket() bool {
return true
}

View File

@ -0,0 +1,178 @@
package ftp_protocol_crawler_go
import (
"loafle.com/overflow/crawler_go"
"encoding/json"
)
type FTPHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *FTPHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewFTPHealthCrawler() *FTPHealthCrawler {
r := &FTPHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(NewFTPMatcher())
return r
}
////////////// Delegate.Get implement /////////////////
//type FTPProtocol struct{}
//
//func (r *FTPProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := ftp.NewFTPMatcher()
//
// bytes := make([]byte, 1024)
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
// if m.Match(0, p, nil) == false {
// return false, nil
// }
//
// for i := 0; i < m.PacketCount(); i++ {
//
// pack := m.Packet(i)
// conn.Write(pack.Buffer)
//
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
//
// if matchFtp(i+1, p) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func matchFtp(idx int, packet *packet.Packet) bool {
// result := false
//
// if packet == nil || packet.Buffer == nil || packet.Len == 0 {
// log.Println("Packet nil")
// return result
// }
//
// str := string(packet.Buffer)
//
// code := str[:3]
//
// if idx == 0 {
// switch code {
// case statusNewConnectOK, statusReadyServer:
// //fmt.Println(code)
// result = true
// break
// }
// } else if idx == 1 {
// switch code {
// case statusSystemNameOK, statusSyntaxErr, statusParamSyntaxErr, statusNotUseCMD, statusUserLoginRequied:
// //fmt.Println(code)
// result = true
// break
// }
// } else if idx == 2 {
// switch code {
// case statusIncorrectCMD, statusParamSyntaxErr, statusNotUseCMD, statusNeedUserId, statusUserLoginRequied:
// //fmt.Println(code)
// result = true
// break
// }
// } else if idx == 3 {
// switch code {
// case statusCloseConnect, statusSyntaxErr:
// //fmt.Println(code)
// result = true
// break
// }
// }
//
// return result
//}
//
//func start() {
//
// rpc.SetDelegate(new(FTPProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,94 @@
package ftp_protocol_crawler_go
import (
"loafle.com/overflow/crawler_go"
"testing"
"loafle.com/overflow/of_rpc_go/models/param"
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/of_rpc_go"
"log"
"time"
"loafle.com/overflow/of_rpc_go/client"
)
func setConfig() crawler.Crawler {
r := NewFTPHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "21"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ftp", m)
return r
}
func TestMatch(t *testing.T) {
r := setConfig()
out := param.Output{}
r.Get("ftp", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ftp", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ftp",
Id: "ftp",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 21, false)
// assert.Equal(t, true, b)
//}
//
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 21, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,76 @@
package ftps_protocol_crawler_go
import (
"loafle.com/overflow/commons_go/matcher/packet"
"loafle.com/overflow/commons_go/model/scaninfo"
)
const (
statusOK = "200"
statusNewConnectOK = "220"
)
type FTPSMatcher struct {
sendPackets []*packet.Packet
isFtps bool
}
func NewFTPSMatcher() *FTPSMatcher {
f := FTPSMatcher{}
pbs := "PBSZ 0\r\n"
pbsByte := make([]byte, len(pbs))
copy(pbsByte[:], pbs)
f.sendPackets = append(f.sendPackets, packet.NewPacket(pbsByte, len(pbs)))
prot := "PROT P\r\n"
protByte := make([]byte, len(prot))
copy(protByte[:], prot)
f.sendPackets = append(f.sendPackets, packet.NewPacket(protByte, len(prot)))
quitStr := "QUIT\r\n"
quitByte := make([]byte, len(quitStr))
copy(quitByte[:], quitStr)
f.sendPackets = append(f.sendPackets, packet.NewPacket(quitByte, len(quitStr)))
return &f
}
func (ftp *FTPSMatcher) Match(idx int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
result := false
str := string(packet.Buffer)
code := str[:3]
if code == statusOK || code == statusNewConnectOK {
result = true
}
return result
}
func (ftp *FTPSMatcher) PacketCount() int {
return len(ftp.sendPackets)
}
func (ftp *FTPSMatcher) Packet(index int) *packet.Packet {
return ftp.sendPackets[index]
}
func (ftp *FTPSMatcher) ServiceName() string {
return "FTPS"
}
func (ftp *FTPSMatcher) IsError(index int, packet *packet.Packet, info scaninfo.ServiceScanInfo) bool {
return false
}
func (ftp *FTPSMatcher) IsNoResponse(index int) bool {
return false
}
func (ftp *FTPSMatcher) IsPrePacket() bool {
return true
}

View File

@ -0,0 +1,69 @@
package ftps_protocol_crawler_go
import (
"loafle.com/overflow/crawler_go"
"encoding/json"
"loafle.com/overflow/commons_go/matcher/ftp"
)
type FTPSHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *FTPSHealthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewFTPSHealthCrawler() *FTPSHealthCrawler {
r := &FTPSHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(ftp.NewFTPMatcher())
return r
}
////////////// Delegate.Get implement /////////////////
//type FTPSProtocol struct{}
//
//func (r *FTPSProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := ftp.StartCheckFTPS(input.Ip, strconv.Itoa(int(input.Port)))
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(FTPSProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,88 @@
package ftps_protocol_crawler_go
import (
"loafle.com/overflow/crawler_go"
"testing"
"loafle.com/overflow/of_rpc_go/models/param"
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/of_rpc_go"
"log"
"time"
"loafle.com/overflow/of_rpc_go/client"
)
func setConfig() crawler.Crawler {
r := NewFTPSHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.103"
m["port"] = "2121"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ftps", m)
return r
}
func TestMatch(t *testing.T) {
r := setConfig()
out := param.Output{}
r.Get("ftps", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ftps", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ftps",
Id: "ftps",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 21, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, false, m.IsMatch)
//}

View File

@ -0,0 +1,119 @@
package http_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/http"
"loafle.com/overflow/crawler_go"
)
type HTTPHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *HTTPHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewHTTPHealthCrawler() *HTTPHealthCrawler {
r := &HTTPHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(http.NewHTTPMatcher())
return r
}
//package main
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "log"
// "loafle.com/overflow/of_rpc/models/protocol"
// rpc "loafle.com/overflow/of_rpc/json"
// "encoding/json"
// "strconv"
// "net"
// "loafle.com/overflow/collector/core/scan/service/matcher/http"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// "loafle.com/overflow/collector/discovery/types/timestamp"
//)
//
//type HttpProtocol struct {
//
//}
//
//func (h *HttpProtocol) Get(input *param.Input, output *param.Output) error {
//
// log.Println("data : " + string(input.Data))
// pr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &pr)
//
// output.StartDate = timestamp.Now()
// match, err := check(input.Ip, input.Port)
//
// if err != nil {
// log.Println(err.Error())
// return err
// }
// output.EndDate = timestamp.Now()
//
// rres := &protocol.HealthResponse{IsMatch:match}
//
// b, err := json.Marshal(&rres)
//
// if err != nil {
// log.Println(err.Error())
// return err
// }
//
// *output = param.Output{Data:b}
//
// return nil
//}
//
//func check(ip string, port uint16) (bool,error) {
//
// var targetHost string = ip
// targetHost += ":"
// targetHost += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", targetHost)
//
//
// if err != nil {
// return false, err
// }
// defer conn.Close()
// hp := http.NewHTTPMatcher()
//
// for i := 0; i < hp.PacketCount(); i++ {
// pack := hp.Packet(i)
// conn.Write(pack.Buffer)
//
// bytes := make([]byte, 1024)
// l, _ := conn.Read(bytes)
//
// p := packet.NewPacket(bytes, l)
//
// if hp.Match(i, p, nil) == false{
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(HttpProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,87 @@
package http_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewHTTPHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.105"
m["port"] = "80"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package main
//
//import (
// "testing"
// "github.com/stretchr/testify/assert"
//)
//
//func TestHttpProtocol_Get(t *testing.T) {
// b, err := check("192.168.1.105", 80)
// if err != nil {
// t.Error(err)
// }
// assert.Equal(t, true, b)
//}

View File

@ -0,0 +1,128 @@
package imap_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/imap"
"loafle.com/overflow/crawler_go"
)
type IMAPHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *IMAPHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewIMAPHealthCrawler() *IMAPHealthCrawler {
r := &IMAPHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(imap.NewIMAPMatcher())
return r
}
//package imap
//
//import (
// "crypto/tls"
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/imap"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type ImapProtocol struct{}
//
//func (r *ImapProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := imap.NewIMAPMatcher()
//
// 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) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(ImapProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,110 @@
package imap_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewIMAPHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "993"
m["portType"] = "tcp"
m["ssl"] = true
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 143, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckSSL(t *testing.T) {
// b, _ := check("192.168.1.215", 993, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 143, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,131 @@
package ldap_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/ldap"
"loafle.com/overflow/crawler_go"
)
type LDAPHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *LDAPHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewLDAPHealthCrawler() *LDAPHealthCrawler {
r := &LDAPHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(ldap.NewLDAPMatcher())
return r
}
//
//import (
// "crypto/tls"
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/ldap"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type LDAPProtocol struct{}
//
//func (r *LDAPProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := ldap.NewLDAPMatcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(LDAPProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,110 @@
package ldap_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewLDAPHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "389"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 389, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckSSL(t *testing.T) {
// b, _ := check("192.168.1.215", 636, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 389, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,127 @@
package mongodb_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/mongodb"
"loafle.com/overflow/crawler_go"
)
type MongoDBHealthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *MongoDBHealthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewMongoDBHealthCrawler() *MongoDBHealthCrawler {
r := &MongoDBHealthCrawler{}
r.SetInternal(r)
r.SetMatcher(mongodb.NewMongoDBMatcher())
return r
}
//import (
// "crypto/tls"
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/mongodb"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type MongoDBProtocol struct{}
//
//func (r *MongoDBProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := mongodb.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 := packet.NewPacket(bytes, n)
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
//
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(MongoDBProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,105 @@
package mongodb_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewMongoDBHealthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.104"
m["port"] = "27017"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("ad", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("ad", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("ad", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "ad",
Id: "ad",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.104", 27017, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: true}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.104", Port: 27017, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,103 @@
package mssql_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/mssql"
"loafle.com/overflow/crawler_go"
)
type MSSqlHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *MSSqlHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewMSSqlHeahthCrawler() *MSSqlHeahthCrawler {
r := &MSSqlHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(mssql.NewMSSqlMatcher())
return r
}
//
//import (
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
// "loafle.com/overflow/collector/core/scan/service/matcher/mssql"
//)
//
//////////////// Delegate.Get implement /////////////////
//type MSSQLProtocol struct{}
//
//func (r *MSSQLProtocol) Get(input *param.Input, output *param.Output) error {
//
// log.Println("data : " + string(input.Data))
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func check(ip string, port uint16) (bool, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := mssql.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 := packet.NewPacket(bytes, n)
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(MSSQLProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,88 @@
package mssql_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewMSSqlHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.106"
m["port"] = "1433"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "testing"
// "github.com/stretchr/testify/assert"
//)
//
//func TestMatch(t *testing.T) {
// b, err := check("192.168.1.106", 1433)
// if err != nil {
// t.Error(err)
// }
// assert.Equal(t, true, b)
//}

View File

@ -0,0 +1,106 @@
package mysql_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/mysql"
"loafle.com/overflow/crawler_go"
)
type MysqlHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *MysqlHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewMysqlHeahthCrawler() *MysqlHeahthCrawler {
r := &MysqlHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(mysql.NewMySqlMatcher())
return r
}
//
//import (
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/mysql"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type MySQLProtocol struct{}
//
//func (r *MySQLProtocol) Get(input *param.Input, output *param.Output) error {
//
// log.Println("data : " + string(input.Data))
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func check(ip string, port uint16) (bool, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := mysql.NewMySqlMatcher()
//
// 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) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(MySQLProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,88 @@
package mysql_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewMysqlHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.103"
m["port"] = "3306"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("redis", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("redis", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("redis", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "redis",
Id: "redis",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "github.com/stretchr/testify/assert"
// "testing"
//)
//
//func TestMatch(t *testing.T) {
// b, err := check("192.168.1.103", 3306)
// if err != nil {
// t.Error(err)
// }
// assert.Equal(t, true, b)
//}

View File

@ -0,0 +1,108 @@
package netbios_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/netbios"
"loafle.com/overflow/crawler_go"
)
type NetbiosHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *NetbiosHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewNetbiosHeahthCrawler() *NetbiosHeahthCrawler {
r := &NetbiosHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(netbios.NewNetBiosMatcher())
return r
}
//import (
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
// "loafle.com/overflow/collector/core/scan/service/matcher/netbios"
//)
//
//////////////// Delegate.Get implement /////////////////
//type NetBiosProtocol struct{}
//
//func (r *NetBiosProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := netbios.NewNetBiosMatcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(NetBiosProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,108 @@
package netbios_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewNetbiosHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.106"
m["port"] = "139"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.106", 139, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.106", Port: 139, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,146 @@
package oracle_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/oracle"
"loafle.com/overflow/crawler_go"
)
type OracleHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *OracleHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewOracleHeahthCrawler() *OracleHeahthCrawler {
r := &OracleHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(oracle.NewOracleMatcher())
return r
}
//package oracle_protocol_crawler
//
//
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
// "crypto/tls"
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/oracle"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type OracleProtocol struct{}
//
//func (r *OracleProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := oracle.NewOracleMatcher()
//
// 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) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(OracleProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,130 @@
package oracle_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewOracleHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.30"
m["port"] = "1521"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "testing"
// "github.com/stretchr/testify/assert"
//)
//
//func TestMatch(t *testing.T) {
// b, err := check("192.168.1.106", 1433)
// if err != nil {
// t.Error(err)
// }
// assert.Equal(t, true, b)
//}
//package oracle_protocol_crawler
//
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.30", 1521, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckTls(t *testing.T) {
// b, _ := check("192.168.1.215", 22, true)
// assert.Equal(t, true, b)
//}
//
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.30", Port: 1521, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,104 @@
package pgsql_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/pgsql"
"loafle.com/overflow/crawler_go"
)
type PGSqlHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *PGSqlHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewPGSqlHeahthCrawler() *PGSqlHeahthCrawler {
r := &PGSqlHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(pgsql.NewPostgreSQLMatcher())
return r
}
//
//import (
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
// "loafle.com/overflow/collector/core/scan/service/matcher/mssql"
//)
//
//////////////// Delegate.Get implement /////////////////
//type PGSQLProtocol struct{}
//
//func (r *PGSQLProtocol) Get(input *param.Input, output *param.Output) error {
//
// log.Println("data : " + string(input.Data))
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func check(ip string, port uint16) (bool, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := mssql.NewPGSqlMatcher()
//
// 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) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(PGSQLProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,88 @@
package pgsql_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewPGSqlHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.107"
m["port"] = "5432"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//
//import (
// "testing"
// "github.com/stretchr/testify/assert"
//)
//
//func TestMatch(t *testing.T) {
// b, err := check("192.168.1.106", 1433)
// if err != nil {
// t.Error(err)
// }
// assert.Equal(t, true, b)
//}

View File

@ -0,0 +1,129 @@
package pop3_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/pop"
"loafle.com/overflow/crawler_go"
)
type POP3HeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *POP3HeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewPOP3HeahthCrawler() *POP3HeahthCrawler {
r := &POP3HeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(pop.NewPOPMatcher())
return r
}
//package pop3
//
//import (
// "crypto/tls"
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// "loafle.com/overflow/collector/core/scan/service/matcher/pop"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type Pop3Protocol struct{}
//
//func (r *Pop3Protocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
// //
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := pop.NewPOPMatcher()
//
// 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) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(Pop3Protocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,114 @@
package pop3_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewPOP3HeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "110"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package pop3
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 110, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckSSL(t *testing.T) {
// b, _ := check("192.168.1.215", 995, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 143, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,27 @@
package redis_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/redis"
"loafle.com/overflow/crawler_go"
)
type RedisHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *RedisHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewRedisHeahthCrawler() *RedisHeahthCrawler {
r := &RedisHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(redis.NewRedisMatcher())
return r
}

View File

@ -0,0 +1,72 @@
package redis_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewRedisHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.104"
m["port"] = "6379"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("redis", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("redis", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("redis", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "redis",
Id: "redis",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}

View File

@ -0,0 +1,106 @@
package rmi_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/rmi"
"loafle.com/overflow/crawler_go"
)
type RMIHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *RMIHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewRMIHeahthCrawler() *RMIHeahthCrawler {
r := &RMIHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(rmi.NewRMIMatcher())
return r
}
//package imap
//
//import (
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// "loafle.com/overflow/collector/core/scan/service/matcher/rmi"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type RMIProtocol struct{}
//
//func (r *RMIProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := rmi.NewRMIMatcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(RMIProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,107 @@
package rmi_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewRMIHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.103"
m["port"] = "9840"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package imap
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.103", 9840, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.103", Port: 9840, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,149 @@
package smb_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/smb"
"loafle.com/overflow/crawler_go"
)
type SMBHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *SMBHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewSMBHeahthCrawler() *SMBHeahthCrawler {
r := &SMBHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(smb.NewSMBMatcher())
return r
}
//package smb_protocol_crawler
//
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
//
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/smb"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
// "crypto/tls"
//)
//
//////////////// Delegate.Get implement /////////////////
//type SMBProtocol struct{}
//
//func (r *SMBProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := smb.NewSMBMatcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(SMBProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,110 @@
package smb_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewSMBHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.106"
m["port"] = "445"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package smb_protocol_crawler
//
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.106", 445, false)
// assert.Equal(t, true, b)
//}
//
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.106", Port: 445, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,136 @@
package smtp_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/smtp"
"loafle.com/overflow/crawler_go"
)
type SMTPHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *SMTPHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewSMTPHeahthCrawler() *SMTPHeahthCrawler {
r := &SMTPHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(smtp.NewSmtpMatcher())
return r
}
//package smtp
//
//import (
// "crypto/tls"
// "encoding/json"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// "loafle.com/overflow/collector/core/scan/service/matcher/smtp"
// rpc "loafle.com/overflow/of_rpc/json"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "log"
// "net"
// "strconv"
//)
//
//////////////// Delegate.Get implement /////////////////
//type SMTPProtocol struct{}
//
//func (r *SMTPProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// rres := &protocol.HealthResponse{IsMatch: match}
//
// b, err := json.Marshal(&rres)
// if err != nil {
// return err
// }
// *output = param.Output{Data: b}
// return nil
//}
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := smtp.NewSmtpMatcher()
//
// bytes := make([]byte, 1024)
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
// if m.Match(0, p, nil) == false {
// return false, nil
// }
//
// for i := 0; i < m.PacketCount(); i++ {
//
// pack := m.Packet(i)
// conn.Write(pack.Buffer)
//
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
//
// if m.Match(i+1, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
// rpc.SetDelegate(new(SMTPProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,112 @@
package smtp_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewSMTPHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "25"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package smtp
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 25, false)
// assert.Equal(t, true, b)
//}
//
//func TestCheckSSL(t *testing.T) {
// b, _ := check("192.168.1.215", 465, true)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 25, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,137 @@
package snmpv2c_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/snmp"
"loafle.com/overflow/crawler_go"
)
type SNMPV2CHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *SNMPV2CHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewSNMPV2CHeahthCrawler() *SNMPV2CHeahthCrawler {
r := &SNMPV2CHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(snmp.NewSNMPv2Matcher())
return r
}
//package snmpv2c_protocol_crawler
//
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
//
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/snmp"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type SNMPv2cProtocol struct{}
//
//func (r *SNMPv2cProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("udp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//
// return nil, nil
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := snmp.NewSNMPv2Matcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(SNMPv2cProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,108 @@
package snmpv2c_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewSNMPV2CHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "161"
m["portType"] = "udp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package snmpv2c_protocol_crawler
//
//import (
// "github.com/stretchr/testify/assert"
// "time"
// "loafle.com/overflow/of_rpc/models/protocol"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/json/client"
// "testing"
// "encoding/json"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 161, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 161, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,136 @@
package snmpv3_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/snmp"
"loafle.com/overflow/crawler_go"
)
type SNMPV3HeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *SNMPV3HeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewSNMPV3HeahthCrawler() *SNMPV3HeahthCrawler {
r := &SNMPV3HeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(snmp.NewSNMPv3Matcher())
return r
}
//package snmpv3_protocol_crawler
//
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
//
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/snmp"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type SNMPv3Protocol struct{}
//
//func (r *SNMPv3Protocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("udp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//
// return nil, nil
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := snmp.NewSNMPv3Matcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(SNMPv3Protocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,107 @@
package snmpv3_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewSNMPV3HeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.254"
m["port"] = "161"
m["portType"] = "udp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package snmpv3_protocol_crawler
//
//import (
// "github.com/stretchr/testify/assert"
// "time"
// "loafle.com/overflow/of_rpc/models/protocol"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/json/client"
// "testing"
// "encoding/json"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.254", 161, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.254", Port: 161, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,151 @@
package ssh_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/ssh"
"loafle.com/overflow/crawler_go"
)
type SSHHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *SSHHeahthCrawler) Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewSSHHeahthCrawler() *SSHHeahthCrawler {
r := &SSHHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(ssh.NewSSHMatcher())
return r
}
//package ssh_protocol_crawler
//
//
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
// "crypto/tls"
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/ssh"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type SSHProtocol struct{}
//
//func (r *SSHProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := ssh.NewSSHMatcher()
//
// bytes := make([]byte, 1024)
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
// if m.Match(0, p, nil) == false {
// return false, nil
// }
//
// for i := 0; i < m.PacketCount(); i++ {
//
// pack := m.Packet(i)
// conn.Write(pack.Buffer)
//
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
//
// if m.Match(i+1, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(SSHProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,108 @@
package ssh_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewSSHHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "22"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package ssh_protocol_crawler
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 22, false)
// assert.Equal(t, true, b)
//}
//
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 22, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,150 @@
package telnet_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/telnet"
"loafle.com/overflow/crawler_go"
)
type TelnetHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *TelnetHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewTelnetHeahthCrawler() *TelnetHeahthCrawler {
r := &TelnetHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(telnet.NewTelnetMatcher())
return r
}
//package main
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
// "crypto/tls"
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/telnet"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type TelnetProtocol struct{}
//
//func (r *TelnetProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// match, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = match
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := telnet.NewTelnetMatcher()
//
// bytes := make([]byte, 1024)
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
// if m.Match(0, p, nil) == false {
// return false, nil
// }
//
// for i := 0; i < m.PacketCount(); i++ {
//
// pack := m.Packet(i)
// conn.Write(pack.Buffer)
//
// n, _ := conn.Read(bytes)
// p := packet.NewPacket(bytes, n)
//
// if m.Match(i+1, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(TelnetProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,108 @@
package telnet_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewTelnetHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.215"
m["port"] = "23"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package main
//
//
//import (
// "encoding/json"
// "github.com/stretchr/testify/assert"
// "loafle.com/overflow/of_rpc/json/client"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/models/protocol"
// "testing"
// "time"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.215", 23, false)
// assert.Equal(t, true, b)
//}
//
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.215", Port: 23, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}

View File

@ -0,0 +1,147 @@
package wmi_protocol_crawler_go
import (
"encoding/json"
"loafle.com/overflow/commons_go/matcher/wmi"
"loafle.com/overflow/crawler_go"
)
type WMIHeahthCrawler struct {
crawler.SocketHeahthCrawler
}
func (r *WMIHeahthCrawler)Internal(params map[string]interface{}) ([]byte, error) {
b, err := r.CheckHeahth(params)
if err != nil {
// set error
}
return json.Marshal(b)
}
func NewWMIHeahthCrawler() *WMIHeahthCrawler {
r := &WMIHeahthCrawler{}
r.SetInternal(r)
r.SetMatcher(wmi.NewWMIMatcher())
return r
}
//package wmi_protocol_crawler
//
//import (
// "loafle.com/overflow/of_rpc/models/param"
// "encoding/json"
// "loafle.com/overflow/of_rpc/models/protocol"
// "strconv"
// "crypto/tls"
// "net"
//
// "loafle.com/overflow/collector/core/scan/service/matcher/wmi"
// "loafle.com/overflow/collector/core/scan/service/matcher/packet"
// rpc "loafle.com/overflow/of_rpc/json"
//
// "log"
//)
//
//////////////// Delegate.Get implement /////////////////
//type WMIProtocol struct{}
//
//func (r *WMIProtocol) Get(input *param.Input, output *param.Output) error {
//
// rr := &protocol.HealthRequest{}
// json.Unmarshal(input.Data, &rr)
//
// rres, err := check(input.Ip, input.Port, rr.IsSSL)
//
// if err != nil {
// return err
// }
//
//
// retVal := &protocol.HealthResponse{}
// retVal.IsMatch = rres
//
// b, err := json.Marshal(retVal)
//
// if err != nil {
// return err
// }
//
// *output = param.Output{Data: b}
// return nil
//}
//
//
//func connect(ip string, port uint16, ssl bool) (net.Conn, error) {
//
// var addr string = ip
// addr += ":"
// addr += strconv.Itoa(int(port))
//
// if ssl == false {
// conn, err := net.Dial("tcp", addr)
// if err != nil {
// return nil, err
// }
// return conn, nil
// } else {
// conn, err := tls.Dial(
// "tcp",
// addr,
// &tls.Config{
// InsecureSkipVerify: true,
// ServerName: ip,
// },
// )
// if err != nil {
// return nil, err
// }
// return conn, nil
// }
//}
//
//
//
//func check(ip string, port uint16, ssl bool) (bool, error) {
//
// conn, err := connect(ip, port, ssl)
// if err != nil {
// return false, err
// }
// defer conn.Close()
//
// m := wmi.NewWMIMatcher()
//
// 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.IsNoResponse(i) == true { // empty last response
// break
// }
//
// if m.Match(i, p, nil) == false {
// return false, nil
// }
// }
//
// return true, nil
//}
//
//func start() {
//
// rpc.SetDelegate(new(WMIProtocol))
// err := rpc.StartJSONRPC()
// if err != nil {
// log.Fatal(err)
// }
//}
//
//func main() {
// start()
//}

View File

@ -0,0 +1,107 @@
package wmi_protocol_crawler_go
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"loafle.com/overflow/crawler_go"
"loafle.com/overflow/of_rpc_go"
"loafle.com/overflow/of_rpc_go/client"
"loafle.com/overflow/of_rpc_go/models/param"
"log"
"testing"
"time"
)
func setConfig() crawler.Crawler {
r := NewWMIHeahthCrawler()
m := make(map[string]interface{}, 0)
m["ip"] = "192.168.1.1"
m["port"] = "135"
m["portType"] = "tcp"
m["ssl"] = false
r.PutConfig("r", m)
return r
}
func TestMatch(t *testing.T) {
// test config
r := setConfig()
out := param.Output{}
r.Get("r", &out)
var check bool
json.Unmarshal(out.Data, &check)
assert.Equal(t, true, check)
}
func start() {
r := setConfig()
of_rpc.AddDelegate("r", r)
err := of_rpc.StartJSONRPC()
if err != nil {
log.Fatal(err)
}
}
func TestRPC(t *testing.T) {
go start()
time.Sleep(2 * time.Second)
in := param.Input{
Name: "r",
Id: "r",
}
result, err := client.InvokeJSONRPCGet("50000", in)
if err != nil {
t.Fatal(err)
}
var check bool
json.Unmarshal(result.Data, &check)
assert.Equal(t, true, check)
}
//package wmi_protocol_crawler
//
//import (
// "github.com/stretchr/testify/assert"
// "time"
// "loafle.com/overflow/of_rpc/models/protocol"
// "loafle.com/overflow/of_rpc/models/param"
// "loafle.com/overflow/of_rpc/json/client"
// "testing"
// "encoding/json"
//)
//
//func TestCheck(t *testing.T) {
// b, _ := check("192.168.1.1", 135, false)
// assert.Equal(t, true, b)
//}
//
//func TestRPC(t *testing.T) {
//
// go start()
// time.Sleep(time.Second * 2)
//
// p := protocol.HealthRequest{IsSSL: false}
// b, _ := json.Marshal(p)
//
// in := param.Input{Ip: "192.168.1.1", Port: 135, Data: b}
//
// re, _ := client.InvokeJSONRPC("50000", in)
// var m protocol.HealthResponse
// json.Unmarshal(re.Data, &m)
//
// assert.Equal(t, true, m.IsMatch)
//}