CWP Security Management
If the user provides specific details via "$ARGUMENTS", focus the response on that security topic. For example: /cwp-pro-centos:cwp-security block IP 1.2.3.4 will focus on blocking that specific IP.
Manage CSF Firewall, ModSecurity, SSL/TLS certificates, SSH hardening, and server security on CWP servers. Handle firewall rules, WAF configuration, certificate management, and security auditing.
Security Components
| Component | Purpose | Status |
|---|---|---|
| CSF Firewall | Network firewall | Discontinued -- use Aetherinox fork |
| ModSecurity | Web application firewall | Active |
| Comodo WAF | ModSecurity ruleset | Abandoned -- use OWASP CRS |
| AutoSSL | Automatic SSL certificates | Active (CWP Pro) |
| Snuffleupagus | PHP security module | Active |
| CWP Secure Kernel | MAC-based kernel protection | Active (paid feature) |
CSF Firewall
Important Notice
The original CSF Firewall was discontinued in August 2025. Use the Aetherinox fork (v15.08+) for continued support and updates.
Installation
# Install iptables on AlmaLinux (prerequisite)
yum install iptables
Core Commands
# Enable/disable
csf -e # Enable firewall
csf -x # Disable firewall
csf -r # Restart firewall
# IP management
csf -g IP # Check why IP is blocked
csf -d IP # Block IP permanently
csf -dr IP # Unblock IP
csf -a IP # Whitelist IP
csf -ta IP 86400 # Temporary whitelist (24h in seconds)
# Status
csf -t # Show temporary blocks
csf -s # Start firewall
Configuration File
/etc/csf/csf.conf
Required Ports
TCP_IN: 20,21,22,25,53,80,110,143,443,465,587,993,995,2030,2031,30000:50000,6666
TCP_OUT: 20,21,22,25,53,80,110,113,443,587,993,995
UDP_IN: 53
UDP_OUT: 53,113,123
Passive FTP ports (35000-50000) must be open for Pure-FTPd.
ModSecurity
Configuration
Config file: /usr/local/apache/conf.d/mod_security.conf
OWASP CRS Setup
The Comodo WAF ruleset has been abandoned. Switch to OWASP CRS v4.27.0+:
- Update ModSecurity to version 2.9.13
- Install OWASP CRS v4.27.0
- Lock the CRS directory:
chattr -R +i /path/to/crs/ - In CWP, select "OWASP old" (not "OWASP Latest") for compatibility
ModSecurity Management
# Check ModSecurity status
apachectl -M | grep security
# View ModSecurity log
tail -f /usr/local/apache/logs/modsec_audit.log
# Restart Apache after changes
systemctl restart httpd
SSL/TLS Certificates
AutoSSL (CWP Pro)
AutoSSL automatically provisions Let's Encrypt certificates for all domains.
ACME Client
Script names vary by CWP version:
# Install/reinstall ACME client (same on most versions)
/scripts/install_acme
# Generate hostname SSL (script name varies)
if [ -f /scripts/generate_hostname_ssl ]; then
sh /scripts/generate_hostname_ssl
elif [ -f /scripts/generate_ssl ]; then
sh /scripts/generate_ssl
fi
# Renew Let's Encrypt certificates (script name varies)
if [ -f /scripts/renew_lets_encrypt ]; then
sh /scripts/renew_lets_encrypt
else
# ACME renewal is typically automatic or via certbot
certbot renew --quiet 2>/dev/null || acme.sh --renew-all
fi
Manual SSL via Let's Encrypt
Store certificates in /etc/letsencrypt/.
SSL Grade Improvement
Edit /usr/local/apache/conf.d/ssl.conf:
SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder on
# Restart Apache after SSL changes
systemctl restart httpd
# Fix AutoSSL temp path issues
/scripts/autossl_fix_tmp_path
SSH Security
Configuration File
/etc/ssh/sshd_config
Hardening Steps
# Change SSH port
sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config
# Disable root login (after creating sudo user)
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
# Disable password authentication (after setting up keys)
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
# Restart SSH
systemctl restart sshd
Important: Always update CSF firewall with the new SSH port before restarting SSH.
PHP Security
For complete PHP security configuration including disabling dangerous functions, open_basedir setup, and PHP Defender (Snuffleupagus), see the cwp-php skill (references/php-security.md).
Key security measures:
- Disable dangerous functions:
exec, system, popen, proc_open, shell_exec, passthru, show_source - Enable open_basedir per user to prevent directory traversal
- Configure PHP Defender (Snuffleupagus) rules at
/usr/local/cwp/.conf/phpdefender/
Brute Force Protection
# Enable CWP brute force protection
/scripts/cwp_bruteforce_protection
Security Auditing
# CWP security audit
/scripts/cwp_security_audit
# Check for server compromises
/scripts/security_is_my_server_hacked
# Update ClamAV virus definitions
/scripts/freshclam
# Install Malware Detect
/scripts/install_maldet
CWP Secure Kernel
Custom kernel with Mandatory Access Control (MAC):
- Default-deny policy
- Protects against symlink attacks and malware
- Supported: CentOS 7, AlmaLinux 8/9, Rocky Linux 8/9
- NOT supported: OpenVZ, CloudLinux, Docker
- Requires active CWP support service
Security Best Practices Checklist
- Enable AutoSSL for all domains
- Activate CSF Firewall with proper rules
- Enable ModSecurity with OWASP CRS
- Change SSH port and update CSF
- Disable dangerous PHP functions
- Enable PHP open_basedir per user
- Hide system processes
- Enforce strong passwords
- Implement IP whitelisting for admin access
- Perform regular updates with backups first
- Enable brute force protection
- Monitor logs regularly
Troubleshooting
| Issue | Solution |
|---|---|
| CSF blocking legitimate traffic | Check csf -g IP and whitelist if needed |
| ModSecurity blocking requests | Check audit log, add rule exceptions |
| SSL certificate not renewing | Run /scripts/install_acme and /scripts/generate_hostname_ssl |
| SSH locked out after port change | Use console access, verify CSF port |
| AutoSSL temp path errors | Run /scripts/autossl_fix_tmp_path |
| Firewall not starting | Check iptables: yum install iptables |
Additional Resources
references/csf-firewall.md-- Complete CSF configuration guidereferences/mod-security.md-- ModSecurity and OWASP CRS setupreferences/ssl-tls.md-- SSL/TLS certificate management and ACME setupreferences/secure-kernel.md-- CWP Secure Kernel and server hardening