Notes / Module 8
Linux Overview
Linux is the operating system most SOC work runs on: open source, driven from the command line and built for networks. This module covers the shell, servers and ports, logs, file permissions, links, processes and rootkits.
8.1Linux basics and the SOC
Linux is an open-source operating system created in 1991 and maintained by a community of programmers. It is fast, reliable and small, needs very little hardware, and is designed to be connected to the network. Anyone can inspect, modify, re-compile and redistribute the kernel source.
A distribution (distro) is the Linux kernel packaged with customised tools and software from one organisation. Examples are Debian, Red Hat, Ubuntu, CentOS and SUSE. Most are free without support; some charge for business support.
- Open source: free, and can be modified into a tailor-built analysis OS.
- Powerful CLI: tasks run at a terminal or remotely.
- More user control: the root user can change any aspect of the OS.
- Network control: many network tools exist for Linux only.
The root user is the administrator (superuser) account with absolute power over the computer. It can modify any aspect of the system with a few keystrokes, which is valuable for low-level work such as the network stack. Root is the only user who can override file permissions, so its credentials need a strong password and must not be shared beyond high-level admins.
Security Onion is an open-source suite of network security analysis tools, packaged as a special Linux version. Its analyst console is Sguil. A SOC uses several kinds of tool:
| Tool type | What it does |
|---|---|
| Packet capture | Observe every detail of a network transaction (Wireshark) |
| Malware analysis | Run malware safely without harming the host |
| IDS | Real-time traffic monitoring against rules |
| Firewall | Allow or block traffic by pre-defined rules |
| Log manager | Makes very large log volumes monitorable |
| SIEM | Real-time analysis of alerts and log entries from appliances such as IDSs and firewalls |
| Ticketing | Assigns and records alerts for analysts |
Penetration testing (PenTesting) is looking for vulnerabilities in a network or computer by attacking it. Tools include packet generators, port scanners and proof-of-concept exploits. Kali Linux is a distribution that groups many penetration-testing tools into one distro.
8.2Working in the shell
A terminal emulator is a GUI application that gives access to the Linux CLI, which is often hidden because Linux boots to the GUI. Examples are Terminator, eterm, xterm, konsole and gnome-terminal. Shell, console, CLI terminal and terminal window are used interchangeably.
Commands are programs stored on disk. The shell looks for a typed command in the directories listed in the path. A command outside the path needs its location specified, or the shell cannot find it. Users can add directories to the path.
| Command | What it does |
|---|---|
man | Shows the documentation (manual) for a command, e.g. man ls |
pwd | Displays the current directory |
cat | Lists the contents of a file (usually text) |
ls | Lists files in a directory |
cd | Changes directory |
mkdir | Creates a directory |
cp | Copies source to destination |
mv | Moves or renames files and directories |
rm | Removes files |
chmod | Modifies file permissions |
chown | Changes the ownership of a file |
su | Simulates a login as another user, or becomes the superuser |
sudo | Runs one command as superuser ("superuser do"), or as another named user |
passwd | Changes the password; with no parameters, the current user's |
ifconfig | Shows or sets network card settings; deprecated, use ip address |
iwconfig | Same as ifconfig for wireless cards |
grep | Searches for text strings in a file or in another command's output |
dd | Copies data from an input to an output |
shutdown | Halts or restarts the system; can also sleep it or log users out |
ps | Lists running processes |
top | Lists running processes live |
kill | Modifies the behaviour of a process (end, restart, pause) |
apt-get | Installs, configures and removes packages on Debian and derivatives |
chkrootkit | Checks for known rootkits |
To search the output of a previous command, grep must be piped onto the end of it. With no parameters, ifconfig and iwconfig only display the current configuration.
Command-line text editors let you edit files on a remote computer over an SSH text shell, where there is no graphical interface. nano is keyboard-only: CTRL+O saves, CTRL+W searches and CTRL+G opens help.
In Linux everything is treated as a file: memory, disks, the monitor and directories. Showing output on the display means writing to the display's file. The computer itself is configured through text configuration files. One example is /etc/hosts, which holds static mappings of host IP addresses to names; only the superuser can change it, e.g. sudo nano /etc/hosts.
8.3Servers, clients and ports
A server runs software that provides services over the network, such as files, email, web pages, log and memory management, or disk scanning. Each service needs separate server software. A client is the hardware/software combination people use directly; client programs use a well-defined protocol to talk to a specific type of server (a web browser talks HTTP to a web server).
A port is a reserved network resource used by a service. Ports let one computer be the server for many services. A server is listening on a port when it has associated itself with that port. Default ports are the well-known ports, and it is common practice to leave a service on its default.
| Port | Service |
|---|---|
| 20/21 | FTP, File Transfer Protocol |
| 22 | SSH, Secure Shell |
| 23 | Telnet remote login |
| 25 | SMTP, Simple Mail Transfer Protocol |
| 53 | DNS, Domain Name System |
| 67/68 | DHCP |
| 69 | TFTP, Trivial File Transfer Protocol |
| 80 | HTTP |
| 110 | POP3 |
| 123 | NTP, Network Time Protocol |
| 143 | IMAP |
| 161/162 | SNMP |
| 443 | HTTPS |
Port scanners such as Nmap find the open ports on a host.
8.4Basic server administration
A service configuration file is a text file a service loads at start-up to set its port, resource location and client authorisation. Changes usually need a service restart and often need superuser rights to edit. There is no fixed format, though option = value is common, and # marks a comment.
Device hardening means implementing proven methods to secure a device and protect its administrative access: maintain passwords, enhance remote login, use SSH, define administrative roles (not all IT staff need the same access), stop legacy services starting at boot, and apply OS updates and patches.
- Ensure physical security.
- Minimise installed packages.
- Disable unused services.
- Use SSH and disable root login over SSH (SSH instead of Telnet).
- Keep the system updated.
- Disable USB auto-detection.
- Enforce strong passwords, periodic changes and no re-use.
Log files give a clear picture of performance, security status and issues, so problems are caught early. Categories are application, event, service and system logs. A daemon is a background process that needs no user interaction. Most Linux logs live in /var/log.
| Log file | Holds |
|---|---|
/var/log/auth.log | Authentication events on Debian and Ubuntu |
/var/log/secure | Authentication events on Red Hat and CentOS; also sudo and SSH logins |
/var/log/messages | Generic informational, non-critical system messages; Debian-based systems use syslog instead |
boot.log | Messages during start-up |
dmesg | Kernel ring buffer: hardware and driver events before syslog runs |
kern.log | Information logged by the kernel |
cron | Status and errors of scheduled tasks (cron jobs) |
mysqld.log / mysql.log | MySQL debug, failure and success messages |
8.5.1File system types and mounting
| File system | Notes |
|---|---|
| ext2 | No journal, so fewer writes; still favoured for flash media |
| ext3 | Adds journaling to ext2; maximum file size 32 TB |
| ext4 | Extends ext3 for performance and larger files; split from ext3 over stability concerns; can run journal-less |
| NFS | Network file system, an open standard; remote files look local |
| CDFS | For optical discs |
| Swap | Used when RAM runs out: the kernel moves inactive RAM content to disk, which is far slower than RAM |
| HFS+ | Apple; Linux can mount it read-write |
| APFS | Apple; strong encryption, optimised for flash and SSDs |
A journal is a log of pending changes used to restore the file system after a crash or power loss. It is the main feature added in ext3 and minimises the risk of file system corruption. The MBR sits in the first sector, stores how the file system is organised and hands over to the OS loader.
Mounting assigns a directory (the mounting point) to a partition so its file system is accessible, similar to a Windows drive letter. mount with no options lists the mounted file systems. The root file system is /; in the module's example it is ext4 on /dev/sda1.
8.5.2Roles and file permissions
Every file carries permissions defining what the owner (user), the group and others may do. The rights are read (r), write (w) and execute (x). They are always displayed in User, Group, Other order. ls -l shows them with extra detail.
[analyst@secOps ~]$ ls -l space.txt -rwxrw-r-- 1 analyst staff 253 May 20 12:49 space.txt
- First character:
-is a file,dis a directory. rwx(user, analyst): read, write and execute.rw-(group, staff): read and write.r--(other): read only.
| Binary | Symbolic | Octal | Meaning |
|---|---|---|---|
| 000 | --- | 0 | No access |
| 001 | --x | 1 | Execute only |
| 010 | -w- | 2 | Write only |
| 011 | -wx | 3 | Write and execute |
| 100 | r-- | 4 | Read only |
| 101 | r-x | 5 | Read and execute |
| 110 | rw- | 6 | Read and write |
| 111 | rwx | 7 | Read, write and execute |
digit = 4·r + 2·w + 1·x
- r
- 1 if read is set, else 0
- w
- 1 if write is set, else 0
- x
- 1 if execute is set, else 0
Do this once per class (user, group, other) to get a three-digit mode.
Try it
owner
4 + 2 + 1 = 7
group
4 + 0 + 1 = 5
other
0 + 0 + 0 = 0
Worked example
rwxr-x--- to octal
- 1Split into three classes:
rwx,r-x,---. - 2
rwx= 4 + 2 + 1 = 7. - 3
r-x= 4 + 0 + 1 = 5. - 4
---= 0. - 5The mode is 750.
Worked example
Which permissions does 754 mean (as in chmod 754 file)?
- 1Read each digit as binary: 7 = 111, 5 = 101, 4 = 100.
- 2111 =
rwxfor the user. - 3101 =
r-xfor the group. - 4100 =
r--for others. - 5754 is rwxr-xr--.
Permissions cannot be broken: a user has only the rights the permissions allow. The only user who can override them is root, who can write to any file, so root access should be carefully controlled.
8.5.3Hard links and symbolic links
A hard link is another file name that points to the same location (the inode) as the original. Create one with ln (existing file first, new file second); the link count in ls -l then shows 2. Changing either name changes the data, and deleting one name leaves the other intact.
ln space.txt space.hard.txt rm space.hard.txt more space.txt # still works
A symbolic link (symlink, soft link) points to a path. Create one with ln -s. Changes through it also change the original, but if the original is deleted the symlink is left pointing at nothing.
ln -s test.txt mytest.txt rm test.txt more mytest.txt ls -l mytest.txt lrwxrwxrwx 1 analyst analyst 8 May 7 20:17 mytest.txt -> test.txt
| Hard link | Symbolic link | |
|---|---|---|
| Created with | ln | ln -s |
| Points to | The same file data (inode) | The file's path |
| Original deleted | Link still works | Link breaks (single point of failure) |
| Crosses file systems | No | Yes |
| Can link a directory | No (the system uses hard links for the directory hierarchy) | Yes |
Easy to find in ls -l | No | Yes, shows name -> target |
8.6The Linux GUI
The X Window System (X or X11) is the windowing framework behind most Linux GUIs. It draws windows and handles the mouse and keyboard. It works as a server: the application can run remotely while its window displays locally. X does not define the look of the interface; window managers do, defining buttons, fonts, icons, borders and colours. Gnome and KDE are examples, and they are why the Linux GUI varies so much between distributions.
Ubuntu's default GUI is Gnome 3, with the Apps Menu, Ubuntu Dock, Top Bar, Activities and Status Menu.
- Ubuntu Dock
- App launcher and switcher on the left
- Activities
- Search apps and files, switch workspaces
- Status Menu
- Network, user settings, lock and shutdown
8.7Working on a Linux host
A package is a program plus its supporting files; a package manager installs it into the right places. pacman serves Arch Linux; dpkg and apt serve Debian and Ubuntu.
| Task | Debian / Ubuntu | Arch |
|---|---|---|
| Refresh the package list | apt-get update | pacman -Syy |
| Update installed packages | apt-get upgrade | pacman -Syu |
| Install | apt install | pacman -S |
| Remove | apt remove | pacman -Rs |
Keep the OS updated because patches fix known vulnerabilities, and unscheduled updates follow major discoveries.
A process is a running instance of a program. Forking is how the kernel lets a process create a copy of itself, and it is the only way to create new processes in Linux. The caller becomes the parent and the new process its child; they have different PIDs but run the same code. Apache forks to serve many requests with fewer resources.
pslists processes once, when invoked. Listing needs no root, but killing or modifying other users' processes does.topkeeps displaying processes dynamically; pressqto exit.killmodifies a process (remove, restart, pause). Runpsortopfirst to find the PID.
Linux is not immune to malware. It is better protected by design, through file system structure, permissions and user restrictions, and open source means patches often appear within hours. Still, server and kernel vulnerabilities get exploited. The common attack vector is a vulnerable service or process, such as an outdated Apache web server: attackers probe open ports for the server version and type, then research known issues for that version. Reduce the opportunity by keeping the computer updated and closing unused services and ports.
A rootkit is malware that raises an unauthorised user's privileges or grants access to protected parts of the system, often to secure a backdoor. It changes kernel code and modules, hides the intrusion and tampers with diagnostic tools so their output hides it. Most need root or admin access to install.
- Detect by booting trusted media (such as a live CD), mounting the compromised drive and inspecting it with trusted tools.
- Inspection methods: behavioural, signature scanning, difference scanning and memory dump analysis.
- Removal usually means reinstalling the OS; firmware rootkits usually need hardware replacement.
chkrootkit is a shell script that checks for known rootkits by comparing signatures of core programs, using common tools such as strings and grep. It also compares /proc contents with the output of ps. It is not 100% reliable.
Piping chains commands with | so one command's output becomes the next one's input.
ls -l | grep host
Check yourself
Answer these out loud, without scrolling up. Any you can't, reread that section — then let the deck mark you.
- 1.Give the four reasons Linux is popular in the SOC, and say what Security Onion and Kali Linux are each built for.
- 2.Convert rwxr-x--- to octal, then say what chmod 754 sets.
- 3.Compare hard links and symbolic links on four points: what happens when the original is deleted, crossing file systems, linking directories, and visibility in ls -l.
- 4.Which log holds authentication events on Debian/Ubuntu and which on Red Hat/CentOS? Name the ports for SSH, Telnet, DNS, HTTPS and SMTP.
- 5.What does apt-get update do compared with apt-get upgrade, and what do ps, top and kill each do?
- 6.What is a rootkit, how is one detected, and what does chkrootkit compare?