{"id":791,"date":"2012-07-12T18:40:13","date_gmt":"2012-07-12T17:40:13","guid":{"rendered":"http:\/\/www.phillips321.co.uk\/?p=791"},"modified":"2012-08-30T12:46:08","modified_gmt":"2012-08-30T11:46:08","slug":"nftf-local-lockdown-getting-prompts-fun-with-macros-and-scripting-help-on-airgapped-systems","status":"publish","type":"post","link":"https:\/\/www.phillips321.co.uk\/2012\/07\/12\/nftf-local-lockdown-getting-prompts-fun-with-macros-and-scripting-help-on-airgapped-systems\/","title":{"rendered":"Getting prompts, Fun with Macros and Scripting Help on Airgapped Systems"},"content":{"rendered":"<p><strong>1. NFTF Quickie &#8211; VBS Funtimes &#8211; Run Scripts? Get Prompt<\/strong><br \/>\nThis is probably a duplicate somewhere but wanted it noted for my own use anyway &#8211; here&#8217;s a very handy VBS that does the job nicely for accessing useful commands as a user on a locked down desktop.<br \/>\n<b>Using VBS to fire up FTP as a local command shell<\/b><\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/><\/div><\/td><td><div class=\"text codecolorer\">Run ftp...<br \/>\nCreateObject(&quot;WScript.Shell&quot;).Run &quot;cmd.exe \/k ftp&quot;<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Using the above and the bang character will let you run commands on the host.<br \/>\nE.G. !cd or !c:\\windows\\system32\\calc.exe (strangely on XP64 !cd will not persist post command, however it does do so on Win7 [pretty sure it does it on 32bit XP as well as it&#8217;s how I used to use FTP all the time])<br \/>\nNoddy stuff indeed but useful.<br \/>\nThe above one-liner can be modified to run any executable you have access to as a user.<\/p>\n<p><strong>2. No Macros Allowed? That&#8217;s what you think&#8230;<\/strong><br \/>\nMe and a colleague got presented with a &#8220;Defect fixed, macros are completely disabled on the host&#8221; statement on Monday, so we decided to give it a bit of a kicking.<br \/>\nAt first glance, no access to the editor was possible and only trusted signed macros were capable of running. We could be forgiven at this point for even mistakenly &#8220;passing&#8221; the defect if we hadn&#8217;t been so determined.<br \/>\nSo after a bit of poking and managing to pop open the editor across the office suite, I was convinced I could get it to play ball all the way. My colleague thankfully indulged my inane ramblings about &#8220;digitally signing&#8221; and &#8220;feeling like it&#8217;s so close&#8221;.<br \/>\n3 to 4 hours later and a fair few dead ends. We get macro editing and execution as a trusted signed macro across all the office apps available on the host (aside from outlook, that could probably fall too given more poking but we had proved the point).<br \/>\nWhat follows is a quick run through of what we did (&#8230;using only a standard user account on a locked down host).<\/p>\n<p><strong>2.1. First Problem &#8211; Creating the macro, we need an editor<\/strong><br \/>\n<img loading=\"lazy\" alt=\"Macro_bar\" height=\"138\" src=\"http:\/\/getfile4.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/5plGhT6OW7BTMwmxuUnlOl0FjwzUFvzuquBptBbslmEsAlRVZmeTpAMWtQuS\/macro_bar.png\" width=\"421\" \/><br \/>\nIf the macro menu is disabled and the buttons on the developer toolbar are greyed out (the buttons above are just to show where they are) try the following:<br \/>\n<strong>In Word:<\/strong> Right click the toolbar, select &#8220;customise quick access toolbar&#8221;, select &#8220;all commands&#8221; and add the button labelled &#8220;view code&#8221;.<br \/>\nAt this point now go to the developer toolbar (enable it within word options if not enabled), select &#8220;design mode&#8221; and now the &#8220;view code&#8221; button will become clickable.<br \/>\nClick this button &#8211; Voila, access to VB Editor.<br \/>\n<strong>In Excel:<\/strong> Right click the sheet tab, View Code &#8211; Voila, access to VB Editor. Alternatively it is also accessible the same way as in word.<br \/>\n<strong>In Powerpoint:<\/strong> Click &#8220;view code&#8221; (should already be on the toolbar somewhere, if not follow the instructions for word)<br \/>\nThe above all work in 2007 and 2010, as well as earlier versions but probably in a slightly different guise. Have a bit of a poke about a bit.<\/p>\n<p><strong>2.2. Just sign here, here and here<\/strong><br \/>\nOur second issue, accessing the &#8220;security&#8221; window and then the &#8220;macro security&#8221; window using the above &#8220;toolbar button&#8221; method (anything with the word &#8220;macro&#8221; in was disabled from a UI point of view in the ribbon\/menus so you had to load the &#8220;security&#8221; window to get there) we could see that only signed macros were allowed to run. <\/p>\n<p \/> Nightmare, what can we do now? Thankfully during the above macro editor poking I had browsed through the office folder (looking for a VB Editor.exe type thing) and noted the following executable.<br \/>\n<b>Run this:<\/b> <i>C:\\Program Files (x86)\\Microsoft Office\\Office12\\selfcert.exe<\/i><br \/>\n<img loading=\"lazy\" alt=\"Selfcert\" height=\"336\" src=\"http:\/\/getfile9.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/D0rnUZP82Nig8rtbDQQlIpdoYfbhyfvSVYlscmHCIfcvFCBWW2Ezm4IvPp9j\/selfcert.png\" width=\"420\" \/><br \/>\nRun it &#8211; Create a certificate. Access the VB Editor using the steps in the previous tip.<br \/>\n<img loading=\"lazy\" alt=\"Signing_word\" height=\"195\" src=\"http:\/\/getfile4.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/KvHxJf0dUjkytlsagrhQsZB6GdQmitvRzgPAm92Erq1WMFNEGWUkRAAZz3wi\/signing_word.png\" width=\"493\" \/><br \/>\nTools -&gt; Digital Signatures -&gt; Choose Certificate -&gt; Select your cert.<br \/>\nNow it&#8217;s signed you will probably need to exit word\/excel\/whatever and reopen the document (we had to when testing).<\/p>\n<p><strong>2.3. &#8230;but wait, mommy told me not to run macros from strangers.<\/strong><br \/>\nOkay so we&#8217;ve now got a macro, it&#8217;s signed but it still won&#8217;t run. They&#8217;ve hobbled the security even further and &#8220;disabled&#8221; any prompts we&#8217;d get allowing us to &#8220;run&#8221; a macro with a self-signed cert, so we&#8217;re going to have to find a way to explicitly trust our self-signed macro.<br \/>\n<img loading=\"lazy\" alt=\"Signing_big\" height=\"341\" src=\"http:\/\/getfile2.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/34CT3Q0BinpP1A7DKjcavVWVmiT5b1UBxfGhFFviwICt2d66hd2uqCUrDe1P\/signing_big.png.scaled.1000.jpg\" width=\"1000\" \/><br \/>\nOpen the VB Editor as before. Then Tools -&gt; Digital Signatures -&gt; Choose -&gt; View Certificate &#8211; &gt; Details -&gt; Copy to File<br \/>\n<img loading=\"lazy\" alt=\"Cert_import\" height=\"386\" src=\"http:\/\/getfile6.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/LWo5DRwrhy06OK24mGt9i4ZdYgD1jnhUKTYqUyMS3Ipnk7fym2DoqGkq2WOe\/cert_import.png\" width=\"503\" \/><br \/>\nNavigate to saved .cer file (just accept the defaults in the export wizard), right click and select &#8220;install certificate&#8221;, Select the location to install the certificate as &#8220;Trusted Publishers&#8221;.<br \/>\nNext&#8230;<br \/>\nCertificate Installed Successfully. You just added your certificate to the trusted signatures that microsoft office will blindly accept without needing you to click on a &#8220;accept the risk&#8221; style warning.<br \/>\n<b>Before <\/b><i>(but this would typically be hidden and not shown to users, meaning that they would not have the option of &#8220;accepting anyway&#8221; in this manner and so self-signed macros would never run)<\/i>:<br \/>\n<img loading=\"lazy\" alt=\"Untrusted\" height=\"336\" src=\"http:\/\/getfile2.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/HoIQyH8jOwQBCGwOSCIv6erfodiIqpOUqGLIT6DnnFHHJFTANeeDvcm32Irc\/untrusted.png\" width=\"484\" \/><br \/>\n<b>After<\/b> <i>(No prompt, macro can be run, certificate is trusted)<\/i>:<br \/>\n<img loading=\"lazy\" alt=\"Trusted_nowarning\" height=\"290\" src=\"http:\/\/getfile7.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/zy7rUJFcdQj93P4qTqsAfODFplWi0nchUQFUh8woRxUE66T9x31zVZy5ITvG\/trusted_nowarning.png\" width=\"221\" \/><img loading=\"lazy\" alt=\"Trust_center\" height=\"275\" src=\"http:\/\/getfile0.posterous.com\/getfile\/files.posterous.com\/scriptmonkey\/UcQzTY1fJdYM6KV3ngWEwSuMXH3VQOUqlIVNLK3EcGEcVKrDsrIhwQXq6JR7\/trust_center.png\" width=\"465\" \/><\/p>\n<p>You may need to restart word or whatever at this point just to get the changes to refresh but your macro will run without hindrance once done.<\/p>\n<p><strong>2.4 So what can I do with these things anyway?<\/strong><br \/>\nSo the mini-nftf in section 1 above, without cscript.exe\/wscript.exe you&#8217;re a bit screwed.<br \/>\nHow about doing it in VBA.<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"text codecolorer\">Sub run_me<br \/>\n&nbsp; &nbsp; retVal = Shell(&quot;C:\\WINDOWS\\SYSTEM32\\cmd.exe \/k ftp&quot;,1)<br \/>\nEnd Sub<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>A quick &#8216;F5&#8217; and you&#8217;re back running the commands you need.<br \/>\nretVal in the above will contain the PID of the process you just launched so the following will kill the process too (in case you were doing something fancy)<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/><\/div><\/td><td><div class=\"text codecolorer\">Sub run_me_kill_me<br \/>\n&nbsp; &nbsp; Dim retVal as String<br \/>\n&nbsp; &nbsp; retVal &nbsp;= Shell(&quot;C:\\WINDOWS\\SYSTEM32\\calc.exe&quot;,1)<br \/>\n&nbsp; &nbsp; killCmd = &quot;C:\\WINDOWS\\SYSTEM32\\cmd.exe \/k taskkill \/PID &quot; &amp;#043; retVal<br \/>\n&nbsp; &nbsp; retVal2 = Shell(killCmd,1)<br \/>\nEnd Sub<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>The &#8220;,1&#8221; part of the Shell call, that&#8217;s describing what you want VB to do with the window. If you are doing calls to a script (perhaps a macro that performs a bunch of commands on the sly?) or a command\/console based program, you can use vbHide instead and no window will appear on the screen.<br \/>\nBe careful doing this on systems with CMD.exe disabled by group policy as you&#8217;ll find that they never show up and so persist within task manager waiting on an invisible but very real &#8220;This command has been disabled by your administrator, press any key to continue&#8221; prompt.<\/p>\n<p><strong>3. Help! No Web, No Hope? No Way!<\/strong><br \/>\nFinal tidbit of an NFTF &#8211; Ever wanted to write some VBS but never sure of exact syntax or even the functions you have access to, no access to the web and someone has helpfully disabled the &#8220;help and support&#8221; service, denying you any &#8216;F1&#8217; action you may want.<br \/>\nThis is a little trick I picked up from previous work. Providing the host you&#8217;re playing with has Microsoft office installed (else it&#8217;s worth just a general C:\\ drive search for clview.exe).<br \/>\nYou have all the scripting reference material you need to make whatever VBS you want.<br \/>\nFirst you make a new shortcut upon the desktop.<br \/>\nSet it to : &#8220;C:\\Program Files (x86)\\Microsoft Office\\Office12\\clview.exe&#8221; &#8220;MSE&#8221; &#8220;Microsoft Scripting Engine&#8221;<br \/>\nDouble click and a blank help screen will open (this does not require the help and support service yay!).<br \/>\nSearch for something &#8220;VBS&#8221; for example and then click &#8220;microsoft scripting engine&#8221; (grey text, top left) and then &#8220;Microsoft Scripting Engine Help&#8221;, you&#8217;ll have help for VBScript and JScript language references along with information on all the juicy runtime objects you can access using VBS\/JScript.<br \/>\nNote: JScript is essentially the same as VBScript (different syntax, but same capabilities), they&#8217;re all run using cscript.exe (if a console based script) or wscript.exe (if a dialog based script).<br \/>\nNeed VBA help? Once again, CLVIEW comes to the rescue.<br \/>\nCreate a shortcut for: &#8220;C:\\Program Files (x86)\\Microsoft Office\\Office12\\CLVIEW.EXE&#8221; &#8220;WINWORD&#8221; &#8220;Microsoft Office Word&#8221;<br \/>\nLooks like it&#8217;s word help but it is the word developer reference and in turn will give you the full VBA language reference too.<br \/>\nDoing fancier application specific stuff in Excel? or Powerpoint? Change the above to suit. <\/p>\n<p \/> Happy Local Lockdown Testing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. NFTF Quickie &#8211; VBS Funtimes &#8211; Run Scripts? Get Prompt This is probably a duplicate somewhere but wanted it noted for my own use anyway &#8211; here&#8217;s a very handy VBS that does the job nicely for accessing useful commands as a user on a locked down desktop. Using VBS to fire up FTP [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":862,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[310,308,112,306,309,311,101,307],"_links":{"self":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/791"}],"collection":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/comments?post=791"}],"version-history":[{"count":7,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/791\/revisions"}],"predecessor-version":[{"id":863,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/791\/revisions\/863"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media\/862"}],"wp:attachment":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media?parent=791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/categories?post=791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/tags?post=791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}