Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7986658bd1 | ||
|
|
4fed53244d | ||
|
|
37fd548364 | ||
|
|
fcd7918125 | ||
|
|
c88ca8abbd | ||
|
|
15206188a2 | ||
|
|
4346445af9 | ||
|
|
f1d67f696d | ||
|
|
4b45f7dee7 | ||
|
|
a8ee7363d4 | ||
|
|
25d0921aed | ||
|
|
73fa5b1373 | ||
|
|
40136ad9d9 | ||
|
|
0b50f202fc | ||
|
|
288d24fffc | ||
|
|
40b42934b6 | ||
|
|
4cd5e72fee | ||
|
|
145f3e63c8 | ||
|
|
6ea53719fd | ||
|
|
8bbd135e96 | ||
|
|
79315c3c18 | ||
|
|
67c5462018 | ||
|
|
4e2473a3cc | ||
|
|
ea45f1b9e5 | ||
|
|
93ec39b561 | ||
|
|
7878ecebfc | ||
|
|
7afb9dc5fb | ||
|
|
8d33c6a6e1 |
50
build.gradle
50
build.gradle
@@ -1,50 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'org.springframework.boot' version '2.6.3'
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'io.spring.dependency-management'
|
|
||||||
|
|
||||||
group = 'ru.serega6531'
|
|
||||||
version = '1.0-SNAPSHOT'
|
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
|
||||||
|
|
||||||
configurations {
|
|
||||||
compileOnly {
|
|
||||||
extendsFrom annotationProcessor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
|
||||||
implementation "org.springframework.boot:spring-boot-starter-security"
|
|
||||||
implementation "org.springframework.boot:spring-boot-starter-websocket"
|
|
||||||
implementation 'org.springframework.session:spring-session-core'
|
|
||||||
implementation 'com.github.jmnarloch:modelmapper-spring-boot-starter:1.1.0'
|
|
||||||
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
|
|
||||||
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
|
|
||||||
implementation 'org.pcap4j:pcap4j-core:1.8.2'
|
|
||||||
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'
|
|
||||||
implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
|
|
||||||
implementation group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.5.1'
|
|
||||||
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
|
|
||||||
implementation group: 'org.bouncycastle', name: 'bctls-jdk15on', version: '1.70'
|
|
||||||
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.4.5'
|
|
||||||
compileOnly 'org.jetbrains:annotations:22.0.0'
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
|
||||||
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
|
|
||||||
runtimeOnly 'org.postgresql:postgresql'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
59
build.gradle.kts
Normal file
59
build.gradle.kts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.springframework.boot") version "3.0.6"
|
||||||
|
id("java")
|
||||||
|
id("io.spring.dependency-management") version "1.1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "ru.serega6531"
|
||||||
|
version = "1.0-SNAPSHOT"
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
get("compileOnly").apply {
|
||||||
|
extendsFrom(configurations.annotationProcessor.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-websocket")
|
||||||
|
implementation("org.springframework.session:spring-session-core")
|
||||||
|
implementation(group = "org.apache.commons", name = "commons-lang3", version = "3.12.0")
|
||||||
|
implementation(group = "commons-io", name = "commons-io", version = "2.11.0")
|
||||||
|
|
||||||
|
implementation("org.pcap4j:pcap4j-core:1.8.2")
|
||||||
|
implementation("org.pcap4j:pcap4j-packetfactory-static:1.8.2")
|
||||||
|
|
||||||
|
constraints {
|
||||||
|
implementation("net.java.dev.jna:jna:5.13.0") {
|
||||||
|
because("upgraded version required to run on MacOS")
|
||||||
|
// https://stackoverflow.com/questions/70368863/unsatisfiedlinkerror-for-m1-macs-while-running-play-server-locally
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
implementation(group = "com.google.guava", name = "guava", version = "31.1-jre")
|
||||||
|
implementation(group = "org.java-websocket", name = "Java-WebSocket", version = "1.5.3")
|
||||||
|
implementation(group = "org.bouncycastle", name = "bcprov-jdk15on", version = "1.70")
|
||||||
|
implementation(group = "org.bouncycastle", name = "bctls-jdk15on", version = "1.70")
|
||||||
|
implementation(group = "org.modelmapper", name = "modelmapper", version = "3.1.1")
|
||||||
|
compileOnly("org.jetbrains:annotations:24.0.1")
|
||||||
|
compileOnly("org.projectlombok:lombok")
|
||||||
|
runtimeOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
|
runtimeOnly("org.postgresql:postgresql")
|
||||||
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.getByName<Test>("test") {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
@@ -17,11 +17,13 @@ COPY --from=1 /tmp/compile/build/libs/packmate-*-SNAPSHOT.jar app.jar
|
|||||||
CMD [ "java", "-Djava.net.preferIPv4Stack=true", "-Djava.net.preferIPv4Addresses=true", \
|
CMD [ "java", "-Djava.net.preferIPv4Stack=true", "-Djava.net.preferIPv4Addresses=true", \
|
||||||
"-jar", "/app/app.jar", "--spring.datasource.url=jdbc:postgresql://127.0.0.1:65001/packmate", \
|
"-jar", "/app/app.jar", "--spring.datasource.url=jdbc:postgresql://127.0.0.1:65001/packmate", \
|
||||||
"--spring.datasource.password=${DB_PASSWORD}", \
|
"--spring.datasource.password=${DB_PASSWORD}", \
|
||||||
"--capture-mode=${MODE}", "--pcap-file=${PCAP_FILE}", \
|
"--packmate.capture-mode=${MODE}", "--packmate.pcap-file=${PCAP_FILE}", \
|
||||||
"--interface-name=${INTERFACE}", "--local-ip=${LOCAL_IP}", "--account-login=${WEB_LOGIN}", \
|
"--packmate.interface-name=${INTERFACE}", "--packmate.local-ip=${LOCAL_IP}", \
|
||||||
"--old-streams-cleanup-enabled=${OLD_STREAMS_CLEANUP_ENABLED}", "--cleanup-interval=${OLD_STREAMS_CLEANUP_INTERVAL}", \
|
"--packmate.web.account-login=${WEB_LOGIN}", "--packmate.web.account-password=${WEB_PASSWORD}", \
|
||||||
"--old-streams-threshold=${OLD_STREAMS_CLEANUP_THRESHOLD}", \
|
"--packmate.cleanup.enabled=${OLD_STREAMS_CLEANUP_ENABLED}", \
|
||||||
"--account-password=${WEB_PASSWORD}", "--server.port=65000", "--server.address=0.0.0.0" \
|
"--packmate.cleanup.interval=${OLD_STREAMS_CLEANUP_INTERVAL}", \
|
||||||
|
"--packmate.cleanup.threshold=${OLD_STREAMS_CLEANUP_THRESHOLD}", \
|
||||||
|
"--server.port=65000", "--server.address=0.0.0.0" \
|
||||||
]
|
]
|
||||||
|
|
||||||
EXPOSE 65000
|
EXPOSE 65000
|
||||||
@@ -75,9 +75,9 @@
|
|||||||
|
|
||||||
Совет: иногда на CTF забывают перезаписать TTL пакетов внутри сети. В таком случае по TTL можно отличить запросы от чекеров и от других команд.
|
Совет: иногда на CTF забывают перезаписать TTL пакетов внутри сети. В таком случае по TTL можно отличить запросы от чекеров и от других команд.
|
||||||
|
|
||||||
Совет #2: по User-Agent можно отличать запросы из разных источников. К примеру, можно предположить, что на скриншоте выше запросы 4 и 5 пришли из разных источников.
|
Совет #​2: по User-Agent можно отличать запросы из разных источников. К примеру, можно предположить, что на скриншоте выше запросы 4 и 5 пришли из разных источников.
|
||||||
|
|
||||||
Совет #3: нажимайте на звездочку, чтобы добавить интересный стрим в избранное. Этот стрим будет выделен в списке, и появится в списке избранных стримов.
|
Совет #​3: нажимайте на звездочку, чтобы добавить интересный стрим в избранное. Этот стрим будет выделен в списке, и появится в списке избранных стримов.
|
||||||
|
|
||||||
#### Управление просмотром
|
#### Управление просмотром
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
|
|
||||||
Совет: создавайте отдельные паттерны для входящих и исходящих флагов. Так легче отличать чекер, кладущий флаги, от эксплоитов.
|
Совет: создавайте отдельные паттерны для входящих и исходящих флагов. Так легче отличать чекер, кладущий флаги, от эксплоитов.
|
||||||
|
|
||||||
Совет #2: используйте Lookback для исследования найденных эксплоитов.
|
Совет #​2: используйте Lookback для исследования найденных эксплоитов.
|
||||||
|
|
||||||
Пример: вы обнаружили, что сервис только что отдал флаг пользователю `abc123` без видимых причин.
|
Пример: вы обнаружили, что сервис только что отдал флаг пользователю `abc123` без видимых причин.
|
||||||
Можно предположить, что атакующая команда создала этого пользователя и подготовила эксплоит в другом стриме.
|
Можно предположить, что атакующая команда создала этого пользователя и подготовила эксплоит в другом стриме.
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ you can switch between binary and text representation using the button in the si
|
|||||||
|
|
||||||
Tip: Sometimes during CTFs, admins forget to overwrite the TTL of packets inside the network. In such cases, you can differentiate requests from checkers and other teams based on TTL.
|
Tip: Sometimes during CTFs, admins forget to overwrite the TTL of packets inside the network. In such cases, you can differentiate requests from checkers and other teams based on TTL.
|
||||||
|
|
||||||
Tip #2: User-Agent can be used to differentiate requests from different sources. For example, in the screenshot above, requests 4 and 5 may have come from different sources.
|
Tip #​2: User-Agent can be used to differentiate requests from different sources. For example, in the screenshot above, requests 4 and 5 may have come from different sources.
|
||||||
|
|
||||||
Tip #3: Click on the star icon to add an interesting stream to your favorites. This stream will be highlighted in the list and will appear in the list of favorite streams.
|
Tip #​3: Click on the star icon to add an interesting stream to your favorites. This stream will be highlighted in the list and will appear in the list of favorite streams.
|
||||||
|
|
||||||
#### Control Panel
|
#### Control Panel
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ Tip #3: Click on the star icon to add an interesting stream to your favorites. T
|
|||||||
|
|
||||||
Tip: Create separate patterns for incoming and outgoing flags to easily distinguish between flag checkers and exploits.
|
Tip: Create separate patterns for incoming and outgoing flags to easily distinguish between flag checkers and exploits.
|
||||||
|
|
||||||
Tip #2: Use Lookback to investigate discovered exploits.
|
Tip #​2: Use Lookback to investigate discovered exploits.
|
||||||
|
|
||||||
Example: You found that the service just handed out a flag to user `abc123` without an apparent reason.
|
Example: You found that the service just handed out a flag to user `abc123` without an apparent reason.
|
||||||
You can assume that the attacking team created this user and prepared an exploit in another stream.
|
You can assume that the attacking team created this user and prepared an exploit in another stream.
|
||||||
|
|||||||
2
frontend
2
frontend
Submodule frontend updated: cfdfc9e578...079e8e95b6
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ pluginManagement {
|
|||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rootProject.name = 'packmate'
|
rootProject.name = "packmate"
|
||||||
@@ -1,28 +1,35 @@
|
|||||||
package ru.serega6531.packmate.configuration;
|
package ru.serega6531.packmate.configuration;
|
||||||
|
|
||||||
|
import org.modelmapper.Converter;
|
||||||
|
import org.modelmapper.ModelMapper;
|
||||||
|
import org.modelmapper.TypeMap;
|
||||||
import org.pcap4j.core.PcapNativeException;
|
import org.pcap4j.core.PcapNativeException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
import ru.serega6531.packmate.model.enums.CaptureMode;
|
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||||
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
import ru.serega6531.packmate.service.ServicesService;
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
import ru.serega6531.packmate.service.SubscriptionService;
|
import ru.serega6531.packmate.service.SubscriptionService;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
|
@ConfigurationPropertiesScan("ru.serega6531.packmate.properties")
|
||||||
public class ApplicationConfiguration {
|
public class ApplicationConfiguration {
|
||||||
|
|
||||||
@Bean(destroyMethod = "stop")
|
@Bean(destroyMethod = "stop")
|
||||||
@@ -30,20 +37,37 @@ public class ApplicationConfiguration {
|
|||||||
public PcapWorker pcapWorker(ServicesService servicesService,
|
public PcapWorker pcapWorker(ServicesService servicesService,
|
||||||
StreamService streamService,
|
StreamService streamService,
|
||||||
SubscriptionService subscriptionService,
|
SubscriptionService subscriptionService,
|
||||||
@Value("${local-ip}") String localIpString,
|
PackmateProperties properties
|
||||||
@Value("${interface-name}") String interfaceName,
|
) throws PcapNativeException, UnknownHostException {
|
||||||
@Value("${pcap-file}") String filename,
|
return switch (properties.captureMode()) {
|
||||||
@Value("${capture-mode}") CaptureMode captureMode) throws PcapNativeException, UnknownHostException {
|
case LIVE -> new LivePcapWorker(servicesService, streamService, properties.localIp(), properties.interfaceName());
|
||||||
return switch (captureMode) {
|
case FILE ->
|
||||||
case LIVE -> new LivePcapWorker(servicesService, streamService, localIpString, interfaceName);
|
new FilePcapWorker(servicesService, streamService, subscriptionService, properties.localIp(), properties.pcapFile());
|
||||||
case FILE -> new FilePcapWorker(servicesService, streamService, subscriptionService, localIpString, filename);
|
|
||||||
case VIEW -> new NoOpPcapWorker();
|
case VIEW -> new NoOpPcapWorker();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public ModelMapper modelMapper() {
|
||||||
return new BCryptPasswordEncoder();
|
ModelMapper modelMapper = new ModelMapper();
|
||||||
|
|
||||||
|
addStreamMapper(modelMapper);
|
||||||
|
|
||||||
|
return modelMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStreamMapper(ModelMapper modelMapper) {
|
||||||
|
TypeMap<Stream, StreamDto> streamMapper = modelMapper.createTypeMap(Stream.class, StreamDto.class);
|
||||||
|
|
||||||
|
Converter<Set<Pattern>, Set<Integer>> patternSetToIdSet = ctx -> ctx.getSource()
|
||||||
|
.stream()
|
||||||
|
.map(Pattern::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
streamMapper.addMappings(mapping ->
|
||||||
|
mapping.using(patternSetToIdSet)
|
||||||
|
.map(Stream::getFoundPatterns, StreamDto::setFoundPatternsIds)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,58 @@
|
|||||||
package ru.serega6531.packmate.configuration;
|
package ru.serega6531.packmate.configuration;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
|
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Value("${account-login}")
|
@Bean
|
||||||
private String login;
|
public InMemoryUserDetailsManager userDetailsService(PackmateProperties properties, PasswordEncoder passwordEncoder) {
|
||||||
|
UserDetails user = User.builder()
|
||||||
|
.username(properties.web().accountLogin())
|
||||||
|
.password(passwordEncoder.encode(properties.web().accountPassword()))
|
||||||
|
.roles("USER")
|
||||||
|
.build();
|
||||||
|
|
||||||
@Value("${account-password}")
|
return new InMemoryUserDetailsManager(user);
|
||||||
private String password;
|
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SecurityConfiguration(PasswordEncoder passwordEncoder) {
|
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Bean
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
return http.csrf()
|
||||||
.withUser(login)
|
|
||||||
.password(passwordEncoder.encode(password))
|
|
||||||
.authorities("ROLE_USER");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
http.csrf()
|
|
||||||
.disable()
|
.disable()
|
||||||
.authorizeRequests()
|
.authorizeHttpRequests((auth) ->
|
||||||
.antMatchers("/site.webmanifest")
|
auth.requestMatchers("/site.webmanifest")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest()
|
||||||
.and()
|
.authenticated()
|
||||||
|
)
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.and()
|
.and()
|
||||||
.headers()
|
.headers()
|
||||||
.frameOptions()
|
.frameOptions()
|
||||||
.sameOrigin();
|
.sameOrigin()
|
||||||
|
.and()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PasswordEncoder passwordEncoder() {
|
||||||
|
return new BCryptPasswordEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import ru.serega6531.packmate.model.Packet;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.serega6531.packmate.model.pojo.PacketDto;
|
import ru.serega6531.packmate.model.pojo.PacketDto;
|
||||||
import ru.serega6531.packmate.model.pojo.PacketPagination;
|
import ru.serega6531.packmate.model.pojo.PacketPagination;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/packet/")
|
@RequestMapping("/api/packet/")
|
||||||
@@ -23,10 +25,7 @@ public class PacketController {
|
|||||||
|
|
||||||
@PostMapping("/{streamId}")
|
@PostMapping("/{streamId}")
|
||||||
public List<PacketDto> getPacketsForStream(@PathVariable long streamId, @RequestBody PacketPagination pagination) {
|
public List<PacketDto> getPacketsForStream(@PathVariable long streamId, @RequestBody PacketPagination pagination) {
|
||||||
List<Packet> packets = streamService.getPackets(streamId, pagination.getStartingFrom(), pagination.getPageSize());
|
return streamService.getPackets(streamId, pagination.getStartingFrom(), pagination.getPageSize());
|
||||||
return packets.stream()
|
|
||||||
.map(streamService::packetToDto)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.serega6531.packmate.model.pojo.PatternCreateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.PatternDto;
|
import ru.serega6531.packmate.model.pojo.PatternDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.PatternUpdateDto;
|
||||||
import ru.serega6531.packmate.service.PatternService;
|
import ru.serega6531.packmate.service.PatternService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/pattern/")
|
@RequestMapping("/api/pattern/")
|
||||||
@@ -24,14 +31,19 @@ public class PatternController {
|
|||||||
public List<PatternDto> getPatterns() {
|
public List<PatternDto> getPatterns() {
|
||||||
return service.findAll()
|
return service.findAll()
|
||||||
.stream().map(service::toDto)
|
.stream().map(service::toDto)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}")
|
@PostMapping("/{id}/enable")
|
||||||
public void enable(@PathVariable int id, @RequestParam boolean enabled) {
|
public void enable(@PathVariable int id, @RequestParam boolean enabled) {
|
||||||
service.enable(id, enabled);
|
service.enable(id, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public void delete(@PathVariable int id) {
|
||||||
|
service.delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/lookback")
|
@PostMapping("/{id}/lookback")
|
||||||
public void lookBack(@PathVariable int id, @RequestBody int minutes) {
|
public void lookBack(@PathVariable int id, @RequestBody int minutes) {
|
||||||
if (minutes < 1) {
|
if (minutes < 1) {
|
||||||
@@ -42,11 +54,13 @@ public class PatternController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public PatternDto addPattern(@RequestBody PatternDto dto) {
|
public PatternDto addPattern(@RequestBody PatternCreateDto dto) {
|
||||||
dto.setEnabled(true);
|
return service.create(dto);
|
||||||
Pattern pattern = service.fromDto(dto);
|
}
|
||||||
Pattern saved = service.save(pattern);
|
|
||||||
return service.toDto(saved);
|
@PostMapping("/{id}")
|
||||||
|
public PatternDto updatePattern(@PathVariable int id, @RequestBody PatternUpdateDto dto) {
|
||||||
|
return service.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.serega6531.packmate.model.pojo.ServiceCreateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.ServiceUpdateDto;
|
||||||
import ru.serega6531.packmate.service.ServicesService;
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/service/")
|
@RequestMapping("/api/service/")
|
||||||
@@ -22,9 +28,7 @@ public class ServiceController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<ServiceDto> getServices() {
|
public List<ServiceDto> getServices() {
|
||||||
return service.findAll().stream()
|
return service.findAll();
|
||||||
.map(service::toDto)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{port}")
|
@DeleteMapping("/{port}")
|
||||||
@@ -33,9 +37,13 @@ public class ServiceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public CtfService addService(@RequestBody ServiceDto dto) {
|
public ServiceDto addService(@RequestBody ServiceCreateDto dto) {
|
||||||
CtfService newService = this.service.fromDto(dto);
|
return this.service.create(dto);
|
||||||
return this.service.save(newService);
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{port}")
|
||||||
|
public ServiceDto updateService(@PathVariable int port, @RequestBody ServiceUpdateDto dto) {
|
||||||
|
return this.service.update(port, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package ru.serega6531.packmate.controller;
|
package ru.serega6531.packmate.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import ru.serega6531.packmate.model.pojo.StreamPagination;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.serega6531.packmate.model.pojo.StreamDto;
|
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.StreamPagination;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/stream/")
|
@RequestMapping("/api/stream/")
|
||||||
@@ -23,16 +26,12 @@ public class StreamController {
|
|||||||
|
|
||||||
@PostMapping("/all")
|
@PostMapping("/all")
|
||||||
public List<StreamDto> getStreams(@RequestBody StreamPagination pagination) {
|
public List<StreamDto> getStreams(@RequestBody StreamPagination pagination) {
|
||||||
return service.findAll(pagination, Optional.empty(), pagination.isFavorites()).stream()
|
return service.findAll(pagination, Optional.empty(), pagination.isFavorites());
|
||||||
.map(service::streamToDto)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{port}")
|
@PostMapping("/{port}")
|
||||||
public List<StreamDto> getStreams(@PathVariable int port, @RequestBody StreamPagination pagination) {
|
public List<StreamDto> getStreams(@PathVariable int port, @RequestBody StreamPagination pagination) {
|
||||||
return service.findAll(pagination, Optional.of(port), pagination.isFavorites()).stream()
|
return service.findAll(pagination, Optional.of(port), pagination.isFavorites());
|
||||||
.map(service::streamToDto)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/favorite")
|
@PostMapping("/{id}/favorite")
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package ru.serega6531.packmate.model;
|
|||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.hibernate.Hibernate;
|
|||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Parameter;
|
import org.hibernate.annotations.Parameter;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.hibernate.Hibernate;
|
|||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Parameter;
|
import org.hibernate.annotations.Parameter;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package ru.serega6531.packmate.model;
|
package ru.serega6531.packmate.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -11,14 +16,13 @@ import ru.serega6531.packmate.model.enums.PatternActionType;
|
|||||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ToString
|
@ToString
|
||||||
@Entity
|
@Entity(name = "pattern")
|
||||||
@GenericGenerator(
|
@GenericGenerator(
|
||||||
name = "pattern_generator",
|
name = "pattern_generator",
|
||||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||||
@@ -34,8 +38,12 @@ public class Pattern {
|
|||||||
@GeneratedValue(generator = "pattern_generator")
|
@GeneratedValue(generator = "pattern_generator")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean deleted = false;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||||||
import org.hibernate.annotations.Parameter;
|
import org.hibernate.annotations.Parameter;
|
||||||
import ru.serega6531.packmate.model.enums.Protocol;
|
import ru.serega6531.packmate.model.enums.Protocol;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -53,7 +53,7 @@ public class Stream {
|
|||||||
|
|
||||||
private long endTimestamp;
|
private long endTimestamp;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
name = "stream_found_patterns",
|
name = "stream_found_patterns",
|
||||||
joinColumns = @JoinColumn(name = "stream_id"),
|
joinColumns = @JoinColumn(name = "stream_id"),
|
||||||
@@ -70,6 +70,12 @@ public class Stream {
|
|||||||
@Column(columnDefinition = "char(3)")
|
@Column(columnDefinition = "char(3)")
|
||||||
private String userAgentHash;
|
private String userAgentHash;
|
||||||
|
|
||||||
|
@Column(name = "size_bytes", nullable = false)
|
||||||
|
private Integer sizeBytes;
|
||||||
|
|
||||||
|
@Column(name = "packets_count", nullable = false)
|
||||||
|
private Integer packetsCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ru.serega6531.packmate.model.enums;
|
|||||||
|
|
||||||
public enum SubscriptionMessageType {
|
public enum SubscriptionMessageType {
|
||||||
SAVE_SERVICE, SAVE_PATTERN,
|
SAVE_SERVICE, SAVE_PATTERN,
|
||||||
DELETE_SERVICE, DELETE_PATTERN,
|
DELETE_SERVICE,
|
||||||
NEW_STREAM,
|
NEW_STREAM,
|
||||||
FINISH_LOOKBACK,
|
FINISH_LOOKBACK,
|
||||||
COUNTERS_UPDATE,
|
COUNTERS_UPDATE,
|
||||||
|
|||||||
@@ -1,23 +1,8 @@
|
|||||||
package ru.serega6531.packmate.model.pojo;
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Getter
|
public record CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
|
||||||
public class CountersHolder {
|
|
||||||
|
|
||||||
private final Map<Integer, Integer> servicesPackets;
|
|
||||||
private final Map<Integer, Integer> servicesStreams;
|
|
||||||
|
|
||||||
private final int totalPackets;
|
|
||||||
private final int totalStreams;
|
|
||||||
|
|
||||||
public CountersHolder(Map<Integer, Integer> servicesPackets, Map<Integer, Integer> servicesStreams,
|
|
||||||
int totalPackets, int totalStreams) {
|
int totalPackets, int totalStreams) {
|
||||||
this.servicesPackets = servicesPackets;
|
|
||||||
this.servicesStreams = servicesStreams;
|
|
||||||
this.totalPackets = totalPackets;
|
|
||||||
this.totalStreams = totalStreams;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||||
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
|
import ru.serega6531.packmate.model.enums.PatternSearchType;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PatternCreateDto {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
private String color;
|
||||||
|
private PatternSearchType searchType;
|
||||||
|
private PatternDirectionType directionType;
|
||||||
|
private PatternActionType actionType;
|
||||||
|
private Integer serviceId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ public class PatternDto {
|
|||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
private boolean deleted;
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
private String value;
|
||||||
private String color;
|
private String color;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PatternUpdateDto {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ServiceCreateDto {
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
private String name;
|
||||||
|
private boolean decryptTls;
|
||||||
|
private boolean processChunkedEncoding;
|
||||||
|
private boolean ungzipHttp;
|
||||||
|
private boolean urldecodeHttpRequests;
|
||||||
|
private boolean mergeAdjacentPackets;
|
||||||
|
private boolean parseWebSockets;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ServiceUpdateDto {
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
private String name;
|
||||||
|
private boolean decryptTls;
|
||||||
|
private boolean processChunkedEncoding;
|
||||||
|
private boolean ungzipHttp;
|
||||||
|
private boolean urldecodeHttpRequests;
|
||||||
|
private boolean mergeAdjacentPackets;
|
||||||
|
private boolean parseWebSockets;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,9 +13,11 @@ public class StreamDto {
|
|||||||
private Protocol protocol;
|
private Protocol protocol;
|
||||||
private long startTimestamp;
|
private long startTimestamp;
|
||||||
private long endTimestamp;
|
private long endTimestamp;
|
||||||
private Set<PatternDto> foundPatterns;
|
private Set<Integer> foundPatternsIds;
|
||||||
private boolean favorite;
|
private boolean favorite;
|
||||||
private int ttl;
|
private int ttl;
|
||||||
private String userAgentHash;
|
private String userAgentHash;
|
||||||
|
private int sizeBytes;
|
||||||
|
private int packetsCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,18 @@
|
|||||||
package ru.serega6531.packmate.model.pojo;
|
package ru.serega6531.packmate.model.pojo;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import ru.serega6531.packmate.model.enums.Protocol;
|
import ru.serega6531.packmate.model.enums.Protocol;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
@AllArgsConstructor
|
public record UnfinishedStream(InetAddress firstIp, InetAddress secondIp, int firstPort, int secondPort,
|
||||||
@Getter
|
Protocol protocol) {
|
||||||
public class UnfinishedStream {
|
|
||||||
|
|
||||||
private final InetAddress firstIp;
|
|
||||||
private final InetAddress secondIp;
|
|
||||||
private final int firstPort;
|
|
||||||
private final int secondPort;
|
|
||||||
private final Protocol protocol;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof UnfinishedStream)) {
|
if (!(obj instanceof UnfinishedStream o)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnfinishedStream o = (UnfinishedStream) obj;
|
|
||||||
|
|
||||||
boolean ipEq1 = firstIp.equals(o.firstIp) && secondIp.equals(o.secondIp);
|
boolean ipEq1 = firstIp.equals(o.firstIp) && secondIp.equals(o.secondIp);
|
||||||
boolean ipEq2 = firstIp.equals(o.secondIp) && secondIp.equals(o.firstIp);
|
boolean ipEq2 = firstIp.equals(o.secondIp) && secondIp.equals(o.firstIp);
|
||||||
boolean portEq1 = firstPort == o.firstPort && secondPort == o.secondPort;
|
boolean portEq1 = firstPort == o.firstPort && secondPort == o.secondPort;
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ public abstract class AbstractPcapWorker implements PcapWorker, PacketListener {
|
|||||||
|
|
||||||
protected AbstractPcapWorker(ServicesService servicesService,
|
protected AbstractPcapWorker(ServicesService servicesService,
|
||||||
StreamService streamService,
|
StreamService streamService,
|
||||||
String localIpString) throws UnknownHostException {
|
InetAddress localIp) throws UnknownHostException {
|
||||||
this.servicesService = servicesService;
|
this.servicesService = servicesService;
|
||||||
this.streamService = streamService;
|
this.streamService = streamService;
|
||||||
|
|
||||||
this.localIp = InetAddress.getByName(localIpString);
|
this.localIp = localIp;
|
||||||
|
|
||||||
BasicThreadFactory factory = new BasicThreadFactory.Builder()
|
BasicThreadFactory factory = new BasicThreadFactory.Builder()
|
||||||
.namingPattern("pcap-loop").build();
|
.namingPattern("pcap-loop").build();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import ru.serega6531.packmate.service.SubscriptionService;
|
|||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -27,9 +28,9 @@ public class FilePcapWorker extends AbstractPcapWorker {
|
|||||||
public FilePcapWorker(ServicesService servicesService,
|
public FilePcapWorker(ServicesService servicesService,
|
||||||
StreamService streamService,
|
StreamService streamService,
|
||||||
SubscriptionService subscriptionService,
|
SubscriptionService subscriptionService,
|
||||||
String localIpString,
|
InetAddress localIp,
|
||||||
String filename) throws UnknownHostException {
|
String filename) throws UnknownHostException {
|
||||||
super(servicesService, streamService, localIpString);
|
super(servicesService, streamService, localIp);
|
||||||
this.subscriptionService = subscriptionService;
|
this.subscriptionService = subscriptionService;
|
||||||
|
|
||||||
File directory = new File("pcaps");
|
File directory = new File("pcaps");
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import ru.serega6531.packmate.exception.PcapInterfaceNotFoundException;
|
|||||||
import ru.serega6531.packmate.service.ServicesService;
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@@ -23,9 +24,9 @@ public class LivePcapWorker extends AbstractPcapWorker {
|
|||||||
|
|
||||||
public LivePcapWorker(ServicesService servicesService,
|
public LivePcapWorker(ServicesService servicesService,
|
||||||
StreamService streamService,
|
StreamService streamService,
|
||||||
String localIpString,
|
InetAddress localIp,
|
||||||
String interfaceName) throws PcapNativeException, UnknownHostException {
|
String interfaceName) throws PcapNativeException, UnknownHostException {
|
||||||
super(servicesService, streamService, localIpString);
|
super(servicesService, streamService, localIp);
|
||||||
device = Pcaps.getDevByName(interfaceName);
|
device = Pcaps.getDevByName(interfaceName);
|
||||||
|
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package ru.serega6531.packmate.pcap;
|
package ru.serega6531.packmate.pcap;
|
||||||
|
|
||||||
import org.pcap4j.core.PcapNativeException;
|
|
||||||
import ru.serega6531.packmate.model.enums.Protocol;
|
import ru.serega6531.packmate.model.enums.Protocol;
|
||||||
|
|
||||||
public class NoOpPcapWorker implements PcapWorker {
|
public class NoOpPcapWorker implements PcapWorker {
|
||||||
@Override
|
@Override
|
||||||
public void start() throws PcapNativeException {
|
public void start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package ru.serega6531.packmate.properties;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
@ConfigurationProperties("packmate")
|
||||||
|
public record PackmateProperties(
|
||||||
|
CaptureMode captureMode,
|
||||||
|
String interfaceName,
|
||||||
|
String pcapFile,
|
||||||
|
InetAddress localIp,
|
||||||
|
WebProperties web,
|
||||||
|
TimeoutProperties timeout,
|
||||||
|
CleanupProperties cleanup,
|
||||||
|
boolean ignoreEmptyPackets
|
||||||
|
) {
|
||||||
|
|
||||||
|
public record WebProperties(
|
||||||
|
String accountLogin,
|
||||||
|
String accountPassword
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record TimeoutProperties(
|
||||||
|
int udpStreamTimeout,
|
||||||
|
int tcpStreamTimeout,
|
||||||
|
int checkInterval
|
||||||
|
){}
|
||||||
|
|
||||||
|
public record CleanupProperties(
|
||||||
|
boolean enabled,
|
||||||
|
int threshold,
|
||||||
|
int interval
|
||||||
|
){}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package ru.serega6531.packmate.repository;
|
package ru.serega6531.packmate.repository;
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.*;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import ru.serega6531.packmate.model.Packet;
|
import ru.serega6531.packmate.model.Packet;
|
||||||
import ru.serega6531.packmate.model.Stream;
|
import ru.serega6531.packmate.model.Stream;
|
||||||
|
|
||||||
import javax.persistence.QueryHint;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface StreamRepository extends JpaRepository<Stream, Long>, JpaSpecificationExecutor<Stream> {
|
public interface StreamRepository extends JpaRepository<Stream, Long>, JpaSpecificationExecutor<Stream> {
|
||||||
@@ -16,13 +18,12 @@ public interface StreamRepository extends JpaRepository<Stream, Long>, JpaSpecif
|
|||||||
|
|
||||||
long deleteByEndTimestampBeforeAndFavoriteIsFalse(long threshold);
|
long deleteByEndTimestampBeforeAndFavoriteIsFalse(long threshold);
|
||||||
|
|
||||||
@Query("SELECT DISTINCT p FROM Packet p " +
|
@Query("SELECT p FROM Packet p " +
|
||||||
"LEFT JOIN FETCH p.matches " +
|
"LEFT JOIN FETCH p.matches " +
|
||||||
"WHERE p.stream.id = :streamId " +
|
"WHERE p.stream.id = :streamId " +
|
||||||
"AND (:startingFrom IS NULL OR p.id > :startingFrom) " +
|
"AND (:startingFrom IS NULL OR p.id > :startingFrom) " +
|
||||||
"ORDER BY p.id"
|
"ORDER BY p.id"
|
||||||
)
|
)
|
||||||
@QueryHints(@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_PASS_DISTINCT_THROUGH, value = "false"))
|
|
||||||
List<Packet> getPackets(long streamId, Long startingFrom, Pageable pageable);
|
List<Packet> getPackets(long streamId, Long startingFrom, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
package ru.serega6531.packmate.service;
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
import ru.serega6531.packmate.model.FoundPattern;
|
import ru.serega6531.packmate.model.FoundPattern;
|
||||||
import ru.serega6531.packmate.model.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||||
|
import ru.serega6531.packmate.model.pojo.PatternCreateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.PatternDto;
|
import ru.serega6531.packmate.model.pojo.PatternDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.PatternUpdateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
import ru.serega6531.packmate.repository.PatternRepository;
|
import ru.serega6531.packmate.repository.PatternRepository;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -59,11 +65,11 @@ public class PatternService {
|
|||||||
|
|
||||||
public Set<FoundPattern> findMatches(byte[] bytes, CtfService service, PatternDirectionType directionType, PatternActionType actionType) {
|
public Set<FoundPattern> findMatches(byte[] bytes, CtfService service, PatternDirectionType directionType, PatternActionType actionType) {
|
||||||
final List<Pattern> list = patterns.values().stream()
|
final List<Pattern> list = patterns.values().stream()
|
||||||
.filter(Pattern::isEnabled)
|
.filter(pattern -> pattern.isEnabled() && !pattern.isDeleted())
|
||||||
.filter(p -> p.getServiceId() == null || p.getServiceId() == service.getPort())
|
.filter(p -> p.getServiceId() == null || p.getServiceId().equals(service.getPort()))
|
||||||
.filter(p -> p.getActionType() == actionType)
|
.filter(p -> p.getActionType() == actionType)
|
||||||
.filter(p -> p.getDirectionType() == directionType || p.getDirectionType() == PatternDirectionType.BOTH)
|
.filter(p -> p.getDirectionType() == directionType || p.getDirectionType() == PatternDirectionType.BOTH)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
return new PatternMatcher(bytes, list).findMatches();
|
return new PatternMatcher(bytes, list).findMatches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,15 +94,47 @@ public class PatternService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pattern save(Pattern pattern) {
|
public void delete(int id) {
|
||||||
|
final Pattern pattern = find(id);
|
||||||
|
if (pattern != null) {
|
||||||
|
pattern.setDeleted(true);
|
||||||
|
final Pattern saved = repository.save(pattern);
|
||||||
|
patterns.put(id, saved);
|
||||||
|
|
||||||
|
log.info("Deleted pattern '{}' with value '{}'", pattern.getName(), pattern.getValue());
|
||||||
|
subscriptionService.broadcast(new SubscriptionMessage(SubscriptionMessageType.SAVE_PATTERN, toDto(saved)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public PatternDto create(PatternCreateDto dto) {
|
||||||
|
Pattern pattern = fromDto(dto);
|
||||||
|
|
||||||
|
pattern.setEnabled(true);
|
||||||
|
pattern.setDeleted(false);
|
||||||
|
pattern.setSearchStartTimestamp(System.currentTimeMillis());
|
||||||
|
|
||||||
|
Pattern saved = save(pattern);
|
||||||
|
return toDto(saved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public PatternDto update(int id, PatternUpdateDto dto) {
|
||||||
|
Pattern pattern = repository.findById(id).orElseThrow();
|
||||||
|
|
||||||
|
modelMapper.map(dto, pattern);
|
||||||
|
|
||||||
|
Pattern saved = save(pattern);
|
||||||
|
return toDto(saved);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pattern save(Pattern pattern) {
|
||||||
try {
|
try {
|
||||||
PatternMatcher.compilePattern(pattern);
|
PatternMatcher.compilePattern(pattern);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException(e.getMessage());
|
throw new IllegalArgumentException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern.setSearchStartTimestamp(System.currentTimeMillis());
|
|
||||||
|
|
||||||
final Pattern saved = repository.save(pattern);
|
final Pattern saved = repository.save(pattern);
|
||||||
patterns.put(saved.getId(), saved);
|
patterns.put(saved.getId(), saved);
|
||||||
|
|
||||||
@@ -121,12 +159,11 @@ public class PatternService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pattern fromDto(PatternDto dto) {
|
public Pattern fromDto(PatternCreateDto dto) {
|
||||||
return modelMapper.map(dto, Pattern.class);
|
return modelMapper.map(dto, Pattern.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatternDto toDto(Pattern pattern) {
|
public PatternDto toDto(Pattern pattern) {
|
||||||
return modelMapper.map(pattern, PatternDto.class);
|
return modelMapper.map(pattern, PatternDto.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.pcap4j.core.PcapNativeException;
|
import org.pcap4j.core.PcapNativeException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
|
||||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||||
|
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
import ru.serega6531.packmate.pcap.NoOpPcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||||
@@ -40,14 +40,14 @@ public class PcapService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFilter(Collection<CtfService> services) {
|
public void updateFilter(Collection<ServiceDto> services) {
|
||||||
String filter;
|
String filter;
|
||||||
|
|
||||||
if (services.isEmpty()) {
|
if (services.isEmpty()) {
|
||||||
filter = "tcp or udp";
|
filter = "tcp or udp";
|
||||||
} else {
|
} else {
|
||||||
final String ports = services.stream()
|
final String ports = services.stream()
|
||||||
.map(CtfService::getPort)
|
.map(ServiceDto::getPort)
|
||||||
.map(p -> "port " + p)
|
.map(p -> "port " + p)
|
||||||
.collect(Collectors.joining(" or "));
|
.collect(Collectors.joining(" or "));
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
package ru.serega6531.packmate.service;
|
package ru.serega6531.packmate.service;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
import ru.serega6531.packmate.model.CtfService;
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||||
|
import ru.serega6531.packmate.model.pojo.ServiceCreateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.ServiceUpdateDto;
|
||||||
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
import ru.serega6531.packmate.repository.ServiceRepository;
|
import ru.serega6531.packmate.repository.ServiceRepository;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.util.HashMap;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -35,12 +40,12 @@ public class ServicesService {
|
|||||||
SubscriptionService subscriptionService,
|
SubscriptionService subscriptionService,
|
||||||
@Lazy PcapService pcapService,
|
@Lazy PcapService pcapService,
|
||||||
ModelMapper modelMapper,
|
ModelMapper modelMapper,
|
||||||
@Value("${local-ip}") String localIpString) throws UnknownHostException {
|
PackmateProperties properties) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.subscriptionService = subscriptionService;
|
this.subscriptionService = subscriptionService;
|
||||||
this.pcapService = pcapService;
|
this.pcapService = pcapService;
|
||||||
this.modelMapper = modelMapper;
|
this.modelMapper = modelMapper;
|
||||||
this.localIp = InetAddress.getByName(localIpString);
|
this.localIp = properties.localIp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@@ -67,8 +72,11 @@ public class ServicesService {
|
|||||||
return Optional.ofNullable(services.get(port));
|
return Optional.ofNullable(services.get(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<CtfService> findAll() {
|
public List<ServiceDto> findAll() {
|
||||||
return services.values();
|
return services.values()
|
||||||
|
.stream()
|
||||||
|
.map(this::toDto)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByPort(int port) {
|
public void deleteByPort(int port) {
|
||||||
@@ -82,9 +90,31 @@ public class ServicesService {
|
|||||||
updateFilter();
|
updateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CtfService save(CtfService service) {
|
@Transactional
|
||||||
log.info("Added or edited service '{}' at port {}", service.getName(), service.getPort());
|
public ServiceDto create(ServiceCreateDto dto) {
|
||||||
|
if (repository.existsById(dto.getPort())) {
|
||||||
|
throw new IllegalArgumentException("Service already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
CtfService service = fromDto(dto);
|
||||||
|
|
||||||
|
log.info("Added service '{}' at port {}", service.getName(), service.getPort());
|
||||||
|
|
||||||
|
return save(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public ServiceDto update(int port, ServiceUpdateDto dto) {
|
||||||
|
CtfService service = repository.findById(port).orElseThrow();
|
||||||
|
|
||||||
|
log.info("Edited service '{}' at port {}", service.getName(), service.getPort());
|
||||||
|
|
||||||
|
modelMapper.map(dto, service);
|
||||||
|
service.setPort(port);
|
||||||
|
return save(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServiceDto save(CtfService service) {
|
||||||
final CtfService saved = repository.save(service);
|
final CtfService saved = repository.save(service);
|
||||||
services.put(saved.getPort(), saved);
|
services.put(saved.getPort(), saved);
|
||||||
|
|
||||||
@@ -92,18 +122,18 @@ public class ServicesService {
|
|||||||
|
|
||||||
updateFilter();
|
updateFilter();
|
||||||
|
|
||||||
return saved;
|
return toDto(saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFilter() {
|
public void updateFilter() {
|
||||||
pcapService.updateFilter(findAll());
|
pcapService.updateFilter(findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceDto toDto(CtfService service) {
|
private ServiceDto toDto(CtfService service) {
|
||||||
return modelMapper.map(service, ServiceDto.class);
|
return modelMapper.map(service, ServiceDto.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CtfService fromDto(ServiceDto dto) {
|
private CtfService fromDto(ServiceCreateDto dto) {
|
||||||
return modelMapper.map(dto, CtfService.class);
|
return modelMapper.map(dto, CtfService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -13,11 +12,20 @@ import org.springframework.scheduling.annotation.Async;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.serega6531.packmate.model.*;
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
|
import ru.serega6531.packmate.model.FoundPattern;
|
||||||
|
import ru.serega6531.packmate.model.Packet;
|
||||||
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
|
import ru.serega6531.packmate.model.Stream;
|
||||||
import ru.serega6531.packmate.model.enums.PatternActionType;
|
import ru.serega6531.packmate.model.enums.PatternActionType;
|
||||||
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
import ru.serega6531.packmate.model.enums.PatternDirectionType;
|
||||||
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
import ru.serega6531.packmate.model.enums.SubscriptionMessageType;
|
||||||
import ru.serega6531.packmate.model.pojo.*;
|
import ru.serega6531.packmate.model.pojo.PacketDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.StreamDto;
|
||||||
|
import ru.serega6531.packmate.model.pojo.StreamPagination;
|
||||||
|
import ru.serega6531.packmate.model.pojo.SubscriptionMessage;
|
||||||
|
import ru.serega6531.packmate.model.pojo.UnfinishedStream;
|
||||||
import ru.serega6531.packmate.repository.StreamRepository;
|
import ru.serega6531.packmate.repository.StreamRepository;
|
||||||
import ru.serega6531.packmate.service.optimization.RsaKeysHolder;
|
import ru.serega6531.packmate.service.optimization.RsaKeysHolder;
|
||||||
import ru.serega6531.packmate.service.optimization.StreamOptimizer;
|
import ru.serega6531.packmate.service.optimization.StreamOptimizer;
|
||||||
@@ -28,7 +36,6 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -41,7 +48,6 @@ public class StreamService {
|
|||||||
private final SubscriptionService subscriptionService;
|
private final SubscriptionService subscriptionService;
|
||||||
private final RsaKeysHolder keysHolder;
|
private final RsaKeysHolder keysHolder;
|
||||||
private final ModelMapper modelMapper;
|
private final ModelMapper modelMapper;
|
||||||
|
|
||||||
private final boolean ignoreEmptyPackets;
|
private final boolean ignoreEmptyPackets;
|
||||||
|
|
||||||
private final java.util.regex.Pattern userAgentPattern = java.util.regex.Pattern.compile("User-Agent: (.+)\\r\\n");
|
private final java.util.regex.Pattern userAgentPattern = java.util.regex.Pattern.compile("User-Agent: (.+)\\r\\n");
|
||||||
@@ -54,7 +60,7 @@ public class StreamService {
|
|||||||
SubscriptionService subscriptionService,
|
SubscriptionService subscriptionService,
|
||||||
RsaKeysHolder keysHolder,
|
RsaKeysHolder keysHolder,
|
||||||
ModelMapper modelMapper,
|
ModelMapper modelMapper,
|
||||||
@Value("${ignore-empty-packets}") boolean ignoreEmptyPackets) {
|
PackmateProperties properties) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.patternService = patternService;
|
this.patternService = patternService;
|
||||||
this.servicesService = servicesService;
|
this.servicesService = servicesService;
|
||||||
@@ -62,7 +68,7 @@ public class StreamService {
|
|||||||
this.subscriptionService = subscriptionService;
|
this.subscriptionService = subscriptionService;
|
||||||
this.keysHolder = keysHolder;
|
this.keysHolder = keysHolder;
|
||||||
this.modelMapper = modelMapper;
|
this.modelMapper = modelMapper;
|
||||||
this.ignoreEmptyPackets = ignoreEmptyPackets;
|
this.ignoreEmptyPackets = properties.ignoreEmptyPackets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,15 +77,15 @@ public class StreamService {
|
|||||||
@Transactional(propagation = Propagation.NEVER)
|
@Transactional(propagation = Propagation.NEVER)
|
||||||
public boolean saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
public boolean saveNewStream(UnfinishedStream unfinishedStream, List<Packet> packets) {
|
||||||
final var serviceOptional = servicesService.findService(
|
final var serviceOptional = servicesService.findService(
|
||||||
unfinishedStream.getFirstIp(),
|
unfinishedStream.firstIp(),
|
||||||
unfinishedStream.getFirstPort(),
|
unfinishedStream.firstPort(),
|
||||||
unfinishedStream.getSecondIp(),
|
unfinishedStream.secondIp(),
|
||||||
unfinishedStream.getSecondPort()
|
unfinishedStream.secondPort()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (serviceOptional.isEmpty()) {
|
if (serviceOptional.isEmpty()) {
|
||||||
log.warn("Failed to save the stream: service at port {} or {} does not exist",
|
log.warn("Failed to save the stream: service at port {} or {} does not exist",
|
||||||
unfinishedStream.getFirstPort(), unfinishedStream.getSecondPort());
|
unfinishedStream.firstPort(), unfinishedStream.secondPort());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CtfService service = serviceOptional.get();
|
CtfService service = serviceOptional.get();
|
||||||
@@ -95,6 +101,9 @@ public class StreamService {
|
|||||||
|
|
||||||
countingService.countStream(service.getPort(), packets.size());
|
countingService.countStream(service.getPort(), packets.size());
|
||||||
|
|
||||||
|
int packetsSize = packets.stream().mapToInt(p -> p.getContent().length).sum();
|
||||||
|
int packetsCount = packets.size();
|
||||||
|
|
||||||
List<Packet> optimizedPackets = new StreamOptimizer(keysHolder, service, packets).optimizeStream();
|
List<Packet> optimizedPackets = new StreamOptimizer(keysHolder, service, packets).optimizeStream();
|
||||||
|
|
||||||
if (isStreamIgnored(optimizedPackets, service)) {
|
if (isStreamIgnored(optimizedPackets, service)) {
|
||||||
@@ -107,7 +116,7 @@ public class StreamService {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
final Stream stream = new Stream();
|
final Stream stream = new Stream();
|
||||||
stream.setProtocol(unfinishedStream.getProtocol());
|
stream.setProtocol(unfinishedStream.protocol());
|
||||||
stream.setTtl(firstIncoming.map(Packet::getTtl).orElse(0));
|
stream.setTtl(firstIncoming.map(Packet::getTtl).orElse(0));
|
||||||
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
stream.setStartTimestamp(packets.get(0).getTimestamp());
|
||||||
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
stream.setEndTimestamp(packets.get(packets.size() - 1).getTimestamp());
|
||||||
@@ -116,6 +125,9 @@ public class StreamService {
|
|||||||
String userAgentHash = getUserAgentHash(optimizedPackets);
|
String userAgentHash = getUserAgentHash(optimizedPackets);
|
||||||
stream.setUserAgentHash(userAgentHash);
|
stream.setUserAgentHash(userAgentHash);
|
||||||
|
|
||||||
|
stream.setSizeBytes(packetsSize);
|
||||||
|
stream.setPacketsCount(packetsCount);
|
||||||
|
|
||||||
Set<Pattern> foundPatterns = matchPatterns(optimizedPackets, service);
|
Set<Pattern> foundPatterns = matchPatterns(optimizedPackets, service);
|
||||||
stream.setFoundPatterns(foundPatterns);
|
stream.setFoundPatterns(foundPatterns);
|
||||||
stream.setPackets(optimizedPackets);
|
stream.setPackets(optimizedPackets);
|
||||||
@@ -190,7 +202,7 @@ public class StreamService {
|
|||||||
foundPatterns.addAll(matches.stream()
|
foundPatterns.addAll(matches.stream()
|
||||||
.map(FoundPattern::getPatternId)
|
.map(FoundPattern::getPatternId)
|
||||||
.map(patternService::find)
|
.map(patternService::find)
|
||||||
.collect(Collectors.toList()));
|
.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundPatterns;
|
return foundPatterns;
|
||||||
@@ -244,9 +256,12 @@ public class StreamService {
|
|||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Packet> getPackets(long streamId, @Nullable Long startingFrom, int pageSize) {
|
@Transactional
|
||||||
// long safeStartingFrom = startingFrom != null ? startingFrom : 0;
|
public List<PacketDto> getPackets(long streamId, @Nullable Long startingFrom, int pageSize) {
|
||||||
return repository.getPackets(streamId, startingFrom, Pageable.ofSize(pageSize));
|
return repository.getPackets(streamId, startingFrom, Pageable.ofSize(pageSize))
|
||||||
|
.stream()
|
||||||
|
.map(this::packetToDto)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,7 +277,8 @@ public class StreamService {
|
|||||||
repository.setFavorite(id, favorite);
|
repository.setFavorite(id, favorite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stream> findAll(StreamPagination pagination, Optional<Integer> service, boolean onlyFavorites) {
|
@Transactional
|
||||||
|
public List<StreamDto> findAll(StreamPagination pagination, Optional<Integer> service, boolean onlyFavorites) {
|
||||||
PageRequest page = PageRequest.of(0, pagination.getPageSize(), Sort.Direction.DESC, "id");
|
PageRequest page = PageRequest.of(0, pagination.getPageSize(), Sort.Direction.DESC, "id");
|
||||||
|
|
||||||
Specification<Stream> spec = Specification.where(null);
|
Specification<Stream> spec = Specification.where(null);
|
||||||
@@ -283,7 +299,11 @@ public class StreamService {
|
|||||||
spec = spec.and(streamPatternsContains(pagination.getPattern()));
|
spec = spec.and(streamPatternsContains(pagination.getPattern()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository.findAll(spec, page).getContent();
|
return repository.findAll(spec, page)
|
||||||
|
.getContent()
|
||||||
|
.stream()
|
||||||
|
.map(this::streamToDto)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stream> findAllBetweenTimestamps(long start, long end) {
|
public List<Stream> findAllBetweenTimestamps(long start, long end) {
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
package ru.serega6531.packmate.tasks;
|
package ru.serega6531.packmate.tasks;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
import ru.serega6531.packmate.service.StreamService;
|
import ru.serega6531.packmate.service.StreamService;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ConditionalOnExpression("${old-streams-cleanup-enabled:false} && '${capture-mode}' == 'LIVE'")
|
@ConditionalOnExpression("${packmate.cleanup.enabled:false} && '${packmate.capture-mode}' == 'LIVE'")
|
||||||
public class OldStreamsCleanupTask {
|
public class OldStreamsCleanupTask {
|
||||||
|
|
||||||
private final StreamService service;
|
private final StreamService service;
|
||||||
private final int oldStreamsThreshold;
|
private final int oldStreamsThreshold;
|
||||||
|
|
||||||
public OldStreamsCleanupTask(StreamService service, @Value("${old-streams-threshold}") int oldStreamsThreshold) {
|
public OldStreamsCleanupTask(StreamService service, PackmateProperties properties) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.oldStreamsThreshold = oldStreamsThreshold;
|
this.oldStreamsThreshold = properties.cleanup().threshold();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedDelayString = "PT${cleanup-interval}M", initialDelayString = "PT1M")
|
@Scheduled(fixedDelayString = "PT${packmate.cleanup.interval}M", initialDelayString = "PT1M")
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
ZonedDateTime before = ZonedDateTime.now().minus(oldStreamsThreshold, ChronoUnit.MINUTES);
|
ZonedDateTime before = ZonedDateTime.now().minusMinutes(oldStreamsThreshold);
|
||||||
log.info("Cleaning up old non-favorite streams (before {})", before);
|
log.info("Cleaning up old non-favorite streams (before {})", before);
|
||||||
long deleted = service.cleanupOldStreams(before);
|
long deleted = service.cleanupOldStreams(before);
|
||||||
log.info("Deleted {} rows", deleted);
|
log.info("Deleted {} rows", deleted);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package ru.serega6531.packmate.tasks;
|
package ru.serega6531.packmate.tasks;
|
||||||
|
|
||||||
import org.pcap4j.core.PcapNativeException;
|
import org.pcap4j.core.PcapNativeException;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
import ru.serega6531.packmate.model.enums.CaptureMode;
|
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||||
import ru.serega6531.packmate.service.PcapService;
|
import ru.serega6531.packmate.service.PcapService;
|
||||||
import ru.serega6531.packmate.service.ServicesService;
|
import ru.serega6531.packmate.service.ServicesService;
|
||||||
@@ -12,29 +12,23 @@ import ru.serega6531.packmate.service.ServicesService;
|
|||||||
@Component
|
@Component
|
||||||
public class StartupListener {
|
public class StartupListener {
|
||||||
|
|
||||||
@Value("${enable-capture}")
|
private final PackmateProperties packmateProperties;
|
||||||
private boolean enableCapture;
|
|
||||||
|
|
||||||
@Value("${capture-mode}")
|
|
||||||
private CaptureMode captureMode;
|
|
||||||
|
|
||||||
private final PcapService pcapService;
|
private final PcapService pcapService;
|
||||||
private final ServicesService servicesService;
|
private final ServicesService servicesService;
|
||||||
|
|
||||||
public StartupListener(PcapService pcapService, ServicesService servicesService) {
|
public StartupListener(PcapService pcapService, ServicesService servicesService, PackmateProperties packmateProperties) {
|
||||||
this.pcapService = pcapService;
|
this.pcapService = pcapService;
|
||||||
this.servicesService = servicesService;
|
this.servicesService = servicesService;
|
||||||
|
this.packmateProperties = packmateProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void afterStartup() throws PcapNativeException {
|
public void afterStartup() throws PcapNativeException {
|
||||||
if (enableCapture) {
|
|
||||||
servicesService.updateFilter();
|
servicesService.updateFilter();
|
||||||
|
|
||||||
if (captureMode == CaptureMode.LIVE) {
|
if (packmateProperties.captureMode() == CaptureMode.LIVE) {
|
||||||
pcapService.start();
|
pcapService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package ru.serega6531.packmate.tasks;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.serega6531.packmate.properties.PackmateProperties;
|
||||||
import ru.serega6531.packmate.model.enums.Protocol;
|
import ru.serega6531.packmate.model.enums.Protocol;
|
||||||
import ru.serega6531.packmate.pcap.PcapWorker;
|
import ru.serega6531.packmate.pcap.PcapWorker;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ConditionalOnProperty(name = "capture-mode", havingValue = "LIVE")
|
@ConditionalOnProperty(name = "packmate.capture-mode", havingValue = "LIVE")
|
||||||
public class TimeoutStreamsSaver {
|
public class TimeoutStreamsSaver {
|
||||||
|
|
||||||
private final PcapWorker pcapWorker;
|
private final PcapWorker pcapWorker;
|
||||||
@@ -22,14 +22,13 @@ public class TimeoutStreamsSaver {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TimeoutStreamsSaver(PcapWorker pcapWorker,
|
public TimeoutStreamsSaver(PcapWorker pcapWorker,
|
||||||
@Value("${udp-stream-timeout}") int udpStreamTimeout,
|
PackmateProperties properties) {
|
||||||
@Value("${tcp-stream-timeout}") int tcpStreamTimeout) {
|
|
||||||
this.pcapWorker = pcapWorker;
|
this.pcapWorker = pcapWorker;
|
||||||
this.udpStreamTimeoutMillis = TimeUnit.SECONDS.toMillis(udpStreamTimeout);
|
this.udpStreamTimeoutMillis = TimeUnit.SECONDS.toMillis(properties.timeout().udpStreamTimeout());
|
||||||
this.tcpStreamTimeoutMillis = TimeUnit.SECONDS.toMillis(tcpStreamTimeout);
|
this.tcpStreamTimeoutMillis = TimeUnit.SECONDS.toMillis(properties.timeout().tcpStreamTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRateString = "PT${timeout-stream-check-interval}S", initialDelayString = "PT${timeout-stream-check-interval}S")
|
@Scheduled(fixedRateString = "PT${packmate.timeout.check-interval}S", initialDelayString = "PT${packmate.timeout.check-interval}S")
|
||||||
public void saveStreams() {
|
public void saveStreams() {
|
||||||
int streamsClosed = pcapWorker.closeTimeoutStreams(Protocol.UDP, udpStreamTimeoutMillis);
|
int streamsClosed = pcapWorker.closeTimeoutStreams(Protocol.UDP, udpStreamTimeoutMillis);
|
||||||
if (streamsClosed > 0) {
|
if (streamsClosed > 0) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: "jdbc:postgresql://localhost/packmate"
|
url: "jdbc:postgresql://localhost:5432/packmate"
|
||||||
username: "packmate"
|
username: "packmate"
|
||||||
password: "123456"
|
password: "123456"
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
@@ -12,22 +12,27 @@ spring:
|
|||||||
jdbc:
|
jdbc:
|
||||||
batch_size: 20
|
batch_size: 20
|
||||||
order_inserts: true
|
order_inserts: true
|
||||||
temp:
|
|
||||||
use_jdbc_metadata_defaults: false
|
|
||||||
database-platform: org.hibernate.dialect.PostgreSQLDialect
|
database-platform: org.hibernate.dialect.PostgreSQLDialect
|
||||||
|
|
||||||
|
server:
|
||||||
|
compression:
|
||||||
|
enabled: true
|
||||||
|
min-response-size: 1KB
|
||||||
|
|
||||||
enable-capture: true
|
packmate:
|
||||||
capture-mode: LIVE # LIVE, FILE, VIEW
|
capture-mode: LIVE # LIVE, FILE, VIEW
|
||||||
interface-name: enp0s31f6
|
interface-name: enp0s31f6
|
||||||
pcap-file: file.pcap
|
pcap-file: file.pcap
|
||||||
local-ip: "192.168.0.125"
|
local-ip: "192.168.0.125"
|
||||||
|
web:
|
||||||
account-login: BinaryBears
|
account-login: BinaryBears
|
||||||
account-password: 123456
|
account-password: 123456
|
||||||
|
timeout:
|
||||||
udp-stream-timeout: 20 # seconds
|
udp-stream-timeout: 20 # seconds
|
||||||
tcp-stream-timeout: 40 # seconds
|
tcp-stream-timeout: 40 # seconds
|
||||||
timeout-stream-check-interval: 10 # seconds
|
check-interval: 10 # seconds
|
||||||
old-streams-cleanup-enabled: true
|
cleanup:
|
||||||
old-streams-threshold: 240 # minutes
|
enabled: true
|
||||||
cleanup-interval: 5 # minutes
|
threshold: 240 # minutes
|
||||||
|
interval: 5 # minutes
|
||||||
ignore-empty-packets: true
|
ignore-empty-packets: true
|
||||||
Reference in New Issue
Block a user