Skip to content

Commit 4d43d28

Browse files
Merge pull request #1 from lamcodeofpwnosec/InfrastructureSecure
build@devsecops
2 parents c682b71 + baace8d commit 4d43d28

File tree

12 files changed

+322
-2
lines changed

12 files changed

+322
-2
lines changed

README.md

+110-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,110 @@
1-
# IT_Infrastructure_Security
2-
IT Infrastructure Security Project aimed at analyzing and protecting against various attacks on servers, applications, and websites, we would need to combine several technologies and implement multiple layers of security.
1+
# IT Infrastructure Security Project
2+
3+
This project provides a multi-layered defense strategy to protect servers, applications, and websites from various types of cyber attacks. It includes firewall setup, real-time monitoring, vulnerability scanning, DDoS protection, and more. By leveraging tools like Nuclei, Nmap, Fail2Ban, and custom Python/Bash scripts, this project offers a complete solution to securing your IT infrastructure.
4+
5+
6+
## Features
7+
8+
1. **Firewall and Intrusion Detection**: Configure iptables firewall rules.
9+
2. **Real-Time Monitoring and Alerts**: Monitor CPU, memory, and disk usage and send alerts.
10+
3. **Web Application Firewall (WAF)**: Protect against SQL injection and XSS attacks.
11+
4. **Brute Force Protection**: Use Fail2Ban to block IPs showing signs of brute force.
12+
5. **Vulnerability Scanning**: Automated vulnerability scanning using Nmap.
13+
6. **DDoS Protection**: NGINX rate limiting to prevent DDoS attacks.
14+
7. **Incident Response**: Automatically block IPs when suspicious activity is detected.
15+
8. **Encrypted Backups**: Secure and encrypt backups automatically.
16+
17+
## How to Set Up
18+
19+
1. Run the `firewall/firewall_setup.sh` to configure the basic firewall.
20+
2. Use `monitoring/real_time_monitor.py` to enable real-time monitoring and alerts.
21+
3. Configure and run the Web Application Firewall (WAF) using `waf/waf.py`.
22+
4. Set up brute force protection with `brute_force_protection/fail2ban_setup.sh`.
23+
5. Automate vulnerability scans with [projectdiscovery](https://github.com/projectdiscovery/nuclei-templates/graphs/contributors) `vulnerability_scanner/vulnerability_scan.py`.
24+
6. Apply DDoS protection using the `ddos_protection/ddos_protection.conf` with your NGINX setup.
25+
7. Enable automated incident response using `incident_response/incident_response.py`.
26+
8. Backup and encrypt important files with `backups/backup_script.sh`.
27+
28+
## Installation
29+
**Prerequisites**
30+
* Linux (Ubuntu/Debian preferred)
31+
* Python 3.6+
32+
* Nuclei by ProjectDiscovery
33+
* Nmap
34+
* NGINX (for DDoS protection)
35+
* Fail2Ban
36+
* iptables and gpg for encryption
37+
38+
### Step-by-Step Installation
39+
1. Clone the Repository
40+
Clone the repository to your local machine:
41+
```
42+
git clone https://github.com/lamcodeofpwnosec/IT_Infrastructure_Security.git
43+
```
44+
2. Install Dependencies
45+
Install required packages and tools using the following commands:
46+
```
47+
sudo apt update
48+
sudo apt install python3-pip fail2ban nmap iptables gpg nginx -y
49+
pip3 install psutil requests
50+
```
51+
3. Install Nuclei
52+
Install Nuclei by running the following commands:
53+
54+
```
55+
curl -s https://api.github.com/repos/projectdiscovery/nuclei/releases/latest | grep "browser_download_url.*nuclei-linux-amd64.zip" | cut -d '"' -f 4 | wget -qi -
56+
unzip nuclei-linux-amd64.zip
57+
sudo mv nuclei /usr/local/bin/
58+
```
59+
Ensure that Nuclei is correctly installed by running:
60+
```
61+
nuclei -version
62+
```
63+
4. Set Up Firewall Rules
64+
Navigate to the `firewall/`` directory and run the firewall setup script:
65+
```
66+
cd firewall
67+
sudo bash firewall_setup.sh
68+
```
69+
5. Set Up Brute Force Protection
70+
Set up Fail2Ban to block brute force attacks:
71+
```
72+
cd ../brute_force_protection
73+
sudo bash fail2ban_setup.sh
74+
```
75+
6. Configure DDoS Protection
76+
Copy the NGINX rate limiting configuration to your NGINX configuration file:
77+
```
78+
sudo cp ../ddos_protection/ddos_protection.conf /etc/nginx/nginx.conf
79+
sudo systemctl restart nginx
80+
```
81+
### Usage
82+
1. **Real-Time Monitoring**
83+
To monitor your system's CPU, memory, and disk usage in real-time and send alerts, run the Python script:
84+
```
85+
cd monitoring
86+
python3 real_time_monitor.py
87+
```
88+
2. Vulnerability Scanning
89+
You can run vulnerability scans using either Nmap or Nuclei by following the steps below:
90+
* Nmap Scan:
91+
```
92+
cd ../vulnerability_scanner
93+
python3 vulnerability_scan.py
94+
```
95+
Choose option 1 for Nmap and enter the target IP.
96+
97+
3. Block Suspicious IP
98+
If you detect suspicious activity, you can block an IP by running the following script:
99+
```
100+
cd ../firewall
101+
sudo bash block_ip.sh <IP_ADDRESS>
102+
```
103+
4. Backup and Encrypt Data
104+
To back up and encrypt sensitive data, use the following backup script:
105+
```
106+
cd ../backups
107+
sudo bash backup_script.sh
108+
```
109+
### Author
110+
IT Infrastructure Security Project was created by [@lamcodeofpwnosec](https://github.com/lamcodeofpwnosec/).

backups/backup_script.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Backup Script
3+
4+
backup_dir="/var/backups"
5+
target_dir="/home/user/data"
6+
backup_file="$backup_dir/data_backup_$(date +%Y%m%d).tar.gz"
7+
8+
# Create a backup and encrypt it using GPG
9+
tar -czf - $target_dir | gpg --symmetric --cipher-algo aes256 -o $backup_file.gpg
10+
11+
echo "Backup and encryption completed: $backup_file.gpg"
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Fail2Ban Setup Script
3+
4+
sudo apt update
5+
sudo apt install fail2ban -y
6+
7+
# Create a new jail configuration for SSH
8+
cat <<EOL > /etc/fail2ban/jail.local
9+
[sshd]
10+
enabled = true
11+
port = ssh
12+
filter = sshd
13+
logpath = /var/log/auth.log
14+
maxretry = 5
15+
bantime = 3600 # Ban for 1 hour
16+
EOL
17+
18+
# Restart Fail2Ban
19+
sudo systemctl restart fail2ban
20+
21+
echo "Fail2Ban setup completed!"

ddos_protection/ddos_protection.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
http {
2+
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
3+
4+
server {
5+
location / {
6+
limit_req zone=one burst=5 nodelay;
7+
}
8+
}
9+
}

firewall/block_ip.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# Block IP Script
3+
4+
if [ "$#" -ne 1 ]; then
5+
echo "Usage: $0 <IP_ADDRESS>"
6+
exit 1
7+
fi
8+
9+
IP=$1
10+
11+
# Block the given IP
12+
iptables -A INPUT -s $IP -j DROP
13+
iptables-save > /etc/iptables/rules.v4
14+
15+
echo "Blocked IP: $IP"

firewall/firewall_setup.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Firewall Setup Script
3+
4+
# Flush existing rules
5+
iptables -F
6+
7+
# Default policy: Drop all traffic
8+
iptables -P INPUT DROP
9+
iptables -P FORWARD DROP
10+
iptables -P OUTPUT ACCEPT
11+
12+
# Allow loopback traffic
13+
iptables -A INPUT -i lo -j ACCEPT
14+
15+
# Allow established connections
16+
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
17+
18+
# Allow SSH
19+
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
20+
21+
# Allow HTTP and HTTPS traffic
22+
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
23+
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
24+
25+
# Log and drop everything else
26+
iptables -A INPUT -j LOG --log-prefix "Dropped: "
27+
iptables -A INPUT -j DROP
28+
29+
# Save iptables rules
30+
iptables-save > /etc/iptables/rules.v4
31+
32+
echo "Firewall setup completed!"
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import subprocess
2+
3+
def block_ip(ip):
4+
command = f"iptables -A INPUT -s {ip} -j DROP"
5+
subprocess.run(command, shell=True)
6+
print(f"Blocked IP: {ip}")
7+
8+
if __name__ == "__main__":
9+
suspicious_ip = "192.168.0.100" # Example suspicious IP
10+
block_ip(suspicious_ip)

monitoring/log_monitor.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Log Monitoring Script
3+
4+
log_file="/var/log/auth.log"
5+
last_checked=$(date)
6+
7+
# Monitor log file for specific keywords (e.g., "Failed password", "Unauthorized")
8+
tail -Fn0 $log_file | while read line; do
9+
echo "$line" | grep -i "failed password"
10+
if [ $? = 0 ]; then
11+
echo "Suspicious activity detected: $line"
12+
echo "Suspicious activity detected on $(date): $line" | mail -s "Security Alert" [email protected]
13+
fi
14+
done

monitoring/real_time_monitor.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import psutil
2+
import time
3+
import requests
4+
5+
def send_alert(message):
6+
webhook_url = 'https://hooks.slack.com/services/YOUR/WEBHOOK/URL'
7+
payload = {'text': message}
8+
requests.post(webhook_url, json=payload)
9+
10+
def monitor_system():
11+
while True:
12+
cpu_usage = psutil.cpu_percent(interval=1)
13+
memory_info = psutil.virtual_memory()
14+
disk_usage = psutil.disk_usage('/')
15+
16+
# Check thresholds
17+
if cpu_usage > 80:
18+
send_alert(f"High CPU Usage: {cpu_usage}%")
19+
if memory_info.percent > 80:
20+
send_alert(f"High Memory Usage: {memory_info.percent}%")
21+
if disk_usage.percent > 80:
22+
send_alert(f"High Disk Usage: {disk_usage.percent}%")
23+
24+
time.sleep(60) # Run every minute
25+
26+
if __name__ == "__main__":
27+
monitor_system()

vulnerability_scanner/nuclei_scan.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Nuclei Scan Script
3+
# Description: This script runs a Nuclei scan against a specified target.
4+
# Dependencies: Nuclei must be installed (https://github.com/projectdiscovery/nuclei)
5+
6+
if [ "$#" -ne 1 ]; then
7+
echo "Usage: $0 <target>"
8+
exit 1
9+
fi
10+
11+
TARGET=$1
12+
13+
# Update Nuclei templates before scanning
14+
echo "Updating Nuclei templates..."
15+
nuclei -update-templates
16+
17+
# Run Nuclei scan against the target
18+
echo "Running Nuclei scan on target: $TARGET..."
19+
nuclei -u $TARGET -o "$TARGET"_nuclei_report.txt
20+
21+
echo "Nuclei scan complete. Report saved to $TARGET_nuclei_report.txt"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import subprocess
2+
3+
def scan_nmap(target_ip):
4+
""" Run Nmap scan """
5+
print(f"Running Nmap scan on {target_ip}...")
6+
nmap_scan_command = ["nmap", "-sV", "--script=vulscan/vulscan.nse", target_ip]
7+
result = subprocess.run(nmap_scan_command, stdout=subprocess.PIPE)
8+
print(result.stdout.decode())
9+
10+
def scan_nuclei(target_url):
11+
""" Run Nuclei scan """
12+
print(f"Running Nuclei scan on {target_url}...")
13+
nuclei_scan_command = ["./nuclei_scan.sh", target_url]
14+
result = subprocess.run(nuclei_scan_command, stdout=subprocess.PIPE)
15+
print(result.stdout.decode())
16+
17+
if __name__ == "__main__":
18+
print("Select a vulnerability scan:")
19+
print("1) Nmap Vulnerability Scan")
20+
print("2) Nuclei Vulnerability Scan")
21+
scan_choice = input("Enter choice: ")
22+
23+
if scan_choice == "1":
24+
target = input("Enter the target IP for Nmap scan: ")
25+
scan_nmap(target)
26+
elif scan_choice == "2":
27+
target = input("Enter the target URL for Nuclei scan: ")
28+
scan_nuclei(target)
29+
else:
30+
print("Invalid choice. Exiting.")

waf/waf.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from flask import Flask, request, abort
2+
3+
app = Flask(__name__)
4+
5+
# Define bad patterns (for SQL injection, XSS, etc.)
6+
BAD_PATTERNS = ["<script>", "SELECT *", "' OR 1=1", "DROP TABLE", "UNION SELECT"]
7+
8+
def is_malicious(payload):
9+
for pattern in BAD_PATTERNS:
10+
if pattern.lower() in payload.lower():
11+
return True
12+
return False
13+
14+
@app.route('/submit', methods=['POST'])
15+
def submit():
16+
data = request.form['data']
17+
if is_malicious(data):
18+
abort(403) # Forbidden
19+
return "Data received safely!"
20+
21+
if __name__ == '__main__':
22+
app.run(port=8080)

0 commit comments

Comments
 (0)