Sitemap
Sebastien Simon

Sebastien Simon

Linux/Windows Kernel Backdoor

3 min readJul 30, 2024

--

In this lab, we’ll walk through the process of creating a Linux kernel backdoor and interacting with it using Kali Linux and an ARM Ubuntu Server. This guide is designed to help you understand the mechanics of kernel modules and their potential security implications.

Prerequisites

  • A x86 computer with Kali Linux (GUI)
  • ARM Ubuntu Server (non-GUI)
  • SSH access between Kali Linux and ARM Ubuntu Server

Step 1: Setup Kali Linux

1.1 Install Necessary Tools

First, ensure your Kali Linux system has the required tools installed:

udo apt-get update
sudo apt-get install build-essential linux-headers-$(uname -r)

1.2 Create the Kernel Module

Create a directory for your kernel module and navigate into it:

mkdir ~/kernel_backdoor
cd ~/kernel_backdoor

Create the kernel module source file backdoor.c:

// backdoor.c
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>

#define PROCFS_NAME "backdoor"

ssize_t procfile_read(struct file *file, char *buffer, size_t length, loff_t *offset)
{
static int finished = 0;
if (finished) {
finished = 0;
return 0;
}
finished = 1;
if (copy_to_user(buffer, "Hello from the kernel!\n", 25)) {
return -EFAULT;
}
return 25;
}

static struct proc_ops proc_file_fops = {
.proc_read = procfile_read,
};

static int __init backdoor_init(void)
{
proc_create(PROCFS_NAME, 0644, NULL, &proc_file_fops);
return 0;
}

static void __exit backdoor_exit(void)
{
remove_proc_entry(PROCFS_NAME, NULL);
}

MODULE_LICENSE("GPL");
module_init(backdoor_init);
module_exit(backdoor_exit);

Create a Makefile for building the kernel module:

Makefile
# Makefile
obj-m += backdoor.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

1.3 Compile the Kernel Module

Clean and compile the kernel module:

make clean
make

Step 2: Transfer the Kernel Module to ARM Ubuntu Server

2.1 Transfer the backdoor.ko File

scp ~/kernel_backdoor/backdoor.ko tuser@<arm_ubuntu_server_ip>:/home/tuser/

Replace <arm_ubuntu_server_ip> with the IP address of your ARM Ubuntu Server.

Step 3: Setup ARM Ubuntu Server

3.1 Install Necessary Headers

SSH into your ARM Ubuntu Server:

ssh tuser@<arm_ubuntu_server_ip>

Install the necessary headers:

sudo apt-get update
sudo apt-get install linux-headers-$(uname -r)

3.2 Load the Kernel Module

Navigate to the directory where you transferred the kernel module:

cd /home/tuser/

Load the kernel module:

sudo insmod backdoor.ko

3.3 Verify the Module is Loaded

Check if the module is loaded and if the proc file is created:

ls /proc/backdoor

If the proc file exists, read its content:

cat /proc/backdoor

Step 4: Interact with the Backdoor from Kali Linux

Create a script on Kali Linux to interact with the proc file on the ARM Ubuntu Server:

Get Sebastien Simon’s stories in your inbox

Join Medium for free to get updates from this writer.

interact_backdoor.sh:

#!/bin/bash
# Define variables
REMOTE_USER=tuser
REMOTE_HOST=<arm_ubuntu_server_ip>
REMOTE_PROC_FILE=/proc/backdoor
# Read the content of the proc file
ssh ${REMOTE_USER}@${REMOTE_HOST} "cat ${REMOTE_PROC_FILE}

Replace <arm_ubuntu_server_ip> with the actual IP address of your ARM Ubuntu Server.

Make the script executable:

chmod +x interact_backdoor.sh

Run the script to interact with the backdoor:

./interact_backdoor.sh

Summary

  • Setup Kali Linux: Installed necessary tools, created, and compiled the kernel module.
  • Transfer the Kernel Module: Moved the backdoor.ko file to the ARM Ubuntu Server.
  • Setup ARM Ubuntu Server: Installed headers, loaded the kernel module, and verified its functionality.
  • Interact with the Backdoor: Created and used a script on Kali Linux to interact with the proc file on the ARM Ubuntu Server.

By following these steps, you should be able to create, deploy, and interact with a kernel backdoor on an ARM Ubuntu Server from a Kali Linux machine, gaining valuable insights into kernel module manipulation and security.

--

--