<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Secure Coding</title>
  <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/" />
  <link rel="self" href="http://www.secure-coding.com/Blog/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2006-01-15T20:29:49.859375-05:00</updated>
  <author>
    <name>Adam Tuliper</name>
  </author>
  <subtitle>Protect Your Applications</subtitle>
  <id>http://www.secure-coding.com/Blog/</id>
  <generator uri="http://www.dasblog.net" version="1.8.5210.0">DasBlog</generator>
  <entry>
    <title>Options for creating firewalls</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,ce0395bf-0730-4935-afaa-aa47424da877.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,ce0395bf-0730-4935-afaa-aa47424da877.aspx</id>
    <published>2006-01-15T20:00:44.468-05:00</published>
    <updated>2006-01-15T20:29:49.859375-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      There are several options if you are looking to create a firewall. This list is by
      no means complete, just as a reference for myself basically : )
   </p>
        <p>
       
   </p>
        <p>
      1. NDIS driver (Protocol - implements a protocol, Intermediate Level - can do filtering,translations,
      and packet scheduling and Miniport drivers - the final level that actually talks
      to the nic) - Best but most difficult
   </p>
        <p>
      2. TDI filter driver - decent, can be circumvented via RawIp
   </p>
        <p>
      3. Layered Service Provider - can be circumvented easily.
   </p>
        <p>
      4. Winsock Hooks (pain to implement, can be circumvented fairly easily)
   </p>
        <p>
      5. Filter-hook driver (only one allowed on a system - if another app uses it - you
      are out of luck) Cant access data
   </p>
        <p>
      uses IOCTL_PF_SET_EXTENSION_POINTER with IoBuildDeviceIoControlRequest();
   </p>
        <p>
      6. Firewall hook driver (relatively undocumented way -  see <a href="http://www.codeproject.com/internet/FwHookDrv.asp">http://www.codeproject.com/internet/FwHookDrv.asp</a>)
      Not recommended by MS. More difficult to modify data than TDI as its pretty undocumented
   </p>
        <p>
      From Microsoft:
   </p>
        <p>
      It is not recommended to implement a <i>firewall-hook driver</i> (or <i>firewall driver</i>)
      for Microsoft Windows XP and later versions of the operating system. 
   </p>
        <p>
      The Microsoft Windows 2000 DDK introduced the concept of a firewall-hook driver. The
      intent of a firewall-hook driver was to manage network packets that were sent and
      received across a firewall in the context of the TCP/IP protocol. A <i>firewall </i>is
      a control system that prevents unauthorized users from gaining access to a local network
      that is connected to the Internet. 
   </p>
        <p>
      A firewall-hook driver did not meet firewall requirements because it ran too high
      in the network stack. A firewall-hook driver could also interfere with the operations
      of Internet Connection Sharing (ICS) or a personal firewall implementation. 
   </p>
        <p>
      To provide firewall functionality on Windows XP and later, you should create an NDIS
      intermediate miniport driver to manage packets sent and received across a firewall.
      For information on creating an NDIS intermediate miniport driver, see <a href="http://msdn.microsoft.com/library/en-us/NetXP_d/hh/NetXp_d/301int_67db673d-f0cf-490e-ae05-7ced7df5c2f3.xml.asp">NDIS
      Intermediate Drivers</a>.
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=ce0395bf-0730-4935-afaa-aa47424da877" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Fighting malware by controlling process creation Part 1</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,0cdd5297-078b-471c-9427-17155022c349.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,0cdd5297-078b-471c-9427-17155022c349.aspx</id>
    <published>2006-01-06T22:45:53.09375-05:00</published>
    <updated>2006-01-06T22:45:53.09375-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I've decided it's time to fight back and provide some tools for people to fight malware.
   </p>
        <p>
      The first step to fighting it on your machine (this article is geared to the more
      technical crowd) is being able to stop it from loading, replicating, and communicating.
   </p>
        <p>
      1. Always review your firewall rules.
   </p>
        <p>
      2 . Process Creation
   </p>
        <p>
       
   </p>
        <p>
      NtCreateSection
   </p>
        <p>
      MiFindImageSectionObject
   </p>
        <p>
      MiLockPfnDatabase
   </p>
        <p>
      MiInsertImageSectionObject
   </p>
        <p>
      MiCreateImageFileMap
   </p>
        <p>
      NtCreateProcessEx
   </p>
        <p>
      MmCreateProcessAddressSpace
   </p>
        <p>
      MmCreatePeb
   </p>
        <p>
      BasePushProcessParameters
   </p>
        <p>
      BaseCreateStack
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=0cdd5297-078b-471c-9427-17155022c349" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Fighting malware - registry keys exploited for loading malware programs</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,d3418501-d3b8-4690-b4af-329aa2e68854.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,d3418501-d3b8-4690-b4af-329aa2e68854.aspx</id>
    <published>2006-01-06T00:07:58.921875-05:00</published>
    <updated>2006-01-06T00:07:58.921875-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Im working on a new utility to help systems guys fight spyware on their systems. I
      was quite frustrated trying to get one off my Mother's machine, random named exes
      would keep appearing, even after safe mode boots and removal of hklm\software\microsoft\windows\run
      keys. I tried also 'pausing' the process using process explorer from sysinternals
      with limited success. So.. now Im writing a kernel mode driver to help combat this. 
   </p>
        <p>
      For starters, lets visit the short list of how all things can load on the system.
   </p>
        <p>
       
   </p>
        <p>
      ShellExecute Hooks<br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellExecuteHooks 
   </p>
        <p>
      Shell Delay Load Objects<br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad 
   </p>
        <p>
      URL Search Hooks<br />
      HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\URLSearchHooks 
   </p>
        <p>
      App Init DLLs<br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\Windows, AppInit_DLLs 
   </p>
        <p>
      Download Manager<br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer, DownloadUI<br />
      HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer, DownloadUI 
   </p>
        <p>
      Notification Packages<br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\Winlogon\Notify 
   </p>
        <p>
       
   </p>
        <p>
      User\Start Menu\Programs\Startup; 
      <br />
      All Users\Start Menu\Programs\Startup; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run; 
      <br />
      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce; 
      <br />
      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices; 
      <br />
      HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Shell; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, System; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, VmApplet; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, UIHost; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, Userinit; 
      <br />
      HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows, run; 
      <br />
      HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows, load; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Active Setup\Installed Components; 
      <br />
      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager, BootExecute; 
      <br />
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows CurrentVersion\Explorer\BrowserHelperObjects<br />
      win.ini, load; 
      <br />
      win.ini, run; 
      <br />
      system.ini, shell. 
   </p>
        <p>
      They can also install themselves as services:
   </p>
        <p>
      HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
   </p>
        <p>
      All of these locations can be exploited.
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=d3418501-d3b8-4690-b4af-329aa2e68854" />
      </div>
    </content>
  </entry>
  <entry>
    <title>building kernel mode drivers with vs.net/ddk</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,792748fa-84fd-4fc4-94cf-ef3d8cb86b91.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,792748fa-84fd-4fc4-94cf-ef3d8cb86b91.aspx</id>
    <published>2006-01-05T23:56:31.71875-05:00</published>
    <updated>2006-01-05T23:56:31.71875-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      So Im trying to compile a kernel mode driver I'm writing against the ddk rather than
      using vs.net.
   </p>
        <p>
      First off, to use visual studio, read:
   </p>
        <p>
          <a href="http://tiger.la.asu.edu/Quick_Ref/DeviceDriver.pdf">http://tiger.la.asu.edu/Quick_Ref/DeviceDriver.pdf</a>
        </p>
        <p>
      as well as there is a nice batch at <a href="http://www.osronline.com/article.cfm?article=43">http://www.osronline.com/article.cfm?article=43</a></p>
        <p>
      but everyone says "hey - use the ddk - that what the compiler is there for"
   </p>
        <p>
      Ok, so I keep getting an error on this line.
   </p>
        <p>
      PHYSICAL_ADDRESS    PhysicalAddress; &lt;-- error here - 
   </p>
        <p>
      PhysicalAddress = MmGetPhysicalAddress((void*)block);
   </p>
        <p>
       
   </p>
        <p>
      error:
   </p>
        <p>
       error C2275: 'PHYSICAL_ADDRESS' : illegal use of this type as an expression
   </p>
        <p>
      hmm... its used throughout the ddk samples that I can build. So I try PVOID,
      void*, ULONG all with the same result.
   </p>
        <p>
      Then it occurs to me - the types are recognized, how about moving the defs to the
      top of the procedure (sorry - I've been so used to modern compilers
   </p>
        <p>
      where you can gladly declare vars anywhere) and voila. Thats an hour of my life I'll
      never get back - thanks ddk guys for packaging that wonderful compiler with the ddk!!
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=792748fa-84fd-4fc4-94cf-ef3d8cb86b91" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Timestamping bookmarks/page access</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,4404bd10-4283-4f43-8c66-4fbc45b84bbb.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,4404bd10-4283-4f43-8c66-4fbc45b84bbb.aspx</id>
    <published>2005-12-28T17:26:58.609375-05:00</published>
    <updated>2005-12-28T17:26:58.609375-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Sometimes there is a need to control when a page is accessed through a link and bookmark
      it. For instance,
   </p>
        <p>
      your company sells a product that should only be valid for a certain time, or provides
      access to a special deal.
   </p>
        <p>
      Every page then needs to include checks to determine if the item in question is valid
      or not. 
   </p>
        <p>
      ex.
   </p>
        <p>
          <a href="http://www.secure-coding.com/ProductDetails.aspx?id=68">www.secure-coding.com/ProductDetails.aspx?id=68</a>
        </p>
        <p>
      So a check needs to be made to the database, requiring an extra hit on what may be
      an already busy system.
   </p>
        <p>
      If you have items that expire quite often, here is an alternative:
   </p>
        <p>
          <a href="http://www.secure-coding.com/ProductDetails.aspx?id=68&amp;expires=12282005">www.secure-coding.com/ProductDetails.aspx?id=68&amp;expires=12282005</a>
        </p>
        <p>
      Now this is quite obvious of course on how one can get around that. However, encrypting
      it becomes:
   </p>
        <p>
          <a href="http://www.secure-coding.com/ProductDetails.aspx?54754a68666e3839467646496659745a7467574750773d3d">www.secure-coding.com/ProductDetails.aspx?54754a68666e3839467646496659745a7467574750773d3d</a>
        </p>
        <p>
      A page can then determine if the access is still valid.
   </p>
        <p>
      Still yet another usage
   </p>
        <p>
          <a href="http://www.secure-coding.com/Admin/DeleteItem.aspx?id=68">www.secure-coding.com/Admin/DeleteItem.aspx?id=68</a>
        </p>
        <p>
      Two scenarios can occur, if you use the querystring to manage items in a database,
      its quite easy to select the wrong one in your recent history.
   </p>
        <p>
      One alternative is when a link is generated to DeleteItem.aspx, generate a timestamp.
      If you use a common page baseclass, then that baseclass can decrypt the querystring
      and check for an expiration date. If it has expired, the user can be redirect, etc. 
   </p>
        <p>
      Once again I advocate encrypting the querystring. I love it : )
   </p>
        <p>
      Yes - this can be attacked, as can just about anything - but provides an extra layer
      of data protection and a means to timestamp your links.
   </p>
        <p>
      This is especially useful when users have very old links they bookmark and you want
      an easy way to check the lengths of time users keep old links, and refer them to new/updated
      links.
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=4404bd10-4283-4f43-8c66-4fbc45b84bbb" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Tips for secure coding</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,6cbfb6f2-d30b-4efa-8db0-044e624cf3fa.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,6cbfb6f2-d30b-4efa-8db0-044e624cf3fa.aspx</id>
    <published>2005-12-28T00:33:11.625-05:00</published>
    <updated>2005-12-28T00:33:11.625-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Heres just a quick list of tips I tell people
   </p>
        <p>
      1. Dont use embedded queries, use stored procedures, avoid sp_executesql
   </p>
        <p>
      2. Remove all &lt; &gt; -- ' / \ from input strings. You will need to write a loop
      that filters multibyte sequences after single byte sequences and loops until no more
      can be found. Because for ex.
   </p>
        <p>
      hello-/-john
   </p>
        <p>
      if you remove the / you are left with hello--john, and thats a problem.
   </p>
        <p>
      3. Refilter ALL input, including querystring. If you provide a link <a href="http://www.somesite.com/products.aspx?id=906B">www.somesite.com/products.aspx?id=906B</a></p>
        <p>
      Assume someone is messing around with the url and trying things like
   </p>
        <p>
          <a href="http://www.somesite.com/products.aspx?id='--">www.somesite.com/products.aspx?id='--</a>
        </p>
        <p>
      to test for sql injection attacks.
   </p>
        <p>
      4. Make sure your login pages are https. I know - seems like a given, however many
      sites actually have login pages that are not https, but post to https pages, hence
      the data is still secure.
   </p>
        <p>
      However, the 'lay user' doesn't see the little 'secure' lock in their browser and
      don't think it is secure. Believe it or not I've heard quite a few complaints from
      users trying to access sites in that manner.
   </p>
        <p>
      5. Encrypt all query string information - I should be posting some code shortly for
      this.
   </p>
        <p>
      6. Configure error pages for all of your applications (in turn make sure your &lt;customErrors&gt;
      section in web.config is set to RemoteOnly so remote users wont get asp.net error
      messages.
   </p>
        <p>
      Catch errors in global.asax application_onerror and log your errors at least to a
      file. If you log to the event log, remember to give asp.net permissions to the eventlog
      registry key
   </p>
        <p>
          <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;329291">http://support.microsoft.com/default.aspx?scid=kb;en-us;329291</a> (I
      believe if you give aspnet (2000,xp)/network service (2003) permissions to 
   </p>
        <div class="indent">HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
   </div>
        <p>
      you should be ok. Log to a file first, since that is the method most likely to work.
      If you log to a db and that fails, your code needs to continue logging, hence easiest
      to log to a file first. TEST THIS for every application you deploy.
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=6cbfb6f2-d30b-4efa-8db0-044e624cf3fa" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Denial of service - Busy network operation can disconnect a terminal service session</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,241e9746-5085-4218-8cea-5961625e1624.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,241e9746-5085-4218-8cea-5961625e1624.aspx</id>
    <published>2005-11-30T16:26:30.796875-05:00</published>
    <updated>2005-11-30T16:26:30.796875-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      From a local machine, it seems maxing out your network connection can cause a terminal
      service session to disconnect.
   </p>
        <p>
      From there, its a small step to enumerate connected users, hammer them and use up
      available sessions.
   </p>
        <p>
      Only solution I can think of is qos packet scheduling. I'll have to investigate this
      one further.
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=241e9746-5085-4218-8cea-5961625e1624" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login' </title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,505dc8c1-c08d-46d3-b3f9-89f979c274ef.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,505dc8c1-c08d-46d3-b3f9-89f979c274ef.aspx</id>
    <published>2005-11-15T11:11:05.625-05:00</published>
    <updated>2005-11-15T11:11:05.625-05:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Nice work on the automatically generated code for the login component - 
   </p>
        <p>
      If you name your page login.aspx and put a login control on the page, it seems theres
      a namespace problem and the code casts to a (Login) control, which really casts to
      your page class - hence the problem, because it's expecting a Login control instead.
      Solution is to rename your page class. 
   </p>
        <p>
      1. Rename your page to AccessLogin.aspx for example
   </p>
        <p>
      2. Rename (right click on it and select refactore-rename for best results) your class
      in your code behind from Login to AccessLogin
   </p>
        <p>
      3. Update your "Inherits" tag on your .aspx page from Inherits="Login" to Inherits="AccessLogin"
   </p>
        <p>
      That should do it.
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=505dc8c1-c08d-46d3-b3f9-89f979c274ef" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Careful of embedded script in server controls</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,0afc5524-9397-4236-8fe0-e72e3f1fcc42.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,0afc5524-9397-4236-8fe0-e72e3f1fcc42.aspx</id>
    <published>2005-11-03T11:23:06.390625-04:00</published>
    <updated>2005-11-03T11:23:06.390625-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <font color="#0000ff" size="2">
          <p>
      Be careful of embedding script in server controls, it won't work and can very well
      lead to information gathering.
   </p>
          <p>
      This is of course a very simple example. Code is not processed in this case:
   </p>
          <p>
      &lt;
   </p>
        </font>
        <font color="#800000" size="2">asp</font>
        <font color="#0000ff" size="2">:</font>
        <font color="#800000" size="2">HyperLink</font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff0000" size="2">id</font>
        <font color="#0000ff" size="2">="HyperLinkStatement"</font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff0000" size="2">NavigateUrl</font>
        <font color="#0000ff" size="2">="MyUrl.aspx?</font>
        <font color="#000000" size="2">&lt;%=GetSecureInformationFromEncryptedFile("c:\\somefile.txt")%&gt;</font>
        <font color="#0000ff" size="2">"</font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff0000" size="2">style</font>
        <font color="#0000ff" size="2">="Z-INDEX:
   101"</font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff0000" size="2">runat</font>
        <font color="#0000ff" size="2">="server"&gt;Download</font>
        <font color="#0000ff" size="2">&lt;/</font>
        <font color="#800000" size="2">asp</font>
        <font color="#0000ff" size="2">:</font>
        <font color="#800000" size="2">HyperLink</font>
        <font color="#0000ff" size="2">&gt;</font>
        <p>
          <font color="#0000ff" size="2">This will not evaluate the method. I always find it
      interesting the results you get when searching for asp code on the net. Because of
      misconfigurations or server migrations, you can view the entire source code for various
      sites out there.
      </font>
        </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=0afc5524-9397-4236-8fe0-e72e3f1fcc42" />
      </div>
    </content>
  </entry>
  <entry>
    <title>LogonUser to access remote machines (impersonation)</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,7c3cd491-2681-4d33-8ce9-375364e7703d.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,7c3cd491-2681-4d33-8ce9-375364e7703d.aspx</id>
    <published>2005-10-25T21:19:08.515625-04:00</published>
    <updated>2005-10-25T21:19:08.515625-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Accessing a remote resource
   </p>
        <p>
      First understand the difference between LOGON32_LOGON_INTERACTIVE and LOGON32_LOGON_NETWORK
   </p>
        <p>
      Second understand that if:
   </p>
        <p>
      1. You are on a machine (Machine A) that is not part of the domain
   </p>
        <p>
      And
   </p>
        <p>
      2. You are trying to access a domain machine (Machine B) using domain credentials
      from Machine A using LogonUser
   </p>
        <p>
      This will not work. Machine A doesn't know about this domain, so getting a token with
      information for some domain that is unknown is useless.
   </p>
        <p>
      You must be using a domain account. One mistake that is quite common deals with a misunderstanding
      about logging on users. If I make a call to LogonUser and specify LOGON32_LOGON_NETWORK,
      there is a search order for domain controllers to validate that name. If you have
      specified the local machine, then there is no validation unless of course you are
      on a domain controller. If you are trying to validate against another machine on the
      network that is NOT PART OF A DOMAIN - you cannot validate these credentials through
      logonuser. You must map the connection as described below. Even if the local login
      and password match that of the remote machine, this will not work. It can be confusing,
      because if I try to access machine b from Machine A, and they both have an administrator
      account with a different password that I need to specify in the credentials from machine
      a:
   </p>
        <p>
      MachineB\administrator 
   </p>
        <p>
      in order to validate the user on machineb. So one would think I can call logon user
      and specify a remote machine name. False. You cannot (as far as anything I am aware
      of). So then how does Windows do it you say, or such things like runas.exe? Think
      what happens in a remote machine network access. Your system tries to setup an SMB
      session. The remote server requires more information and sends back STATUS_MORE_PROCESSING_REQUIRED.
      Your system sends over the appropriate authentication information. You then access
      the interprocess communication share at <a href="file://MachineB/IPC$">\\MachineB\IPC$</a> and
      once this is established (with a proper account) can perform your network request
      (ex. c:&gt;dir <a href="file://machineb/someshare">\\machineb\someshare</a>)
   </p>
        <p>
      How can you then achieve this behavior? Simply enough, in this case you use the WNetAddConnection2
      api to establish a session to <a href="file://machineb/ipc$">\\machineb\ipc$</a>.
      Once that session is established you have "remote permissions" for your current login
      and can then do your mojo. You are using SMB session information, and not logonuser
      to achieve this. 
   </p>
        <p>
       
   </p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=7c3cd491-2681-4d33-8ce9-375364e7703d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Machine running SLOW? Possibly OS Loader Slowness - Do not put unc locations in your path statement!</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,69be5f4f-93df-4a68-9cac-306135ff6ca3.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,69be5f4f-93df-4a68-9cac-306135ff6ca3.aspx</id>
    <published>2005-10-25T16:27:19.156-04:00</published>
    <updated>2005-10-25T16:51:29.9375-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I realize this doesn't relate to secure coding (Although something quickly comes to
      mind of a way to modify a user's path statement to load libraries they didn't intend
      to) but felt this was important to post.
   </p>
        <p>
      I was troubleshooting a coworkers system that was running extremely slow. Running
      calc.exe would take at least a minute to load. I noticed the network icon was lighting
      up every 8 seconds or so with a transmit but no receive. One thing to note, once she
      unplugged her machine from the network, response time was normal again. Loading up
      tdimon from <a href="http://www.sysinternals.com/">www.sysinternals.com</a> (netmon
      would have worked as well but was not yet on this system) I was seeing an attempt
      to contact a remote machine on port 445. The first though was something had hooked
      the shell and was receiving notifications of program loading and trying something
      shady. Turned out to be a bit simpler. The path statement contained a unc path so
      every program searched this path for dependencies upon loading. I would check your
      path statements to make sure this isn't there, as this would affect the loading of
      almost every program on the system. When the machine was unplugged, the network services
      knew there was no network interface to use to try to contact the remote machine, and
      thus performance was restored. 
   </p>
        <p>
      You can see here the process that is used and how a dll is resolved upon loading.
      This process can be examined a bit more in detail at:
   </p>
        <p>
          <a href="http://msdn.microsoft.com/msdnmag/issues/02/03/Loader/">http://msdn.microsoft.com/msdnmag/issues/02/03/Loader/</a>
        </p>
        <p>
      The call stack order something like this:
   </p>
        <p>
      LdrLoadDll 
      <br />
          LdrpLoadDll<br />
              LdrpCheckForLoadedDll 
      <br />
              LdrpMapDll 
      <br />
                  LdrpCheckForKnownDll 
      <br />
                  LdrpResolveDllName<br />
                    
      RtlInitUnicodeString     
      <br />
                    
      LdrpResolveDllNameForAppPrivateRedirection 
      <br />
                    
      LdrpSearchPath 
      <br />
                      
      RtlDetermineDosPathNameType_U     
      <br />
                      
      RtlInitUnicodeStringEx<br />
                      
      RtlDoesFileExists_UstrEx<br />
                      
      LdrpResolveFullName<br /></p>
        <p>
      So when the path is parsed, a remote unc will be checked om RtlDoesFileExists_UstrEx
   </p>
        <p>
      Recommendation: Remove all unc paths if you are able to from your path statement
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=69be5f4f-93df-4a68-9cac-306135ff6ca3" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Network authentication with runas.exe does not take place when the command is run</title>
    <link rel="alternate" type="text/html" href="http://www.secure-coding.com/Blog/PermaLink,guid,03291510-ac87-4d4e-96c1-b04776b145bb.aspx" />
    <id>http://www.secure-coding.com/Blog/PermaLink,guid,03291510-ac87-4d4e-96c1-b04776b145bb.aspx</id>
    <published>2005-10-10T17:37:13.328-04:00</published>
    <updated>2005-10-20T14:26:20.53125-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
      If you run runas.exe with the /netonly flag and specify totally invalid user credentials,
      it never even checks those credentials until you access the network.
   </p>
        <p>
      You would think the resulting program that runs (cmd.exe for instance) would check
      that first, especially since the window title is:
   </p>
        <p>
      cmd(running as machinename\someinvalidaccount)
   </p>
        <p>
      Just an oddity to watch out for. You are not actually authenticated with network permissions
      until you attempt to use those network permissions.
   </p>
        <p>
      In other news tokenmon from sysinternals has caused a system crash twice now in as
      many days on two separate systems.
   </p>
        <p>
      The first was in my physical server in lsass.exe the second occured on a virtual server
      and it just rebooted the virtual server. 
   </p>
        <p>
      Don't get me wrong, I absolutely love their utilities and they've served me well for
      a long time. The guys from sysinternals should be role models for everyone in
      the IT world - but the utilities shouldn't crash my servers. I'm going to try
      to get an exact duplication as Im concerned about the possibility of a denial of service
      on any system running it.
   </p>
        <p>
      I've sent an email to them, haven't heard anything back though. 
   </p>
        <p>
       
   </p>
        <img width="0" height="0" src="http://www.secure-coding.com/Blog/aggbug.ashx?id=03291510-ac87-4d4e-96c1-b04776b145bb" />
      </div>
    </content>
  </entry>
</feed>