A Basic Kernel Interaction Challenge
The Module
#define PASSWORD "p4ssw0rd"
#define FLAG "flag{YES!}"
#define FAIL "FAIL: Not Authenticated!"
static int authenticated = 0;
static ssize_t auth_read(struct file *filp, char __user *buf, size_t len, loff_t *off) {
printk(KERN_ALERT "[Auth] Attempting to read flag...");
if (authenticated) {
copy_to_user(buf, FLAG, sizeof(FLAG)); // ignoring `len` here
return 1;
}
copy_to_user(buf, FAIL, sizeof(FAIL));
return 0;
}
static ssize_t auth_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) {
char password_attempt[20];
printk(KERN_ALERT "[Auth] Reading password from user...");
copy_from_user(password_attempt, buf, count);
if (!strcmp(password_attempt, PASSWORD)) {
printk(KERN_ALERT "[Auth] Password correct!");
authenticated = 1;
return 1;
}
printk(KERN_ALERT "[Auth] Password incorrect!");
return 0;
}Interacting
Final Code
Challenge - IOCTL
Last updated
Was this helpful?