Merge branch 'update-versions' into 'master'
Update versions See merge request packmate/Packmate!17
This commit is contained in:
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()
|
||||||
|
}
|
||||||
@@ -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
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,5 +1,6 @@
|
|||||||
package ru.serega6531.packmate.configuration;
|
package ru.serega6531.packmate.configuration;
|
||||||
|
|
||||||
|
import org.modelmapper.ModelMapper;
|
||||||
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.beans.factory.annotation.Value;
|
||||||
@@ -7,8 +8,6 @@ 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 org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import ru.serega6531.packmate.model.enums.CaptureMode;
|
import ru.serega6531.packmate.model.enums.CaptureMode;
|
||||||
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
import ru.serega6531.packmate.pcap.FilePcapWorker;
|
||||||
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
import ru.serega6531.packmate.pcap.LivePcapWorker;
|
||||||
@@ -42,8 +41,8 @@ public class ApplicationConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public ModelMapper modelMapper() {
|
||||||
return new BCryptPasswordEncoder();
|
return new ModelMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
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.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
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;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Value("${account-login}")
|
@Value("${account-login}")
|
||||||
private String login;
|
private String login;
|
||||||
@@ -23,35 +26,39 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
@Value("${account-password}")
|
@Value("${account-password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
@Bean
|
||||||
|
public InMemoryUserDetailsManager userDetailsService(PasswordEncoder passwordEncoder) {
|
||||||
@Autowired
|
UserDetails user = User.builder()
|
||||||
public SecurityConfiguration(PasswordEncoder passwordEncoder) {
|
.username(login)
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
|
||||||
auth.inMemoryAuthentication()
|
|
||||||
.withUser(login)
|
|
||||||
.password(passwordEncoder.encode(password))
|
.password(passwordEncoder.encode(password))
|
||||||
.authorities("ROLE_USER");
|
.roles("USER")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return new InMemoryUserDetailsManager(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.csrf()
|
return 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,13 +1,18 @@
|
|||||||
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.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.Pattern;
|
import ru.serega6531.packmate.model.Pattern;
|
||||||
import ru.serega6531.packmate.model.pojo.PatternDto;
|
import ru.serega6531.packmate.model.pojo.PatternDto;
|
||||||
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,7 +29,7 @@ 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}")
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
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 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.CtfService;
|
import ru.serega6531.packmate.model.CtfService;
|
||||||
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
import ru.serega6531.packmate.model.pojo.ServiceDto;
|
||||||
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/")
|
||||||
@@ -24,7 +29,7 @@ public class ServiceController {
|
|||||||
public List<ServiceDto> getServices() {
|
public List<ServiceDto> getServices() {
|
||||||
return service.findAll().stream()
|
return service.findAll().stream()
|
||||||
.map(service::toDto)
|
.map(service::toDto)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{port}")
|
@DeleteMapping("/{port}")
|
||||||
|
|||||||
@@ -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/")
|
||||||
@@ -25,14 +28,14 @@ public class StreamController {
|
|||||||
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()).stream()
|
||||||
.map(service::streamToDto)
|
.map(service::streamToDto)
|
||||||
.collect(Collectors.toList());
|
.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()).stream()
|
||||||
.map(service::streamToDto)
|
.map(service::streamToDto)
|
||||||
.collect(Collectors.toList());
|
.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;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ 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 jakarta.persistence.*;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,5 +1,6 @@
|
|||||||
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;
|
||||||
@@ -15,11 +16,13 @@ import ru.serega6531.packmate.model.pojo.PatternDto;
|
|||||||
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
|
||||||
@@ -60,10 +63,10 @@ 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::isEnabled)
|
||||||
.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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ 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.repository.ServiceRepository;
|
import ru.serega6531.packmate.repository.ServiceRepository;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|||||||
@@ -13,11 +13,19 @@ 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.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
|
||||||
@@ -71,15 +78,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();
|
||||||
@@ -107,7 +114,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());
|
||||||
@@ -190,7 +197,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;
|
||||||
@@ -245,7 +252,6 @@ public class StreamService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Packet> getPackets(long streamId, @Nullable Long startingFrom, int pageSize) {
|
public List<Packet> getPackets(long streamId, @Nullable Long startingFrom, int pageSize) {
|
||||||
// long safeStartingFrom = startingFrom != null ? startingFrom : 0;
|
|
||||||
return repository.getPackets(streamId, startingFrom, Pageable.ofSize(pageSize));
|
return repository.getPackets(streamId, startingFrom, Pageable.ofSize(pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user