A comprehensive guide to building a secure penetration testing environment
Create a secure, minimal, and reliable penetration testing environment based on Parrot OS Security Edition with full disk encryption, network hardening, and intrusion detection.
Penetration testers, security researchers, and cybersecurity professionals who need a secure field kit for assessments.
Reduce installed packages and services to only what's necessary
Implement MFA and secure password policies
Full disk encryption to protect data at rest
Minimize network exposure and secure services
Automatic security updates and patch management
Comprehensive activity tracking and monitoring
This Ansible playbook automates the hardening process for Parrot OS Security Edition. It includes disk encryption setup, firewall configuration, service management, and intrusion detection.
---
- name: Harden Parrot OS Security Edition
hosts: all
become: true
vars:
# User configuration
admin_user: "pentester"
admin_groups: "sudo"
ssh_port: 2222
# Packages to remove
packages_to_remove:
- xserver-xorg
- bluetooth
- cups
- avahi-daemon
- modemmanager
# Services to disable
services_to_disable:
- bluetooth
- cups
- avahi-daemon
- modemmanager
- apparmor
tasks:
# Update system
- name: Update all packages
apt:
update_cache: yes
upgrade: dist
autoremove: yes
# Remove unnecessary packages
- name: Remove unwanted packages
apt:
name: "{{ packages_to_remove }}"
state: absent
purge: yes
# Disable unnecessary services
- name: Disable unwanted services
systemd:
name: "{{ item }}"
enabled: no
state: stopped
loop: "{{ services_to_disable }}"
# Configure UFW firewall
- name: Install UFW
apt:
name: ufw
state: present
- name: Configure UFW default policies
ufw:
state: enabled
policy: deny
direction: incoming
- name: Allow SSH on custom port
ufw:
rule: allow
port: "{{ ssh_port }}"
proto: tcp
# Install and configure Fail2Ban
- name: Install Fail2Ban
apt:
name: fail2ban
state: present
- name: Configure Fail2Ban
copy:
dest: /etc/fail2ban/jail.local
content: |
[DEFAULT]
ignoreip = 127.0.0.1/8
bantime = 3600
findtime = 600
maxretry = 3
[sshd]
enabled = true
port = {{ ssh_port }}
filter = sshd
logpath = /var/log/auth.log
- name: Restart Fail2Ban
systemd:
name: fail2ban
state: restarted
# Configure automatic updates
- name: Install unattended-upgrades
apt:
name: unattended-upgrades
state: present
- name: Configure automatic updates
copy:
dest: /etc/apt/apt.conf.d/50unattended-upgrades
content: |
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESM:${distro_codename}";
};
Unattended-Upgrade::Package-Blacklist {
};
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
# Install security tools
- name: Install security tools
apt:
name:
- lynis
- aide
- rkhunter
- chkrootkit
- auditd
state: present
# Configure auditd
- name: Configure auditd rules
copy:
dest: /etc/audit/rules.d/hardening.rules
content: |
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change
-a always,exit -F arch=b64 -S clock_settime -k time-change
-a always,exit -F arch=b32 -S clock_settime -k time-change
-w /etc/localtime -p wa -k time-change
-w /etc/group -p wa -k identity
-w /etc/passwd -p wa -k identity
-w /etc/gshadow -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/security/opasswd -p wa -k identity
- name: Restart auditd
systemd:
name: auditd
state: restarted
# Configure sysctl hardening
- name: Configure sysctl settings
sysctl:
name: "{{ item.key }}"
value: "{{ item.value }}"
state: present
reload: yes
with_items:
- { key: "net.ipv4.conf.all.rp_filter", value: "1" }
- { key: "net.ipv4.conf.default.rp_filter", value: "1" }
- { key: "net.ipv4.icmp_echo_ignore_broadcasts", value: "1" }
- { key: "net.ipv4.icmp_ignore_bogus_error_responses", value: "1" }
- { key: "net.ipv4.conf.all.accept_redirects", value: "0" }
- { key: "net.ipv4.conf.default.accept_redirects", value: "0" }
- { key: "net.ipv4.conf.all.secure_redirects", value: "0" }
- { key: "net.ipv4.conf.default.secure_redirects", value: "0" }
- { key: "net.ipv6.conf.all.accept_redirects", value: "0" }
- { key: "net.ipv6.conf.default.accept_redirects", value: "0" }
- { key: "net.ipv4.conf.all.send_redirects", value: "0" }
- { key: "net.ipv4.conf.default.send_redirects", value: "0" }
- { key: "net.ipv4.tcp_syncookies", value: "1" }
- { key: "net.ipv4.tcp_max_syn_backlog", value: "2048" }
- { key: "net.ipv4.tcp_synack_retries", value: "2" }
- { key: "net.ipv4.tcp_syn_retries", value: "5" }
- { key: "kernel.randomize_va_space", value: "2" }
# Configure SSH hardening
- name: Configure SSH
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^{{ item.regexp }}$"
line: "{{ item.line }}"
state: present
with_items:
- { regexp: "Port", line: "Port {{ ssh_port }}" }
- { regexp: "PermitRootLogin", line: "PermitRootLogin no" }
- { regexp: "Protocol", line: "Protocol 2" }
- { regexp: "X11Forwarding", line: "X11Forwarding no" }
- { regexp: "MaxAuthTries", line: "MaxAuthTries 3" }
- { regexp: "IgnoreRhosts", line: "IgnoreRhosts yes" }
- { regexp: "HostbasedAuthentication", line: "HostbasedAuthentication no" }
- { regexp: "PermitEmptyPasswords", line: "PermitEmptyPasswords no" }
- { regexp: "ClientAliveInterval", line: "ClientAliveInterval 300" }
- { regexp: "ClientAliveCountMax", line: "ClientAliveCountMax 2" }
- { regexp: "LoginGraceTime", line: "LoginGraceTime 60" }
- { regexp: "AllowAgentForwarding", line: "AllowAgentForwarding no" }
- { regexp: "AllowTcpForwarding", line: "AllowTcpForwarding no" }
- { regexp: "PermitTunnel", line: "PermitTunnel no" }
- name: Restart SSH
systemd:
name: ssh
state: restarted
# Configure password policies
- name: Install libpam-pwquality
apt:
name: libpam-pwquality
state: present
- name: Configure password policies
copy:
dest: /etc/security/pwquality.conf
content: |
minlen = 14
minclass = 4
maxrepeat = 2
maxsequence = 3
maxclassrepeat = 2
gecoscheck = 1
dictcheck = 1
usercheck = 1
enforcing = 1
- name: Configure PAM password policies
lineinfile:
dest: /etc/pam.d/common-password
regexp: "^password.*pam_pwquality.so.*$"
line: "password requisite pam_pwquality.so retry=3"
state: present
# Final message
- name: Display completion message
debug:
msg: "Parrot OS hardening complete. System reboot recommended."
sudo apt install ansibleparrot_hardening.ymlansible-playbook -i inventory parrot_hardening.ymlEdit /etc/ssh/sshd_config:
Then restart SSH:
After completing all hardening steps, perform a full system reboot and verify all security measures are still in place. Some settings (like sysctl parameters) may require a reboot to take effect.
For additional assistance with hardening your Parrot OS system, consider consulting with security professionals or posting specific questions on the Parrot OS community forums.