Python | System hardening and compliance reports using Lynis
Lynis is a battle-tested security tool for systems running Linux, macOS, or Unix-based operating systems. It performs an extensive health scan of your systems to support system hardening and compliance testing. The project is open-source software with the GPL license and available since 2007.
Since Lynis is flexible, it is used for several different purposes. Typical use cases for Lynis include:
- Security auditing
- Compliance testing (e.g. PCI, HIPAA, SOx)
- Penetration testing
- Vulnerability detection
- System Hardening
System hardening refers to securing your system from potential Threats and Vulnerabilities. Lynis can be used to generate a detailed report on various Threats and Vulnerabilities in your system. The user or System Administrator can then take the necessary actions to secure the system.
Lynis reports are hard to read and usually have a lot of information. Therefore, we use Bash and Python scripts to parse through the report, extract relevant information from the report such as warnings, suggestions and store them in an excel file as a report.
Prerequisites for Lynis –
- Install Lynis on your system by cloning the github repository: https://github.com/CISOfy/lynis
- Install the pandas library using the command sudo pip3 install pandas.
- Once you have installed Lynis on your system, navigate to the Lynis directory where you will find a bunch of files along with an executable file called Lynis.
- Use the bash script (code is given below) to extract relevant information such as warning and suggestions given in the lynis report. create a file called run.sh and copy paste the bash code into that file and type: sudo ./run.sh to run the bash script.
- Run the Python script (code is given below) to clean and parse the extracted data and output the relevant information as an excel file.
Below are the Bash and Python scripts –
Once you run the above scripts, you will find a folder called outputs in the current directory. navigate to the outputs folder where you will find excel sheets that contain warnings, suggestions, and installed packages.