לדלג לתוכן

סביבת עבודה מתקדמת

מבוא

בקורס הבסיסי עבדנו בעיקר עם אפליקציות פגיעות מוכנות. בקורס המתקדם נצטרך סביבת עבודה גמישה יותר - סביבה שמאפשרת לנו להקים מעבדות מותאמות, לדמות תרחישים מציאותיים, ולתרגל תקיפות מורכבות.

בשיעור זה נלמד להקים סביבת עבודה מלאה באמצעות Docker, נגדיר שירותים מרובים, ונכין את הכל לשימוש לאורך הקורס.


התקנת Docker

לינוקס (Ubuntu/Debian)

# Update and install
sudo apt update
sudo apt install -y docker.io docker-compose-plugin

# Add the user to the docker group
sudo usermod -aG docker $USER

# Restart the session (or logout and login)
newgrp docker

# Verify everything works
docker run hello-world
docker compose version

macOS

# Install using Homebrew
brew install --cask docker

# After installation, open Docker Desktop from Applications
# Test
docker run hello-world

אימות ההתקנה

# Check versions
docker --version
docker compose version

# Verify the service is running
docker info

יסודות Docker Compose לסביבות בדיקה

מבנה בסיסי של docker-compose.yml

קובץ Docker Compose מאפשר לנו להגדיר מספר שירותים (קונטיינרים) שעובדים יחד. זה חיוני עבור סביבות בדיקה מציאותיות שכוללות אפליקציית ווב, בסיס נתונים, ולפעמים גם Reverse Proxy.

# docker-compose.yml - basic structure
version: "3.8"

services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html
    depends_on:
      - db

  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: testdb
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

פקודות Docker Compose חיוניות

# Start all services in the background
docker compose up -d

# View logs
docker compose logs -f

# Stop all services
docker compose down

# Stop and delete volumes (delete data)
docker compose down -v

# Rebuild images
docker compose build --no-cache

# Enter a specific container
docker compose exec web bash

התקנת אפליקציות פגיעות

DVWA - הגדרה מתקדמת

DVWA (Damn Vulnerable Web Application) מוכרת מהקורס הבסיסי, אך הפעם נגדיר אותה ברמת אבטחה גבוהה יותר כדי לתרגל bypass הגנות.

# docker-compose-dvwa.yml
version: "3.8"

services:
  dvwa:
    image: vulnerables/web-dvwa
    ports:
      - "8081:80"
    environment:
      - RECAPTCHA_PRIV_KEY=
      - RECAPTCHA_PUB_KEY=
      - SECURITY_LEVEL=high
      - PHPIDS_ENABLED=1
    depends_on:
      - dvwa-db

  dvwa-db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: dvwa
      MYSQL_DATABASE: dvwa
      MYSQL_USER: dvwa
      MYSQL_PASSWORD: dvwa
    volumes:
      - dvwa_data:/var/lib/mysql

volumes:
  dvwa_data:
# Start
docker compose -f docker-compose-dvwa.yml up -d

# Access in browser: http://localhost:8081
# Username: admin, password: password
# Change the security level to High or Impossible for advanced practice

OWASP WebGoat

WebGoat הוא כלי לימודי מצוין עם שיעורים אינטראקטיביים בנושאי אבטחה מתקדמים.

# docker-compose-webgoat.yml
version: "3.8"

services:
  webgoat:
    image: webgoat/webgoat
    ports:
      - "8082:8080"
      - "9090:9090"
    environment:
      - WEBGOAT_HOST=0.0.0.0
      - WEBGOAT_PORT=8080
    volumes:
      - webgoat_data:/home/webgoat/.webgoat

volumes:
  webgoat_data:
# Start
docker compose -f docker-compose-webgoat.yml up -d

# Access in browser: http://localhost:8082/WebGoat
# Register with a new username and password

OWASP Juice Shop

Juice Shop הוא אפליקציית חנות מקוונת מודרנית (Angular + Node.js) עם עשרות חולשות מובנות, כולל חולשות מתקדמות.

# docker-compose-juiceshop.yml
version: "3.8"

services:
  juiceshop:
    image: bkimminich/juice-shop
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=unsafe
# Start
docker compose -f docker-compose-juiceshop.yml up -d

# Access in browser: http://localhost:3000
# Score board: http://localhost:3000/#/score-board

מעבדה מותאמת - אפליקציית PHP עם מסד נתונים

לעיתים נצטרך לבנות אפליקציה פגיעה מותאמת. הנה דוגמה למעבדה מלאה:

# docker-compose-custom-lab.yml
version: "3.8"

services:
  web:
    build: ./web
    ports:
      - "8085:80"
    volumes:
      - ./web/src:/var/www/html
    depends_on:
      - db
    networks:
      - lab-network

  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: labpass
      MYSQL_DATABASE: vulnerable_app
    volumes:
      - ./db/init.sql:/docker-entrypoint-initdb.d/init.sql
      - lab_db:/var/lib/mysql
    networks:
      - lab-network

  proxy:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - web
    networks:
      - lab-network

networks:
  lab-network:
    driver: bridge

volumes:
  lab_db:

קובץ Dockerfile לשירות הווב:

# web/Dockerfile
FROM php:8.1-apache

RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN a2enmod rewrite headers

# Install useful debugging tools
RUN apt-get update && apt-get install -y \
    vim \
    curl \
    net-tools \
    && rm -rf /var/lib/apt/lists/*

COPY src/ /var/www/html/
RUN chown -R www-data:www-data /var/www/html

קובץ תצורת Nginx כ-Reverse Proxy:

# nginx/default.conf
server {
    listen 80;
    server_name localhost;

    location / {
        proxy_pass http://web:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

הגדרת PortSwigger Web Security Academy

יצירת חשבון

  1. היכנסו ל-https://portswigger.net/web-security
  2. צרו חשבון חינמי
  3. המעבדות מתחלקות לשלוש רמות: Apprentice, Practitioner, Expert
  4. בקורס זה נתמקד ברמות Practitioner ו-Expert

חיבור Burp Suite למעבדות

# Configure Burp Suite to work with PortSwigger Labs:
# 1. Open Burp Suite
# 2. Go to User Options > Connections
# 3. Make sure the Proxy Listener is set to 127.0.0.1:8080
# 4. In the browser, set the proxy to 127.0.0.1:8080
# 5. Install Burp's CA certificate: http://burp/cert

הגדרת כלים לבדיקות Out-of-Band

Burp Collaborator

Burp Collaborator זמין בגרסת Pro ומאפשר לזהות אינטראקציות out-of-band - כלומר, כאשר שרת היעד יוצר בקשה חזרה לשרת שלנו.

# Using Burp Collaborator:
# 1. Burp > Burp Collaborator Client
# 2. Click "Copy to clipboard" to get a unique address
# 3. Use the address in your payloads
# 4. Click "Poll now" to check for interactions

שימוש ב-webhook.site

חלופה חינמית ל-Burp Collaborator:

# 1. Go to https://webhook.site
# 2. You'll get a unique URL
# 3. Every request to that address is shown in real time

# Example use for testing SSRF:
# https://target.com/fetch?url=https://webhook.site/YOUR-UNIQUE-ID

# Example use for testing XXE:
# <!DOCTYPE foo [<!ENTITY xxe SYSTEM "https://webhook.site/YOUR-UNIQUE-ID">]>

הקמת שרת Collaborator עצמי

לתרחישים מתקדמים, ניתן להקים שרת משלנו:

# simple_collaborator.py - simple server for detecting interactions
from http.server import HTTPServer, BaseHTTPRequestHandler
import datetime
import json

class CollaboratorHandler(BaseHTTPRequestHandler):
    interactions = []

    def do_GET(self):
        interaction = {
            "time": str(datetime.datetime.now()),
            "method": "GET",
            "path": self.path,
            "headers": dict(self.headers),
            "client": self.client_address[0]
        }
        CollaboratorHandler.interactions.append(interaction)
        print(f"[+] Interaction received: {json.dumps(interaction, indent=2)}")

        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.end_headers()
        self.wfile.write(b"OK")

    def do_POST(self):
        content_length = int(self.headers.get("Content-Length", 0))
        body = self.rfile.read(content_length)
        interaction = {
            "time": str(datetime.datetime.now()),
            "method": "POST",
            "path": self.path,
            "headers": dict(self.headers),
            "body": body.decode("utf-8", errors="replace"),
            "client": self.client_address[0]
        }
        CollaboratorHandler.interactions.append(interaction)
        print(f"[+] Interaction received: {json.dumps(interaction, indent=2)}")

        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.end_headers()
        self.wfile.write(b"OK")

if __name__ == "__main__":
    server = HTTPServer(("0.0.0.0", 9999), CollaboratorHandler)
    print("[*] Collaborator server running on port 9999")
    server.serve_forever()
# Run
python3 simple_collaborator.py

# Expose to the internet with ngrok (for remote tests)
ngrok http 9999

הגדרות רשת לבדיקות

עריכת קובץ hosts

קובץ hosts מאפשר לנו למפות שמות דומיין לכתובות IP מקומיות. זה חיוני כאשר אנחנו רוצים לדמות סביבה עם מספר דומיינים.

# Edit the hosts file on Linux/macOS
sudo vim /etc/hosts

# Add entries for local labs
127.0.0.1   vulnerable.local
127.0.0.1   admin.vulnerable.local
127.0.0.1   api.vulnerable.local
127.0.0.1   dev.vulnerable.local
127.0.0.1   staging.vulnerable.local

הגדרת DNS מקומי עם dnsmasq

לסביבות מורכבות עם סאבדומיינים רבים, שימוש ב-dnsmasq נוח יותר:

# Install
sudo apt install dnsmasq

# Configuration - all .lab subdomains will resolve to 127.0.0.1
echo "address=/.lab/127.0.0.1" | sudo tee /etc/dnsmasq.d/lab.conf

# Restart
sudo systemctl restart dnsmasq

# Now every address ending in .lab resolves to localhost
# For example: target.lab, admin.target.lab, api.target.lab

הגדרת Nginx כ-Reverse Proxy מרובה דומיינים

# nginx-multi-domain.conf
# Main server
server {
    listen 80;
    server_name vulnerable.lab;

    location / {
        proxy_pass http://localhost:8081;
    }
}

# Admin panel
server {
    listen 80;
    server_name admin.vulnerable.lab;

    location / {
        proxy_pass http://localhost:8082;
    }
}

# API server
server {
    listen 80;
    server_name api.vulnerable.lab;

    location / {
        proxy_pass http://localhost:8083;
    }
}

סביבת Docker Compose מלאה - מעבדת קורס

הנה קובץ Docker Compose שמקים את כל הסביבות שנצטרך לאורך הקורס:

# docker-compose-course-lab.yml
version: "3.8"

services:
  # DVWA - high security level
  dvwa:
    image: vulnerables/web-dvwa
    ports:
      - "8081:80"
    environment:
      - SECURITY_LEVEL=high

  # Juice Shop - modern application
  juiceshop:
    image: bkimminich/juice-shop
    ports:
      - "3000:3000"

  # WebGoat - interactive lessons
  webgoat:
    image: webgoat/webgoat
    ports:
      - "8082:8080"
      - "9090:9090"

  # Collaborator server
  collaborator:
    build:
      context: ./collaborator
      dockerfile: Dockerfile
    ports:
      - "9999:9999"

  # Vulnerable GraphQL server for practice
  graphql-lab:
    image: dolevf/damned-vulnerable-graphql-application
    ports:
      - "5013:5013"

  # Vulnerable API server
  crapi:
    image: crapi/crapi
    ports:
      - "8888:8888"

  # Shared database
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql

volumes:
  mysql_data:
# Start all labs
docker compose -f docker-compose-course-lab.yml up -d

# Check status
docker compose -f docker-compose-course-lab.yml ps

# View logs for a specific service
docker compose -f docker-compose-course-lab.yml logs -f juiceshop

# Stop a specific service
docker compose -f docker-compose-course-lab.yml stop dvwa

# Stop everything
docker compose -f docker-compose-course-lab.yml down

ארגון תיקיות העבודה

מומלץ לארגן את תיקיית העבודה בצורה הבאה:

advanced-web-hacking-lab/
    docker/
        docker-compose-course-lab.yml
        docker-compose-dvwa.yml
        docker-compose-custom.yml
        collaborator/
            Dockerfile
            simple_collaborator.py
        web/
            Dockerfile
            src/
        nginx/
            default.conf
    tools/
        scripts/
        wordlists/
    notes/
        recon/
        exploits/
        reports/
    loot/
# Create the directory structure
mkdir -p advanced-web-hacking-lab/{docker/{collaborator,web/src,nginx},tools/{scripts,wordlists},notes/{recon,exploits,reports},loot}

בדיקת הסביבה

לאחר הקמת הסביבה, בצעו את הבדיקות הבאות:

# Verify all containers are running
docker ps

# Check access to each service
curl -s -o /dev/null -w "%{http_code}" http://localhost:8081  # DVWA
curl -s -o /dev/null -w "%{http_code}" http://localhost:3000  # Juice Shop
curl -s -o /dev/null -w "%{http_code}" http://localhost:8082  # WebGoat

# Verify Burp Suite is intercepting traffic
# 1. Set the browser proxy to 127.0.0.1:8080
# 2. Browse to one of the addresses
# 3. Verify the request appears in Burp's HTTP History tab

echo "Environment is ready!"

סיכום

בשיעור זה הקמנו סביבת עבודה מלאה הכוללת:

  • התקנת Docker ו-Docker Compose
  • אפליקציות פגיעות מגוונות (DVWA, WebGoat, Juice Shop)
  • כלי Collaborator לבדיקות out-of-band
  • הגדרות רשת מותאמות
  • מבנה תיקיות מאורגן

הסביבה הזו תלווה אותנו לאורך כל הקורס. בשיעור הבא נלמד על כלים מתקדמים ב-Burp Suite שישמשו אותנו בכל תרגיל ובדיקה.