Skip to the content.

đź”— Link to the Room

🏷️ Table of Contents

  1. Lab Connection
  2. Linux Incident Surface - An Overview
    2.1 Linux Attack Surface
    2.2 Linux Incident Surface
  3. Processes and Network Communication
    3.1 Investigating Processes
    3.2 Process with Network Connection
    3.3 Investigating Network Communication
    3.4 Where Processes Fit in the Linux Incident Surface
  4. Persistence
    4.1 Persistence: Taking Foothold
    4.2 Activity 1: Account Creation
    4.3 Identifying the Footprints
    4.4 Activity 2: Cron Job
    4.5 Examining Malicious Cronjobs
    4.6 Activity 2 Services
    4.7 Examining the Running Service
  5. Footprints on Disk
    5.1 File System and Directories
    5.2 Investigating Malicious Package
    5.3 Investigate the Suspicious Installed Package
  6. Linux Logs
    6.1 Syslog
    6.2 Messages
    6.3 Authentication Logs

📚 Study Notes

The Linux Incident Surface focuses on all potential points or sources in the Linux system where an incident could occur or traces of incidents could be found. This could lead to a security breach, which could also be part of the Linux Attack Surface.

Linux Attack Surface refers to various entry points where an attack or unauthorized attempt could be made to enter the system or gain unauthorized attempts.

Lab Connection

 

image

Note: All the important files are placed in the /home/activities/processes directory.

 


❓Connect with the lab. How many files and folders are in the /home/activities/processes directory?3

✅Run ls -la /home/activities/processes —

 

Linux Incident Surface - An Overview

 

The Linux Incident Surface is all the places on a Linux system where traces of an attack can be found. It’s what security analysts check after a system has been compromised.

Concept What it is Goal
Attack Surface Points where an attacker could try to break in (open ports, vulnerable software, running services, network connections) Reduce the number of ways attackers can get in
Incident Surface Areas where signs of an attack can be detected and investigated (logs, running processes, network traffic, file integrity) Detect, respond to, and recover from an attack

Understanding the incident surface helps analysts quickly spot attacks, limit damage, restore systems, and prevent future incidents.

 

Linux Attack Surface

The Linux Attack Surface refers to all the points of interaction in a Linux system where an adversary might attempt to exploit vulnerabilities to gain unauthorized access or carry out malicious activities.

Some of the key entry points that could be identified as part of the Linux Attack Surface are: Open ports, running services, running software or applications with vulnerabilities, network communication

The primary goal is to minimize the attack surface by reducing potential weaknesses from the areas the attacker could exploit. Some of the steps that are involved in achieving this goal are:

 

Linux Incident Surface

It refers to all the system areas involved in the detection, management, and response to an actual security incident (post-compromise). It includes where security breaches may be detected and analyzed and where a response plan must be implemented to mitigate the incident.

Key points where we could find the incident traces:

 

Processes and Network Communication

 

 

Investigating Processes

Activity # 1: Create and Run a Simple Process

In the /home/activities/processes directory, there is a code called simple.c, which runs on the system when executed. Note: It is important to note that all the commands we are running will be through the root user. Run the command sudo su to change the user from default to root.

  1. Compiling the Code - run gcc simple.c -o /tmp/simple to compile and create an executable program image

  2. Detecting the Footprints - use ps aux to examine the running processes on the Linux. image

ps aux displays all processes for all users in a detailed format. Flags:

Filter out the output with simple process by running ps aux | grep simple image

The output provides the following information:

Examine the files/resources connected with this process by using lsof with PID. As PID use the one assigned to our process which is 49782. Hence the syntax is lsof -p 49782 image

 

Process with Network Connection

In many incident scenarios, processes communicating via network to an external IP or the server are worth investigating. Therefore, examining the processes of making network connections and hunting down suspicious ones is very important.

Hence we will execute a process called netcom placed in the home/activities/processes. To execute the process use ./netcom - this will establish a network connection to a remote IP.

 

Investigating Network Communication

Use ps aux | grep netcom to filter the results to see whether the process is running on the system. image

The output confirms that the process is indeed running and has been assigned PID 267490, which will be different in your case.

In another terminal run lsof -i -P -n to see if there is any network connection associated with this PID. image

Let’s break down the query and the flags first for better understanding:

To explore processes and its network connection use osquery. To start osquery, open a new terminal and run the osqueryi as a root image

Narrow down the resurt to display the network connection associated with this PID using SELECT pid, fd, socket, local_address, remote_address FROM process_open_sockets WHERE pid = 267490; image

 

Where Processes Fit in the Linux Incident Surface

Processes can be exploited, manipulated, or used by attackers to execute malicious activities. It is important to investigate the processes running on the system from various angles. The following points are a few use cases of the incidents related to processes:

 


❓What is the remote IP to which the process netcom establishes the connection?68.53.23.246

❓Update the osquery command. What is the remote port the netcom process is communicating to?443

 

Persistence

 

Persistence refers to techniques attackers use to maintain access to a compromised system even after the initial exploit.

To understand how incidents are detected on a Linux endpoint, we will:

  1. Perform the attack
  2. Examine how and where the attack leaves footprints

 

Persistence: Taking Foothold

Investigating persistence is crucial, as it’s often one of the first steps an intruder takes after post-exploitation.
Some of the attack actions that can result in persistence on a Linux machine are explained below:

 

Activity 1: Account Creation

In an assumed compromised scenario, let’s pretend to be Alice, who has got hold of the system. Start by creating a backdoor account using following commands to create an account attacker and will be added into the sudo group: sudo useradd attacker -G sudo sudo passwd attacker echo "attacker ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers

image

 

Identifying the Footprints

Let’s pretend to be Bob, a blue teamer trying to examine various incident surfaces to identify the footprints of the backdoor account that was created.

  1. Examining Logs: One of the key places we could begin looking at would be the logs. All common logs can be found at the /var/log/ location, as shown below:

image

  1. Examining auth.log
    • use cat auth.log | grep useradd command image
  2. Examining /etc/passwd File
    • use cat /etc/passwd image

In the output, we can see all the accounts, including the one we just created. Some of the information this file contains are:

 

Activity 2: Cron Job

Another persistence method is cron jobs, which attackers can use to maintain persistent access to a compromised system. Cron is a time-based job scheduler in Unix-like systems that allows tasks (scripts, commands, or programs) to be executed automatically at specified intervals.

To create a malicious cron job, we can modify the crontab file or use the crontab command to edit scheduled jobs for the current user or system using crontab -e which will open the crontab file, and we can add entry.

Examples of Crontab Entry:

image

 

Examining Malicious Cronjobs

Explore /var/spool/cron/crontabs/[username] to explore the cronjobs associated with each user, as shown below:

image

 

Activity 2 Services

Another way to achieve persistence on a compromised system is installing a service on the Linux server that will run in the background and start on every reboot. Let’s learn how to investigate this activity by first creating a service and installing it on the disk:

  1. Create a Configuration File: use sudo nano /etc/systemd/system/suspicious.service
    • Add the following content to the configuration file: image

This configuration file will create a service and will execute the mentioned process.

  1. Enable and Start Service
    • reload the systemd manager config: sudo systemctl daemon-reload
    • enable the service to run at startup: sudo systemctl enable suspicious.service
    • start the service right away: sudo systemctl start suspicious.service

image

Check status of the service with sudo systemctl status suspicious.service

image

 

Examining the Running Service

Now that we know how an adversary could install and run the service in the background, let’s see how we can find this service’s footprints on the system.

  1. Reviewing the Directory - all services installed and enabled on the Linux can be found in /etc/systemd/system image

  2. Evidence in the Logs - look at the /var/log/systlog; search for suspicious by running cat /var/log/syslog | grep suspicious image

  3. Examining Journalctl - by using sudo journalctl -u suspicious image

 


❓What is the default path that contains all the installed services in Linux?/etc/systemd/system

❓Which suspicious service was found to be running on the host?benign.service

❓What process does this service point to?benign

❓Before getting this service stopped on 11th Sept, how many log entries were observed in the journalctl against this service?7

 

Footprints on Disk

 

Attackers often leave traces on the filesystem during their activities. From a forensics and incident response perspective, these areas-called incident surfaces - are critical to examine.

Investigating disk footprints is key to understanding the scope and impact of a security incident.

 

File System and Directories

In the Linux filesystem, some files or directories contain sensitive information and can keep track of any attack attempt. Some of the key places are Configuration Files:

 

Investigating Malicious Package

Attackers can leverage Debian packages to compromise a Linux system. This can happen in two main ways:

  1. Attacker-created packages: Malicious packages installed intentionally to execute harmful actions.
  2. User-tricked packages: A user is deceived into installing a malicious package, unknowingly allowing compromise.

Practical Exercise:

1.** Create Directory**: run mkdir to create a directory for the package, e.g.: mkdir malicious-package

  1. Create Control File: It should contain info or metadata about the package we will build and install on this host. Open a file in any text editor within the DEBIAN folder and name it control. Add the content mentioned below to the file before saving it:

Package: malicious-package
Version: 1.0
Section: base
Priority: optional
Architecture: all
Maintainer: attacker@test.com
Description: This is a malicious Package

  1. Add Malicious Script: create a malicious script with the content below and save it as postinst and place it in the DEBIAN directory: #!/bin/bash # Malicious post-installation script # It will run this script after installation # Print a suspicious message - for demonstration echo "something suspicious"

  2. Make the Script Executable: change permission with chmod 775, syntax: chmod 755 malicious-package/DEBIAN/postinst

  3. Build the Package: run dpkg-deb --build malicious-package

  4. Install the Package: run dpkg -i malicious-package.deb

 

Investigate the Suspicious Installed Package

  1. Check the Installed Packages: run dpkg -l image
  1. Examining dpkg.log: run grep " install " /var/log/dpkg.log

 


❓Create a suspicious Debian package on the disk by following the steps mentioned in the task. How many log entries are observed in the dpkg.log file associated with this installation acitvity?6

❓What package was installed on the system on the 17th of September, 2024?c2comm

 

Linux Logs

 

Logs are records of events that happen on a system.
They help administrators and security analysts understand what happened on a machine, detect attacks, and investigate incidents.

Most Linux logs are stored in /var/log

 

Syslog

Useful for:

image

 

Messages

Useful for:

Example threat indicator: repeated kernel panic messages (possible denial-of-service attempt)

 

Authentication Logs

Useful for detecting:

Example indicator: many failed login attempts from the same IP address

image

Logs may reveal signs of an attack, such as:

Linux logs are critical for monitoring system health, detecting attacks, investigating incidents and understanding system activity

[!NOTE] When analyzing Linux logs, these three commands are essential for quickly filtering, viewing, and monitoring system activity:

  1. grep - search for Patterns in Logs. grep lets you search log files for specific keywords or patterns.
  2. journalctl - view systemd logs. journalctl is powerful for checking system and service activity.
  3. tail -f - monitor logs live. It lets you watch log files as they’re updated, perfect for live monitoring.

 


❓Examine the auth.log files. Which user attempted to connect with SSH on 11th Sept 2024?saqib

❓From which IP was this failed SSH connection attempt made?10.11.75.247

Â