From 43d2a34c609b493dce4468a855c0f8c12a39e21d Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 6 Apr 2018 19:16:19 +0900 Subject: [PATCH] project init --- .gitignore | 28 ++++ dh.json | 173 +++++++++++++++++++++++++ golang/server_grpc.pb.go | 214 +++++++++++++++++++++++++++++++ golang/server_test.go | 61 +++++++++ pom.xml | 90 +++++++++++++ src/main/proto/cmd | 1 + src/main/proto/server_grpc.proto | 26 ++++ src/main/resources/_ | 0 8 files changed, 593 insertions(+) create mode 100644 .gitignore create mode 100644 dh.json create mode 100644 golang/server_grpc.pb.go create mode 100644 golang/server_test.go create mode 100644 pom.xml create mode 100644 src/main/proto/cmd create mode 100644 src/main/proto/server_grpc.proto create mode 100644 src/main/resources/_ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c314e7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +target/ +*.iml +.idea/ diff --git a/dh.json b/dh.json new file mode 100644 index 0000000..c7bb126 --- /dev/null +++ b/dh.json @@ -0,0 +1,173 @@ +[{ + "firstScanRange": 1, + "lastScanRange": 10000, + "name": "", + "ip": 3232235818, + "mac": 91754662925, + "os":"Windows", + "ports": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "SSH", + "target":true + }], + "portType": "TCP", + "portNumber": 22 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 443 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 80 + }], + "createDate": 1498470178000, + "updateDate": 1498470178000 +}, + { + "firstScanRange": 1, + "lastScanRange": 10000, + "name": "", + "ip": 3232235781, + "mac": 91754660625, + "os":"Windows", + "ports": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "SSH" + }], + "portType": "TCP", + "portNumber": 22 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 80 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 1936 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": null, + "portType": "TCP", + "portNumber": 443 + }], + "createDate": 1498470178000, + "updateDate": 1498470178000 + }, + { + "firstScanRange": 1, + "lastScanRange": 10000, + "name": "", + "ip": 3232235797, + "mac": 91754662913, + "os":"Windows", + "target":true, + "ports": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 80 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "SSH" + }], + "portType": "TCP", + "portNumber": 22 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 3343 + }, + { + "createDate": -62135596800000, + "updateDate": -62135596800000, + "services": [{ + "createDate": -62135596800000, + "updateDate": -62135596800000, + "portType": "TCP", + "serviceName": "HTTP" + }], + "portType": "TCP", + "portNumber": 443 + }], + "createDate": 1498470178000, + "updateDate": 1498470178000 + }, + { + "firstScanRange": 1, + "lastScanRange": 10000, + "name": "", + "ip": 3232235877, + "mac": 75361038758387, + "os":"Windows", + "ports": null, + "createDate": 1498470179000, + "updateDate": 1498470179000 + } + + +] \ No newline at end of file diff --git a/golang/server_grpc.pb.go b/golang/server_grpc.pb.go new file mode 100644 index 0000000..d3ec97a --- /dev/null +++ b/golang/server_grpc.pb.go @@ -0,0 +1,214 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: server_grpc.proto + +/* +Package server_grpc is a generated protocol buffer package. + +It is generated from these files: + server_grpc.proto + +It has these top-level messages: + ServerInput + ServerParam + ServerOutput +*/ +package server_grpc + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" + +import ( + context "golang.org/x/net/context" + grpc "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 ServerInput struct { + Target string `protobuf:"bytes,1,opt,name=target" json:"target,omitempty"` + Method string `protobuf:"bytes,2,opt,name=method" json:"method,omitempty"` + Params []string `protobuf:"bytes,3,rep,name=params" json:"params,omitempty"` +} + +func (m *ServerInput) Reset() { *m = ServerInput{} } +func (m *ServerInput) String() string { return proto.CompactTextString(m) } +func (*ServerInput) ProtoMessage() {} +func (*ServerInput) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +func (m *ServerInput) GetTarget() string { + if m != nil { + return m.Target + } + return "" +} + +func (m *ServerInput) GetMethod() string { + if m != nil { + return m.Method + } + return "" +} + +func (m *ServerInput) GetParams() []string { + if m != nil { + return m.Params + } + return nil +} + +type ServerParam struct { + Type string `protobuf:"bytes,1,opt,name=type" json:"type,omitempty"` + Data string `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` + IsCollection bool `protobuf:"varint,3,opt,name=isCollection" json:"isCollection,omitempty"` +} + +func (m *ServerParam) Reset() { *m = ServerParam{} } +func (m *ServerParam) String() string { return proto.CompactTextString(m) } +func (*ServerParam) ProtoMessage() {} +func (*ServerParam) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *ServerParam) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *ServerParam) GetData() string { + if m != nil { + return m.Data + } + return "" +} + +func (m *ServerParam) GetIsCollection() bool { + if m != nil { + return m.IsCollection + } + return false +} + +type ServerOutput struct { + Result string `protobuf:"bytes,1,opt,name=result" json:"result,omitempty"` +} + +func (m *ServerOutput) Reset() { *m = ServerOutput{} } +func (m *ServerOutput) String() string { return proto.CompactTextString(m) } +func (*ServerOutput) ProtoMessage() {} +func (*ServerOutput) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *ServerOutput) GetResult() string { + if m != nil { + return m.Result + } + return "" +} + +func init() { + proto.RegisterType((*ServerInput)(nil), "ServerInput") + proto.RegisterType((*ServerParam)(nil), "ServerParam") + proto.RegisterType((*ServerOutput)(nil), "ServerOutput") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.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 _ = grpc.SupportPackageIsVersion4 + +// Client API for OverflowApiServer service + +type OverflowApiServerClient interface { + Exec(ctx context.Context, in *ServerInput, opts ...grpc.CallOption) (*ServerOutput, error) +} + +type overflowApiServerClient struct { + cc *grpc.ClientConn +} + +func NewOverflowApiServerClient(cc *grpc.ClientConn) OverflowApiServerClient { + return &overflowApiServerClient{cc} +} + +func (c *overflowApiServerClient) Exec(ctx context.Context, in *ServerInput, opts ...grpc.CallOption) (*ServerOutput, error) { + out := new(ServerOutput) + err := grpc.Invoke(ctx, "/OverflowApiServer/exec", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for OverflowApiServer service + +type OverflowApiServerServer interface { + Exec(context.Context, *ServerInput) (*ServerOutput, error) +} + +func RegisterOverflowApiServerServer(s *grpc.Server, srv OverflowApiServerServer) { + s.RegisterService(&_OverflowApiServer_serviceDesc, srv) +} + +func _OverflowApiServer_Exec_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServerInput) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OverflowApiServerServer).Exec(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/OverflowApiServer/Exec", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OverflowApiServerServer).Exec(ctx, req.(*ServerInput)) + } + return interceptor(ctx, in, info, handler) +} + +var _OverflowApiServer_serviceDesc = grpc.ServiceDesc{ + ServiceName: "OverflowApiServer", + HandlerType: (*OverflowApiServerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "exec", + Handler: _OverflowApiServer_Exec_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "server_grpc.proto", +} + +func init() { proto.RegisterFile("server_grpc.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 240 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x3d, 0x4f, 0xc3, 0x30, + 0x10, 0x40, 0x31, 0xa9, 0x2a, 0x38, 0xc2, 0x50, 0x0f, 0x10, 0x31, 0xa0, 0xc8, 0x12, 0xa8, 0x93, + 0x07, 0xd8, 0xd8, 0x80, 0x89, 0xa9, 0x55, 0x11, 0x03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x1f, 0xc7, + 0xe3, 0xdd, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x11, 0xfd, 0x20, 0xaf, 0x51, 0x01, 0x00, 0x00, +} diff --git a/golang/server_test.go b/golang/server_test.go new file mode 100644 index 0000000..42763f0 --- /dev/null +++ b/golang/server_test.go @@ -0,0 +1,61 @@ +package server_grpc + +import ( + "testing" + "google.golang.org/grpc" + "golang.org/x/net/context" + "io/ioutil" +) + +func TestTarDis_saveAllTarget(t *testing.T) { + + contents,_ := ioutil.ReadFile("../dh.json") + + si := &ServerInput{} + + si.Target = "TargetDiscoveryService" + si.Method = "saveAllTarget" + + si.Params = append(si.Params, string(contents)) + si.Params = append(si.Params, "{\"id\":1}") + + callRPC(t, si) + +} + + +func TestRPCNP_readAllByDomain(t *testing.T) { + + + si := &ServerInput{} + + si.Target = "NoAuthProbeService" + si.Method = "readAllByDomain" + + //sp := &ServerParam{} + //sp.IsCollection = false + //sp.Type = "com.loafle.overflow.module.domain.model.Domain" + //sp.Data = "{\"id\":1}" + si.Params = append(si.Params, "{\"id\":1}") + + callRPC(t, si) +} + +func callRPC(t *testing.T, si *ServerInput) { + + conn, err := grpc.Dial(":50006", grpc.WithInsecure()) + + if err != nil { + t.Log(err) + } + + client := NewOverflowApiServerClient(conn) + + out, err := client.Exec(context.Background(), si) + if err != nil { + t.Fatal(err) + } + + t.Log(out) + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dec1853 --- /dev/null +++ b/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + + + com.loafle + maven_parent_jar + 1.0.0-RELEASE + + + com.loafle + central_api + jar + 1.0.0-SNAPSHOT + com.loafle.central_api + + + 1.2.0 + 3.2.0 + 0.5.0 + + + + + io.grpc + grpc-protobuf + ${grpc.version} + + + io.grpc + grpc-stub + ${grpc.version} + + + + + + + src/main/resources + true + + + + + src/test/resources + true + + + + + + kr.motd.maven + os-maven-plugin + 1.5.0.Final + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + ${protoc-maven-plugin.version} + + com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} + + + + + compile + compile-custom + + + + + + com.google.protobuf + protobuf-java + ${protoc.version} + + + + + + + + \ No newline at end of file diff --git a/src/main/proto/cmd b/src/main/proto/cmd new file mode 100644 index 0000000..cba582f --- /dev/null +++ b/src/main/proto/cmd @@ -0,0 +1 @@ +protoc -I src/main/proto/ src/main/proto/server_grpc.proto --go_out=plugins=grpc:golang \ No newline at end of file diff --git a/src/main/proto/server_grpc.proto b/src/main/proto/server_grpc.proto new file mode 100644 index 0000000..97464f6 --- /dev/null +++ b/src/main/proto/server_grpc.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "com.loafle.overflow.api"; +option java_generic_services = true; + +message ServerInput { + string target = 1; + string method = 2; + repeated string params = 3; +} + +message ServerParam { + string type = 1; + string data = 2; + bool isCollection = 3; +} + +message ServerOutput { + string result = 1; +} + +service OverflowApiServer { + rpc exec(ServerInput) returns (ServerOutput) {} +} + diff --git a/src/main/resources/_ b/src/main/resources/_ new file mode 100644 index 0000000..e69de29