what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

megas.c

megas.c
Posted Oct 7, 1999
Authored by Pmsac

Module to retrieve privilege to processes.

systems | linux
SHA-256 | 3c1a53d2029af8aaf19ab04983497d4575d25c39406d48c1321172829309cb20

megas.c

Change Mirror Download
/*
* megas.c, by pmsac@toxyn.org, 1998
*
* Just another ripp off from:
* - cocain.c, by pmsac@toxyn.org, 1998, which is a rip off:
* - heroin.c, by Runar Jensen, zarq@opaque.org, 1998(?), from BugTraq
* - itf.c v0.8, by plaguez, dube0866@eurobretagne.fr, 1997, from Phrack52
*
* gcc -Wall -O3 -fomit-frame-pointer -c megas.c
*
*/

#define MODULE
#define __KERNEL__
#define VERSION_COUNT sn199807290335

#include <linux/proc_fs.h>
#include <linux/module.h>
#include <linux/limits.h>
#include <sys/syscall.h>

/* Examine, Allow */
#define EXAMINE 0
#define ALLOW 1
char *TASKSTR[][2] = {
{ "pine", NULL },
{ "pine", "joe" },
{ "bash", "ls" },
{ "bash", "rmmod" },
{ NULL, NULL }
};

#define PID 0
#define SIGDEBUG 31
#define SIGSANE 10
#define SIGCOUNT 0

extern void *sys_call_table[];

int errno;
int VERSION_COUNT = 0;
int debug = 0;
int __NR_myexecve;
#define TMPBINMAXLEN (PATH_MAX + 1)


int (*oldKill)(pid_t, int);
int (*oldExecve)(const char *, const char *[], const char *[]);
void cleanup_module(void);

#define DEBUG(X); if (debug) printk(X);
#define DEBUG2(X,Y); if (debug) printk(X,Y);
#define DEBUG3(X,Y,Z); if (debug) printk(X,Y,Z);



int newKill(pid_t pid, int sig) {
int ret;

DEBUG("newKill()\n");

if ((pid != PID) ||
((sig != SIGCOUNT) &&
(sig != SIGDEBUG) &&
(sig != SIGSANE))) {
DEBUG("-> oldKill()...\n");
ret = (*oldKill)(pid, sig);
if (ret == -1)
return (-errno);
return(ret);
}
if (sig == SIGCOUNT) {
DEBUG("-> Toggling usage count...\n");
VERSION_COUNT ^= 1;
if (VERSION_COUNT)
MOD_INC_USE_COUNT;
else
MOD_DEC_USE_COUNT;
}
if (sig == SIGSANE) {
DEBUG("-> Sanitizing module, pls remove by hand...\n");
while (VERSION_COUNT != 0) {
MOD_DEC_USE_COUNT;
VERSION_COUNT--;
}
cleanup_module();
}
if (sig == SIGDEBUG) {
DEBUG("-> Toggling debugging...\n");
debug ^= 1;
}

DEBUG("-> Returning...\n");
return(0);
}

int cryptic_execve(const char *filename, const char *argv[], const char *envp[])
{
long __res;
__asm__ volatile ("int $0x80":"=a" (__res):"0"(__NR_myexecve), "b"((long) (filename)), "c"((long) (argv)), "d"((long) (envp)));
return (int) __res;
}

int newExecve(const char *bin, const char *argv[], const char *envp[]) {
int ret;
int allow = 0;
int spotted = 0;
char *tmpBinName;


DEBUG("newExecve()\n");

DEBUG("-> Allocating kernel space...\n");
tmpBinName = (char *) kmalloc(TMPBINMAXLEN, GFP_KERNEL);
DEBUG("-> Copying to kernel space...\n");
memcpy_fromfs(tmpBinName, bin, TMPBINMAXLEN);
DEBUG2("-> bin == %s\n", tmpBinName);

DEBUG("-> Examining list...\n");
for (ret = 0; TASKSTR[ret][EXAMINE] != NULL; ret++) {
if (TASKSTR[ret][ALLOW] == NULL) {
DEBUG("-> Deny all (further ?)...\n");
break;
}
if (strstr(current->comm, TASKSTR[ret][EXAMINE]) != NULL) {
DEBUG3("-> Spotted... %s/%s\n", TASKSTR[ret][EXAMINE], TASKSTR[ret][ALLOW]);
spotted = 1;
if (strstr(tmpBinName, TASKSTR[ret][ALLOW]) != NULL) {
DEBUG("-> List allowed...\n");
allow = 1;
break;
}
}
}

DEBUG("-> Deallocating kernel space...\n");

if ((TASKSTR[ret][EXAMINE] == NULL) && !spotted) {
DEBUG("-> Unlisted, allowing...\n");
allow = 1;
}

if (allow) {
DEBUG("-> Allowed, oldExecve()...\n");
ret = (*cryptic_execve)(bin, argv, envp);
return (ret);
}

DEBUG("-> Not allowed, -EPERM...\n");
return(-EPERM);
}

int init_module(void) {

DEBUG("init_module()\n");

DEBUG("-> Replacing kill()...\n");
oldKill = sys_call_table[SYS_kill];
sys_call_table[SYS_kill] = newKill;

DEBUG("-> Replacing execve()...\n");
__NR_myexecve = 164;
while (__NR_myexecve != 0 && sys_call_table[__NR_myexecve] != 0)
__NR_myexecve--;
oldExecve = sys_call_table[SYS_execve];
if (__NR_myexecve != 0) {
sys_call_table[__NR_myexecve] = oldExecve;
sys_call_table[SYS_execve] = newExecve;
}

DEBUG("-> Returning...\n");
return 0;
}

void cleanup_module(void) {

DEBUG("cleanup_module()\n");

DEBUG("-> Restoring kill()...\n");
sys_call_table[SYS_kill] = oldKill;

DEBUG("-> Restoring execve()...\n");
sys_call_table[SYS_execve] = oldExecve;
DEBUG("-> Restoring __NR_myexecve");
if (__NR_myexecve != 0)
sys_call_table[__NR_myexecve] = 0;
DEBUG("-> Returning\n");
}
Login or Register to add favorites

File Archive:

May 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close