<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>durdle.com &#187; Scripting</title>
	<atom:link href="http://durdle.com/archives/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://durdle.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Apr 2012 21:13:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>FindTheHole.vbs</title>
		<link>http://durdle.com/archives/2008/08/11/findtheholevbs/</link>
		<comments>http://durdle.com/archives/2008/08/11/findtheholevbs/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 09:59:39 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[effective permissions]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[vbscript]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/?p=388</guid>
		<description><![CDATA[Recently I needed to write a script that could locate a folder on a system that had particular characteristics.  I was looking for hidden folders that the logged on user had rights to read, write/append and execute on.  ie, they can drop a binary into the folder and then run it. This is the script...]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to write a script that could locate a folder on a system that had particular characteristics.  I was looking for hidden folders that the logged on user had rights to read, write/append and execute on.  ie, they can drop a binary into the folder and then run it.</p>
<p>This is the script I came up with.  It uses a WMI query and method to first locate all the hidden folders on the system, and then compare each ones effective permissions to a mask I created:</p>
<div class="wp_syntax">
<div class="code">
<pre class="vbnet" style="font-family:monospace;">strComputer <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;.&quot;</span>
<span style="color: #FF8000;">Set</span> objWMIService <span style="color: #008000;">=</span> GetObject<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;winmgmts:&quot;</span> _
<span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;{impersonationLevel=impersonate}!&quot;</span> <span style="color: #008000;">&amp;</span> strComputer <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;rootcimv2&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Set</span> colFiles <span style="color: #008000;">=</span> objWMIService.<span style="color: #0000FF;">ExecQuery</span> _
<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Select * from Win32_Directory Where Hidden = True&quot;</span><span style="color: #000000;">&#41;</span>
wscript.<span style="color: #0000FF;">echo</span> <span style="color: #808080;">&quot;Hidden folders which you can write to...&quot;</span>
intW <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #008080; font-style: italic;">' initialise Writable folder count</span>
<span style="color: #008080; font-style: italic;">' Iterate through each hidden folder on the computer</span>
<span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> objFile in colFiles
	<span style="color: #008080; font-style: italic;">' Ignore some well known hidden folders</span>
	<span style="color: #0600FF;">If</span> <span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;documents and settings&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;$nt&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;$hf_mig$&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;ie7updates&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;visual studio&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;dllcache&quot;</span><span style="color: #000000;">&#41;</span> or _
		<span style="color: #0600FF;">InStr</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">lcase</span><span style="color: #000000;">&#40;</span>objFile.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, <span style="color: #808080;">&quot;$patchcache$&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
	<span style="color: #FF8000;">Else</span>
		<span style="color: #008080; font-style: italic;">' Can we read (1), write (2, 4), and execute (32) in this folder?</span>
		intPermissions <span style="color: #008000;">=</span> <span style="color: #FF0000;">39</span>
		<span style="color: #008080; font-style: italic;">' Use WMI method to compare permissions</span>
		<span style="color: #0600FF;">If</span> objFile.<span style="color: #0000FF;">GetEffectivePermission</span><span style="color: #000000;">&#40;</span>intPermissions<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
			wscript.<span style="color: #0000FF;">echo</span> objFile.<span style="color: #0000FF;">Name</span>
			intW <span style="color: #008000;">=</span> intW <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>
		<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #FF8000;">Next</span>
wscript.<span style="color: #0000FF;">echo</span> intW <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot; vulnerable folders.&quot;</span></pre>
</div>
</div>
<p>This was important as part of a wider effort to prove a particular vulnerability existed.  Imagine the scenario where a standard user is prevented from running unknown binaries except for one hidden folder somewhere on the system which is excluded from this protection.  If one could quickly find that folder, the user could run whatever he liked.</p>
<p>I&#8217;m aware that there are plenty of command line tools that would have helped in this endeavour (such as AccessChk) but remember: this is a system where unauthorised apps can not be run.  It&#8217;s VBScript or nothing.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2008/08/11/findtheholevbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LDAP Query based on account SID in VBscript</title>
		<link>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/</link>
		<comments>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 12:36:16 +0000</pubDate>
		<dc:creator>Howard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[vbscript security ldap sid wmi]]></category>

		<guid isPermaLink="false">http://blog.durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/</guid>
		<description><![CDATA[This is a bit of code I wish I&#8217;d found sooner. There is a &#8211; it seems mostly undocumented &#8211; feature of the ldap provider in Server 2003 that allows you to form an ldap query just on the SID of an account: bindSid = &#34;LDAP://&#38;lt;sid =&#34; &#38;amp; SID &#38;amp; &#34;&#38;gt;&#34; set oVal = GetObject(bindSid)...]]></description>
			<content:encoded><![CDATA[<p>This is a bit of code I wish I&#8217;d found sooner.  There is a &#8211; it seems mostly undocumented &#8211; feature of the ldap provider in Server 2003 that allows you to form an ldap query just on the SID of an account:<br />
</p>
<div class="wp_syntax">
<div class="code">
<pre class="vbscript" style="font-family:monospace;">bindSid = &quot;LDAP://&amp;lt;sid =&quot; &amp;amp; SID &amp;amp; &quot;&amp;gt;&quot;
set oVal = GetObject(bindSid)
Result = oVal.Get(&quot;cn&quot;)
set oVal = Nothing</pre>
</div>
</div>
<p>So if you have a list of SIDs and want to translate them into meaningful account names, this will do it without relying on using WMI &#8211; which on a lot of secure networks is locked down (or at least should be!).</p>
<p>Why do I need this?  It&#8217;s a part of a larger script I&#8217;m writing that will archive specific Group Policy Objects from the <strong>\SYSVOL\&lt;domainname&gt;\Policies\</strong> folder of a PDCe.  One of the files in a GPO is the <strong>GptTmpl.inf</strong> file which gives a list of the <a title="User Rights Assignments" href="http://technet2.microsoft.com/windowsserver/en/library/71b2772f-e3c0-4134-b7f0-54c244ee9aef1033.mspx?mfr=true" target="_blank">User Rights Assignments</a> (SeBackupPrivilege, SeShutdownPrivileg etc) along with the SIDs of the accounts that have been given those privileges (e.g. S-1-5-19).  I wrote a script that reads the SIDs and queries the DC for the account names.  This code fragment works more reliably (and I think faster) than the WMI calls I was previously using.</p>
]]></content:encoded>
			<wfw:commentRss>http://durdle.com/archives/2008/01/09/ldap-query-based-on-account-sid-in-vbscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

