Security Administration - Paiet/Tech-Journal-for-Everything GitHub Wiki
- Audit system for files with
suid/sgid
bit set- Set user ID bit allows a program to run as the owner of the file instead of the current user
- passwd is an example as it is allowed to write to
/etc/passwd
whereas a user cannot- User:
find / -perm +4000
find / -perm -u+s
- Group:
find / -perm +2000
find / -perm -g+s
- Both:
find / -perm +6000
- User:
- Use
nmap
andnetstat
to discover open ports- View listening ports
netstat -tp
netstat -atp
- Actively scan with nmap
yum install nmap
- Basic scan
nmap <host>
- Reserved port scan
nmap -v <host>
- Stealth SYN and OS Detection
nmap -sS -O 192.168.0.1/24
- View listening ports
- Setup limits on user logins, processes and memory usage
- View limits
-
ulimit -a
Can temporarily set limits
-
- To persistently set limits
/etc/security/limits.conf
- View limits
- Sudo configuration and usage
- sudo
- Executes command as root
- Password cached for five minutes by default
- User must be authorized to run sudo
- In some distros (like Ubuntu) simply add 'sudo' group as a secondary group
- In others (like RedHat) you must create your own group and add it to
/etc/sudoers
visudo <user/group> <machine>=<commands>
dpezet ALL=(ALL)
%techsupport localhost=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
- sudo
- Turn off network services not in use
- Extended Internet Daemon (xinetd)
/etc/xinetd.conf
(If present)yum install xinetd /etc/xinietd.d/*
- Extended Internet Daemon (xinetd)
- TCP wrappers
- Network access control system to filter connections Applies to anything that depends on libwrap (like xinetd)
ldd /usr/sbin/sshd | grep wrap
/etc/hosts.allow
- `/etc/hosts.deny
sshd : 192.168.0.1
- OR
sshd : 192.168.0.0/255.255.255.0
-
ALL : ALL
Deny is checked first, then allow overrides it
- Network access control system to filter connections Applies to anything that depends on libwrap (like xinetd)
- Sudo configuration and usage
- sudo
- Executes command as root
- Password cached for five minutes by default
- User must be authorized to run sudo
- In some distros (like Ubuntu) simply add 'sudo' group as a secondary group
- In others (like RedHat) you must create your own group and add it to
/etc/sudoers
visudo <user/group> <machine>=<commands>
dpezet ALL=(ALL)
%techsupport localhost=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
- sudo
- Turn off network services not in use
- Extended Internet Daemon (xinetd)
/etc/xinetd.conf
(If present)yum install xinetd /etc/xinietd.d/*
- Extended Internet Daemon (xinetd)
- TCP wrappers
- Network access control system to filter connections Applies to anything that depends on libwrap (like xinetd)
ldd /usr/sbin/sshd | grep wrap
/etc/hosts.allow
- `/etc/hosts.deny
sshd : 192.168.0.1
- OR
sshd : 192.168.0.0/255.255.255.0
-
ALL : ALL
Deny is checked first, then allow overrides it
- Network access control system to filter connections Applies to anything that depends on libwrap (like xinetd)
- GPG Installation (Sender and Recipient)
- GNU Privacy Guard is open source product similar to PGP (Pretty Good Privacy)
- Usually pre-installed
yum install gpg
- GPG configuration (Recipient)
- Create private key
gpg --gen-key
- Creates keyring files
- Starts a setup wizard
- Run it from console if possible
- In another TTY run high activity command to generate entropy
md5sum /dev/sda
ls -laR /
dd if=/dev/sda of=/dev/zero
- To see available entropy
cat /proc/sys/kernel/random/entropy_avail
- Generally around 2000
- VMs could be lower
- Entropy normally comes from
/dev/hwrandom
which is hardware - A TPM is the best source of entropy
- VMs can substitute a psuedo-random number generator
- OPTIONAL: Changing your Random Number Generator (RNG)
yum install rng-tools
vi /etc/sysconfig/rngd
- Insert:
EXTRAOPTIONS="-r /dev/urandom"
service rngd start
chkconfig rngd on
- Exchange keys with sender
gpg --export --output <directory> <filename>
- Send public key file to sender
- Create private key
- GPG Encryption (Sender)
- Import the recipients public key
gpg --import <directory_containing_key>
gpg --list-key
- Encrypt the file
gpg --encrypt -r <dest_user> <filename>
- Creates
<filename>.gpg
- Send
*.gpg
file to the recipient
- Import the recipients public key
- GPG Decryption (Recipient)
- Decrypt the file
gpg <filename>
- Enter private key's passkey
- Output is unencrypted
<filename>
- OpenSSH client configuration and usage
ssh <username>@<hostname>
ssh -l <username> <hostname>
- Configuration file is
/etc/ssh/ssh_config
- Options
-
-1
v1 Only -
-2
v2 Only -
-4
IPv4 Only -
-6
IPv6 Only -
-b <address>
Specify the source address -
-F <file>
Overrides system wide configuration -
who
command will show a psuedo tunnel (pts#) - Must accept public key on first connection
-
- OpenSSH server host keys
- Cached in
~/.ssh/known_hosts
for individual users - Cached in
/etc/ssh/ssh_known_hosts
for the entire system - If you receive a key before hand you can pre-load it
ssh-keyscan <host>
ssh-keyscan 192.168.0.100 >> ~/.ssh/known_hosts
- Can require key to pre-exist in
/etc/ssh/ssh_config
using the StrictHostKeyChecking option - Server keys are stored in
/etc/ssh
- Cached in
- Generating new keys
- Delete the 6 key files (
rm -f /etc/ssh/*key*
) ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
- Delete the 6 key files (
Example
| File | Description |
|-----------------------|-----------------------|
|ssh_host_key |SSHv1 Private Key |
|ssh_host_key.pub |SSHv1 Public Key |
|ssh_host_rsa_key |SSHv2 RSA Private Key |
|ssh_host_rsa_key.pub |SSHv2 RSA Public Key |
|ssh_host_dsa_key |SSHv2 DSA Private Key |
|ssh_host_dsa_key.pub |SSHv2 DSA Public Key |
- SSH port tunnels
- Send any port's traffic over an SSH tunnel
- Useful for encrypting any traffic regardless of protocol
- Telnet example setup
yum install telnet-server
vi /etc/xinetd.d/telnet disable=no
service xinetd start
chkconfig telnet on
chkconfig xinetd on
-
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dpport 23 -j ACCEPT
service iptables restart
- Telnet example lab
- Establish the SSH tunnel
ssh -f <username>@<hostname> -L <localport>:<hostname>:<remoteport> -N
- The -N means do not execute any commands on the remote system
ssh -f [email protected] -L 65023:172.16.116.129:23 -N
- Telnet through the tunnel
telnet 127.0.0.1 65023
- Establish the SSH tunnel