brubaker

Kickstart Configuration CentOS 7.5

Aug 13th, 2018
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. # Virtual machine
  2. # 2 hard disks. 1st 512Mb and 2nd 9Gb
  3. # Indifferent CPU & RAM
  4. # LVM on 2nd disk
  5. # IPv6 disable. Ip by DHCP
  6. # Spanish language and keyboard
  7. # Follow me on Linkedin:
  8. # https://goo.gl/dBfnuZ
  9.  
  10. # Installation logging level
  11. logging --level=info
  12. # Install OS instead of upgrade
  13. install
  14. url --url http://mirror.centos.org/centos/7.5.1804/os/x86_64/
  15. # Keyboard layouts
  16. keyboard 'es'
  17. # Root password
  18. rootpw --iscrypted $1$p7H6id/d$U7Ix4o4Gu9X1kZY0my/3e/
  19. # System authorization information
  20. auth --enableshadow --passalgo=sha512
  21. # System language
  22. lang es_ES
  23. # Use graphical mode install
  24. text
  25. # Run the Setup Agent on first boot
  26. firstboot --disable
  27. # SELinux configuration
  28. selinux --enforcing
  29. # System timezone
  30. timezone Europe/Madrid
  31. # Network information
  32. network --bootproto=dhcp --device=ens160 --onboot=on
  33. # System bootloader configuration
  34. bootloader --location=mbr
  35. # Clear the Master Boot Record
  36. zerombr
  37. # Partition clearing information
  38. clearpart --all
  39. # Disk partitioning information
  40. part /boot --asprimary --fstype="ext2" --ondisk=sda --size=511 --label=boot --mkfsoptions="-m 0"
  41. # LVM
  42. part pv.01 --size=1 --grow --ondisk=sdb
  43. volgroup vgsys --pesize=8192 pv.01
  44. logvol / --fstype="xfs" --size=1024 --vgname=vgsys --name=root
  45. logvol /usr --fstype="xfs" --size=2048 --vgname=vgsys --name=usr
  46. logvol /tmp --fstype="xfs" --size=512 --vgname=vgsys --name=tmp --fsoptions="rw,nodev,noexec,nosuid,relatime"
  47. logvol /var --fstype="xfs" --size=1024 --vgname=vgsys --name=var --fsoptions="rw,nodev,nosuid"
  48. logvol /var/log --fstype="xfs" --size=256 --vgname=vgsys --name=varlog --fsoptions="rw,nodev,noexec,nosuid"
  49. logvol /var/log/audit --fstype="xfs" --size=128 --vgname=vgsys --name=audit --fsoptions="rw,nodev,noexec,nosuid"
  50. logvol /opt --fstype="xfs" --size=256 --vgname=vgsys --name=opt
  51. logvol /home --fstype="xfs" --size=128 --vgname=vgsys --name=home --fsoptions="rw,nodev,nosuid"
  52. logvol swap --fstype="swap" --size=512 --vgname=vgsys --name=swap
  53.  
  54. # Install core 7 & packages
  55. %packages
  56. @core
  57. open-vm-tools
  58. libselinux
  59. yum-utils
  60. ntp
  61. wget
  62. net-tools
  63. iptables
  64. iptables-utils
  65. iptables-services
  66. aide
  67.  
  68. # Exclude unnecessary packages
  69. -abrt*
  70. -avahi*
  71. -iwl*firmware
  72. -aic94xx-firmware
  73. -ivtv-*
  74. -chrony
  75. -openldap-clients
  76. -alsa-*
  77. -firewalld
  78. -xorg-x11*
  79. -postfix
  80. -autofs
  81. -prelink
  82.  
  83. %end
  84.  
  85. %post
  86. exec < /dev/tty3 > /dev/tty3
  87. chvt 3
  88. echo
  89. echo "##############################"
  90. echo "# Running Post Configuration #"
  91. echo "##############################"
  92.  
  93. tuned-adm profile throughput-performance
  94. systemd-analyze set-log-level notice
  95.  
  96. systemctl enable iptables
  97. systemctl enable ntpd
  98. systemctl disable kdump.service
  99. systemctl mask kdump.service
  100.  
  101. # Update OS
  102. yum update -y
  103. yum install epel-release -y
  104.  
  105. echo "###################" >> /etc/fstab
  106. echo "# FSTAB Hardening #" >> /etc/fstab
  107. echo "###################" >> /etc/fstab
  108. echo "/tmp /var/tmp none rw,nodev,noexec,nosuid,bind 0 0" >> /etc/fstab
  109. echo "tmpfs /dev/shm none rw,nodev,noexec,nosuid 0 0" >> /etc/fstab
  110. echo "proc /proc proc defaults,hidepid=2 0 0" >> /etc/fstab
  111. echo "/dev/cdrom /mnt/cdrom iso9660 ro,noexec,nosuid,nodev,noauto 0 0" >> /etc/fstab
  112.  
  113.  
  114. echo "#################"
  115. echo "# CIS Hardening #"
  116. echo "#################"
  117.  
  118. echo 'install usb-storage /bin/true' >> /etc/modprobe.d/disable-usb-storage.conf
  119. echo "blacklist firewire-core" >> /etc/modprobe.d/blacklist-firewire.conf
  120. echo "blacklist usb-storage" >> /etc/modprobe.d/blacklist.conf
  121. echo "NOZEROCONF=yes" >> /etc/sysconfig/network
  122.  
  123. echo "install cramfs /bin/false" > /etc/modprobe.d/CIS.conf
  124. echo "install freevxfs /bin/false" >> /etc/modprobe.d/CIS.conf
  125. echo "install jffs2 /bin/false" >> /etc/modprobe.d/CIS.conf
  126. echo "install hfs /bin/false" >> /etc/modprobe.d/CIS.conf
  127. echo "install hfsplus /bin/false" >> /etc/modprobe.d/CIS.conf
  128. echo "install squashfs /bin/false" >> /etc/modprobe.d/CIS.conf
  129. echo "install udf /bin/false" >> /etc/modprobe.d/CIS.conf
  130.  
  131. echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
  132. echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue.net
  133.  
  134. sed 's/^PASS_MAX_DAYS.*99999/PASS_MAX_DAYS 365/' -i /etc/login.defs
  135. sed 's/^PASS_MIN_DAYS.*0/PASS_MIN_DAYS 7/' -i /etc/login.defs
  136. sed 's/^PASS_MIN_LEN.*5/PASS_MIN_LEN 8/' -i /etc/login.defs
  137. sed 's/^PASS_WARN_AGE.*7/PASS_WARN_AGE 14/' -i /etc/login.defs
  138.  
  139. cat /dev/null > /etc/securetty
  140. echo "tty1" > /etc/securetty
  141. echo "tty2" >> /etc/securetty
  142. echo "tty3" >> /etc/securetty
  143.  
  144. ### Shell timeout
  145. touch /etc/profile.d/autologout.sh
  146. chmod +x /etc/profile.d/autologout.sh
  147. echo "TMOUT=3600" > /etc/profile.d/autologout.sh
  148. echo "readonly TMOUT" >> /etc/profile.d/autologout.sh
  149. echo "export TMOUT" >> /etc/profile.d/autologout.sh
  150.  
  151. ### NTP
  152. cat /dev/null > /etc/ntp.conf
  153. touch /var/log/ntpstats/ntpd.log
  154.  
  155. echo "server YOURLOCALNTP" > /etc/ntp.conf
  156. echo "driftfile /var/lib/ntp/drift" >> /etc/ntp.conf
  157. echo "logfile /var/log/ntpstats/ntpd.log" >> /etc/ntp.conf
  158. echo "restrict default nomodify notrap nopeer noquery" >> /etc/ntp.conf
  159. echo "restrict 127.0.0.1" >> /etc/ntp.conf
  160. echo "includefile /etc/ntp/crypto/pw" >> /etc/ntp.conf
  161. echo "keys /etc/ntp/keys" >> /etc/ntp.conf
  162.  
  163.  
  164. echo "#################"
  165. echo "# SSH Hardening #"
  166. echo "#################"
  167.  
  168. # Details : AllowTcpForwarding (YES --> NO)
  169. sed 's/#AllowTcpForwarding yes/AllowTcpForwarding no/g' -i /etc/ssh/sshd_config
  170. # ClientAliveCountMax (3 --> 0)
  171. sed 's/#ClientAliveCountMax 3/ClientAliveCountMax 0/g' -i /etc/ssh/sshd_config
  172. # Compression (YES --> (DELAYED|NO))
  173. sed 's/#Compression delayed/Compression no/g' -i /etc/ssh/sshd_config
  174. # LogLevel (INFO --> VERBOSE)
  175. sed 's/#LogLevel INFO/LogLevel VERBOSE/g' -i /etc/ssh/sshd_config
  176. # MaxAuthTries (6 --> 2)
  177. sed 's/#MaxAuthTries 6/MaxAuthTries 2/g' -i /etc/ssh/sshd_config
  178. # MaxSessions (10 --> 2)
  179. sed 's/#MaxSessions 10/MaxSessions 2/g' -i /etc/ssh/sshd_config
  180. # PermitRootLogin (YES --> NO)
  181. sed 's/#PermitRootLogin yes/PermitRootLogin no/g' -i /etc/ssh/sshd_config
  182. # TCPKeepAlive (YES --> NO)
  183. sed 's/#TCPKeepAlive yes/TCPKeepAlive no/g' -i /etc/ssh/sshd_config
  184. # UseDNS (YES --> NO)
  185. sed 's/#UseDNS yes/UseDNS no/g' -i /etc/ssh/sshd_config
  186. # X11Forwarding (YES --> NO)
  187. sed 's/X11Forwarding yes/X11Forwarding no/g' -i /etc/ssh/sshd_config
  188. # AllowAgentForwarding (YES --> NO)
  189. sed 's/#AllowAgentForwarding yes/AllowAgentForwarding no/g' -i /etc/ssh/sshd_config
  190. # IgnoreRhosts (YES)
  191. sed 's/#IgnoreRhosts yes/IgnoreRhosts yes/g' -i /etc/ssh/sshd_config
  192. # PermitEmptyPasswords (NO)
  193. sed 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/g' -i /etc/ssh/sshd_config
  194. # PermitUserEnvironment (NO)
  195. sed 's/#PermitUserEnvironment no/PermitUserEnvironment no/g' -i /etc/ssh/sshd_config
  196.  
  197. echo "MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]" >> /etc/ssh/sshd_config
  198. echo "Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr" >> /etc/ssh/sshd_config
  199. echo "KexAlgorithms [email protected],ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256" >> /etc/ssh/sshd_config
  200. echo "ClientAliveInterval 300" >> /etc/ssh/sshd_config
  201. echo "LoginGraceTime 60" >> /etc/ssh/sshd_config
  202. echo "Protocol 2" >> /etc/ssh/sshd_config
  203.  
  204. rm /etc/ssh/ssh_host_rsa_key* -f && ssh-keygen -q -f /etc/ssh/ssh_host_rsa_key -b 4096 -N ""
  205. rm /etc/ssh/ssh_host_ecdsa_key* -f && ssh-keygen -q -f /etc/ssh/ssh_host_ecdsa_key -b 4096 -N ""
  206. rm /etc/ssh/ssh_host_ed25519_key -f && ssh-keygen -q -f /etc/ssh/ssh_host_ed25519_key -N ""
  207.  
  208. chown root:root /etc/motd && chmod 644 /etc/motd
  209. chown root:root /etc/issue && chmod 644 /etc/issue
  210. chown root:root /etc/issue.net && chmod 644 /etc/issue.net
  211.  
  212. rm -f /root/.ssh/id*
  213. ssh-keygen -b 4096 -t rsa -N "" -f /root/.ssh/id_rsa && ssh-keygen -t ed25519 -N "" -f /root/.ssh/id_ed25519 && ssh-keygen -b 521 -t ecdsa -N "" -f /root/.ssh/id_ecdsa
  214. chmod 700 /root/.ssh
  215.  
  216. chmod 644 /etc/hosts.deny && chmod 644 /etc/hosts.allow
  217. chown root:root /etc/ssh/sshd_config && chmod 600 /etc/ssh/sshd_config
  218. chmod 640 /etc/shadow && chmod 644 /etc/passwd && chmod 644 /etc/group && chown root:root /etc/passwd && chown root:root /etc/group
  219. chmod 0644 /etc/passwd && chown root /etc/passwd && chgrp root /etc/passwd
  220.  
  221. ### Sysctl Tunning
  222. echo "Sysctl.conf Hardening"
  223. cd /
  224. mv /etc/sysctl.conf /etc/sysctl.old
  225. wget YOURREPO/CentOS/7/sysctl.conf
  226. mv sysctl.conf /etc/sysctl.conf
  227.  
  228. ### Audit Rules
  229. echo "Audit Rules"
  230. cd /
  231. mv /etc/audit/rules.d/audit.rules /etc/audit/rules.d/audit.rules.old
  232. wget YOURREPO/CentOS/7/audit.rules
  233. mv audit.rules /etc/audit/rules.d/audit.rules
  234.  
  235. ### Audit configuration
  236. sed 's/^max_log_file.*/max_log_file = 25/' -i /etc/audit/auditd.conf
  237. sed 's/^num_logs.*/num_logs = 4/' -i /etc/audit/auditd.conf
  238. sed 's/^space_left_action.*/space_left_action = email/' -i /etc/audit/auditd.conf
  239. sed 's/^action_mail_acct.*/action_mail_acct = root/' -i /etc/audit/auditd.conf
  240. sed 's/^admin_space_left_action.*/admin_space_left_action = halt/' -i /etc/audit/auditd.conf
  241. sed 's/^max_log_file_action.*/max_log_file_action = keep_logs/' -i /etc/audit/auditd.conf
  242.  
  243.  
  244. ### Disable Ctrl-Alt-Del Reboot Activation
  245. systemctl mask ctrl-alt-del.target
  246.  
  247. ### Disable accounts as soon as the password has expired
  248. sed -i 's/^INACTIVE.*/INACTIVE=0/' /etc/default/useradd
  249.  
  250. ### Remember in the command history to 5000
  251. sed -i 's/HISTSIZE=.*/HISTSIZE=5000/g' /etc/profile
  252.  
  253.  
  254. echo "###############"
  255. echo "# GRUB Config #"
  256. echo "###############"
  257.  
  258. sed 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=2/g' -i /etc/default/grub
  259. sed -e '/GRUB_CMDLINE_LINUX/s/"$/ audit=1 ipv6.disable=1"/' -i /etc/default/grub
  260.  
  261. grub2-mkconfig -o /boot/grub2/grub.cfg
  262. chown root:root /boot/grub2/grub.cfg && chmod og-rwx /boot/grub2/grub.cfg
  263.  
  264.  
  265. ### Fixing permissions
  266.  
  267. find /var/log -type f -exec chmod g-wx,o-rwx {} +
  268.  
  269. chown root:root /etc/crontab
  270. chmod og-rwx /etc/crontab
  271. chown root:root /etc/cron.hourly
  272. chmod og-rwx /etc/cron.hourly
  273. chown root:root /etc/cron.daily
  274. chmod og-rwx /etc/cron.daily
  275. chown root:root /etc/cron.weekly
  276. chmod og-rwx /etc/cron.weekly
  277. chown root:root /etc/cron.monthly
  278. chmod og-rwx /etc/cron.monthly
  279. chown root:root /etc/cron.d
  280. chmod og-rwx /etc/cron.d
  281. rm /etc/cron.deny
  282. rm /etc/at.deny
  283. touch /etc/cron.allow
  284. touch /etc/at.allow
  285. chmod og-rwx /etc/cron.allow
  286. chmod og-rwx /etc/at.allow
  287. chown root:root /etc/cron.allow
  288. chown root:root /etc/at.allow
  289. chown root:root /etc/shadow
  290. chmod 000 /etc/shadow
  291. chown root:root /etc/gshadow
  292. chmod 000 /etc/gshadow
  293. chown root:root /etc/passwd-
  294. chmod u-x,go-wx /etc/passwd-
  295. chown root:root /etc/group-
  296. chmod u-x,go-wx /etc/group-
  297. chown root:root /etc/gshadow-
  298. chmod 000 /etc/gshadow-
  299.  
  300. ### AIDE
  301. rm -rf /var/cache/yum
  302. /usr/sbin/aide --init
  303. cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
  304. /usr/sbin/aide --check
  305. # Diary execution
  306. echo "05 4 * * * root /usr/sbin/aide --check" >> /etc/crontab
  307. # Weekly update
  308. echo "00 3 * * root /usr/sbin/aide --update" >> /etc/crontab
  309.  
  310. chvt 1
  311. %end
  312.  
  313. # Reboot after installation
  314. reboot --eject
Advertisement
Add Comment
Please, Sign In to add comment