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:
- Installation
- Configuration
- Implementation
- Usage
- Troubleshooting
Each folder includes labeled and highlighted screenshots specific to the project.
1. Installation
Setting Up Tools for DoS Protection
-
Install iptables for Traffic Filtering:
- Command:
sudo apt-get install iptables
- [Screenshot 1]: Terminal output confirming successful installation of
iptables
.
- Command:
-
Install Docker:
- Commands:
sudo apt-get update sudo apt-get install docker docker --version
- Commands:
-
[Screenshot 2]: Terminal output showing Docker version.
-
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.
- Install Mamba:
-
Install Required Python Libraries:
- Command:
pip install requests flask
- Command:
-
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.
- Command:
2. Configuration
Configuring DoS Protection
-
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
- Commands:
-
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.
- Dockerfile content:
-
Update Environment Variables:
- Add the following variables in
.env
:APP_PORT=5000 RATE_LIMIT=10 # Requests per minute
- Add the following variables in
-
Run Docker Compose:
- Command:
docker-compose up --build
- Command:
- [Screenshot 6]: Terminal output confirming successful build and run.
3. Implementation
Implementing DoS Protection
-
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.
-
-
Test Application Locally:
- Run the Flask application:
python app.py
- Simulate requests:
for i in {1..20}; do curl http://localhost:5000; done
- Run the Flask application:
-
Dockerize and Deploy:
- Build and run the Docker container:
docker build -t team4-app .
- Build and run the Docker container:
docker run -p 5004:5004 -p 6004:6004 team4-app
- [Screenshot 7]: Docker build and run logs.
4. Usage
Using the DoS Protection System
-
Simulate Traffic:
- Run the
app.py
script or Docker container:
orpython app.py
docker run -p 5000:5000 dos-protection
- Run the
-
Monitor Logs:
- Command:
docker logs <container-id>
- [Screenshot 8]: Terminal showing logs for rate-limited requests.
- Command:
-
Verify iptables Rules:
- Command:
sudo iptables -L
- Command:
5. Troubleshooting
Common Issues and Solutions
- iptables Rules Not Applied:
- Error: Traffic is not blocked.
- Solution: Ensure
iptables
rules are active:sudo iptables -L
- [Screenshot 9]: Output confirming active rules. ```
- 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.
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.