Linux Security: Structure, Permissions and Access
Linux Security: Structure, Permissions and Access
Linux Security: Structure, Permissions and Access
com/in/muhammed-dardir
Windows started as a desktop OS, but is now a respected Old: Single-user platform
server platform New; Multiple processes for multiple users at the same
time
Old: Installed on servers with many simultaneous users
UNIX took the opposite route
New: Used as a desktop OS
Ubuntu (Debian) Ubuntu is a Linux distribution
Main Linux Distributions
Fedora (Red Hat) The Fedora project is based on Red Hat Linux
type of linux operating system Main Linux Distributions Cygwin for Windows
macOS (BSD)
NOTE: Kali is based on Debian Linux
Open-source operating system with many variants
Originally developed for personal computers, but has been
ported to other platforms
Many security tools are freely available and often only run
on Linux
Linux
Linux and Windows: Desktops and Servers
Runs the Linux kernel as the "brains" of the operating
system
Kernel: The core component of the operating system that The memory-resident part of an operating system that
is often referred to as the "brains" of the operating system directly interfaces with the hardware is called the kernel
Shell: The portion of the operating system with which users
and the process interact directly
operating system overview Hardware: A collection of physical components such as
the actual CPU and memory chips
Linux shells
Symbolic
File Attributes
The idea was that any program which had the sticky bit set
was supposed to "stick around11 in the memory of the
operating system after the program had finished executing
Permissions
SUID/SGID Programs Keep track of the SUID /SGID programs provided with your
operating system
Raise an alarm if new or unexpected SUID /SGID
programs appear
Umask sets default newly created file permissions umask u-x,g=r,o-w
Umask and chmod Umask reads existing umask setting chmod u=rwx,g=rx,o=r filename
Chmod changes existing file permissions chmod 754:filename
Chown changes file ownership chown user1 /home/user1
Chgrp changes group ownership chgrp support /home/user1
permissions : Chown and Chgrp Both user and group ownership can be changed at the
same time withchown
Chown will use both user and group IDs or their names
Usernames and passwords are case sensitive
User and group names are for the convenience of humans
User Account and Groups
Linux systems store ownership information with user IDs
and group IDs
Normal users
Superusers control all files, processes, and devices
Superuser A two-class security model:
Superuser is usually called root
Superusers Superuser accounts always have a UID of 0
Multiple UID 0 accounts can exist besides the root account
UID 0 account creation or access is any attacker's goal
You should never log in as root or UID 0
Anonymous login is very dangerous
Logging in as UID O provides no accountability if there are
PrivEsc
multiple accounts
Always log in as a normal user
Utilize su or sudo to escalate privileges
Linux operating systems tend to come with many service
accounts for various apps
Typically, these accounts have low UID numbers (UID <
100?, 500?, 1,000?)
UNIX systems Accounts Attackers sometimes activate these accounts as
"backdoors" into the system
If you're not using a particular service or app, remove (or
block) the account
Passwd File
init is the first process to start init was the original boottime service starter
It is responsible for the setup of the entire user
environment
Also known as System-VStyle init
The init process starts as a process PID 1
it checks and mounts filesystems and starts necessary
services
Init is the parent process to all other processes and adopts
all orphaned processes in the user space
Tracks services only during sudden changes to the system
Unable to detect and handle sudden changes to the
Classic init system
Run level 0 means shut down the systems
Runlevel 1 means single-user mode
All init-based solutions use runlevels, which tell services Runlevel 2 means multiuser mode
how a process will start as the init process starts Run level 3 means multiuser mode with networking
Runlevel 5 means starting the system with appropriate
display manager and graphics.
Runlevel 6 means system reboot
Port control and port restriction SSH key management is generally ad hoc
Private keys for your SSH are generally stored on your
local computer with minimal, if any, security to protect them
Solutions exist to centrally manage SSH keys
SSH/TLS Key Management Manages user roles
Manages keys
KeyBox web-based SSH manager
Manages simultaneous SSH sessions across multiple
systems
Puppet also can manage SSH keys
Logs the switch of the user to the other user
su (switch user) is often used to elevate to root No other control; the user has all root privileges
All users know the root user's password
Users only know their own password
sudo gives granular control of execution Allowed to execute only the commands specified in
Sudo and Sudoers sudoers file
effective user ID
effective group ID
environment list
Security policy that can be set with sudo working directory
umask
SELinux role
scheduling priority
The sysctl utility audits and can dynamically change
settings within a Linux system while the system is running
Sysctl is used to modify kernel settings at runtime
Running sysctl -a shows you all the variables for the system
1Pv4 and 1Pv6 settings
Hardening and Securing Linux Services
Execshield
Sysctl configures network and system settings Network attack preventions
Logging attacks
Address Space Layout Randomization
Recommended way to edit the variables is to edit the / etc/
sysctl.conf file
To see all the variables for the system, run sysctl -a. To
write to a variable using the sysctl command, enter sysctl -
w variable=value. The -w option tells sysctl to write
the value to the variable
Allows a packets' sender to partially or completely specify
the route the packet takes through the network
The danger is it allows for two-way spoofed communication
It is possible for a Linux system to be part of a source
SysctI Hardening : Source routing
routing path
SysctI Hardening Set the net.ipv4.conf.default.accept_source_route to 0
sysctl ·a I grep source_route
net.ipv6.conf.all.accept_ra=0
Disable router advertisement
net.ipv6.conf.default.accept_ra=0
SELinux Policy
When using categories, the level is written as
Each level is a sensitivity-category pair, with categories sensitivity:category-set.
MLS/MCS being optional: When not using categories, the level is written as
sensitivity.
Syslog facility codes A facility code is used to specify the type of program that is
logging the message
The most common facility codes used are kern, user,
daemon, auth, syslog, and auth priv
Sender authentication
Message confidentiality
Message delivery and replays
Syslog doesuot, by default, encrypt the traffic, so syslog
traffic is inherently not confidential, and all traffic is sent in
cleartext
Enhancing the Overall Security Always identify the overall risk that is going to be reduced
Determine if the solution is the most cost-effective way of
reducing the risk
WARNING- WARNING - WARNING
Often, security professionals criticize a tool because it is
either old or does not solve all security problems
understanding of security Instead of trying to find fault, ask yourself whether the utility
helps or hurts your overall security
The ultimate question to always ask is based on the cost
that is required to implement the solution, whether the
reduction in risk is worth the overall effort
Security is about visibility, baselining, and automation; all
three are very powerful components of Linux
It is important to understand what is running on a system
and what is happening on the system
There is no such thing as an invisible adversary
Many people always look for third-party tools when Linux
has a vast area of built-in capabilities
ls
Shows network connectionson a system
Network connections
Routing tables
Used to printout
Intetface statistics
Connections
netstat
Command-line tool to understand what's happening from a
Using built-in commands and security features network perspective
-a Show all ports
-l Show all listening ports
help -at Show all TCP ports
-au Show all UDP ports
-s Show the statistics for each protocol
Shows active processes thafare running onthesystem
Basic but essential process .. management tool
Shows running-processes
Displays process information to include CPU usage,
ps memory usage,. command name
ps -ef Show all running processes
help ps -C apache2 Shows process by name
Four powerful built-in commands
ps --sort=pcpu Sort by CPU utilization
ps -ef lgrep syslog
Provides a dynamic, real-time view of a running Linux
system
401.6_linuxEssentials
While top is running, press z to allow for color coding of
top different processes
While top is running, press c to allow for the full path of the
file to be displayed
some tricks with top.
While top is running, press Shift-p to sort by CPU utilization
Start top using the -u option followed by a username to see
all process details associated with that user
Displays the1ast10 lines of a file by default and is . useful
for log files
tail tail -f-s 5 /var/log/messages
tail -c 500 /var/log/messages
the power of I and grep
Two versions : Open source and commercial version
Focused on file integrity checking
Writes alertsto logs
Tripwire
Intrusion detection through integrity checking
Creates a "secure" database of file and directory attributes
Can include SHA signatures for verification
Open source
File integrity checking plus other features
Can be centralized managed and controlled
Checks ports and executable files
A-host-based intrusion detection system-(HIDS)
Contains various features to both prevent and, detect host-
Samhain
based attacks
When it comes to file integrity checking on Linux, you have Can monitor multiple operating systems
Configuring integrity checkers many options Open~source multiplatform application
Features
Detection of rogue executables
Features Rootkit detection
Port monitoring
Log file analysis and correlation
Open source
Runs on several different operating systems
Breadth offeatures and capabilities
Integrates host-based intrusion detection
Comprehensive protection
OSSEe File integrity checking
Log monitoring
Rootcheck
Process monitoring
Send emailalerts and alert logs
Integrates with SIEM
Firewalls are critical to manage and filter traffic
Network firewalls provide a boundary defense
Host-based firewalls are needed to complement network
firewalls
With Linux, the same software can provide both network
and host-based firewalls
Using the same software allows for better control,
manageability, and scalability across the enterprise
In Windows, there are host-based and network-based
firewallsoften made by different vendors with minimal
relationships
Built-infirewall (host or network) for Linux ·Powerful and customizable
Many free scripts and GUis available for simplifying
The Linux kernel includes IP Tables
configuration . and maintenance
Firewalls Stateful firewall with NAT capability
Flush any existing rules iptables -F
iptables -P INPUT DROP
Set our default policy to drop all packets iptables -P OUTPUT DROP
firewall features
Linux package management Features Key features of Linux package management tools Standard locations for installations: Use standards to
install files in common locations to enable reuse of code
Deploying package management strategies such as libraries
User experience components: Add features to make it
easier and enhance the user experience
Verification of installation: Verify the install was done
correctly and make sure it is a stable install
Debian package management is based on the tool dpkg
Thecommon package management solution is "APT"
Packages often have the extension .deb
Often cqmpatible with Ubuntu (be careful with declared
dependencies)