From 3f9d6c05c211a620a7b491c13b059b1c7d827f24 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 16 Mar 2018 16:32:43 +0900 Subject: [PATCH] ing --- .../commons/model/SessionMetadata.java | 8 +- .../overflow/commons/stereotype/ProbeAPI.java | 11 + .../commons/stereotype/WebappAPI.java | 11 + .../module/discovery/model/DiscoveryHost.java | 52 ++++ .../module/discovery/model/DiscoveryPort.java | 61 +++++ .../discovery/model/DiscoveryService.java | 15 ++ .../module/discovery/model/DiscoveryZone.java | 25 ++ .../overflow/module/discovery/model/Host.java | 56 +--- .../overflow/module/discovery/model/Port.java | 76 +----- .../module/discovery/model/Service.java | 87 ++---- .../overflow/module/discovery/model/Zone.java | 21 +- .../discovery/service/DiscoveryService.java | 63 ++++- .../module/member/service/MemberService.java | 9 +- .../service/NoAuthProbeService.java | 5 + .../service/TargetDiscoveryService.java | 252 +++++++++--------- .../proxy/ProxyServerInterceptor.java | 4 +- 16 files changed, 435 insertions(+), 321 deletions(-) create mode 100644 src/main/java/com/loafle/overflow/commons/stereotype/ProbeAPI.java create mode 100644 src/main/java/com/loafle/overflow/commons/stereotype/WebappAPI.java create mode 100644 src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryHost.java create mode 100644 src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryPort.java create mode 100644 src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryService.java create mode 100644 src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryZone.java diff --git a/src/main/java/com/loafle/overflow/commons/model/SessionMetadata.java b/src/main/java/com/loafle/overflow/commons/model/SessionMetadata.java index e285db6..481a836 100644 --- a/src/main/java/com/loafle/overflow/commons/model/SessionMetadata.java +++ b/src/main/java/com/loafle/overflow/commons/model/SessionMetadata.java @@ -6,10 +6,10 @@ import io.grpc.Metadata; import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; public class SessionMetadata { - public static final Context.Key CTX_EMAIL_KEY = Context.key("email"); - public static final Metadata.Key METADATA_EMAIL_KEY = Metadata.Key.of("email", ASCII_STRING_MARSHALLER); + public static final Context.Key CTX_SESSION_ID_KEY = Context.key("SESSION_ID"); + public static final Metadata.Key METADATA_SESSION_ID_KEY = Metadata.Key.of("SESSION_ID", ASCII_STRING_MARSHALLER); - public static String getEmail() { - return CTX_EMAIL_KEY.get(); + public static String getSessionID() { + return CTX_SESSION_ID_KEY.get(); } } diff --git a/src/main/java/com/loafle/overflow/commons/stereotype/ProbeAPI.java b/src/main/java/com/loafle/overflow/commons/stereotype/ProbeAPI.java new file mode 100644 index 0000000..ce14bde --- /dev/null +++ b/src/main/java/com/loafle/overflow/commons/stereotype/ProbeAPI.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.commons.stereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface ProbeAPI { +} diff --git a/src/main/java/com/loafle/overflow/commons/stereotype/WebappAPI.java b/src/main/java/com/loafle/overflow/commons/stereotype/WebappAPI.java new file mode 100644 index 0000000..6ccb1f1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/commons/stereotype/WebappAPI.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.commons.stereotype; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface WebappAPI { +} diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryHost.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryHost.java new file mode 100644 index 0000000..b7bf02e --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryHost.java @@ -0,0 +1,52 @@ +package com.loafle.overflow.module.discovery.model; + +import java.util.List; + +public class DiscoveryHost { + private String firstScanRange; + private String lastScanRange; + private List excludeHosts; + private List includeHosts; + + private DiscoveryPort discoveryPort; + + public String getFirstScanRange() { + return firstScanRange; + } + + public void setFirstScanRange(String firstScanRange) { + this.firstScanRange = firstScanRange; + } + + public String getLastScanRange() { + return lastScanRange; + } + + public void setLastScanRange(String lastScanRange) { + this.lastScanRange = lastScanRange; + } + + public List getExcludeHosts() { + return excludeHosts; + } + + public void setExcludeHosts(List excludeHosts) { + this.excludeHosts = excludeHosts; + } + + public List getIncludeHosts() { + return includeHosts; + } + + public void setIncludeHosts(List includeHosts) { + this.includeHosts = includeHosts; + } + + public DiscoveryPort getDiscoveryPort() { + return discoveryPort; + } + + public void setDiscoveryPort(DiscoveryPort discoveryPort) { + this.discoveryPort = discoveryPort; + } +} diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryPort.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryPort.java new file mode 100644 index 0000000..6c61d1c --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryPort.java @@ -0,0 +1,61 @@ +package com.loafle.overflow.module.discovery.model; + +import java.util.List; + +public class DiscoveryPort { + private int firstScanRange; + private int lastScanRange; + private List excludePorts; + private boolean includeTCP; + private boolean includeUDP; + + private DiscoveryService discoveryService; + + public int getFirstScanRange() { + return firstScanRange; + } + + public void setFirstScanRange(int firstScanRange) { + this.firstScanRange = firstScanRange; + } + + public int getLastScanRange() { + return lastScanRange; + } + + public void setLastScanRange(int lastScanRange) { + this.lastScanRange = lastScanRange; + } + + public List getExcludePorts() { + return excludePorts; + } + + public void setExcludePorts(List excludePorts) { + this.excludePorts = excludePorts; + } + + public boolean isIncludeTCP() { + return includeTCP; + } + + public void setIncludeTCP(boolean includeTCP) { + this.includeTCP = includeTCP; + } + + public boolean isIncludeUDP() { + return includeUDP; + } + + public void setIncludeUDP(boolean includeUDP) { + this.includeUDP = includeUDP; + } + + public DiscoveryService getDiscoveryService() { + return discoveryService; + } + + public void setDiscoveryService(DiscoveryService discoveryService) { + this.discoveryService = discoveryService; + } +} diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryService.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryService.java new file mode 100644 index 0000000..527792b --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryService.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.module.discovery.model; + +import java.util.List; + +public class DiscoveryService { + private List includeServices; + + public List getIncludeServices() { + return includeServices; + } + + public void setIncludeServices(List includeServices) { + this.includeServices = includeServices; + } +} diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryZone.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryZone.java new file mode 100644 index 0000000..de75507 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoveryZone.java @@ -0,0 +1,25 @@ +package com.loafle.overflow.module.discovery.model; + +import java.util.List; + +public class DiscoveryZone { + private List excludePatterns; + + private DiscoveryHost discoveryHost; + + public List getExcludePatterns() { + return excludePatterns; + } + + public void setExcludePatterns(List excludePatterns) { + this.excludePatterns = excludePatterns; + } + + public DiscoveryHost getDiscoveryHost() { + return discoveryHost; + } + + public void setDiscoveryHost(DiscoveryHost discoveryHost) { + this.discoveryHost = discoveryHost; + } +} diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Host.java b/src/main/java/com/loafle/overflow/module/discovery/model/Host.java index 35a1c31..d4196af 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Host.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Host.java @@ -1,39 +1,19 @@ package com.loafle.overflow.module.discovery.model; - import java.util.Date; -import java.util.List; /** * Created by root on 17. 6. 4. */ public class Host { - - private long id; private long ip; private long mac; - - private Date createDate; - private Date updateDate; - private String os; - private boolean target; - - - private List ports; - - public List getPorts() { - return ports; - } - - public void setPorts(List ports) { - this.ports = ports; - } - - + private Date discoveredDate; + private Zone zone; public Host(){} @@ -66,22 +46,6 @@ public class Host { this.mac = mac; } - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - public Date getUpdateDate() { - return updateDate; - } - - public void setUpdateDate(Date updateDate) { - this.updateDate = updateDate; - } - public String getOs() { return os; } @@ -90,11 +54,19 @@ public class Host { this.os = os; } - public boolean isTarget() { - return target; + public Date getDiscoveredDate() { + return discoveredDate; } - public void setTarget(boolean target) { - this.target = target; + public void setDiscoveredDate(Date discoveredDate) { + this.discoveredDate = discoveredDate; + } + + public Zone getZone() { + return zone; + } + + public void setZone(Zone zone) { + this.zone = zone; } } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Port.java b/src/main/java/com/loafle/overflow/module/discovery/model/Port.java index e6e28aa..ada17f0 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Port.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Port.java @@ -8,7 +8,6 @@ package com.loafle.overflow.module.discovery.model; import com.loafle.overflow.module.discovery.type.PortType; import java.util.Date; -import java.util.List; /** * Created by root on 17. 6. 4. @@ -18,54 +17,14 @@ public class Port { private long id; - + private PortType portType; + private int portNumber; + private Date discoveredDate; private Host host; - public Host getHost() { - return host; - } - - public void setHost(Host host) { - this.host = host; - } - - private PortType portType; - - - private int portNumber; - - - - private List services; - - public List getServices() { - return services; - } - - public void setServices(List services) { - this.services = services; - } - - - private Date createDate; - - - private Date updateDate; public Port() {} - public Port(PortType type, int portNumber) { - this.portType = type; - this.portNumber = portNumber; - } - - public Port(Host host, PortType type, int portNumber) { - this.host = host; - this.portType = type; - this.portNumber = portNumber; - } - - public long getId() { return id; } @@ -90,33 +49,20 @@ public class Port { this.portNumber = portNumber; } - - - public Date getCreateDate() { - return createDate; + public Date getDiscoveredDate() { + return discoveredDate; } - public void setCreateDate(Date createDate) { - this.createDate = createDate; + public void setDiscoveredDate(Date discoveredDate) { + this.discoveredDate = discoveredDate; } - public Date getUpdateDate() { - return updateDate; + public Host getHost() { + return host; } - public void setUpdateDate(Date updateDate) { - this.updateDate = updateDate; + public void setHost(Host host) { + this.host = host; } - public void mappingChildren(Host discoveryHost) { - this.setHost(discoveryHost); - - - List discoveryServices = this.getServices(); - if (discoveryServices != null) { - for (int z = 0 ; z < discoveryServices.size() ; ++z) { - discoveryServices.get(z).setPort(this); - } - } - } } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Service.java b/src/main/java/com/loafle/overflow/module/discovery/model/Service.java index e58138e..f180bcd 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Service.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Service.java @@ -1,8 +1,5 @@ package com.loafle.overflow.module.discovery.model; - -import com.loafle.overflow.module.discovery.type.PortType; - import java.util.Date; /** @@ -10,48 +7,29 @@ import java.util.Date; */ public class Service { - - private long id; - + private String cryptoType; + private String serviceName; + private Date discoveredDate; private Port port; - public Port getPort() { - return port; - } - - public void setPort(Port port) { - this.port = port; - } - - - private PortType portType; - - - private String serviceName; - - - private Date createDate; - - - private Date updateDate; - - private boolean target; public Service() {} - public Service(Port port, PortType t, String serviceName) { - this.port = port; - this.portType = t; - this.serviceName = serviceName; + public long getId() { + return id; } - public PortType getPortType() { - return portType; + public void setId(long id) { + this.id = id; } - public void setPortType(PortType portType) { - this.portType = portType; + public String getCryptoType() { + return cryptoType; + } + + public void setCryptoType(String cryptoType) { + this.cryptoType = cryptoType; } public String getServiceName() { @@ -62,36 +40,21 @@ public class Service { this.serviceName = serviceName; } - public long getId() { - return id; + public Date getDiscoveredDate() { + return discoveredDate; } - public void setId(long id) { - this.id = id; + public void setDiscoveredDate(Date discoveredDate) { + this.discoveredDate = discoveredDate; + } + + public Port getPort() { + return port; + } + + public void setPort(Port port) { + this.port = port; } - public Date getCreateDate() { - return createDate; - } - - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } - - public Date getUpdateDate() { - return updateDate; - } - - public void setUpdateDate(Date updateDate) { - this.updateDate = updateDate; - } - - public boolean isTarget() { - return target; - } - - public void setTarget(boolean target) { - this.target = target; - } } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java b/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java index dd8b9b6..b55bd51 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java @@ -1,5 +1,7 @@ package com.loafle.overflow.module.discovery.model; +import java.util.Date; + /** * Created by snoop on 17. 10. 31. */ @@ -9,8 +11,7 @@ public class Zone { private String ip; private String iface; private String mac; - private long firstScanRange; - private long lastScanRange; + private Date discoveredDate; public long getId() { return id; @@ -52,19 +53,11 @@ public class Zone { this.mac = mac; } - public long getFirstScanRange() { - return firstScanRange; + public Date getDiscoveredDate() { + return discoveredDate; } - public void setFirstScanRange(long firstScanRange) { - this.firstScanRange = firstScanRange; - } - - public long getLastScanRange() { - return lastScanRange; - } - - public void setLastScanRange(long lastScanRange) { - this.lastScanRange = lastScanRange; + public void setDiscoveredDate(Date discoveredDate) { + this.discoveredDate = discoveredDate; } } diff --git a/src/main/java/com/loafle/overflow/module/discovery/service/DiscoveryService.java b/src/main/java/com/loafle/overflow/module/discovery/service/DiscoveryService.java index 03fdbf4..4ae0826 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/service/DiscoveryService.java +++ b/src/main/java/com/loafle/overflow/module/discovery/service/DiscoveryService.java @@ -1,7 +1,16 @@ package com.loafle.overflow.module.discovery.service; +import com.loafle.overflow.commons.model.SessionMetadata; import com.loafle.overflow.commons.service.MessagePublisher; +import com.loafle.overflow.commons.stereotype.ProbeAPI; +import com.loafle.overflow.commons.stereotype.WebappAPI; +import com.loafle.overflow.module.discovery.model.DiscoveryHost; +import com.loafle.overflow.module.discovery.model.DiscoveryPort; import com.loafle.overflow.module.discovery.model.DiscoveryStartInfo; +import com.loafle.overflow.module.discovery.model.DiscoveryZone; +import com.loafle.overflow.module.discovery.model.Host; +import com.loafle.overflow.module.discovery.model.Port; +import com.loafle.overflow.module.discovery.model.Zone; import com.loafle.overflow.module.domain.model.Domain; import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; @@ -49,5 +58,55 @@ public class DiscoveryService { return true; - } -} + } + + @WebappAPI + public void discoverZone(String probeID, DiscoveryZone discoveryZone) { + String requestMemberEmail = SessionMetadata.getSessionID(); + + messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverZone", requestMemberEmail, discoveryZone); + } + + @WebappAPI + public void discoverHost(String probeID, Zone zone, DiscoveryHost discoveryHost) { + String requestMemberEmail = SessionMetadata.getSessionID(); + + messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverHost", requestMemberEmail, zone, discoveryHost); + } + + @WebappAPI + public void discoverPort(String probeID, Host host, DiscoveryPort discoveryPort) { + String requestMemberEmail = SessionMetadata.getSessionID(); + + messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverPort", requestMemberEmail, host, discoveryPort); + } + + @WebappAPI + public void discoverService(String probeID, Port port, com.loafle.overflow.module.discovery.model.DiscoveryService discoveryService) { + String requestMemberEmail = SessionMetadata.getSessionID(); + + messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverService", requestMemberEmail, port, discoveryService); + } + + + @ProbeAPI + public void discoveredZone(String requestMemberEmail, Zone zone) { + messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredZone", zone); + } + + @ProbeAPI + public void discoveredHost(String requestMemberEmail, Host host) { + messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredHost", host); + } + + @ProbeAPI + public void discoveredPort(String requestMemberEmail, Port port) { + messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredPort", port); + } + + @ProbeAPI + public void discoveredService(String requestMemberEmail, com.loafle.overflow.module.discovery.model.Service service) { + messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredService", service); + } + +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java index 31dead5..b036edd 100644 --- a/src/main/java/com/loafle/overflow/module/member/service/MemberService.java +++ b/src/main/java/com/loafle/overflow/module/member/service/MemberService.java @@ -1,6 +1,7 @@ package com.loafle.overflow.module.member.service; import com.loafle.overflow.commons.model.SessionMetadata; +import com.loafle.overflow.commons.stereotype.WebappAPI; import com.loafle.overflow.commons.utils.EmailSender; import com.loafle.overflow.module.apikey.model.ApiKey; import com.loafle.overflow.module.apikey.service.ApiKeyService; @@ -21,7 +22,6 @@ import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.net.URLEncoder; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -113,7 +113,6 @@ public class MemberService { e.printStackTrace(); } - return resMember; } @@ -161,8 +160,9 @@ public class MemberService { // Todo websocket session remove } + @WebappAPI public Member modify(Member member, String pw) { - String email = SessionMetadata.getEmail(); + String email = SessionMetadata.getSessionID(); Member preMember = this.memberDAO.findByEmail(member.getEmail()); if (null != pw && !pw.equals("")) { @@ -227,8 +227,9 @@ public class MemberService { return resMember; } + @WebappAPI public void withdrawal(Member member) { - String email = SessionMetadata.getEmail(); + String email = SessionMetadata.getSessionID(); // Todo DB delete? } diff --git a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java index 2348c5c..b2d4c42 100644 --- a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java @@ -1,6 +1,8 @@ package com.loafle.overflow.module.noauthprobe.service; import com.loafle.overflow.commons.service.MessagePublisher; +import com.loafle.overflow.commons.stereotype.ProbeAPI; +import com.loafle.overflow.commons.stereotype.WebappAPI; import com.loafle.overflow.module.apikey.model.ApiKey; import com.loafle.overflow.module.apikey.service.ApiKeyService; import com.loafle.overflow.module.domain.model.Domain; @@ -44,6 +46,7 @@ public class NoAuthProbeService { @Autowired private MessagePublisher messagePublisher; + @ProbeAPI public NoAuthProbe regist(NoAuthProbe noAuthProbe) { noAuthProbe.setTempProbeKey(UUID.randomUUID().toString()); @@ -67,6 +70,7 @@ public class NoAuthProbeService { return this.noAuthProbeDAO.findOne(id); } + @WebappAPI public List acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException { // Todo domain injection & member injection @@ -108,6 +112,7 @@ public class NoAuthProbeService { return this.readAllByDomain(noAuthProbe.getDomain()); } + @WebappAPI public List denyNoauthProbe(NoAuthProbe noAuthProbe) { this.noAuthProbeDAO.save(noAuthProbe); diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java index 5fa6116..0895d71 100644 --- a/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetDiscoveryService.java @@ -44,177 +44,177 @@ public class TargetDiscoveryService { @Autowired private InfraServiceService infraServiceService; - @Transactional - public boolean saveAllTarget(List hosts, Probe probe) { + // @Transactional + // public boolean saveAllTarget(List hosts, Probe probe) { - InfraHost infraHost = null; + // InfraHost infraHost = null; - for(Host host : hosts) { + // for(Host host : hosts) { - infraHost = this.createAndReadHost(host, probe); + // infraHost = this.createAndReadHost(host, probe); - this.createPort(infraHost, host, probe); + // this.createPort(infraHost, host, probe); - } - return true; - } + // } + // return true; + // } - private void createService(InfraHost infraHost, Port port, Probe probe) { + // private void createService(InfraHost infraHost, Port port, Probe probe) { - if(port.getServices() == null) { - return; - } + // if(port.getServices() == null) { + // return; + // } - MetaInfraType typeService = new MetaInfraType(); - typeService.setId(7); + // MetaInfraType typeService = new MetaInfraType(); + // typeService.setId(7); - String portType = "UDP"; + // String portType = "UDP"; - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { - portType = "TCP"; - } + // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + // portType = "TCP"; + // } - for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { + // for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { - InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType); + // InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType); - if(dbInfraService != null) { - if(service.isTarget() && dbInfraService.getTarget() == null) { - Target targetService = new Target(); - targetService.setDisplayName(service.getServiceName() + "-Service"); - this.targetService.regist(targetService); - dbInfraService.setTarget(targetService); - this.infraServiceService.regist(dbInfraService); - } - continue; - } + // if(dbInfraService != null) { + // if(service.isTarget() && dbInfraService.getTarget() == null) { + // Target targetService = new Target(); + // targetService.setDisplayName(service.getServiceName() + "-Service"); + // this.targetService.regist(targetService); + // dbInfraService.setTarget(targetService); + // this.infraServiceService.regist(dbInfraService); + // } + // continue; + // } - InfraService infraService = new InfraService(); - infraService.setHost(infraHost); - infraService.setPort(port.getPortNumber()); - infraService.setPortType(portType); - infraService.setInfraType(typeService); - infraService.setProbe(probe); + // InfraService infraService = new InfraService(); + // infraService.setHost(infraHost); + // infraService.setPort(port.getPortNumber()); + // infraService.setPortType(portType); + // infraService.setInfraType(typeService); + // infraService.setProbe(probe); - if (port.getPortType() == PortType.TLS) { - infraService.setTlsType(true); - } - infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); + // if (port.getPortType() == PortType.TLS) { + // infraService.setTlsType(true); + // } + // infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); - if(service.isTarget()) { - Target targetService = new Target(); - targetService.setDisplayName(service.getServiceName() + "-Service"); - this.targetService.regist(targetService); - infraService.setTarget(targetService); - } + // if(service.isTarget()) { + // Target targetService = new Target(); + // targetService.setDisplayName(service.getServiceName() + "-Service"); + // this.targetService.regist(targetService); + // infraService.setTarget(targetService); + // } - this.infraServiceService.regist(infraService); + // this.infraServiceService.regist(infraService); - } + // } - } + // } - private void createPort(InfraHost infraHost, Host host, Probe probe) { + // private void createPort(InfraHost infraHost, Host host, Probe probe) { - if(host.getPorts() == null) { - return; - } + // if(host.getPorts() == null) { + // return; + // } - String portType = "UDP"; + // String portType = "UDP"; - MetaInfraType typePort = new MetaInfraType(); - typePort.setId(6); + // MetaInfraType typePort = new MetaInfraType(); + // typePort.setId(6); - InfraOS infraOS = infraHost.getOs(); + // InfraOS infraOS = infraHost.getOs(); - for(Port port : host.getPorts()) { + // for(Port port : host.getPorts()) { - if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { - portType = "TCP"; - } + // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { + // portType = "TCP"; + // } - InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType); - if(dbInfraOSPort == null) { - InfraOSPort infraOSPort = new InfraOSPort(); - infraOSPort.setOs(infraOS); - infraOSPort.setPort(port.getPortNumber()); - infraOSPort.setPortType(portType); - infraOSPort.setProbe(probe); - infraOSPort.setInfraType(typePort); + // InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType); + // if(dbInfraOSPort == null) { + // InfraOSPort infraOSPort = new InfraOSPort(); + // infraOSPort.setOs(infraOS); + // infraOSPort.setPort(port.getPortNumber()); + // infraOSPort.setPortType(portType); + // infraOSPort.setProbe(probe); + // infraOSPort.setInfraType(typePort); - if (port.getPortType() == PortType.TLS) { - infraOSPort.setTlsType(true); - } - infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); - this.infraOSPortService.regist(infraOSPort); - } + // if (port.getPortType() == PortType.TLS) { + // infraOSPort.setTlsType(true); + // } + // infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); + // this.infraOSPortService.regist(infraOSPort); + // } - this.createService(infraHost, port, probe); - } - } + // this.createService(infraHost, port, probe); + // } + // } - private InfraHost createAndReadHost(Host host, Probe probe) { + // private InfraHost createAndReadHost(Host host, Probe probe) { - InfraHost infraHost = this.infraHostService.readByIp(host.getIp()); - if(infraHost != null) { + // InfraHost infraHost = this.infraHostService.readByIp(host.getIp()); + // if(infraHost != null) { - if(host.isTarget() && infraHost.getTarget() == null) { - Target target = new Target(); - target.setDisplayName(String.valueOf(host.getIp()) + "-Host"); + // if(host.isTarget() && infraHost.getTarget() == null) { + // Target target = new Target(); + // target.setDisplayName(String.valueOf(host.getIp()) + "-Host"); - this.targetService.regist(target); - infraHost.setTarget(target); - this.infraHostService.regist(infraHost); - } + // this.targetService.regist(target); + // infraHost.setTarget(target); + // this.infraHostService.regist(infraHost); + // } - return infraHost; - } else { - MetaInfraType typeMachine = new MetaInfraType(); - typeMachine.setId(1); // 1 = Machine; + // return infraHost; + // } else { + // MetaInfraType typeMachine = new MetaInfraType(); + // typeMachine.setId(1); // 1 = Machine; - MetaInfraType typeOS = new MetaInfraType(); - typeOS.setId(3); // 3 = Os + // MetaInfraType typeOS = new MetaInfraType(); + // typeOS.setId(3); // 3 = Os - MetaInfraType typeHost = new MetaInfraType(); - typeHost.setId(2); // 2 = Host + // MetaInfraType typeHost = new MetaInfraType(); + // typeHost.setId(2); // 2 = Host - InfraMachine infraMachine = new InfraMachine(); - infraMachine.setProbe(probe); - infraMachine.setInfraType(typeMachine); - infraMachine.setMeta(StringConvertor.intToIp(host.getIp())+"-MACHINE"); - this.infraMachineService.regist(infraMachine); + // InfraMachine infraMachine = new InfraMachine(); + // infraMachine.setProbe(probe); + // infraMachine.setInfraType(typeMachine); + // infraMachine.setMeta(StringConvertor.intToIp(host.getIp())+"-MACHINE"); + // this.infraMachineService.regist(infraMachine); - InfraOS infraOS = new InfraOS(); - infraOS.setMachine(infraMachine); - infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); - infraOS.setInfraType(typeOS); - infraOS.setProbe(probe); - infraOS.setMeta(StringConvertor.intToIp(host.getIp())+"-OS"); - this.infraOSService.regist(infraOS); + // InfraOS infraOS = new InfraOS(); + // infraOS.setMachine(infraMachine); + // infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); + // infraOS.setInfraType(typeOS); + // infraOS.setProbe(probe); + // infraOS.setMeta(StringConvertor.intToIp(host.getIp())+"-OS"); + // this.infraOSService.regist(infraOS); - InfraHost newInfraHost = new InfraHost(); - newInfraHost.setIp(host.getIp()); - newInfraHost.setMac(host.getMac()); - newInfraHost.setOs(infraOS); - newInfraHost.setInfraType(typeHost); - newInfraHost.setProbe(probe); + // InfraHost newInfraHost = new InfraHost(); + // newInfraHost.setIp(host.getIp()); + // newInfraHost.setMac(host.getMac()); + // newInfraHost.setOs(infraOS); + // newInfraHost.setInfraType(typeHost); + // newInfraHost.setProbe(probe); - if(host.isTarget()) { - Target target = new Target(); - target.setDisplayName(StringConvertor.intToIp(host.getIp()) + "-Host"); + // if(host.isTarget()) { + // Target target = new Target(); + // target.setDisplayName(StringConvertor.intToIp(host.getIp()) + "-Host"); - this.targetService.regist(target); - newInfraHost.setTarget(target); - } + // this.targetService.regist(target); + // newInfraHost.setTarget(target); + // } - this.infraHostService.regist(newInfraHost); - infraHost = newInfraHost; - } + // this.infraHostService.regist(newInfraHost); + // infraHost = newInfraHost; + // } - return infraHost; - } + // return infraHost; + // } diff --git a/src/main/java/com/loafle/overflow/proxy/ProxyServerInterceptor.java b/src/main/java/com/loafle/overflow/proxy/ProxyServerInterceptor.java index 815634e..cec9aff 100644 --- a/src/main/java/com/loafle/overflow/proxy/ProxyServerInterceptor.java +++ b/src/main/java/com/loafle/overflow/proxy/ProxyServerInterceptor.java @@ -7,8 +7,8 @@ public class ProxyServerInterceptor implements ServerInterceptor { @Override public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler next) { - String email = headers.get(SessionMetadata.METADATA_EMAIL_KEY); - Context ctx = Context.current().withValue(SessionMetadata.CTX_EMAIL_KEY, email); + String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY); + Context ctx = Context.current().withValue(SessionMetadata.CTX_SESSION_ID_KEY, sessionID); return Contexts.interceptCall(ctx, call, headers, next); }