Добавлена возможность выключения перехвата пакетов
This commit is contained in:
@@ -54,6 +54,6 @@ public class ApplicationConfiguration extends WebSecurityConfigurerAdapter imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(webSocketHandler, "/ws").withSockJS();
|
registry.addHandler(webSocketHandler, "/api/ws").withSockJS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.serega6531.packmate;
|
package ru.serega6531.packmate;
|
||||||
|
|
||||||
import org.pcap4j.core.PcapNativeException;
|
import org.pcap4j.core.PcapNativeException;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
@@ -11,14 +12,19 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class PackmateApplication {
|
public class PackmateApplication {
|
||||||
|
|
||||||
|
@Value("${enable-capture}")
|
||||||
|
private boolean enableCapture;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(PackmateApplication.class, args);
|
SpringApplication.run(PackmateApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
|
public void afterStartup(ApplicationReadyEvent event) throws PcapNativeException {
|
||||||
|
if(enableCapture) {
|
||||||
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
|
final PcapWorker pcapWorker = event.getApplicationContext().getBean(PcapWorker.class);
|
||||||
pcapWorker.start();
|
pcapWorker.start();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
|
import ru.serega6531.packmate.model.Protocol;
|
||||||
import ru.serega6531.packmate.model.UnfinishedStream;
|
import ru.serega6531.packmate.model.UnfinishedStream;
|
||||||
import ru.serega6531.packmate.service.ServicesService;
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class UdpStreamsSaver {
|
|||||||
this.pcapWorker = pcapWorker;
|
this.pcapWorker = pcapWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRateString = "PT${udp-stream-check-interval}S")
|
@Scheduled(fixedRateString = "PT${udp-stream-check-interval}S", initialDelayString = "PT${udp-stream-check-interval}S")
|
||||||
public void saveStreams() {
|
public void saveStreams() {
|
||||||
final int streamsClosed = pcapWorker.closeUdpStreams();
|
final int streamsClosed = pcapWorker.closeUdpStreams();
|
||||||
if(streamsClosed > 0) {
|
if(streamsClosed > 0) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ru.serega6531.packmate;
|
package ru.serega6531.packmate.model;
|
||||||
|
|
||||||
public enum Protocol {
|
public enum Protocol {
|
||||||
TCP, UDP
|
TCP, UDP
|
||||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import ru.serega6531.packmate.Protocol;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package ru.serega6531.packmate.model;
|
|||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import ru.serega6531.packmate.Protocol;
|
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class ServicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByPort(int port) {
|
public void deleteByPort(int port) {
|
||||||
|
log.info("Удален сервис на порту {}", port);
|
||||||
repository.deleteById(port);
|
repository.deleteById(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.serega6531.packmate.model.Packet;
|
import ru.serega6531.packmate.model.*;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
|
||||||
import ru.serega6531.packmate.model.Stream;
|
|
||||||
import ru.serega6531.packmate.model.UnfinishedStream;
|
|
||||||
import ru.serega6531.packmate.repository.StreamRepository;
|
import ru.serega6531.packmate.repository.StreamRepository;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -42,17 +39,25 @@ public class StreamService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
public void saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
||||||
Stream stream = new Stream();
|
final Optional<CtfService> serviceOptional = servicesService.findService(
|
||||||
stream.setProtocol(unfinishedStream.getProtocol());
|
|
||||||
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
|
||||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
|
||||||
stream.setService(servicesService.findService(
|
|
||||||
localIp,
|
localIp,
|
||||||
unfinishedStream.getFirstIp().getHostAddress(),
|
unfinishedStream.getFirstIp().getHostAddress(),
|
||||||
unfinishedStream.getFirstPort(),
|
unfinishedStream.getFirstPort(),
|
||||||
unfinishedStream.getSecondIp().getHostAddress(),
|
unfinishedStream.getSecondIp().getHostAddress(),
|
||||||
unfinishedStream.getSecondPort()
|
unfinishedStream.getSecondPort()
|
||||||
).get());
|
);
|
||||||
|
|
||||||
|
if (!serviceOptional.isPresent()) {
|
||||||
|
log.info("Не удалось сохранить стрим: сервиса на порту {} или {} не существует",
|
||||||
|
unfinishedStream.getFirstPort(), unfinishedStream.getSecondPort());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.setProtocol(unfinishedStream.getProtocol());
|
||||||
|
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
||||||
|
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||||
|
stream.setService(serviceOptional.get());
|
||||||
|
|
||||||
Stream savedStream = save(stream);
|
Stream savedStream = save(stream);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ spring:
|
|||||||
hibernate:
|
hibernate:
|
||||||
temp:
|
temp:
|
||||||
use_jdbc_metadata_defaults: false
|
use_jdbc_metadata_defaults: false
|
||||||
|
|
||||||
|
enable-capture: false
|
||||||
interface-name: enp0s31f6
|
interface-name: enp0s31f6
|
||||||
local-ip: "192.168.0.125"
|
local-ip: "192.168.0.125"
|
||||||
account-login: BinaryBears
|
account-login: BinaryBears
|
||||||
|
|||||||
Reference in New Issue
Block a user