project linux-cis-hardening-auditor complete

This commit is contained in:
CarterPerez-dev 2026-03-30 15:50:06 -04:00
parent cf5df3c928
commit ec7a41bb3f
121 changed files with 9339 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# ©AngelaMos | 2026
# .gitignore
*.tmp
*.bak
*.swp
*~
reports/
baselines/
.DS_Store
Thumbs.db
.vscode/
.idea/

View File

@ -0,0 +1,84 @@
# ©AngelaMos | 2026
# Justfile
set shell := ["bash", "-uc"]
project := "cisaudit"
src := "src"
tests := "tests"
default:
@just --list --unsorted
[group('run')]
audit *ARGS:
sudo ./{{src}}/cisaudit.sh {{ARGS}}
[group('run')]
audit-json:
sudo ./{{src}}/cisaudit.sh -f json
[group('run')]
audit-html file="/tmp/cis-report.html":
sudo ./{{src}}/cisaudit.sh -f html -o {{file}} && echo "Report: {{file}}"
[group('run')]
audit-level level:
sudo ./{{src}}/cisaudit.sh -l {{level}}
[group('run')]
audit-category cats:
sudo ./{{src}}/cisaudit.sh -c {{cats}}
[group('run')]
list-controls:
./{{src}}/cisaudit.sh --list-controls
[group('test')]
test:
bash {{tests}}/test_runner.sh
[group('test')]
test-verbose:
bash {{tests}}/test_runner.sh 2>&1
[group('test')]
test-file file:
bash {{tests}}/test_runner.sh {{file}}
[group('lint')]
shellcheck:
shellcheck -x {{src}}/cisaudit.sh {{src}}/lib/*.sh {{src}}/checks/*.sh {{src}}/controls/*.sh
[group('util')]
install:
bash install.sh
[group('util')]
clean:
rm -rf reports/ baselines/ /tmp/cis-report.html /tmp/cis_baseline*.json
[group('util')]
info:
@echo "Project: {{project}}"
@./{{src}}/cisaudit.sh --version
@echo "Bash: $(bash --version | head -1)"
@echo "Controls: $(./{{src}}/cisaudit.sh --list-controls 2>/dev/null | tail -1)"
[group('util')]
smoke:
./{{src}}/cisaudit.sh --version
./{{src}}/cisaudit.sh --help > /dev/null
./{{src}}/cisaudit.sh --list-controls > /dev/null
./{{src}}/cisaudit.sh -t testdata/fixtures -f json 2>/dev/null | python3 -m json.tool > /dev/null
./{{src}}/cisaudit.sh -t testdata/fixtures -f terminal > /dev/null 2>&1
@echo "Smoke tests passed"
[group('baseline')]
save-baseline file="baselines/latest.json":
mkdir -p baselines
sudo ./{{src}}/cisaudit.sh -f json -s {{file}} > /dev/null
[group('baseline')]
diff-baseline file:
sudo ./{{src}}/cisaudit.sh -f terminal -b {{file}}

View File

@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

View File

@ -0,0 +1,105 @@
```ruby
██████╗██╗███████╗ █████╗ ██╗ ██╗██████╗ ██╗████████╗
██╔════╝██║██╔════╝██╔══██╗██║ ██║██╔══██╗██║╚══██╔══╝
██║ ██║███████╗███████║██║ ██║██║ ██║██║ ██║
██║ ██║╚════██║██╔══██║██║ ██║██║ ██║██║ ██║
╚██████╗██║███████║██║ ██║╚██████╔╝██████╔╝██║ ██║
╚═════╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝
```
[![Cybersecurity Projects](https://img.shields.io/badge/Cybersecurity--Projects-Project%20%2321-red?style=flat&logo=github)](https://github.com/CarterPerez-dev/Cybersecurity-Projects/tree/main/PROJECTS/beginner/linux-cis-hardening-auditor)
[![Bash](https://img.shields.io/badge/Bash-4%2B-4EAA25?style=flat&logo=gnubash&logoColor=white)](https://www.gnu.org/software/bash/)
[![License: AGPLv3](https://img.shields.io/badge/License-AGPL_v3-purple.svg)](https://www.gnu.org/licenses/agpl-3.0)
> CIS Benchmark compliance auditor for Linux systems with scored reporting, baseline comparison, and remediation guidance.
*This is a quick overview — security theory, architecture, and full walkthroughs are in the [learn modules](#learn).*
## What It Does
- Audit Linux systems against 104 CIS Benchmark controls (Debian/Ubuntu)
- Check filesystem hardening, services, network parameters, logging, SSH, and user accounts
- Generate scored compliance reports in terminal, JSON, or HTML format
- Compare results against a saved baseline to detect regressions and improvements
- Provide specific remediation commands for every failed control
- Support Level 1 and Level 2 benchmark profiles
- Run in test mode against mock fixtures without root access
## Quick Start
```bash
./install.sh
sudo cisaudit
```
> [!TIP]
> This project uses [`just`](https://github.com/casey/just) as a command runner. Type `just` to see all available commands.
>
> Install: `curl -sSf https://just.systems/install.sh | bash -s -- --to ~/.local/bin`
## Commands
| Command | Description |
|---------|-------------|
| `sudo cisaudit` | Run full audit with terminal output |
| `sudo cisaudit -l 1` | Audit Level 1 controls only |
| `sudo cisaudit -f json -o report.json` | Generate JSON report |
| `sudo cisaudit -f html -o report.html` | Generate HTML report |
| `sudo cisaudit -c 5` | Audit only Section 5 (Access/Auth) |
| `cisaudit --list-controls` | List all 104 registered controls |
| `sudo cisaudit -s baseline.json` | Save current results as baseline |
| `sudo cisaudit -b baseline.json` | Compare against a previous baseline |
| `cisaudit -t testdata/fixtures` | Run against test fixtures (no root needed) |
### Options
| Flag | Default | Description |
|------|---------|-------------|
| `-l, --level` | `all` | Benchmark level: `1`, `2`, or `all` |
| `-f, --format` | `terminal` | Output format: `terminal`, `json`, `html` |
| `-o, --output` | stdout | Write report to file |
| `-c, --categories` | `all` | Categories to audit: `1,2,3,4,5,6` |
| `-t, --test-root` | `/` | System root for testing |
| `--threshold` | `0` | Minimum pass % to exit 0 |
| `-q, --quiet` | off | Suppress progress output |
## CIS Benchmark Sections
| # | Section | Controls |
|---|---------|----------|
| 1 | Initial Setup | 20 |
| 2 | Services | 18 |
| 3 | Network Configuration | 20 |
| 4 | Logging and Auditing | 18 |
| 5 | Access, Authentication and Authorization | 18 |
| 6 | System Maintenance | 10 |
| | **Total** | **104** |
## Examples
```bash
sudo cisaudit -l 1 -f json -o report.json
sudo cisaudit -c 3,5 -f terminal
sudo cisaudit -s baselines/march.json
sudo cisaudit -b baselines/march.json
cisaudit -t testdata/fixtures -f json | python3 -m json.tool
```
## Learn
This project includes step-by-step learning materials covering security theory, architecture, and implementation.
| Module | Topic |
|--------|-------|
| [00 - Overview](learn/00-OVERVIEW.md) | Prerequisites and quick start |
| [01 - Concepts](learn/01-CONCEPTS.md) | CIS benchmarks, real breaches, and compliance frameworks |
| [02 - Architecture](learn/02-ARCHITECTURE.md) | System design, module layout, and data flow |
| [03 - Implementation](learn/03-IMPLEMENTATION.md) | Code walkthrough with file references |
| [04 - Challenges](learn/04-CHALLENGES.md) | Extension ideas and exercises |
## License
AGPL 3.0

View File

@ -0,0 +1,157 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# install.sh
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${CYAN}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
fail() { echo -e "${RED}[FAIL]${NC} $1"; exit 1; }
PROJECT="cisaudit"
INSTALL_DIR="${HOME}/.local/bin"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo -e "${BOLD}${CYAN}"
cat << 'BANNER'
_____ ___ ____ _ _ _ _
/ ____|_ _/ ___| / \ _ _ __| (_) |_
| | | |\___ \ / _ \| | | |/ _` | | __|
| |___ | | ___) / ___ \ |_| | (_| | | |_
\____|___|____/_/ \_\__,_|\__,_|_|\__|
CIS Benchmark Compliance Auditor
BANNER
echo -e "${NC}"
check_bash_version() {
if (( BASH_VERSINFO[0] < 4 )); then
fail "Bash 4+ required (found ${BASH_VERSION})"
fi
success "Bash ${BASH_VERSION}"
}
check_dependencies() {
local deps=(grep awk sed stat date hostname)
local missing=()
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
missing+=("$dep")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
fail "Missing required tools: ${missing[*]}"
fi
success "All dependencies found"
}
install_shellcheck() {
if command -v shellcheck &> /dev/null; then
success "shellcheck found (optional, for development)"
return
fi
info "shellcheck not found (optional, for linting)"
read -rp "Install shellcheck for development? [y/N] " answer
if [[ "${answer,,}" != "y" ]]; then
return
fi
if command -v apt-get &> /dev/null; then
sudo apt-get install -y shellcheck
elif command -v dnf &> /dev/null; then
sudo dnf install -y ShellCheck
elif command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm shellcheck
elif command -v brew &> /dev/null; then
brew install shellcheck
else
warn "Could not detect package manager — install shellcheck manually"
return
fi
success "shellcheck installed"
}
make_executable() {
find "${SCRIPT_DIR}/src" -name "*.sh" -exec chmod +x {} \;
success "All scripts marked executable"
}
install_binary() {
mkdir -p "${INSTALL_DIR}"
ln -sf "${SCRIPT_DIR}/src/cisaudit.sh" "${INSTALL_DIR}/${PROJECT}"
success "Linked ${PROJECT} to ${INSTALL_DIR}/${PROJECT}"
}
ensure_path() {
if echo "$PATH" | grep -q "${INSTALL_DIR}"; then
return
fi
warn "${INSTALL_DIR} is not in your PATH"
SHELL_NAME=$(basename "${SHELL:-bash}")
case "${SHELL_NAME}" in
zsh) RC_FILE="${HOME}/.zshrc" ;;
fish) RC_FILE="${HOME}/.config/fish/config.fish" ;;
*) RC_FILE="${HOME}/.bashrc" ;;
esac
if [[ "${SHELL_NAME}" == "fish" ]]; then
PATH_LINE="fish_add_path ${INSTALL_DIR}"
else
PATH_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
if [[ -f "${RC_FILE}" ]] && grep -q "${INSTALL_DIR}" "${RC_FILE}" 2>/dev/null; then
info "PATH entry already in ${RC_FILE}"
else
echo "${PATH_LINE}" >> "${RC_FILE}"
success "Added ${INSTALL_DIR} to PATH in ${RC_FILE}"
warn "Run 'source ${RC_FILE}' or restart your shell"
fi
export PATH="${INSTALL_DIR}:${PATH}"
}
verify_install() {
if command -v "${PROJECT}" &> /dev/null; then
VERSION=$("${PROJECT}" --version 2>/dev/null || echo "unknown")
success "Verification passed: ${VERSION}"
else
warn "Installed but not found in PATH"
info "Run: ${INSTALL_DIR}/${PROJECT} --version"
fi
}
check_bash_version
check_dependencies
make_executable
install_binary
ensure_path
install_shellcheck
verify_install
echo ""
echo -e "${GREEN}${BOLD}Installation complete!${NC}"
echo ""
echo -e "${BOLD}Usage:${NC}"
echo " sudo cisaudit"
echo " sudo cisaudit -l 1 -f json -o report.json"
echo " sudo cisaudit -f html -o report.html"
echo " cisaudit -t testdata/fixtures -f terminal"
echo " cisaudit --list-controls"
echo ""
echo -e "${BOLD}Run tests:${NC}"
echo " just test"
echo ""

View File

@ -0,0 +1,140 @@
<!-- © AngelaMos | 2026 | 00-OVERVIEW.md -->
# Linux CIS Hardening Auditor
## What This Is
A command-line tool written entirely in Bash that audits Linux systems against 104 controls from the CIS Debian Linux 12 Benchmark. It checks filesystem hardening, service minimization, network parameters, logging configuration, access controls, and system maintenance. It produces scored compliance reports in terminal, JSON, or HTML format, and it can compare results against a saved baseline to track drift over time.
## Why This Matters
In December 2019, a misconfigured Citrix server (CVE-2019-19781) gave attackers a foothold into hundreds of organizations because basic CIS controls were not enforced. The patch existed. The advisory existed. But the systems were not hardened, and no automated audit caught the exposure before it was exploited. The attackers did not need a zero-day. They needed one server where IP forwarding was enabled, SSH root login was permitted, and audit logging was turned off.
Capital One's 2019 breach exposed 100 million credit applications. The root cause was a misconfigured WAF on an EC2 instance with excessive IAM permissions. But the forensic investigation revealed that basic system hardening controls, the exact kind CIS benchmarks define, were absent on the compromised servers. There was no file integrity monitoring, no restrictive mount options on /tmp, and the audit subsystem was not enabled.
CIS benchmarks exist because security teams kept seeing the same misconfigurations cause breaches. The Center for Internet Security formalized these lessons into prescriptive hardening guides that map directly to regulatory frameworks like NIST 800-53, PCI DSS, SOC 2, and HIPAA. If you run a CIS audit and score 85%, you can tell an auditor exactly which 15% you have not addressed and why. Without a benchmark, you are guessing.
**Real world scenarios where this applies:**
- A SOC analyst needs to verify that newly provisioned servers meet the organization's hardening standard before they go into production
- An incident responder wants to quickly assess whether a compromised host had basic security controls in place when the breach occurred
- A compliance team needs evidence that Linux servers meet CIS Level 1 benchmarks for a SOC 2 Type II audit
## What You'll Learn
This project teaches you how CIS benchmarks translate from PDF documents into automated compliance checks. By building it yourself, you understand what each control actually verifies at the system level.
**Security Concepts:**
- CIS Benchmark structure: how controls are organized into sections, levels, and scored vs. unscored categories
- Linux system hardening: what kernel parameters, mount options, service states, and file permissions matter and why
- Compliance scoring: how to quantify a system's security posture as a percentage and track it over time
- Defense in depth: how 104 small controls layer together to create a hardened system
**Technical Skills:**
- Bash architecture: building a modular CLI tool with a registry pattern, pluggable check functions, and multiple output formatters
- System inspection: reading /proc, parsing config files, checking systemd service states, and querying sysctl values without external dependencies
- Test fixtures: running compliance checks against mock filesystem trees so tests work without root access or a live system
**Tools and Techniques:**
- `sysctl` and `/proc/sys` for reading kernel parameters
- `modprobe` configuration for disabling kernel modules
- `auditd` rules for tracking security-relevant system calls
- PAM configuration for password policies and account lockout
- `iptables` for verifying firewall default policies
## Prerequisites
**Required knowledge:**
- Comfortable reading and writing Bash scripts (functions, arrays, conditionals, string manipulation)
- Basic Linux administration: you know what `/etc/passwd`, `/etc/ssh/sshd_config`, and `systemctl` do
- Understanding of file permissions (owner, group, mode bits like 644 and 600)
**Tools you'll need:**
- Bash 4+ (ships with every modern Linux distribution)
- `just` command runner (optional but recommended for running tasks)
- `shellcheck` for linting (optional, offered during install)
**Helpful but not required:**
- Familiarity with the CIS Benchmark PDF documents (reading them alongside the code makes the controls click faster)
- Experience with `auditd` and PAM configuration
## Quick Start
```bash
cd PROJECTS/beginner/linux-cis-hardening-auditor
./install.sh
sudo cisaudit
```
Expected output: a terminal report showing the CIS ASCII banner, an overall compliance score, a section breakdown table with pass/fail/warn/skip counts and progress bars, and detailed results for each of the 104 controls. Failed controls include evidence explaining what was found and a remediation command.
To run without root access, use the test fixtures:
```bash
cisaudit -t testdata/fixtures -f terminal
```
This runs the full audit against the mock filesystem in `testdata/fixtures/` and produces the same report format. Every control that can be evaluated from config files will produce a result.
## Project Structure
```
linux-cis-hardening-auditor/
├── src/
│ ├── cisaudit.sh # Entry point: CLI parsing, orchestration
│ ├── lib/
│ │ ├── constants.sh # Version, colors, status codes, section names
│ │ ├── utils.sh # Logging, OS detection, file/sysctl helpers
│ │ ├── registry.sh # Control registration and result recording
│ │ ├── engine.sh # Score computation per section and level
│ │ ├── report_terminal.sh # Terminal report with ASCII art and progress bars
│ │ ├── report_json.sh # Machine-readable JSON report
│ │ ├── report_html.sh # Standalone HTML report with dark theme
│ │ └── baseline.sh # Save and diff baselines for drift detection
│ ├── controls/
│ │ └── registry_data.sh # All 104 control definitions with metadata
│ └── checks/
│ ├── 01_initial_setup.sh # Filesystem, bootloader, ASLR, core dumps
│ ├── 02_services.sh # Unnecessary service detection
│ ├── 03_network.sh # Kernel network params, firewall, protocols
│ ├── 04_logging.sh # auditd, rsyslog, audit rules
│ ├── 05_access.sh # cron, SSH configuration
│ ├── 05_access_password.sh # PAM, password policies, account lockout
│ └── 06_maintenance.sh # File permissions, duplicate UIDs, legacy entries
├── tests/
│ ├── test_runner.sh # Custom test framework runner
│ ├── test_helpers.sh # assert_status, assert_evidence_contains
│ └── test_*.sh # One test file per section + engine/baseline
├── testdata/
│ ├── fixtures/ # Mock filesystem that passes most controls
│ └── fixtures_fail/ # Mock filesystem designed to fail controls
├── install.sh # One-command setup with PATH integration
├── Justfile # Command runner for audit, test, lint, baseline
└── learn/ # You are here
```
## Next Steps
1. **Understand the concepts** - Read [01-CONCEPTS.md](./01-CONCEPTS.md) to learn CIS benchmarks, system hardening principles, and the real breaches that motivated these controls
2. **Study the architecture** - Read [02-ARCHITECTURE.md](./02-ARCHITECTURE.md) to see how the registry pattern, check engine, and report formatters fit together
3. **Walk through the code** - Read [03-IMPLEMENTATION.md](./03-IMPLEMENTATION.md) for a function-by-function walkthrough of the core modules
4. **Extend the project** - Read [04-CHALLENGES.md](./04-CHALLENGES.md) for ideas like adding RHEL support, auto-remediation mode, and Ansible playbook generation
## Common Issues
**"Bash 4+ required" error**
```
[✖] Bash 4+ required (found 3.2.57)
```
Solution: macOS ships with Bash 3.2 due to licensing. Install Bash 5 via `brew install bash` and run with `/opt/homebrew/bin/bash src/cisaudit.sh`.
**Most controls show SKIP in test mode**
Solution: Controls that require live system access (checking running services with `systemctl`, querying `iptables` rules, inspecting running kernel modules with `lsmod`) will skip when using `-t testdata/fixtures` because those commands are not available in test mode. This is expected. File-based checks will still produce PASS/FAIL results.
**Low score on a real system**
Solution: Most Linux installations are not CIS-hardened out of the box. A fresh Debian install typically scores 40-60%. This is normal. Use the remediation commands in the report to harden the system, then re-run the audit.
## Related Projects
If you found this interesting, check out:
- **Firewall Rule Engine** (intermediate) - builds the iptables/nftables rule management that CIS Section 3.3 checks for
- **Network Traffic Analyzer** (beginner) - captures and analyzes the traffic that CIS network controls are designed to restrict

View File

@ -0,0 +1,298 @@
<!-- © AngelaMos | 2026 | 01-CONCEPTS.md -->
# Core Security Concepts
This document covers the security fundamentals behind CIS benchmarks, system hardening, and compliance auditing. By the end you should understand why each of the six audit sections exists, what real attacks they prevent, and how the controls map to compliance frameworks you will encounter in production environments. Read time is roughly 20-25 minutes.
---
## CIS Benchmarks
### What They Are
The Center for Internet Security (CIS) publishes hardening guides called benchmarks for operating systems, cloud platforms, databases, and applications. Each benchmark is a PDF document containing hundreds of prescriptive controls, organized into sections, with a title, a rationale, an audit procedure, and a remediation command for every single one.
This project implements the **CIS Debian Linux 12 Benchmark v1.1.0**, which contains 104 controls spread across six sections. Each control is either Level 1 (should be applied to every system) or Level 2 (for high-security environments where the hardening may break some functionality). Each control is also scored (counts toward a compliance percentage) or unscored (advisory only).
The benchmark does not invent new security ideas. It codifies the lessons that security teams learned from decades of breaches, incident response, and penetration testing. When the benchmark says "disable IP forwarding," it is because IP forwarding on a non-router host has been used in countless attacks to pivot traffic between network segments.
### How Levels Work
**Level 1** controls are the baseline. They are intended to be applied to every system without breaking standard functionality. If you deploy a Debian server and apply all Level 1 controls, the system should still function normally as a web server, database server, or application host. Examples: disable unused filesystems, set noexec on /tmp, disable SSH root login.
**Level 2** controls provide deeper hardening but may restrict functionality. Disabling the squashfs filesystem (control 1.1.6) is Level 2 because it breaks snap packages on Ubuntu. Disabling vfat (control 1.1.8) is Level 2 because UEFI systems need vfat for the EFI System Partition. An organization running containers might skip squashfs restrictions. A bare-metal server with legacy BIOS can safely disable vfat.
The level distinction matters in practice. A compliance audit that demands "CIS Level 1" is achievable for nearly every Linux deployment. An audit that demands "CIS Level 2" requires careful evaluation of which controls are safe to apply in your specific environment.
### Scored vs. Unscored
Scored controls count toward the compliance percentage. If you have 80 scored controls and pass 64 of them, your score is 80%. Unscored controls are recommendations that do not affect the score. They are typically controls where the correct configuration depends entirely on the organization's context (like which syslog destination to send logs to).
This project treats all 104 controls as scored by default. The scoring engine in `engine.sh` counts only PASS and FAIL results (not WARN or SKIP) when computing percentages, which matches how CIS scoring guidelines work.
---
## System Hardening
### What It Is
System hardening is the process of reducing a system's attack surface by disabling unnecessary features, restricting permissions, and configuring security controls. A freshly installed operating system is designed for broad compatibility, not security. It ships with dozens of kernel modules loaded, services enabled, and permissive default configurations because the vendor does not know your use case.
Hardening is the opposite of that. You start with the defaults and methodically lock down everything that is not required for the system's specific role.
### Why It Matters
The 2017 Equifax breach exposed 147 million Social Security numbers. The initial attack vector was CVE-2017-5638, an Apache Struts vulnerability. But the breach was catastrophic because of systemic hardening failures. The compromised server had unencrypted credentials stored in configuration files, no network segmentation isolating the web tier from the database tier, and expired SSL certificates on internal monitoring tools, which meant that intrusion detection had been effectively blind for 19 months.
Hardening would not have prevented the Struts vulnerability. But it would have contained the blast radius. If /tmp had noexec set, the attacker's uploaded web shell would not have executed. If the audit subsystem had been enabled, the initial compromise would have generated alerts. If file permissions on sensitive configuration files had been restricted, the attacker would not have found database credentials in plaintext.
The point of hardening is not to make a system invulnerable. It is to make the gap between initial compromise and full breach as wide as possible.
### Defense in Depth
CIS benchmarks implement defense in depth through six layers, each corresponding to a section of the benchmark. No single control stops every attack. But together, they create a system where an attacker has to defeat multiple independent defenses.
```
Layer 6: System Maintenance (file permissions, user accounts)
↑ prevents privilege escalation via misconfigurations
Layer 5: Access Controls (cron, SSH, passwords, PAM)
↑ restricts who can authenticate and how
Layer 4: Logging and Auditing (auditd, rsyslog)
↑ ensures attacks leave evidence
Layer 3: Network Configuration (sysctl, firewall, protocols)
↑ limits lateral movement and network attacks
Layer 2: Services (remove unnecessary daemons)
↑ reduces attack surface
Layer 1: Initial Setup (filesystems, bootloader, kernel)
↑ hardens the foundation
```
An attacker who compromises a web application on a hardened system faces all six layers. They cannot drop executables in /tmp (Layer 1). They cannot pivot through an unnecessary DHCP or NFS service (Layer 2). They cannot redirect traffic via IP forwarding (Layer 3). Their actions are logged by auditd (Layer 4). They cannot SSH as root (Layer 5). They cannot find a second account with UID 0 (Layer 6).
---
## Section 1: Initial Setup
### Filesystem Hardening
Controls 1.1.1 through 1.1.8 disable kernel modules for filesystems that servers should never need to mount. cramfs, freevxfs, jffs2, hfs, hfsplus, squashfs, udf, and vfat are all filesystems designed for embedded systems, Apple hardware, optical media, or removable devices. A production Linux server has no reason to mount HFS volumes from a Mac.
The risk is not theoretical. CVE-2013-1773 was a buffer overflow in the Linux kernel's VFAT filesystem driver that allowed arbitrary code execution when mounting a crafted FAT filesystem image. CVE-2019-19813 was a use-after-free in the HFS+ filesystem driver. If the kernel module is loaded, any user who can trigger a mount (or trick the kernel into auto-mounting) can exploit these vulnerabilities. Disabling the module eliminates the attack surface entirely.
The check function `_check_module_disabled` in `01_initial_setup.sh` verifies that each module has an `install [module] /bin/true` directive in `/etc/modprobe.d/`, which causes the kernel to silently ignore load requests.
Controls 1.2.1 through 1.2.4 ensure that /tmp is a separate partition with `noexec`, `nosuid`, and `nodev` mount options. The /tmp directory is world-writable, which makes it the first place an attacker drops payloads after gaining initial access. With noexec, those payloads will not execute. With nosuid, setuid binaries placed in /tmp cannot escalate privileges. With nodev, device nodes cannot be created.
### Bootloader Protection
Controls 1.4.1 through 1.4.3 protect the boot process. Without a bootloader password (1.4.1), anyone with physical or console access can modify GRUB boot parameters to boot into single-user mode and reset the root password. Control 1.4.3 verifies that single-user mode requires `sulogin` authentication, which prevents the classic "init=/bin/bash" attack from granting an unauthenticated root shell.
### Kernel Hardening
ASLR (Address Space Layout Randomization, control 1.5.1) randomizes the memory addresses used by system libraries, the stack, and the heap. Without ASLR (`kernel.randomize_va_space = 0`), an attacker who finds a buffer overflow vulnerability can predict exactly where their shellcode will land in memory. With full ASLR (`kernel.randomize_va_space = 2`), they have to guess from billions of possible addresses.
Core dump restriction (control 1.5.2) prevents programs from writing their memory contents to disk when they crash. Core dumps can contain passwords, encryption keys, and other sensitive data that was in memory at the time of the crash.
---
## Section 2: Services
### Attack Surface Reduction
Every running service is a potential entry point. CIS Section 2 checks for 16 services that should not be installed on a hardened server unless there is an explicit business requirement. The philosophy is simple: if you do not need it, remove it.
The services checked include:
- **xinetd and openbsd-inetd** (2.1.1, 2.1.2): Legacy super-daemons that listen for connections and spawn other services. These are relics from the 1990s when memory was expensive and running a separate daemon for each service was wasteful. Modern systems use systemd socket activation. inetd has been a favored target in attacks for decades.
- **X Window System** (2.2.1): A graphical display server has no place on a headless server. The X protocol was designed without security in mind. Running X increases the attack surface dramatically and provides capabilities (screen capture, input recording) that attackers exploit for collection.
- **NFS, Samba, LDAP, DNS, FTP** (2.2.5 through 2.2.8): Each is a complex network service with a long history of vulnerabilities. An NFS server misconfiguration in 2020 (no specific CVE, it was a configuration error) allowed an attacker to mount an internal file share from the internet and exfiltrate 4TB of customer data from an unnamed financial institution.
- **MTA local-only configuration** (2.2.15): Mail transfer agents like Postfix default to listening on all interfaces. Control 2.2.15 verifies that the MTA only listens on loopback (`inet_interfaces = loopback-only`). An MTA listening on a public interface is an open relay waiting to happen.
---
## Section 3: Network Configuration
### Kernel Network Parameters
The Linux kernel exposes tunable network parameters through `/proc/sys/net/` and `sysctl`. Controls 3.1.1 through 3.2.6 verify that these parameters are set to secure values.
**IP forwarding** (3.1.1): `net.ipv4.ip_forward` controls whether the kernel routes packets between network interfaces. On a server with two NICs, enabled forwarding turns that server into a router. An attacker who compromises such a server can pivot traffic between network segments, bypassing network segmentation controls. Unless the server is explicitly a router or VPN gateway, this must be disabled.
**ICMP redirects** (3.1.2, 3.1.4): ICMP redirect messages tell a host to use a different gateway for a specific destination. An attacker on the local network can send forged ICMP redirects to reroute a victim's traffic through an attacker-controlled machine, enabling man-in-the-middle attacks. Disabling send_redirects and accept_redirects eliminates this vector.
**Source routing** (3.1.3): Source-routed packets allow the sender to specify the exact path through the network. This bypasses routing policies and firewall rules because the attacker dictates which routers the packet traverses. Modern networks should never accept source-routed packets.
**Reverse path filtering** (3.2.4): `rp_filter` causes the kernel to verify that incoming packets on an interface could legitimately arrive on that interface based on the routing table. This stops IP spoofing attacks where an attacker sends packets with a forged source address.
**TCP SYN cookies** (3.2.5): `tcp_syncookies` defends against SYN flood denial-of-service attacks. Without SYN cookies, an attacker who sends millions of SYN packets can exhaust the server's connection table, preventing legitimate clients from connecting. With SYN cookies enabled, the kernel uses a cryptographic technique to validate connection attempts without allocating resources until the handshake completes.
### Firewall Configuration
Controls 3.3.1 through 3.3.5 verify that iptables is installed, that the default policies for INPUT, FORWARD, and OUTPUT chains are DROP or REJECT, and that every open port has a matching firewall rule.
A default-deny firewall policy means that any traffic not explicitly allowed is dropped. This is the opposite of the default-accept policy that most distributions ship with. Default-deny catches the cases where a developer starts a service on an unexpected port, a dependency opens a debug listener, or a misconfiguration exposes an internal service to the network.
### Uncommon Protocol Modules
Controls 3.4.2 through 3.4.5 disable DCCP, SCTP, RDS, and TIPC kernel modules. These are specialized transport protocols that most servers never use. Each has had kernel vulnerabilities (CVE-2017-6074 was a double-free in DCCP that allowed local privilege escalation to root). Disabling the module is the simplest mitigation.
---
## Section 4: Logging and Auditing
### Why Logging Matters
Without logging, a breach is invisible. The median dwell time for attackers (the gap between initial compromise and detection) was 16 days in 2023 according to Mandiant's M-Trends report. For organizations with poor logging, it was significantly longer. The Target breach in 2013 went undetected for weeks despite FireEye generating alerts, because the security team did not have adequate logging infrastructure to correlate the events.
### auditd
Controls 4.1.1 through 4.1.14 verify that the Linux audit framework (`auditd`) is installed, enabled, configured to start at boot, and has rules covering security-critical system calls and files.
The audit framework operates at the kernel level. When configured with rules, it generates log entries every time a process calls specific system calls or modifies specific files. The audit rules in this project check for:
- **Time changes** (4.1.5): `adjtimex`, `settimeofday`, `clock_settime`. Attackers modify system time to make their activity appear to have occurred during a maintenance window or to invalidate time-based authentication tokens.
- **User/group changes** (4.1.6): Modifications to `/etc/passwd`, `/etc/shadow`, `/etc/group`. Any unauthorized changes to these files indicate account creation, privilege escalation, or persistence.
- **Network environment changes** (4.1.7): `sethostname`, `setdomainname`, modifications to `/etc/hosts`. Changing the hostname or DNS configuration can be part of a man-in-the-middle attack or C2 redirection.
- **DAC permission changes** (4.1.11): `chmod`, `chown`, `fchmod`, `setxattr`. These system calls modify file access controls. Attackers use them to make sensitive files readable or to set the setuid bit for privilege escalation.
- **Unauthorized access attempts** (4.1.12): Failed file access attempts that return EACCES or EPERM. A pattern of denied access attempts is a strong indicator of an attacker probing the filesystem for sensitive files.
### rsyslog
Controls 4.2.1 through 4.2.4 verify that rsyslog is installed, enabled, configured with a restrictive file creation mode (0640 or stricter), and has logging rules defined. rsyslog captures application and system messages that auditd does not cover: authentication events, service start/stop, kernel messages, and application logs.
---
## Section 5: Access, Authentication and Authorization
### Cron Security
Controls 5.1.1 through 5.1.4 verify that cron is enabled and that cron-related files and directories have restrictive permissions. An attacker who can write to `/etc/cron.daily/` can install a persistence mechanism that executes every day as root. Restricting cron directories to mode 700 owned by root:root prevents non-root users from planting cron jobs.
### SSH Hardening
Controls 5.2.1 through 5.2.14 cover SSH configuration. SSH is the primary remote access vector for Linux servers, and its configuration directly determines whether the server is accessible to attackers.
**Root login** (5.2.8): `PermitRootLogin no` forces administrators to log in with a named account and then escalate to root with `sudo`. This creates an audit trail of who performed which actions. When root login is allowed, multiple administrators share the root password, and there is no way to determine which human executed which commands.
**Weak cryptography** (5.2.11 through 5.2.13): These controls check that SSH does not allow CBC-mode ciphers (vulnerable to plaintext recovery attacks like CVE-2008-5161), MD5-based MACs (computationally broken), or weak key exchange algorithms like diffie-hellman-group1-sha1 (vulnerable to the Logjam attack, CVE-2015-4000, which allowed man-in-the-middle attackers to downgrade connections to 512-bit keys).
**MaxAuthTries** (5.2.6): Limiting authentication attempts to 4 makes brute-force attacks impractical over SSH. Without this limit, an attacker can try thousands of passwords in a single connection.
**LoginGraceTime** (5.2.14): The time window for completing authentication. Setting it to 60 seconds prevents attackers from opening hundreds of connections and holding them open indefinitely, which can exhaust the SSH daemon's connection pool.
### Password Policies
Controls 5.3.1 and 5.4.1 through 5.4.3 check PAM password quality modules and login.defs settings. `PASS_MAX_DAYS` forces password rotation. `PASS_MIN_DAYS` prevents users from immediately cycling back to their old password. `PASS_WARN_AGE` gives users advance notice of expiration.
Control 5.5.1 verifies account lockout. Without `pam_faillock` or `pam_tally2`, an attacker can attempt unlimited password guesses against a local account through PAM without any lockout mechanism.
---
## Section 6: System Maintenance
### File Permissions
Controls 6.1.1 through 6.1.5 verify that critical system files have correct ownership and permissions:
- `/etc/passwd` should be 644 root:root (readable by all, writable only by root)
- `/etc/shadow` should be 640 root:shadow (only root and the shadow group can read password hashes)
- `/etc/group` should be 644 root:root
- `/etc/gshadow` should be 640 root:shadow
If `/etc/shadow` were world-readable, any user on the system could extract password hashes and crack them offline with tools like hashcat. A modern GPU can test billions of hash combinations per second against SHA-512 hashes.
### Account Integrity
Controls 6.2.1 through 6.2.5 check for duplicate UIDs, duplicate GIDs, duplicate usernames, UID 0 accounts other than root, and legacy "+" entries in passwd/shadow/group files.
**UID 0 accounts** (6.2.4): Any account with UID 0 has full root privileges regardless of its name. A common persistence technique is to create an innocent-looking account like "sysadmin" or "backup" with UID 0. Control 6.2.4 catches this by verifying that only "root" has UID 0.
**Legacy + entries** (6.2.5): The "+" prefix in passwd/shadow/group files is a relic of NIS (Network Information Service). A line starting with "+" in /etc/passwd tells the system to include entries from a remote NIS server. If NIS is not in use, a "+" entry can introduce unexpected accounts or, in some configurations, create a passwordless root-equivalent account.
---
## How These Concepts Relate
```
CIS Benchmark (104 controls)
↓ organized into
6 Sections (defense in depth layers)
↓ each control has
Level (1 = baseline, 2 = advanced)
↓ and produces
Scored Results (PASS / FAIL / WARN / SKIP)
↓ which feed into
Compliance Score (percentage)
↓ which maps to
Regulatory Frameworks (NIST 800-53, PCI DSS, SOC 2)
```
---
## Industry Standards and Frameworks
### NIST 800-53
CIS benchmarks map directly to NIST 800-53 control families:
- **AC (Access Control)**: SSH hardening, cron permissions, password policies
- **AU (Audit and Accountability)**: auditd configuration, audit rules, rsyslog
- **CM (Configuration Management)**: Kernel parameters, disabled services, mount options
- **SC (System and Communications Protection)**: Firewall policies, disabled protocols, IP forwarding
### PCI DSS
PCI DSS Requirement 2 ("Do not use vendor-supplied defaults") maps directly to CIS hardening. Requirement 2.2 specifically calls for removing unnecessary services, protocols, and daemons, which is exactly what CIS Section 2 checks. PCI QSAs (Qualified Security Assessors) regularly accept CIS benchmark audit reports as evidence for Requirement 2 compliance.
### MITRE ATT&CK
The controls in this project map to ATT&CK mitigations:
- **M1042 (Disable or Remove Feature)**: Disabling unused filesystems and services (Sections 1, 2)
- **M1037 (Filter Network Traffic)**: Firewall configuration (Section 3)
- **M1029 (Remote Data Storage)**: rsyslog forwarding (Section 4)
- **M1032 (Multi-factor Authentication)**: SSH key authentication enforcement (Section 5)
- **M1018 (User Account Management)**: Duplicate UID checks, UID 0 restriction (Section 6)
---
## Real World Examples
### Case Study 1: The Equifax Breach (2017)
The initial compromise was CVE-2017-5638, a remote code execution vulnerability in Apache Struts. But the breach investigation revealed that the compromised servers lacked basic hardening controls that CIS benchmarks define. The internal certificate authority had expired certificates, which meant encrypted traffic inspection was disabled. Filesystem permissions were permissive. Network segmentation was absent. The attackers moved laterally from the web tier to the database tier without triggering any alerts because audit logging was insufficient.
A CIS Level 1 audit on those servers would have flagged the missing audit rules, the permissive file permissions, and the absence of network controls. The initial exploit would still have worked, but the attacker's lateral movement and data exfiltration would have been significantly harder and would have generated audit events.
### Case Study 2: The SolarWinds SUNBURST Attack (2020)
The SUNBURST backdoor inserted into SolarWinds Orion updates used sophisticated C2 communications, but the compromised build systems showed evidence of inadequate hardening. Build servers had IP forwarding enabled between network segments, audit logging was not configured to capture file modifications in the build pipeline, and SSH access was not restricted to authorized groups.
The lesson: even the most sophisticated supply chain attack exploits the gap between having security tools and actually hardening the systems those tools run on.
---
## Testing Your Understanding
Before moving to the architecture, make sure you can answer:
1. Why does the CIS benchmark distinguish between Level 1 and Level 2 controls? Give an example where applying a Level 2 control would break functionality.
2. An attacker has compromised a web application and can write files to /tmp. Explain which three mount options would limit their ability to use /tmp for privilege escalation and why each one works.
3. Why is `kernel.randomize_va_space = 1` (partial ASLR) insufficient while `2` (full ASLR) is required by the CIS benchmark?
4. A SOC analyst finds that `net.ipv4.conf.all.accept_redirects = 1` on a production server. Describe the specific attack this enables.
---
## Further Reading
**Essential:**
- [CIS Debian Linux 12 Benchmark v1.1.0](https://www.cisecurity.org/benchmark/debian_linux) - The actual benchmark document this project implements
- [NIST 800-123: Guide to General Server Security](https://csrc.nist.gov/publications/detail/sp/800-123/final) - The foundational document on server hardening
**Deep dives:**
- [Linux Audit Framework Documentation](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/security_hardening/auditing-the-system_security-hardening) - Comprehensive guide to auditd configuration
- [OpenSSH Hardening Guide](https://www.ssh-audit.com/hardening_guides.html) - Detailed analysis of SSH cipher and key exchange security
**Historical context:**
- [Mandiant M-Trends Report](https://www.mandiant.com/m-trends) - Annual report on attacker dwell times, techniques, and the role of logging in detection

View File

@ -0,0 +1,423 @@
<!-- © AngelaMos | 2026 | 02-ARCHITECTURE.md -->
# System Architecture
This document breaks down how cisaudit is designed, how data flows through the system, and why the modular architecture makes it straightforward to add new controls, output formats, and benchmark versions.
---
## High Level Architecture
```
┌──────────────────────────────────────────────────────────┐
│ cisaudit.sh (entry point) │
│ Parse CLI args → Load modules → Orchestrate audit │
└────────────────┬──────────────────────────┬──────────────┘
│ │
┌────────────▼────────────┐ ┌──────────▼──────────────┐
│ controls/ │ │ lib/ │
│ registry_data.sh │ │ constants.sh │
│ │ │ utils.sh │
│ 104 register_control │ │ registry.sh │
│ calls defining every │ │ engine.sh │
│ control's metadata │ │ baseline.sh │
└────────────┬────────────┘ │ report_terminal.sh │
│ │ report_json.sh │
│ │ report_html.sh │
┌────────────▼────────────┐ └──────────────────────────┘
│ checks/ │
│ 01_initial_setup.sh │
│ 02_services.sh │
│ 03_network.sh │
│ 04_logging.sh │
│ 05_access.sh │
│ 05_access_password.sh │
│ 06_maintenance.sh │
│ │
│ check_X_Y_Z() │
│ functions that │
│ inspect the system │
│ and call │
│ record_result() │
└─────────────────────────┘
```
### Component Breakdown
**cisaudit.sh (Entry Point)**
- Parses command-line arguments into global variables
- Sources all library modules, control definitions, and check functions
- Orchestrates the audit: detect OS, run checks, compute scores, emit report
- Handles baseline save/diff and threshold exit codes
**controls/registry_data.sh (Control Registry)**
- Contains 104 `register_control` calls, each defining one CIS benchmark control
- Each call specifies: control ID, section name, title, level, scored status, description, and remediation command
- This is the single source of truth for what the tool audits
**checks/*.sh (Check Functions)**
- One file per CIS benchmark section
- Each file contains `check_X_Y_Z()` functions that inspect the system and call `record_result()`
- Check functions read config files, query sysctl values, verify file permissions, and test for installed packages
**lib/ (Core Libraries)**
- `constants.sh`: Version, benchmark name, ANSI color codes, status codes, section names
- `utils.sh`: Logging, OS detection, file read helpers, sysctl helpers, service/package queries
- `registry.sh`: `register_control()` and `record_result()` functions, result storage
- `engine.sh`: Score computation by section and by level
- `report_*.sh`: Three output formatters (terminal, JSON, HTML)
- `baseline.sh`: Save results as JSON, load and diff against a previous baseline
---
## Data Flow
### Full Audit Flow
Step by step walkthrough of what happens when you run `sudo cisaudit -l 1 -f json -o report.json`:
```
1. cisaudit.sh starts
└─ source lib/constants.sh, utils.sh, registry.sh, engine.sh
└─ source lib/report_*.sh, baseline.sh
└─ source controls/registry_data.sh (populates CTRL_* arrays)
└─ source checks/*.sh (defines check_X_Y_Z functions)
2. parse_args() processes CLI arguments
└─ OPT_LEVEL="1", OPT_FORMAT="json", OPT_OUTPUT="report.json"
3. detect_os() reads /etc/os-release
└─ DETECTED_ID="debian", DETECTED_VERSION="12"
4. run_checks() iterates REGISTERED_IDS[]
└─ For each control ID:
├─ should_run_check() filters by level and category
├─ Calls check_X_Y_Z() function via CTRL_CHECK_FN lookup
└─ check function calls record_result(id, status, evidence)
└─ Appends to RESULT_STATUS[], RESULT_EVIDENCE[], RESULT_ORDER[]
└─ Increments TOTAL_PASS/FAIL/WARN/SKIP counters
5. compute_scores() aggregates results
└─ Counts pass/fail per section → SCORE_BY_SECTION[]
└─ Computes SCORE_OVERALL, SCORE_LEVEL1, SCORE_LEVEL2
6. generate_report() dispatches to emit_json_report()
└─ Iterates RESULT_ORDER[] and SECTION_ORDER[]
└─ Prints JSON with metadata, summary, sections, controls
└─ Writes to report.json via OPT_OUTPUT
7. Threshold check: if SCORE_OVERALL < OPT_THRESHOLD, exit 1
```
### Control Registration Flow
Every control follows the same path from definition to result:
```
registry_data.sh checks/0X_section.sh
│ │
register_control( check_1_1_1() {
"1.1.1", status = PASS
"Initial Setup", evidence = ""
"Ensure cramfs disabled", # inspect system
"1", "yes", # ...
"description...", record_result(
"remediation..." "1.1.1",
) status,
│ evidence
▼ )
CTRL_TITLE["1.1.1"] }
CTRL_SECTION["1.1.1"] │
CTRL_LEVEL["1.1.1"] ▼
CTRL_SCORED["1.1.1"] RESULT_STATUS["1.1.1"]
CTRL_DESCRIPTION["1.1.1"] RESULT_EVIDENCE["1.1.1"]
CTRL_REMEDIATION["1.1.1"] RESULT_ORDER += "1.1.1"
CTRL_CHECK_FN["1.1.1"] TOTAL_PASS++
= "check_1_1_1"
```
The naming convention is automatic. `register_control "1.1.1"` generates the function name `check_1_1_1` by replacing dots with underscores. The check function must exist with that exact name, or the engine logs a SKIP with "Check function check_1_1_1 not implemented."
---
## Design Patterns
### Registry Pattern
The core architectural pattern is a control registry. All 104 controls are registered through a single function (`register_control`) into associative arrays. The engine does not hardcode any control logic. It iterates `REGISTERED_IDS[]`, looks up the check function name from `CTRL_CHECK_FN[]`, and calls it dynamically.
This pattern means:
- Adding a new control requires exactly two changes: one `register_control` call and one `check_X_Y_Z` function
- The engine, reporters, and baseline modules are completely independent of which controls exist
- Controls can be added or removed without modifying any core code
```bash
register_control "1.1.1" \
"Initial Setup" \
"Ensure mounting of cramfs is disabled" \
"1" \
"yes" \
"The cramfs filesystem type is..." \
"echo 'install cramfs /bin/true' >> /etc/modprobe.d/cramfs.conf"
```
This call populates six associative arrays and one indexed array. The function name is derived from the ID: `check_1_1_1`.
### Strategy Pattern for Reporters
Three reporter modules (`report_terminal.sh`, `report_json.sh`, `report_html.sh`) each expose a single entry function: `emit_terminal_report`, `emit_json_report`, `emit_html_report`. The `generate_report` function in `cisaudit.sh` dispatches to the correct one based on `OPT_FORMAT`.
Each reporter reads the same global state (RESULT_STATUS, RESULT_EVIDENCE, SCORE_BY_SECTION, etc.) and transforms it into a different format. They share no code between them because each output format has fundamentally different structure.
Adding a new format (CSV, SARIF, Markdown) means writing one new file with one `emit_X_report` function and adding one case to `generate_report`. Nothing else changes.
### SYSROOT Abstraction
Every file access goes through helper functions that prepend the `SYSROOT` variable:
```bash
file_exists() {
[[ -f "${SYSROOT}${1}" ]]
}
read_file() {
local path="${SYSROOT}${1}"
if [[ -f "$path" ]]; then
cat "$path"
else
return 1
fi
}
get_sysctl() {
local param="$1"
local proc_path="${SYSROOT}/proc/sys/${param//\.//}"
if [[ -f "$proc_path" ]]; then
cat "$proc_path"
return 0
fi
# ...
}
```
When `SYSROOT="/"`, these functions access the real system. When `SYSROOT="testdata/fixtures"`, they access the mock filesystem. This single abstraction enables the entire test suite to run without root and without a live system.
---
## Layer Separation
```
┌──────────────────────────────────────┐
│ Layer 1: CLI / Orchestration │
│ cisaudit.sh │
│ - Parses arguments │
│ - Controls execution order │
│ - Does NOT inspect the system │
└──────────────────────────────────────┘
┌──────────────────────────────────────┐
│ Layer 2: Control Definitions │
│ controls/registry_data.sh │
│ - Declares what to check │
│ - Contains no check logic │
│ - Pure metadata │
└──────────────────────────────────────┘
┌──────────────────────────────────────┐
│ Layer 3: Check Functions │
│ checks/01_initial_setup.sh ... │
│ - Inspects the system │
│ - Calls record_result() │
│ - Does NOT format output │
└──────────────────────────────────────┘
┌──────────────────────────────────────┐
│ Layer 4: Scoring and Reporting │
│ lib/engine.sh, report_*.sh │
│ - Computes scores from results │
│ - Formats output │
│ - Does NOT know what was checked │
└──────────────────────────────────────┘
```
### Why Layers?
- **Testability**: Check functions can be tested against mock filesystems without involving the CLI layer. The scoring engine can be tested with synthetic result data without running any checks.
- **Extensibility**: A new CIS benchmark version means updating Layer 2 (control definitions) and Layer 3 (check functions). Layers 1 and 4 are unchanged.
- **Separation of concerns**: A check function never touches formatting. A reporter never touches the filesystem. Each module has one job.
---
## Data Models
cisaudit uses Bash associative arrays as its data model. There are no external data stores.
### Control Registry (populated by register_control)
```
CTRL_TITLE["1.1.1"] = "Ensure mounting of cramfs is disabled"
CTRL_SECTION["1.1.1"] = "Initial Setup"
CTRL_LEVEL["1.1.1"] = "1"
CTRL_SCORED["1.1.1"] = "yes"
CTRL_DESCRIPTION["1.1.1"] = "The cramfs filesystem type is..."
CTRL_REMEDIATION["1.1.1"] = "echo 'install cramfs /bin/true' >> ..."
CTRL_CHECK_FN["1.1.1"] = "check_1_1_1"
REGISTERED_IDS[] = ("1.1.1" "1.1.2" "1.1.3" ...)
```
### Result Storage (populated by record_result)
```
RESULT_STATUS["1.1.1"] = "PASS"
RESULT_EVIDENCE["1.1.1"] = "cramfs disabled via /etc/modprobe.d/cramfs.conf"
RESULT_ORDER[] = ("1.1.1" "1.1.2" ...)
TOTAL_PASS = 72
TOTAL_FAIL = 18
TOTAL_WARN = 6
TOTAL_SKIP = 8
```
### Score Aggregation (populated by compute_scores)
```
SECTION_PASS["Initial Setup"] = 16
SECTION_FAIL["Initial Setup"] = 2
SCORE_BY_SECTION["Initial Setup"] = "88.9"
SCORE_OVERALL = "80.0"
SCORE_LEVEL1 = "82.5"
SCORE_LEVEL2 = "75.0"
```
---
## Test Architecture
### Fixture-Based Testing
The test suite runs checks against two mock filesystems:
```
testdata/
├── fixtures/ # Hardened system (most checks PASS)
│ ├── etc/
│ │ ├── modprobe.d/ # cramfs.conf, dccp.conf, etc.
│ │ ├── ssh/sshd_config
│ │ ├── pam.d/
│ │ ├── audit/rules.d/cis.rules
│ │ ├── sysctl.conf
│ │ ├── fstab
│ │ ├── passwd, shadow, group, gshadow
│ │ └── ...
│ └── proc/sys/ # Simulated /proc values
│ ├── kernel/randomize_va_space (contains "2")
│ ├── net/ipv4/ip_forward (contains "0")
│ └── ...
└── fixtures_fail/ # Unhardened system (most checks FAIL)
├── etc/
│ ├── modprobe.d/ # empty
│ ├── ssh/sshd_config (PermitRootLogin yes, etc.)
│ └── ...
└── proc/sys/ # Insecure values
├── net/ipv4/ip_forward (contains "1")
└── ...
```
Each `/proc/sys/` parameter is a plain file containing the expected value. The `get_sysctl` function reads the file at `${SYSROOT}/proc/sys/net/ipv4/ip_forward` instead of calling `sysctl -n net.ipv4.ip_forward`. This lets the test fixtures simulate kernel parameters without running on a real kernel.
### Test Framework
The test runner is a custom framework in `test_helpers.sh` with three assertion functions:
```bash
assert_status "1.1.1" "$STATUS_PASS"
assert_evidence_contains "1.1.1" "cramfs disabled"
assert_json_valid "$json_output"
```
Tests follow a consistent pattern:
```bash
test_cramfs_disabled_pass() {
CURRENT_TEST="test_cramfs_disabled_pass"
setup_test "${PROJECT_DIR}/testdata/fixtures"
check_1_1_1
assert_status "1.1.1" "$STATUS_PASS"
}
test_cramfs_disabled_fail() {
CURRENT_TEST="test_cramfs_disabled_fail"
setup_test "${PROJECT_DIR}/testdata/fixtures_fail"
check_1_1_1
assert_status "1.1.1" "$STATUS_FAIL"
}
```
Each test resets the result state via `setup_test`, sets `SYSROOT` to the appropriate fixture directory, calls the check function, and asserts the expected status.
---
## Security Architecture
### Threat Model
**What we protect against:**
1. Misconfigured Linux systems going into production without hardening
2. Configuration drift where a system's hardening regresses over time (detected via baseline comparison)
3. Compliance gaps where an organization does not know which CIS controls they pass or fail
**What we do NOT protect against:**
- Runtime exploitation of services (this is an audit tool, not an IDS)
- Active attacks in progress (cisaudit is a point-in-time snapshot, not continuous monitoring)
- Misrepresentation of results (someone could modify fixture files to fake a passing audit)
### Defense in the Tool Itself
- `set -euo pipefail` in every script: fails on undefined variables, pipe errors, and uncaught errors
- `json_escape` and `html_escape` prevent injection in JSON and HTML reports
- `SYSROOT` defaults to `/` so the tool cannot accidentally audit a test fixture when run as root without `-t`
- The tool never modifies the system. It is read-only by design. All check functions use `grep`, `cat`, `stat`, and `sysctl` to inspect without changing state
---
## Design Decisions
### Why Bash?
CIS auditing needs to run on minimal systems where Python, Ruby, or Go might not be installed. Bash 4+ is present on every modern Linux distribution. The tool has zero external dependencies beyond standard GNU utilities (grep, awk, sed, stat, date). This means it can run on a freshly provisioned server before any configuration management or package installation has occurred.
The trade-off is that Bash's associative arrays are slower than hash tables in compiled languages, and string manipulation is verbose. For 104 controls, the performance difference is negligible. The audit completes in under 2 seconds on typical systems.
### Why Not Use Existing Tools?
Tools like OpenSCAP and Lynis provide similar functionality. This project exists as a learning resource that demonstrates how compliance auditing works from first principles. OpenSCAP uses XCCDF/OVAL XML definitions that are difficult to read. Lynis is a monolithic 7000+ line script. cisaudit is intentionally modular and readable so that every design decision is visible.
### Why Associative Arrays Instead of JSON/SQLite?
Bash associative arrays keep the tool dependency-free. Using `jq` for JSON manipulation or `sqlite3` for storage would add external dependencies. The trade-off is that the data model is implicit (arrays must be declared and populated in the right order) rather than schema-enforced. For 104 controls, the simplicity is worth it.
---
## Key Files Reference
Quick map of where to find things:
- `src/cisaudit.sh` - CLI entry point, argument parsing, orchestration
- `src/lib/constants.sh` - All constants (version, colors, status codes, section names)
- `src/lib/registry.sh` - `register_control()` and `record_result()` functions
- `src/lib/engine.sh` - Score computation logic
- `src/lib/utils.sh` - System inspection helpers (`get_sysctl`, `read_file`, `file_exists`)
- `src/controls/registry_data.sh` - All 104 control definitions
- `src/checks/01_initial_setup.sh` - Filesystem and bootloader checks
- `src/checks/03_network.sh` - Network parameter and firewall checks
- `src/lib/report_terminal.sh` - ASCII art terminal report
- `src/lib/report_html.sh` - Standalone HTML report with CSS
- `tests/test_helpers.sh` - Test assertion functions
---
## Next Steps
Now that you understand the architecture:
1. Read [03-IMPLEMENTATION.md](./03-IMPLEMENTATION.md) for a code walkthrough of each module
2. Try running `cisaudit -t testdata/fixtures -f json | python3 -m json.tool` and trace the output back through the code

View File

@ -0,0 +1,682 @@
<!-- © AngelaMos | 2026 | 03-IMPLEMENTATION.md -->
# Implementation Guide
This document walks through the actual code. We will trace how controls are registered, how check functions inspect the system, how scores are computed, and how reports are generated. Code snippets come directly from the project source files.
---
## File Structure Walkthrough
```
src/
├── cisaudit.sh # Entry point and CLI orchestration
├── lib/
│ ├── constants.sh # All constants and color codes
│ ├── utils.sh # System inspection helpers
│ ├── registry.sh # Control registration and result storage
│ ├── engine.sh # Score aggregation
│ ├── report_terminal.sh # Terminal output with progress bars
│ ├── report_json.sh # Machine-readable JSON
│ ├── report_html.sh # Standalone HTML with embedded CSS
│ └── baseline.sh # Save/load/diff baselines
├── controls/
│ └── registry_data.sh # 104 control definitions
└── checks/
├── 01_initial_setup.sh # 20 checks for Section 1
├── 02_services.sh # 16 checks for Section 2
├── 03_network.sh # 20 checks for Section 3
├── 04_logging.sh # 18 checks for Section 4
├── 05_access.sh # 14 checks for Section 5 (cron, SSH)
├── 05_access_password.sh # 4 checks for Section 5 (passwords, PAM)
└── 06_maintenance.sh # 10 checks for Section 6
```
---
## Building the Control Registry
### The register_control Function
Every CIS control starts as a call to `register_control` in `registry_data.sh`. The function in `registry.sh` stores control metadata into associative arrays and derives the check function name from the control ID:
```bash
register_control() {
local id="$1"
local section="$2"
local title="$3"
local level="$4"
local scored="$5"
local description="$6"
local remediation="$7"
CTRL_TITLE["$id"]="$title"
CTRL_SECTION["$id"]="$section"
CTRL_LEVEL["$id"]="$level"
CTRL_SCORED["$id"]="$scored"
CTRL_DESCRIPTION["$id"]="$description"
CTRL_REMEDIATION["$id"]="$remediation"
local fn_name="check_${id//\./_}"
CTRL_CHECK_FN["$id"]="$fn_name"
REGISTERED_IDS+=("$id")
}
```
The expression `${id//\./_}` replaces every dot with an underscore. Control ID `"1.1.1"` becomes function name `"check_1_1_1"`. Control ID `"5.2.14"` becomes `"check_5_2_14"`. This naming convention is enforced by the registration system, not by documentation. If a check function does not exist, the engine skips it with evidence explaining why.
### A Registration Call
In `registry_data.sh`, each control definition looks like this:
```bash
register_control "1.2.1" \
"Initial Setup" \
"Ensure /tmp is a separate partition" \
"1" \
"yes" \
"The /tmp directory is a world-writable location used for temporary file storage..." \
"echo 'tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime 0 0' >> /etc/fstab && mount -o remount /tmp"
```
The seven positional arguments are: ID, section, title, level, scored, description, remediation. The description is stored but not displayed in terminal reports (only in JSON and HTML). The remediation string is shown to the user when a control fails, so they know exactly what command to run.
### The record_result Function
After a check function inspects the system, it records its finding:
```bash
record_result() {
local id="$1"
local status="$2"
local evidence="$3"
RESULT_STATUS["$id"]="$status"
RESULT_EVIDENCE["$id"]="$evidence"
RESULT_ORDER+=("$id")
case "$status" in
"$STATUS_PASS") ((TOTAL_PASS++)) || true ;;
"$STATUS_FAIL") ((TOTAL_FAIL++)) || true ;;
"$STATUS_WARN") ((TOTAL_WARN++)) || true ;;
"$STATUS_SKIP") ((TOTAL_SKIP++)) || true ;;
esac
}
```
The `|| true` after the increment is necessary because `((TOTAL_PASS++))` returns exit code 1 when TOTAL_PASS was 0 (because `0` is falsy in arithmetic context), and `set -e` would terminate the script. This is a common Bash gotcha that silently kills scripts using strict mode.
---
## Writing Check Functions
### Pattern 1: Shared Helper with Per-Control Wrappers
Many controls in the same section follow an identical check pattern with different parameters. Instead of duplicating logic, a private helper function does the work and thin wrappers call it.
The filesystem module disable checks all follow this pattern. The helper `_check_module_disabled` in `01_initial_setup.sh` handles the full logic:
```bash
_check_module_disabled() {
local id="$1"
local module="$2"
local status="$STATUS_PASS"
local evidence=""
local modprobe_conf="${SYSROOT}/etc/modprobe.d/${module}.conf"
if run_cmd lsmod | grep -q "^${module} "; then
status="$STATUS_FAIL"
evidence="${module} module is currently loaded"
elif [[ -f "$modprobe_conf" ]] && grep -q "install ${module} /bin/true\|install ${module} /bin/false" "$modprobe_conf"; then
evidence="${module} disabled via ${modprobe_conf}"
else
local found_disabled="false"
for conf in "${SYSROOT}"/etc/modprobe.d/*.conf; do
[[ -f "$conf" ]] || continue
if grep -q "install ${module} /bin/true\|install ${module} /bin/false\|blacklist ${module}" "$conf"; then
found_disabled="true"
evidence="${module} disabled via ${conf}"
break
fi
done
if [[ "$found_disabled" == "false" ]]; then
status="$STATUS_FAIL"
evidence="${module} is not disabled"
fi
fi
record_result "$id" "$status" "$evidence"
}
```
The function checks three things in order: (1) is the module currently loaded in memory, (2) does a dedicated modprobe config file exist, (3) does any modprobe config file contain a disable or blacklist directive for this module. If none of these succeed, the control fails.
Each control wraps the helper in a one-liner:
```bash
check_1_1_1() { _check_module_disabled "1.1.1" "cramfs"; }
check_1_1_2() { _check_module_disabled "1.1.2" "freevxfs"; }
check_1_1_3() { _check_module_disabled "1.1.3" "jffs2"; }
```
The same pattern appears throughout the codebase. SSH checks use `_check_ssh_value` and `_check_ssh_max_int`. Password policy checks use `_check_login_defs_value`. File permission checks use `_check_file_permissions`.
### Pattern 2: Standalone Complex Check
Some controls have unique logic that does not generalize. The MTA local-only check (`check_2_2_15`) inspects multiple mail transfer agents in priority order:
```bash
check_2_2_15() {
local id="2.2.15"
local status="$STATUS_PASS"
local evidence=""
local listening_external=""
if run_cmd ss -lntp | grep -qE ':25\s' 2>/dev/null; then
local listeners
listeners=$(run_cmd ss -lntp | grep -E ':25\s' 2>/dev/null) || true
if echo "$listeners" | grep -qvE '127\.0\.0\.1:25|::1:25|\[::1\]:25|\*:25'; then
local bound_addrs
bound_addrs=$(echo "$listeners" | awk '{print $4}')
if echo "$bound_addrs" | grep -qvE '^127\.0\.0\.1:|^\[::1\]:|^::1:'; then
listening_external="true"
fi
fi
fi
# ... continues with Postfix, Exim, Sendmail checks ...
}
```
This function first checks whether anything is listening on port 25 on a non-loopback interface (the definitive test). Then it falls back to reading Postfix's `inet_interfaces` setting, then Exim's `dc_local_interfaces`, then checks for Sendmail. The layered approach handles different MTA configurations without hardcoding assumptions about which MTA is installed.
### Pattern 3: Audit Rule Verification
The `_check_audit_rules` function in `04_logging.sh` takes a list of patterns and verifies that each one appears in at least one audit rules file:
```bash
_check_audit_rules() {
local id="$1"
shift
local description="$1"
shift
local search_patterns=("$@")
local status="$STATUS_PASS"
local evidence=""
local rules_dir="${SYSROOT}/etc/audit/rules.d"
local audit_rules="${SYSROOT}/etc/audit/audit.rules"
local missing=()
for pattern in "${search_patterns[@]}"; do
local found="false"
if [[ -d "$rules_dir" ]]; then
for rule_file in "$rules_dir"/*.rules; do
[[ -f "$rule_file" ]] || continue
if grep -q "$pattern" "$rule_file"; then
found="true"
break
fi
done
fi
if [[ "$found" == "false" && -f "$audit_rules" ]]; then
if grep -q "$pattern" "$audit_rules"; then
found="true"
fi
fi
if [[ "$found" == "false" ]]; then
missing+=("$pattern")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
status="$STATUS_FAIL"
evidence="Missing audit rules for: ${missing[*]}"
else
evidence="${description} audit rules are configured"
fi
record_result "$id" "$status" "$evidence"
}
```
Callers pass variable-length pattern lists:
```bash
check_4_1_5() {
_check_audit_rules "4.1.5" "Time change" \
"adjtimex" "settimeofday" "clock_settime" "/etc/localtime"
}
```
If any pattern is missing from all rules files, the control fails with evidence listing exactly which patterns were not found. This gives the user actionable information about what audit rules to add.
---
## The SYSROOT Abstraction
### How It Works
The `SYSROOT` variable defaults to `"/"`. When running in test mode (`-t testdata/fixtures`), it is set to the fixture directory path. Every system inspection function prepends `SYSROOT` to file paths:
```bash
file_exists() {
[[ -f "${SYSROOT}${1}" ]]
}
read_file() {
local path="${SYSROOT}${1}"
if [[ -f "$path" ]]; then
cat "$path"
else
return 1
fi
}
```
The `get_sysctl` function is where this gets interesting. Sysctl values are normally read with `sysctl -n net.ipv4.ip_forward`, but that requires a running kernel. In test mode, the function translates the dotted sysctl parameter name into a `/proc/sys/` path:
```bash
get_sysctl() {
local param="$1"
local proc_path="${SYSROOT}/proc/sys/${param//\.//}"
if [[ -f "$proc_path" ]]; then
cat "$proc_path"
return 0
fi
if run_cmd sysctl -n "$param"; then
return 0
fi
return 1
}
```
The expression `${param//\.//}` replaces dots with slashes. So `net.ipv4.ip_forward` becomes `net/ipv4/ip_forward`, and the full path becomes `testdata/fixtures/proc/sys/net/ipv4/ip_forward`. That file contains `0` (the expected secure value).
The `run_cmd` function explicitly blocks command execution in test mode:
```bash
run_cmd() {
if [[ "$SYSROOT" != "/" ]]; then
return 1
fi
"$@" 2>/dev/null
}
```
When `SYSROOT` is not `/`, `run_cmd` always returns failure. This means checks that rely on `systemctl`, `dpkg-query`, `lsmod`, or `iptables` will skip in test mode because those commands cannot run against a fixture directory. Only file-based checks produce results.
---
## Score Computation
The `compute_scores` function in `engine.sh` aggregates results per section and per level:
```bash
compute_scores() {
local section
for section in "${SECTION_ORDER[@]}"; do
SECTION_PASS["$section"]=0
SECTION_FAIL["$section"]=0
SECTION_WARN["$section"]=0
SECTION_SKIP["$section"]=0
done
local id
for id in "${RESULT_ORDER[@]}"; do
section="${CTRL_SECTION[$id]}"
case "${RESULT_STATUS[$id]}" in
"$STATUS_PASS") ((SECTION_PASS["$section"]++)) || true ;;
"$STATUS_FAIL") ((SECTION_FAIL["$section"]++)) || true ;;
"$STATUS_WARN") ((SECTION_WARN["$section"]++)) || true ;;
"$STATUS_SKIP") ((SECTION_SKIP["$section"]++)) || true ;;
esac
done
# ...
}
```
Scores are computed as `(pass / (pass + fail)) * 100`. WARN and SKIP results are excluded from the percentage because CIS scoring guidelines only count definitively passed or failed controls. A control that was skipped (because it requires a live system) should not penalize the score.
The `awk` call for percentage calculation avoids Bash's limitation of integer-only arithmetic:
```bash
SCORE_OVERALL=$(awk "BEGIN { printf \"%.1f\", ($TOTAL_PASS / $scored_total) * 100 }")
```
---
## Report Generation
### Terminal Report
The terminal reporter in `report_terminal.sh` produces a structured ASCII output with colored sections. The main function chains four rendering steps:
```bash
emit_terminal_report() {
_print_banner
_print_summary_cards
_print_section_table
_print_detail_results
_print_footer
}
```
The progress bar function `_progress_bar` renders a 20-character wide bar using block characters:
```bash
_progress_bar() {
local percentage="$1"
local width=20
local filled
local empty
if [[ "$percentage" == "N/A" ]]; then
printf '%s' "░░░░░░░░░░░░░░░░░░░░"
return
fi
filled=$(awk "BEGIN { printf \"%d\", ($percentage / 100) * $width + 0.5 }")
empty=$((width - filled))
local bar=""
local i
for (( i = 0; i < filled; i++ )); do
bar+="█"
done
for (( i = 0; i < empty; i++ )); do
bar+="░"
done
printf '%s' "$bar"
}
```
The detail results section shows per-control status with evidence and remediation for failed controls:
```bash
if [[ "$status" == "$STATUS_FAIL" ]]; then
local evidence="${RESULT_EVIDENCE[$id]:-}"
local remediation="${CTRL_REMEDIATION[$id]:-}"
if [[ -n "$evidence" ]]; then
printf ' %b Evidence: %s%b\n' "$DIM" "$evidence" "$RESET"
fi
if [[ -n "$remediation" ]]; then
printf ' %b Fix: %s%b\n' "$YELLOW" "$remediation" "$RESET"
fi
fi
```
### JSON Report
The JSON reporter in `report_json.sh` uses `printf` to build valid JSON without `jq`. The `json_escape` function handles the five characters that must be escaped in JSON strings:
```bash
json_escape() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//$'\n'/\\n}"
s="${s//$'\t'/\\t}"
s="${s//$'\r'/\\r}"
printf '%s' "$s"
}
```
The report includes metadata (version, benchmark, timestamp, hostname, OS), a summary object, an array of section scores, and an array of all control results. Each control result includes the ID, section, title, level, scored status, result status, evidence, and remediation. This makes the JSON output usable for ingestion into SIEMs, dashboards, or compliance platforms.
### HTML Report
The HTML reporter in `report_html.sh` generates a standalone HTML document with embedded CSS. The entire report is a single self-contained file with no external dependencies, which means it can be emailed, archived, or viewed offline.
The CSS uses a dark color scheme with CSS custom properties for theme colors. Failed controls are rendered with `<details open>` so they are expanded by default, while passing controls are collapsed. The report includes responsive breakpoints for mobile viewing and a print stylesheet that switches to a light theme.
---
## Baseline Comparison
The baseline module in `baseline.sh` lets users save a JSON snapshot and compare future runs against it.
Saving is straightforward: it calls `emit_json_report` and writes the output to a file.
Loading and diffing uses pure Bash regex matching to extract control IDs and statuses from the JSON without requiring `jq`:
```bash
load_baseline() {
local file="$1"
BASELINE_STATUS=()
local current_id=""
local id_pattern='"id":[[:space:]]*"([^"]+)"'
local status_pattern='"status":[[:space:]]*"([^"]+)"'
while IFS= read -r line; do
if [[ "$line" =~ $id_pattern ]]; then
current_id="${BASH_REMATCH[1]}"
fi
if [[ -n "$current_id" && "$line" =~ $status_pattern ]]; then
BASELINE_STATUS["$current_id"]="${BASH_REMATCH[1]}"
current_id=""
fi
done < "$file"
}
```
The diff output categorizes changes as regressions (PASS to FAIL), improvements (FAIL to PASS), unchanged, new controls, and removed controls. Regressions are highlighted in red and generate a warning.
---
## The Test Framework
### Test Runner
The test runner in `test_runner.sh` sources all project modules, then discovers test files by globbing `test_*.sh` (excluding `test_helpers.sh` and `test_runner.sh`). For each file, it sources it, discovers functions matching `^test_`, calls each one, and then unsets them to prevent collisions with the next file:
```bash
run_test_file() {
local test_file="$1"
source "$test_file"
local test_fns
test_fns=$(declare -F | awk '{print $3}' | grep '^test_')
local fn
for fn in $test_fns; do
echo " Running: ${fn}"
"$fn"
done
for fn in $test_fns; do
unset -f "$fn"
done
}
```
### Assertion Helpers
The `setup_test` function resets all result state and sets `SYSROOT` to a fixture directory:
```bash
setup_test() {
local fixtures_dir="$1"
reset_results
SYSROOT="$fixtures_dir"
DETECTED_ID="debian"
DETECTED_VERSION="12"
}
```
`assert_status` compares the recorded result status for a control ID against the expected value:
```bash
assert_status() {
local id="$1" expected="$2"
local actual="${RESULT_STATUS[$id]:-UNSET}"
((TEST_TOTAL++)) || true
if [[ "$actual" == "$expected" ]]; then
((TEST_PASS++)) || true
else
((TEST_FAIL++)) || true
echo " FAIL: ${CURRENT_TEST} — ${id}: expected ${expected}, got ${actual}" >&2
fi
}
```
`assert_evidence_contains` verifies that the evidence string contains an expected substring. This is more robust than exact matching because evidence strings often include variable details like file paths or numeric values.
---
## Adding a New Control
To add a new CIS control, you need exactly two changes:
**Step 1: Register the control** in `controls/registry_data.sh`:
```bash
register_control "1.6.1" \
"Initial Setup" \
"Ensure SELinux or AppArmor is installed" \
"1" \
"yes" \
"Mandatory access control frameworks restrict process capabilities beyond DAC permissions" \
"apt-get install apparmor apparmor-utils"
```
**Step 2: Write the check function** in the appropriate `checks/0X_section.sh` file:
```bash
check_1_6_1() {
local id="1.6.1"
local status="$STATUS_PASS"
local evidence=""
if package_is_installed "apparmor"; then
evidence="AppArmor is installed"
elif package_is_installed "selinux-basics"; then
evidence="SELinux is installed"
elif file_exists "/usr/sbin/apparmor_parser"; then
evidence="AppArmor binary found"
else
status="$STATUS_FAIL"
evidence="Neither AppArmor nor SELinux is installed"
fi
record_result "$id" "$status" "$evidence"
}
```
**Step 3: Add tests** in the appropriate `tests/test_0X_section.sh` file:
```bash
test_selinux_apparmor_pass() {
CURRENT_TEST="test_selinux_apparmor_pass"
setup_test "${PROJECT_DIR}/testdata/fixtures"
# add /usr/sbin/apparmor_parser to fixtures first
check_1_6_1
assert_status "1.6.1" "$STATUS_PASS"
}
```
The engine, reporters, baseline module, and scoring engine automatically pick up the new control. No other files need modification.
---
## Common Implementation Pitfalls
### Pitfall 1: Arithmetic Increment Under set -e
**Symptom:** Script exits silently when incrementing a counter that is currently 0.
**Cause:**
```bash
((count++))
```
When `count` is 0, `((count++))` evaluates to 0 (the pre-increment value), which is falsy in Bash arithmetic. Under `set -e`, this non-zero exit code terminates the script.
**Fix:**
```bash
((count++)) || true
```
The `|| true` swallows the false exit code. This pattern appears throughout the codebase wherever a counter is incremented.
### Pitfall 2: Grep Failure Under set -e
**Symptom:** Script exits when grep finds no matches.
**Cause:** `grep` returns exit code 1 when it finds no matches. Under `set -e`, this is treated as a fatal error.
**Fix:**
```bash
local result
result=$(grep "pattern" "$file") || true
```
The `|| true` ensures the script continues when grep finds nothing. The variable `result` will be empty, and the check function should handle that case.
### Pitfall 3: Missing Quote Around Variable in Array Key
**Symptom:** Associative array lookups return empty for keys containing special characters.
**Cause:**
```bash
RESULT_STATUS[$id]="PASS"
```
If `$id` contains characters that Bash might interpret (spaces, special characters), the lookup fails.
**Fix:**
```bash
RESULT_STATUS["$id"]="PASS"
```
Always quote associative array keys. The codebase consistently quotes all array key accesses.
---
## Debugging Tips
### Control Returns Unexpected Status
1. Run the specific control in isolation against a fixture:
```bash
source src/lib/constants.sh src/lib/utils.sh src/lib/registry.sh
source src/controls/registry_data.sh
source src/checks/01_initial_setup.sh
SYSROOT="testdata/fixtures" QUIET="true"
check_1_1_1
echo "${RESULT_STATUS[1.1.1]}: ${RESULT_EVIDENCE[1.1.1]}"
```
2. Check whether the fixture file exists and contains the expected content
3. Verify that the check function is looking at the right file path under `SYSROOT`
### JSON Report Is Invalid
1. Pipe through `python3 -m json.tool` to see where the parser fails
2. Check whether any evidence string contains unescaped quotes or newlines
3. The `json_escape` function handles `\`, `"`, `\n`, `\t`, and `\r`. If a new character causes issues, add it to the function
### Tests Pass Locally But Fail in CI
1. Check the Bash version: `bash --version`. Some CI environments ship Bash 4.x where a check relies on Bash 5.x features
2. Verify that the working directory is set correctly. `SCRIPT_DIR` and `PROJECT_DIR` in the test runner depend on `${BASH_SOURCE[0]}`
3. Ensure that fixture files have the correct line endings (LF, not CRLF)
---
## Next Steps
You have seen how the code works. Now:
1. **Try the challenges** - [04-CHALLENGES.md](./04-CHALLENGES.md) has extension ideas ranging from new output formats to multi-distro support
2. **Modify a check** - Pick a control, change the expected value in a fixture, and verify the check fails as expected
3. **Add a control** - Follow the three-step process above to add a control from the CIS benchmark that is not yet implemented

View File

@ -0,0 +1,455 @@
<!-- © AngelaMos | 2026 | 04-CHALLENGES.md -->
# Extension Challenges
You have built the base project. Now make it yours by extending it with new features.
These challenges are ordered by difficulty. Start with the easier ones to build confidence, then tackle the harder ones when you want to dive deeper.
---
## Easy Challenges
### Challenge 1: CSV Report Output
**What to build:**
Add a `csv` output format that produces a spreadsheet-friendly report.
**Why it's useful:**
Compliance teams live in spreadsheets. A CSV report can be imported into Excel, Google Sheets, or a GRC (Governance, Risk, Compliance) platform for tracking and sign-off workflows. JSON is great for automation, but when an auditor asks for evidence, they want a spreadsheet.
**What you'll learn:**
- How the report strategy pattern works
- CSV escaping (fields containing commas or quotes need to be quoted)
- Adding a new option value to the CLI parser
**Hints:**
- Create `src/lib/report_csv.sh` with an `emit_csv_report` function
- Add `csv` as a case in `generate_report` in `cisaudit.sh`
- Header row: `ID,Section,Title,Level,Scored,Status,Evidence,Remediation`
- Use a `csv_escape` function that wraps fields containing commas or double quotes in double quotes, and doubles any internal double quotes
**Test it works:**
```bash
cisaudit -t testdata/fixtures -f csv -o report.csv
head -5 report.csv
```
### Challenge 2: Control Count Summary
**What to build:**
Add a `--summary` flag that prints a one-line summary instead of the full report.
**Why it's useful:**
CI/CD pipelines need a quick pass/fail answer, not a multi-page report. A summary line like `cisaudit: 82/104 passed (78.8%) Level1=85.2% Level2=68.0%` is easy to parse in shell scripts and log aggregators.
**What you'll learn:**
- Adding a new CLI flag to `parse_args`
- Short-circuiting the report generation
**Hints:**
- Add `OPT_SUMMARY="false"` to the global declarations
- Add a `--summary` case to `parse_args`
- In `main`, after `compute_scores`, check `OPT_SUMMARY` and print the one-liner instead of calling `generate_report`
**Test it works:**
```bash
cisaudit -t testdata/fixtures --summary
```
### Challenge 3: Color Toggle
**What to build:**
Add a `--no-color` flag that disables ANSI color codes in terminal output.
**Why it's useful:**
Piping colored output to a file or another tool produces garbage characters like `[0;32m`. Log aggregation systems, pagers like `less` (without `-R`), and CI logs often render ANSI codes as literal text. A `--no-color` flag makes the output clean for non-terminal use.
**What you'll learn:**
- How ANSI color constants work in `constants.sh`
- Conditional initialization of global variables
**Hints:**
- Add `--no-color` to `parse_args`
- After parsing, if `--no-color` was set, re-declare all color variables as empty strings: `RED=""`, `GREEN=""`, etc.
- Alternatively, detect `[[ ! -t 1 ]]` (stdout is not a terminal) and auto-disable colors
**Test it works:**
```bash
cisaudit -t testdata/fixtures --no-color | cat
cisaudit -t testdata/fixtures -f terminal | less
```
---
## Intermediate Challenges
### Challenge 4: RHEL/CentOS Support
**What to build:**
Extend the check functions to handle Red Hat-based distributions (RHEL, CentOS, Rocky Linux, AlmaLinux) in addition to Debian/Ubuntu.
**Why it's useful:**
CIS publishes separate benchmarks for different distributions, but many controls are identical. Enterprise environments often run both Debian and RHEL systems. A single audit tool that handles both reduces tooling overhead.
**What you'll learn:**
- How package management differs between distributions (dpkg vs rpm)
- Distribution detection from `/etc/os-release`
- Conditional logic based on OS family
**Implementation approach:**
1. **Modify `utils.sh`** to add RHEL-aware functions:
```bash
package_is_installed() {
case "$DETECTED_ID" in
debian|ubuntu)
run_cmd dpkg-query -W -f='${Status}' "$1" | grep -q "install ok installed"
;;
rhel|centos|rocky|almalinux)
run_cmd rpm -q "$1" &>/dev/null
;;
esac
}
```
2. **Update check functions** where Debian and RHEL differ:
- PAM configuration paths differ (`/etc/pam.d/common-password` vs `/etc/pam.d/system-auth`)
- Service names may differ (`rsyslog` is the same, but package names vary)
- Firewall tools may differ (`iptables` vs `firewalld`)
3. **Add RHEL test fixtures** in `testdata/fixtures_rhel/` with RHEL-style config files
**Hints:**
- Start by making `detect_os` set a `DETECTED_FAMILY` variable (`debian` or `rhel`)
- Modify the package and service helpers first since many checks depend on them
- Add RHEL fixture files and tests incrementally, one section at a time
### Challenge 5: Markdown Report
**What to build:**
Add a `markdown` output format that produces a clean Markdown document suitable for pasting into GitHub issues, Confluence pages, or pull request comments.
**Why it's useful:**
Security review findings are often documented in Markdown. A compliance report in Markdown format can be committed to a repository, attached to a pull request, or pasted into a wiki page for review.
**What you'll learn:**
- Markdown table generation
- How to structure a report format for readability in both raw and rendered form
**Hints:**
- Create `src/lib/report_markdown.sh` with an `emit_markdown_report` function
- Use Markdown tables for the section breakdown
- Use collapsible details blocks (`<details><summary>`) for individual control results
- Failed controls should be expanded by default, passing controls collapsed
**Test it works:**
```bash
cisaudit -t testdata/fixtures -f markdown -o report.md
```
### Challenge 6: Parallel Check Execution
**What to build:**
Run independent check functions in parallel using background jobs to reduce audit time on systems with many controls.
**Why it's useful:**
Some checks involve network operations or file scans that take time. Running independent checks in parallel can cut audit time on large systems from minutes to seconds.
**What you'll learn:**
- Bash background jobs (`&`)
- `wait` for job completion
- Handling shared state (result arrays) with parallel writers
- Temporary file-based result collection to avoid race conditions
**Hints:**
- Checks within different sections are independent and can run in parallel
- Checks within the same section may share state and should run sequentially
- Write results to temporary files (one per check) and merge them after all jobs complete
- Use `mktemp -d` for the temporary result directory and clean it up in a trap
**Gotchas:**
- Bash associative arrays cannot be safely written from multiple background jobs
- You will need to serialize results to temporary files and load them in the parent process
---
## Advanced Challenges
### Challenge 7: Auto-Remediation Mode
**What to build:**
Add a `--fix` flag that applies remediation commands for failed controls after confirmation.
**Why it's useful:**
Going from audit report to hardened system currently requires manually running each remediation command. An auto-remediation mode with confirmation prompts turns a 2-hour manual hardening process into a 10-minute guided session.
**What you'll learn:**
- Dangerous operations and confirmation UX
- Idempotent remediation (applying the same fix twice should not break anything)
- Dry-run mode for previewing changes
**Implementation steps:**
1. **Add `--fix` and `--fix-dry-run` flags** to the CLI parser
2. **After running checks**, iterate failed controls and display the remediation command
3. **Prompt the user** for each control: "Apply fix for 1.1.1 (cramfs)? [y/N/a(ll)]"
4. **Execute remediation** with error handling (some commands require root, some may fail)
5. **Re-run the specific check** after applying the fix to verify it passes
6. **Print a summary** of what was fixed and what still needs manual attention
**Gotchas:**
- Some remediation commands are destructive (modifying GRUB config, changing fstab). Always require confirmation.
- Some remediations require a reboot to take effect (kernel parameters set via sysctl.conf)
- Never auto-fix in non-interactive mode (piped input). Check `[[ -t 0 ]]` before prompting.
### Challenge 8: Ansible Playbook Generation
**What to build:**
Add a `--emit-playbook` flag that generates an Ansible playbook to remediate all failed controls.
**Why it's useful:**
In infrastructure-as-code environments, manual remediation does not persist. The next time the server is provisioned from a base image, all hardening is lost. An Ansible playbook captures the remediation as code that can be applied to every server, reviewed in pull requests, and versioned in Git.
**What you'll learn:**
- YAML generation from structured data
- Ansible module selection (sysctl, lineinfile, service, mount, modprobe)
- Idempotent configuration management concepts
**Architecture changes needed:**
```
┌──────────────────────────┐
│ New: playbook_emitter │
│ Reads RESULT_STATUS[] │
│ Maps remediation to │
│ Ansible modules │
│ Outputs YAML playbook │
└──────────────────────────┘
```
**Implementation steps:**
1. **Create a mapping** from CIS control categories to Ansible modules:
- Kernel modules (1.1.x) → `community.general.modprobe`
- Mount options (1.2.x) → `ansible.posix.mount`
- Sysctl parameters (3.x.x) → `ansible.posix.sysctl`
- SSH config (5.2.x) → `ansible.builtin.lineinfile`
- Package removal (2.x.x) → `ansible.builtin.apt` with `state: absent`
- File permissions (6.x.x) → `ansible.builtin.file`
2. **Generate the playbook** with tasks only for failed controls
3. **Include tags** per CIS section so operators can run `ansible-playbook --tags section3` to apply only network hardening
**Hints:**
- Use a heredoc for the playbook header (hosts, become, vars)
- Generate one task per failed control
- Include the CIS control ID in the task name for traceability
### Challenge 9: Configuration Profiles
**What to build:**
Support custom benchmark profiles that override which controls are enabled, their expected values, and their levels.
**Why it's useful:**
Organizations rarely apply the CIS benchmark as-is. A database server might need different SSH settings than a web server. A Docker host cannot disable squashfs. Profiles let teams define "our CIS baseline for web servers" and "our CIS baseline for database servers" as separate configurations.
**What you'll learn:**
- Configuration file parsing in Bash
- Override/inheritance patterns
- Profile composition (base profile + role-specific overrides)
**Implementation approach:**
1. **Define a profile format** (YAML or INI-style config):
```ini
[profile]
name = web-server
base = cis-debian-12-l1
[overrides]
1.1.6 = skip # squashfs needed for snap
1.1.8 = skip # vfat needed for UEFI
5.2.5 = skip # X11 forwarding needed for remote IDE
[thresholds]
overall = 80
section.3 = 90
```
2. **Load the profile** before running checks
3. **Apply overrides** in `should_run_check` to skip or modify controls
4. **Support per-section thresholds** in the exit code logic
---
## Expert Challenges
### Challenge 10: Multi-Host Scanning with SSH
**What to build:**
Add the ability to scan remote hosts over SSH, collecting results from multiple servers and generating a consolidated report.
**Why it's useful:**
A security team managing 200 servers cannot log into each one individually. A multi-host scanner runs the audit remotely, collects JSON results, and produces a fleet-wide compliance dashboard showing which servers are out of compliance and on which specific controls.
**Prerequisites:**
Complete Challenge 4 (RHEL support) first since remote hosts may run different distributions.
**What you'll learn:**
- SSH-based remote command execution
- Parallel remote job management
- Result aggregation from multiple sources
- Fleet-level compliance scoring
**Implementation phases:**
**Phase 1: Remote execution**
- Accept a host list file (`--hosts hosts.txt`)
- SSH to each host, copy cisaudit, run it with `-f json`, and collect the output
- Handle SSH authentication (key-based only, never passwords)
**Phase 2: Result aggregation**
- Parse JSON results from each host
- Compute per-host scores and a fleet-wide average
- Identify controls that fail across multiple hosts (systemic issues)
**Phase 3: Consolidated reporting**
- Generate a fleet report showing per-host scores in a table
- Highlight controls with the highest failure rate across the fleet
- Export as HTML with a host-level drill-down
**Gotchas:**
- SSH connections can fail. Handle timeouts and unreachable hosts gracefully
- Different hosts may have different Bash versions. Ship cisaudit as a self-contained script
- Rate-limit parallel SSH connections to avoid overloading the network or triggering IDS alerts
### Challenge 11: Continuous Compliance Monitoring
**What to build:**
A systemd service and timer that runs cisaudit on a schedule, stores results, and sends alerts when compliance regresses.
**Why it's useful:**
Point-in-time audits catch problems but do not prevent drift. A server that passes CIS today can be misconfigured tomorrow by a package update, a manual change, or a configuration management failure. Continuous monitoring catches drift within hours instead of waiting for the next quarterly audit.
**What you'll learn:**
- systemd service and timer unit files
- Result storage and trend analysis
- Alert integration (email, Slack webhook, syslog)
- Time-series compliance data
**Implementation steps:**
1. **Create a systemd timer** that runs cisaudit daily:
```ini
[Timer]
OnCalendar=daily
Persistent=true
```
2. **Store results** in a directory like `/var/lib/cisaudit/` with timestamped JSON files
3. **Compare against the previous run** using the baseline module
4. **Send alerts** when:
- Overall score drops below a threshold
- A previously passing control starts failing (regression)
- A new control appears with FAIL status
5. **Generate a weekly summary** showing the compliance trend
**Success criteria:**
- [ ] systemd timer runs cisaudit daily
- [ ] Results are stored with timestamps
- [ ] Regressions trigger alerts
- [ ] A CLI command shows the compliance trend over the last 30 days
---
## Security Challenges
### Challenge: Pass CIS Level 2
**The goal:**
Take a fresh Debian 12 installation and use cisaudit to achieve 100% compliance on Level 2.
**Current gaps on a fresh install:**
- Filesystem modules are not disabled
- /tmp is not a separate partition
- Bootloader has no password
- Most services are in default configuration
- Audit rules are not configured
- SSH allows root login
- Password policies use defaults
**Approach:**
1. Run `sudo cisaudit -l 2 -f json -o baseline-fresh.json`
2. Work through each failed control using the remediation commands
3. Re-run after each section to track progress
4. Document which Level 2 controls you had to skip and why
**Watch out for:**
- Disabling vfat breaks UEFI boot on some systems
- Disabling squashfs breaks snap packages
- Setting aggressive password policies can lock you out if you are not careful
- Some audit rules generate large volumes of log data
---
## Real World Integration Challenges
### Integrate with Wazuh
**The goal:**
Send cisaudit results to a Wazuh SIEM for centralized compliance monitoring.
**What you'll need:**
- A Wazuh server (can be deployed with Docker)
- Understanding of Wazuh's log collection and rule engine
**Implementation plan:**
1. Output cisaudit results as syslog-formatted messages
2. Configure Wazuh agent to read cisaudit logs
3. Create Wazuh rules that generate alerts for CIS failures
4. Build a Wazuh dashboard showing compliance posture across hosts
### Integrate with Prometheus/Grafana
**The goal:**
Expose cisaudit scores as Prometheus metrics for visualization in Grafana.
**Implementation plan:**
1. Add a `prometheus` output format that emits metrics in OpenMetrics format
2. Write a textfile collector script that runs cisaudit and writes metrics to `/var/lib/node_exporter/textfile_collector/`
3. Create a Grafana dashboard with compliance gauges per section and a trend line over time
**Metrics to expose:**
```
cisaudit_score_overall{hostname="web01"} 82.5
cisaudit_score_section{section="Initial Setup"} 88.9
cisaudit_controls_pass{hostname="web01"} 72
cisaudit_controls_fail{hostname="web01"} 18
```
---
## Challenge Completion
Track your progress:
- [ ] Easy Challenge 1: CSV Report
- [ ] Easy Challenge 2: Control Count Summary
- [ ] Easy Challenge 3: Color Toggle
- [ ] Intermediate Challenge 4: RHEL/CentOS Support
- [ ] Intermediate Challenge 5: Markdown Report
- [ ] Intermediate Challenge 6: Parallel Execution
- [ ] Advanced Challenge 7: Auto-Remediation
- [ ] Advanced Challenge 8: Ansible Playbook Generation
- [ ] Advanced Challenge 9: Configuration Profiles
- [ ] Expert Challenge 10: Multi-Host SSH Scanning
- [ ] Expert Challenge 11: Continuous Monitoring
- [ ] Security Challenge: Pass CIS Level 2
- [ ] Integration: Wazuh
- [ ] Integration: Prometheus/Grafana
Completed all of them? You have built a production-grade compliance platform. Consider contributing enhancements back to the project or using the patterns you learned to build compliance tooling for other benchmarks (CIS AWS, CIS Kubernetes, CIS Docker).

View File

@ -0,0 +1,469 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 01_initial_setup.sh
_check_module_disabled() {
local id="$1"
local module="$2"
local status="$STATUS_PASS"
local evidence=""
local modprobe_conf="${SYSROOT}/etc/modprobe.d/${module}.conf"
if run_cmd lsmod | grep -q "^${module} "; then
status="$STATUS_FAIL"
evidence="${module} module is currently loaded"
elif [[ -f "$modprobe_conf" ]] && grep -q "install ${module} /bin/true\|install ${module} /bin/false" "$modprobe_conf"; then
evidence="${module} disabled via ${modprobe_conf}"
elif run_cmd modprobe -n -v "$module" 2>/dev/null | grep -q "install /bin/true\|install /bin/false"; then
evidence="${module} disabled via modprobe config"
else
local found_disabled="false"
for conf in "${SYSROOT}"/etc/modprobe.d/*.conf; do
[[ -f "$conf" ]] || continue
if grep -q "install ${module} /bin/true\|install ${module} /bin/false\|blacklist ${module}" "$conf"; then
found_disabled="true"
evidence="${module} disabled via ${conf}"
break
fi
done
if [[ "$found_disabled" == "false" ]]; then
if [[ "$SYSROOT" != "/" ]]; then
status="$STATUS_FAIL"
evidence="No modprobe config found disabling ${module}"
else
status="$STATUS_FAIL"
evidence="${module} is not disabled"
fi
fi
fi
record_result "$id" "$status" "$evidence"
}
check_1_1_1() { _check_module_disabled "1.1.1" "cramfs"; }
check_1_1_2() { _check_module_disabled "1.1.2" "freevxfs"; }
check_1_1_3() { _check_module_disabled "1.1.3" "jffs2"; }
check_1_1_4() { _check_module_disabled "1.1.4" "hfs"; }
check_1_1_5() { _check_module_disabled "1.1.5" "hfsplus"; }
check_1_1_6() { _check_module_disabled "1.1.6" "squashfs"; }
check_1_1_7() { _check_module_disabled "1.1.7" "udf"; }
check_1_1_8() { _check_module_disabled "1.1.8" "vfat"; }
check_1_2_1() {
local id="1.2.1"
local status="$STATUS_PASS"
local evidence=""
local fstab_content
fstab_content=$(read_file "/etc/fstab" 2>/dev/null) || true
if [[ -n "$fstab_content" ]]; then
local tmp_line
tmp_line=$(echo "$fstab_content" | grep -E '\s/tmp\s' || true)
if [[ -n "$tmp_line" ]]; then
evidence="/tmp is a separate partition in fstab"
else
status="$STATUS_FAIL"
evidence="/tmp is not configured as a separate partition in fstab"
fi
elif run_cmd findmnt -n /tmp > /dev/null 2>&1; then
evidence="/tmp is a separate partition (findmnt)"
else
status="$STATUS_FAIL"
evidence="/tmp is not configured as a separate partition"
fi
record_result "$id" "$status" "$evidence"
}
_check_tmp_mount_option() {
local id="$1"
local option="$2"
local status="$STATUS_PASS"
local evidence=""
local fstab_content
fstab_content=$(read_file "/etc/fstab" 2>/dev/null) || true
local options=""
if [[ -n "$fstab_content" ]]; then
local tmp_line
tmp_line=$(echo "$fstab_content" | grep -E '\s/tmp\s' || true)
if [[ -n "$tmp_line" ]]; then
options=$(echo "$tmp_line" | awk '{print $4}')
fi
fi
if [[ -z "$options" ]]; then
options=$(run_cmd findmnt -n -o OPTIONS /tmp 2>/dev/null) || true
fi
if [[ -z "$options" ]]; then
status="$STATUS_SKIP"
evidence="/tmp partition not found or not accessible"
elif echo "$options" | grep -q "$option"; then
evidence="${option} is set on /tmp (${options})"
else
status="$STATUS_FAIL"
evidence="${option} is not set on /tmp (${options})"
fi
record_result "$id" "$status" "$evidence"
}
check_1_2_2() { _check_tmp_mount_option "1.2.2" "noexec"; }
check_1_2_3() { _check_tmp_mount_option "1.2.3" "nosuid"; }
check_1_2_4() { _check_tmp_mount_option "1.2.4" "nodev"; }
check_1_3_1() {
local id="1.3.1"
local status="$STATUS_PASS"
local evidence=""
local sources_list="${SYSROOT}/etc/apt/sources.list"
local sources_dir="${SYSROOT}/etc/apt/sources.list.d"
local found_repos="false"
if [[ -f "$sources_list" ]]; then
local active_lines
active_lines=$(grep -cE '^\s*deb\s' "$sources_list" 2>/dev/null) || true
if [[ "$active_lines" -gt 0 ]]; then
found_repos="true"
evidence="Found ${active_lines} repo(s) in sources.list"
fi
fi
if [[ -d "$sources_dir" ]]; then
local source_files
source_files=$(find "$sources_dir" -maxdepth 1 -name "*.list" -o -name "*.sources" 2>/dev/null | head -20) || true
if [[ -n "$source_files" ]]; then
local file_count
file_count=$(echo "$source_files" | wc -l)
found_repos="true"
if [[ -n "$evidence" ]]; then
evidence="${evidence}; ${file_count} source file(s) in sources.list.d"
else
evidence="${file_count} source file(s) in sources.list.d"
fi
fi
fi
if [[ "$found_repos" == "false" ]]; then
status="$STATUS_FAIL"
evidence="No package repositories configured"
fi
record_result "$id" "$status" "$evidence"
}
check_1_3_2() {
local id="1.3.2"
local status="$STATUS_PASS"
local evidence=""
local trusted_dir="${SYSROOT}/etc/apt/trusted.gpg.d"
local keyrings_dir="${SYSROOT}/etc/apt/keyrings"
local found_keys="false"
if [[ -d "$trusted_dir" ]]; then
local key_files
key_files=$(find "$trusted_dir" -maxdepth 1 -name "*.gpg" -o -name "*.asc" 2>/dev/null | head -20) || true
if [[ -n "$key_files" ]]; then
local key_count
key_count=$(echo "$key_files" | wc -l)
found_keys="true"
evidence="${key_count} GPG key(s) in trusted.gpg.d"
fi
fi
if [[ -d "$keyrings_dir" ]]; then
local keyring_files
keyring_files=$(find "$keyrings_dir" -maxdepth 1 -name "*.gpg" -o -name "*.asc" 2>/dev/null | head -20) || true
if [[ -n "$keyring_files" ]]; then
local ring_count
ring_count=$(echo "$keyring_files" | wc -l)
found_keys="true"
if [[ -n "$evidence" ]]; then
evidence="${evidence}; ${ring_count} keyring(s) in apt/keyrings"
else
evidence="${ring_count} keyring(s) in apt/keyrings"
fi
fi
fi
if [[ "$found_keys" == "false" ]]; then
local apt_key_output
if apt_key_output=$(run_cmd apt-key list 2>/dev/null) && [[ -n "$apt_key_output" ]]; then
found_keys="true"
evidence="GPG keys found via apt-key"
fi
fi
if [[ "$found_keys" == "false" ]]; then
status="$STATUS_FAIL"
evidence="No GPG keys configured for package verification"
fi
record_result "$id" "$status" "$evidence"
}
check_1_4_1() {
local id="1.4.1"
local status="$STATUS_PASS"
local evidence=""
local grub_dir="${SYSROOT}/etc/grub.d"
local grub_default="${SYSROOT}/etc/default/grub"
local found_password="false"
if [[ -d "$grub_dir" ]]; then
for grub_file in "${grub_dir}"/*; do
[[ -f "$grub_file" ]] || continue
if grep -q "password" "$grub_file" 2>/dev/null; then
found_password="true"
evidence="Bootloader password set in ${grub_file}"
break
fi
done
fi
if [[ "$found_password" == "false" && -f "$grub_default" ]]; then
if grep -q "GRUB_PASSWORD\|GRUB_USERS" "$grub_default" 2>/dev/null; then
found_password="true"
evidence="Bootloader password configured in /etc/default/grub"
fi
fi
if [[ "$found_password" == "false" ]]; then
local grub_cfg="${SYSROOT}/boot/grub/grub.cfg"
if [[ -f "$grub_cfg" ]]; then
if grep -q "password_pbkdf2\|password " "$grub_cfg" 2>/dev/null; then
found_password="true"
evidence="Bootloader password found in grub.cfg"
fi
fi
fi
if [[ "$found_password" == "false" ]]; then
status="$STATUS_FAIL"
evidence="Bootloader password is not set"
fi
record_result "$id" "$status" "$evidence"
}
check_1_4_2() {
local id="1.4.2"
local status="$STATUS_PASS"
local evidence=""
local grub_cfg="${SYSROOT}/boot/grub/grub.cfg"
if [[ ! -f "$grub_cfg" ]]; then
status="$STATUS_SKIP"
evidence="/boot/grub/grub.cfg not found"
record_result "$id" "$status" "$evidence"
return
fi
local file_stat
if file_stat=$(run_cmd stat -c '%a %U %G' "$grub_cfg" 2>/dev/null); then
local perms owner group
perms=$(echo "$file_stat" | awk '{print $1}')
owner=$(echo "$file_stat" | awk '{print $2}')
group=$(echo "$file_stat" | awk '{print $3}')
if [[ "$owner" != "root" || "$group" != "root" ]]; then
status="$STATUS_FAIL"
evidence="grub.cfg owned by ${owner}:${group} (expected root:root)"
elif (( 8#$perms > 8#0600 )); then
status="$STATUS_FAIL"
evidence="grub.cfg permissions ${perms} (expected 600 or more restrictive)"
else
evidence="grub.cfg permissions ${perms}, owned by ${owner}:${group}"
fi
else
local ls_output
ls_output=$(ls -l "$grub_cfg" 2>/dev/null) || true
if [[ -n "$ls_output" ]]; then
local perm_str
perm_str=$(echo "$ls_output" | awk '{print $1}')
local file_owner
file_owner=$(echo "$ls_output" | awk '{print $3}')
local file_group
file_group=$(echo "$ls_output" | awk '{print $4}')
if [[ "$file_owner" != "root" || "$file_group" != "root" ]]; then
status="$STATUS_FAIL"
evidence="grub.cfg owned by ${file_owner}:${file_group} (expected root:root)"
elif echo "$perm_str" | grep -q "......r\|.......w\|........x"; then
status="$STATUS_FAIL"
evidence="grub.cfg has excessive permissions (${perm_str})"
else
evidence="grub.cfg permissions ${perm_str}, owned by ${file_owner}:${file_group}"
fi
else
status="$STATUS_SKIP"
evidence="Unable to determine grub.cfg permissions"
fi
fi
record_result "$id" "$status" "$evidence"
}
check_1_4_3() {
local id="1.4.3"
local status="$STATUS_PASS"
local evidence=""
local rescue_service="${SYSROOT}/usr/lib/systemd/system/rescue.service"
local emergency_service="${SYSROOT}/usr/lib/systemd/system/emergency.service"
local found_sulogin="false"
if [[ -f "$rescue_service" ]]; then
if grep -q "sulogin" "$rescue_service" 2>/dev/null; then
found_sulogin="true"
evidence="sulogin required for rescue mode"
fi
fi
if [[ -f "$emergency_service" ]]; then
if grep -q "sulogin" "$emergency_service" 2>/dev/null; then
if [[ "$found_sulogin" == "true" ]]; then
evidence="sulogin required for rescue and emergency modes"
else
found_sulogin="true"
evidence="sulogin required for emergency mode"
fi
fi
fi
if [[ "$found_sulogin" == "false" ]]; then
local inittab="${SYSROOT}/etc/inittab"
if [[ -f "$inittab" ]]; then
if grep -q "sulogin" "$inittab" 2>/dev/null; then
found_sulogin="true"
evidence="sulogin required via /etc/inittab"
fi
fi
fi
if [[ "$found_sulogin" == "false" ]]; then
local override_rescue="${SYSROOT}/etc/systemd/system/rescue.service.d"
local override_emergency="${SYSROOT}/etc/systemd/system/emergency.service.d"
for override_dir in "$override_rescue" "$override_emergency"; do
[[ -d "$override_dir" ]] || continue
for override_file in "${override_dir}"/*.conf; do
[[ -f "$override_file" ]] || continue
if grep -q "sulogin" "$override_file" 2>/dev/null; then
found_sulogin="true"
evidence="sulogin required via systemd override"
break 2
fi
done
done
fi
if [[ "$found_sulogin" == "false" ]]; then
status="$STATUS_FAIL"
evidence="Authentication not required for single-user mode"
fi
record_result "$id" "$status" "$evidence"
}
check_1_5_1() {
local id="1.5.1"
local status="$STATUS_PASS"
local evidence=""
local aslr_value
aslr_value=$(get_sysctl "kernel.randomize_va_space") || true
if [[ -z "$aslr_value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to determine ASLR status"
elif [[ "$aslr_value" == "2" ]]; then
evidence="ASLR is fully enabled (kernel.randomize_va_space = 2)"
elif [[ "$aslr_value" == "1" ]]; then
status="$STATUS_WARN"
evidence="ASLR is partially enabled (kernel.randomize_va_space = 1, expected 2)"
else
status="$STATUS_FAIL"
evidence="ASLR is disabled (kernel.randomize_va_space = ${aslr_value}, expected 2)"
fi
record_result "$id" "$status" "$evidence"
}
check_1_5_2() {
local id="1.5.2"
local status="$STATUS_PASS"
local evidence=""
local limits_ok="false"
local sysctl_ok="false"
local limits_file="${SYSROOT}/etc/security/limits.conf"
local limits_dir="${SYSROOT}/etc/security/limits.d"
if [[ -f "$limits_file" ]]; then
if grep -qE '^\s*\*\s+hard\s+core\s+0' "$limits_file" 2>/dev/null; then
limits_ok="true"
fi
fi
if [[ "$limits_ok" == "false" && -d "$limits_dir" ]]; then
for lconf in "${limits_dir}"/*.conf; do
[[ -f "$lconf" ]] || continue
if grep -qE '^\s*\*\s+hard\s+core\s+0' "$lconf" 2>/dev/null; then
limits_ok="true"
break
fi
done
fi
local dumpable
dumpable=$(get_sysctl "fs.suid_dumpable") || true
if [[ "$dumpable" == "0" ]]; then
sysctl_ok="true"
fi
if [[ "$limits_ok" == "true" && "$sysctl_ok" == "true" ]]; then
evidence="Core dumps restricted (limits.conf + fs.suid_dumpable = 0)"
elif [[ "$limits_ok" == "true" && "$sysctl_ok" == "false" ]]; then
status="$STATUS_FAIL"
evidence="Core limit set but fs.suid_dumpable = ${dumpable:-unknown} (expected 0)"
elif [[ "$limits_ok" == "false" && "$sysctl_ok" == "true" ]]; then
status="$STATUS_FAIL"
evidence="fs.suid_dumpable = 0 but hard core 0 not set in limits.conf"
else
status="$STATUS_FAIL"
evidence="Core dumps not restricted (missing limits.conf and sysctl settings)"
fi
record_result "$id" "$status" "$evidence"
}
check_1_5_3() {
local id="1.5.3"
local status="$STATUS_PASS"
local evidence=""
if run_cmd dpkg-query -W prelink > /dev/null 2>&1; then
status="$STATUS_FAIL"
evidence="prelink is installed"
else
local prelink_bin="${SYSROOT}/usr/sbin/prelink"
if [[ -f "$prelink_bin" ]]; then
status="$STATUS_FAIL"
evidence="prelink binary found at /usr/sbin/prelink"
else
evidence="prelink is not installed"
fi
fi
record_result "$id" "$status" "$evidence"
}

View File

@ -0,0 +1,428 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 02_services.sh
check_2_1_1() {
local id="2.1.1"
local status="$STATUS_PASS"
local evidence=""
local pkg="xinetd"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/etc/xinetd.conf" || file_exists "/etc/xinetd.d"; then
status="$STATUS_FAIL"
evidence="${pkg} configuration found at /etc/xinetd.conf"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_1_2() {
local id="2.1.2"
local status="$STATUS_PASS"
local evidence=""
local pkg="openbsd-inetd"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/etc/inetd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} configuration found at /etc/inetd.conf"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_1() {
local id="2.2.1"
local status="$STATUS_PASS"
local evidence=""
local pkg="xserver-xorg"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/bin/X" || file_exists "/usr/bin/Xorg"; then
status="$STATUS_FAIL"
evidence="X Window System binary found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_2() {
local id="2.2.2"
local status="$STATUS_PASS"
local evidence=""
local pkg="avahi-daemon"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/avahi-daemon" || file_exists "/etc/avahi/avahi-daemon.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_3() {
local id="2.2.3"
local status="$STATUS_PASS"
local evidence=""
local pkg="cups"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/cupsd" || file_exists "/etc/cups/cupsd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_4() {
local id="2.2.4"
local status="$STATUS_PASS"
local evidence=""
local pkg="isc-dhcp-server"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/dhcpd" || file_exists "/etc/dhcp/dhcpd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_5() {
local id="2.2.5"
local status="$STATUS_PASS"
local evidence=""
local pkg="slapd"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/slapd" || file_exists "/etc/ldap/slapd.d"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_6() {
local id="2.2.6"
local status="$STATUS_PASS"
local evidence=""
local pkg="nfs-kernel-server"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/rpc.nfsd" || file_exists "/etc/exports"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_7() {
local id="2.2.7"
local status="$STATUS_PASS"
local evidence=""
local pkg="bind9"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/named" || file_exists "/etc/bind/named.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_8() {
local id="2.2.8"
local status="$STATUS_PASS"
local evidence=""
local pkg="vsftpd"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/vsftpd" || file_exists "/etc/vsftpd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_9() {
local id="2.2.9"
local status="$STATUS_PASS"
local evidence=""
local installed=""
if package_is_installed "apache2"; then
installed="apache2"
elif package_is_installed "nginx"; then
installed="nginx"
elif file_exists "/usr/sbin/apache2" || file_exists "/etc/apache2/apache2.conf"; then
installed="apache2"
elif file_exists "/usr/sbin/nginx" || file_exists "/etc/nginx/nginx.conf"; then
installed="nginx"
fi
if [[ -n "$installed" ]]; then
status="$STATUS_FAIL"
evidence="${installed} is installed"
else
evidence="No HTTP server is installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_10() {
local id="2.2.10"
local status="$STATUS_PASS"
local evidence=""
local installed=""
if package_is_installed "dovecot-imapd"; then
installed="dovecot-imapd"
fi
if package_is_installed "dovecot-pop3d"; then
if [[ -n "$installed" ]]; then
installed="${installed} and dovecot-pop3d"
else
installed="dovecot-pop3d"
fi
fi
if [[ -z "$installed" ]]; then
if file_exists "/usr/sbin/dovecot" || file_exists "/etc/dovecot/dovecot.conf"; then
installed="dovecot"
fi
fi
if [[ -n "$installed" ]]; then
status="$STATUS_FAIL"
evidence="${installed} is installed"
else
evidence="No IMAP or POP3 server is installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_11() {
local id="2.2.11"
local status="$STATUS_PASS"
local evidence=""
local pkg="samba"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/smbd" || file_exists "/etc/samba/smb.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_12() {
local id="2.2.12"
local status="$STATUS_PASS"
local evidence=""
local pkg="squid"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/squid" || file_exists "/etc/squid/squid.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_13() {
local id="2.2.13"
local status="$STATUS_PASS"
local evidence=""
local pkg="snmpd"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/snmpd" || file_exists "/etc/snmp/snmpd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_14() {
local id="2.2.14"
local status="$STATUS_PASS"
local evidence=""
local pkg="nis"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif file_exists "/usr/sbin/ypserv" || file_exists "/etc/yp.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary or configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_2_2_15() {
local id="2.2.15"
local status="$STATUS_PASS"
local evidence=""
local listening_external=""
if run_cmd ss -lntp | grep -qE ':25\s' 2>/dev/null; then
local listeners
listeners=$(run_cmd ss -lntp | grep -E ':25\s' 2>/dev/null) || true
if echo "$listeners" | grep -qvE '127\.0\.0\.1:25|::1:25|\[::1\]:25|\*:25'; then
local bound_addrs
bound_addrs=$(echo "$listeners" | awk '{print $4}')
if echo "$bound_addrs" | grep -qvE '^127\.0\.0\.1:|^\[::1\]:|^::1:'; then
listening_external="true"
fi
fi
fi
if [[ "$listening_external" == "true" ]]; then
status="$STATUS_FAIL"
evidence="MTA is listening on non-loopback interface on port 25"
record_result "$id" "$status" "$evidence"
return
fi
local main_cf
main_cf=$(read_file "/etc/postfix/main.cf" 2>/dev/null) || true
if [[ -n "$main_cf" ]]; then
local inet_interfaces
inet_interfaces=$(echo "$main_cf" | grep -Ei '^\s*inet_interfaces\s*=' | tail -1 | awk -F= '{print $2}' | tr -d ' ') || true
if [[ -z "$inet_interfaces" ]]; then
status="$STATUS_FAIL"
evidence="Postfix inet_interfaces not configured (defaults to all)"
elif [[ "$inet_interfaces" == "loopback-only" || "$inet_interfaces" == "localhost" || "$inet_interfaces" == "127.0.0.1" ]]; then
evidence="Postfix configured for local-only (inet_interfaces = ${inet_interfaces})"
else
status="$STATUS_FAIL"
evidence="Postfix inet_interfaces = ${inet_interfaces} (expected loopback-only or localhost)"
fi
record_result "$id" "$status" "$evidence"
return
fi
local exim_conf
exim_conf=$(read_file "/etc/exim4/update-exim4.conf.conf" 2>/dev/null) || true
if [[ -n "$exim_conf" ]]; then
local listen_addrs
listen_addrs=$(echo "$exim_conf" | grep -Ei '^\s*dc_local_interfaces' | tail -1 | awk -F= "'{print \$2}'" | tr -d "' ") || true
if [[ -z "$listen_addrs" || "$listen_addrs" == "127.0.0.1;::1" || "$listen_addrs" == "127.0.0.1" ]]; then
evidence="Exim configured for local-only (dc_local_interfaces = ${listen_addrs:-127.0.0.1;::1})"
else
status="$STATUS_FAIL"
evidence="Exim dc_local_interfaces = ${listen_addrs} (expected 127.0.0.1;::1)"
fi
record_result "$id" "$status" "$evidence"
return
fi
if file_exists "/usr/sbin/sendmail" || file_exists "/usr/lib/sendmail"; then
status="$STATUS_WARN"
evidence="Sendmail detected but configuration not checked in test mode"
record_result "$id" "$status" "$evidence"
return
fi
evidence="No MTA detected or MTA not listening on port 25"
record_result "$id" "$status" "$evidence"
}
check_2_2_16() {
local id="2.2.16"
local status="$STATUS_PASS"
local evidence=""
local pkg="rsync"
if package_is_installed "$pkg"; then
status="$STATUS_FAIL"
evidence="${pkg} is installed"
elif service_is_enabled "rsync"; then
status="$STATUS_FAIL"
evidence="rsync service is enabled"
elif file_exists "/usr/bin/rsync" && file_exists "/etc/rsyncd.conf"; then
status="$STATUS_FAIL"
evidence="${pkg} binary and daemon configuration found"
else
evidence="${pkg} is not installed"
fi
record_result "$id" "$status" "$evidence"
}

View File

@ -0,0 +1,448 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 03_network.sh
check_3_1_1() {
local id="3.1.1"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.ip_forward") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.ip_forward"
elif [[ "$value" != "0" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.ip_forward = ${value} (expected 0)"
else
evidence="IP forwarding is disabled (net.ipv4.ip_forward = 0)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_1_2() {
local id="3.1.2"
local status="$STATUS_PASS"
local evidence=""
local val_all val_default
val_all=$(get_sysctl "net.ipv4.conf.all.send_redirects") || true
val_default=$(get_sysctl "net.ipv4.conf.default.send_redirects") || true
if [[ -z "$val_all" && -z "$val_default" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read send_redirects sysctl values"
elif [[ "$val_all" != "0" || "$val_default" != "0" ]]; then
status="$STATUS_FAIL"
evidence="send_redirects: all=${val_all:-unset} default=${val_default:-unset} (expected 0)"
else
evidence="Packet redirect sending disabled (all=0, default=0)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_1_3() {
local id="3.1.3"
local status="$STATUS_PASS"
local evidence=""
local val_all val_default
val_all=$(get_sysctl "net.ipv4.conf.all.accept_source_route") || true
val_default=$(get_sysctl "net.ipv4.conf.default.accept_source_route") || true
if [[ -z "$val_all" && -z "$val_default" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read accept_source_route sysctl values"
elif [[ "$val_all" != "0" || "$val_default" != "0" ]]; then
status="$STATUS_FAIL"
evidence="accept_source_route: all=${val_all:-unset} default=${val_default:-unset} (expected 0)"
else
evidence="Source routed packets not accepted (all=0, default=0)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_1_4() {
local id="3.1.4"
local status="$STATUS_PASS"
local evidence=""
local val_all val_default
val_all=$(get_sysctl "net.ipv4.conf.all.accept_redirects") || true
val_default=$(get_sysctl "net.ipv4.conf.default.accept_redirects") || true
if [[ -z "$val_all" && -z "$val_default" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read accept_redirects sysctl values"
elif [[ "$val_all" != "0" || "$val_default" != "0" ]]; then
status="$STATUS_FAIL"
evidence="accept_redirects: all=${val_all:-unset} default=${val_default:-unset} (expected 0)"
else
evidence="ICMP redirects not accepted (all=0, default=0)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_1() {
local id="3.2.1"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.conf.all.log_martians") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.conf.all.log_martians"
elif [[ "$value" != "1" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.conf.all.log_martians = ${value} (expected 1)"
else
evidence="Suspicious packets are logged (net.ipv4.conf.all.log_martians = 1)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_2() {
local id="3.2.2"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.icmp_echo_ignore_broadcasts") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.icmp_echo_ignore_broadcasts"
elif [[ "$value" != "1" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.icmp_echo_ignore_broadcasts = ${value} (expected 1)"
else
evidence="Broadcast ICMP requests ignored (net.ipv4.icmp_echo_ignore_broadcasts = 1)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_3() {
local id="3.2.3"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.icmp_ignore_bogus_error_responses") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.icmp_ignore_bogus_error_responses"
elif [[ "$value" != "1" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.icmp_ignore_bogus_error_responses = ${value} (expected 1)"
else
evidence="Bogus ICMP responses ignored (net.ipv4.icmp_ignore_bogus_error_responses = 1)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_4() {
local id="3.2.4"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.conf.all.rp_filter") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.conf.all.rp_filter"
elif [[ "$value" != "1" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.conf.all.rp_filter = ${value} (expected 1)"
else
evidence="Reverse Path Filtering enabled (net.ipv4.conf.all.rp_filter = 1)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_5() {
local id="3.2.5"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv4.tcp_syncookies") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv4.tcp_syncookies"
elif [[ "$value" != "1" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv4.tcp_syncookies = ${value} (expected 1)"
else
evidence="TCP SYN Cookies enabled (net.ipv4.tcp_syncookies = 1)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_2_6() {
local id="3.2.6"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_sysctl "net.ipv6.conf.all.accept_ra") || true
if [[ -z "$value" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read net.ipv6.conf.all.accept_ra"
elif [[ "$value" != "0" ]]; then
status="$STATUS_FAIL"
evidence="net.ipv6.conf.all.accept_ra = ${value} (expected 0)"
else
evidence="IPv6 router advertisements not accepted (net.ipv6.conf.all.accept_ra = 0)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_3_1() {
local id="3.3.1"
local status="$STATUS_PASS"
local evidence=""
if package_is_installed "iptables"; then
evidence="iptables package is installed"
elif file_exists "/usr/sbin/iptables"; then
evidence="iptables binary found at /usr/sbin/iptables"
else
status="$STATUS_FAIL"
evidence="iptables is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_3_3_2() {
local id="3.3.2"
local status="$STATUS_PASS"
local evidence=""
local policy=""
local iptables_output
if iptables_output=$(run_cmd iptables -L INPUT -n 2>/dev/null); then
policy=$(echo "$iptables_output" | head -1 | grep -oP 'policy \K\w+') || true
fi
if [[ -z "$policy" ]]; then
local rules_file="${SYSROOT}/etc/iptables/rules.v4"
if [[ -f "$rules_file" ]]; then
policy=$(grep -E '^\s*:INPUT\s' "$rules_file" | awk '{print $2}') || true
fi
fi
if [[ -z "$policy" ]]; then
status="$STATUS_SKIP"
evidence="Unable to determine INPUT chain policy"
elif [[ "$policy" == "DROP" || "$policy" == "REJECT" ]]; then
evidence="INPUT chain default policy is ${policy}"
else
status="$STATUS_FAIL"
evidence="INPUT chain default policy is ${policy} (expected DROP or REJECT)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_3_3() {
local id="3.3.3"
local status="$STATUS_PASS"
local evidence=""
local policy=""
local iptables_output
if iptables_output=$(run_cmd iptables -L FORWARD -n 2>/dev/null); then
policy=$(echo "$iptables_output" | head -1 | grep -oP 'policy \K\w+') || true
fi
if [[ -z "$policy" ]]; then
local rules_file="${SYSROOT}/etc/iptables/rules.v4"
if [[ -f "$rules_file" ]]; then
policy=$(grep -E '^\s*:FORWARD\s' "$rules_file" | awk '{print $2}') || true
fi
fi
if [[ -z "$policy" ]]; then
status="$STATUS_SKIP"
evidence="Unable to determine FORWARD chain policy"
elif [[ "$policy" == "DROP" || "$policy" == "REJECT" ]]; then
evidence="FORWARD chain default policy is ${policy}"
else
status="$STATUS_FAIL"
evidence="FORWARD chain default policy is ${policy} (expected DROP or REJECT)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_3_4() {
local id="3.3.4"
local status="$STATUS_PASS"
local evidence=""
local policy=""
local iptables_output
if iptables_output=$(run_cmd iptables -L OUTPUT -n 2>/dev/null); then
policy=$(echo "$iptables_output" | head -1 | grep -oP 'policy \K\w+') || true
fi
if [[ -z "$policy" ]]; then
local rules_file="${SYSROOT}/etc/iptables/rules.v4"
if [[ -f "$rules_file" ]]; then
policy=$(grep -E '^\s*:OUTPUT\s' "$rules_file" | awk '{print $2}') || true
fi
fi
if [[ -z "$policy" ]]; then
status="$STATUS_SKIP"
evidence="Unable to determine OUTPUT chain policy"
elif [[ "$policy" == "DROP" || "$policy" == "REJECT" ]]; then
evidence="OUTPUT chain default policy is ${policy}"
else
status="$STATUS_FAIL"
evidence="OUTPUT chain default policy is ${policy} (expected DROP or REJECT)"
fi
record_result "$id" "$status" "$evidence"
}
check_3_3_5() {
local id="3.3.5"
local status="$STATUS_PASS"
local evidence=""
if [[ "$SYSROOT" != "/" ]]; then
status="$STATUS_SKIP"
evidence="Firewall rule coverage requires live system (test mode)"
record_result "$id" "$status" "$evidence"
return
fi
local open_ports
open_ports=$(run_cmd ss -tlnp 2>/dev/null | awk 'NR>1 {print $4}' | grep -oP '\d+$' | sort -un) || true
if [[ -z "$open_ports" ]]; then
evidence="No open TCP ports detected"
record_result "$id" "$status" "$evidence"
return
fi
local iptables_rules
iptables_rules=$(run_cmd iptables -L INPUT -n 2>/dev/null) || true
if [[ -z "$iptables_rules" ]]; then
status="$STATUS_SKIP"
evidence="Unable to read iptables INPUT rules"
record_result "$id" "$status" "$evidence"
return
fi
local uncovered=""
local port
for port in $open_ports; do
if ! echo "$iptables_rules" | grep -q "dpt:${port}\b"; then
if [[ -n "$uncovered" ]]; then
uncovered="${uncovered}, ${port}"
else
uncovered="${port}"
fi
fi
done
if [[ -n "$uncovered" ]]; then
status="$STATUS_FAIL"
evidence="Open ports without firewall rules: ${uncovered}"
else
evidence="All open ports have matching firewall rules"
fi
record_result "$id" "$status" "$evidence"
}
check_3_4_1() {
local id="3.4.1"
local status="$STATUS_PASS"
local evidence=""
if [[ "$SYSROOT" != "/" ]]; then
status="$STATUS_SKIP"
evidence="Wireless interface check requires live system (test mode)"
record_result "$id" "$status" "$evidence"
return
fi
local wireless_ifaces
wireless_ifaces=$(run_cmd ip link show 2>/dev/null | grep -oP '^\d+:\s+\Kwlan\S+') || true
if [[ -n "$wireless_ifaces" ]]; then
local all_blocked="true"
if run_cmd rfkill list wifi 2>/dev/null | grep -q "Soft blocked: yes"; then
evidence="Wireless interfaces found but blocked via rfkill"
else
all_blocked="false"
fi
if [[ "$all_blocked" == "false" ]]; then
status="$STATUS_FAIL"
evidence="Active wireless interfaces found: ${wireless_ifaces}"
fi
else
evidence="No wireless interfaces detected"
fi
record_result "$id" "$status" "$evidence"
}
_check_protocol_module_disabled() {
local id="$1"
local module="$2"
local status="$STATUS_PASS"
local evidence=""
local found_disabled="false"
for conf in "${SYSROOT}"/etc/modprobe.d/*.conf; do
[[ -f "$conf" ]] || continue
if grep -q "install ${module} /bin/true\|install ${module} /bin/false\|blacklist ${module}" "$conf"; then
found_disabled="true"
evidence="${module} disabled via ${conf}"
break
fi
done
if [[ "$found_disabled" == "false" ]]; then
if run_cmd lsmod | grep -q "^${module} "; then
status="$STATUS_FAIL"
evidence="${module} module is loaded"
else
status="$STATUS_FAIL"
evidence="No modprobe config found disabling ${module}"
fi
fi
record_result "$id" "$status" "$evidence"
}
check_3_4_2() { _check_protocol_module_disabled "3.4.2" "dccp"; }
check_3_4_3() { _check_protocol_module_disabled "3.4.3" "sctp"; }
check_3_4_4() { _check_protocol_module_disabled "3.4.4" "rds"; }
check_3_4_5() { _check_protocol_module_disabled "3.4.5" "tipc"; }

View File

@ -0,0 +1,364 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 04_logging.sh
check_4_1_1() {
local id="4.1.1"
local status="$STATUS_PASS"
local evidence=""
if package_is_installed "auditd"; then
evidence="auditd package is installed"
elif file_exists "/usr/sbin/auditd"; then
evidence="auditd binary found at /usr/sbin/auditd"
else
status="$STATUS_FAIL"
evidence="auditd is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_2() {
local id="4.1.2"
local status="$STATUS_PASS"
local evidence=""
if service_is_enabled "auditd"; then
evidence="auditd service is enabled"
else
local symlink="${SYSROOT}/etc/systemd/system/multi-user.target.wants/auditd.service"
if [[ -L "$symlink" || -f "$symlink" ]]; then
evidence="auditd enabled via systemd symlink"
else
status="$STATUS_FAIL"
evidence="auditd service is not enabled"
fi
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_3() {
local id="4.1.3"
local status="$STATUS_PASS"
local evidence=""
local grub_default="${SYSROOT}/etc/default/grub"
if [[ ! -f "$grub_default" ]]; then
status="$STATUS_SKIP"
evidence="/etc/default/grub not found"
record_result "$id" "$status" "$evidence"
return
fi
local cmdline
cmdline=$(grep -E '^\s*GRUB_CMDLINE_LINUX=' "$grub_default" | tail -1) || true
if [[ -z "$cmdline" ]]; then
status="$STATUS_FAIL"
evidence="GRUB_CMDLINE_LINUX not configured"
elif echo "$cmdline" | grep -q 'audit=1'; then
evidence="Pre-auditd auditing enabled (audit=1 in GRUB_CMDLINE_LINUX)"
else
status="$STATUS_FAIL"
evidence="audit=1 not found in GRUB_CMDLINE_LINUX"
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_4() {
local id="4.1.4"
local status="$STATUS_PASS"
local evidence=""
local grub_default="${SYSROOT}/etc/default/grub"
if [[ ! -f "$grub_default" ]]; then
status="$STATUS_SKIP"
evidence="/etc/default/grub not found"
record_result "$id" "$status" "$evidence"
return
fi
local cmdline
cmdline=$(grep -E '^\s*GRUB_CMDLINE_LINUX=' "$grub_default" | tail -1) || true
if [[ -z "$cmdline" ]]; then
status="$STATUS_FAIL"
evidence="GRUB_CMDLINE_LINUX not configured"
elif echo "$cmdline" | grep -qE 'audit_backlog_limit=[0-9]+'; then
local limit
limit=$(echo "$cmdline" | grep -oE 'audit_backlog_limit=[0-9]+' | cut -d= -f2)
if (( limit >= 8192 )); then
evidence="Audit backlog limit is sufficient (${limit})"
else
status="$STATUS_FAIL"
evidence="Audit backlog limit is ${limit} (expected >= 8192)"
fi
else
status="$STATUS_FAIL"
evidence="audit_backlog_limit not found in GRUB_CMDLINE_LINUX"
fi
record_result "$id" "$status" "$evidence"
}
_check_audit_rules() {
local id="$1"
shift
local description="$1"
shift
local search_patterns=("$@")
local status="$STATUS_PASS"
local evidence=""
local rules_dir="${SYSROOT}/etc/audit/rules.d"
local audit_rules="${SYSROOT}/etc/audit/audit.rules"
local missing=()
for pattern in "${search_patterns[@]}"; do
local found="false"
if [[ -d "$rules_dir" ]]; then
for rule_file in "$rules_dir"/*.rules; do
[[ -f "$rule_file" ]] || continue
if grep -q "$pattern" "$rule_file"; then
found="true"
break
fi
done
fi
if [[ "$found" == "false" && -f "$audit_rules" ]]; then
if grep -q "$pattern" "$audit_rules"; then
found="true"
fi
fi
if [[ "$found" == "false" ]]; then
missing+=("$pattern")
fi
done
if [[ ${#missing[@]} -gt 0 ]]; then
status="$STATUS_FAIL"
evidence="Missing audit rules for: ${missing[*]}"
else
evidence="${description} audit rules are configured"
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_5() {
_check_audit_rules "4.1.5" "Time change" \
"adjtimex" "settimeofday" "clock_settime" "/etc/localtime"
}
check_4_1_6() {
_check_audit_rules "4.1.6" "User/group change" \
"/etc/group" "/etc/passwd" "/etc/gshadow" "/etc/shadow" "/etc/security/opasswd"
}
check_4_1_7() {
_check_audit_rules "4.1.7" "Network environment" \
"sethostname" "setdomainname" "/etc/issue" "/etc/hosts" "/etc/networks"
}
check_4_1_8() {
local id="4.1.8"
local status="$STATUS_PASS"
local evidence=""
local rules_dir="${SYSROOT}/etc/audit/rules.d"
local audit_rules="${SYSROOT}/etc/audit/audit.rules"
local found="false"
local mac_patterns=("/etc/selinux/" "/etc/apparmor/")
for pattern in "${mac_patterns[@]}"; do
if [[ -d "$rules_dir" ]]; then
for rule_file in "$rules_dir"/*.rules; do
[[ -f "$rule_file" ]] || continue
if grep -q "$pattern" "$rule_file"; then
found="true"
break 2
fi
done
fi
if [[ "$found" == "false" && -f "$audit_rules" ]]; then
if grep -q "$pattern" "$audit_rules"; then
found="true"
break
fi
fi
done
if [[ "$found" == "false" ]]; then
status="$STATUS_FAIL"
evidence="Missing audit rules for MAC policy changes"
else
evidence="MAC policy change audit rules are configured"
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_9() {
_check_audit_rules "4.1.9" "Login/logout event" \
"/var/log/lastlog" "/var/run/faillock/"
}
check_4_1_10() {
_check_audit_rules "4.1.10" "Session initiation" \
"/var/run/utmp" "/var/log/wtmp" "/var/log/btmp"
}
check_4_1_11() {
_check_audit_rules "4.1.11" "DAC permission change" \
"chmod" "chown" "fchmod" "fchown" "lchown" "setxattr"
}
check_4_1_12() {
local id="4.1.12"
local status="$STATUS_PASS"
local evidence=""
local rules_dir="${SYSROOT}/etc/audit/rules.d"
local audit_rules="${SYSROOT}/etc/audit/audit.rules"
local found_eacces="false"
local found_eperm="false"
if [[ -d "$rules_dir" ]]; then
for rule_file in "$rules_dir"/*.rules; do
[[ -f "$rule_file" ]] || continue
grep -q "EACCES" "$rule_file" && found_eacces="true"
grep -q "EPERM" "$rule_file" && found_eperm="true"
done
fi
if [[ -f "$audit_rules" ]]; then
grep -q "EACCES" "$audit_rules" && found_eacces="true"
grep -q "EPERM" "$audit_rules" && found_eperm="true"
fi
if [[ "$found_eacces" == "false" || "$found_eperm" == "false" ]]; then
local missing_items=""
[[ "$found_eacces" == "false" ]] && missing_items="EACCES"
[[ "$found_eperm" == "false" ]] && missing_items="${missing_items:+${missing_items} }EPERM"
status="$STATUS_FAIL"
evidence="Missing audit rules for unauthorized access: ${missing_items}"
else
evidence="Unauthorized file access audit rules are configured"
fi
record_result "$id" "$status" "$evidence"
}
check_4_1_13() {
_check_audit_rules "4.1.13" "File system mount" \
"mount"
}
check_4_1_14() {
_check_audit_rules "4.1.14" "File deletion" \
"unlink" "rename"
}
check_4_2_1() {
local id="4.2.1"
local status="$STATUS_PASS"
local evidence=""
if package_is_installed "rsyslog"; then
evidence="rsyslog package is installed"
elif file_exists "/usr/sbin/rsyslogd"; then
evidence="rsyslogd binary found at /usr/sbin/rsyslogd"
else
status="$STATUS_FAIL"
evidence="rsyslog is not installed"
fi
record_result "$id" "$status" "$evidence"
}
check_4_2_2() {
local id="4.2.2"
local status="$STATUS_PASS"
local evidence=""
if service_is_enabled "rsyslog"; then
evidence="rsyslog service is enabled"
else
local symlink="${SYSROOT}/etc/systemd/system/multi-user.target.wants/rsyslog.service"
if [[ -L "$symlink" || -f "$symlink" ]]; then
evidence="rsyslog enabled via systemd symlink"
else
status="$STATUS_FAIL"
evidence="rsyslog service is not enabled"
fi
fi
record_result "$id" "$status" "$evidence"
}
check_4_2_3() {
local id="4.2.3"
local status="$STATUS_PASS"
local evidence=""
local rsyslog_conf="${SYSROOT}/etc/rsyslog.conf"
if [[ ! -f "$rsyslog_conf" ]]; then
status="$STATUS_SKIP"
evidence="/etc/rsyslog.conf not found"
record_result "$id" "$status" "$evidence"
return
fi
local file_mode
file_mode=$(grep -E '^\s*\$FileCreateMode' "$rsyslog_conf" | tail -1 | awk '{print $2}') || true
if [[ -z "$file_mode" ]]; then
status="$STATUS_FAIL"
evidence="\$FileCreateMode not set in rsyslog.conf"
elif (( 8#$file_mode <= 8#0640 )); then
evidence="rsyslog FileCreateMode is ${file_mode}"
else
status="$STATUS_FAIL"
evidence="rsyslog FileCreateMode is ${file_mode} (expected 0640 or stricter)"
fi
record_result "$id" "$status" "$evidence"
}
check_4_2_4() {
local id="4.2.4"
local status="$STATUS_PASS"
local evidence=""
local rsyslog_conf="${SYSROOT}/etc/rsyslog.conf"
if [[ ! -f "$rsyslog_conf" ]]; then
status="$STATUS_SKIP"
evidence="/etc/rsyslog.conf not found"
record_result "$id" "$status" "$evidence"
return
fi
local rule_count
rule_count=$(grep -cE '^\s*[a-z]+\.\*\s+/|^\s*\*\.\*\s+/' "$rsyslog_conf") || true
if [[ "$rule_count" -gt 0 ]]; then
evidence="Found ${rule_count} logging rule(s) in rsyslog.conf"
else
local include_count
include_count=$(grep -cE '^\s*\$IncludeConfig|^\s*include\(' "$rsyslog_conf") || true
if [[ "$include_count" -gt 0 ]]; then
evidence="Logging configured via included config files (${include_count} include directive(s))"
else
status="$STATUS_FAIL"
evidence="No logging rules found in rsyslog.conf"
fi
fi
record_result "$id" "$status" "$evidence"
}

View File

@ -0,0 +1,429 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 05_access.sh
check_5_1_1() {
local id="5.1.1"
local status="$STATUS_PASS"
local evidence=""
if service_is_enabled "cron"; then
evidence="cron daemon is enabled"
elif file_exists "/etc/crontab"; then
evidence="cron configuration exists (/etc/crontab found)"
else
status="$STATUS_FAIL"
evidence="cron daemon is not enabled"
fi
record_result "$id" "$status" "$evidence"
}
check_5_1_2() {
local id="5.1.2"
local status="$STATUS_PASS"
local evidence=""
local crontab="${SYSROOT}/etc/crontab"
if [[ ! -f "$crontab" ]]; then
status="$STATUS_SKIP"
evidence="/etc/crontab not found"
record_result "$id" "$status" "$evidence"
return
fi
local file_stat
if file_stat=$(run_cmd stat -c '%a %U %G' "$crontab"); then
local perms owner group
perms=$(echo "$file_stat" | awk '{print $1}')
owner=$(echo "$file_stat" | awk '{print $2}')
group=$(echo "$file_stat" | awk '{print $3}')
if [[ "$owner" != "root" || "$group" != "root" ]]; then
status="$STATUS_FAIL"
evidence="/etc/crontab owned by ${owner}:${group} (expected root:root)"
elif (( 8#$perms > 8#0600 )); then
status="$STATUS_FAIL"
evidence="/etc/crontab permissions ${perms} (expected 600 or stricter)"
else
evidence="/etc/crontab permissions ${perms}, owned by ${owner}:${group}"
fi
else
evidence="/etc/crontab exists (permissions not verifiable in test mode)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_1_3() {
local id="5.1.3"
local status="$STATUS_PASS"
local evidence=""
local cron_hourly="${SYSROOT}/etc/cron.hourly"
if [[ ! -d "$cron_hourly" ]]; then
status="$STATUS_SKIP"
evidence="/etc/cron.hourly not found"
record_result "$id" "$status" "$evidence"
return
fi
local dir_stat
if dir_stat=$(run_cmd stat -c '%a %U %G' "$cron_hourly"); then
local perms owner group
perms=$(echo "$dir_stat" | awk '{print $1}')
owner=$(echo "$dir_stat" | awk '{print $2}')
group=$(echo "$dir_stat" | awk '{print $3}')
if [[ "$owner" != "root" || "$group" != "root" ]]; then
status="$STATUS_FAIL"
evidence="/etc/cron.hourly owned by ${owner}:${group} (expected root:root)"
elif (( 8#$perms > 8#0700 )); then
status="$STATUS_FAIL"
evidence="/etc/cron.hourly permissions ${perms} (expected 700 or stricter)"
else
evidence="/etc/cron.hourly permissions ${perms}, owned by ${owner}:${group}"
fi
else
evidence="/etc/cron.hourly exists (permissions not verifiable in test mode)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_1_4() {
local id="5.1.4"
local status="$STATUS_PASS"
local evidence=""
local cron_daily="${SYSROOT}/etc/cron.daily"
if [[ ! -d "$cron_daily" ]]; then
status="$STATUS_SKIP"
evidence="/etc/cron.daily not found"
record_result "$id" "$status" "$evidence"
return
fi
local dir_stat
if dir_stat=$(run_cmd stat -c '%a %U %G' "$cron_daily"); then
local perms owner group
perms=$(echo "$dir_stat" | awk '{print $1}')
owner=$(echo "$dir_stat" | awk '{print $2}')
group=$(echo "$dir_stat" | awk '{print $3}')
if [[ "$owner" != "root" || "$group" != "root" ]]; then
status="$STATUS_FAIL"
evidence="/etc/cron.daily owned by ${owner}:${group} (expected root:root)"
elif (( 8#$perms > 8#0700 )); then
status="$STATUS_FAIL"
evidence="/etc/cron.daily permissions ${perms} (expected 700 or stricter)"
else
evidence="/etc/cron.daily permissions ${perms}, owned by ${owner}:${group}"
fi
else
evidence="/etc/cron.daily exists (permissions not verifiable in test mode)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_1() {
local id="5.2.1"
local status="$STATUS_PASS"
local evidence=""
local sshd_config="${SYSROOT}/etc/ssh/sshd_config"
if [[ ! -f "$sshd_config" ]]; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
record_result "$id" "$status" "$evidence"
return
fi
local file_stat
if file_stat=$(run_cmd stat -c '%a %U %G' "$sshd_config"); then
local perms owner group
perms=$(echo "$file_stat" | awk '{print $1}')
owner=$(echo "$file_stat" | awk '{print $2}')
group=$(echo "$file_stat" | awk '{print $3}')
if [[ "$owner" != "root" ]]; then
status="$STATUS_FAIL"
evidence="sshd_config owned by ${owner} (expected root)"
elif (( 8#$perms > 8#0600 )); then
status="$STATUS_FAIL"
evidence="sshd_config permissions ${perms} (expected 600 or stricter)"
else
evidence="sshd_config permissions ${perms}, owned by ${owner}:${group}"
fi
else
evidence="sshd_config exists (permissions not verifiable in test mode)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_2() {
local id="5.2.2"
local status="$STATUS_PASS"
local evidence=""
if ! file_exists "/etc/ssh/sshd_config"; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
record_result "$id" "$status" "$evidence"
return
fi
local sshd_config="${SYSROOT}/etc/ssh/sshd_config"
local found_directive="false"
local directives=("AllowUsers" "AllowGroups" "DenyUsers" "DenyGroups")
local found_list=""
for directive in "${directives[@]}"; do
if grep -Eiq "^\s*${directive}\s" "$sshd_config"; then
found_directive="true"
found_list="${found_list:+${found_list}, }${directive}"
fi
done
if [[ "$found_directive" == "true" ]]; then
evidence="SSH access limited via: ${found_list}"
else
status="$STATUS_FAIL"
evidence="No SSH access restrictions configured (no AllowUsers/AllowGroups/DenyUsers/DenyGroups)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_3() {
local id="5.2.3"
local status="$STATUS_PASS"
local evidence=""
local ssh_dir="${SYSROOT}/etc/ssh"
local bad_keys=""
local key_count=0
if [[ ! -d "$ssh_dir" ]]; then
status="$STATUS_SKIP"
evidence="/etc/ssh directory not found"
record_result "$id" "$status" "$evidence"
return
fi
for key_file in "${ssh_dir}"/ssh_host_*_key; do
[[ -f "$key_file" ]] || continue
((key_count++)) || true
local file_stat
if file_stat=$(run_cmd stat -c '%a %U' "$key_file"); then
local perms owner
perms=$(echo "$file_stat" | awk '{print $1}')
owner=$(echo "$file_stat" | awk '{print $2}')
if [[ "$owner" != "root" ]] || (( 8#$perms > 8#0600 )); then
bad_keys="${bad_keys:+${bad_keys}, }${key_file##*/}(${perms}/${owner})"
fi
fi
done
if [[ "$key_count" -eq 0 ]]; then
if [[ "$SYSROOT" != "/" ]]; then
evidence="No SSH host private keys found (test mode)"
else
status="$STATUS_WARN"
evidence="No SSH host private keys found"
fi
elif [[ -n "$bad_keys" ]]; then
status="$STATUS_FAIL"
evidence="Insecure SSH private key files: ${bad_keys}"
else
evidence="All ${key_count} SSH private key file(s) have correct permissions"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_4() {
local id="5.2.4"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_config_value "/etc/ssh/sshd_config" "LogLevel") || true
if [[ -z "$value" ]]; then
if ! file_exists "/etc/ssh/sshd_config"; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
else
evidence="LogLevel not set (default is INFO)"
fi
elif [[ "${value^^}" == "INFO" || "${value^^}" == "VERBOSE" ]]; then
evidence="SSH LogLevel = ${value}"
else
status="$STATUS_FAIL"
evidence="SSH LogLevel = ${value} (expected INFO or VERBOSE)"
fi
record_result "$id" "$status" "$evidence"
}
_check_ssh_value() {
local id="$1"
local directive="$2"
local expected="$3"
local default_status="$4"
local default_msg="$5"
local pass_msg="$6"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_config_value "/etc/ssh/sshd_config" "$directive") || true
if [[ -z "$value" ]]; then
if ! file_exists "/etc/ssh/sshd_config"; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
else
status="$default_status"
evidence="${directive} not set (${default_msg})"
fi
elif [[ "${value,,}" == "${expected,,}" ]]; then
evidence="$pass_msg"
else
status="$STATUS_FAIL"
evidence="${directive} = ${value} (expected ${expected})"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_5() {
_check_ssh_value "5.2.5" "X11Forwarding" "no" "$STATUS_FAIL" \
"default may allow forwarding" "SSH X11Forwarding is disabled"
}
_check_ssh_max_int() {
local id="$1"
local directive="$2"
local threshold="$3"
local default_msg="$4"
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_config_value "/etc/ssh/sshd_config" "$directive") || true
if [[ -z "$value" ]]; then
if ! file_exists "/etc/ssh/sshd_config"; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
else
status="$STATUS_FAIL"
evidence="${directive} not set (${default_msg})"
fi
elif (( value <= threshold )); then
evidence="SSH ${directive} = ${value}"
else
status="$STATUS_FAIL"
evidence="${directive} = ${value} (expected ${threshold} or less)"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_6() { _check_ssh_max_int "5.2.6" "MaxAuthTries" 4 "default is 6"; }
check_5_2_7() {
_check_ssh_value "5.2.7" "IgnoreRhosts" "yes" "$STATUS_PASS" \
"default is yes" "SSH IgnoreRhosts = yes"
}
check_5_2_8() {
_check_ssh_value "5.2.8" "PermitRootLogin" "no" "$STATUS_FAIL" \
"default allows root login" "SSH root login is disabled (PermitRootLogin = no)"
}
check_5_2_9() {
_check_ssh_value "5.2.9" "PermitEmptyPasswords" "no" "$STATUS_PASS" \
"default is no" "SSH empty passwords are disabled"
}
check_5_2_10() {
_check_ssh_value "5.2.10" "PermitUserEnvironment" "no" "$STATUS_PASS" \
"default is no" "SSH user environment processing is disabled"
}
_check_ssh_no_weak() {
local id="$1"
local directive="$2"
local label="$3"
shift 3
local weak_items=("$@")
local status="$STATUS_PASS"
local evidence=""
local value
value=$(get_config_value "/etc/ssh/sshd_config" "$directive") || true
if [[ -z "$value" ]]; then
if ! file_exists "/etc/ssh/sshd_config"; then
status="$STATUS_SKIP"
evidence="sshd_config not found"
else
status="$STATUS_WARN"
evidence="${directive} not explicitly configured (using defaults)"
fi
record_result "$id" "$status" "$evidence"
return
fi
local found_weak=""
for weak in "${weak_items[@]}"; do
if echo ",$value," | grep -qi ",${weak},"; then
found_weak="${found_weak:+${found_weak}, }${weak}"
fi
done
if [[ -n "$found_weak" ]]; then
status="$STATUS_FAIL"
evidence="Weak SSH ${label} found: ${found_weak}"
else
evidence="Only strong SSH ${label} configured"
fi
record_result "$id" "$status" "$evidence"
}
check_5_2_11() {
_check_ssh_no_weak "5.2.11" "Ciphers" "ciphers" \
"3des-cbc" "aes128-cbc" "aes192-cbc" "aes256-cbc" \
"blowfish-cbc" "cast128-cbc" "arcfour" "arcfour128" "arcfour256"
}
check_5_2_12() {
_check_ssh_no_weak "5.2.12" "MACs" "MACs" \
"hmac-md5" "hmac-md5-96" "hmac-md5-etm@openssh.com" \
"hmac-md5-96-etm@openssh.com" "hmac-sha1-96" \
"hmac-sha1-96-etm@openssh.com" "umac-64@openssh.com" \
"umac-64-etm@openssh.com"
}
check_5_2_13() {
_check_ssh_no_weak "5.2.13" "KexAlgorithms" "key exchange algorithms" \
"diffie-hellman-group1-sha1" "diffie-hellman-group14-sha1" \
"diffie-hellman-group-exchange-sha1"
}
check_5_2_14() { _check_ssh_max_int "5.2.14" "LoginGraceTime" 60 "default is 120"; }

View File

@ -0,0 +1,108 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 05_access_password.sh
check_5_3_1() {
local id="5.3.1"
local status="$STATUS_PASS"
local evidence=""
local common_password="${SYSROOT}/etc/pam.d/common-password"
if [[ ! -f "$common_password" ]]; then
status="$STATUS_SKIP"
evidence="/etc/pam.d/common-password not found"
record_result "$id" "$status" "$evidence"
return
fi
if grep -qE '^\s*password\s+.*pam_pwquality\.so' "$common_password"; then
evidence="pam_pwquality is configured in common-password"
elif grep -qE '^\s*password\s+.*pam_cracklib\.so' "$common_password"; then
evidence="pam_cracklib is configured in common-password"
else
status="$STATUS_FAIL"
evidence="No password quality module (pam_pwquality or pam_cracklib) in common-password"
fi
record_result "$id" "$status" "$evidence"
}
_check_login_defs_value() {
local id="$1"
local param="$2"
local comparison="$3"
local threshold="$4"
local pass_desc="$5"
local fail_desc="$6"
local status="$STATUS_PASS"
local evidence=""
local login_defs="${SYSROOT}/etc/login.defs"
if [[ ! -f "$login_defs" ]]; then
status="$STATUS_SKIP"
evidence="/etc/login.defs not found"
record_result "$id" "$status" "$evidence"
return
fi
local value
value=$(grep -E "^\s*${param}\s" "$login_defs" | tail -1 | awk '{print $2}') || true
if [[ -z "$value" ]]; then
status="$STATUS_FAIL"
evidence="${param} not set in /etc/login.defs"
elif [[ "$comparison" == "le" ]] && (( value <= threshold )); then
evidence="${pass_desc} (${param} = ${value})"
elif [[ "$comparison" == "ge" ]] && (( value >= threshold )); then
evidence="${pass_desc} (${param} = ${value})"
else
status="$STATUS_FAIL"
evidence="${param} = ${value} (${fail_desc})"
fi
record_result "$id" "$status" "$evidence"
}
check_5_4_1() {
_check_login_defs_value "5.4.1" "PASS_MAX_DAYS" "le" 365 \
"Password expiration is configured" \
"expected 365 or less"
}
check_5_4_2() {
_check_login_defs_value "5.4.2" "PASS_MIN_DAYS" "ge" 1 \
"Minimum days between password changes is configured" \
"expected 1 or more"
}
check_5_4_3() {
_check_login_defs_value "5.4.3" "PASS_WARN_AGE" "ge" 7 \
"Password expiration warning is configured" \
"expected 7 or more"
}
check_5_5_1() {
local id="5.5.1"
local status="$STATUS_PASS"
local evidence=""
local common_auth="${SYSROOT}/etc/pam.d/common-auth"
if [[ ! -f "$common_auth" ]]; then
status="$STATUS_SKIP"
evidence="/etc/pam.d/common-auth not found"
record_result "$id" "$status" "$evidence"
return
fi
if grep -qE '^\s*auth\s+.*pam_faillock\.so' "$common_auth"; then
evidence="Account lockout configured via pam_faillock in common-auth"
elif grep -qE '^\s*auth\s+.*pam_tally2\.so' "$common_auth"; then
evidence="Account lockout configured via pam_tally2 in common-auth"
else
status="$STATUS_FAIL"
evidence="No account lockout module (pam_faillock or pam_tally2) in common-auth"
fi
record_result "$id" "$status" "$evidence"
}

View File

@ -0,0 +1,215 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# 06_maintenance.sh
_check_file_permissions() {
local id="$1"
local filepath="$2"
local expected_perms="$3"
local expected_owner="$4"
local expected_group="$5"
local status="$STATUS_PASS"
local evidence=""
local full_path="${SYSROOT}${filepath}"
if [[ ! -f "$full_path" ]]; then
status="$STATUS_SKIP"
evidence="${filepath} not found"
record_result "$id" "$status" "$evidence"
return
fi
local file_stat
if file_stat=$(run_cmd stat -c '%a %U %G' "$full_path"); then
local perms owner group
perms=$(echo "$file_stat" | awk '{print $1}')
owner=$(echo "$file_stat" | awk '{print $2}')
group=$(echo "$file_stat" | awk '{print $3}')
local issues=""
if [[ "$owner" != "$expected_owner" ]]; then
issues="${issues:+${issues}; }owner is ${owner} (expected ${expected_owner})"
fi
if [[ "$group" != "$expected_group" ]]; then
issues="${issues:+${issues}; }group is ${group} (expected ${expected_group})"
fi
if (( 8#$perms > 8#$expected_perms )); then
issues="${issues:+${issues}; }permissions ${perms} (expected ${expected_perms} or stricter)"
fi
if [[ -n "$issues" ]]; then
status="$STATUS_FAIL"
evidence="${filepath}: ${issues}"
else
evidence="${filepath} permissions ${perms}, owned by ${owner}:${group}"
fi
else
evidence="${filepath} exists (permissions not verifiable in test mode)"
fi
record_result "$id" "$status" "$evidence"
}
check_6_1_1() {
_check_file_permissions "6.1.1" "/etc/passwd" "644" "root" "root"
}
check_6_1_2() {
_check_file_permissions "6.1.2" "/etc/shadow" "640" "root" "shadow"
}
check_6_1_3() {
_check_file_permissions "6.1.3" "/etc/group" "644" "root" "root"
}
check_6_1_4() {
_check_file_permissions "6.1.4" "/etc/gshadow" "640" "root" "shadow"
}
check_6_1_5() {
_check_file_permissions "6.1.5" "/etc/passwd-" "600" "root" "root"
}
check_6_2_1() {
local id="6.2.1"
local status="$STATUS_PASS"
local evidence=""
local passwd_file="${SYSROOT}/etc/passwd"
if [[ ! -f "$passwd_file" ]]; then
status="$STATUS_SKIP"
evidence="/etc/passwd not found"
record_result "$id" "$status" "$evidence"
return
fi
local duplicates
duplicates=$(awk -F: '{print $3}' "$passwd_file" | sort | uniq -d)
if [[ -n "$duplicates" ]]; then
status="$STATUS_FAIL"
evidence="Duplicate UIDs found: ${duplicates}"
else
evidence="No duplicate UIDs found"
fi
record_result "$id" "$status" "$evidence"
}
check_6_2_2() {
local id="6.2.2"
local status="$STATUS_PASS"
local evidence=""
local group_file="${SYSROOT}/etc/group"
if [[ ! -f "$group_file" ]]; then
status="$STATUS_SKIP"
evidence="/etc/group not found"
record_result "$id" "$status" "$evidence"
return
fi
local duplicates
duplicates=$(awk -F: '{print $3}' "$group_file" | sort | uniq -d)
if [[ -n "$duplicates" ]]; then
status="$STATUS_FAIL"
evidence="Duplicate GIDs found: ${duplicates}"
else
evidence="No duplicate GIDs found"
fi
record_result "$id" "$status" "$evidence"
}
check_6_2_3() {
local id="6.2.3"
local status="$STATUS_PASS"
local evidence=""
local passwd_file="${SYSROOT}/etc/passwd"
if [[ ! -f "$passwd_file" ]]; then
status="$STATUS_SKIP"
evidence="/etc/passwd not found"
record_result "$id" "$status" "$evidence"
return
fi
local duplicates
duplicates=$(awk -F: '{print $1}' "$passwd_file" | sort | uniq -d)
if [[ -n "$duplicates" ]]; then
status="$STATUS_FAIL"
evidence="Duplicate user names found: ${duplicates}"
else
evidence="No duplicate user names found"
fi
record_result "$id" "$status" "$evidence"
}
check_6_2_4() {
local id="6.2.4"
local status="$STATUS_PASS"
local evidence=""
local passwd_file="${SYSROOT}/etc/passwd"
if [[ ! -f "$passwd_file" ]]; then
status="$STATUS_SKIP"
evidence="/etc/passwd not found"
record_result "$id" "$status" "$evidence"
return
fi
local uid0_accounts
uid0_accounts=$(awk -F: '$3 == 0 {print $1}' "$passwd_file")
local uid0_count
uid0_count=$(echo "$uid0_accounts" | wc -l)
if [[ "$uid0_count" -eq 1 && "$uid0_accounts" == "root" ]]; then
evidence="Only root has UID 0"
elif [[ "$uid0_count" -eq 0 ]]; then
status="$STATUS_WARN"
evidence="No accounts with UID 0 found"
else
local non_root
non_root=$(echo "$uid0_accounts" | grep -v '^root$') || true
status="$STATUS_FAIL"
evidence="Non-root accounts with UID 0: ${non_root}"
fi
record_result "$id" "$status" "$evidence"
}
check_6_2_5() {
local id="6.2.5"
local status="$STATUS_PASS"
local evidence=""
local files_to_check=("/etc/passwd" "/etc/shadow" "/etc/group")
local legacy_found=""
for filepath in "${files_to_check[@]}"; do
local full_path="${SYSROOT}${filepath}"
[[ -f "$full_path" ]] || continue
if grep -q '^+:' "$full_path"; then
legacy_found="${legacy_found:+${legacy_found}, }${filepath}"
fi
done
if [[ -n "$legacy_found" ]]; then
status="$STATUS_FAIL"
evidence="Legacy + entries found in: ${legacy_found}"
else
evidence="No legacy + entries found in passwd/shadow/group"
fi
record_result "$id" "$status" "$evidence"
}

View File

@ -0,0 +1,277 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# cisaudit.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
declare -g QUIET="false"
declare -g OPT_LEVEL="all"
declare -g OPT_FORMAT="terminal"
declare -g OPT_OUTPUT=""
declare -g OPT_CATEGORIES="all"
declare -g OPT_BASELINE=""
declare -g OPT_SAVE_BASELINE=""
declare -g OPT_THRESHOLD=0
declare -g OPT_LIST_CONTROLS="false"
source "${SCRIPT_DIR}/lib/constants.sh"
source "${SCRIPT_DIR}/lib/utils.sh"
source "${SCRIPT_DIR}/lib/registry.sh"
source "${SCRIPT_DIR}/lib/engine.sh"
_source_if_exists() {
local path="$1"
if [[ -f "$path" ]]; then
source "$path"
fi
}
_source_if_exists "${SCRIPT_DIR}/lib/report_terminal.sh"
_source_if_exists "${SCRIPT_DIR}/lib/report_json.sh"
_source_if_exists "${SCRIPT_DIR}/lib/report_html.sh"
_source_if_exists "${SCRIPT_DIR}/lib/baseline.sh"
_source_if_exists "${SCRIPT_DIR}/controls/registry_data.sh"
for check_file in "${SCRIPT_DIR}"/checks/*.sh; do
[[ -f "$check_file" ]] && source "$check_file"
done
print_version() {
echo "cisaudit v${VERSION}"
}
print_help() {
echo -e "${BOLD}cisaudit${RESET} — CIS Benchmark Compliance Auditor for Linux"
echo ""
echo -e "${BOLD}USAGE${RESET}"
echo " cisaudit [OPTIONS]"
echo ""
echo -e "${BOLD}OPTIONS${RESET}"
echo " -l, --level LEVEL Benchmark level: 1, 2, or all (default: all)"
echo " -f, --format FORMAT Output: terminal, json, html (default: terminal)"
echo " -o, --output FILE Write report to file (default: stdout)"
echo " -c, --categories LIST Categories to audit: 1,2,3,4,5,6 (default: all)"
echo " -b, --baseline FILE Compare against a previous baseline JSON"
echo " -s, --save-baseline FILE Save results as a baseline JSON file"
echo " -t, --test-root DIR Use DIR as system root (for testing)"
echo " --threshold PCT Minimum pass % to exit 0 (default: 0)"
echo " --list-controls List all registered controls and exit"
echo " -q, --quiet Suppress progress output"
echo " -v, --version Print version and exit"
echo " -h, --help Print this help and exit"
echo ""
echo -e "${BOLD}EXAMPLES${RESET}"
echo " sudo cisaudit"
echo " sudo cisaudit -l 1 -f json -o report.json"
echo " sudo cisaudit -c 5 -f terminal"
echo " cisaudit -t testdata/fixtures -f json"
echo " cisaudit --list-controls"
echo ""
echo -e "${BOLD}BENCHMARK${RESET}"
echo " ${CIS_BENCHMARK}"
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
-l|--level)
OPT_LEVEL="$2"
shift 2
;;
-f|--format)
OPT_FORMAT="$2"
shift 2
;;
-o|--output)
OPT_OUTPUT="$2"
shift 2
;;
-c|--categories)
OPT_CATEGORIES="$2"
shift 2
;;
-b|--baseline)
OPT_BASELINE="$2"
shift 2
;;
-s|--save-baseline)
OPT_SAVE_BASELINE="$2"
shift 2
;;
-t|--test-root)
SYSROOT="${2%/}"
shift 2
;;
--threshold)
OPT_THRESHOLD="$2"
shift 2
;;
--list-controls)
OPT_LIST_CONTROLS="true"
shift
;;
-q|--quiet)
QUIET="true"
shift
;;
-v|--version)
print_version
exit "$EXIT_OK"
;;
-h|--help)
print_help
exit "$EXIT_OK"
;;
*)
fail "Unknown option: $1 (use --help for usage)"
;;
esac
done
}
list_controls() {
local id
printf "${BOLD}%-10s %-8s %-8s %-50s${RESET}\n" "ID" "Level" "Scored" "Title"
printf "%-10s %-8s %-8s %-50s\n" "----------" "--------" "--------" "--------------------------------------------------"
for id in "${REGISTERED_IDS[@]}"; do
printf "%-10s %-8s %-8s %-50s\n" \
"$id" \
"${CTRL_LEVEL[$id]}" \
"${CTRL_SCORED[$id]}" \
"${CTRL_TITLE[$id]}"
done
echo ""
echo "Total: ${#REGISTERED_IDS[@]} controls"
}
should_run_check() {
local id="$1"
if [[ "$OPT_LEVEL" != "all" && "${CTRL_LEVEL[$id]}" != "$OPT_LEVEL" ]]; then
return 1
fi
if [[ "$OPT_CATEGORIES" != "all" ]]; then
local section_num="${id%%.*}"
if [[ ! ",$OPT_CATEGORIES," == *",$section_num,"* ]]; then
return 1
fi
fi
return 0
}
run_checks() {
local total="${#REGISTERED_IDS[@]}"
local count=0
local id fn
for id in "${REGISTERED_IDS[@]}"; do
((count++)) || true
fn="${CTRL_CHECK_FN[$id]}"
if ! should_run_check "$id"; then
continue
fi
progress "${count}/${total}" "${CTRL_TITLE[$id]}"
if declare -f "$fn" &>/dev/null; then
"$fn" || true
else
record_result "$id" "$STATUS_SKIP" "Check function ${fn} not implemented"
fi
done
clear_progress
}
generate_report() {
local output=""
case "$OPT_FORMAT" in
terminal)
if declare -f emit_terminal_report &>/dev/null; then
output=$(emit_terminal_report)
else
fail "Terminal reporter not loaded"
fi
;;
json)
if declare -f emit_json_report &>/dev/null; then
output=$(emit_json_report)
else
fail "JSON reporter not loaded"
fi
;;
html)
if declare -f emit_html_report &>/dev/null; then
output=$(emit_html_report)
else
fail "HTML reporter not loaded"
fi
;;
*)
fail "Unknown format: ${OPT_FORMAT} (use terminal, json, or html)"
;;
esac
if [[ -n "$OPT_OUTPUT" ]]; then
echo "$output" > "$OPT_OUTPUT"
info "Report written to ${OPT_OUTPUT}"
else
echo "$output"
fi
}
main() {
check_bash_version
parse_args "$@"
if [[ "$OPT_LIST_CONTROLS" == "true" ]]; then
list_controls
exit "$EXIT_OK"
fi
detect_os
local is_root=0
check_root && is_root=1
info "cisaudit v${VERSION}${CIS_BENCHMARK}"
info "Target: ${SYSROOT} | OS: ${DETECTED_ID} ${DETECTED_VERSION} | Level: ${OPT_LEVEL}"
info "Controls: $(get_total_controls) registered"
[[ "$QUIET" == "true" ]] || echo "" >&2
run_checks
compute_scores
generate_report
if [[ -n "$OPT_SAVE_BASELINE" ]]; then
if declare -f save_baseline &>/dev/null; then
save_baseline "$OPT_SAVE_BASELINE"
info "Baseline saved to ${OPT_SAVE_BASELINE}"
else
warn "Baseline module not loaded"
fi
fi
if [[ -n "$OPT_BASELINE" ]]; then
if declare -f diff_baseline &>/dev/null; then
diff_baseline "$OPT_BASELINE"
else
warn "Baseline module not loaded"
fi
fi
local score_int="${SCORE_OVERALL%.*}"
if (( score_int < OPT_THRESHOLD )); then
exit "$EXIT_FAIL"
fi
exit "$EXIT_OK"
}
main "$@"

View File

@ -0,0 +1,875 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# registry_data.sh
register_control "1.1.1" \
"Initial Setup" \
"Ensure mounting of cramfs is disabled" \
"1" \
"yes" \
"The cramfs filesystem type is a compressed read-only Linux filesystem embedded in small footprint systems. Disabling cramfs eliminates a potential attack surface by preventing rarely-used filesystem modules from being loaded. Most modern systems have no legitimate need for cramfs support." \
"echo 'install cramfs /bin/true' >> /etc/modprobe.d/cramfs.conf && echo 'blacklist cramfs' >> /etc/modprobe.d/cramfs.conf"
register_control "1.1.2" \
"Initial Setup" \
"Ensure mounting of freevxfs is disabled" \
"1" \
"yes" \
"The freevxfs filesystem type is a free version of the Veritas filesystem used by HP-UX and other commercial systems. Disabling this module reduces the attack surface by removing support for an uncommon filesystem. Exploitation of vulnerabilities in rarely maintained filesystem drivers is a known threat vector." \
"echo 'install freevxfs /bin/true' >> /etc/modprobe.d/freevxfs.conf && echo 'blacklist freevxfs' >> /etc/modprobe.d/freevxfs.conf"
register_control "1.1.3" \
"Initial Setup" \
"Ensure mounting of jffs2 is disabled" \
"1" \
"yes" \
"The jffs2 filesystem type is a log-structured filesystem used in flash memory devices. Disabling this module prevents potential exploitation through crafted jffs2 filesystem images. Standard servers typically do not require jffs2 support as it is designed for embedded systems." \
"echo 'install jffs2 /bin/true' >> /etc/modprobe.d/jffs2.conf && echo 'blacklist jffs2' >> /etc/modprobe.d/jffs2.conf"
register_control "1.1.4" \
"Initial Setup" \
"Ensure mounting of hfs is disabled" \
"1" \
"yes" \
"The hfs filesystem type is the native filesystem for older Macintosh systems. Disabling hfs prevents potential exploits targeting this legacy filesystem driver. Linux servers rarely need to mount Apple HFS volumes and removing the capability reduces risk." \
"echo 'install hfs /bin/true' >> /etc/modprobe.d/hfs.conf && echo 'blacklist hfs' >> /etc/modprobe.d/hfs.conf"
register_control "1.1.5" \
"Initial Setup" \
"Ensure mounting of hfsplus is disabled" \
"1" \
"yes" \
"The hfsplus filesystem type is the successor to hfs used on modern Apple systems. Disabling this kernel module reduces exposure to vulnerabilities in an unnecessary filesystem driver. Servers should not need to interact with Apple-formatted media." \
"echo 'install hfsplus /bin/true' >> /etc/modprobe.d/hfsplus.conf && echo 'blacklist hfsplus' >> /etc/modprobe.d/hfsplus.conf"
register_control "1.1.6" \
"Initial Setup" \
"Ensure mounting of squashfs is disabled" \
"2" \
"yes" \
"The squashfs filesystem is a compressed read-only filesystem commonly used for live CDs and snap packages. Disabling squashfs prevents attackers from using crafted squashfs images to exploit kernel vulnerabilities. This is a Level 2 control because disabling squashfs may break snap package functionality." \
"echo 'install squashfs /bin/true' >> /etc/modprobe.d/squashfs.conf && echo 'blacklist squashfs' >> /etc/modprobe.d/squashfs.conf"
register_control "1.1.7" \
"Initial Setup" \
"Ensure mounting of udf is disabled" \
"1" \
"yes" \
"The udf filesystem type is the universal disk format used on DVDs and newer optical media. Disabling this module prevents potential exploitation of vulnerabilities in the UDF driver through crafted media. Servers generally do not need optical disc filesystem support." \
"echo 'install udf /bin/true' >> /etc/modprobe.d/udf.conf && echo 'blacklist udf' >> /etc/modprobe.d/udf.conf"
register_control "1.1.8" \
"Initial Setup" \
"Ensure mounting of vfat is limited" \
"2" \
"yes" \
"The vfat filesystem type is used for the FAT filesystem common on removable media and UEFI system partitions. On non-UEFI systems this module should be disabled to reduce the attack surface. UEFI systems require vfat for the EFI System Partition so this control must be evaluated accordingly." \
"echo 'install vfat /bin/true' >> /etc/modprobe.d/vfat.conf && echo 'blacklist vfat' >> /etc/modprobe.d/vfat.conf"
register_control "1.2.1" \
"Initial Setup" \
"Ensure /tmp is a separate partition" \
"1" \
"yes" \
"The /tmp directory is a world-writable location used for temporary file storage by all users and applications. Mounting /tmp as a separate partition enables administrators to apply restrictive mount options. This prevents /tmp from consuming root filesystem space and allows enforcing noexec, nosuid, and nodev protections." \
"echo 'tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime 0 0' >> /etc/fstab && mount -o remount /tmp"
register_control "1.2.2" \
"Initial Setup" \
"Ensure noexec option set on /tmp" \
"1" \
"yes" \
"The noexec mount option prevents execution of binaries stored on the /tmp partition. This blocks attackers from downloading and running malicious executables in the world-writable /tmp directory. Setting noexec on /tmp is a critical defense-in-depth measure against privilege escalation attacks." \
"mount -o remount,noexec /tmp"
register_control "1.2.3" \
"Initial Setup" \
"Ensure nosuid option set on /tmp" \
"1" \
"yes" \
"The nosuid mount option prevents setuid and setgid bits from taking effect on the /tmp partition. This stops attackers from placing setuid binaries in /tmp to escalate privileges. Combined with noexec this provides strong protection against local privilege escalation via temporary files." \
"mount -o remount,nosuid /tmp"
register_control "1.2.4" \
"Initial Setup" \
"Ensure nodev option set on /tmp" \
"1" \
"yes" \
"The nodev mount option prevents the creation and use of block and character special devices on the /tmp partition. Attackers could create device files in /tmp to access hardware directly and bypass security controls. Setting nodev on /tmp ensures that no device nodes can be exploited from temporary storage." \
"mount -o remount,nodev /tmp"
register_control "1.3.1" \
"Initial Setup" \
"Ensure package manager repositories are configured" \
"1" \
"no" \
"Package repositories provide a trusted source for installing and updating software on the system. Verifying that repositories are correctly configured ensures that security patches come from legitimate sources. Misconfigured or unauthorized repositories could introduce backdoored or vulnerable packages." \
"apt-cache policy"
register_control "1.3.2" \
"Initial Setup" \
"Ensure GPG keys are configured" \
"1" \
"no" \
"GPG keys are used to authenticate packages downloaded from repositories before installation. Ensuring GPG keys are properly configured prevents the installation of tampered or unsigned packages. Without valid GPG keys an attacker could perform a man-in-the-middle attack on package downloads." \
"apt-key list"
register_control "1.4.1" \
"Initial Setup" \
"Ensure bootloader password is set" \
"1" \
"yes" \
"Setting a bootloader password prevents unauthorized users from modifying boot parameters at the GRUB menu. Without this protection an attacker with physical access could boot into single user mode or modify kernel parameters. A GRUB password ensures that only authorized administrators can alter the boot process." \
"grub-mkpasswd-pbkdf2 && cat <<GRUBEOF >> /etc/grub.d/40_custom\nset superusers=\"root\"\npassword_pbkdf2 root <encrypted-password>\nGRUBEOF\nupdate-grub"
register_control "1.4.2" \
"Initial Setup" \
"Ensure permissions on bootloader config are configured" \
"1" \
"yes" \
"The GRUB configuration file contains sensitive boot parameters and potentially the bootloader password hash. Restricting permissions ensures only root can read or modify the bootloader configuration. World-readable bootloader configs could leak password hashes or reveal system configuration details." \
"chown root:root /boot/grub/grub.cfg && chmod 600 /boot/grub/grub.cfg"
register_control "1.4.3" \
"Initial Setup" \
"Ensure authentication required for single user mode" \
"1" \
"yes" \
"Single user mode provides a root shell with minimal services for system recovery. Without authentication requirements an attacker with physical access gains immediate root access through single user mode. Requiring a root password for single user mode prevents unauthorized recovery-mode access." \
"passwd root"
register_control "1.5.1" \
"Initial Setup" \
"Ensure address space layout randomization is enabled" \
"1" \
"yes" \
"Address Space Layout Randomization (ASLR) randomizes the memory addresses used by processes including the stack, heap, and libraries. This makes it significantly harder for attackers to exploit memory corruption vulnerabilities reliably. ASLR should be set to mode 2 for full randomization of stack, VDSO, shared memory, and data segments." \
"sysctl -w kernel.randomize_va_space=2 && echo 'kernel.randomize_va_space = 2' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "1.5.2" \
"Initial Setup" \
"Ensure core dumps are restricted" \
"1" \
"yes" \
"Core dumps capture the memory contents of a process when it crashes and may contain sensitive data such as passwords or encryption keys. Restricting core dumps prevents users from creating files that could expose this information. Setuid programs must also be prevented from dumping core via the suid_dumpable sysctl." \
"echo '* hard core 0' >> /etc/security/limits.conf && sysctl -w fs.suid_dumpable=0 && echo 'fs.suid_dumpable = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "1.5.3" \
"Initial Setup" \
"Ensure prelink is not installed" \
"1" \
"yes" \
"Prelink modifies ELF shared libraries and executables to reduce startup time by pre-computing symbol resolutions. However prelink interferes with AIDE and other integrity-checking tools by changing binary checksums after each prelink run. Removing prelink ensures that file integrity monitoring produces reliable and consistent results." \
"prelink -ua && apt-get remove -y prelink"
register_control "2.1.1" \
"Services" \
"Ensure xinetd is not installed" \
"1" \
"yes" \
"The xinetd service is an extended internet services daemon that manages network connections for various legacy services. Modern systems use systemd socket activation instead making xinetd unnecessary. Removing xinetd eliminates a potential entry point for attacks targeting legacy network services." \
"apt-get remove -y xinetd"
register_control "2.1.2" \
"Services" \
"Ensure openbsd-inetd is not installed" \
"1" \
"yes" \
"The openbsd-inetd package provides a legacy internet super-server similar to xinetd. Like xinetd it has been superseded by systemd socket activation on modern distributions. Removing it reduces the attack surface by eliminating an unnecessary network service dispatcher." \
"apt-get remove -y openbsd-inetd"
register_control "2.2.1" \
"Services" \
"Ensure X Window System is not installed" \
"1" \
"yes" \
"The X Window System provides a graphical user interface framework that is unnecessary on server systems. Running X11 significantly increases the attack surface with a large codebase that has a history of security vulnerabilities. Servers should be administered remotely via SSH and do not require graphical display capabilities." \
"apt-get remove -y xserver-xorg*"
register_control "2.2.2" \
"Services" \
"Ensure Avahi Server is not installed" \
"1" \
"yes" \
"Avahi is a system that implements multicast DNS/DNS-SD for zero-configuration networking and automatic service discovery. On a server this service is unnecessary and exposes the system to multicast-based network attacks. Removing Avahi eliminates a service that could be exploited for network reconnaissance or denial of service." \
"systemctl disable avahi-daemon && apt-get remove -y avahi-daemon"
register_control "2.2.3" \
"Services" \
"Ensure CUPS is not installed" \
"1" \
"no" \
"CUPS provides the Common Unix Printing System that enables a system to act as a print server. Unless the server specifically needs to manage printers CUPS should be removed to reduce the attack surface. CUPS listens on network ports and has had multiple remote code execution vulnerabilities in the past." \
"apt-get remove -y cups"
register_control "2.2.4" \
"Services" \
"Ensure DHCP Server is not installed" \
"1" \
"yes" \
"The ISC DHCP server package allows a system to act as a DHCP server assigning IP addresses to network clients. Unless the system is specifically designated as a DHCP server this service should not be present. An unauthorized DHCP server can be used to perform man-in-the-middle attacks on the local network." \
"apt-get remove -y isc-dhcp-server"
register_control "2.2.5" \
"Services" \
"Ensure LDAP server is not installed" \
"1" \
"yes" \
"The slapd package provides an OpenLDAP directory server for centralized authentication and directory services. Unless the system is specifically designated as an LDAP server this service increases the attack surface unnecessarily. LDAP servers handle sensitive authentication data and must be carefully secured if required." \
"apt-get remove -y slapd"
register_control "2.2.6" \
"Services" \
"Ensure NFS is not installed" \
"1" \
"yes" \
"NFS allows sharing directories over the network and is a common target for exploitation. Unless the system specifically needs to serve NFS shares the server package should be removed. NFS has historically had numerous security issues including weak authentication and data exposure." \
"apt-get remove -y nfs-kernel-server"
register_control "2.2.7" \
"Services" \
"Ensure DNS Server is not installed" \
"1" \
"yes" \
"The BIND DNS server package allows a system to act as a domain name resolver for the network. DNS servers are high-value targets frequently exploited for cache poisoning and denial of service attacks. Unless the system is a designated DNS server this package should be removed." \
"apt-get remove -y bind9"
register_control "2.2.8" \
"Services" \
"Ensure FTP Server is not installed" \
"1" \
"yes" \
"FTP is an insecure file transfer protocol that transmits credentials and data in cleartext. The vsftpd package or any other FTP server should be removed in favor of secure alternatives like SFTP. Attackers can trivially capture FTP credentials through network sniffing." \
"apt-get remove -y vsftpd"
register_control "2.2.9" \
"Services" \
"Ensure HTTP Server is not installed" \
"1" \
"yes" \
"Web server packages such as Apache or nginx should not be installed unless the system is a designated web server. Web servers present a large attack surface with complex configurations that are frequently misconfigured. Removing unused web servers eliminates a major category of potential remote exploitation." \
"apt-get remove -y apache2 nginx"
register_control "2.2.10" \
"Services" \
"Ensure IMAP and POP3 server is not installed" \
"1" \
"yes" \
"IMAP and POP3 servers like Dovecot provide email retrieval services for mail clients. Unless the system is a designated mail server these services needlessly expand the attack surface. Mail servers handle sensitive communications and require dedicated security hardening if needed." \
"apt-get remove -y dovecot-imapd dovecot-pop3d"
register_control "2.2.11" \
"Services" \
"Ensure Samba is not installed" \
"1" \
"yes" \
"Samba provides Windows-compatible file and print sharing services using the SMB/CIFS protocol. Unless the system must share resources with Windows clients Samba should be removed. The SMB protocol has been the target of numerous critical vulnerabilities including the WannaCry ransomware exploit." \
"apt-get remove -y samba"
register_control "2.2.12" \
"Services" \
"Ensure HTTP Proxy Server is not installed" \
"1" \
"yes" \
"HTTP proxy servers like Squid allow a system to act as an intermediary for web requests. Unless the system is a designated proxy this service increases the attack surface and could be abused for traffic interception. Proxy servers can be leveraged to bypass network security controls if misconfigured." \
"apt-get remove -y squid"
register_control "2.2.13" \
"Services" \
"Ensure SNMP Server is not installed" \
"1" \
"yes" \
"SNMP provides network management and monitoring capabilities but older versions transmit community strings in cleartext. The SNMP server should be removed unless it is specifically needed for network monitoring infrastructure. Attackers can exploit SNMP to gather detailed system information or modify device configurations." \
"apt-get remove -y snmpd"
register_control "2.2.14" \
"Services" \
"Ensure NIS Server is not installed" \
"1" \
"yes" \
"The Network Information Service is a legacy client-server directory service for distributing system configuration data. NIS transmits all data including password hashes unencrypted over the network. Modern systems should use LDAP with TLS or other encrypted directory services instead of NIS." \
"apt-get remove -y nis"
register_control "2.2.15" \
"Services" \
"Ensure mail transfer agent is configured for local-only mode" \
"1" \
"yes" \
"Mail Transfer Agents like Postfix or Exim handle email delivery and may listen on network port 25. Unless the system is a designated mail relay the MTA should only accept connections from localhost. Configuring local-only mode prevents the system from being used as an open relay for spam or phishing attacks." \
"sed -i 's/^inet_interfaces.*/inet_interfaces = loopback-only/' /etc/postfix/main.cf && systemctl restart postfix"
register_control "2.2.16" \
"Services" \
"Ensure rsync service is not installed" \
"1" \
"yes" \
"The rsync service provides fast file synchronization over the network and can run as a daemon on port 873. Unless specifically required for system administration rsync should be removed to reduce exposure. An improperly configured rsync daemon can expose sensitive files to unauthorized network access." \
"apt-get remove -y rsync"
register_control "3.1.1" \
"Network Configuration" \
"Ensure IP forwarding is disabled" \
"1" \
"yes" \
"IP forwarding allows the system to route packets between network interfaces acting as a router. Unless the system is specifically designed as a router or gateway IP forwarding must be disabled. An attacker could exploit IP forwarding to redirect network traffic through a compromised system for interception." \
"sysctl -w net.ipv4.ip_forward=0 && echo 'net.ipv4.ip_forward = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.1.2" \
"Network Configuration" \
"Ensure packet redirect sending is disabled" \
"1" \
"yes" \
"ICMP redirect messages inform hosts of more efficient routes and should only be sent by routers. A non-router system sending redirects could be exploited to manipulate routing tables on neighboring hosts. Disabling send_redirects prevents the system from being used in route manipulation attacks." \
"sysctl -w net.ipv4.conf.all.send_redirects=0 && sysctl -w net.ipv4.conf.default.send_redirects=0 && echo 'net.ipv4.conf.all.send_redirects = 0' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv4.conf.default.send_redirects = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.1.3" \
"Network Configuration" \
"Ensure source routed packets are not accepted" \
"1" \
"yes" \
"Source routed packets allow the sender to specify the route through the network bypassing normal routing decisions. Attackers use source routing to direct traffic through compromised systems for eavesdropping or to bypass firewall rules. Disabling acceptance of source routed packets forces all traffic to follow the normal routing path." \
"sysctl -w net.ipv4.conf.all.accept_source_route=0 && sysctl -w net.ipv4.conf.default.accept_source_route=0 && echo 'net.ipv4.conf.all.accept_source_route = 0' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv4.conf.default.accept_source_route = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.1.4" \
"Network Configuration" \
"Ensure ICMP redirects are not accepted" \
"1" \
"yes" \
"ICMP redirect messages can alter the routing table of a host directing traffic to a different gateway. Attackers can send forged ICMP redirects to perform man-in-the-middle attacks by rerouting traffic through a malicious host. Disabling ICMP redirect acceptance prevents these routing table manipulation attacks." \
"sysctl -w net.ipv4.conf.all.accept_redirects=0 && sysctl -w net.ipv4.conf.default.accept_redirects=0 && echo 'net.ipv4.conf.all.accept_redirects = 0' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv4.conf.default.accept_redirects = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.1" \
"Network Configuration" \
"Ensure suspicious packets are logged" \
"1" \
"yes" \
"Logging martian packets records instances where the system receives packets with impossible source addresses. These packets often indicate spoofing attempts, misconfigured systems, or ongoing attacks. Enabling log_martians provides valuable forensic data for security incident investigation." \
"sysctl -w net.ipv4.conf.all.log_martians=1 && sysctl -w net.ipv4.conf.default.log_martians=1 && echo 'net.ipv4.conf.all.log_martians = 1' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv4.conf.default.log_martians = 1' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.2" \
"Network Configuration" \
"Ensure broadcast ICMP requests are ignored" \
"1" \
"yes" \
"Broadcast ICMP echo requests can be used in Smurf amplification attacks where an attacker sends pings to a broadcast address causing all hosts to respond. Ignoring broadcast ICMP requests prevents the system from participating in these amplification attacks. This is a fundamental network hardening measure against denial of service." \
"sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1 && echo 'net.ipv4.icmp_echo_ignore_broadcasts = 1' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.3" \
"Network Configuration" \
"Ensure bogus ICMP responses are ignored" \
"1" \
"yes" \
"Some routers send bogus ICMP error responses that violate RFC standards and can fill up log files. Ignoring these bogus responses prevents unnecessary log noise and potential log-based denial of service. This setting reduces the impact of malformed ICMP traffic on system stability." \
"sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1 && echo 'net.ipv4.icmp_ignore_bogus_error_responses = 1' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.4" \
"Network Configuration" \
"Ensure Reverse Path Filtering is enabled" \
"1" \
"yes" \
"Reverse Path Filtering validates that incoming packets arrive on the interface that would be used to reach the source address. This prevents IP spoofing by dropping packets whose source address does not match the expected routing path. Enabling strict mode (value 1) provides the strongest anti-spoofing protection." \
"sysctl -w net.ipv4.conf.all.rp_filter=1 && sysctl -w net.ipv4.conf.default.rp_filter=1 && echo 'net.ipv4.conf.all.rp_filter = 1' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv4.conf.default.rp_filter = 1' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.5" \
"Network Configuration" \
"Ensure TCP SYN Cookies is enabled" \
"1" \
"yes" \
"TCP SYN Cookies protect against SYN flood attacks by encoding connection state in the sequence number instead of allocating memory for half-open connections. When the SYN queue is full the kernel uses cryptographic cookies to validate legitimate connections. This is an essential defense against one of the most common denial of service attack vectors." \
"sysctl -w net.ipv4.tcp_syncookies=1 && echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.2.6" \
"Network Configuration" \
"Ensure IPv6 router advertisements are not accepted" \
"1" \
"yes" \
"IPv6 router advertisements allow routers to automatically configure IPv6 addresses and routing on hosts. Accepting rogue router advertisements could allow an attacker to redirect IPv6 traffic or perform man-in-the-middle attacks. Disabling acceptance of router advertisements prevents unauthorized network reconfiguration via IPv6." \
"sysctl -w net.ipv6.conf.all.accept_ra=0 && sysctl -w net.ipv6.conf.default.accept_ra=0 && echo 'net.ipv6.conf.all.accept_ra = 0' >> /etc/sysctl.d/99-cisaudit.conf && echo 'net.ipv6.conf.default.accept_ra = 0' >> /etc/sysctl.d/99-cisaudit.conf"
register_control "3.3.1" \
"Network Configuration" \
"Ensure iptables is installed" \
"1" \
"yes" \
"Iptables provides host-based firewall functionality that is essential for controlling network traffic to and from the system. Without a firewall all network services are exposed to the network without any filtering. Installing iptables is the prerequisite for implementing any host-based firewall policy." \
"apt-get install -y iptables"
register_control "3.3.2" \
"Network Configuration" \
"Ensure default deny firewall policy for INPUT" \
"1" \
"yes" \
"A default deny policy for the INPUT chain drops all incoming packets that do not match an explicit allow rule. This ensures that only specifically authorized traffic can reach the system. Without a default deny policy any traffic not explicitly blocked will be accepted." \
"iptables -P INPUT DROP"
register_control "3.3.3" \
"Network Configuration" \
"Ensure default deny firewall policy for FORWARD" \
"1" \
"yes" \
"A default deny policy for the FORWARD chain prevents the system from routing traffic between interfaces unless explicitly permitted. This is critical for systems with multiple network interfaces to prevent unauthorized traffic forwarding. Even on single-interface systems this policy provides defense in depth." \
"iptables -P FORWARD DROP"
register_control "3.3.4" \
"Network Configuration" \
"Ensure default deny firewall policy for OUTPUT" \
"1" \
"yes" \
"A default deny policy for the OUTPUT chain blocks all outgoing packets that do not match an explicit allow rule. This restricts what traffic the system can send preventing compromised services from establishing outbound connections. Outbound filtering is essential for detecting and containing breaches." \
"iptables -P OUTPUT DROP"
register_control "3.3.5" \
"Network Configuration" \
"Ensure firewall rules exist for all open ports" \
"1" \
"yes" \
"Every listening network port should have a corresponding firewall rule that explicitly allows or denies access. Ports without firewall rules rely solely on the default policy which may change over time. Explicit rules provide documentation of intended network access and ensure consistent security posture." \
"iptables -L INPUT -v -n"
register_control "3.4.1" \
"Network Configuration" \
"Ensure wireless interfaces are disabled" \
"1" \
"no" \
"Wireless interfaces provide an additional attack vector through which unauthorized users can access the network. Server systems rarely need wireless connectivity and should use wired connections for reliability and security. Disabling wireless interfaces prevents rogue access point attacks and unauthorized wireless connections." \
"ip link set wlan0 down && echo 'blacklist cfg80211' >> /etc/modprobe.d/wireless.conf"
register_control "3.4.2" \
"Network Configuration" \
"Ensure DCCP is disabled" \
"2" \
"yes" \
"The Datagram Congestion Control Protocol is a transport protocol that is rarely used on production systems. Disabling DCCP reduces the kernel attack surface by removing an unnecessary protocol handler. Vulnerabilities in rarely audited protocol implementations can provide exploitation opportunities." \
"echo 'install dccp /bin/true' >> /etc/modprobe.d/dccp.conf && echo 'blacklist dccp' >> /etc/modprobe.d/dccp.conf"
register_control "3.4.3" \
"Network Configuration" \
"Ensure SCTP is disabled" \
"2" \
"yes" \
"The Stream Control Transmission Protocol is a transport protocol primarily used in telecommunications. Unless specifically required SCTP should be disabled to minimize the kernel attack surface. Reducing the number of loaded protocol modules limits the potential for kernel-level exploitation." \
"echo 'install sctp /bin/true' >> /etc/modprobe.d/sctp.conf && echo 'blacklist sctp' >> /etc/modprobe.d/sctp.conf"
register_control "3.4.4" \
"Network Configuration" \
"Ensure RDS is disabled" \
"2" \
"yes" \
"The Reliable Datagram Sockets protocol is a transport protocol developed by Oracle for high-performance cluster communication. RDS is not needed on most systems and has had critical kernel vulnerabilities in the past. Disabling RDS eliminates a protocol module with a history of security issues." \
"echo 'install rds /bin/true' >> /etc/modprobe.d/rds.conf && echo 'blacklist rds' >> /etc/modprobe.d/rds.conf"
register_control "3.4.5" \
"Network Configuration" \
"Ensure TIPC is disabled" \
"2" \
"yes" \
"The Transparent Inter-Process Communication protocol is a cluster communication protocol designed for intra-cluster messaging. TIPC is unnecessary on systems that are not part of a TIPC-based cluster. Disabling this module reduces kernel attack surface by removing an uncommon network protocol handler." \
"echo 'install tipc /bin/true' >> /etc/modprobe.d/tipc.conf && echo 'blacklist tipc' >> /etc/modprobe.d/tipc.conf"
register_control "4.1.1" \
"Logging and Auditing" \
"Ensure auditd is installed" \
"2" \
"yes" \
"The Linux Audit daemon provides detailed system call auditing and security event logging. Auditd is essential for forensic analysis, compliance monitoring, and detecting unauthorized access attempts. Without auditd the system lacks the ability to record detailed security-relevant events." \
"apt-get install -y auditd audispd-plugins"
register_control "4.1.2" \
"Logging and Auditing" \
"Ensure auditd service is enabled" \
"2" \
"yes" \
"The auditd service must be enabled to start automatically at boot to ensure continuous security event logging. A gap in audit logging between boot and manual service start could allow attackers to operate undetected. Enabling the service guarantees audit coverage from the earliest possible point in the boot process." \
"systemctl enable auditd"
register_control "4.1.3" \
"Logging and Auditing" \
"Ensure auditing for processes that start prior to auditd is enabled" \
"2" \
"yes" \
"Some processes start before the auditd service is running and their activity would not be captured by default. Adding audit=1 to the kernel boot parameters ensures the kernel begins auditing from the earliest stages of boot. This closes the window where malicious activity could occur before the audit daemon starts." \
"sed -i 's/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"audit=1 /' /etc/default/grub && update-grub"
register_control "4.1.4" \
"Logging and Auditing" \
"Ensure audit_backlog_limit is sufficient" \
"2" \
"yes" \
"The audit_backlog_limit parameter sets the maximum number of audit records that can be queued before the kernel begins dropping events. An insufficient backlog limit can cause audit events to be lost during periods of high system activity. Setting this to at least 8192 ensures adequate buffer space for burst audit activity." \
"sed -i 's/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"audit_backlog_limit=8192 /' /etc/default/grub && update-grub"
register_control "4.1.5" \
"Logging and Auditing" \
"Ensure events that modify date and time information are collected" \
"2" \
"yes" \
"Monitoring changes to the system clock is critical because attackers often modify timestamps to cover their tracks. Audit rules should capture all calls to adjtimex, settimeofday, stime, and clock_settime as well as changes to /etc/localtime. Time modification events are essential for maintaining the integrity of audit log timelines." \
"echo '-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change' >> /etc/audit/rules.d/cisaudit.rules && echo '-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/localtime -p wa -k time-change' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.6" \
"Logging and Auditing" \
"Ensure events that modify user/group information are collected" \
"2" \
"yes" \
"Changes to user and group files such as /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow must be monitored. Unauthorized modifications to these files could indicate an attacker creating backdoor accounts or escalating privileges. Audit rules on identity files provide early detection of account manipulation." \
"echo '-w /etc/group -p wa -k identity' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/passwd -p wa -k identity' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/gshadow -p wa -k identity' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/shadow -p wa -k identity' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.7" \
"Logging and Auditing" \
"Ensure events that modify the system network environment are collected" \
"2" \
"yes" \
"Network configuration changes including modifications to /etc/hosts, /etc/hostname, and sethostname system calls should be audited. Unauthorized network configuration changes could redirect traffic or hide malicious activity. Monitoring these events helps detect network-based attacks and unauthorized system reconfiguration." \
"echo '-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/issue -p wa -k system-locale' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/hosts -p wa -k system-locale' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/hostname -p wa -k system-locale' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.8" \
"Logging and Auditing" \
"Ensure events that modify the system MAC policy are collected" \
"2" \
"yes" \
"Mandatory Access Control policies defined by AppArmor or SELinux provide an additional layer of access restrictions beyond standard permissions. Changes to MAC policies could weaken security controls or disable protection for critical services. Auditing modifications to /etc/apparmor/ and /etc/selinux/ detects unauthorized policy weakening." \
"echo '-w /etc/apparmor/ -p wa -k MAC-policy' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /etc/apparmor.d/ -p wa -k MAC-policy' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.9" \
"Logging and Auditing" \
"Ensure login and logout events are collected" \
"2" \
"yes" \
"Login and logout events recorded in /var/log/faillog, /var/log/lastlog, and /var/log/tallylog provide critical authentication audit trails. Monitoring these files helps detect brute force attacks, unauthorized access, and anomalous login patterns. These records are essential for security incident investigation and compliance reporting." \
"echo '-w /var/log/faillog -p wa -k logins' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /var/log/lastlog -p wa -k logins' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /var/log/tallylog -p wa -k logins' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.10" \
"Logging and Auditing" \
"Ensure session initiation information is collected" \
"2" \
"yes" \
"Session initiation files such as /var/run/utmp, /var/log/wtmp, and /var/log/btmp track active sessions and login history. Monitoring these files provides visibility into who is logged in and historical session data. Unauthorized modifications to session tracking files could indicate an attacker attempting to hide their presence." \
"echo '-w /var/run/utmp -p wa -k session' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /var/log/wtmp -p wa -k logins' >> /etc/audit/rules.d/cisaudit.rules && echo '-w /var/log/btmp -p wa -k logins' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.11" \
"Logging and Auditing" \
"Ensure discretionary access control permission modification events are collected" \
"2" \
"yes" \
"DAC permission changes via chmod, fchmod, chown, fchown, lchown, setxattr, and similar system calls should be audited. Unauthorized permission changes could grant attackers access to sensitive files or enable privilege escalation. Collecting these events provides a complete record of who changed permissions on which files." \
"echo '-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -k perm_mod' >> /etc/audit/rules.d/cisaudit.rules && echo '-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -k perm_mod' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.12" \
"Logging and Auditing" \
"Ensure unsuccessful unauthorized file access attempts are collected" \
"2" \
"yes" \
"Failed file access attempts where the system returns EACCES or EPERM indicate either misconfigured applications or potential attack activity. Monitoring these failures helps detect unauthorized users attempting to access files beyond their permission level. Patterns of access failures often precede successful exploitation." \
"echo '-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=4294967295 -k access' >> /etc/audit/rules.d/cisaudit.rules && echo '-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=4294967295 -k access' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.13" \
"Logging and Auditing" \
"Ensure successful file system mounts are collected" \
"2" \
"yes" \
"Monitoring the mount system call detects when users mount filesystems which could be used to introduce unauthorized media or access hidden data. Successful mounts by non-privileged users are particularly suspicious and should be investigated. This audit rule captures all mount operations along with the user identity for forensic analysis." \
"echo '-a always,exit -F arch=b64 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts' >> /etc/audit/rules.d/cisaudit.rules && echo '-a always,exit -F arch=b32 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.1.14" \
"Logging and Auditing" \
"Ensure file deletion events by users are collected" \
"2" \
"yes" \
"Monitoring file deletion system calls such as unlink, unlinkat, rename, and renameat detects when users delete or overwrite files. Attackers often delete log files and other evidence after compromising a system. Collecting file deletion events ensures that evidence destruction attempts are themselves recorded in the audit log." \
"echo '-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete' >> /etc/audit/rules.d/cisaudit.rules && echo '-a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete' >> /etc/audit/rules.d/cisaudit.rules"
register_control "4.2.1" \
"Logging and Auditing" \
"Ensure rsyslog is installed" \
"1" \
"yes" \
"Rsyslog is the standard system logging facility that collects messages from services, the kernel, and applications. Without rsyslog critical system events including security warnings and errors go unrecorded. Installing rsyslog is the foundation for all system-level log collection and analysis." \
"apt-get install -y rsyslog"
register_control "4.2.2" \
"Logging and Auditing" \
"Ensure rsyslog service is enabled" \
"1" \
"yes" \
"The rsyslog service must be enabled to start automatically at boot to ensure continuous logging coverage. A system without active logging cannot detect or record security incidents, hardware failures, or application errors. Enabling rsyslog ensures log collection begins immediately at system startup." \
"systemctl enable rsyslog"
register_control "4.2.3" \
"Logging and Auditing" \
"Ensure rsyslog default file permissions configured" \
"1" \
"yes" \
"Log files should be created with restrictive permissions to prevent unauthorized users from reading sensitive log data. The FileCreateMode setting in rsyslog controls the default permissions applied to newly created log files. Setting this to 0640 ensures only root and the syslog group can access log contents." \
"echo '\$FileCreateMode 0640' >> /etc/rsyslog.conf && systemctl restart rsyslog"
register_control "4.2.4" \
"Logging and Auditing" \
"Ensure logging is configured" \
"1" \
"no" \
"System logging should be configured to capture relevant events from all critical services and facilities. The rsyslog configuration should direct logs to appropriate files based on facility and severity. Proper logging configuration ensures that security events are recorded and available for review and incident response." \
"vi /etc/rsyslog.conf"
register_control "5.1.1" \
"Access, Authentication and Authorization" \
"Ensure cron daemon is enabled and running" \
"1" \
"yes" \
"The cron daemon executes scheduled commands and is essential for automated system maintenance tasks including log rotation and security updates. If cron is disabled scheduled security tasks such as ClamAV scans and AIDE integrity checks will not run. Ensuring cron is enabled maintains the automated security posture of the system." \
"systemctl enable cron && systemctl start cron"
register_control "5.1.2" \
"Access, Authentication and Authorization" \
"Ensure permissions on /etc/crontab are configured" \
"1" \
"yes" \
"The /etc/crontab file contains system-wide cron job definitions that run with elevated privileges. Improper permissions on this file could allow unauthorized users to schedule malicious commands as root. Restricting access to root only prevents privilege escalation through crontab manipulation." \
"chown root:root /etc/crontab && chmod 600 /etc/crontab"
register_control "5.1.3" \
"Access, Authentication and Authorization" \
"Ensure permissions on /etc/cron.hourly are configured" \
"1" \
"yes" \
"The /etc/cron.hourly directory contains scripts that execute every hour with root privileges. Unrestricted access to this directory would allow any user to place malicious scripts that run as root. Setting restrictive permissions ensures only authorized administrators can manage hourly cron jobs." \
"chown root:root /etc/cron.hourly && chmod 700 /etc/cron.hourly"
register_control "5.1.4" \
"Access, Authentication and Authorization" \
"Ensure permissions on /etc/cron.daily are configured" \
"1" \
"yes" \
"The /etc/cron.daily directory contains scripts that execute daily with root privileges including log rotation and package updates. Unauthorized access could allow attackers to insert persistent backdoors that execute once per day. Restricting this directory to root prevents privilege escalation through daily cron job manipulation." \
"chown root:root /etc/cron.daily && chmod 700 /etc/cron.daily"
register_control "5.2.1" \
"Access, Authentication and Authorization" \
"Ensure permissions on /etc/ssh/sshd_config are configured" \
"1" \
"yes" \
"The sshd_config file controls the behavior of the SSH daemon including authentication methods and access restrictions. If this file is writable by unauthorized users an attacker could weaken SSH security settings to facilitate access. Restricting permissions ensures only root can view or modify the SSH server configuration." \
"chown root:root /etc/ssh/sshd_config && chmod 600 /etc/ssh/sshd_config"
register_control "5.2.2" \
"Access, Authentication and Authorization" \
"Ensure SSH access is limited" \
"1" \
"yes" \
"SSH access should be restricted to specific users or groups using AllowUsers, AllowGroups, DenyUsers, or DenyGroups directives. Without explicit access controls any valid user account can authenticate via SSH potentially including service accounts. Limiting SSH access reduces the number of accounts that can be targeted for remote brute force attacks." \
"sed -i 's/^#*AllowUsers.*/AllowUsers root/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.3" \
"Access, Authentication and Authorization" \
"Ensure permissions on SSH private host key files are configured" \
"1" \
"yes" \
"SSH private host key files must be protected from unauthorized access as they authenticate the server to clients. Compromised host keys allow attackers to impersonate the server and perform man-in-the-middle attacks. These files should be owned by root with permissions set to 600 to prevent any non-root access." \
"find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chown root:root {} \\; -exec chmod 600 {} \\;"
register_control "5.2.4" \
"Access, Authentication and Authorization" \
"Ensure SSH LogLevel is appropriate" \
"1" \
"yes" \
"SSH LogLevel controls the verbosity of the SSH daemon logging and should be set to INFO or VERBOSE for adequate security monitoring. Insufficient logging prevents detection of brute force attacks and unauthorized access attempts. The INFO level provides a balance between useful security data and log volume." \
"sed -i 's/^#*LogLevel.*/LogLevel INFO/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.5" \
"Access, Authentication and Authorization" \
"Ensure SSH X11 forwarding is disabled" \
"2" \
"yes" \
"X11 forwarding allows graphical applications to be tunneled over SSH which introduces security risks from the X11 protocol. The X11 protocol was not designed with security in mind and forwarding can expose the local X server to attacks from the remote system. Disabling X11 forwarding eliminates this attack vector on servers that do not need graphical application support." \
"sed -i 's/^#*X11Forwarding.*/X11Forwarding no/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.6" \
"Access, Authentication and Authorization" \
"Ensure SSH MaxAuthTries is set to 4 or less" \
"1" \
"yes" \
"MaxAuthTries limits the number of authentication attempts permitted per SSH connection. Setting this to 4 or less slows down brute force attacks by forcing the attacker to establish new connections frequently. A lower value combined with fail2ban provides effective protection against automated password guessing." \
"sed -i 's/^#*MaxAuthTries.*/MaxAuthTries 4/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.7" \
"Access, Authentication and Authorization" \
"Ensure SSH IgnoreRhosts is enabled" \
"1" \
"yes" \
"The IgnoreRhosts parameter prevents SSH from using the legacy .rhosts and .shosts files for host-based authentication. These files allow authentication without passwords based solely on the source hostname which can be trivially spoofed. Enabling IgnoreRhosts forces proper cryptographic authentication for all SSH sessions." \
"sed -i 's/^#*IgnoreRhosts.*/IgnoreRhosts yes/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.8" \
"Access, Authentication and Authorization" \
"Ensure SSH root login is disabled" \
"1" \
"yes" \
"Allowing direct root login via SSH provides attackers with a known username to target for brute force attacks. Disabling root login forces administrators to authenticate with personal accounts before using sudo for privilege escalation. This improves accountability by ensuring all administrative actions are traceable to individual users." \
"sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.9" \
"Access, Authentication and Authorization" \
"Ensure SSH PermitEmptyPasswords is disabled" \
"1" \
"yes" \
"The PermitEmptyPasswords parameter controls whether accounts with empty passwords can authenticate via SSH. Allowing empty passwords completely undermines authentication security and gives attackers trivial access. This must be disabled to ensure all SSH connections require proper credential verification." \
"sed -i 's/^#*PermitEmptyPasswords.*/PermitEmptyPasswords no/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.10" \
"Access, Authentication and Authorization" \
"Ensure SSH PermitUserEnvironment is disabled" \
"1" \
"yes" \
"The PermitUserEnvironment option allows users to set environment variables that could modify the behavior of SSH sessions. Attackers can use this to set LD_PRELOAD or PATH variables to load malicious libraries or override system commands. Disabling this option prevents environment-based attacks through SSH sessions." \
"sed -i 's/^#*PermitUserEnvironment.*/PermitUserEnvironment no/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.11" \
"Access, Authentication and Authorization" \
"Ensure only strong ciphers are used" \
"1" \
"yes" \
"SSH cipher configuration determines the encryption algorithms used to protect session confidentiality. Weak ciphers such as 3des-cbc, arcfour, and blowfish can be broken with modern computing resources. Restricting SSH to strong ciphers like chacha20-poly1305 and aes256-gcm ensures session data remains protected." \
"sed -i 's/^#*Ciphers.*/Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.12" \
"Access, Authentication and Authorization" \
"Ensure only strong MAC algorithms are used" \
"1" \
"yes" \
"Message Authentication Code algorithms ensure the integrity of SSH traffic by detecting tampering. Weak MAC algorithms such as hmac-md5 and hmac-sha1 are vulnerable to collision attacks that could allow traffic modification. Configuring only strong MACs like hmac-sha2-512-etm ensures reliable integrity verification of all SSH communications." \
"sed -i 's/^#*MACs.*/MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.13" \
"Access, Authentication and Authorization" \
"Ensure only strong Key Exchange algorithms are used" \
"1" \
"yes" \
"Key Exchange algorithms negotiate the shared secret used to derive session encryption keys. Weak key exchange methods like diffie-hellman-group1-sha1 use small key sizes vulnerable to offline attacks. Restricting to curve25519-sha256 and strong diffie-hellman groups ensures the key exchange cannot be compromised." \
"sed -i 's/^#*KexAlgorithms.*/KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.2.14" \
"Access, Authentication and Authorization" \
"Ensure SSH LoginGraceTime is set to one minute or less" \
"1" \
"yes" \
"LoginGraceTime sets the maximum time allowed for a user to complete authentication after connecting to SSH. A long grace time allows attackers to hold open unauthenticated connections consuming server resources. Setting this to 60 seconds or less limits the window for brute force attacks and reduces resource consumption from idle connections." \
"sed -i 's/^#*LoginGraceTime.*/LoginGraceTime 60/' /etc/ssh/sshd_config && systemctl restart sshd"
register_control "5.3.1" \
"Access, Authentication and Authorization" \
"Ensure password creation requirements are configured" \
"1" \
"yes" \
"Password quality modules like pam_pwquality enforce minimum complexity requirements for user passwords. Without these requirements users can set trivially guessable passwords that are vulnerable to brute force and dictionary attacks. The 2019 Collection #1 breach exposed 773 million credentials many of which used weak passwords that complexity rules would have prevented." \
"apt-get install -y libpam-pwquality && echo 'password requisite pam_pwquality.so retry=3' >> /etc/pam.d/common-password"
register_control "5.4.1" \
"Access, Authentication and Authorization" \
"Ensure password expiration is 365 days or less" \
"1" \
"yes" \
"PASS_MAX_DAYS in /etc/login.defs sets the maximum number of days a password may be used before it must be changed. Requiring periodic password changes limits the window during which a compromised password can be exploited. The NIST 800-63B guidelines recommend expiration only when compromise is suspected but CIS maintains this control for defense in depth." \
"sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 365/' /etc/login.defs"
register_control "5.4.2" \
"Access, Authentication and Authorization" \
"Ensure minimum days between password changes is configured" \
"1" \
"yes" \
"PASS_MIN_DAYS prevents users from immediately changing passwords back to a previous value after a forced change. Without a minimum interval users can cycle through password history to reuse a compromised password. Setting this to at least 1 day forces meaningful password rotation." \
"sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 1/' /etc/login.defs"
register_control "5.4.3" \
"Access, Authentication and Authorization" \
"Ensure password expiration warning days is 7 or more" \
"1" \
"yes" \
"PASS_WARN_AGE controls how many days before password expiration the user receives a warning. Adequate warning prevents account lockouts caused by expired passwords which can disrupt operations and trigger helpdesk overhead. Seven days provides sufficient notice for users to change their password before expiration." \
"sed -i 's/^PASS_WARN_AGE.*/PASS_WARN_AGE 7/' /etc/login.defs"
register_control "5.5.1" \
"Access, Authentication and Authorization" \
"Ensure account lockout for failed password attempts is configured" \
"1" \
"yes" \
"Account lockout after failed authentication attempts prevents brute force password attacks against local and remote accounts. The pam_faillock module tracks failed attempts and temporarily locks accounts after a configurable threshold. Without lockout an attacker can attempt unlimited password guesses against any account on the system." \
"echo 'auth required pam_faillock.so preauth' >> /etc/pam.d/common-auth && echo 'auth required pam_faillock.so authfail' >> /etc/pam.d/common-auth"
register_control "6.1.1" \
"System Maintenance" \
"Ensure permissions on /etc/passwd are configured" \
"1" \
"yes" \
"The /etc/passwd file contains user account information that all users and many system processes need to read. This file must be owned by root with permissions set to 644 to allow read access while preventing unauthorized modifications. Incorrect permissions on /etc/passwd could allow attackers to add accounts or modify existing ones." \
"chown root:root /etc/passwd && chmod 644 /etc/passwd"
register_control "6.1.2" \
"System Maintenance" \
"Ensure permissions on /etc/shadow are configured" \
"1" \
"yes" \
"The /etc/shadow file stores hashed passwords and must have the most restrictive permissions possible. This file should be owned by root with group shadow and permissions set to 640 to prevent unauthorized password hash access. Exposed password hashes can be cracked offline giving attackers valid credentials." \
"chown root:shadow /etc/shadow && chmod 640 /etc/shadow"
register_control "6.1.3" \
"System Maintenance" \
"Ensure permissions on /etc/group are configured" \
"1" \
"yes" \
"The /etc/group file defines group membership information used for access control decisions across the system. This file must be owned by root with 644 permissions to allow read access while preventing unauthorized group modifications. Tampering with group membership could grant attackers access to resources protected by group permissions." \
"chown root:root /etc/group && chmod 644 /etc/group"
register_control "6.1.4" \
"System Maintenance" \
"Ensure permissions on /etc/gshadow are configured" \
"1" \
"yes" \
"The /etc/gshadow file contains encrypted group passwords and group administrator information. This file should be owned by root with group shadow and permissions set to 640 similar to /etc/shadow. Unauthorized access to gshadow could reveal group passwords enabling lateral movement within the system." \
"chown root:shadow /etc/gshadow && chmod 640 /etc/gshadow"
register_control "6.1.5" \
"System Maintenance" \
"Ensure permissions on /etc/passwd- are configured" \
"1" \
"yes" \
"The /etc/passwd- file is a backup copy of /etc/passwd created automatically by system utilities. This backup file must have the same restrictive permissions as the original to prevent information leakage. Attackers could read an improperly secured backup to enumerate system users and their properties." \
"chown root:root /etc/passwd- && chmod 644 /etc/passwd-"
register_control "6.2.1" \
"System Maintenance" \
"Ensure no duplicate UIDs exist" \
"1" \
"yes" \
"Each user account must have a unique User ID to ensure proper access control and audit trail attribution. Duplicate UIDs cause multiple users to share the same file permissions and appear identical in log files. Resolving duplicate UIDs ensures that every action on the system can be traced to a specific user account." \
"cat /etc/passwd | cut -f3 -d: | sort -n | uniq -d"
register_control "6.2.2" \
"System Maintenance" \
"Ensure no duplicate GIDs exist" \
"1" \
"yes" \
"Each group must have a unique Group ID to ensure correct group-based access control enforcement. Duplicate GIDs cause different group names to share the same access permissions leading to unintended access grants. Eliminating duplicate GIDs ensures that group membership provides the expected level of access." \
"cat /etc/group | cut -f3 -d: | sort -n | uniq -d"
register_control "6.2.3" \
"System Maintenance" \
"Ensure no duplicate user names exist" \
"1" \
"yes" \
"Duplicate user names in /etc/passwd would cause ambiguity in permission assignments and audit logging. Systems may behave unpredictably when multiple entries share the same username potentially granting unintended access. Each user name must be unique to ensure consistent authentication and authorization behavior." \
"cat /etc/passwd | cut -f1 -d: | sort | uniq -d"
register_control "6.2.4" \
"System Maintenance" \
"Ensure root is the only UID 0 account" \
"1" \
"yes" \
"UID 0 grants unrestricted superuser privileges and should only be assigned to the root account. Additional UID 0 accounts create hidden administrator access that bypasses normal sudo-based privilege escalation auditing. Any account other than root with UID 0 should be investigated as a potential backdoor." \
"awk -F: '(\$3 == 0) { print \$1 }' /etc/passwd"
register_control "6.2.5" \
"System Maintenance" \
"Ensure no legacy + entries exist in passwd, shadow, or group" \
"1" \
"yes" \
"Legacy plus entries in /etc/passwd, /etc/shadow, or /etc/group were used with NIS to include external directory data. These entries can introduce security vulnerabilities by importing uncontrolled account or group information. Removing legacy + entries eliminates the risk of unintended account injection from external sources." \
"sed -i '/^+/d' /etc/passwd /etc/shadow /etc/group"

View File

@ -0,0 +1,92 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# baseline.sh
declare -gA BASELINE_STATUS
save_baseline() {
local file="$1"
emit_json_report > "$file"
}
load_baseline() {
local file="$1"
BASELINE_STATUS=()
if [[ ! -f "$file" ]]; then
warn "Baseline file not found: ${file}"
return 1
fi
local current_id=""
local id_pattern='"id":[[:space:]]*"([^"]+)"'
local status_pattern='"status":[[:space:]]*"([^"]+)"'
while IFS= read -r line; do
if [[ "$line" =~ $id_pattern ]]; then
current_id="${BASH_REMATCH[1]}"
fi
if [[ -n "$current_id" && "$line" =~ $status_pattern ]]; then
BASELINE_STATUS["$current_id"]="${BASH_REMATCH[1]}"
current_id=""
fi
done < "$file"
}
diff_baseline() {
local file="$1"
if ! load_baseline "$file"; then
return 1
fi
local regressions=0
local improvements=0
local new_controls=0
local unchanged=0
echo ""
echo -e "${BOLD}Baseline Comparison${RESET} (vs ${file})"
echo -e "$(printf '%.0s─' {1..60})"
local id baseline_stat current_stat
for id in "${RESULT_ORDER[@]}"; do
current_stat="${RESULT_STATUS[$id]}"
baseline_stat="${BASELINE_STATUS[$id]:-}"
if [[ -z "$baseline_stat" ]]; then
((new_controls++)) || true
printf " ${CYAN}+${RESET} %-10s %s ${DIM}(new)${RESET}\n" "$id" "${CTRL_TITLE[$id]}"
continue
fi
if [[ "$baseline_stat" == "$current_stat" ]]; then
((unchanged++)) || true
continue
fi
if [[ "$baseline_stat" == "$STATUS_PASS" && "$current_stat" == "$STATUS_FAIL" ]]; then
((regressions++)) || true
printf " ${RED}-${RESET} %-10s %s ${RED}(PASS → FAIL)${RESET}\n" "$id" "${CTRL_TITLE[$id]}"
elif [[ "$baseline_stat" == "$STATUS_FAIL" && "$current_stat" == "$STATUS_PASS" ]]; then
((improvements++)) || true
printf " ${GREEN}+${RESET} %-10s %s ${GREEN}(FAIL → PASS)${RESET}\n" "$id" "${CTRL_TITLE[$id]}"
else
printf " ${YELLOW}~${RESET} %-10s %s ${YELLOW}(${baseline_stat}${current_stat})${RESET}\n" "$id" "${CTRL_TITLE[$id]}"
fi
done
local removed=0
for id in "${!BASELINE_STATUS[@]}"; do
if [[ -z "${RESULT_STATUS[$id]:-}" ]]; then
((removed++)) || true
printf " ${DIM}x${RESET} %-10s ${DIM}(removed)${RESET}\n" "$id"
fi
done
echo ""
echo -e "${BOLD}Summary:${RESET} ${GREEN}${improvements} improved${RESET}, ${RED}${regressions} regressed${RESET}, ${unchanged} unchanged, ${new_controls} new, ${removed} removed"
if (( regressions > 0 )); then
warn "${regressions} regression(s) detected"
fi
}

View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# constants.sh
declare -gr VERSION="1.0.0"
declare -gr CIS_BENCHMARK="CIS Debian Linux 12 Benchmark v1.1.0"
declare -gr MIN_BASH_VERSION=4
declare -gr EXIT_OK=0
declare -gr EXIT_FAIL=1
declare -gr EXIT_USAGE=2
declare -gr RED='\033[0;31m'
declare -gr GREEN='\033[0;32m'
declare -gr YELLOW='\033[1;33m'
declare -gr CYAN='\033[0;36m'
declare -gr BLUE='\033[0;34m'
declare -gr MAGENTA='\033[0;35m'
declare -gr BOLD='\033[1m'
declare -gr DIM='\033[2m'
declare -gr RESET='\033[0m'
declare -gr STATUS_PASS="PASS"
declare -gr STATUS_FAIL="FAIL"
declare -gr STATUS_WARN="WARN"
declare -gr STATUS_SKIP="SKIP"
declare -g SYSROOT="/"
declare -gr SECTION_INITIAL_SETUP="Initial Setup"
declare -gr SECTION_SERVICES="Services"
declare -gr SECTION_NETWORK="Network Configuration"
declare -gr SECTION_LOGGING="Logging and Auditing"
declare -gr SECTION_ACCESS="Access, Authentication and Authorization"
declare -gr SECTION_MAINTENANCE="System Maintenance"
declare -ga SECTION_ORDER=(
"$SECTION_INITIAL_SETUP"
"$SECTION_SERVICES"
"$SECTION_NETWORK"
"$SECTION_LOGGING"
"$SECTION_ACCESS"
"$SECTION_MAINTENANCE"
)

View File

@ -0,0 +1,89 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# engine.sh
declare -gA SCORE_BY_SECTION
declare -gA SECTION_PASS
declare -gA SECTION_FAIL
declare -gA SECTION_WARN
declare -gA SECTION_SKIP
declare -g SCORE_OVERALL=0
declare -g SCORE_LEVEL1=0
declare -g SCORE_LEVEL2=0
compute_scores() {
local section
for section in "${SECTION_ORDER[@]}"; do
SECTION_PASS["$section"]=0
SECTION_FAIL["$section"]=0
SECTION_WARN["$section"]=0
SECTION_SKIP["$section"]=0
done
local id
for id in "${RESULT_ORDER[@]}"; do
section="${CTRL_SECTION[$id]}"
case "${RESULT_STATUS[$id]}" in
"$STATUS_PASS") ((SECTION_PASS["$section"]++)) || true ;;
"$STATUS_FAIL") ((SECTION_FAIL["$section"]++)) || true ;;
"$STATUS_WARN") ((SECTION_WARN["$section"]++)) || true ;;
"$STATUS_SKIP") ((SECTION_SKIP["$section"]++)) || true ;;
esac
done
for section in "${SECTION_ORDER[@]}"; do
local p="${SECTION_PASS[$section]}"
local f="${SECTION_FAIL[$section]}"
local total=$((p + f))
if (( total > 0 )); then
SCORE_BY_SECTION["$section"]=$(awk "BEGIN { printf \"%.1f\", ($p / $total) * 100 }")
else
SCORE_BY_SECTION["$section"]="N/A"
fi
done
local scored_total=$((TOTAL_PASS + TOTAL_FAIL))
if (( scored_total > 0 )); then
SCORE_OVERALL=$(awk "BEGIN { printf \"%.1f\", ($TOTAL_PASS / $scored_total) * 100 }")
else
SCORE_OVERALL="0.0"
fi
_compute_level_score 1
SCORE_LEVEL1="$_LEVEL_SCORE"
_compute_level_score 2
SCORE_LEVEL2="$_LEVEL_SCORE"
}
_compute_level_score() {
local level="$1"
local pass=0
local fail=0
local id
for id in "${RESULT_ORDER[@]}"; do
if [[ "${CTRL_LEVEL[$id]}" == "$level" ]]; then
case "${RESULT_STATUS[$id]}" in
"$STATUS_PASS") ((pass++)) || true ;;
"$STATUS_FAIL") ((fail++)) || true ;;
esac
fi
done
local total=$((pass + fail))
if (( total > 0 )); then
_LEVEL_SCORE=$(awk "BEGIN { printf \"%.1f\", ($pass / $total) * 100 }")
else
_LEVEL_SCORE="N/A"
fi
}
get_section_total() {
local section="$1"
local p="${SECTION_PASS[$section]:-0}"
local f="${SECTION_FAIL[$section]:-0}"
local w="${SECTION_WARN[$section]:-0}"
local s="${SECTION_SKIP[$section]:-0}"
echo $((p + f + w + s))
}

View File

@ -0,0 +1,93 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# registry.sh
declare -gA CTRL_TITLE
declare -gA CTRL_SECTION
declare -gA CTRL_LEVEL
declare -gA CTRL_SCORED
declare -gA CTRL_DESCRIPTION
declare -gA CTRL_REMEDIATION
declare -gA CTRL_CHECK_FN
declare -gA RESULT_STATUS
declare -gA RESULT_EVIDENCE
declare -ga RESULT_ORDER=()
declare -g TOTAL_PASS=0
declare -g TOTAL_FAIL=0
declare -g TOTAL_WARN=0
declare -g TOTAL_SKIP=0
declare -ga REGISTERED_IDS=()
register_control() {
local id="$1"
local section="$2"
local title="$3"
local level="$4"
local scored="$5"
local description="$6"
local remediation="$7"
CTRL_TITLE["$id"]="$title"
CTRL_SECTION["$id"]="$section"
CTRL_LEVEL["$id"]="$level"
CTRL_SCORED["$id"]="$scored"
CTRL_DESCRIPTION["$id"]="$description"
CTRL_REMEDIATION["$id"]="$remediation"
local fn_name="check_${id//\./_}"
CTRL_CHECK_FN["$id"]="$fn_name"
REGISTERED_IDS+=("$id")
}
record_result() {
local id="$1"
local status="$2"
local evidence="$3"
RESULT_STATUS["$id"]="$status"
RESULT_EVIDENCE["$id"]="$evidence"
RESULT_ORDER+=("$id")
case "$status" in
"$STATUS_PASS") ((TOTAL_PASS++)) || true ;;
"$STATUS_FAIL") ((TOTAL_FAIL++)) || true ;;
"$STATUS_WARN") ((TOTAL_WARN++)) || true ;;
"$STATUS_SKIP") ((TOTAL_SKIP++)) || true ;;
esac
}
reset_results() {
RESULT_STATUS=()
RESULT_EVIDENCE=()
RESULT_ORDER=()
TOTAL_PASS=0
TOTAL_FAIL=0
TOTAL_WARN=0
TOTAL_SKIP=0
}
get_controls_for_section() {
local section="$1"
local id
for id in "${REGISTERED_IDS[@]}"; do
if [[ "${CTRL_SECTION[$id]}" == "$section" ]]; then
echo "$id"
fi
done
}
get_controls_for_level() {
local level="$1"
local id
for id in "${REGISTERED_IDS[@]}"; do
if [[ "${CTRL_LEVEL[$id]}" == "$level" ]]; then
echo "$id"
fi
done
}
get_total_controls() {
echo "${#REGISTERED_IDS[@]}"
}

View File

@ -0,0 +1,434 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# report_html.sh
html_escape() {
local s="$1"
s="${s//&/\&amp;}"
s="${s//</\&lt;}"
s="${s//>/\&gt;}"
s="${s//\"/\&quot;}"
printf '%s' "$s"
}
_html_score_color() {
local score="$1"
if [[ "$score" == "N/A" ]]; then
printf '%s' "#565f89"
return
fi
local int_score="${score%.*}"
if (( int_score >= 80 )); then
printf '%s' "#9ece6a"
elif (( int_score >= 60 )); then
printf '%s' "#e0af68"
else
printf '%s' "#f7768e"
fi
}
_html_status_class() {
local status="$1"
case "$status" in
"$STATUS_PASS") printf '%s' "pass" ;;
"$STATUS_FAIL") printf '%s' "fail" ;;
"$STATUS_WARN") printf '%s' "warn" ;;
"$STATUS_SKIP") printf '%s' "skip" ;;
esac
}
_emit_html_head() {
cat <<'CSSEOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CIS Benchmark Audit Report</title>
<style>
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
:root{
--bg:#1a1b26;--card:#24283b;--text:#c0caf5;--text-dim:#565f89;
--pass:#9ece6a;--fail:#f7768e;--warn:#e0af68;--skip:#565f89;
--border:#414868;--code-bg:#1a1b26;--accent:#7aa2f7;
}
html{font-size:16px;scroll-behavior:smooth}
body{
background:var(--bg);color:var(--text);
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;
line-height:1.6;padding:0;margin:0;
}
.container{max-width:1100px;margin:0 auto;padding:1.5rem}
header{text-align:center;padding:2.5rem 1rem 1.5rem;border-bottom:1px solid var(--border)}
header h1{font-size:1.75rem;font-weight:700;color:#c0caf5;margin-bottom:.5rem}
header .meta{font-size:.85rem;color:var(--text-dim);display:flex;flex-wrap:wrap;justify-content:center;gap:.5rem 1.5rem;margin-top:.5rem}
header .meta span{white-space:nowrap}
.dashboard{
display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
gap:1rem;margin:2rem 0;
}
.card{
background:var(--card);border:1px solid var(--border);border-radius:10px;
padding:1.25rem 1rem;text-align:center;
}
.card .label{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;color:var(--text-dim);margin-bottom:.35rem}
.card .value{font-size:1.85rem;font-weight:700}
.card.overall .value{font-size:2.5rem}
.card.pass .value{color:var(--pass)}
.card.fail .value{color:var(--fail)}
.card.warn .value{color:var(--warn)}
.card.skip .value{color:var(--skip)}
.card.total .value{color:var(--accent)}
.level-scores{
display:flex;justify-content:center;gap:2.5rem;margin-bottom:2rem;
flex-wrap:wrap;
}
.level-scores .ls{
background:var(--card);border:1px solid var(--border);border-radius:8px;
padding:.75rem 1.5rem;text-align:center;
}
.level-scores .ls .label{font-size:.75rem;text-transform:uppercase;letter-spacing:.06em;color:var(--text-dim)}
.level-scores .ls .val{font-size:1.35rem;font-weight:700}
h2{font-size:1.25rem;margin:2rem 0 1rem;padding-bottom:.5rem;border-bottom:1px solid var(--border)}
table{width:100%;border-collapse:collapse;margin-bottom:2rem;font-size:.9rem}
thead th{
text-align:left;padding:.6rem .75rem;border-bottom:2px solid var(--border);
font-size:.75rem;text-transform:uppercase;letter-spacing:.06em;color:var(--text-dim);
}
thead th.num{text-align:center}
tbody td{padding:.55rem .75rem;border-bottom:1px solid var(--border)}
tbody td.num{text-align:center;font-variant-numeric:tabular-nums}
tbody td.pass{color:var(--pass)}
tbody td.fail{color:var(--fail)}
tbody td.warn{color:var(--warn)}
tbody td.skip{color:var(--skip)}
tbody td.score{font-weight:600}
.progress-bar{
background:var(--bg);border-radius:6px;height:10px;overflow:hidden;
min-width:80px;border:1px solid var(--border);
}
.progress-fill{height:100%;border-radius:6px;transition:width .3s ease}
.section-group{margin-bottom:1.5rem}
.section-group h3{font-size:1rem;color:var(--accent);margin-bottom:.75rem}
details.control{
background:var(--card);border:1px solid var(--border);border-radius:8px;
margin-bottom:.5rem;overflow:hidden;
}
details.control summary{
display:flex;align-items:center;gap:.65rem;padding:.65rem 1rem;
cursor:pointer;user-select:none;font-size:.9rem;list-style:none;
}
details.control summary::-webkit-details-marker{display:none}
details.control summary::before{
content:"";display:inline-block;width:0;height:0;
border-left:5px solid var(--text-dim);border-top:4px solid transparent;border-bottom:4px solid transparent;
transition:transform .2s ease;flex-shrink:0;
}
details.control[open] summary::before{transform:rotate(90deg)}
.badge{
display:inline-block;padding:.15em .6em;border-radius:999px;
font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.04em;
line-height:1.4;flex-shrink:0;
}
.badge.pass{background:rgba(158,206,106,.15);color:var(--pass)}
.badge.fail{background:rgba(247,118,142,.15);color:var(--fail)}
.badge.warn{background:rgba(224,175,104,.15);color:var(--warn)}
.badge.skip{background:rgba(86,95,137,.2);color:var(--skip)}
.badge.level{background:rgba(122,162,247,.12);color:var(--accent);font-size:.65rem}
.control-id{font-family:"SF Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:.85rem;color:var(--text-dim);flex-shrink:0}
.control-title{flex:1;min-width:0}
.control-detail{
padding:.75rem 1rem 1rem 2.5rem;border-top:1px solid var(--border);
font-size:.85rem;
}
.control-detail .evidence{
background:var(--code-bg);border:1px solid var(--border);border-radius:6px;
padding:.6rem .85rem;margin-bottom:.65rem;
font-family:"SF Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;
font-size:.8rem;color:var(--text-dim);white-space:pre-wrap;word-break:break-word;
}
.control-detail .remediation{color:var(--warn)}
.control-detail .remediation code{
background:var(--code-bg);border:1px solid var(--border);border-radius:4px;
padding:.15em .4em;font-size:.8rem;
font-family:"SF Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;
}
footer{
text-align:center;padding:2rem 1rem;margin-top:2rem;border-top:1px solid var(--border);
font-size:.8rem;color:var(--text-dim);
}
@media(max-width:640px){
.dashboard{grid-template-columns:repeat(2,1fr)}
.card.overall{grid-column:1/-1}
table{font-size:.8rem}
thead th,tbody td{padding:.4rem .5rem}
details.control summary{padding:.5rem .75rem;font-size:.82rem;gap:.45rem}
}
@media print{
:root{--bg:#fff;--card:#f8f8f8;--text:#1a1a1a;--text-dim:#666;--border:#ddd;--code-bg:#f0f0f0}
body{background:#fff;color:#1a1a1a}
.card{box-shadow:none;border:1px solid #ddd}
details.control{break-inside:avoid}
.badge.pass{background:#e8f5e9;color:#2e7d32}
.badge.fail{background:#ffebee;color:#c62828}
.badge.warn{background:#fff8e1;color:#f57f17}
.badge.skip{background:#f5f5f5;color:#757575}
}
</style>
</head>
CSSEOF
}
_emit_html_header() {
local timestamp="$1"
local hostname="$2"
local score_color
score_color=$(_html_score_color "$SCORE_OVERALL")
local total=$((TOTAL_PASS + TOTAL_FAIL + TOTAL_WARN + TOTAL_SKIP))
local l1_display
if [[ "$SCORE_LEVEL1" == "N/A" ]]; then
l1_display="N/A"
else
l1_display="${SCORE_LEVEL1}%"
fi
local l2_display
if [[ "$SCORE_LEVEL2" == "N/A" ]]; then
l2_display="N/A"
else
l2_display="${SCORE_LEVEL2}%"
fi
local l1_color
l1_color=$(_html_score_color "$SCORE_LEVEL1")
local l2_color
l2_color=$(_html_score_color "$SCORE_LEVEL2")
local esc_hostname
esc_hostname=$(html_escape "$hostname")
local esc_os
esc_os=$(html_escape "${DETECTED_ID} ${DETECTED_VERSION}")
local esc_bench
esc_bench=$(html_escape "$CIS_BENCHMARK")
cat <<HEADEREOF
<body>
<div class="container">
<header>
<h1>CIS Benchmark Audit Report</h1>
<div class="meta">
<span>${esc_bench}</span>
<span>${esc_hostname}</span>
<span>OS: ${esc_os}</span>
<span>${timestamp}</span>
</div>
</header>
<section class="dashboard">
<div class="card overall">
<div class="label">Overall Score</div>
<div class="value" style="color:${score_color}">${SCORE_OVERALL}%</div>
</div>
<div class="card total">
<div class="label">Total</div>
<div class="value">${total}</div>
</div>
<div class="card pass">
<div class="label">Pass</div>
<div class="value">${TOTAL_PASS}</div>
</div>
<div class="card fail">
<div class="label">Fail</div>
<div class="value">${TOTAL_FAIL}</div>
</div>
<div class="card warn">
<div class="label">Warn</div>
<div class="value">${TOTAL_WARN}</div>
</div>
<div class="card skip">
<div class="label">Skip</div>
<div class="value">${TOTAL_SKIP}</div>
</div>
</section>
<div class="level-scores">
<div class="ls">
<div class="label">Level 1 Score</div>
<div class="val" style="color:${l1_color}">${l1_display}</div>
</div>
<div class="ls">
<div class="label">Level 2 Score</div>
<div class="val" style="color:${l2_color}">${l2_display}</div>
</div>
</div>
HEADEREOF
}
_emit_html_section_table() {
cat <<'TABLESTART'
<h2>Section Breakdown</h2>
<table>
<thead>
<tr>
<th>Section</th>
<th class="num">Pass</th>
<th class="num">Fail</th>
<th class="num">Warn</th>
<th class="num">Skip</th>
<th class="num">Score</th>
<th>Progress</th>
</tr>
</thead>
<tbody>
TABLESTART
local section
for section in "${SECTION_ORDER[@]}"; do
local p="${SECTION_PASS[$section]:-0}"
local f="${SECTION_FAIL[$section]:-0}"
local w="${SECTION_WARN[$section]:-0}"
local s="${SECTION_SKIP[$section]:-0}"
local score="${SCORE_BY_SECTION[$section]:-N/A}"
local score_display
if [[ "$score" == "N/A" ]]; then
score_display="N/A"
else
score_display="${score}%"
fi
local bar_width
if [[ "$score" == "N/A" ]]; then
bar_width="0"
else
bar_width="$score"
fi
local bar_color
bar_color=$(_html_score_color "$score")
local esc_section
esc_section=$(html_escape "$section")
printf '<tr>\n'
printf '<td>%s</td>\n' "$esc_section"
printf '<td class="num pass">%d</td>\n' "$p"
printf '<td class="num fail">%d</td>\n' "$f"
printf '<td class="num warn">%d</td>\n' "$w"
printf '<td class="num skip">%d</td>\n' "$s"
printf '<td class="num score" style="color:%s">%s</td>\n' "$bar_color" "$score_display"
printf '<td><div class="progress-bar"><div class="progress-fill" style="width:%s%%;background:%s"></div></div></td>\n' "$bar_width" "$bar_color"
printf '</tr>\n'
done
cat <<'TABLEEND'
</tbody>
</table>
TABLEEND
}
_emit_html_details() {
printf '<h2>Detailed Results</h2>\n'
local section
for section in "${SECTION_ORDER[@]}"; do
local has_results=0
local id
for id in "${RESULT_ORDER[@]}"; do
if [[ "${CTRL_SECTION[$id]}" == "$section" ]]; then
has_results=1
break
fi
done
if (( has_results == 0 )); then
continue
fi
local esc_section
esc_section=$(html_escape "$section")
printf '<div class="section-group">\n'
printf '<h3>%s</h3>\n' "$esc_section"
for id in "${RESULT_ORDER[@]}"; do
if [[ "${CTRL_SECTION[$id]}" != "$section" ]]; then
continue
fi
local status="${RESULT_STATUS[$id]}"
local title="${CTRL_TITLE[$id]}"
local level="${CTRL_LEVEL[$id]}"
local evidence="${RESULT_EVIDENCE[$id]:-}"
local remediation="${CTRL_REMEDIATION[$id]:-}"
local cls
cls=$(_html_status_class "$status")
local esc_id
esc_id=$(html_escape "$id")
local esc_title
esc_title=$(html_escape "$title")
local open_attr=""
if [[ "$status" == "$STATUS_FAIL" ]]; then
open_attr=" open"
fi
printf '<details class="control %s"%s>\n' "$cls" "$open_attr"
printf '<summary>\n'
printf '<span class="badge %s">%s</span>\n' "$cls" "$status"
printf '<span class="control-id">%s</span>\n' "$esc_id"
printf '<span class="control-title">%s</span>\n' "$esc_title"
printf '<span class="badge level">L%s</span>\n' "$level"
printf '</summary>\n'
if [[ -n "$evidence" || -n "$remediation" ]]; then
printf '<div class="control-detail">\n'
if [[ -n "$evidence" ]]; then
local esc_evidence
esc_evidence=$(html_escape "$evidence")
printf '<div class="evidence">%s</div>\n' "$esc_evidence"
fi
if [[ -n "$remediation" ]]; then
local esc_remediation
esc_remediation=$(html_escape "$remediation")
printf '<p class="remediation">Remediation: <code>%s</code></p>\n' "$esc_remediation"
fi
printf '</div>\n'
fi
printf '</details>\n'
done
printf '</div>\n'
done
}
_emit_html_footer() {
local esc_version
esc_version=$(html_escape "$VERSION")
cat <<FOOTEREOF
<footer>
cisaudit v${esc_version}
</footer>
</div>
</body>
</html>
FOOTEREOF
}
emit_html_report() {
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S %Z')
local hostname
hostname=$(hostname 2>/dev/null || echo "unknown")
_emit_html_head
_emit_html_header "$timestamp" "$hostname"
_emit_html_section_table
_emit_html_details
_emit_html_footer
}

View File

@ -0,0 +1,118 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# report_json.sh
json_escape() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//$'\n'/\\n}"
s="${s//$'\t'/\\t}"
s="${s//$'\r'/\\r}"
printf '%s' "$s"
}
_json_score() {
local val="$1"
if [[ "$val" == "N/A" ]]; then
printf 'null'
else
printf '%s' "$val"
fi
}
_json_bool() {
local val="$1"
if [[ "$val" == "yes" ]]; then
printf 'true'
else
printf 'false'
fi
}
emit_json_report() {
local timestamp
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
local hn
hn=$(hostname 2>/dev/null || echo "unknown")
local total=$((TOTAL_PASS + TOTAL_FAIL + TOTAL_WARN + TOTAL_SKIP))
printf '{\n'
printf ' "version": "%s",\n' "$(json_escape "$VERSION")"
printf ' "cis_benchmark": "%s",\n' "$(json_escape "$CIS_BENCHMARK")"
printf ' "timestamp": "%s",\n' "$timestamp"
printf ' "hostname": "%s",\n' "$(json_escape "$hn")"
printf ' "os_id": "%s",\n' "$(json_escape "$DETECTED_ID")"
printf ' "os_version": "%s",\n' "$(json_escape "$DETECTED_VERSION")"
printf ' "summary": {\n'
printf ' "total": %d,\n' "$total"
printf ' "pass": %d,\n' "$TOTAL_PASS"
printf ' "fail": %d,\n' "$TOTAL_FAIL"
printf ' "warn": %d,\n' "$TOTAL_WARN"
printf ' "skip": %d,\n' "$TOTAL_SKIP"
printf ' "score_percent": %s,\n' "$(_json_score "$SCORE_OVERALL")"
printf ' "level1_score": %s,\n' "$(_json_score "$SCORE_LEVEL1")"
printf ' "level2_score": %s\n' "$(_json_score "$SCORE_LEVEL2")"
printf ' },\n'
printf ' "sections": [\n'
local sec_count=0
local sec_total="${#SECTION_ORDER[@]}"
for section in "${SECTION_ORDER[@]}"; do
((sec_count++)) || true
local p="${SECTION_PASS[$section]:-0}"
local f="${SECTION_FAIL[$section]:-0}"
local w="${SECTION_WARN[$section]:-0}"
local s="${SECTION_SKIP[$section]:-0}"
local score="${SCORE_BY_SECTION[$section]:-N/A}"
printf ' {\n'
printf ' "name": "%s",\n' "$(json_escape "$section")"
printf ' "pass": %d,\n' "$p"
printf ' "fail": %d,\n' "$f"
printf ' "warn": %d,\n' "$w"
printf ' "skip": %d,\n' "$s"
printf ' "score_percent": %s\n' "$(_json_score "$score")"
printf ' }'
if (( sec_count < sec_total )); then
printf ','
fi
printf '\n'
done
printf ' ],\n'
printf ' "controls": [\n'
local ctrl_count=0
local ctrl_total="${#RESULT_ORDER[@]}"
for id in "${RESULT_ORDER[@]}"; do
((ctrl_count++)) || true
local status="${RESULT_STATUS[$id]}"
local evidence="${RESULT_EVIDENCE[$id]:-}"
local title="${CTRL_TITLE[$id]}"
local ctrl_section="${CTRL_SECTION[$id]}"
local level="${CTRL_LEVEL[$id]}"
local scored="${CTRL_SCORED[$id]}"
local remediation="${CTRL_REMEDIATION[$id]:-}"
printf ' {\n'
printf ' "id": "%s",\n' "$(json_escape "$id")"
printf ' "section": "%s",\n' "$(json_escape "$ctrl_section")"
printf ' "title": "%s",\n' "$(json_escape "$title")"
printf ' "level": %d,\n' "$level"
printf ' "scored": %s,\n' "$(_json_bool "$scored")"
printf ' "status": "%s",\n' "$(json_escape "$status")"
printf ' "evidence": "%s",\n' "$(json_escape "$evidence")"
printf ' "remediation": "%s"\n' "$(json_escape "$remediation")"
printf ' }'
if (( ctrl_count < ctrl_total )); then
printf ','
fi
printf '\n'
done
printf ' ]\n'
printf '}\n'
}

View File

@ -0,0 +1,261 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# report_terminal.sh
_status_color() {
local status="$1"
case "$status" in
"$STATUS_PASS") printf '%b' "$GREEN" ;;
"$STATUS_FAIL") printf '%b' "$RED" ;;
"$STATUS_WARN") printf '%b' "$YELLOW" ;;
"$STATUS_SKIP") printf '%b' "$DIM" ;;
esac
}
_status_symbol() {
local status="$1"
case "$status" in
"$STATUS_PASS") printf '%s' "✔" ;;
"$STATUS_FAIL") printf '%s' "✖" ;;
"$STATUS_WARN") printf '%s' "⚠" ;;
"$STATUS_SKIP") printf '%s' "─" ;;
esac
}
_progress_bar() {
local percentage="$1"
local width=20
local filled
local empty
if [[ "$percentage" == "N/A" ]]; then
printf '%s' "░░░░░░░░░░░░░░░░░░░░"
return
fi
filled=$(awk "BEGIN { printf \"%d\", ($percentage / 100) * $width + 0.5 }")
empty=$((width - filled))
local bar=""
local i
for (( i = 0; i < filled; i++ )); do
bar+="█"
done
for (( i = 0; i < empty; i++ )); do
bar+="░"
done
printf '%s' "$bar"
}
_score_color() {
local score="$1"
if [[ "$score" == "N/A" ]]; then
printf '%b' "$DIM"
return
fi
local int_score="${score%.*}"
if (( int_score >= 80 )); then
printf '%b' "$GREEN"
elif (( int_score >= 60 )); then
printf '%b' "$YELLOW"
else
printf '%b' "$RED"
fi
}
_repeat_char() {
local char="$1"
local count="$2"
local i
for (( i = 0; i < count; i++ )); do
printf '%s' "$char"
done
}
_print_banner() {
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S %Z')
local hostname
hostname=$(hostname 2>/dev/null || echo "unknown")
printf '\n'
printf '%b' "$CYAN"
printf ' _____ ___ ____ _ _ _ _\n'
printf ' / ____|_ _/ ___| / \\ _ _ __| (_) |_\n'
printf ' | | | |\\___ \\ / _ \\| | | |/ _` | | __|\n'
printf ' | |___ | | ___) / ___ \\ |_| | (_| | | |_\n'
printf ' \\____|___|____/_/ \\_\\__,_|\\__,_|_|\\__|\n'
printf '%b' "$RESET"
printf '\n'
printf ' %b%s%b\n' "$BOLD" "$CIS_BENCHMARK" "$RESET"
printf ' %bcisaudit v%s%b | %s | %s\n' "$DIM" "$VERSION" "$RESET" "$hostname" "$timestamp"
printf '\n'
}
_print_summary_cards() {
local total=$((TOTAL_PASS + TOTAL_FAIL + TOTAL_WARN + TOTAL_SKIP))
local score_clr
score_clr=$(_score_color "$SCORE_OVERALL")
printf ' %b┌─────────────────────────────────────────────────────────────────────┐%b\n' "$DIM" "$RESET"
printf ' %b│%b %bOVERALL SCORE%b %b│%b\n' "$DIM" "$RESET" "$BOLD" "$RESET" "$DIM" "$RESET"
printf ' %b│%b %b│%b\n' "$DIM" "$RESET" "$DIM" "$RESET"
printf ' %b│%b %b%s%%%b %b│%b\n' "$DIM" "$RESET" "${score_clr}${BOLD}" "$SCORE_OVERALL" "$RESET" "$DIM" "$RESET"
printf ' %b│%b %b│%b\n' "$DIM" "$RESET" "$DIM" "$RESET"
printf ' %b│%b %bTotal:%b %-6d %b%bPass:%b %-6d %b%bFail:%b %-6d %b%bWarn:%b %-6d %b%bSkip:%b %-4d %b│%b\n' \
"$DIM" "$RESET" \
"$BOLD" "$RESET" "$total" \
"$GREEN" "$BOLD" "$RESET" "$TOTAL_PASS" \
"$RED" "$BOLD" "$RESET" "$TOTAL_FAIL" \
"$YELLOW" "$BOLD" "$RESET" "$TOTAL_WARN" \
"$DIM" "$BOLD" "$RESET" "$TOTAL_SKIP" \
"$DIM" "$RESET"
printf ' %b└─────────────────────────────────────────────────────────────────────┘%b\n' "$DIM" "$RESET"
printf '\n'
}
_print_section_table() {
printf ' %b%-44s %4s %4s %4s %4s %6s%b\n' \
"$BOLD" "Section" "Pass" "Fail" "Warn" "Skip" "Score" "$RESET"
printf ' '
_repeat_char "─" 75
printf '\n'
local section
for section in "${SECTION_ORDER[@]}"; do
local p="${SECTION_PASS[$section]:-0}"
local f="${SECTION_FAIL[$section]:-0}"
local w="${SECTION_WARN[$section]:-0}"
local s="${SECTION_SKIP[$section]:-0}"
local score="${SCORE_BY_SECTION[$section]:-N/A}"
local bar
bar=$(_progress_bar "$score")
local sclr
sclr=$(_score_color "$score")
local score_display
if [[ "$score" == "N/A" ]]; then
score_display=" N/A"
else
score_display=$(printf '%5s%%' "$score")
fi
printf ' %-44s %b%4d%b %b%4d%b %b%4d%b %b%4d%b %b%s%b %b%s%b\n' \
"$section" \
"$GREEN" "$p" "$RESET" \
"$RED" "$f" "$RESET" \
"$YELLOW" "$w" "$RESET" \
"$DIM" "$s" "$RESET" \
"${sclr}${BOLD}" "$score_display" "$RESET" \
"$sclr" "$bar" "$RESET"
done
printf '\n'
}
_print_detail_results() {
local section
for section in "${SECTION_ORDER[@]}"; do
local has_results=0
local id
for id in "${RESULT_ORDER[@]}"; do
if [[ "${CTRL_SECTION[$id]}" == "$section" ]]; then
has_results=1
break
fi
done
if (( has_results == 0 )); then
continue
fi
printf ' %b━━━ %s ━━━%b\n' "$BOLD" "$section" "$RESET"
printf '\n'
for id in "${RESULT_ORDER[@]}"; do
if [[ "${CTRL_SECTION[$id]}" != "$section" ]]; then
continue
fi
local status="${RESULT_STATUS[$id]}"
local title="${CTRL_TITLE[$id]}"
local symbol
symbol=$(_status_symbol "$status")
local clr
clr=$(_status_color "$status")
local suffix=""
if [[ "$status" == "$STATUS_SKIP" ]]; then
suffix=" [SKIPPED]"
fi
printf " ${clr} %s ${BOLD}%-9s ${RESET}${clr}%s%s${RESET}\n" \
"$symbol" "$id" "$title" "$suffix"
if [[ "$status" == "$STATUS_FAIL" ]]; then
local evidence="${RESULT_EVIDENCE[$id]:-}"
local remediation="${CTRL_REMEDIATION[$id]:-}"
if [[ -n "$evidence" ]]; then
printf ' %b Evidence: %s%b\n' "$DIM" "$evidence" "$RESET"
fi
if [[ -n "$remediation" ]]; then
printf ' %b Fix: %s%b\n' "$YELLOW" "$remediation" "$RESET"
fi
fi
if [[ "$status" == "$STATUS_WARN" ]]; then
local evidence="${RESULT_EVIDENCE[$id]:-}"
if [[ -n "$evidence" ]]; then
printf ' %b Evidence: %s%b\n' "$DIM" "$evidence" "$RESET"
fi
fi
done
printf '\n'
done
}
_print_footer() {
local l1_clr
l1_clr=$(_score_color "$SCORE_LEVEL1")
local l2_clr
l2_clr=$(_score_color "$SCORE_LEVEL2")
local ov_clr
ov_clr=$(_score_color "$SCORE_OVERALL")
printf ' '
_repeat_char "═" 75
printf '\n'
local l1_display
if [[ "$SCORE_LEVEL1" == "N/A" ]]; then
l1_display="N/A"
else
l1_display="${SCORE_LEVEL1}%"
fi
local l2_display
if [[ "$SCORE_LEVEL2" == "N/A" ]]; then
l2_display="N/A"
else
l2_display="${SCORE_LEVEL2}%"
fi
printf ' %bLevel 1 Score:%b %b%s%b' "$BOLD" "$RESET" "${l1_clr}${BOLD}" "$l1_display" "$RESET"
printf ' %bLevel 2 Score:%b %b%s%b' "$BOLD" "$RESET" "${l2_clr}${BOLD}" "$l2_display" "$RESET"
printf ' %bOverall Score:%b %b%s%%%b\n' "$BOLD" "$RESET" "${ov_clr}${BOLD}" "$SCORE_OVERALL" "$RESET"
printf ' '
_repeat_char "═" 75
printf '\n'
printf '\n'
}
emit_terminal_report() {
_print_banner
_print_summary_cards
_print_section_table
_print_detail_results
_print_footer
}

View File

@ -0,0 +1,111 @@
#!/usr/bin/env bash
# ©AngelaMos | 2026
# utils.sh
info() { [[ "$QUIET" == "true" ]] || echo -e "${CYAN}[*]${RESET} $1" >&2; }
success() { [[ "$QUIET" == "true" ]] || echo -e "${GREEN}[✔]${RESET} $1" >&2; }
warn() { [[ "$QUIET" == "true" ]] || echo -e "${YELLOW}[!]${RESET} $1" >&2; }
fail() { echo -e "${RED}[✖]${RESET} $1" >&2; exit "$EXIT_FAIL"; }
progress() {
[[ "$QUIET" == "true" ]] && return
printf "\r${DIM}[%s] Checking: %s${RESET}%s" "$1" "$2" "$(printf '%40s')" >&2
}
clear_progress() {
[[ "$QUIET" == "true" ]] && return
printf "\r%80s\r" "" >&2
}
check_bash_version() {
if (( BASH_VERSINFO[0] < MIN_BASH_VERSION )); then
fail "Bash ${MIN_BASH_VERSION}+ required (found ${BASH_VERSION})"
fi
}
check_root() {
if [[ $EUID -ne 0 && "$SYSROOT" == "/" ]]; then
warn "Running without root privileges — some checks will be skipped"
return 1
fi
return 0
}
detect_os() {
local os_release="${SYSROOT}/etc/os-release"
if [[ -f "$os_release" ]]; then
DETECTED_ID=$(grep -oP '^ID=\K.*' "$os_release" | tr -d '"')
DETECTED_VERSION=$(grep -oP '^VERSION_ID=\K.*' "$os_release" | tr -d '"')
else
DETECTED_ID="unknown"
DETECTED_VERSION="unknown"
fi
}
run_cmd() {
if [[ "$SYSROOT" != "/" ]]; then
return 1
fi
"$@" 2>/dev/null
}
file_exists() {
[[ -f "${SYSROOT}${1}" ]]
}
read_file() {
local path="${SYSROOT}${1}"
if [[ -f "$path" ]]; then
cat "$path"
else
return 1
fi
}
get_sysctl() {
local param="$1"
local proc_path="${SYSROOT}/proc/sys/${param//\.//}"
if [[ -f "$proc_path" ]]; then
cat "$proc_path"
return 0
fi
if run_cmd sysctl -n "$param"; then
return 0
fi
return 1
}
get_config_value() {
local file="$1"
local key="$2"
local path="${SYSROOT}${file}"
if [[ ! -f "$path" ]]; then
return 1
fi
grep -Ei "^\s*${key}\s" "$path" | tail -1 | awk '{print $2}'
}
service_is_enabled() {
if run_cmd systemctl is-enabled "$1"; then
return 0
fi
return 1
}
service_is_active() {
if run_cmd systemctl is-active "$1"; then
return 0
fi
return 1
}
package_is_installed() {
if run_cmd dpkg-query -W -f='${Status}' "$1" | grep -q "install ok installed"; then
return 0
fi
return 1
}

View File

@ -0,0 +1,5 @@
# ©AngelaMos | 2026
# auditd.conf
log_file = /var/log/audit/audit.log
max_log_file = 8
max_log_file_action = keep_logs

View File

@ -0,0 +1,29 @@
# ©AngelaMos | 2026
# cis.rules
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
-a always,exit -F arch=b64 -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
-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
-w /etc/issue -p wa -k system-locale
-w /etc/issue.net -p wa -k system-locale
-w /etc/hosts -p wa -k system-locale
-w /etc/networks -p wa -k system-locale
-w /etc/apparmor/ -p wa -k MAC-policy
-w /etc/apparmor.d/ -p wa -k MAC-policy
-w /var/log/lastlog -p wa -k logins
-w /var/run/faillock/ -p wa -k logins
-w /var/run/utmp -p wa -k session
-w /var/log/wtmp -p wa -k session
-w /var/log/btmp -p wa -k session
-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -k perm_mod
-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -k perm_mod
-a always,exit -F arch=b64 -S setxattr -S lsetxattr -S fsetxattr -k perm_mod
-a always,exit -F arch=b64 -S open -S truncate -S ftruncate -F exit=-EACCES -k access
-a always,exit -F arch=b64 -S open -S truncate -S ftruncate -F exit=-EPERM -k access
-a always,exit -F arch=b64 -S mount -k mounts
-a always,exit -F arch=b64 -S unlink -S rename -S unlinkat -S renameat -k delete

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# crontab
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# grub
GRUB_CMDLINE_LINUX="audit=1 audit_backlog_limit=8192"
GRUB_TIMEOUT=5

View File

@ -0,0 +1,6 @@
# ©AngelaMos | 2026
# fstab
/dev/sda1 / ext4 defaults 0 1
tmpfs /tmp tmpfs defaults,noexec,nosuid,nodev 0 0
/dev/sda2 /var ext4 defaults 0 2
/dev/sda3 /var/log ext4 defaults 0 2

View File

@ -0,0 +1,4 @@
root:x:0:
daemon:x:1:
bin:x:2:
nogroup:x:65534:

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# gshadow
root:*::
daemon:*::

View File

@ -0,0 +1,5 @@
# ©AngelaMos | 2026
# login.defs
PASS_MAX_DAYS 365
PASS_MIN_DAYS 1
PASS_WARN_AGE 7

View File

@ -0,0 +1 @@
install cramfs /bin/true

View File

@ -0,0 +1 @@
install dccp /bin/true

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# freevxfs.conf
install freevxfs /bin/true
blacklist freevxfs

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# hfs.conf
install hfs /bin/true
blacklist hfs

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# hfsplus.conf
install hfsplus /bin/true
blacklist hfsplus

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# jffs2.conf
install jffs2 /bin/true
blacklist jffs2

View File

@ -0,0 +1 @@
install rds /bin/true

View File

@ -0,0 +1 @@
install sctp /bin/true

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# squashfs.conf
install squashfs /bin/true
blacklist squashfs

View File

@ -0,0 +1 @@
install tipc /bin/true

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# udf.conf
install udf /bin/true
blacklist udf

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# vfat.conf
install vfat /bin/true
blacklist vfat

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# os-release
ID=debian
VERSION_ID="13"

View File

@ -0,0 +1,5 @@
# ©AngelaMos | 2026
# common-auth
auth required pam_faillock.so preauth
auth [success=1 default=ignore] pam_unix.so nullok_secure
auth required pam_faillock.so authfail

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# common-password
password requisite pam_pwquality.so retry=3
password [success=1 default=ignore] pam_unix.so obscure use_authtok try_first_pass sha512

View File

@ -0,0 +1,4 @@
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# main.cf
inet_interfaces = loopback-only

View File

@ -0,0 +1,5 @@
# ©AngelaMos | 2026
# rsyslog.conf
$FileCreateMode 0640
*.* /var/log/syslog
auth,authpriv.* /var/log/auth.log

View File

@ -0,0 +1 @@
* hard core 0

View File

@ -0,0 +1,4 @@
root:!:19000::::::
daemon:*:19000::::::
bin:*:19000::::::
nobody:*:19000::::::

View File

@ -0,0 +1,14 @@
# ©AngelaMos | 2026
# sshd_config
PermitRootLogin no
PermitEmptyPasswords no
X11Forwarding no
MaxAuthTries 4
IgnoreRhosts yes
PermitUserEnvironment no
LogLevel INFO
LoginGraceTime 60
Ciphers aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms curve25519-sha256,diffie-hellman-group16-sha512
AllowUsers admin

View File

@ -0,0 +1,17 @@
# ©AngelaMos | 2026
# sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv6.conf.all.accept_ra = 0
kernel.randomize_va_space = 2
fs.suid_dumpable = 0

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# apache2.conf
ServerRoot "/etc/apache2"

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# grub
GRUB_CMDLINE_LINUX=""

View File

@ -0,0 +1 @@
/dev/sda1 / ext4 defaults 0 1

View File

@ -0,0 +1,3 @@
root:x:0:
daemon:x:1:
nogroup:x:65534:

View File

@ -0,0 +1,5 @@
# ©AngelaMos | 2026
# login.defs
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_WARN_AGE 0

View File

@ -0,0 +1,4 @@
# ©AngelaMos | 2026
# os-release
ID=debian
VERSION_ID="13"

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# common-auth
auth [success=1 default=ignore] pam_unix.so nullok_secure

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# common-password
password [success=1 default=ignore] pam_unix.so obscure sha512

View File

@ -0,0 +1,5 @@
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
admin:x:0:0:admin:/home/admin:/bin/bash
test:x:1000:1000:test:/home/test:/bin/bash
dupe:x:1000:1000:dupe:/home/dupe:/bin/bash

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# main.cf
inet_interfaces = all

View File

@ -0,0 +1,3 @@
# ©AngelaMos | 2026
# rsyslog.conf
$FileCreateMode 0777

View File

@ -0,0 +1 @@
# no core dump restrictions

View File

@ -0,0 +1,3 @@
root:!:19000::::::
daemon:*:19000::::::
+:::::::

View File

@ -0,0 +1,11 @@
PermitRootLogin yes
PermitEmptyPasswords yes
X11Forwarding yes
MaxAuthTries 10
IgnoreRhosts no
PermitUserEnvironment yes
LogLevel QUIET
LoginGraceTime 300
Ciphers aes256-gcm@openssh.com,aes256-cbc,3des-cbc
MACs hmac-sha2-512-etm@openssh.com,hmac-md5
KexAlgorithms curve25519-sha256,diffie-hellman-group1-sha1

View File

@ -0,0 +1,8 @@
# ©AngelaMos | 2026
# sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.all.accept_redirects = 1
net.ipv4.conf.all.log_martians = 0
net.ipv4.tcp_syncookies = 0
kernel.randomize_va_space = 0

View File

@ -0,0 +1,6 @@
# ©AngelaMos | 2026
# xinetd.conf
defaults
{
instances = 60
}

Some files were not shown because too many files have changed in this diff Show More