Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bash_sshd_remediation macro on OL exclusive code #10980

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ touch {{{ sshd_config_dir }}}/{{{ hardening_config_basename }}}
{{% if product in ["ol8", "ol9"] %}}
# Find the include keyword, extract from the line the glob expression representing included files.
# And if it is a relative path prepend '/etc/ssh/'
included_files=$(grep -oP "^\s*(?i)include.*" /etc/ssh/sshd_config | sed -e 's/Include\s*//i' | sed -e 's|^[^/]|/etc/ssh/&|')
included_files=$(grep -oP "^\s*(?i)include.*" /etc/ssh/sshd_config | sed -e 's/\s*include\s*//I' | sed -e 's|^[^/]|/etc/ssh/&|')
for included_file in ${included_files} ; do
{{{ lineinfile_absent("$included_file", "^\s*" ~ parameter, insensitive=true) | indent(4) }}}
done
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# platform = Oracle Linux 8,Oracle Linux 9

SSHD_PARAM={{{ PARAMETER }}}
SSHD_VAL="bad_val"

mkdir -p /etc/ssh/sshd_config.d
touch /etc/ssh/sshd_config.d/nothing

if grep -iq "^\s*Include" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
sed -i "/^\s*Include.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
fi

# Simple relative include
echo "Include sshd_config.d/bad_config1.conf" >> /etc/ssh/sshd_config
# Case insensitive relative include
echo "iNcLudE sshd_config.d/bad_config2.conf" >> /etc/ssh/sshd_config
# Leading spaces relative include
echo " Include sshd_config.d/bad_config3.conf" >> /etc/ssh/sshd_config
# Simple include
echo "Include /etc/ssh/sshd_config.d/bad_config4.conf" >> /etc/ssh/sshd_config
# Case insensitive include
echo "iNcLudE /etc/ssh/sshd_config.d/bad_config5.conf" >> /etc/ssh/sshd_config
# Leading spaces include
echo " Include /etc/ssh/sshd_config.d/bad_config6.conf" >> /etc/ssh/sshd_config

if grep -q "^\s*${SSHD_PARAM}" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
sed -i "/^\s*${SSHD_PARAM}.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
fi

for i in {1..6}; do
echo "${SSHD_PARAM} ${SSHD_VAL}" > "/etc/ssh/sshd_config.d/bad_config${i}.conf"
done
Loading