Denial of Service (DoS) - DrAlzahraniProjects/csusb_fall2024_cse6550_team4 GitHub Wiki

Denial of Service (DoS) Documentation


Folder Structure

The documentation is organized into the following folders, each with at least 5 pages as required:

  1. Installation
  2. Configuration
  3. Implementation
  4. Usage
  5. Troubleshooting

Each folder includes labeled and highlighted screenshots specific to the project.


1. Installation

Setting Up Tools for DoS Protection

  1. Install iptables for Traffic Filtering:

    • Command:
      sudo apt-get install iptables
      
    • [Screenshot 1]: Terminal output confirming successful installation of iptables. image
  2. Install Docker:

    • Commands:
      sudo apt-get update
      sudo apt-get install docker
      docker --version
      
  • [Screenshot 2]: Terminal output showing Docker version.

    image

  1. Set Up Mamba Environment:

    • Install Mamba:
      curl -L https://micro.mamba.pm/install.sh | bash
      
    • Create and activate the environment:
      mamba create -n dos-protection python=3.9
      mamba activate dos-protection
      
    • [Screenshot 3]: Terminal output confirming Mamba environment creation and activation. image
  2. Install Required Python Libraries:

    • Command:
      pip install requests flask
      
  3. Clone Project Repository from GitHub:

    • Command:
      git clone https://github.com/example/dos-protection.git
      cd dos-protection
      
    • [Screenshot 4]: Terminal showing the cloned repository structure.

image


2. Configuration

Configuring DoS Protection

  1. Set Up iptables Rules for Traffic Filtering:

    • Commands:
      sudo iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
      sudo iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
      sudo iptables -A INPUT -s 192.168.1.100 -j DROP
      
  2. Create a Dockerfile for Deployment:

    • Dockerfile content:
      FROM python:3.9
      WORKDIR /app
      COPY . .
      RUN pip install -r requirements.txt
      CMD ["python", "app.py"]
      
    • [Screenshot 5]: Dockerfile content in a text editor. WhatsApp Image 2024-11-21 at 2 57 41 PM
  3. Update Environment Variables:

    • Add the following variables in .env:
      APP_PORT=5000
      RATE_LIMIT=10  # Requests per minute
      
  4. Run Docker Compose:

    • Command:
      docker-compose up --build
      
  • [Screenshot 6]: Terminal output confirming successful build and run. image

3. Implementation

Implementing DoS Protection

  1. Develop app.py:

    • Code for simulating requests:

      from flask import Flask, request
      import time
      
      app = Flask(__name__)
      
      request_count = {}
      
      @app.route("/")
      def handle_request():
          client_ip = request.remote_addr
          current_time = time.time()
      
          if client_ip not in request_count:
              request_count[client_ip] = [current_time]
          else:
              request_count[client_ip].append(current_time)
      
          recent_requests = [
              req_time for req_time in request_count[client_ip] if current_time - req_time < 60
          ]
          request_count[client_ip] = recent_requests
      
          if len(recent_requests) > 10:  # Limit to 10 requests per minute
              return "Too Many Requests", 429
      
          return "Request Processed", 200
      
      if __name__ == "__main__":
          app.run(host="0.0.0.0", port=5000)
      
    • [Screenshot 6]: app.py code displayed in a text editor. image

  2. Test Application Locally:

    • Run the Flask application:
      python app.py
      
    • Simulate requests:
      for i in {1..20}; do curl http://localhost:5000; done
      
  3. Dockerize and Deploy:

    • Build and run the Docker container:
      docker build -t team4-app .
      
docker run -p 5004:5004 -p 6004:6004 team4-app
  • [Screenshot 7]: Docker build and run logs.

image


4. Usage

Using the DoS Protection System

  1. Simulate Traffic:

    • Run the app.py script or Docker container:
      python app.py
      
      or
      docker run -p 5000:5000 dos-protection
      
  2. Monitor Logs:

    • Command:
      docker logs <container-id>
      
    • [Screenshot 8]: Terminal showing logs for rate-limited requests. image
  3. Verify iptables Rules:

    • Command:
      sudo iptables -L
      

5. Troubleshooting

Common Issues and Solutions

  1. iptables Rules Not Applied:
    • Error: Traffic is not blocked.
    • Solution: Ensure iptables rules are active:
      sudo iptables -L
      
  • [Screenshot 9]: Output confirming active rules. ``` image
  1. Docker Container Does Not Start:
    • Error: Flask app fails to start.
    • Solution: Check Docker logs for errors:
      docker logs <container-id>
      
    • [Screenshot 10]: Docker logs displaying errors. image

Additional Requirements

SRS (Software Requirements Specification)

  • Description of the system requirements for DoS protection.

System Design (Low-Fidelity)

  • Includes architecture diagrams for DoS protection.

GitHub Features

  • List and explanation of 10 GitHub features used in the project (e.g., branching, pull requests).

ZAP Usage

  • Instructions for using ZAP for security testing.