Link to this headingKernel
Link to this headingSystemcalls
Link to this headingCreating a custom syscall
https://medium.com/@aryan20/create-custom-system-call-on-linux-6-8-126edef6caaf
Link to this headingDrivers
Implementing Drivers in other Languages
Link to this headingKernel Modules
https://github.com/sysprog21/lkmpg
https://sysprog21.github.io/lkmpg/
https://xcellerator.github.io/posts/linux_rootkits_11/
Basic Kernel Module:
;
;
;
;
static struct kprobe kp = ;
static unsigned long * __sys_call_table;
/* Despite what's written in include/linux/syscalls.h,
* we have to declare the original syscall as taking
* a single pt_regs struct as an argument. This enables
* us to unpack this struct in our hook syscall and access
* the arguments that are being passed, while still being
* able to just pass this struct on again to the real syscall
* without any issues. This way, we don't have to unpack
* EVERY argument from the struct - only the ones we care about.
*
* Note that asmlinkage is used to prevent GCC from being
* "helpful" by allocation arguments on the stack */
typedef asmlinkage int ;
orig_open_t orig_open;
/* This is our function hook.
*
* Getting this to work is a little awkward. We have to un-pack
* the arguments from the pt_regs struct in order to be able to
* reference the new directory name without getting a null-pointer
* dereference.
*
* The pt_regs struct contains all the arguments passed to the syscall
* in each register. Looking up sys_mkdir, pathname is stored in rdi, so
* simply dereferencing regs->di gives the pathname argument.
* See arch/x86/include/asm/ptrace.h for more info.
*
* Note that we call the real sys_mkdir() function at the end */
asmlinkage int
/* The built in linux write_cr0() function stops us from modifying
* the WP bit, so we write our own instead */
inline void
/* Bit 16 in the cr0 register is the W(rite) P(rotection) bit which
* determines whether read-only pages can be written to. We are modifying
* the syscall table, so we need to unset it first */
static inline void
static inline void
static inline unsigned long
/* Module initialization function */
static int __init
static void __exit
;
;
Generate Kernel Module:
VERS=
VERS=5.15.24-1-lts
Get Kernel Mod Info:
Run Kernel Module:
#Run Module
#Check that is is running
|
#Remove
Link to this headingIORing
https://chomp.ie/Blog+Posts/Put+an+io_uring+on+it+-+Exploiting+the+Linux+Kernel
https://ruia-ruia.github.io/2022/08/05/CVE-2022-29582-io-uring/