<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Syncio Blog - Access Denied</title>
    <link>http://sync-io.net/go/blog/</link>
    <description>fixitchris@twitter</description>
    <language>en-us</language>
    <copyright>Chris Misztur</copyright>
    <lastBuildDate>Thu, 27 Mar 2008 21:00:07 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>chris@sync-io.net</managingEditor>
    <webMaster>chris@sync-io.net</webMaster>
    <item>
      <trackback:ping>http://sync-io.net/go/blog/Trackback.aspx?guid=d71d00da-05d7-4832-86fc-eeaf416cd7be</trackback:ping>
      <pingback:server>http://sync-io.net/go/blog/pingback.aspx</pingback:server>
      <pingback:target>http://sync-io.net/go/blog/PermaLink,guid,d71d00da-05d7-4832-86fc-eeaf416cd7be.aspx</pingback:target>
      <dc:creator>Chris</dc:creator>
      <wfw:comment>http://sync-io.net/go/blog/CommentView,guid,d71d00da-05d7-4832-86fc-eeaf416cd7be.aspx</wfw:comment>
      <wfw:commentRss>http://sync-io.net/go/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=d71d00da-05d7-4832-86fc-eeaf416cd7be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The following code has been tested on Windows 2003 SP2.  The calling user
account must have 'Assign Primary Token' and 'Increase Quota' permissions to
properly execute CreateProcessAsUser; see MS KB285879.  
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Function</span> RunProc(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ByVal</span> CMD <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">String</span>, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ByVal</span> ARG <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">String</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">String</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> er <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> Int16 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> exitCode <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> System.UInt32 <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Convert.ToUInt32(123) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> saThreadAttributes <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> SECURITY_ATTRIBUTES <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">New</span> SECURITY_ATTRIBUTES
saThreadAttributes.nLength <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Marshal.SizeOf(saThreadAttributes) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> impToken <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> System.IntPtr <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> IntPtr.Zero <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> priToken <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> System.IntPtr <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> IntPtr.Zero <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span> LogonUser(<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"DomainUser"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Domain"</span>, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Passwd"</span>,
LogonType.LOGON32_LOGON_INTERACTIVE, _ LogonProvider.LOGON32_PROVIDER_DEFAULT, impToken) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Then</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span> DuplicateTokenEx(impToken,
&amp;H2000000, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Nothing</span>,
SecurityImpersonationLevel.SecurityDelegation, TOKEN_TYPE.TokenPrimary, priToken) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Then</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> pi <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> PROCESS_INFORMATION <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">New</span> PROCESS_INFORMATION <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> si <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> STARTUPINFO <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">New</span> STARTUPINFO
si.cb <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Marshal.SizeOf(si)
si.lpDesktop <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> IntPtr.Zero <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Dim</span> saProcessAttributes <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">As</span> SECURITY_ATTRIBUTES <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">New</span> SECURITY_ATTRIBUTES
saProcessAttributes.nLength <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Marshal.SizeOf(saProcessAttributes) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Not</span> CreateProcessAsUser(priToken,
CMD, CMD &amp; <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"
"</span> &amp; ARG, saProcessAttributes, _ saThreadAttributes, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">False</span>,
0, IntPtr.Zero, <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"c:\"</span>,
si, pi) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Then</span> er <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Marshal.GetLastWin32Error
RunProc <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> (<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"err
runas "</span> &amp; er) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Else</span> WaitForSingleObject(pi.hProcess,
Infinite) GetExitCodeProcess(pi.hProcess, exitCode) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">End</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span> CloseHandle(priToken)
CloseHandle(impToken) CloseHandle(pi.hProcess) CloseHandle(pi.hThread) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">End</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">End</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">If</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">End</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">Function</span></span>
        </pre>
        <img width="0" height="0" src="http://sync-io.net/go/blog/aggbug.ashx?id=d71d00da-05d7-4832-86fc-eeaf416cd7be" />
      </body>
      <title>CreateProcessAsUser from System Service (VB.NET)</title>
      <guid isPermaLink="false">http://sync-io.net/go/blog/PermaLink,guid,d71d00da-05d7-4832-86fc-eeaf416cd7be.aspx</guid>
      <link>http://sync-io.net/go/blog/2008/03/27/CreateProcessAsUserFromSystemServiceVBNET.aspx</link>
      <pubDate>Thu, 27 Mar 2008 21:00:07 GMT</pubDate>
      <description>&lt;p&gt;
The following code has been tested on Windows 2003 SP2.&amp;nbsp;&amp;nbsp;The calling user
account must have&amp;nbsp;'Assign Primary Token' and&amp;nbsp;'Increase Quota'&amp;nbsp;permissions&amp;nbsp;to
properly execute CreateProcessAsUser; see MS KB285879.&amp;nbsp; 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Function&lt;/span&gt; RunProc(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ByVal&lt;/span&gt; CMD &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;String&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ByVal&lt;/span&gt; ARG &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;String&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;String&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; er &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; Int16 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; exitCode &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; System.UInt32 &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Convert.ToUInt32(123) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; saThreadAttributes &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; SECURITY_ATTRIBUTES &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;New&lt;/span&gt; SECURITY_ATTRIBUTES
saThreadAttributes.nLength &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Marshal.SizeOf(saThreadAttributes) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; impToken &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; System.IntPtr &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; IntPtr.Zero &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; priToken &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; System.IntPtr &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; IntPtr.Zero &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; LogonUser(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"DomainUser"&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Domain"&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Passwd"&lt;/span&gt;,
LogonType.LOGON32_LOGON_INTERACTIVE, _ LogonProvider.LOGON32_PROVIDER_DEFAULT, impToken) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Then&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; DuplicateTokenEx(impToken,
&amp;amp;H2000000, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Nothing&lt;/span&gt;,
SecurityImpersonationLevel.SecurityDelegation, TOKEN_TYPE.TokenPrimary, priToken) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Then&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; pi &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; PROCESS_INFORMATION &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;New&lt;/span&gt; PROCESS_INFORMATION &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; si &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; STARTUPINFO &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;New&lt;/span&gt; STARTUPINFO
si.cb &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Marshal.SizeOf(si)
si.lpDesktop &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; IntPtr.Zero &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Dim&lt;/span&gt; saProcessAttributes &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;As&lt;/span&gt; SECURITY_ATTRIBUTES &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;New&lt;/span&gt; SECURITY_ATTRIBUTES
saProcessAttributes.nLength &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Marshal.SizeOf(saProcessAttributes) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Not&lt;/span&gt; CreateProcessAsUser(priToken,
CMD, CMD &amp;amp; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"
"&lt;/span&gt; &amp;amp; ARG, saProcessAttributes, _ saThreadAttributes, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;False&lt;/span&gt;,
0, IntPtr.Zero, &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"c:\"&lt;/span&gt;,
si, pi) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Then&lt;/span&gt; er &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Marshal.GetLastWin32Error
RunProc &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"err
runas "&lt;/span&gt; &amp;amp; er) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Else&lt;/span&gt; WaitForSingleObject(pi.hProcess,
Infinite) GetExitCodeProcess(pi.hProcess, exitCode) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;End&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; CloseHandle(priToken)
CloseHandle(impToken) CloseHandle(pi.hProcess) CloseHandle(pi.hThread) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;End&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;End&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;If&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;End&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;Function&lt;/span&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;img width="0" height="0" src="http://sync-io.net/go/blog/aggbug.ashx?id=d71d00da-05d7-4832-86fc-eeaf416cd7be" /&gt;</description>
      <comments>http://sync-io.net/go/blog/CommentView,guid,d71d00da-05d7-4832-86fc-eeaf416cd7be.aspx</comments>
      <category>Access Denied</category>
      <category>VB.NET</category>
    </item>
    <item>
      <trackback:ping>http://sync-io.net/go/blog/Trackback.aspx?guid=edb235b1-c20b-41c7-b2b8-a9ad90893f37</trackback:ping>
      <pingback:server>http://sync-io.net/go/blog/pingback.aspx</pingback:server>
      <pingback:target>http://sync-io.net/go/blog/PermaLink,guid,edb235b1-c20b-41c7-b2b8-a9ad90893f37.aspx</pingback:target>
      <dc:creator>Chris</dc:creator>
      <wfw:comment>http://sync-io.net/go/blog/CommentView,guid,edb235b1-c20b-41c7-b2b8-a9ad90893f37.aspx</wfw:comment>
      <wfw:commentRss>http://sync-io.net/go/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=edb235b1-c20b-41c7-b2b8-a9ad90893f37</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Let's pretend that Joe Smith working for company A just got an offer from company
B to steal company A's products database for one million dollars.  However company
A already has aleady secured their system pretty tightly.  All external storage
such as USB has been blocked, there are no floppies and Joe does not even have outside
email access.  Joe, however, does have CIFS access to the precious database. 
So he decides to bring a laptop from home, plugs into the network and obtains an IP
from the DHCP server.  He attempts to join Company A domain but is denied since
he is not an administrator.  Joe decides to navigate to '\\FileServer\Databases'. 
Windows prompts him for a username and password, so Joe types in 'CompanyA\JoeSmith'
and his usual domain password.  Voila, he gained access to the Databases share
and now is copying data from the file server onto his laptop; hands the data to company
B and receives a million dollars.  Scary, isn't it?
</p>
        <p>
Wouldn't it be much better if Joe brought his laptop, obtained and IP but when
he tried to access the shared folder all he would receive was an Access Denied message? 
Here is how:
</p>
        <p>
          <em>First of all this setup works because the Windows machine itself is a security
principal with an account name and password in Active Directory Services.</em>
        </p>
        <p>
We need to create two IPSEC policies, one for the file server and the second one for
all clients.  
</p>
        <p>
          <strong>File Server Setup:</strong>
        </p>
        <p>
IP Filter List will contain the following source ports:<br /><u>TCP 137<br />
TCP 139<br />
TCP 445<br />
UDP 137<br />
UDP 139<br /></u>The source IP address will be the file server's IP address and the destination
subnet will be any client grouping you choose.  
</p>
        <p>
The Filter Action will be a custom filter to negotiate security.  Inside the
Custom Security Methods use MD5 to protect 'data and address integrity without encryption'.  <em>Note:
Enabling encryption will affect SMB/CIFS performance.</em></p>
        <p>
          <strong>Client Setup:<br /></strong>The IP Filter List will contain the same source ports as the File Server
setup did.  However the source address will be the File Server's IP address and
the destination address will be My IP Address.<br />
The Filter Action will be the same custom filter as in the setup above.
</p>
        <p>
          <em>After applying the IPSEC policy through GPO, you can use the IPSEC Monitor MMC
to view statistics and associations.  Sniffing the cable should produce ISAKMP
protocol between the client and server.  Any existing CIFS connections will not
survive IPSEC taking effect, so remember to do this overnight or force a client reboot. 
Turning up event logging is also a good way to debug any failed key exchanges.</em>
        </p>
        <p>
          <em>Another approach is individual share protection by using the 'NTLM Authenticator'
user.</em>
        </p>
        <img width="0" height="0" src="http://sync-io.net/go/blog/aggbug.ashx?id=edb235b1-c20b-41c7-b2b8-a9ad90893f37" />
      </body>
      <title>Protecting CIFS from unauthorized access with IPSEC</title>
      <guid isPermaLink="false">http://sync-io.net/go/blog/PermaLink,guid,edb235b1-c20b-41c7-b2b8-a9ad90893f37.aspx</guid>
      <link>http://sync-io.net/go/blog/2008/03/20/ProtectingCIFSFromUnauthorizedAccessWithIPSEC.aspx</link>
      <pubDate>Thu, 20 Mar 2008 18:34:45 GMT</pubDate>
      <description>&lt;p&gt;
Let's pretend that Joe Smith working for company A just got an offer from company
B to steal company A's products database for one million dollars.&amp;nbsp; However company
A already has aleady secured their system pretty tightly.&amp;nbsp; All external storage
such as USB has been blocked, there are no floppies and Joe does not even have outside
email access.&amp;nbsp; Joe, however, does have CIFS access to the precious database.&amp;nbsp;
So he decides to bring a laptop from home, plugs into the network and obtains an IP
from the DHCP server.&amp;nbsp; He attempts to join Company A domain but is denied since
he is not an administrator.&amp;nbsp; Joe decides to navigate to '\\FileServer\Databases'.&amp;nbsp;
Windows prompts him for a username and password, so Joe types in 'CompanyA\JoeSmith'
and his usual domain password.&amp;nbsp; Voila, he gained access to the Databases share
and now is copying data from the file server onto his laptop; hands the data to company
B and receives a million dollars.&amp;nbsp; Scary, isn't it?
&lt;/p&gt;
&lt;p&gt;
Wouldn't it be much better if Joe brought&amp;nbsp;his laptop, obtained and IP but when
he tried to access the shared folder all he would receive was an Access Denied message?&amp;nbsp;
Here is how:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;First of all this setup works because the Windows machine itself is a security
principal with an account name and password in&amp;nbsp;Active Directory Services.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
We need to create two IPSEC policies, one for the file server and the second one for
all clients.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;File Server Setup:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
IP Filter List will contain the following source ports:&lt;br&gt;
&lt;u&gt;TCP 137&lt;br&gt;
TCP 139&lt;br&gt;
TCP 445&lt;br&gt;
UDP 137&lt;br&gt;
UDP 139&lt;br&gt;
&lt;/u&gt;The source IP address will be the file server's IP address and the destination
subnet will be any client&amp;nbsp;grouping you choose.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The Filter Action will be a custom filter to negotiate security.&amp;nbsp; Inside the
Custom Security Methods use MD5 to protect 'data and address integrity without encryption'.&amp;nbsp; &lt;em&gt;Note:
Enabling encryption will affect SMB/CIFS performance.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Client Setup:&lt;br&gt;
&lt;/strong&gt;The IP Filter List will contain the same source ports as the File Server
setup did.&amp;nbsp; However the source address will be the File Server's IP address and
the destination address will be My IP Address.&lt;br&gt;
The Filter Action will be the same custom filter as in the setup above.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;After applying the IPSEC policy through GPO, you can use the IPSEC Monitor MMC
to view statistics and associations.&amp;nbsp; Sniffing the cable should produce ISAKMP
protocol between the client and server.&amp;nbsp; Any existing CIFS connections will not
survive IPSEC taking effect, so remember to do this overnight or force a client reboot.&amp;nbsp;
Turning up event logging is also a good way to debug any failed key exchanges.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Another approach is individual share protection by using the 'NTLM Authenticator'
user.&lt;/em&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://sync-io.net/go/blog/aggbug.ashx?id=edb235b1-c20b-41c7-b2b8-a9ad90893f37" /&gt;</description>
      <comments>http://sync-io.net/go/blog/CommentView,guid,edb235b1-c20b-41c7-b2b8-a9ad90893f37.aspx</comments>
      <category>Access Denied</category>
    </item>
  </channel>
</rss>