Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
cphlf — CyberPatriot Linux hardening in Bash: dry-run mode, backups, bats tests and a containerized dry-run check on Ubuntu 22.04 and 24.04. | Kitploit
Tools/GitLabGitLab/whereisxuezugi/cphlf
Defensive ToolsScripting & AutomationConfiguration AuditingForensicsSecurity VirtualizationPenetration TestingLearning & EducationIncident ResponseLabs & Practice
GitLabwhereisxuezugi/cphlf

cphlf

CyberPatriot Linux hardening in Bash: dry-run mode, backups, bats tests and a containerized dry-run check on Ubuntu 22.04 and 24.04.

3 days agoNot yet reviewed
Share
View RepositoryWebsite

cphlf

CyberPatriot hardening for Linux: a Bash framework that runs the scriptable part of a hardening pass during a timed round. It logs every change and backs up each file before it edits it. Judgment calls stay with the operator.

Built by Andrew Melek for the Lakeside High School CyberPatriot team.

pipeline status

CI runs ShellCheck, the 27 bats tests on Ubuntu 24.04, and the dry-run check on Ubuntu 22.04 and 24.04.

A dry run of cphlf in an Ubuntu 24.04 container

Real output from make dry-run in an Ubuntu 24.04 container, trimmed. The clip is also at docs/media/cphlf-demo.mp4.

[!warning] A real run purges packages, resets the passwords of the accounts you review, and rewrites sshd_config, PAM and firewall rules. Use it on a competition image or a throwaway VM, and start with --dry-run.

Try it safely

You need Docker and make. Each target starts a throwaway --rm container with the repo mounted read-only, so the script never runs on your machine.

git clone https://gitlab.com/WhereIsXuezugi/cphlf.git
cd cphlf
make dry-run IMAGE=ubuntu:24.04
[00:00] INFO  === harden.sh starting on Ubuntu 24.04 ===
[00:00] INFO  DRY-RUN MODE: no changes will be made
[...]
[00:01] INFO  DRY-RUN: default deny incoming -- would execute: ufw default deny incoming
[00:01] INFO  DRY-RUN: default allow outgoing -- would execute: ufw default allow outgoing
[...]
[00:01] INFO  === Hardening run complete ===
[...]
check: harden.sh exit 0, stderr empty
check: files changed in /etc /home /usr /var /root: 1
check:   /root/hardening-run/harden.log
check: a config with DRY_RUN=0 still dry-runs
check: passed

The check records the sha256 sum, mode and owner of every file under /etc, /home, /usr, /var and /root (skipping /var/cache and /var/log) before and after the run. It fails if the script exits non-zero, writes to stderr, or changes anything outside /root/hardening-run. A second pass uses a config that sets DRY_RUN=0 and checks that the flag still wins.

Run it on a competition image

Targets Ubuntu 22.04 and 24.04 (apt, ufw, PAM).

cp examples/config.env.example my-machine.env
sudo ./bin/harden.sh --config my-machine.env --dry-run
sudo ./bin/harden.sh --config my-machine.env --auto-approve

Set the WANT_* role answers and HARDEN_DEFAULT_PASSWORD in your copy first. examples/config.env.example lists every variable.

FlagEffect
--dry-runLogs each command instead of running it. Writes only under /root/hardening-run.
--auto-approvePurges the reviewed dual-use and legacy packages without asking.
--config FILEPresets the role answers. Root sources the file as shell code.

Flags on the command line win over the config file. These steps still prompt: the account review, new accounts, a password for each reviewed account, the media sweep and the reboot. With stdin closed (</dev/null) each one takes its default: no accounts reviewed, no media deleted, no reboot.

Output goes to /root/hardening-run: harden.log (appended on each run), backups/ and baseline/ (overwritten on each run). Set HARDEN_STATE_DIR to move it.

How it works

flowchart LR
  cli["bin/harden.sh<br/>flags, config, role answers"] --> mods["lib/*.sh<br/>10 modules in a fixed order"]
  mods -->|commands| run["run()<br/>dry run: log it<br/>real run: execute, WARN on failure"]
  mods -->|file edits| guard["DRY_RUN check<br/>backup_file first"]
  run --> state["/root/hardening-run<br/>log, backups, baseline"]
  guard --> state

Commands go through run() in lib/common.sh. A failed command is logged as WARN and the run moves on. File edits that are not a single command check the same DRY_RUN flag and back the file up first. ensure_line_in_file and ensure_block_in_file stop a second run from adding duplicate lines. Reviewed passwords are set again on every run.

ModuleWhat it does
packages.shUpdates the system, runs autoremove and sets apt to update daily. Removes 18 offensive tools and 7 games. Asks before purging 12 dual-use tools and 14 legacy services, default keep.
firewall.shufw: deny inbound by default, allow outbound, enable.
ssh.shWrites sshd_config to a temp file, checks it with sshd -t, then moves it in. No root login, 3 auth tries, chacha20-poly1305, AES-GCM and AES-CTR ciphers, sftp kept.
services.shFirewall rules for 8 services by role. When a role is off it purges Samba, vsftpd, telnetd, MySQL, Apache and BIND. When on it installs Samba and leaves the shares for you to review, and it installs and hardens vsftpd, MySQL and Apache. Mail and printing get port rules only.
users.shReviews the accounts you name: delete, admin rights, a password reset and 90/1/7 day aging. Creates new accounts. Locks the password of extra UID 0 accounts and of accounts with an empty password.
kernel.sh24 sysctl keys in one marked block: 15 IPv4 network keys and 9 kernel and filesystem keys. IPv6 goes off only with DISABLE_IPV6=yes.
pam.shPassword quality (12 characters, all 4 classes), a history of 5, lockout after 5 failures for 30 minutes on the stock common-auth layout, and login.defs aging of 90/1/7 days. Also holds kernel_login_defs.
filesystem.shPermissions on shadow, passwd, group, home directories and /root. Root-only cron and at, a login banner, a reset of an existing rc.local. Optional: USB, FireWire and Thunderbolt storage off, and a media sweep under /home. Writes SUID, world-writable, unowned and PHP file lists.
monitoring.shInstalls fail2ban, auditd (distribution default rules), rkhunter and chkrootkit without recommended packages. ClamAV and the rootkit scan are opt-in.
forensics.shSaves 11 baseline files at the end of the run: system info, users, groups, last logins, processes, services, listening ports, installed and manually installed packages, firewall status and sshd_config.

tools/ has two helpers: find-port-owner.sh names the process on a port, and list-nonstandard-users.sh lists accounts you did not expect.

Safe defaults

DecisionDefaultWhy
SSH password loginOn (SSH_PASSWORD_AUTH=yes)A team without SSH keys keeps a way in. Turn it off once keys are in place.
Deleting accountsAsks, default noA wrong delete cannot be undone. Your own account is never deleted, demoted or reset.
Account passwordsReset to HARDEN_DEFAULT_PASSWORDThe value in the repo is a placeholder, and the log warns when it is used. Set your own.
Dual-use and legacy packagesAsks, default keepnmap or a telnet server can be part of a machine's role.
Media sweepOff unless ALLOW_MEDIA_FILES=no and you type DELETEIt deletes image, audio and video files under /home. It prints the count first.
Account lockout5 failures, 30 minutesTeammates can lock themselves out too. Root is not locked.
ClamAV and rootkit scansOff (INSTALL_CLAMAV, RUN_BASELINE_SCAN)They are slow. Run them when the round allows.
IPv6Left on (DISABLE_IPV6=no)Turn it off only if your checklist asks.
GRUB passwordNot automatedA mistake can leave the machine unable to boot.

Inbound traffic is default-deny, with allows for the roles you pick. If the image reports to a scoring agent, run sudo ss -tulpn before hardening and check that it still connects after.

Download Tool

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    565
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    478
  • 3

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    383
  • 4

    redforge

    cybersecurity91/redforge

    Browser-side red team toolkit with 102 offline tools for recon, payload generation, credential attacks, crypto, encoding and engagement reporting.

    327
  • 5

    estorides

    grisuno/estorides

    Aggregates 99+ free OSINT sources in parallel, resolves entities into a knowledge graph, and exports STIX 2.1, MISP, or GraphML with LLM-assisted analysis.

    258
  • 6

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    The system of action for AI-native cybersecurity—where intent becomes governed execution, evidence becomes operational memory, and every operation improves the next.

    256

Explore all tools

Browse our collection of tools

View all tools →