diff --git a/crawler/crawler.go b/crawler/crawler.go new file mode 100644 index 0000000..b81a494 --- /dev/null +++ b/crawler/crawler.go @@ -0,0 +1,79 @@ +package crawler + +import ( + "encoding/json" + "errors" + + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" + "log" +) + +type Internal interface { + Internal(params config.Config) ([]byte, error) +} + +type Crawler interface { + Init(path []byte) ([]byte, error) + Add(data []byte) ([]byte, error) + Remove(id string) ([]byte, error) + Get(id string) ([]byte, error) +} + +type CrawlerImpl struct { + Crawler + configs map[string]config.Config + internal Internal +} + +func (c *CrawlerImpl) Init(data []byte) ([]byte, error) { + if c.configs == nil { + c.configs = make(map[string]config.Config, 0) + } + + _, err := c.Add(data) + + if err != nil { + log.Fatal(err) + } + + // load all file in path + return json.Marshal(true) +} +func (c *CrawlerImpl) Add(data []byte) ([]byte, error) { + + var m = config.Config{} + json.Unmarshal(data, &m) + c.configs[m.Id] = m + + return json.Marshal(true) +} +func (c *CrawlerImpl) Remove(id string) ([]byte, error) { + //remove in config + delete(c.configs, id) + return json.Marshal(true) +} +func (c *CrawlerImpl) Get(id string) ([]byte, error) { + if c.internal != nil { + out, err := c.internal.Internal(c.GetConfig(id)) + if err != nil { + //set error fail, message + return nil, err + } + return out, nil + } + return nil, errors.New("Not Assigned") +} + +// internal methods +func (c *CrawlerImpl) GetConfig(id string) config.Config { + return c.configs[id] +} +func (c *CrawlerImpl) SetInternal(i Internal) { + c.internal = i +} +func (c *CrawlerImpl) PutConfig(name string, m config.Config) { + if c.configs == nil { + c.configs = make(map[string]config.Config, 0) + } + c.configs[name] = m +} diff --git a/crawler/crawler_generalization_test.go b/crawler/crawler_generalization_test.go new file mode 100644 index 0000000..5c594ed --- /dev/null +++ b/crawler/crawler_generalization_test.go @@ -0,0 +1,47 @@ +package crawler + +import ( + "fmt" + "testing" +) + +type Super interface { + Method() +} + +type sss struct{} + +func (s *sss) Method() { + fmt.Println("Super") +} + +type Child struct { + sss +} + +func (c *Child) Method() { + c.sss.Method() + fmt.Println("Child") +} + +func TestGene(t *testing.T) { + c := Child{} + c.Method() + + var s Super = &Child{} + s.Method() + +} + +func TestExistInterface(t *testing.T) { + + m := make(map[string]Super, 0) + m["test"] = &Child{} + + _, ok := m["test1"] + if ok { + fmt.Println(ok) + } else { + fmt.Println(ok) + } +} diff --git a/crawler/crawler_map_convert_test.go b/crawler/crawler_map_convert_test.go new file mode 100644 index 0000000..adf4b26 --- /dev/null +++ b/crawler/crawler_map_convert_test.go @@ -0,0 +1,19 @@ +package crawler + +import ( + "fmt" + "testing" +) + +func TestInterfaceValueToTypeCast(t *testing.T) { + + m := make(map[string]interface{}) + + m["a"] = "1" + m["b"] = 2 + m["c"] = false + + fmt.Println(m["a"].(string)) + fmt.Println(m["b"].(int)) + fmt.Println(m["c"].(bool)) +} diff --git a/crawler/grpc/cmd.txt b/crawler/grpc/cmd.txt new file mode 100644 index 0000000..d41c703 --- /dev/null +++ b/crawler/grpc/cmd.txt @@ -0,0 +1 @@ +protoc -I grpc/ grpc/grpc.proto --go_out=plugins=grpc:grpc \ No newline at end of file diff --git a/crawler/grpc/grpc.pb.go b/crawler/grpc/grpc.pb.go new file mode 100644 index 0000000..1bd1352 --- /dev/null +++ b/crawler/grpc/grpc.pb.go @@ -0,0 +1,612 @@ +// Code generated by protoc-gen-go. +// source: grpc.proto +// DO NOT EDIT! + +/* +Package grpc is a generated protocol buffer package. + +It is generated from these files: + grpc.proto + +It has these top-level messages: + Empty + Boolean + InputArray + Init + Input + InputAdd + Output +*/ +package grpc + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc1 "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type Crawlers int32 + +const ( + Crawlers_HEALTH_ACTIVEDIRECTORY Crawlers = 0 + Crawlers_HEALTH_DNS Crawlers = 1 + Crawlers_HEALTH_FTP Crawlers = 2 + Crawlers_HEALTH_FTPS Crawlers = 3 + Crawlers_HEALTH_IMAP Crawlers = 4 + Crawlers_HEALTH_LDAP Crawlers = 5 + Crawlers_HEALTH_MONGODB Crawlers = 6 + Crawlers_HEALTH_MSSQL Crawlers = 7 + Crawlers_HEALTH_MYSQL Crawlers = 8 + Crawlers_HEALTH_MARIADB Crawlers = 9 + Crawlers_HEALTH_PGSQL Crawlers = 10 + Crawlers_HEALTH_NETBIOS Crawlers = 11 + Crawlers_HEALTH_ORACLE Crawlers = 12 + Crawlers_HEALTH_POP3 Crawlers = 13 + Crawlers_HEALTH_REDIS Crawlers = 14 + Crawlers_HEALTH_RMI Crawlers = 15 + Crawlers_HEALTH_SMB Crawlers = 16 + Crawlers_HEALTH_SMTP Crawlers = 17 + Crawlers_HEALTH_SNMPV2C Crawlers = 18 + Crawlers_HEALTH_SNMPV3 Crawlers = 19 + Crawlers_HEALTH_SSH Crawlers = 20 + Crawlers_HEALTH_TELNET Crawlers = 21 + Crawlers_HEALTH_WMI Crawlers = 22 + Crawlers_HEALTH_CASSANDRA Crawlers = 23 + Crawlers_HEALTH_HTTP Crawlers = 24 + Crawlers_SQL Crawlers = 25 + Crawlers_SNMP Crawlers = 26 + Crawlers_WMI Crawlers = 27 + Crawlers_JMX Crawlers = 28 + Crawlers_REDIS Crawlers = 29 + Crawlers_MONGODB Crawlers = 30 +) + +var Crawlers_name = map[int32]string{ + 0: "HEALTH_ACTIVEDIRECTORY", + 1: "HEALTH_DNS", + 2: "HEALTH_FTP", + 3: "HEALTH_FTPS", + 4: "HEALTH_IMAP", + 5: "HEALTH_LDAP", + 6: "HEALTH_MONGODB", + 7: "HEALTH_MSSQL", + 8: "HEALTH_MYSQL", + 9: "HEALTH_MARIADB", + 10: "HEALTH_PGSQL", + 11: "HEALTH_NETBIOS", + 12: "HEALTH_ORACLE", + 13: "HEALTH_POP3", + 14: "HEALTH_REDIS", + 15: "HEALTH_RMI", + 16: "HEALTH_SMB", + 17: "HEALTH_SMTP", + 18: "HEALTH_SNMPV2C", + 19: "HEALTH_SNMPV3", + 20: "HEALTH_SSH", + 21: "HEALTH_TELNET", + 22: "HEALTH_WMI", + 23: "HEALTH_CASSANDRA", + 24: "HEALTH_HTTP", + 25: "SQL", + 26: "SNMP", + 27: "WMI", + 28: "JMX", + 29: "REDIS", + 30: "MONGODB", +} +var Crawlers_value = map[string]int32{ + "HEALTH_ACTIVEDIRECTORY": 0, + "HEALTH_DNS": 1, + "HEALTH_FTP": 2, + "HEALTH_FTPS": 3, + "HEALTH_IMAP": 4, + "HEALTH_LDAP": 5, + "HEALTH_MONGODB": 6, + "HEALTH_MSSQL": 7, + "HEALTH_MYSQL": 8, + "HEALTH_MARIADB": 9, + "HEALTH_PGSQL": 10, + "HEALTH_NETBIOS": 11, + "HEALTH_ORACLE": 12, + "HEALTH_POP3": 13, + "HEALTH_REDIS": 14, + "HEALTH_RMI": 15, + "HEALTH_SMB": 16, + "HEALTH_SMTP": 17, + "HEALTH_SNMPV2C": 18, + "HEALTH_SNMPV3": 19, + "HEALTH_SSH": 20, + "HEALTH_TELNET": 21, + "HEALTH_WMI": 22, + "HEALTH_CASSANDRA": 23, + "HEALTH_HTTP": 24, + "SQL": 25, + "SNMP": 26, + "WMI": 27, + "JMX": 28, + "REDIS": 29, + "MONGODB": 30, +} + +func (x Crawlers) String() string { + return proto.EnumName(Crawlers_name, int32(x)) +} +func (Crawlers) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +type Empty struct { +} + +func (m *Empty) Reset() { *m = Empty{} } +func (m *Empty) String() string { return proto.CompactTextString(m) } +func (*Empty) ProtoMessage() {} +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +type Boolean struct { + Check bool `protobuf:"varint,1,opt,name=check" json:"check,omitempty"` +} + +func (m *Boolean) Reset() { *m = Boolean{} } +func (m *Boolean) String() string { return proto.CompactTextString(m) } +func (*Boolean) ProtoMessage() {} +func (*Boolean) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *Boolean) GetCheck() bool { + if m != nil { + return m.Check + } + return false +} + +type InputArray struct { + In []*Init `protobuf:"bytes,1,rep,name=in" json:"in,omitempty"` +} + +func (m *InputArray) Reset() { *m = InputArray{} } +func (m *InputArray) String() string { return proto.CompactTextString(m) } +func (*InputArray) ProtoMessage() {} +func (*InputArray) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *InputArray) GetIn() []*Init { + if m != nil { + return m.In + } + return nil +} + +type Init struct { + Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *Init) Reset() { *m = Init{} } +func (m *Init) String() string { return proto.CompactTextString(m) } +func (*Init) ProtoMessage() {} +func (*Init) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func (m *Init) GetName() Crawlers { + if m != nil { + return m.Name + } + return Crawlers_HEALTH_ACTIVEDIRECTORY +} + +func (m *Init) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +type Input struct { + Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id" json:"id,omitempty"` +} + +func (m *Input) Reset() { *m = Input{} } +func (m *Input) String() string { return proto.CompactTextString(m) } +func (*Input) ProtoMessage() {} +func (*Input) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } + +func (m *Input) GetName() Crawlers { + if m != nil { + return m.Name + } + return Crawlers_HEALTH_ACTIVEDIRECTORY +} + +func (m *Input) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +type InputAdd struct { + Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *InputAdd) Reset() { *m = InputAdd{} } +func (m *InputAdd) String() string { return proto.CompactTextString(m) } +func (*InputAdd) ProtoMessage() {} +func (*InputAdd) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } + +func (m *InputAdd) GetName() Crawlers { + if m != nil { + return m.Name + } + return Crawlers_HEALTH_ACTIVEDIRECTORY +} + +func (m *InputAdd) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +// response models +type Output struct { + StartDate int64 `protobuf:"varint,1,opt,name=startDate" json:"startDate,omitempty"` + EndDate int64 `protobuf:"varint,2,opt,name=endDate" json:"endDate,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` +} + +func (m *Output) Reset() { *m = Output{} } +func (m *Output) String() string { return proto.CompactTextString(m) } +func (*Output) ProtoMessage() {} +func (*Output) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } + +func (m *Output) GetStartDate() int64 { + if m != nil { + return m.StartDate + } + return 0 +} + +func (m *Output) GetEndDate() int64 { + if m != nil { + return m.EndDate + } + return 0 +} + +func (m *Output) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func init() { + proto.RegisterType((*Empty)(nil), "Empty") + proto.RegisterType((*Boolean)(nil), "Boolean") + proto.RegisterType((*InputArray)(nil), "InputArray") + proto.RegisterType((*Init)(nil), "Init") + proto.RegisterType((*Input)(nil), "Input") + proto.RegisterType((*InputAdd)(nil), "InputAdd") + proto.RegisterType((*Output)(nil), "Output") + proto.RegisterEnum("Crawlers", Crawlers_name, Crawlers_value) +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc1.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc1.SupportPackageIsVersion4 + +// Client API for Config service + +type ConfigClient interface { + Add(ctx context.Context, in *InputAdd, opts ...grpc1.CallOption) (*Output, error) + Remove(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) + Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error) +} + +type configClient struct { + cc *grpc1.ClientConn +} + +func NewConfigClient(cc *grpc1.ClientConn) ConfigClient { + return &configClient{cc} +} + +func (c *configClient) Add(ctx context.Context, in *InputAdd, opts ...grpc1.CallOption) (*Output, error) { + out := new(Output) + err := grpc1.Invoke(ctx, "/Config/Add", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Remove(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) { + out := new(Output) + err := grpc1.Invoke(ctx, "/Config/Remove", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *configClient) Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error) { + out := new(Output) + err := grpc1.Invoke(ctx, "/Config/Init", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Config service + +type ConfigServer interface { + Add(context.Context, *InputAdd) (*Output, error) + Remove(context.Context, *Input) (*Output, error) + Init(context.Context, *InputArray) (*Output, error) +} + +func RegisterConfigServer(s *grpc1.Server, srv ConfigServer) { + s.RegisterService(&_Config_serviceDesc, srv) +} + +func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { + in := new(InputAdd) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Add(ctx, in) + } + info := &grpc1.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Add", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Add(ctx, req.(*InputAdd)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { + in := new(Input) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Remove(ctx, in) + } + info := &grpc1.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Remove", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Remove(ctx, req.(*Input)) + } + return interceptor(ctx, in, info, handler) +} + +func _Config_Init_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { + in := new(InputArray) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ConfigServer).Init(ctx, in) + } + info := &grpc1.UnaryServerInfo{ + Server: srv, + FullMethod: "/Config/Init", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ConfigServer).Init(ctx, req.(*InputArray)) + } + return interceptor(ctx, in, info, handler) +} + +var _Config_serviceDesc = grpc1.ServiceDesc{ + ServiceName: "Config", + HandlerType: (*ConfigServer)(nil), + Methods: []grpc1.MethodDesc{ + { + MethodName: "Add", + Handler: _Config_Add_Handler, + }, + { + MethodName: "Remove", + Handler: _Config_Remove_Handler, + }, + { + MethodName: "Init", + Handler: _Config_Init_Handler, + }, + }, + Streams: []grpc1.StreamDesc{}, + Metadata: "grpc.proto", +} + +// Client API for Data service + +type DataClient interface { + Get(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) +} + +type dataClient struct { + cc *grpc1.ClientConn +} + +func NewDataClient(cc *grpc1.ClientConn) DataClient { + return &dataClient{cc} +} + +func (c *dataClient) Get(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) { + out := new(Output) + err := grpc1.Invoke(ctx, "/Data/Get", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Data service + +type DataServer interface { + Get(context.Context, *Input) (*Output, error) +} + +func RegisterDataServer(s *grpc1.Server, srv DataServer) { + s.RegisterService(&_Data_serviceDesc, srv) +} + +func _Data_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { + in := new(Input) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DataServer).Get(ctx, in) + } + info := &grpc1.UnaryServerInfo{ + Server: srv, + FullMethod: "/Data/Get", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DataServer).Get(ctx, req.(*Input)) + } + return interceptor(ctx, in, info, handler) +} + +var _Data_serviceDesc = grpc1.ServiceDesc{ + ServiceName: "Data", + HandlerType: (*DataServer)(nil), + Methods: []grpc1.MethodDesc{ + { + MethodName: "Get", + Handler: _Data_Get_Handler, + }, + }, + Streams: []grpc1.StreamDesc{}, + Metadata: "grpc.proto", +} + +// Client API for Status service + +type StatusClient interface { + Status(ctx context.Context, in *Empty, opts ...grpc1.CallOption) (*Boolean, error) +} + +type statusClient struct { + cc *grpc1.ClientConn +} + +func NewStatusClient(cc *grpc1.ClientConn) StatusClient { + return &statusClient{cc} +} + +func (c *statusClient) Status(ctx context.Context, in *Empty, opts ...grpc1.CallOption) (*Boolean, error) { + out := new(Boolean) + err := grpc1.Invoke(ctx, "/Status/Status", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Status service + +type StatusServer interface { + Status(context.Context, *Empty) (*Boolean, error) +} + +func RegisterStatusServer(s *grpc1.Server, srv StatusServer) { + s.RegisterService(&_Status_serviceDesc, srv) +} + +func _Status_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StatusServer).Status(ctx, in) + } + info := &grpc1.UnaryServerInfo{ + Server: srv, + FullMethod: "/Status/Status", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StatusServer).Status(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +var _Status_serviceDesc = grpc1.ServiceDesc{ + ServiceName: "Status", + HandlerType: (*StatusServer)(nil), + Methods: []grpc1.MethodDesc{ + { + MethodName: "Status", + Handler: _Status_Status_Handler, + }, + }, + Streams: []grpc1.StreamDesc{}, + Metadata: "grpc.proto", +} + +func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 576 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x6d, 0x6c, 0xc7, 0x4e, 0x26, 0x6d, 0x3a, 0x1d, 0xda, 0x12, 0xd2, 0x0f, 0x22, 0x23, 0xa1, + 0x8a, 0x83, 0x0f, 0xa9, 0x84, 0xc4, 0x81, 0x83, 0x63, 0x9b, 0xc6, 0x28, 0x8e, 0xcd, 0xae, 0x55, + 0xe8, 0x09, 0xb9, 0x8d, 0x29, 0x11, 0xad, 0x13, 0xb9, 0x1b, 0x50, 0xff, 0x05, 0x3f, 0x19, 0xf9, + 0x23, 0xcd, 0x1e, 0x90, 0x90, 0xb8, 0xcd, 0x7b, 0x6f, 0xf6, 0xbd, 0x5d, 0x7b, 0x77, 0x00, 0x6e, + 0xf3, 0xe5, 0x8d, 0xb5, 0xcc, 0x17, 0x62, 0x61, 0x1a, 0xd0, 0xf4, 0xee, 0x97, 0xe2, 0xd1, 0x7c, + 0x09, 0xc6, 0x68, 0xb1, 0xb8, 0x4b, 0x93, 0x8c, 0xf6, 0xa1, 0x79, 0xf3, 0x3d, 0xbd, 0xf9, 0xd1, + 0x6b, 0x0c, 0x1a, 0x67, 0x2d, 0x56, 0x01, 0xf3, 0x15, 0x80, 0x9f, 0x2d, 0x57, 0xc2, 0xce, 0xf3, + 0xe4, 0x91, 0x0e, 0x40, 0x99, 0x67, 0xbd, 0xc6, 0x40, 0x3d, 0xeb, 0x0c, 0x9b, 0x96, 0x9f, 0xcd, + 0x05, 0x53, 0xe6, 0x99, 0xf9, 0x0e, 0xb4, 0xa2, 0xa6, 0x13, 0xd0, 0xb2, 0xe4, 0x3e, 0x2d, 0x1d, + 0xba, 0xc3, 0xb6, 0xe5, 0xe4, 0xc9, 0xaf, 0xbb, 0x34, 0x7f, 0x60, 0x25, 0x4d, 0x04, 0xda, 0x2c, + 0x11, 0x49, 0x4f, 0x19, 0x34, 0xce, 0xb6, 0x59, 0x59, 0x9b, 0x6f, 0xa1, 0x59, 0xfa, 0xff, 0x6b, + 0x6d, 0x17, 0x94, 0xf9, 0xac, 0x5c, 0xd9, 0x66, 0xca, 0x7c, 0x66, 0xbe, 0x87, 0x56, 0xb5, 0xaf, + 0xd9, 0xec, 0x7f, 0x62, 0x63, 0xd0, 0xc3, 0x95, 0x28, 0x72, 0x8f, 0xa1, 0xfd, 0x20, 0x92, 0x5c, + 0xb8, 0x89, 0xa8, 0x1c, 0x54, 0xb6, 0x21, 0xa8, 0x07, 0x46, 0x9a, 0xcd, 0x4a, 0x4d, 0x29, 0xb5, + 0x35, 0x7c, 0x72, 0x55, 0x37, 0xae, 0x6f, 0x7e, 0x6b, 0xd0, 0x5a, 0x87, 0x53, 0x1f, 0x0e, 0xc7, + 0x9e, 0x3d, 0x89, 0xc7, 0x5f, 0x6d, 0x27, 0xf6, 0x2f, 0x3d, 0xd7, 0x67, 0x9e, 0x13, 0x87, 0xec, + 0x0a, 0xb7, 0xa8, 0x0b, 0x50, 0x6b, 0xee, 0x94, 0x63, 0x43, 0xc2, 0x1f, 0xe2, 0x08, 0x15, 0xda, + 0x85, 0xce, 0x06, 0x73, 0x54, 0x25, 0xc2, 0x0f, 0xec, 0x08, 0x35, 0x89, 0x98, 0xb8, 0x76, 0x84, + 0x4d, 0x22, 0xe8, 0xd6, 0x44, 0x10, 0x4e, 0x2f, 0x42, 0x77, 0x84, 0x3a, 0x21, 0x6c, 0xaf, 0x39, + 0xce, 0x3f, 0x4d, 0xd0, 0x90, 0x99, 0xab, 0x82, 0x69, 0xc9, 0xeb, 0x6c, 0xe6, 0xdb, 0xee, 0x08, + 0xdb, 0x52, 0x57, 0x74, 0x51, 0x74, 0x81, 0xd4, 0x35, 0xf5, 0xe2, 0x91, 0x1f, 0x72, 0xec, 0xd0, + 0x1e, 0xec, 0xd4, 0x5c, 0xc8, 0x6c, 0x67, 0xe2, 0xe1, 0xb6, 0xb4, 0xab, 0x28, 0x8c, 0xce, 0x71, + 0x47, 0x72, 0x62, 0x9e, 0xeb, 0x73, 0xec, 0x4a, 0x47, 0x65, 0x81, 0x8f, 0xbb, 0x12, 0xe6, 0xc1, + 0x08, 0x51, 0xb2, 0xe0, 0x41, 0x1c, 0xe1, 0x9e, 0x14, 0xcd, 0xa7, 0x41, 0x74, 0x39, 0x74, 0x90, + 0xa4, 0xe8, 0x92, 0x3b, 0xc7, 0x67, 0xb2, 0x0f, 0x1f, 0xe3, 0xbe, 0xd4, 0x12, 0x7b, 0x93, 0xa9, + 0x17, 0xe3, 0x81, 0xd4, 0xf2, 0x39, 0xf0, 0xf1, 0x90, 0xf6, 0x01, 0x6b, 0xec, 0xd8, 0x9c, 0xdb, + 0x53, 0x97, 0xd9, 0xf8, 0x5c, 0xda, 0xc0, 0x38, 0x8e, 0x23, 0xec, 0x91, 0x01, 0x6a, 0xf1, 0x11, + 0x5e, 0x50, 0x0b, 0xb4, 0x22, 0x0e, 0xfb, 0x05, 0x55, 0x58, 0x1c, 0x15, 0xc5, 0xc7, 0xe0, 0x0b, + 0x1e, 0x53, 0x1b, 0x9a, 0xd5, 0x09, 0x4f, 0xa8, 0x03, 0xc6, 0xfa, 0x17, 0x9c, 0x0e, 0xaf, 0x41, + 0x77, 0x16, 0xd9, 0xb7, 0xf9, 0x2d, 0x1d, 0x81, 0x5a, 0x5c, 0xd6, 0xb6, 0xb5, 0xbe, 0xb7, 0x7d, + 0xc3, 0xaa, 0xee, 0xa0, 0xb9, 0x45, 0x47, 0xa0, 0xb3, 0xf4, 0x7e, 0xf1, 0x33, 0x25, 0xbd, 0xd2, + 0x65, 0xf1, 0xb4, 0x7e, 0x5e, 0x1d, 0x6b, 0xf3, 0x14, 0x25, 0x7d, 0x38, 0x00, 0xcd, 0x4d, 0x44, + 0x42, 0x3d, 0x50, 0x2f, 0x52, 0xf1, 0x17, 0x87, 0xe1, 0x6b, 0xd0, 0xb9, 0x48, 0xc4, 0xea, 0x81, + 0x8e, 0x9f, 0x2a, 0xdd, 0x2a, 0x47, 0x40, 0xbf, 0x65, 0xd5, 0x13, 0xc0, 0xdc, 0xba, 0xd6, 0xcb, + 0xf1, 0x70, 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe6, 0x5f, 0x44, 0x44, 0x2c, 0x04, 0x00, 0x00, +} diff --git a/crawler/grpc/grpc.proto b/crawler/grpc/grpc.proto new file mode 100644 index 0000000..b61ef32 --- /dev/null +++ b/crawler/grpc/grpc.proto @@ -0,0 +1,83 @@ +syntax = "proto3"; + + +enum Crawlers { + HEALTH_ACTIVEDIRECTORY = 0; + HEALTH_DNS = 1; + HEALTH_FTP = 2; + HEALTH_FTPS = 3; + HEALTH_IMAP = 4; + HEALTH_LDAP = 5; + HEALTH_MONGODB = 6; + HEALTH_MSSQL = 7; + HEALTH_MYSQL = 8; + HEALTH_MARIADB = 9; + HEALTH_PGSQL = 10; + HEALTH_NETBIOS = 11; + HEALTH_ORACLE = 12; + HEALTH_POP3 = 13; + HEALTH_REDIS = 14; + HEALTH_RMI = 15; + HEALTH_SMB = 16; + HEALTH_SMTP = 17; + HEALTH_SNMPV2C = 18; + HEALTH_SNMPV3 = 19; + HEALTH_SSH = 20; + HEALTH_TELNET = 21; + HEALTH_WMI = 22; + HEALTH_CASSANDRA = 23; + HEALTH_HTTP = 24; + SQL = 25; + SNMP = 26; + WMI = 27; + JMX = 28; + REDIS = 29; + MONGODB = 30; +} + +// services +service Config { + rpc Add (InputAdd) returns (Output) {} + rpc Remove (Input) returns (Output) {} + rpc Init (InputArray) returns (Output) {} +} + +service Data { + rpc Get (Input) returns (Output) {} +} + + +service Status { + rpc Status(Empty) returns (Boolean) {} +} + +message Empty {} +message Boolean { + bool check = 1; +} + +message InputArray { + repeated Init in = 1; +} + +message Init { + Crawlers name = 1; + bytes data = 2; +} + +message Input { + Crawlers name = 1; + string id =2; +} + +message InputAdd { + Crawlers name = 1; + bytes data =2; +} + +// response models +message Output { + int64 startDate = 1; + int64 endDate = 2; + bytes data = 3; +} \ No newline at end of file diff --git a/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler.go b/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler.go new file mode 100644 index 0000000..e33516f --- /dev/null +++ b/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler.go @@ -0,0 +1,29 @@ +package activedirectory_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/activedirectory" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" + "git.loafle.net/overflow/overflow_probe/crawler" +) + +type ActiveDirectoryHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *ActiveDirectoryHealthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewActiveDirectoryHealthCrawler() *ActiveDirectoryHealthCrawler { + ad := &ActiveDirectoryHealthCrawler{} + ad.SetInternal(ad) + ad.SetMatcher(activedirectory.NewActiveDirectoryMatcher()) + return ad +} diff --git a/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler_test.go b/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler_test.go new file mode 100644 index 0000000..a4a21f4 --- /dev/null +++ b/crawler/health_crawler/activedirectory_protocol_crawler_go/ad_protocol_crawler_test.go @@ -0,0 +1,109 @@ +package activedirectory_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "log" + "testing" + "time" +) + +//import ( +// "encoding/json" +// "github.com/stretchr/testify/assert" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +} diff --git a/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler.go b/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler.go new file mode 100644 index 0000000..4e3f5f8 --- /dev/null +++ b/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler.go @@ -0,0 +1,28 @@ +package cassandra_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/cassandra" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type CassandraHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *CassandraHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewCassandraHealthCrawler() *CassandraHealthCrawler { + r := &CassandraHealthCrawler{} + r.SetInternal(r) + r.SetMatcher(cassandra.NewCassandraMatcher()) + return r +} diff --git a/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler_test.go b/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler_test.go new file mode 100644 index 0000000..34cce0d --- /dev/null +++ b/crawler/health_crawler/cassandra_protocol_crawler_go/cassandra_protocol_crawler_test.go @@ -0,0 +1,104 @@ +package cassandra_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler.go b/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler.go new file mode 100644 index 0000000..83777fa --- /dev/null +++ b/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler.go @@ -0,0 +1,28 @@ +package dns_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/dns" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type DNSHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *DNSHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewDNSHealthCrawler() *DNSHealthCrawler { + r := &DNSHealthCrawler{} + r.SetInternal(r) + r.SetMatcher(dns.NewDnsMatcher()) + return r +} diff --git a/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler_test.go b/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler_test.go new file mode 100644 index 0000000..9d3dca3 --- /dev/null +++ b/crawler/health_crawler/dns_protocol_crawler_go/dns_protocol_crawler_test.go @@ -0,0 +1,104 @@ +package dns_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/ftp_protocol_crawler_go/ftp_health_matcher.go b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_health_matcher.go new file mode 100644 index 0000000..bc3d57e --- /dev/null +++ b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_health_matcher.go @@ -0,0 +1,121 @@ +package ftp_protocol_crawler_go + +import ( + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "git.loafle.net/overflow/overflow_probe/model/scaninfo" + "log" +) + +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 +} diff --git a/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler.go b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler.go new file mode 100644 index 0000000..3611eff --- /dev/null +++ b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler.go @@ -0,0 +1,179 @@ +package ftp_protocol_crawler_go + + +import ( + "git.loafle.net/overflow/overflow_probe/crawler" + "encoding/json" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type FTPHealthCrawler struct { + crawler.SocketHeahthCrawler +} + + +func (r *FTPHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + 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() +//} diff --git a/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler_test.go b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler_test.go new file mode 100644 index 0000000..6b708f6 --- /dev/null +++ b/crawler/health_crawler/ftp_protocol_crawler_go/ftp_protocol_crawler_test.go @@ -0,0 +1,93 @@ +package ftp_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "log" + "testing" + "time" +) + +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) +//} diff --git a/crawler/health_crawler/ftps_protocol_crawler_go/ftps_health_matcher.go b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_health_matcher.go new file mode 100644 index 0000000..4add4e4 --- /dev/null +++ b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_health_matcher.go @@ -0,0 +1,75 @@ +package ftps_protocol_crawler_go + +import ( + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "git.loafle.net/overflow/overflow_probe/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 +} diff --git a/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler.go b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler.go new file mode 100644 index 0000000..bc43f73 --- /dev/null +++ b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler.go @@ -0,0 +1,70 @@ +package ftps_protocol_crawler_go + +import ( + "git.loafle.net/overflow/overflow_probe/crawler" + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/ftp" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type FTPSHealthCrawler struct { + crawler.SocketHeahthCrawler +} + + +func (r *FTPSHealthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + 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() +//} diff --git a/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler_test.go b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler_test.go new file mode 100644 index 0000000..ef79280 --- /dev/null +++ b/crawler/health_crawler/ftps_protocol_crawler_go/ftps_protocol_crawler_test.go @@ -0,0 +1,87 @@ +package ftps_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "log" + "testing" + "time" +) + +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) +//} diff --git a/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http.go b/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http.go new file mode 100644 index 0000000..102b032 --- /dev/null +++ b/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http.go @@ -0,0 +1,120 @@ +package http_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/http" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type HTTPHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *HTTPHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} +func NewHTTPHealthCrawler() *HTTPHealthCrawler { + r := &HTTPHealthCrawler{} + r.SetInternal(r) + r.SetMatcher(http.NewHTTPMatcher()) + return r +} + +//package main +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "log" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "encoding/json" +// "strconv" +// "net" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/http" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http_test.go b/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http_test.go new file mode 100644 index 0000000..252c40d --- /dev/null +++ b/crawler/health_crawler/http_protocol_crawler_go/crawler_protocol_http_test.go @@ -0,0 +1,87 @@ +package http_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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) +//} diff --git a/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler.go b/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler.go new file mode 100644 index 0000000..b8550d3 --- /dev/null +++ b/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler.go @@ -0,0 +1,129 @@ +package imap_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/imap" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type IMAPHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *IMAPHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + 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" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/imap" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler_test.go b/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler_test.go new file mode 100644 index 0000000..7fb00ad --- /dev/null +++ b/crawler/health_crawler/imap_protocol_crawler_go/imap_protocol_crawler_test.go @@ -0,0 +1,110 @@ +package imap_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler.go b/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler.go new file mode 100644 index 0000000..6a19a8f --- /dev/null +++ b/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler.go @@ -0,0 +1,132 @@ +package ldap_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/ldap" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type LDAPHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *LDAPHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewLDAPHealthCrawler() *LDAPHealthCrawler { + r := &LDAPHealthCrawler{} + r.SetInternal(r) + r.SetMatcher(ldap.NewLDAPMatcher()) + return r +} + +// +//import ( +// "crypto/tls" +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/ldap" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler_test.go b/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler_test.go new file mode 100644 index 0000000..aef4a73 --- /dev/null +++ b/crawler/health_crawler/ldap_protocol_crawler_go/ldap_protocol_crawler_test.go @@ -0,0 +1,110 @@ +package ldap_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol.go b/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol.go new file mode 100644 index 0000000..120ecc3 --- /dev/null +++ b/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol.go @@ -0,0 +1,128 @@ +package mongodb_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/mongodb" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type MongoDBHealthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *MongoDBHealthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewMongoDBHealthCrawler() *MongoDBHealthCrawler { + r := &MongoDBHealthCrawler{} + r.SetInternal(r) + r.SetMatcher(mongodb.NewMongoDBMatcher()) + return r +} + +//import ( +// "crypto/tls" +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/mongodb" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol_test.go b/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol_test.go new file mode 100644 index 0000000..618dcd9 --- /dev/null +++ b/crawler/health_crawler/mongodb_protocol_crawler_go/mongodb_protocol_test.go @@ -0,0 +1,105 @@ +package mongodb_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol.go b/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol.go new file mode 100644 index 0000000..1888afc --- /dev/null +++ b/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol.go @@ -0,0 +1,104 @@ +package mssql_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/mssql" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type MSSqlHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *MSSqlHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} +func NewMSSqlHeahthCrawler() *MSSqlHeahthCrawler { + r := &MSSqlHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(mssql.NewMSSqlMatcher()) + return r +} + +// +//import ( +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "log" +// "net" +// "strconv" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol_test.go b/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol_test.go new file mode 100644 index 0000000..8d96018 --- /dev/null +++ b/crawler/health_crawler/mssql_protocol_crawler_go/mssql_protocol_test.go @@ -0,0 +1,86 @@ +package mssql_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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) +//} diff --git a/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol.go b/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol.go new file mode 100644 index 0000000..3e88b2c --- /dev/null +++ b/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol.go @@ -0,0 +1,107 @@ +package mysql_protocol_crawler_go + + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/mysql" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type MysqlHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *MysqlHeahthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewMysqlHeahthCrawler() *MysqlHeahthCrawler { + r := &MysqlHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(mysql.NewMySqlMatcher()) + return r +} + + +// +//import ( +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/mysql" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol_test.go b/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol_test.go new file mode 100644 index 0000000..5a158d0 --- /dev/null +++ b/crawler/health_crawler/mysql_protocol_crawler_go/mysql_protocol_test.go @@ -0,0 +1,86 @@ +package mysql_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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) +//} diff --git a/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler.go b/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler.go new file mode 100644 index 0000000..d5e58ea --- /dev/null +++ b/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler.go @@ -0,0 +1,109 @@ +package netbios_protocol_crawler_go + + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/netbios" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type NetbiosHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *NetbiosHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewNetbiosHeahthCrawler() *NetbiosHeahthCrawler { + r := &NetbiosHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(netbios.NewNetBiosMatcher()) + return r +} + + +//import ( +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "log" +// "net" +// "strconv" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler_test.go b/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler_test.go new file mode 100644 index 0000000..79d63e7 --- /dev/null +++ b/crawler/health_crawler/netbios_protocol_crawler_go/netbios_protocol_crawler_test.go @@ -0,0 +1,105 @@ +package netbios_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler.go b/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler.go new file mode 100644 index 0000000..de42e75 --- /dev/null +++ b/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler.go @@ -0,0 +1,147 @@ +package oracle_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/oracle" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type OracleHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *OracleHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewOracleHeahthCrawler() *OracleHeahthCrawler { + r := &OracleHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(oracle.NewOracleMatcher()) + return r +} + + +//package oracle_protocol_crawler +// +// +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// "crypto/tls" +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/oracle" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler_test.go b/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler_test.go new file mode 100644 index 0000000..6410f27 --- /dev/null +++ b/crawler/health_crawler/oracle_protocol_crawler_go/oracle_protocol_crawler_test.go @@ -0,0 +1,127 @@ +package oracle_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol.go b/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol.go new file mode 100644 index 0000000..1137021 --- /dev/null +++ b/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol.go @@ -0,0 +1,105 @@ +package pgsql_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/pgsql" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type PGSqlHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *PGSqlHeahthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewPGSqlHeahthCrawler() *PGSqlHeahthCrawler { + r := &PGSqlHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(pgsql.NewPostgreSQLMatcher()) + return r +} + +// +//import ( +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "log" +// "net" +// "strconv" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol_test.go b/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol_test.go new file mode 100644 index 0000000..e53396d --- /dev/null +++ b/crawler/health_crawler/pgsql_protocol_crawler_go/pgsql_protocol_test.go @@ -0,0 +1,86 @@ +package pgsql_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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) +//} diff --git a/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler.go b/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler.go new file mode 100644 index 0000000..122af36 --- /dev/null +++ b/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler.go @@ -0,0 +1,130 @@ +package pop3_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/pop" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type POP3HeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *POP3HeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + 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" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/pop" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler_test.go b/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler_test.go new file mode 100644 index 0000000..5d53171 --- /dev/null +++ b/crawler/health_crawler/pop3_protocol_crawler_go/pop3_protocol_crawler_test.go @@ -0,0 +1,111 @@ +package pop3_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol.go b/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol.go new file mode 100644 index 0000000..1c186d8 --- /dev/null +++ b/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol.go @@ -0,0 +1,28 @@ +package redis_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/redis" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type RedisHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *RedisHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewRedisHeahthCrawler() *RedisHeahthCrawler { + r := &RedisHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(redis.NewRedisMatcher()) + return r +} diff --git a/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go b/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go new file mode 100644 index 0000000..b26cc15 --- /dev/null +++ b/crawler/health_crawler/redis_protocol_crawler_go/redis_protocol_test.go @@ -0,0 +1,69 @@ +package redis_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/crawler" + "git.loafle.net/overflow/overflow_probe/crawler/config" + "github.com/stretchr/testify/assert" + "testing" +) + +func setConfig() crawler.Crawler { + + r := NewRedisHeahthCrawler() + + m := config.Config{} + m.Target = config.Target{} + m.Target.Connection = config.Connection{} + m.Target.Connection.Ip = "192.168.1.104" + m.Target.Connection.Port = "6379" + m.Target.Connection.PortType = "tcp" + m.Target.Connection.SSL = false + + r.PutConfig("redis", m) + + return r +} + +func TestMatch(t *testing.T) { + // test config + r := setConfig() + + b, _ := r.Get("redis") + + var check bool + json.Unmarshal(b, &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) +//} diff --git a/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler.go b/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler.go new file mode 100644 index 0000000..9de61cd --- /dev/null +++ b/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler.go @@ -0,0 +1,107 @@ +package rmi_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/rmi" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type RMIHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *RMIHeahthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} +func NewRMIHeahthCrawler() *RMIHeahthCrawler { + r := &RMIHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(rmi.NewRMIMatcher()) + return r +} + +//package imap +// +//import ( +// "encoding/json" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/rmi" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler_test.go b/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler_test.go new file mode 100644 index 0000000..8fd63b6 --- /dev/null +++ b/crawler/health_crawler/rmi_protocol_crawler_go/rmi_protocol_crawler_test.go @@ -0,0 +1,106 @@ +package rmi_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler.go b/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler.go new file mode 100644 index 0000000..ec1e916 --- /dev/null +++ b/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler.go @@ -0,0 +1,150 @@ +package smb_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/smb" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SMBHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *SMBHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewSMBHeahthCrawler() *SMBHeahthCrawler { + r := &SMBHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(smb.NewSMBMatcher()) + return r +} + + +//package smb_protocol_crawler +// +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/smb" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler_test.go b/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler_test.go new file mode 100644 index 0000000..4211fe7 --- /dev/null +++ b/crawler/health_crawler/smb_protocol_crawler_go/smb_protocol_crawler_test.go @@ -0,0 +1,108 @@ +package smb_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler.go b/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler.go new file mode 100644 index 0000000..d9071e9 --- /dev/null +++ b/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler.go @@ -0,0 +1,137 @@ +package smtp_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/smtp" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SMTPHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *SMTPHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + 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" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/smtp" +// rpc "git.loafle.net/overflow/of_rpc/json" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler_test.go b/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler_test.go new file mode 100644 index 0000000..acac5ab --- /dev/null +++ b/crawler/health_crawler/smtp_protocol_crawler_go/smtp_protocol_crawler_test.go @@ -0,0 +1,111 @@ +package smtp_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler.go b/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler.go new file mode 100644 index 0000000..dd2a615 --- /dev/null +++ b/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler.go @@ -0,0 +1,137 @@ +package snmpv2c_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/snmp" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SNMPV2CHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *SNMPV2CHeahthCrawler)Internal(params config.Config) ([]byte, error) { + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewSNMPV2CHeahthCrawler() *SNMPV2CHeahthCrawler { + r := &SNMPV2CHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(snmp.NewSNMPv2Matcher()) + return r +} + + +//package snmpv2c_protocol_crawler +// +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/snmp" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler_test.go b/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler_test.go new file mode 100644 index 0000000..2dd0564 --- /dev/null +++ b/crawler/health_crawler/snmpv2c_protocol_crawler_go/snmpv2c_protocol_crawler_test.go @@ -0,0 +1,106 @@ +package snmpv2c_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler.go b/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler.go new file mode 100644 index 0000000..d343206 --- /dev/null +++ b/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler.go @@ -0,0 +1,137 @@ +package snmpv3_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/snmp" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SNMPV3HeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *SNMPV3HeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewSNMPV3HeahthCrawler() *SNMPV3HeahthCrawler { + r := &SNMPV3HeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(snmp.NewSNMPv3Matcher()) + return r +} + +//package snmpv3_protocol_crawler +// +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/snmp" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler_test.go b/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler_test.go new file mode 100644 index 0000000..1d8b62f --- /dev/null +++ b/crawler/health_crawler/snmpv3_protocol_crawler_go/snmpv3_protocol_crawler_test.go @@ -0,0 +1,106 @@ +package snmpv3_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler.go b/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler.go new file mode 100644 index 0000000..cdc2935 --- /dev/null +++ b/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler.go @@ -0,0 +1,152 @@ +package ssh_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/ssh" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SSHHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *SSHHeahthCrawler) Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} +func NewSSHHeahthCrawler() *SSHHeahthCrawler { + r := &SSHHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(ssh.NewSSHMatcher()) + return r +} + + +//package ssh_protocol_crawler +// +// +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// "crypto/tls" +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/ssh" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler_test.go b/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler_test.go new file mode 100644 index 0000000..ba23ef0 --- /dev/null +++ b/crawler/health_crawler/ssh_protocol_crawler_go/ssh_protocol_crawler_test.go @@ -0,0 +1,107 @@ +package ssh_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet.go b/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet.go new file mode 100644 index 0000000..f0fce13 --- /dev/null +++ b/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet.go @@ -0,0 +1,151 @@ +package telnet_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/telnet" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type TelnetHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *TelnetHeahthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewTelnetHeahthCrawler() *TelnetHeahthCrawler { + r := &TelnetHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(telnet.NewTelnetMatcher()) + return r +} + + +//package main +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// "crypto/tls" +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/telnet" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet_test.go b/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet_test.go new file mode 100644 index 0000000..57dee76 --- /dev/null +++ b/crawler/health_crawler/telnet_protocol_crawler_go/crawler_protocol_telnet_test.go @@ -0,0 +1,108 @@ +package telnet_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/json/client" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler.go b/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler.go new file mode 100644 index 0000000..96e9539 --- /dev/null +++ b/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler.go @@ -0,0 +1,148 @@ +package wmi_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/matcher/wmi" + "git.loafle.net/overflow/overflow_probe/crawler" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type WMIHeahthCrawler struct { + crawler.SocketHeahthCrawler +} + +func (r *WMIHeahthCrawler)Internal(params config.Config) ([]byte, error) { + + b, err := r.CheckHeahth(params) + if err != nil { + return nil, err + } + return json.Marshal(b) +} + +func NewWMIHeahthCrawler() *WMIHeahthCrawler { + r := &WMIHeahthCrawler{} + r.SetInternal(r) + r.SetMatcher(wmi.NewWMIMatcher()) + return r +} + + +//package wmi_protocol_crawler +// +//import ( +// "git.loafle.net/overflow/of_rpc/models/param" +// "encoding/json" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "strconv" +// "crypto/tls" +// "net" +// +// "git.loafle.net/overflow/collector/core/scan/service/matcher/wmi" +// "git.loafle.net/overflow/collector/core/scan/service/matcher/packet" +// rpc "git.loafle.net/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() +//} diff --git a/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler_test.go b/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler_test.go new file mode 100644 index 0000000..78c991f --- /dev/null +++ b/crawler/health_crawler/wmi_protocol_crawler_go/wmi_protocol_crawler_test.go @@ -0,0 +1,106 @@ +package wmi_protocol_crawler_go + +import ( + "encoding/json" + "git.loafle.net/overflow/of_rpc_go" + "git.loafle.net/overflow/of_rpc_go/client" + "git.loafle.net/overflow/of_rpc_go/models/param" + "git.loafle.net/overflow/overflow_probe/crawler" + "github.com/stretchr/testify/assert" + "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" +// "git.loafle.net/overflow/of_rpc/models/protocol" +// "git.loafle.net/overflow/of_rpc/models/param" +// "git.loafle.net/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) +//} diff --git a/crawler/socket_health_crawler.go b/crawler/socket_health_crawler.go new file mode 100644 index 0000000..fe33117 --- /dev/null +++ b/crawler/socket_health_crawler.go @@ -0,0 +1,112 @@ +package crawler + +import ( + "crypto/tls" + "git.loafle.net/overflow/overflow_probe/matcher" + "git.loafle.net/overflow/overflow_probe/matcher/packet" + "net" + "git.loafle.net/overflow/overflow_probe/model/scaninfo" + config "git.loafle.net/overflow/overflow_probe/agent_api/config_manager" +) + +type SocketHeahthCrawler struct { + CrawlerImpl + m matcher.Matcher +} + +func (s *SocketHeahthCrawler) SetMatcher(m matcher.Matcher) { + s.m = m +} + +func (s *SocketHeahthCrawler) getConnection(params config.Config) (net.Conn, error) { + + connection := params.Target.Connection + + ip := connection.Ip + port := connection.Port + portType := connection.PortType + ssl := connection.SSL + + var addr string = ip + addr += ":" + addr += port + + if ssl == false { + conn, err := net.Dial(portType, addr) + if err != nil { + return nil, err + } + return conn, nil + } else { + conn, err := tls.Dial( + portType, + addr, + &tls.Config{ + InsecureSkipVerify: true, + ServerName: ip, + ClientAuth: tls.RequestClientCert, + }, + ) + if err != nil { + return nil, err + } + return conn, nil + } +} + +func (s *SocketHeahthCrawler) CheckHeahth(params config.Config) (bool, error) { + conn, err := s.getConnection(params) + if err != nil { + return false, err + } + defer conn.Close() + + connection := params.Target.Connection + info := scaninfo.NewScanInfoImpl(connection.Ip,connection.Port) + + if s.m.IsPrePacket() == true { + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + p := packet.NewPacket(bytes, n) + if s.m.Match(0, p, info) == false { + return false, nil + } else { + + for i := 0; i < s.m.PacketCount(); i++ { + pack := s.m.Packet(i) + conn.Write(pack.Buffer) + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + + if s.m.IsNoResponse(i+1) == true { // empty last response + break + } + + p := packet.NewPacket(bytes, n) + if s.m.Match(i+1, p, info) == false { + return false, nil + } + } + + } + + } else { + for i := 0; i < s.m.PacketCount(); i++ { + pack := s.m.Packet(i) + conn.Write(pack.Buffer) + bytes := make([]byte, 1024) + n, _ := conn.Read(bytes) + + if s.m.IsNoResponse(i) == true { // empty last response + break + } + + p := packet.NewPacket(bytes, n) + if s.m.Match(i, p, info) == false { + return false, nil + } + } + } + + return true, nil +} diff --git a/crawler/test/crawler_test.go b/crawler/test/crawler_test.go new file mode 100644 index 0000000..9326b88 --- /dev/null +++ b/crawler/test/crawler_test.go @@ -0,0 +1,93 @@ +package test + +import ( + "encoding/json" + "git.loafle.net/overflow/overflow_probe/crawler" + "git.loafle.net/overflow/overflow_probe/crawler/health_crawler/redis_protocol_crawler_go" + "github.com/stretchr/testify/assert" + "testing" + + "io/ioutil" +) + +func initConfig() crawler.CrawlerImpl { + c := crawler.CrawlerImpl{} + c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler()) + + b, _ := ioutil.ReadFile("./example.json") + + c.Init(b) + return c +} + +func TestCrawlerInit(t *testing.T) { + + c := initConfig() + m := c.GetConfig("test_id_001") + assert.Equal(t, m.Id, "test_id_001") + +} + +func TestCrawlerAdd(t *testing.T) { + + c := initConfig() + c.Remove("test_id_001") + bb, _ := ioutil.ReadFile("./example.json") + b, _ := c.Add(bb) + + var ck bool + json.Unmarshal(b, &ck) + + assert.Equal(t, true, ck) + +} + +func TestCrawlerRemove(t *testing.T) { + c := initConfig() + b, _ := c.Remove("test_id_001") + + var ck bool + json.Unmarshal(b, &ck) + + assert.Equal(t, true, ck) +} + +func TestCrawlerGet(t *testing.T) { + c := initConfig() + b, _ := c.Get("test_id_001") + + var ck bool + json.Unmarshal(b, &ck) + + assert.Equal(t, true, ck) +} + +func TestFolder(t *testing.T) { + + configPath := "./" + files, err := ioutil.ReadDir(configPath) + if err != nil { + t.Log(err) + } + + for _, file := range files { + if file.IsDir() == true { + continue + } + + t.Log(file.Name()) + //_,err := c.Add(file.Name()) + if err != nil { + t.Log(err) + } + } + +} + +func TestFile(t *testing.T) { + + b, _ := ioutil.ReadFile("./example.json") + + t.Log(string(b)) + +} diff --git a/crawler/test/example.json b/crawler/test/example.json new file mode 100644 index 0000000..55c45cf --- /dev/null +++ b/crawler/test/example.json @@ -0,0 +1,28 @@ +{ + "id" : "test_id_001", + "target" : { + "connection" : { + "ip" : "192.168.1.104", + "port" : "6379", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"redis_crawler", + "container":"java_proxy" + }, + "items" : [ + { + "type":"cpu", + "":[], + "":[], + } + ] +} \ No newline at end of file