Coder Social home page Coder Social logo

konstruktoid / hardening Goto Github PK

View Code? Open in Web Editor NEW
1.3K 54.0 250.0 7.43 MB

Hardening Ubuntu. Systemd edition.

License: Apache License 2.0

Shell 98.82% Dockerfile 0.50% HCL 0.68%
ubuntu ubuntu-server shell hardening security security-hardening systemd security-tools security-automation security-compliance

hardening's Introduction

Ubuntu Hardening

Hardening Ubuntu. Systemd edition.

A quick way to make a Ubuntu server a bit more secure.

Use the newly installed and configured system as a reference, or golden, image. Use that image as a baseline installation media and ensure that any future installation comply with benchmarks and policies using a configuration management tool, e.g Ansible or Puppet.

Tested on Ubuntu 20.04 Focal Fossa and Ubuntu 22.04 Jammy Jellyfish.

If you’re just interested in the security focused systemd configuration, it’s available as a separate document.

If you’re interested in testing your host settings, you’ll find the instructions here.

Note
Read the code and do not run this script without first testing in a non-operational environment. The code is not idempotent, use the Ansible role in production environments instead.
Note
There is a SLSA artifact present under the slsa workflow for file checksum verification.

Packer template and Ansible playbook

A Packer template is available in the Packer directory.

An Ansible playbook is available in the konstruktoid/ansible-role-hardening repository.

Howto

  1. Start the server installation.

  2. Pick language and keyboard layout.

  3. Select "Ubuntu Server (minimized)".

  4. Configure network connections.

  5. Partition the system, see below for recommendations.

  6. Do not install the OpenSSH server, "Featured Server Snaps", or any other packages.

  7. Finish the installation and reboot.

  8. Log in.

  9. If wanted, set a Grub2 password with grub-mkpasswd-pbkdf2. See https://help.ubuntu.com/community/Grub2/Passwords for more information.

  10. Install necessary packages: sudo apt-get -y install git net-tools procps --no-install-recommends.

  11. Download the script: git clone https://github.com/konstruktoid/hardening.git.

  12. Change the configuration options in the ubuntu.cfg file.

  13. Run the script: sudo bash ubuntu.sh.

  14. Reboot.

/boot (rw)
/home (rw,nosuid,nodev)
/var/log (rw,nosuid,nodev,noexec)
/var/log/audit (rw,nosuid,nodev,noexec)
/var/tmp (rw,nosuid,nodev,noexec)

Note that /tmp will be added automatically by the script.

Configuration options

FW_ADMIN='127.0.0.1' // (1)
SSH_GRPS='sudo' // (2)
SSH_PORT='22' // (3)
SYSCTL_CONF='./misc/sysctl.conf' // (4)
AUDITD_MODE='1' // (5)
AUDITD_RULES='./misc/audit-base.rules ./misc/audit-aggressive.rules ./misc/audit-docker.rules' // (6)
LOGROTATE_CONF='./misc/logrotate.conf' // (7)
NTPSERVERPOOL='0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org pool.ntp.org' // (8)
TIMEDATECTL='' // (9)
VERBOSE='N' // (10)
AUTOFILL='N' // (11)
ADMINEMAIL="root@localhost" // (12)
KEEP_SNAPD='Y' // (13)
CHANGEME='' // (14)

# Configuration files // (15)
ADDUSER='/etc/adduser.conf'
AUDITDCONF='/etc/audit/auditd.conf'
AUDITRULES='/etc/audit/rules.d/hardening.rules'
COMMONPASSWD='/etc/pam.d/common-password'
COMMONACCOUNT='/etc/pam.d/common-account'
COMMONAUTH='/etc/pam.d/common-auth'
COREDUMPCONF='/etc/systemd/coredump.conf'
DEFAULTGRUB='/etc/default/grub.d'
DISABLEFS='/etc/modprobe.d/disablefs.conf'
DISABLEMOD='/etc/modprobe.d/disablemod.conf'
DISABLENET='/etc/modprobe.d/disablenet.conf'
FAILLOCKCONF='/etc/security/faillock.conf'
JOURNALDCONF='/etc/systemd/journald.conf'
LIMITSCONF='/etc/security/limits.conf'
LOGINDCONF='/etc/systemd/logind.conf'
LOGINDEFS='/etc/login.defs'
LOGROTATE='/etc/logrotate.conf'
PAMLOGIN='/etc/pam.d/login'
PSADCONF='/etc/psad/psad.conf'
PSADDL='/etc/psad/auto_dl'
RESOLVEDCONF='/etc/systemd/resolved.conf'
RKHUNTERCONF='/etc/default/rkhunter'
RSYSLOGCONF='/etc/rsyslog.conf'
SECURITYACCESS='/etc/security/access.conf'
SSHFILE='/etc/ssh/ssh_config'
SSHDFILE='/etc/ssh/sshd_config'
SYSCTL='/etc/sysctl.conf'
SYSTEMCONF='/etc/systemd/system.conf'
TIMESYNCD='/etc/systemd/timesyncd.conf'
UFWDEFAULT='/etc/default/ufw'
USERADD='/etc/default/useradd'
USERCONF='/etc/systemd/user.conf'
  1. The IP addresses that will be able to connect with SSH, separated by spaces.

  2. Which group the users have to be member of in order to acess via SSH, separated by spaces.

  3. Configure SSH port.

  4. Stricter sysctl settings.

  5. Auditd failure mode. 0=silent 1=printk 2=panic.

  6. Auditd rules.

  7. Logrotate settings.

  8. NTP server pool.

  9. Add a specific time zone or use the system default by leaving it empty.

  10. If you want all the details or not.

  11. Let the script guess the FW_ADMIN and SSH_GRPS settings.

  12. Add a valid email address, so PSAD can send notifications.

  13. If 'Y' then the snapd package will be held to prevent removal.

  14. Add something just to verify that you actually glanced the code.

  15. Default configuration file locations.

Functions

Function list in execution order

Note that all functions has the f_ prefix in the code.

pre

Sets apt flags and performs basic permission check.

The pre function is located in ./scripts/pre.

kernel

Sets /sys/module/nf_conntrack/parameters/hashsize to 1048576 if hashsize exists and is writable.

Sets /sys/kernel/security/lockdown to confidentiality if lockdown exists and is writable.

The kernel function is located in ./scripts/kernel.

firewall

Configures UFW if installed.

Allows connections from the adresses in $FW_ADMIN to the $SSH_PORT.

Sets logging and IPT_SYSCTL=/etc/sysctl.conf.

The firewall function is located in ./scripts/ufw.

disablenet

Disables the dccp, sctp, rds and tipc kernel modules.

The disablenet function is located in ./scripts/disablenet.

disablefs

Disables the cramfs freevxfs jffs2 ksmbd hfs hfsplus udf kernel modules.

The disablefs function is located in ./scripts/disablefs.

disablemod

Disables the bluetooth, bnep, btusb, cpia2, firewire-core, floppy, n_hdlc, net-pf-31, pcspkr, soundcore, thunderbolt, usb-midi, usb-storage, uvcvideo, v4l2_common kernel modules.

Note that disabling the usb-storage module will disable any usage of USB storage devices, if such devices are needed USBGuard should be configured accordingly.

The disablemod function is located in ./scripts/disablemod.

systemdconf

Sets CrashShell=no, DefaultLimitCORE=0, DefaultLimitNOFILE=1024, DefaultLimitNPROC=1024, DumpCore=no in $SYSTEMCONF and $USERCONF.

The systemdconf function is located in ./scripts/systemdconf.

resolvedconf

Sets DNS=$dnslist, DNSOverTLS=opportunistic, DNSSEC=allow-downgrade, FallbackDNS=1.0.0.1 in $RESOLVEDCONF, where $dnslist is an array with the nameservers present in /etc/resolv.conf.

The resolvedconf function is located in ./scripts/resolvedconf.

logindconf

Sets IdleAction=lock, IdleActionSec=15min, KillExcludeUsers=root, KillUserProcesses=1, RemoveIPC=yes in $LOGINDCONF.

The logindconf function is located in ./scripts/logindconf.

journalctl

Copies ./misc/logrotate.conf to $LOGROTATE.

Sets Compress=yes, ForwardToSyslog=yes, Storage=persistent in $JOURNALDCONF.

Sets $FileCreateMode 0600/ in $RSYSLOGCONF. if RSYSLOGCONF is writable.

The journalctl function is located in ./scripts/journalctl.

timesyncd

Sets NTP=${SERVERARRAY}, FallbackNTP=${FALLBACKARRAY}, RootDistanceMaxSec=1 in $TIMESYNCD where the arrays are up to four time servers with < 50ms latency.

The timesyncd function is located in ./scripts/timesyncd.

fstab

Configures the /boot and /home partitions with defaults,nosuid,nodev if they are available in /etc/fstab.

Configures the /var/log, /var/log/audit and /var/tmp partitions with defaults,nosuid,nodev,noexec if they are available in /etc/fstab.

Adds /run/shm tmpfs rw,noexec,nosuid,nodev, /dev/shm tmpfs rw,noexec,nosuid,nodev and /proc proc rw,nosuid,nodev,noexec,relatime,hidepid=2 to /etc/fstab if the partition isn’t present in /etc/fstab.

Removes any floppy drivers from /etc/fstab.

Copies ./config/tmp.mount[./config/tmp.mount] to /etc/systemd/system/tmp.mount, removes /tmp from /etc/fstab and enables the tmpfs /tmp mount instead.

The fstab function is located in ./scripts/fstab.

Reverts binaries and libraries to their original content before they were prelinked and uninstalls prelink.

The prelink function is located in ./scripts/prelink.

aptget_configure

Sets apt options Acquire::http::AllowRedirect "false";, APT::Get::AllowUnauthenticated "false";, APT::Periodic::AutocleanInterval "7";, APT::Install-Recommends "false";, APT::Get::AutomaticRemove "true";, APT::Install-Suggests "false";, Acquire::AllowDowngradeToInsecureRepositories "false";, Acquire::AllowInsecureRepositories "false";, APT::Sandbox::Seccomp "1";

The aptget_configure function is located in ./scripts/aptget.

aptget

Upgrades installed packages.

The aptget function is located in ./scripts/aptget.

hosts

Sets sshd : ALL : ALLOW, ALL: LOCAL, 127.0.0.1 in /etc/hosts.allow and ALL: ALL in /etc/hosts.deny.

See https://manpages.ubuntu.com/manpages/jammy/man5/hosts_access.5.html for the format of host access control files.

The hosts function is located in ./scripts/hosts.

issue

Writes a notice regarding authorized use only to /etc/issue, /etc/issue.net and /etc/motd.

Removes the executable flag from every file in /etc/update-motd.d/.

The issue function is located in ./scripts/issue.

sudo

Restricts su access to members of the sudo group using pam_wheel.

Sets !pwfeedback, !visiblepw, logfile=/var/log/sudo.log, passwd_timeout=1, timestamp_timeout=5, use_pty sudo options.

The sudo function is located in ./scripts/sudo.

logindefs

Writes LOG_OK_LOGINS yes, UMASK 077, PASS_MIN_DAYS 1, PASS_MAX_DAYS 60, DEFAULT_HOME no, ENCRYPT_METHOD SHA512, USERGROUPS_ENAB no, SHA_CRYPT_MIN_ROUNDS 10000, SHA_CRYPT_MAX_ROUNDS 65536 to $LOGINDEFS

The logindefs function is located in ./scripts/logindefs.

sysctl

Copies ./misc/sysctl.conf to $SYSCTL.

For an explanation of the options set, see https://www.kernel.org/doc/html/latest/admin-guide/sysctl/.

The sysctl function is located in ./scripts/sysctl.

limitsconf

Sets hard maxlogins 10, hard core 0, soft nproc 512, hard nproc 1024 in $LIMITSCONF

The limitsconf function is located in ./scripts/limits.

adduser

Sets DIR_MODE=0750,DSHELL=/bin/false, and USERGROUPS=yes in $ADDUSER.

Sets INACTIVE=30 and SHELL=/bin/false in $USERADD.

The adduser function is located in ./scripts/adduser.

rootaccess

Writes +:root:127.0.0.1/' to $SECURITYACCESS and console to /etc/securetty.

Masks debug-shell.

The rootaccess function is located in ./scripts/rootaccess.

package_install

Installs acct, aide-common, cracklib-runtime, debsums, gnupg2, haveged, libpam-pwquality, libpam-tmpdir, needrestart, openssh-server, postfix, psad, rkhunter, sysstat, systemd-coredump, tcpd, update-notifier-common, vlock.

The package_install function is located in ./scripts/packages.

psad

Installs and configures PSAD

The psad function is located in ./scripts/psad.

coredump

Writes Storage=none and ProcessSizeMax=0 to $COREDUMPCONF.

The coredump function is located in ./scripts/coredump.

usbguard

Installs and configures USBGuard.

The usbguard function is located in ./scripts/usbguard.

postfix

Installs postfix and sets disable_vrfy_command=yes, inet_interfaces=loopback-only, smtpd_banner="\$myhostname, smtpd_client_restrictions=permit_mynetworks,reject using postconf.

The postfix function is located in ./scripts/postfix.

apport

The apport function is located in ./scripts/apport.

motdnews

Disables apt_news and motd-news.

The motdnews function is located in ./scripts/motdnews.

rkhunter

Sets CRON_DAILY_RUN="yes", APT_AUTOGEN="yes" in $RKHUNTERCONF.

The rkhunter function is located in ./scripts/rkhunter.

sshconfig

Sets HashKnownHosts yes, Ciphers [email protected],[email protected],aes256-ctr and MACs [email protected],[email protected],hmac-sha2-512,hmac-sha2-256 in $SSHFILE.

The sshconfig function is located in ./scripts/sshdconfig.

sshdconfig

Configures the OpenSSH daemon. The configuration changes will be placed in the directory defined by the Include option if present, otherwise $SSHDFILE will be modified.

By default /etc/ssh/sshd_config.d/hardening.conf will contain the following:

AcceptEnv LANG LC_*
AllowAgentForwarding no
AllowGroups sudo
AllowTcpForwarding no
Banner /etc/issue.net
Ciphers [email protected],[email protected],aes256-ctr
ClientAliveCountMax 3
ClientAliveInterval 200
Compression no
GSSAPIAuthentication no
HostbasedAuthentication no
IgnoreUserKnownHosts yes
KbdInteractiveAuthentication no
KerberosAuthentication no
KexAlgorithms [email protected],ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
LogLevel VERBOSE
LoginGraceTime 20
Macs [email protected],[email protected],hmac-sha2-512,hmac-sha2-256
MaxAuthTries 3
MaxSessions 3
MaxStartups 10:30:60
PasswordAuthentication no
PermitEmptyPasswords no
PermitRootLogin no
PermitUserEnvironment no
Port 22
PrintLastLog yes
PrintMotd no
RekeyLimit 512M 1h
StrictModes yes
TCPKeepAlive no
UseDNS no
UsePAM yes
X11Forwarding no

The sshdconfig function is located in ./scripts/sshdconfig.

password

Copies ./config/pwquality.conf[./config/pwquality.conf] to /etc/security/pwquality.conf,

Removes nullok from PAM $COMMONAUTH.

Configures faillock or pam_tally2 depending on which is installed.

Adds a password list to cracklib.

The password function is located in ./scripts/password.

cron

Disables atd and only allow root to use at or cron.

The cron function is located in ./scripts/cron.

ctrlaltdel

The ctrlaltdel function is located in ./scripts/ctraltdel.

auditd

Configures auditd.

The auditd function is located in ./scripts/auditd.

aide

Excludes /var/lib/lxcfs/cgroup and /var/lib/docker from AIDE.

The aide function is located in ./scripts/aide.

rhosts

Removes any existing hosts.equiv or .rhosts files.

The rhosts function is located in ./scripts/rhosts.

users

Removes the games, gnats, irc, list, news, sync, uucp users.

The users function is located in ./scripts/users.

lockroot

Locks root account

The lockroot function is located in ./scripts/lockroot.

package_remove

Removes the apport*, autofs, avahi*, beep, git, pastebinit, popularity-contest, rsh*, rsync, talk*, telnet*, tftp*, whoopsie, xinetd, yp-tools, ypbind packages.

The package_remove function is located in ./scripts/packages.

suid

Ensures the executables in ./misc/suid.list don’t have suid bits set.

The suid function is located in ./scripts/suid.

restrictcompilers

Changes mode to 0750 on any installed compilers.

The restrictcompilers function is located in ./scripts/compilers.

umask

Sets the default umask to 077

The umask function is located in ./scripts/umask.

path

Copies ./config/initpath.sh[./config/initpath.sh] to /etc/profile.d/initpath.sh and sets PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin for the root user and PATH=/usr/local/bin:/usr/sbin:/usr/bin:/bin:/snap/bin for everyone else.

The path function is located in ./scripts/path.

aa_enforce

Enforces available apparmor profiles.

The aa_enforce function is located in ./scripts/apparmor.

aide_post

Creates a new AIDE database.

The aide_post function is located in ./scripts/aide.

aide_timer

Copies a systemd AIDE check service and timer to /etc/systemd/system/.

The aide_timer function is located in ./scripts/aide.

aptget_noexec

Adds a DPkg::Pre-Invoke and DPkg::Post-Invoke to ensure package updates don’t fail on a noexec /tmp partition.

The aptget_noexec function is located in ./scripts/aptget.

aptget_clean

Runs apt-get clean and autoremove.

The aptget_clean function is located in ./scripts/aptget.

systemddelta

Runs systemd-delta if running in verbose mode.

The systemddelta function is located in ./scripts/systemddelta.

post

Ensures fwupdmgr and secureboot-db is installed and GRUB is updated.

The post function is located in ./scripts/post.

checkreboot

Checks if a reboot is required.

The checkreboot function is located in ./scripts/reboot.

Tests

There are approximately 760 Bats tests for most of the above settings available in the tests directory.

sudo apt-get -y install bats
git clone https://github.com/konstruktoid/hardening.git
cd hardening/tests/
sudo bats .

Test automation using Vagrant

Running bash ./runTests.sh will use Vagrant to run all above tests, Lynis and OpenSCAP with a CIS Ubuntu benchmark on all supported Ubuntu versions.

The script will generate a file named TESTRESULTS.adoc and CIS report in HTML-format.

Testing a host

Running bash ./runHostTests.sh, located in the tests directory, will generate a TESTRESULTS-<HOSTNAME>.adoc report.

Running bash ./runHostTestsCsv.sh, located in the tests directory, will generate a TESTRESULTS-<HOSTNAME>.csv report.

Contributing

Do you want to contribute? That’s great! Contributions are always welcome, no matter how large or small. If you found something odd, feel free to submit a new issue, improve the code by creating a pull request, or by sponsoring this project.

Logo by reallinfo.

hardening's People

Contributors

asiebelt avatar dependabot[bot] avatar et304383 avatar frederikbosch avatar gcb avatar hellresistor avatar josephlimb avatar konstruktoid avatar readonlyuser1 avatar reallinfo avatar renovate-bot avatar renovate[bot] avatar step-security-bot avatar superpenguin612 avatar swipswaps avatar taeduard avatar wimjongman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hardening's Issues

Possible mistake with 'w' command getting IP

Well.. I have installed "physically" on vm machine with AUTOFIL=Y
noW

Detected 'w' command will not get the IP, because exist no connections/sessions active.

maybe should change this line: USERIP="$($WBIN -ih | awk '{print $3}' | head -n1)"

Aide Service duplication

I was inspecting the aide logs for my server today and realised that AIDE currently runs twice a day. At midnight, and then again at 6:30am.

It seems to me that the hardening script install a service to be run at midnight, while the standard AIDE configuration adds a daily cron job

My question is, are these serving different purposes, or is one of them redundant?

[BUG] Missing dependency pexpcet

Describe the bug
I am trying to use your role on an Raspbian. I experienced the following error :

TASK [konstruktoid.hardening : initialize Debian aide] ****************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pexpect
fatal: [hostname]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pexpect) on pi2's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

You use expect directive in the task "TASK [konstruktoid.hardening : initialize Debian aide]" but sometime the package python-pexpect is missing. Install it on dependencies and all will be fine. This is a requirement according to Ansible documentation

To Reproduce
Use raspbian system

System (lsb_release -a):
lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster

Noticed Some Weirdness

Hi,

I'm looking through some of your code now, and have some things like I'd like to address:

File: ubuntu.sh

  • There are a lot of, and I'd wager the same in other scripts, redundant processes. So many process make this very inefficient and only serve to raise the dependency count. You're using Bash, so I recommend using Bash. ;) For example, printf is more than capable of telling and storing the time and date, making date redundant in most cases.

  • You have a lot of error messages, but none of them seem to redirect to STDERR; is that by design? Also, since you're repeating the same code over and over, that's a good opportunity to make use of a function. For example:

die(){
  printf 'ERROR: %s\n' "$2" 1>&2
  [ $1 -gt 0 ] && exit $1
}
  • You seem to be needlessly storing command locations (determined by $PATH anyway, hence command) only to go ahead and use the variables. It's a lot of work and code for no gain, at least that I can see. Am I missing something here? If it's a security issue, you're already using $PATH, as mentioned, so I don't see the gain there.

  • You have 53 functions running in this file, as sourced by 53 other files. All that extra processing and hassle -- I feel like there's a better way, which will reduce the hassle. Perhaps a function library within the one file, then the main code in the other? That seems to be a fairly common approach.

  • I get the impression that you're a long-time shell programmer who's got much more experience with Bourne shell programming. The reason, is because I see a lot of Bourne-isms, I guess you could say. Bash has made a lot of that stuff entirely unnecessary. For example, there's $USER, instead of using yet another process for id -un. There's $UID instead of yet another process for id -u, and one more example, there's $HOSTNAME making hostname redundant in probably most cases. I suggest you read up on the Bash manual; it'll change your world.

  • Lines 88-93, you have a for loop iterating over files to be sourced, but you're only checking 'they' exist, not what they actually are; they could be directories, links, block specials, FIFOs, etc. I recommend using -f instead. It's usually good to be more specific than just -e.

  • This isn't too big a deal, at least how I've seen you use echo, but I would strongly recommend you ditch echo, saving it only for quick terminal stuff, as printf is more feature-rich (especially in Bash) and far more reliable and consistent.

  • While there are at least two naming conventions to things like variables and functions, there is one which is typically shunned, and that's the all-caps way. I actually did the same thing for a very long time, until I finally stopped being so stubborn. :P I'm glad I did, because ThisMethod is a lot easier to read.

Hope this helps. Let me know if you'd be interested in some pull requests.

BTW, this is some seriously awesome stuff! Must have taken a lot of research.

Ubuntu 18.04 Crashing While Applying Apt Updates

The system is crashing due to kernel panic when the audit logging rate exceeds some limit on both VMs and bare metal boxes.

Fix that worked for us is changing the audit rules -f parameter from 2 to 1 in /etc/audit/rules.d/hardening.rules configuration file.

Other then that great scripts, thank you!

LXC VPS

I'm having a few challenges getting this to work on a VPS running on an LXC containier.

  1. First auditd and app armor need to be disabled
  2. Second, ssh access to the VPS stops working:
  • have tried to disable f_sshconfig, f_sshdconfig, f_hosts, f_logindconf, and f_sysctl with no luck
    Any suggestions on how I might try to repurpose your repo to work on a VPS running LXC?

Remove NTP

NTP is both an ancient and insecure protoocol.The protcol itself can be abused and cause much bigger replies than expected,thus crashing the system.This is known as an amplification attack.MOre n this here https://blog.hboeck.de/archives/863-Dont-update-NTP-stop-using-it.html and http://netpatterns.blogspot.de/2016/01/the-rising-sophistication-of-network.html
An attacker can exploit flaws in the protocol and gain access into the system.The unencrypted and unauthenticated nature of NTP makes this attack very easy. for network adversaries.More info https://blog.hboeck.de/archives/863-Dont-update-NTP-stop-using-it.html and https://www.cvedetails.com/vulnerability-list/vendor_id-2153/NTP.html.
NTP can leak host time and expose the system tyo attacks described here https://www.whonix.org/wiki/Time_Attacks.More M0re here https://trac.torproject.org/projects/tor/ticket/16659#comment:13.
\Its best fo the uses that is seek9ng high-lvel security to follow this https://www.whonix.org/wiki/Time_Attacks#GNU.2FLinux_Host.
The only two nice alternatives to NTP clients is sdwdate by Whonix or this
DO NOT use NTPsec as it is also not secure aand even its devs say so.More steps can be taken for time hardening.

DNS Service

You've done some great work.

Sorry if this goes beyond your original intent of your hardening scripts. I'm trying to harden a server that is running Pihole. After running your process, the DNS Service (dnsmasq) gets completely disabled somehow and prevents Pihole from working. Also, Pihole uses php7.4-fpm, which leverages a run folder (/run/php) that also disappears after hardening.

Could you point me in the right direction on debugging the part of your process "over hardens"? :)

Thanks in advance!!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

dockerfile
action-shellcheck/Dockerfile
  • koalaman/shellcheck-alpine stable@sha256:10d8a40c4ee029bce4e04ba9a92efd7a0df4afba023c0cd8fc9c55a1e3ae7aeb
github-actions
.github/workflows/dependency-review.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/dependency-review-action v4.2.5@5bbc3ba658137598168acb2ab73b21c432dd411b
.github/workflows/issues.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • pozil/auto-assign-issue v1.14.0@65947009a243e6b3993edeef4e64df3ca85d760c
.github/workflows/scorecards.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • ossf/scorecard-action v2.3.1@0864cf19026789058feabb7e87baa5f140aac736
  • actions/upload-artifact v4.3.3@65462800fd760344b1a7b4382951275a0abb4808
  • github/codeql-action v3.25.3@d39d31e687223d841ef683f52467bd88e9b21c14
.github/workflows/shellcheck.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
.github/workflows/slsa.yml
  • step-security/harden-runner v2.7.0@63c24ba6bd7ba022e95695ff85de572c04a18142
  • actions/checkout v4.1.4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • actions/upload-artifact v4.3.3@65462800fd760344b1a7b4382951275a0abb4808
  • slsa-framework/slsa-github-generator v2.0.0
  • actions/download-artifact v4.1.7@65a9edc5881444af0b9093a5e628f2fe47ea3b2e
  • softprops/action-gh-release v2.0.4@9d7c94cfd0a1f3ed45544c887983e9fa900f0564

  • Check this box to trigger a request for Renovate to run again on this repository

47 - Enforce apparmor profiles

--- On Cli running ---

[47] Enforce apparmor profiles
.....
ERROR: /etc/apparmor.d/lxc-containers contains no profile
Setting /etc/apparmor.d/lxc-containers to enforce mode.

--- On LOG file ---

Jun 08 17:22:40 tester systemd[1]: Starting AppArmor initialization...
Jun 08 17:22:40 tester apparmor[108961]:  * Starting AppArmor profiles
Jun 08 17:22:40 tester apparmor[108961]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Jun 08 17:22:40 tester apparmor[108961]:    ...done.
Jun 08 17:22:40 tester systemd[1]: Started AppArmor initialization.

[BUG]: grub-efi-amd64-signed package post-installation script subprocess returned error exit status 32

Describe the bug

during installation process the f_aptget() returns error:

Setting up grub-efi-amd64-signed (1.167.2+2.04-1ubuntu44.2) ...
mount: /var/lib/grub/esp: special device /dev/disk/by-id/mmc-S0J58X_0x158869a0-part1 does not exist.
dpkg: error processing package grub-efi-amd64-signed (--configure):
 installed grub-efi-amd64-signed package post-installation script subprocess returned error exit status 32
No apport report written because the error message indicates its a followup error from a previous failure.Setting up linux-generic (5.4.0.81.85) ...
Setting up fwupd-signed (1.27.1ubuntu5+1.5.11-0ubuntu1~20.04.2) ...
dpkg: dependency problems prevent configuration of shim-signed:
 shim-signed depends on grub-efi-amd64-signed | grub-efi-arm64-signed; however:
  Package grub-efi-amd64-signed is not configured yet.
  Package grub-efi-arm64-signed is not installed.

dpkg: error processing package shim-signed (--configure):
 dependency problems - leaving unconfigured

and after

Processing triggers for initramfs-tools (0.136ubuntu6.6) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-81-generic
Errors were encountered while processing:
 grub-efi-amd64-signed
 shim-signed
E: Sub-process /usr/bin/dpkg returned an error code (1)

To Reproduce
The system uses EFI:

$ sudo lsblk
[sudo] password for tfence: 
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0          7:0    0   55M  1 loop /snap/core18/1880
loop1          7:1    0 55.4M  1 loop /snap/core18/2128
loop2          7:2    0 71.3M  1 loop /snap/lxd/16099
loop3          7:3    0 29.9M  1 loop /snap/snapd/8542
loop4          7:4    0 70.3M  1 loop /snap/lxd/21029
loop5          7:5    0 32.3M  1 loop /snap/snapd/12883
mmcblk1      179:0    0 59.3G  0 disk 
├─mmcblk1p1  179:1    0  512M  0 part /boot/efi
├─mmcblk1p2  179:2    0    1G  0 part /boot
├─mmcblk1p3  179:3    0   30G  0 part /
├─mmcblk1p4  179:4    0    5G  0 part /home
├─mmcblk1p5  179:5    0    5G  0 part /var
├─mmcblk1p6  179:6    0    5G  0 part /var/tmp
├─mmcblk1p7  179:7    0    5G  0 part /var/log
├─mmcblk1p8  259:0    0    5G  0 part /var/log/audit
└─mmcblk1p9  259:1    0  2.8G  0 part /srv
mmcblk1boot0 179:8    0 31.5M  1 disk 

I run the install script step by step, I mean function by function (f_pre () function always works). Every time I start, I change "ubuntu.sh" something like this:
Run 1:

  f_pre
  SCRIPT_COUNT=1
  f_kernel
  SCRIPT_COUNT=2
#  f_firewall
  SCRIPT_COUNT=3
#  f_disablenet
  SCRIPT_COUNT=4
# ...

Run 2:

 f_pre
  SCRIPT_COUNT=1
 # f_kernel
  SCRIPT_COUNT=2
  f_firewall
  SCRIPT_COUNT=3
#  f_disablenet
  SCRIPT_COUNT=4
# ...

So during the step 'aptget ...' :

  #  f_prelink
# ....
  SCRIPT_COUNT=12
  f_aptget_configure
SCRIPT_COUNT=13
  f_aptget
SCRIPT_COUNT=15
#  f_hosts
# ...

I have an error:
harden_install_error.txt

Expected behavior
A clear and concise description of what you expected to happen.

System (lsb_release -a):
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal

Additional context
Add any other context about the problem here.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

rsyslog : imudp: Could not create udp listener

Hi Thomas,
you are making a great job - thank you very much.
I have installed the version v1.0.0 on our device and now testing the
functionality of all the features under hardening. I am currently
investigating the syslog problem and cannot figure out
what is happening. I would be very grateful if you can help me with this.

Problem:

rsyslog imudp plugin can't create udp listener
/-----------------------------------------------------------------/
$ sudo systemctl status rsyslog.service
● rsyslog.service - System Logging Service
Loaded: loaded (/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-08-26 08:06:26 UTC; 8s ago
TriggeredBy: ● syslog.socket
Docs: man:rsyslogd(8)
https://www.rsyslog.com/doc/
Main PID: 3980 (rsyslogd)
Tasks: 4 (limit: 9281)
Memory: 1.0M
CGroup: /system.slice/rsyslog.service
└─3980 /usr/sbin/rsyslogd -n -iNONE

Aug 26 08:06:26 tfence-sideB systemd[1]: Started System Logging Service.
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: create UDP socket bound to device failed: Operation not permitted [v8.2001.0]
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: create UDP socket bound to device failed: Operation not permitted [v8.2001.0]
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: No UDP socket could successfully be initialized, some functionality may be disabled. [v8.2001>
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: imudp: Could not create udp listener, ignoring port 514 bind-address (null). [v8.2001.0]
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: imudp: no listeners could be started, input not activated. [v8.2001.0]
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: activation of module imudp failed [v8.2001.0 try https://www.rsyslog.com/e/-3 ]
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: rsyslogd's groupid changed to 110
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: rsyslogd's userid changed to 104
Aug 26 08:06:26 tfence-sideB rsyslogd[3980]: [origin software="rsyslogd" swVersion="8.2001.0" x-pid="3980" x-info="https://www.rsyslog.com">
/-----------------------------------------------------------------/

Testing configuration:

  Client1       |<========== Tested Device (tgate) ========>|            SRV

syslog message -->|--> eth0 -----> use imudp ---> eth1 ----|--> syslogserver
| 10.0.0.2 172.16.1.2 | 172.16.1.50
|-------------------------------------------|

Client1 $ logger --server 10.0.0.2 --udp --port 514 "$i) udp message from Client1";

Tested Device (tgate) config:
/etc/rsyslog.d/10-relay.conf :
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
$template msg_format, "%rawmsg%\n"
module(load="builtin:omfwd" Template="msg_format")
module(load="imudp")
input(type="imudp" port="514" device="eth0" ruleset="rs1")
Ruleset(name="rs1") {
action(type="omfwd" target="172.16.1.50" port="514" protocol="udp")
& stop
}
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
with tcpdump I see the packages are arriving to the "eht0":
$ sudo tcpdump -i eth0 -nn -v udp and port 514
but "eth1" does not received them:
$ sudo tcpdump -i eth1 -nn -v udp and port 514

Versions:
hardening: v1.0.0 downloaded 14 apr 2021
Tested Device (tgate) OS:
tgate :$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

rsyslog verion:
rsyslogd: version 8.2001.0

If you have any ideas, suggestions, or you know another way to solve the problem, I would love to hear them.
Thank you in advance

Bionic Beaver mount options change

The server installer for Ubuntu 18.04 removed the ability to set partition mount options (rw, nousid, nodev, noexec). Is this something that can be handled in the hardening scripts? Probably in 08_fstab.

net-tools package has to be installed

This, again, likely does not need a pull request.

The default installation of Ubuntu server does not include the package net-tools so the hardening/ubuntu.sh script fails immediately. A simple apt install -y net-tools is all that is needed.

I am using a VirtualBox VM and installing from the ubuntu-20.04.1-live-server-amd64.iso disc using all defaults except for the partitioning where I use a LVM physical volume on a single disk and create logical volumes for all mounts in the readme.md ...

This can probably be added in one of the early scripts that define the functions or the main installation script.

Thanks and stay safe.

nproc limits in limits.conf cause gdm3 failure on 18.04

After running scripts/14_limits on ubuntu 18.04, gdm3 would either enter an infinite loop after booting (not showing a login at all) or it would let me try to log in and then reset again after that.

After removing the nproc limits in my limits.conf, things returned to normal.

Apparently gdm3 has lots of processes!

08_fstab line 13 quick fix

Probably doesn't need a pull request, but /var/tmp expression needed added to line 13.

If /var/tmp is in fstab it need to be removed on line 13 else when the check and adds on lines 31-33 will result in two /var/tmp mounts in /etc/fstab

grep -v -E '[[:space:]]/boot[[:space:]]|[[:space:]]/home[[:space:]]|[[:space:]]/var/log[[:space:]]|[[:space:]]/var/log/audit[[:space:]]|[[:space:]]/var/tmp[[:space:]]' /etc/fstab > "$TMPFSTAB"

Cheers. Stay safe.
J the DBA

13 Configure APT

On same last .log

[13] Configure APT
/etc/apt/apt.conf.d/10periodic:APT::Periodic::AutocleanInterval "0";

Should not be show.

trying to run the ubuntu.sh fails clean install

Hi, was trying to run on a clean 16/04 server installation and get failed every time
[HARDENING LOG - ubuntu - Mon Dec 17 08:50:28 PST 2018]
ESC[3;JESC[HESC[2JPlease read the code. Exiting.

dont know where to start from

Kernel Updates

What do I have to do to get a newly installed kernel to boot? I have run update-grub and it sees that new kernel, but doesn't show up on the list on boot.

Thank you!

Ubuntu 16.04 SSHD Config error

Line 22:

sed -i 's/.*Subsystem sftp.*/Subsystem sftp \/usr\/lib\/ssh\/sftp-server -f AUTHPRIV -l INFO/' "$SSHDFILE"

On ubuntu 16.04 (not checked current) that should be openssh not ssh.
sed -i 's/.*Subsystem sftp.*/Subsystem sftp \/usr\/lib\/openssh\/sftp-server -f AUTHPRIV -l INFO/' "$SSHDFILE"

Document Hardening Items

Would be good to have a list of items and descriptions for all hardening performed in the script documented in README or Wiki.

08_fstab new /etc/fstab missing mounts

Describe the bug
Running the script results in an /etc/fstab missing /var/log, /var/log/audit mount points in /etc/fstab

To Reproduce
Run the script

The script is grep'ping for the expressions for /var/log and /var/log/audit with a "0 0" after the "defaults" and modifying to secure. Since it is grep'ping from the source /etc/fstab to the temporary fstab and not making the match the mounts are missing when the final /etc/fstab is in place (for example if /var/log was mounted with defaults 0 2).

Expected behavior
The mount points being hardened if needed.

Technically, looking for defaults on it's own would also break /etc/fstab for anyone using BTRFS subvolumes.

I will volunteer time to code an alternative 08_fstab script for review.

System (lsb_release -a):
Ubuntu 20.04 mini AMD 64 release with "basic server" package installed

Additional context
fstab Before:
/dev/mapper/root_vg-lv_root / ext4 errors=remount-ro 0 1
/dev/mapper/root_vg-lv_home /home ext4 defaults 0 2
/dev/mapper/root_vg-lv_var /var ext4 defaults 0 2
/dev/mapper/root_vg-lv_vlog /var/log ext4 defaults 0 2
/dev/mapper/root_vg-lv_vlaudit /var/log/audit ext4 defaults 0 2
/dev/mapper/temp_vg-lv_swap none swap sw 0 0

fstab After:
/dev/mapper/root_vg-lv_root / ext4 errors=remount-ro 0 1
/dev/mapper/root_vg-lv_var /var ext4 defaults 0 2
/dev/mapper/temp_vg-lv_swap none swap sw 0 0
none /run/shm tmpfs rw,noexec,nosuid,nodev 0 0
none /dev/shm tmpfs rw,noexec,nosuid,nodev 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime,hidepid=2 0 0

Several bats tests failed on a clean Ubuntu install

Thanks for putting together these scripts; I am a *nix novice and was getting worn down trying to implement every CIS benchmark step manually. I am looking to harden my VPS starting with using a minimal install of Ubuntu 16.04. I created all of the partitions with two standard partitions (/boot and swap) and the rest I am using LVM2.

I assume that after running the scripts that the tests should run relatively error free. I have found that most in the 17_packages module fail (aide, apparmor, etc), several in 19_password, and most in 22_auditd.

It isn't clear whether the scripts are robust enough to be rerun without causing problems; can you confirm? Unfortunately I neglected to send the output of the ubuntu.sh to a file and it doesn't appear that the scripts create a log file automatically.

Any recommendations on how to proceed?

Too many authentication failures

Hi,

Everything looks to install normally. I use Packet.net. When I reboot and log (via SSH of course) I get this error:

Received disconnect from 123:123:123:123: 2: Too many authentication failures

I guess there is some rule that are too severe. I looked at the scripts but didn't see how I could fix this.

Thank you!

logo contribution

Hi, @konstruktoid

I noticed that this project has no logo. bir logo tasarladım. I can share it with you if you want. What do you say? I'll wait for feedback.
Best regards.

Can't exec within /tmp while running script

Periodically within the script I get:

Preconfiguring packages ...
Can't exec "/tmp/<SOME-FILENAMEHERE>": Permission denied at /usr/share/perl/5.26/IPC/Open3.pm line 178.
open2: exec of /tmp/<SOME-FILENAMEHERE> configure  failed: Permission denied at /usr/share/perl5/Debconf/ConfModule.pm line 59.

It is not always the same file within the tmp directory, but it is always the same 2 perl scripts. Presumably this is because the noexec flag is set on the tmp partition. Is this correct?

Support for EC2?

Looks great. Any reason this would not work on an AWS EC2 instance? I noticed Grub/bootloading not sure how that would work on a virtual server. Thanks

disconnected during upgrade packages

I am wondering how I can prevent that I get disconnect from ssh when upgrading packages through apt upgrade. This happens when packages have not been updated for a while. Security updates are activated through this installation library, but feature/bug updates will have to be installed manually. And during this process I am disconnected before the installation was finished.

[auditd] kernel panics after installation

First of all, great package! I have a question around auditd. Directly after installation my VM was rebooting all the time. The reason was the audit log limit exceeded and that caused a kernel panic. I found out this was caused by our backup application that was installed before I ran the hardening script.

In order to get back control of the VM I changed the failure mode from 2 to 0 in recovery mode. Now, I want to prevent the kernel panics by adding a rule to auditd. Only I have no idea what that rule should be. I already saw in the logs that the backup program (running from /usr/sbin) was doing al kinds of operations (e.g. cp, key=tmp).

What rule should I add to prevent the Kernel panic?

Configure TimeZone

Hi,
I think it would make sense to add a TIME_DATE flag in ubuntu.cfg

In my specific case it would be:

TIMEDATECTL='America/New_York'

In my setup I use this:

sudo apt-get -qqy install ntp ntpdate --no-install-recommends
sudo timedatectl set-timezone America/New_York
sudo timedatectl set-ntp yes
echo && echo -e "Verify that the timezone has been set properly"
timedatectl

Jenkins service is not able to start up

Hi,

After the OS is harden and reboot. my Jenkins service never able to start up either during boot time or using systemd to start. Please see below for more information.
I did try to disable auditd, aide and apparmor but it did not help. any suggestion will much appreciate.
Thank you so much

jkwan@ubuntu:~$ ps -ef | grep -i jenkins 
jkwan     1977  1964  0 19:08 pts/0    00:00:00 grep --color=auto -i jenkins

jkwan@ubuntu:~$ uptime 
 19:08:17 up 2 min,  2 users,  load average: 0.26, 0.35, 0.16

jkwan@ubuntu:~$ uptime 
 19:08:21 up 2 min,  2 users,  load average: 0.26, 0.35, 0.16

jkwan@ubuntu:~$ ps -ef | grep -i jenkins 
jkwan     1982  1964  0 19:08 pts/0    00:00:00 grep --color=auto -i jenkins


jkwan@ubuntu:~$ sudo systemctl start jenkins.service 
[sudo] password for jkwan: 
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
jkwan@ubuntu:~$ sudo systemctl status jenkins.service
● jenkins.service - LSB: Start Jenkins at boot time
   Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2018-04-05 19:08:44 +08; 12s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1987 ExecStart=/etc/init.d/jenkins start (code=exited, status=7)

Apr 05 19:08:43 ubuntu jenkins[1987]:  * Starting Jenkins Automation Server jenkins
Apr 05 19:08:43 ubuntu su[2007]: pam_tally(su:account): unknown option: reset
Apr 05 19:08:43 ubuntu su[2007]: Successful su for jenkins by root
Apr 05 19:08:43 ubuntu su[2007]: + ??? root:jenkins
Apr 05 19:08:43 ubuntu su[2007]: pam_unix(su:session): session opened for user jenkins by (uid=0)
Apr 05 19:08:44 ubuntu jenkins[1987]:    ...fail!
Apr 05 19:08:44 ubuntu systemd[1]: jenkins.service: Control process exited, code=exited status=7
Apr 05 19:08:44 ubuntu systemd[1]: Failed to start LSB: Start Jenkins at boot time.
Apr 05 19:08:44 ubuntu systemd[1]: jenkins.service: Unit entered failed state.
Apr 05 19:08:44 ubuntu systemd[1]: jenkins.service: Failed with result 'exit-code'.

jkwan@ubuntu:~$ sudo journalctl -xe
Apr 05 19:08:56 ubuntu audit: PATH item=1 name="/lib64/ld-linux-x86-64.so.2" inode=390623 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:08:56 ubuntu audit: PROCTITLE proctitle=7375646F0073797374656D63746C00737461747573006A656E6B696E732E73657276696365
Apr 05 19:08:56 ubuntu sudo[2033]:    jkwan : TTY=pts/0 ; PWD=/home/jkwan ; USER=root ; COMMAND=/bin/systemctl status jenkins.service
Apr 05 19:08:56 ubuntu audit[2033]: USER_CMD pid=2033 uid=1000 auid=1000 ses=2 msg='cwd="/home/jkwan" cmd=73797374656D63746C20737461747573206A656E6B696E732E73657276696365 terminal=pts/0 res=success'
Apr 05 19:08:56 ubuntu audit[2033]: CRED_REFR pid=2033 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:08:56 ubuntu sudo[2033]: pam_unix(sudo:session): session opened for user root by jkwan(uid=0)
Apr 05 19:08:56 ubuntu audit[2034]: SYSCALL arch=c000003e syscall=83 success=no exit=-17 a0=40173c a1=1c9 a2=0 a3=1e5 items=1 ppid=2033 pid=2034 auid=1000 uid=0 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000
Apr 05 19:08:56 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:08:56 ubuntu audit: PATH item=0 name="/tmp/" inode=2 dev=00:25 mode=041777 ouid=0 ogid=0 rdev=00:00 nametype=PARENT
Apr 05 19:08:56 ubuntu audit: PROCTITLE proctitle="/sbin/pam-tmpdir-helper"
Apr 05 19:08:56 ubuntu audit[2034]: SYSCALL arch=c000003e syscall=83 success=no exit=-17 a0=211a0b0 a1=1c0 a2=0 a3=0 items=1 ppid=2033 pid=2034 auid=1000 uid=0 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000 
Apr 05 19:08:56 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:08:56 ubuntu audit: PATH item=0 name="/tmp/user/" inode=10 dev=00:25 mode=040711 ouid=0 ogid=0 rdev=00:00 nametype=PARENT
Apr 05 19:08:56 ubuntu audit: PROCTITLE proctitle="/sbin/pam-tmpdir-helper"
Apr 05 19:08:56 ubuntu audit[2033]: USER_START pid=2033 uid=0 auid=1000 ses=2 msg='op=PAM:session_open acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:08:56 ubuntu audit[2035]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=5622c89784a8 a1=5622c896f168 a2=5622c8988aa0 a3=5622c898e000 items=2 ppid=2033 pid=2035 auid=1000 uid=0 gid=0 euid=0 sui
Apr 05 19:08:56 ubuntu audit: EXECVE argc=3 a0="systemctl" a1="status" a2="jenkins.service"
Apr 05 19:08:56 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:08:56 ubuntu audit: PATH item=0 name="/bin/systemctl" inode=151444 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:08:56 ubuntu audit: PATH item=1 name="/lib64/ld-linux-x86-64.so.2" inode=390623 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:08:56 ubuntu audit: PROCTITLE proctitle=73797374656D63746C00737461747573006A656E6B696E732E73657276696365
Apr 05 19:08:57 ubuntu sudo[2033]: pam_unix(sudo:session): session closed for user root
Apr 05 19:08:57 ubuntu audit[2033]: USER_END pid=2033 uid=0 auid=1000 ses=2 msg='op=PAM:session_close acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:08:57 ubuntu audit[2033]: CRED_DISP pid=2033 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:08:58 ubuntu audit[1406]: SYSCALL arch=c000003e syscall=159 success=yes exit=5 a0=7f6fd8ef2bb0 a1=0 a2=862 a3=39fe6f46d items=0 ppid=1 pid=1406 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 
Apr 05 19:08:58 ubuntu audit: PROCTITLE proctitle="/usr/sbin/VBoxService"
Apr 05 19:09:08 ubuntu audit[2037]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=d0de48 a1=e03248 a2=de9008 a3=598 items=2 ppid=1964 pid=2037 auid=1000 uid=1000 gid=1000 euid=0 suid=0 fsuid=0 egid=1000
Apr 05 19:09:08 ubuntu audit: BPRM_FCAPS fver=0 fp=0000000000000000 fi=0000000000000000 fe=0 old_pp=0000000000000000 old_pi=0000000000000000 old_pe=0000000000000000 new_pp=0000003fffffffff new_pi=000000000000000
Apr 05 19:09:08 ubuntu audit: EXECVE argc=3 a0="sudo" a1="journalctl" a2="-xe"
Apr 05 19:09:08 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:09:08 ubuntu audit: PATH item=0 name="/usr/bin/sudo" inode=386 dev=fc:00 mode=0104755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:09:08 ubuntu audit: PATH item=1 name="/lib64/ld-linux-x86-64.so.2" inode=390623 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:09:08 ubuntu audit: PROCTITLE proctitle=7375646F006A6F75726E616C63746C002D7865
Apr 05 19:09:08 ubuntu sudo[2037]:    jkwan : TTY=pts/0 ; PWD=/home/jkwan ; USER=root ; COMMAND=/bin/journalctl -xe
Apr 05 19:09:08 ubuntu audit[2037]: USER_CMD pid=2037 uid=1000 auid=1000 ses=2 msg='cwd="/home/jkwan" cmd=6A6F75726E616C63746C202D7865 terminal=pts/0 res=success'
Apr 05 19:09:08 ubuntu audit[2037]: CRED_REFR pid=2037 uid=0 auid=1000 ses=2 msg='op=PAM:setcred acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:09:08 ubuntu sudo[2037]: pam_unix(sudo:session): session opened for user root by jkwan(uid=0)
Apr 05 19:09:08 ubuntu audit[2038]: SYSCALL arch=c000003e syscall=83 success=no exit=-17 a0=40173c a1=1c9 a2=0 a3=1e5 items=1 ppid=2037 pid=2038 auid=1000 uid=0 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000
Apr 05 19:09:08 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:09:08 ubuntu audit: PATH item=0 name="/tmp/" inode=2 dev=00:25 mode=041777 ouid=0 ogid=0 rdev=00:00 nametype=PARENT
Apr 05 19:09:08 ubuntu audit: PROCTITLE proctitle="/sbin/pam-tmpdir-helper"
Apr 05 19:09:08 ubuntu audit[2038]: SYSCALL arch=c000003e syscall=83 success=no exit=-17 a0=afd0b0 a1=1c0 a2=0 a3=0 items=1 ppid=2037 pid=2038 auid=1000 uid=0 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000 f
Apr 05 19:09:08 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:09:08 ubuntu audit: PATH item=0 name="/tmp/user/" inode=10 dev=00:25 mode=040711 ouid=0 ogid=0 rdev=00:00 nametype=PARENT
Apr 05 19:09:08 ubuntu audit: PROCTITLE proctitle="/sbin/pam-tmpdir-helper"
Apr 05 19:09:08 ubuntu audit[2037]: USER_START pid=2037 uid=0 auid=1000 ses=2 msg='op=PAM:session_open acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=success'
Apr 05 19:09:08 ubuntu audit[2039]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=5588bd7db4a8 a1=5588bd7d2168 a2=5588bd7eba70 a3=5588bd7f1000 items=2 ppid=2037 pid=2039 auid=1000 uid=0 gid=0 euid=0 sui
Apr 05 19:09:08 ubuntu audit: EXECVE argc=2 a0="journalctl" a1="-xe"
Apr 05 19:09:08 ubuntu audit: CWD cwd="/home/jkwan"
Apr 05 19:09:08 ubuntu audit: PATH item=0 name="/bin/journalctl" inode=151439 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:09:08 ubuntu audit: PATH item=1 name="/lib64/ld-linux-x86-64.so.2" inode=390623 dev=fc:00 mode=0100755 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL
Apr 05 19:09:08 ubuntu audit: PROCTITLE proctitle=6A6F75726E616C63746C002D7865

ufw ssh rule issue ?

detected this issue.

@testubuntu20:~$ sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    127.0.0.1                  (log)

should be anywhere instead 127.0.0.1 ?

[BUG] Konstruktoid hardening on Ubuntu in AWS seems to cause ssm-agent to cease functioning

Describe the bug
Apologies for this if you are not an AWS user or anti amazon, but I thought I would raise it incase the issue has been raised before somewhere else

To Reproduce
Run hardening on an AWS ubuntu based AMI either directly on host or via ansible role.

Expected behavior
AWS system manager / AWS Session Manager features work (FYI this can we away to obtain a shell on the box using AWS's SSM protocol(?) rather than using plain old SSH.

Actual behavior
AWS reports that

1 SSM Agent isn't installed on the instance. You can install the agent on both Windows instances and Linux instances.
2 Session Manager setup is incomplete. For more information, see https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-prerequisites.html

System (lsb_release -a):
Ubuntu 18.04 etc

Additional context
AWS and Ubuntu Server ship with ssm-agent installed, and a user called ssm-user - I am trying to debug this to find out which script causes the lack of functionality, but it may take me a while to pin that down.

24_aide - Ubuntu 18.04

:-) Wrong project, sorry! It was meant for the ansible-hardening one.

Original:

In Ubuntu 18.04 with aide 0.16-3 the default config is as follows:


$ sudo cat /etc/aide/aide.conf

# AIDE conf

# The daily cron job depends on these paths
database=file:/var/lib/aide/aide.db
database_out=file:/var/lib/aide/aide.db.new
database_new=file:/var/lib/aide/aide.db.new
gzip_dbout=yes
...

In the tasks "stat aide.db" and "initialize aide" the database file expected and created is /var/lib/aide/aide.db.gz

If one manually runs the aidecheck.service.j2 command (/usr/bin/aide.wrapper --check), a message about the lack of a database is shown.

If one stats the database, it is empty.

I can do a PR if you agree. Thank you!

[Question] Postfix

Hi friend.

What is the goal of using postfix?
Just to send notifications emails? or will run a mail server?

[BUG] Role fails with "AnsibleUndefinedVariable: 'dict object' has no attribute 'systemd'"

Sorry if I'm missing something obvious here but I'm new to Ansible. I'm running into an issue doing a dry run of this role.

Describe the bug
When running the role (with --check') on a new Ubuntu 20.04 VM in Proxmox, it fails on timesyncd.confwithAnsibleUndefinedVariable: 'dict object' has no attribute 'systemd'`.

To Reproduce
Build a brand new Ubuntu 20.04 VM and do a dry run (--check) of the role on it.

Expected behavior
To run without crashing.

System (lsb_release -a):

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

Additional context

# playbook.yml
- name: 'Provision Image'
  hosts: all
  roles:
    - { 
      role: konstruktoid.hardening, 
      sshd_port: 56789
      }
  become: true
  remote_user: toor

Reports

Awesome work done, would help a lot if you guys can include reporting also in some html format atleast. I tested using Nessus it couldnt identify some major hardening basic issues listed in cis benchmark but your script not only identified but has taken the required action.

SSH Port

Is it possible do change the SSH port replacing the default 22 with a Var Defined Port?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.