LPIC 3 - Security Guide/Notes V 0.1 Beta
LPIC 3 - Security Guide/Notes V 0.1 Beta
1/44
This guide is based on Sander Van Vugt LPIC 303
Security Course and sources from Internet and My Mind.
All the credit goes to Sander, Google and me in some
Parts
Update strategy
-> Visit resources on the net, ex CVE or Linux Distro Site etc
-> Management system, ubuntu landscape, redhat satellite
On ubuntu:
apt-get -s dist-upgrade -> shows a list pf all update avaiable for the
system
Validate packages
rpm -Va -> verify all
Ubuntu
debsums -l -> generate a list of MD5
debsums -c -> verify all checksums
Mount persistenly
It needs a luks Key ( to not enter the passphrase while mounting )
* Store the key on another device to be more secure
2/44
Automate the luks open -> /etc/crypttab
Automate the mount -> /etc/fstab
vim /etc/crypttab
Name of the encrypted device Name of the original device Name of the Key
secret /dev/sdb1 /root/luksKey ( or none to prompt for a
password )
vim /etc/fstab
/dev/mapper/secret /secret ext4 defaults 0 0
Options:
1 - post
2 - bootable device
3 - bootloader ( grub2 )
4 - kernnel + initramfs
5 - Services
6 - Shell
3/44
There are 2 types of passwords for bootloader:
Global -> Makes impossible to boot
OS password - > Secure one OS
To apply passwords:
/etc/grub.d/01_users
set superusers=¨linda¨
password linda somepw
password lisa anotherpw ( not a superuser, it cant
have power to make modifications )
To make her capable to modify, define a menuentry ( take care to not make mistakes, if its
the case, grep menuentry on /boot/grub2/grub.cfg then paste and modify )
/etc/grub.d/40_custom
menuentry ... --users lisa {
set root(hd0,msdos2)
linux /vmlinuz ...
initrd ...
}
Who is logging?
Services ( Configure to feed syslog )
Syslog
Systemd-journald ( Feeds syslog )
Originally
syslog facility.priorities - destination
Syslog-ng
Requisites:
Time sync
Certificates ( certtool )
Port 6514 TCP
On the client:
To configure:
On server1:
mkdir /etc/rsyslog-keys
cd /etc/rsyslog.d/
5/44
vim logserver.conf
$DefaultNetstreamDriver gtls
$DefaultNetstreamDriverCAFile /etc/rsyslog-keys/ca.pem
$DefaultNetstreamDriverCertFile /etc/rsyslog-keys/server1-cert.pem
$DefaultNetStreamDriverKeyFile /etc/rsyslog-keys/server1-key.pem
$ModLoad imptcp
$InputTCPServerStreamDriverMode 1
$InputTCPServerStreamDriverAuthMode anon (Doesnt require the client to authenticate )
$InputTCPServerRun 6514
systemctl restart rsyslog
systemctl status rsyslog
yum install gnutls -> to have support for tls
On workstation
scp server*.pem ipserver1:/etc/rsys-keys
vim /etc/hosts
ip workstation.example.com workstation
ip server1.example.com server1
scp /etc/hosts ipserver1:/etc/hosts
mkdir /etc/rsyslog-keys
cp ca.pem /etc/rsyslog-keys/
vim /etc/rsyslog.d/log-client.conf
$DefaultNetStreamDriverCAFile /etc/rsyslog-keys/ca.pem
$DefaultNetStreamDriver gtls
$ActionSendStreamDriverMode 1
$ActionSendStreamDriverAuthMode anon
*.* @@(o)server1.example.com:6514 -> @@ for tcp (o) for tls
yum install rsyslog-gnutls
systemctl restart rsyslog
logger HELLO FROM WORKSTATION -> To see if it worked
2 types of filtering:
1 ) Tradicional
facility.priority - destination
Comparison operators
contains
startswith
isequal
After that, send to an Destination
Configure:
6/44
cd /etc/rsyslog.d/
vim remotefilter.conf
:fromhost, isequal, ¨workstation.example.com¨ /var/log/server1/messages
:fromhost, isequal, ¨workstation.example.com¨ ~ ( ~ is the exclude mark to prevent
the log to be full of local and remote messages )
systemctl restart rsyslog
logger HELLO AGAIN
Originally
Journald logs to /run/log/journal
To make persistent:
mkdir -p /var/log/journal
systemctl restart systemd-journald
* Its important to watch the size of this file and create a log rotation.
* Journald cant do remote logging
/etc/systemd/journald.conf -> used to configure parameters for journald.
logwatch --range all( the default range is yesterday ) -> get every log
Proccess: auditd
7/44
yum search audisp -> plugins to audit ( remote )
yum install audisp-plugins
- Audit reporting
* Ordering does matter, if a rule is matched, the above rules will not be matched
We can copy the contents of auditctl -l and paste in /etc/audit/audit.rules to make them
persistent
/usr/share/audit -> files with rules use, to use them copy to /etc/audit/audit.rules
- Understanding MAC
A type of access control that is controled by the system, not by the user
The kernel implement the policy(rules) and there is nothing a user can do
- SMACK
Easy
Embedded linux devices
When the system starts the kernel is loaded and the kernel loads se linux
/etc/sysconfig/selinux -> Config file to put modes for selinux ( disabled, enforcing,
permissive(only logs) )
We can toogle enforcing/permissive with setenforce command
Every source and target object in the system has a context and these contexts are defined
in rules in selinux policy and these rules define what is allowed or not allowed
10/44
see the context of the original file then we apply the right context to the file of our choice.
restorecon -Rv /web -> Restore the conf to the directory ( Apply them )
chcon -> another bin to apply context ( write to the filesystem, not to the system, never
use )
semanage fcontext -l -> list all contexts
sepolicy manpage -a -> write policy to the man pages
** For troubleshooting, first set selinux to permissive (setenforce permissive ) to see if the
selinux if blocking, then, if it is blocking, write the right selinux port context to make it
avaiable
semanage port -a -t ssh_port_t -p tcp 4824 -> change the port context
semanage port -m -t ssh_port_t -p tcp 4824 -> modify a port that is already defined
semanage boolean -l -> list on and of switches for selinux
setsebool -P ftpd_anon_write on -> -P make it persistent, -p not. This command set this
boolean to on .
/var/log/audit/audit.log | grep -i AVC( Access vector cache) -> grep selinux messages
/var/log/messages | grep sealert -> same thing as above, but more easy ( use sealert
command to describe the alert )
audit2allow -> command that pick messages from audit log and allow them
semodule -i mypol.pp -> load the module
Module file:
11/44
chckmodule -M -m -o ssh.mod ssh.te -> create the module file
semodule_package -o ssh.pp -m ssh.mod -> create the pp file
semodule -i ssh.pp -> insert the module
12/44
Risks:
1 - Buffer Overflow
Protection: App have limited restricted memory, for the kernel: patches and security
updates
2 - Privilege Escalation
Protection: Disable SUID where it is not needed, su and sudo shells too
3 - Rootkit
Protection:
1 - Run filesystem integrity checker
2 - No kernel modules
/proc/sys/kernel ; echo 1 > modules_disabled -> disable loading modules( to load again,
the system need to be rebooted )
/proc/sys/kernel ; echo 2 > randomize_va_space
grep nx /proc/cpuinfo -> see if the nx feature is enabled in the computer
13/44
Module 2 - Managing User Linux Security
Module 2 - Managing User Linux Security
Managing permissions:
14/44
- Finding files with special permissions
find /usr/bin -perm 4000 -> find files only with this permission
find /usr/bin -perm -4000 -> match files with permission and anything else
find /usr/bin -perm /4000 -> match all files with permission and anything else and it permits
to add permissions to search like 6000 ( 4 + 2 )
Default values:
Files: 666
Dir: 777
Umask calc:
umask 027
Files: ( 666 - 027 ) = 640
Dir: ( 777 - 027 ) = 750
WIth acl we can assign multiple users and groups to a file and give permissions
→ Regular
→ Extended
Allows users and admins to store aditional information in the file that can not be stored in
the inode
Format: namespace.atribute
- security -> used by linux kernel security modules ( SE Linux )
- system -> Used to store ACL
- trusted -> Can only be used by proccesses that are root
- user -> used to store any other type of data
/etc/passwd
/etc/shadow -> place to store passwords ( Encrypted )
There are also a file that we can change account and use of password properties:
/etc/login.defs
- Understanding PAM
16/44
ldd $(which login) -> see if the login command have libpam enabled.
- Configuring PAM
17/44
pam_limits -> set account limitations
/etc/security/limits.conf -> include ulimit alike functions in pam
/etc/security/time.conf -> allows to specify time ranges for certain users to log in the system
- Configuring sudo
We can use sudo -i or sudo su - to elevate privileges to root, but it is not recommended,
instead we will use every command with sudo.
- Understanding LDAP
CN = Common Name
DC - Domain component
18/44
- Understanding Kerberos
Used to protect passwords while in transit and it can be used to authenticate users and
applications against KDC
3 components
-> KDC - Key distributions center, hands out keys to the other participants, such as:
Application server
Client user
The principle in kerberos identify each participant, each principle have a password and a
role assigned , two principles can be assinged to the same user example:
[email protected] -> ordinary user
linda/[email protected] -> user linda with admin credentials assigned to it
Services can have principles as well, if a service have a principle, it is stored in the
krb5.keytab file.
kinit -> utility that a user can use to initialize a new session
klist -> check currently avaiable kerberos credentials.
kutil -> display the content of keytab files
Components:
→ LDAP Server
19/44
→ Kerberos ( enhancing ldap )
→ DNS
→ Certificate system
→ NTP
** If the IPA complains about enter ad ip address, cancel the installation, go to /etc/hosts
and create a new entry like with your IP, like 192.168.1.58 ipa.example.com
First add the free ipa dns in the client ( sysconfig network scripts )
Central server in the auth proccess that is going to determine how the auth is going to
happen
20/44
/etc/sssd/sssd.conf -> config file
22/44
Module 3 - Securing Linux Services
Module 3 - Securing Linux Services
Solutions
- DNSSEC
- TSIG
- Restrict Access
- Run bind in chroot
- Securing DNS
Generic Parameters
23/44
-> allow-query
-> allow-transfer
-> recursion
-> listen-on
Eg:
acl ¨internal¨ { 192.168.4.0/24 ; } ;
allow-query{internal ; } ;
TSIG -> Securs the communication between master and slave, works with a shared key
that must be installed on each machine, also we need NTP.
zone ¨myzone.example.com¨ {
type master ;
file ¨/var/named/master/myzone.example.com.signed¨;
allow-update { nome ; } ;
};
After that, restart the named and contact the registrar to make sure that the keys are
avaiable to the registrars as well.
- Securing apache
Security Challenges:
MAC is important to apache, make sure selinux or apparmor rules are used for apache
Security Options:
Order statements
<Directory /web>
order allow, deny
allow from example.com
24/44
</Directory>
Authentication:
- Securing Email
Threats:
Important parameters:
postmap /etc/postfix/access -> activate the access ( convert access table to access.db )
** By default, postfix uses unencrypted traffic on port 25
tls_key_file
25/44
tls_cert_file
tls_tls_CAfile
tls_loglevel
smtpd_use_tls -> enable tls
- Securing SSH
Protocol
Ciphers
Macs
26/44
- Securing VSFTPD
Problems
→ Weak auth
→ Easily hijacked
→ Plain text passwords ( Use sftp to be more secure )
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enabled=YES
anon_mkdir_write_enable=YES
xferlog_enable=YES
chown_uploads=YES -> Use file like a dropbox where a user that dropped the file cant
access it anymore
idle_session_timeout
data_connection_timeout
chroot_local_user=YES
NFS -> Create a share on one server and access on the another server. With the same
credentials on those servers.
Security problems
-> Host Based
-> Uid Mapping
-> Random firewall ports
->portmapper-> randomly assign ports when nfs starting
-> services running as root
-> Complex
Portmapper
rpc.mountd
rpc.statd
lockd
Nfsv4
Without the no_root_squash, if the mount the share with the root user, we cant do
anything, because the root user will be mapped to the nfs user nobody ( without rights ).
- Nfsv4 Acls
Example of an acl:
nfsv4_setfacl A::[email protected]:rxtncy -> alice has the equivalent read and execute
permissions ( rxtncy ) and A for allow.
29/44
30/44
Specific Samba options for lpic 303 (smb.conf ):
unix extensions(G)
This boolean parameter controls whether Samba implments the CIFS
UNIX extensions, as defined by HP. These extensions enable
Samba to better serve UNIX CIFS clients by supporting features
such as symbolic links, hard links, etc... These extensions
require a similarly enabled client, and are of no current use to
Windows clients.
31/44
/etc/raddb/ -> Conf directory, radius db.
clientsf.conf -> security related settings, for every client we need to specify a config here.
/proc/sys/net/ipv6/conf/all
Set forwarding to 0
accept_ra 0 ( accept Router advertisements set to 0 )
32/44
Port 1194.
on /etc/sysctl.conf:
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
33/44
Module 4 - Securing Linux Infrastructure
Module 4 - Securing Linux Infrastructure
- Introducing nmap
nmap ip
nmap -sS ip -> stealth scan
nmap -sV ip-> scan version
nmap -sn 192.168.1.0/24 -> scan network
nmap -v -A 192.168.1.0/24 -> verbose all scan
nmap -PN ipp -> scan to go through firewall ( Try to pass )
nmap -O ip -> OS scan
- Understanding Nessus
Vulnerability Scanner
Versions:
Cloud Version
Manager
Professional
Use Agents in the target that we are scanning ( Better, but we didnt use it )
- Using tripwire
- Introducing SNORT
Paid
Alternative: SURICATA
snort*
daq*
- Introducing Nagios
Monitoring System
Web-based
Plugin capable.
htpasswd -c /etc/nagios/passwd nagiosadmin -> Create a passwd for nagios
After that, go to the ip of the server in browser
- Using NTOP
35/44
Defaul port: 3000
Web browser interface.
- Introducing Puppet
Characteristics:
36/44
Ordering does matter
Policy -> Default action of a chain ( Behavior )
Syntax:
37/44
- Working with firewalld
38/44
ufw deny proto tcp from 192.168.4.10 to any port 22 -> Deny this host to access port 22
ufw app list -> Show app list
ufw allow Apache -> Allow apache
ufw logging on -> enable logging
Algorithms:
→ DES
→ 3DES
→ Blowfish
→ AES
Example
openssl enc -des3 -salt -a -in /etc/passwd -out secret.des3 -> Create an encrypted file with
DES3
openssl enc -d -des3 -salt -a -in secret.des3 -out unsecret -> Decrypt the file
Hash -> Is used to convert an input string with no fixed lenght to an ouput string of fixed
lenght
39/44
Common Hash Algorithms
→ CRC-32
→ MD5
→ SHA1
→ md5-sum
→ openssl dgst
Example:
Another example:
/etc/passwd
$6$/IIx6a0wmZRABy$JXYCEkb4YE7oGqPwisPu/
jzafAFLSK8wwUJVVf6Si1zXSfZGdZc6nuVpp5MbNU14ALfPB5RPk4YnjIFyjLE9p0
$6$ = Algorithm
IIx6a0wmZRABy$JXYCEkb4YE7oGqPwisPu = Salt
jzafAFLSK8wwUJVVf6Si1zXSfZGdZc6nuVpp5MbNU14ALfPB5RPk4YnjIFyjLE9p0 =
Password
Assymmetric Encryption -> Public and private keys ( Private used to encrypt and public to
decrypt )
Used in:
-> Digital signatures
-> Key distribution
-> Digital certificates
In cryptography, X.509 is a standard defining the format of public key certificates. X.509
certificatesare used in many Internet protocols, including TLS/SSL, which is the basis for
HTTPS, the secure protocol for browsing the web. They are also used in offline applications,
like electronic signatures.
X509 is used to create PKI ceritficates. In PKI public and private keys are used for 3
different purposes:
→ Proof of identity
→ Encryption
→ Prove that the data is not tampered
The CA is a well known party that is used to sign the public key, resulting in a PKI certificate
CSR( Certificate sign in request ) -> Issued to a CA.
40/44
Extensions:
41/44
→ A public key infrastructure (PKI) is a set of roles, policies, and procedures needed to
create, manage, distribute, use, store, and revoke digital certificates and manage public-
key encryption. The purpose of a PKI is to facilitate the secure electronic transfer of
information for a range of network activities such as e-commerce, internet banking and
confidential email. It is required for activities where simple passwords are an inadequate
authentication method and more rigorous proof is required to confirm the identity of the
parties involved in the communication and to validate the information being transferred. [1]
→ In cryptography, a PKI is an arrangement that binds public keys with respective identities
of entities (like people and organizations). The binding is established through a process of
registration and issuance of certificates at and by a certificate authority (CA). Depending on
the assurance level of the binding, this may be carried out by an automated process or
under human supervision.
The trusted root signs a top level CA that signs another and so on.
openssl genrsa -aes128 2048 > /etc/pki/tls/private/mykey.key -> generate an rsa key
openssl req -utf8 -new -key /etc/pki/tls/private/mykey.key -x509 -days 365 -out /etc/pki/tls/
certs/mykey.crt -set_serial 0 -> Create a pki certificate ( Self Sign )
42/44
can sign and copy our certificate )
- Issuing a CSR
openssl s_client -connect ipa.example.com:636 -showcerts -> Tries to connect and show
certificates on this host
43/44
44/44