No description
  • Shell 61.5%
  • Python 33.8%
  • Makefile 4.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-11 22:22:54 -06:00
.vscode Add installer script and hello_world module 2026-10-10 15:34:39 -06:00
build Added zulu module 2026-10-11 22:22:54 -06:00
src Added zulu module 2026-10-11 22:22:54 -06:00
.gitignore Add installer script and hello_world module 2026-10-10 15:34:39 -06:00
AGENTS.md Add installer script and hello_world module 2026-10-10 15:34:39 -06:00
Makefile Refactor installation script and add new module for firewall configuration 2026-10-10 16:12:31 -06:00
README.md Added zulu module 2026-10-11 22:22:54 -06:00

linux-hardening

Contains the Linux hardening script and additional Linux tools.

Installation Guide

Download and run the install script in the build directory. You must run it with sudo:

sudo bash build/install

The installer downloads <GITHUB_URL>/ccdc (normalizing the trailing slash), checks its Bash syntax, and installs it at CCDC_SCRIPT_PATH (by default, /usr/local/bin/ccdc). It creates /usr/local/lib/ccdc/modules/; the loader downloads modules there as needed. You need curl or wget, and the download URL must serve the compiled loader.

The installer sets the module directory and its parent (/usr/local/lib/ccdc/ by default) to mode 777, giving every user read, write, and directory traversal permissions. This lets any local user replace modules, including ones later executed as root. The loader executable remains mode 755.

The installer checks that ccdc resolves to the installed file on PATH. If the directory is missing from PATH, or another ccdc takes precedence, it reports the issue instead of declaring success. It does not edit your shell configuration.

Usage Guide

After installation, run ccdc -h to view the help menu. Usage is simple:

ccdc [options] <module-name> [module arguments...]

The ccdc script acts as a loader: it keeps valid cached modules and downloads missing or malformed modules and their declared dependencies, then executes the module. Arguments after the module name are passed directly to that module.

Use -v or --verbose before the module name for verbose logging, or --debug for debug logging:

ccdc -v hello_world
ccdc --debug hello_world

If both logging options are given, debug takes precedence. Flags after the module name are passed to the module unchanged. For example, ccdc hello_world --debug passes --debug to hello_world; it does not enable loader debugging. Unknown options before the module name fail with an error and usage information before any download. Logging flags without a module print help.

Download failures and cache repair

GITHUB_URL points to the build root, not its modules/ directory. The current value is:

https://git.kchatt.dev/Kai/linux-hardening/raw/branch/main/build/

The installer requests <base>/ccdc; the loader requests <base>/modules/<module-name>. A trailing slash on the base is optional.

The loader prefers curl and falls back to wget. Both follow redirects and reject HTTP failures. Downloader diagnostics remain visible, while the loader's error includes the module name, requested URL, destination, and exit status. Failed or invalid responses are never saved or executed.

Downloaded and cached modules must have the four-line compiled header described below and pass bash -n. Valid caches are reused without a download. Malformed caches are replaced automatically only after a replacement passes validation. Read errors stop the loader. Writes use a temporary file beside the destination, mode 644, and an atomic rename; failed replacements preserve the previous file and clean up the temporary file. The old malformed file is not executed.

Validation checks format and Bash syntax without executing downloaded code. It does not establish that the code is trustworthy.

Rebuild and reinstall an older loader

Changing source files or running a build does not update the installed ccdc. An older /usr/local/bin/ccdc may still lack flag support. After building successfully, install the new local loader:

make build
sudo install -m 755 build/ccdc /usr/local/bin/ccdc
hash -r
ccdc --debug hello_world

Use your configured CCDC_SCRIPT_PATH if it differs from /usr/local/bin/ccdc. This installs the local build; running build/install instead downloads the remote loader.

The loader and installer use these logging levels:

Level Output
INFO Major actions, such as downloading, installing, and executing modules.
VERBOSE Decisions and progress, such as cached dependencies, download tool selection, and privilege checks.
DEBUG Paths, parsed header values, effective user IDs, permissions, and argument counts.
ERROR Failed operations with the relevant path or module and exit status where available. Errors remain visible when logging is disabled.

Module contents and argument values are not logged. The installer uses the compiled VERBOSITY value; the loader also supports the command-line logging flags above.

For example:

ccdc hello_world

If a module requires root, run the command with sudo:

sudo ccdc <module-name> [module arguments...]

Modules can also be downloaded and executed directly as standalone Bash scripts:

bash build/modules/hello_world

Build Guide

You need Amber, Bash, GNU Make, and the standard command-line tools used by the Makefile (awk, sed, head, tail, cat, mktemp, basename, mv, and chmod). The tests also need Python 3, curl, wget, and access to a localhost HTTP socket. Function fixtures use file://; HTTP integration checks use a temporary local server.

Run:

make build

This compiles src/install.ab, src/ccdc.ab, and all .ab files in src/modules/. The default output directory is build/. To choose another directory, run:

make build OUTPUT_DIR=/path/to/dir

The built scripts have no file extension. There is no .sh suffix.

The build keeps minified compilation and prepends an explicit Bash shebang to every generated script. Module metadata immediately follows that shebang. It checks module headers and compiled Bash syntax before compiling and again afterward. If the initial lint check fails, compilation does not start.

Run the tests or check module headers independently:

make tests
make lint
make lint OUTPUT_DIR=/path/to/dir

Architecture

linux-hardening/
|-- Makefile
|-- README.md
|-- src/
|   |-- ccdc.ab                 # Module loader
|   |-- install.ab              # Downloads and installs the loader
|   |-- modules/
|   |   `-- hello_world.ab      # Standalone module source
|   |-- utils/
|   |   |-- vars.ab             # Shared configuration
|   |   |-- utils.ab            # Logging and utility functions
|   |   `-- modules.ab          # URL construction and module validation
|   `-- tests/
|       |-- tests.ab            # Function tests with temporary fixtures
|       `-- integration.py      # Installer, CLI, and logging checks
`-- build/                      # Generated by make build
    |-- ccdc
    |-- install
    `-- modules/
        `-- hello_world

The build/ directory contains compiled Bash code from running make build. Its location can be changed with OUTPUT_DIR.

The src/utils/ directory contains global variables in vars.ab, utility functions in utils.ab, and other libraries available to modules. Import them into your module to use them. When Amber compiles the module to Bash, imported utility functions are included in the output, allowing the module to operate as a standalone script.

The src/tests/ directory contains tests.ab and integration.py. The tests create temporary directories and files for filesystem and download checks, then clean them up. Running make tests runs both suites; existing files in src/tests/dir/ are not required. Integration checks cover installer failures and successes, the loader's CLI, logging, real local HTTP responses, module validation, and cache repair. Privileges and installer downloads are simulated, so the tests do not modify system installation paths or require sudo.

The src/modules/ directory contains standalone scripts that, once compiled to Bash, can be used individually or downloaded and run with the ccdc loader. Every module needs the header described in Module Format.

The Makefile compiles scripts to Bash, runs the tests, and checks header compliance.

The ccdc.ab script is the loader. The install.ab script downloads and installs the loader, creates its module directory, and verifies that it is accessible on PATH.

Module Format

Modules must have a header like the following:

// @module_name: module_name
// @mod-imports: mod1, mod2
// @needs-sudo: true

These three lines must be at the very top of the source file, in this order. Keep the spacing consistent, and separate multiple module dependencies with a comma followed by a space.

Field Format
@module_name A nonempty name without whitespace.
@mod-imports Blank, one module name, or a comma-and-space-separated list of names.
@needs-sudo Exactly true or false.

Leaving @mod-imports blank is supported:

// @module_name: hello_world
// @mod-imports:
// @needs-sudo: false

The @mod-imports section lists modules that your module needs available locally. It does not list functions from src/utils/; Amber includes those functions automatically when you import them in your source. The loader downloads declared modules but does not execute them automatically or recursively resolve their imports.

Use the compiled module filenames in @mod-imports, without the .ab extension. The first CLI argument is also the module's compiled filename; the loader does not resolve it from @module_name.

The Makefile places a Bash version of the header immediately after the compiled script's shebang:

#!/usr/bin/env bash
# @module_name: hello_world
# @mod-imports:
# @needs-sudo: false

The loader accepts #!/bin/bash, #!/usr/bin/bash, or #!/usr/bin/env bash on line 1. The next three lines must match the compiled header above, using LF line endings. Blank lines before or within this header are invalid. Both the runtime validator and compiled-header lint enforce this format and check Bash syntax.

When embedding Bash in an Amber $ … $ command, escape literal dollar signs as \$ and opening braces as \{. This includes shell variables (\$user), substitutions (\$(date)), parameter expansions (\$\{HOME}), and function bodies (function example() \{). Leave the command's opening $ and closing $? unescaped. See Amber's command syntax for delimiters, interpolation, and failure handling.

Code Breakdown

Makefile

The Makefile has three targets. Running make without a target is equivalent to make build.

Target What it does
build Lints source and existing output headers, compiles the scripts, preserves module headers, marks outputs executable, then lints again.
tests Runs the Amber function tests, then the Python integration checks. A failed test makes the target fail.
lint Checks source headers in src/modules/*.ab and headers plus Bash syntax in OUTPUT_DIR/modules/*. Prints the filenames that fail and returns a failure status.

build removes the .ab extension from each output filename. It writes install and ccdc directly into the output directory and places compiled modules under its modules/ directory.

For module builds, the first three source lines are converted from // comments to # comments and inserted after the generated Bash shebang. Header preservation does not depend on where Amber places the original comments in its output.

lint checks the three source lines, or the three lines following a compiled script's shebang. Successful checks produce no output. Missing build artifacts are skipped, so lint can run before the first build. An invalid existing output header also blocks a new build; fix or remove that invalid artifact before rebuilding.

Two Make variables can be overridden:

Variable Default Purpose
OUTPUT_DIR build Directory for generated scripts and compiled-header checks.
AMBER amber Amber executable used for compilation and tests.

For example:

make build OUTPUT_DIR=dist AMBER=/path/to/amber

ccdc.ab

The loader takes a module name followed by any arguments for that module. Its main flow is:

  1. Parse leading -v, --verbose, and --debug options. Print help when no module is given, or when -h or --help appears before the module name.
  2. Validate the cached module under MOD_DIR, if present. Stop on read errors.
  3. If it is missing or malformed, download and validate a replacement, then save it atomically.
  4. Read @needs-sudo. If it is true and the effective user is not root, print instructions to run with sudo and exit.
  5. Read @mod-imports and ensure each declared dependency is present and valid, repairing malformed caches as needed.
  6. Validate the module again, then hand execution to Bash, preserving the remaining arguments and its exit status.

The loader checks privileges before downloading additional dependencies. It does not elevate privileges automatically. Writing a missing module into the default /usr/local/lib/ccdc/modules/ directory may itself require root permissions, even when the module does not declare @needs-sudo: true.

Function Purpose
is_downloaded Checks whether MOD_DIR + mod_name is a regular file.
download Fetches <GITHUB_URL>/modules/<mod_name>, rejects HTTP errors, validates the module, and returns its contents.
write_dep Atomically writes contents to MOD_DIR + mod_name, mode 644, preserving the old file on failure.
make_ccdc_dir Creates the module directory and any missing parent directories.
extract_imports Parses the first @mod-imports entry and returns its module names. Missing or empty declarations return an empty array.
download_imports Ensures imports exist and validate; keeps valid caches and repairs malformed ones.
needs_sudo Parses @needs-sudo. Missing declarations mean false; invalid values cause failure.
execute_module Validates the module, then replaces the loader process with bash -p -- <module-path>, forwarding module arguments.
print_help Prints usage information.

Shared helpers in src/utils/modules.ab:

Function Purpose
build_url Normalizes the build-root trailing slash and appends a relative path.
validate_module Checks the Bash shebang, all three metadata lines, and Bash syntax without executing the module.

Both header-reading functions accept // and # comments. They scan the leading comment header and stop at the first nonblank code line. Missing modules and read errors cause failure.

execute_module runs the downloaded file directly; it does not compile it. Bash inherits the caller's permissions, and -p preserves the effective user ID if it differs from the real user ID. Since execution replaces the loader process, the loader does not resume after the module finishes.

Shared configuration lives in src/utils/vars.ab:

Variable Default Purpose
VERBOSITY 0 Logging level: 0 for info, 1 for verbose, 2 for debug, or -1 to disable logging.
GITHUB_URL https://git.kchatt.dev/Kai/linux-hardening/raw/branch/main/build/ Build-root URL used for loader and module downloads.
MOD_DIR /usr/local/lib/ccdc/modules/ Local directory for downloaded modules.
CCDC_SCRIPT_PATH /usr/local/bin/ccdc Destination used by the installer for the loader.

Keep MOD_DIR ending with /. GITHUB_URL points to the build root and its trailing slash is normalized. That root must serve ccdc and compiled Bash modules under modules/<name>. These values are compiled into the loader; changing their defaults requires rebuilding it.