This commit is contained in:
Vomitblood 2025-01-16 03:18:48 +08:00
parent 22f312cbb9
commit 4f984a46f8
9 changed files with 47 additions and 27 deletions

3
.gitignore vendored
View file

@ -16,3 +16,6 @@
# src-tauri # src-tauri
**/target/ **/target/
**/gen/schemas **/gen/schemas
# server
server/server

View file

@ -1,21 +1,12 @@
# cspj application # CSPJ Application
## attacks ## Services
1. sql injection - 3331: Apache + ModSecurity
2. xss - 3332: Suricata
3. command injection - 3333: Backend server
4. file inclusion attacks - 3334: Python backend server
5. csrf - 3335: PostgreSQL
6. directory traversal
7. insecure deserialization
8. session hijacking
9. xml external entity injection
10. sever side request forgery
11. broken authentication and session management
12. clickjacking
## backend
backend-for-frontend server backend-for-frontend server
@ -42,6 +33,7 @@ PGPASSWORD=asdfpassword
### SQL Injection ### SQL Injection
Use `' OR 1=1; --` Use `' OR 1=1; --`
Use `tohyouxuan@gmail.com' UNION SELECT id, email, password FROM users WHERE email = 'tohyouxuan@gmail.com'; --`
- `/unsecure-register-sql` - `/unsecure-register-sql`
- `/secure-register-sql` - `/secure-register-sql`
@ -52,3 +44,12 @@ Use `' OR 1=1; --`
Used `pool.Query()` with a parameterized query, instead of dynamically constructing the SQL query by directly inserting the user input. Used `pool.Query()` with a parameterized query, instead of dynamically constructing the SQL query by directly inserting the user input.
Parameterized queries separate the SQL code from the data, so user input is never directly put into the query's structure. Placeholders are used instead, and the data is passed as parameters. The DB will treat them as data, not executable code. Parameterized queries separate the SQL code from the data, so user input is never directly put into the query's structure. Placeholders are used instead, and the data is passed as parameters. The DB will treat them as data, not executable code.
## ZAP
Content-Type: application/json
{
"email": "tohyouxuan@gmail.com",
"password": "testpassword"
}

View file

@ -1,7 +1,9 @@
import { BugReportOutlined } from "@mui/icons-material"; import { BugReportOutlined } from "@mui/icons-material";
import { Box, Button, IconButton, useTheme } from "@mui/material"; import { Box, Button, IconButton, useTheme } from "@mui/material";
import { fetch } from "@tauri-apps/plugin-http"; import { fetch } from "@tauri-apps/plugin-http";
import { useAtom } from "jotai";
import { useState } from "react"; import { useState } from "react";
import { serverUrlAtom } from "../../lib/jotai";
import { defaultSettings } from "../../lib/settings"; import { defaultSettings } from "../../lib/settings";
import { FloatingDialog } from "../Generic/FloatingDialog"; import { FloatingDialog } from "../Generic/FloatingDialog";
@ -9,6 +11,9 @@ export const Testing = () => {
// contexts // contexts
const theme = useTheme(); const theme = useTheme();
// atoms
const [serverUrl, setServerUrl] = useAtom(serverUrlAtom);
// states // states
const [openState, setOpenState] = useState(false); const [openState, setOpenState] = useState(false);
const [maximisedState, setMaximisedState] = useState(false); const [maximisedState, setMaximisedState] = useState(false);
@ -17,10 +22,10 @@ export const Testing = () => {
const close = () => setOpenState(false); const close = () => setOpenState(false);
const testing = () => { const testing = () => {
fetch("http://localhost:5000/nuke-db").then((response) => { fetch(serverUrl + "/nuke-db").then((response) => {
console.log(response); console.log(response);
}); });
fetch("http://localhost:5000/setup-demo-db").then((response) => { fetch(serverUrl + "/setup-demo-db").then((response) => {
console.log(response); console.log(response);
}); });
}; };

View file

@ -4,13 +4,13 @@ services:
container_name: modsecurity container_name: modsecurity
restart: always restart: always
ports: ports:
- "8080:8080" - "3331:3331"
extra_hosts: extra_hosts:
- "host.docker.internal:host-gateway" - "host.docker.internal:host-gateway"
environment: environment:
BACKEND: "http://host.docker.internal:5000" BACKEND: "http://host.docker.internal:3333" # TODO: CHANGE THIS TO SURICATA'S PORT COS INLINE
SERVER_NAME: "localhost" SERVER_NAME: "localhost"
PORT: "8080" PORT: "3331"
networks: networks:
- modsec-network - modsec-network

View file

@ -7,7 +7,7 @@ services:
POSTGRES_PASSWORD: asdfpassword POSTGRES_PASSWORD: asdfpassword
POSTGRES_DB: asdfdb POSTGRES_DB: asdfdb
ports: ports:
- "5432:5432" - "3335:5432"
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
volumes: volumes:

1
docker/zaproxy/run.sh Normal file
View file

@ -0,0 +1 @@
docker run -v $(pwd):/zap/wrk/:rw -t zaproxy/zap-stable zap.sh -cmd -autorun /zap/wrk/zap.yaml

10
docker/zaproxy/zap.yaml Normal file
View file

@ -0,0 +1,10 @@
jobs:
- type: spider
parameters:
context: "Default Context"
url: "http://localhost:5000/unsafe-login"
maxDuration: 2
- type: activeScan
parameters:
context: "Default Context"
policy: "SQL Injection"

View file

@ -14,7 +14,7 @@ import (
// !MIGHT CHANGE // !MIGHT CHANGE
const ( const (
host = "localhost" host = "localhost"
port = 5432 port = 3335
user = "asdfuser" user = "asdfuser"
password = "asdfpassword" password = "asdfpassword"
dbname = "asdfdb" dbname = "asdfdb"

View file

@ -26,8 +26,8 @@ func ServeApi() {
http.HandleFunc("/unsecure-login-sql", sql_injection.UnsecureLoginSql) http.HandleFunc("/unsecure-login-sql", sql_injection.UnsecureLoginSql)
http.HandleFunc("/secure-login-sql", sql_injection.SecureLoginSql) http.HandleFunc("/secure-login-sql", sql_injection.SecureLoginSql)
log.Println("Server is running on http://localhost:5000") log.Println("Server is running on http://localhost:3333")
if err := http.ListenAndServe(":5000", nil); err != nil { if err := http.ListenAndServe(":3333", nil); err != nil {
log.Fatalf("Failed to start server: %v", err) log.Fatalf("Failed to start server: %v", err)
} }
} }