<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;C08NRnY6cCp7ImA9WxNUGU4.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575</id><updated>2009-11-11T01:31:37.818-08:00</updated><title>Building Secure Code</title><subtitle type="html">Advice on creating, deploying and maintaining secure applications and protecting them from malicious hackers -- An &lt;a href="http://www.impactalabs.com/handlers/fwlink.aspx?linkid=00000"&gt;Impacta LLC&lt;/a&gt; Community Project</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><author><name>Building Secure Code (Impacta LLC)</name><uri>http://www.blogger.com/profile/16221121325665581681</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="self" href="http://feeds.feedburner.com/BuildingSecureCode" type="application/atom+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">BuildingSecureCode</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry gd:etag="W/&quot;D0UCQn44eCp7ImA9WxRXF0w.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-5607567695088412840</id><published>2008-10-22T15:38:00.000-07:00</published><updated>2008-10-22T15:41:03.030-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-22T15:41:03.030-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="General" /><title>Impacta Company Blog is Launched!</title><content type="html">If you didn't already know, Impacta launched a company blog at &lt;a href="http://blog.impactalabs.com/"&gt;http://blog.impactalabs.com&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;This blog (&lt;a href="http://www.buildingsecurecode.com/"&gt;www.buildingsecurecode.com&lt;/a&gt;) will definitely continue on with emphasis on providing expert, and pragmatic tips to developers/testers for building secure code, whereas the company blog will be more for discussing online risk topics and innovations.  Check it out when you get a chance!&lt;br /&gt;&lt;br /&gt;--Kevin&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-5607567695088412840?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/2IWRA-Sjepc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/5607567695088412840/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=5607567695088412840" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/5607567695088412840?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/5607567695088412840?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2008/10/impacta-company-blog-is-launched.html" title="Impacta Company Blog is Launched!" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DEcDQH86fSp7ImA9WxRQEEw.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-410774848032122636</id><published>2008-10-02T23:34:00.000-07:00</published><updated>2008-10-02T23:41:11.115-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-02T23:41:11.115-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="General" /><title>Has It Really Been a Year?</title><content type="html">Talk about neglecting your readership -- it's been over a year since I last posted on this blog!  Anyhow, with &lt;a href="http://www.impactalabs.com/"&gt;Impacta&lt;/a&gt;'s flagship product nearing beta completion, and a good cash flow coming in, I should have more time now to devote to this blog and helping people build more secure code! &lt;br /&gt;&lt;br /&gt;Even if you are already a security professional, a year's worth of non-stop developing a security product on some awesome Microsoft technologies can teach you a lot, so I am eager to starting sharing again!&lt;br /&gt;&lt;br /&gt;--Kevin&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-410774848032122636?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/_4ntd4A68iE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/410774848032122636/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=410774848032122636" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/410774848032122636?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/410774848032122636?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2008/10/has-it-really-been-year.html" title="Has It Really Been a Year?" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;AkQHSXk5fip7ImA9WxdUFU8.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-3928126415283775277</id><published>2007-09-21T17:21:00.000-07:00</published><updated>2008-07-31T11:18:58.726-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-07-31T11:18:58.726-07:00</app:edited><title>Have You Checked Out Microsoft's Guidance Explorer Lately?</title><content type="html">&lt;strong&gt;&lt;span style="font-family:arial;"&gt;Overview&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/jmeier"&gt;&lt;span style="font-family:arial;"&gt;J.D. Meier&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; and the rest of the &lt;/span&gt;&lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=guidanceExplorer"&gt;&lt;span style="font-family:arial;"&gt;Patterns &amp;amp; Practices team&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; over at Microsoft are at it again (when did they stop?). If you haven't checked out Guidance Explorer Web Edition, you should and bookmark it now! Here's the link:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.guidancelibrary.com/guidanceexplorerbeta/"&gt;&lt;span style="font-family:arial;"&gt;&lt;del&gt;Guidance Explorer Online (Web Edition)&lt;/del&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/guidanceExplorer"&gt;Guidance Explorer on Code Plex&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:arial;"&gt;I knew about this site way back when I was at Microsoft, but they've made significant improvements since then. It gives you instant access to all the patterns and practices developed at Microsoft and it's a great tool to find out the best ways to identify, mitigate and learn about common coding mistakes that can leave you exposed to malicious hackers. Checklists, methodologies, all there.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;For instance, want to learn how to defend your application from SQL injection attacks, type "sql injection" in the search box. Cross site scripting (XSS)? Type "XSS" into the search box and you get everything you need to know from a variety of angles like input validation, authentication etc.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Enjoy,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;--Kevin&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-3928126415283775277?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/IZrnGaCJGYk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/3928126415283775277/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=3928126415283775277" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/3928126415283775277?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/3928126415283775277?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2007/09/have-you-checked-out-microsofts.html" title="Have You Checked Out Microsoft's Guidance Explorer Lately?" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></entry><entry gd:etag="W/&quot;CEEFSXo7fSp7ImA9WxdXEE4.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-1958101388723777778</id><published>2007-09-18T12:18:00.000-07:00</published><updated>2008-06-21T00:16:58.405-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-06-21T00:16:58.405-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Architecture and Planning" /><category scheme="http://www.blogger.com/atom/ns#" term="Requirements and Analysis" /><title>Prioritizing Security Assessments in 20 Minutes or Less!</title><content type="html">&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br /&gt;Imagine you’re the CSO of some organization, or work for the CSO of your organization and you’ve been asked to come up with a prioritized list of systems/applications that need to be assessed this year and justify why need to be assessed. How do you start? Let me show you.&lt;br /&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Your first thoughts might be consulting firms. Couldn’t they help prioritize security assessments? Consulting companies certainly can (they can do anything when the price is right: conduct a full inside and out regulatory compliance check of your IT operations, mow the lawn, paint the side of the building …), but there are several reasons why creating the prioritization yourself is better. First consultants by definition are “outsiders” to your company and won’t have the same understanding and appreciation of systems/applications/data or their criticality and interdependencies as you will. Second, even if consultants could build up that knowledge about your company (unless you don’t mind) it would be on your dime and you would essentially be paying them to learn about your company instead of helping your company. Finally, most vendors will place the assessment projects that will result in the most potential hours for them at the front of the “priority listing” which often helps their bottom line (revenue) and if you’re lucky maybe even yours (reducing critical risks to your business).&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;So now that using consultants are out the door, what about using tools and surveys to come up with a prioritization? These can definitely help, but here are reasons why they may not be for you:&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Threat Modeling Tools.&lt;/strong&gt; Threat modeling helps you understand threats to a system and the prioritization of those threats. You could reasonably base your assessment prioritization on the systems/applications/data that yield the most high risks and threats, but in order to do so you need to have someone who understands the threat modeling process to create the models (more consulting hours) and you need to invest significant time to complete the threat models (even more consulting hours) for every system/application in order to make that prioritization. If you’ve got budget/time/inclination, by all means go the expensive threat modeling services route, but if you don’t read on! &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Surveys.&lt;/strong&gt; Most surveys work by asking questions along the lines of “does this risk/threat/hazard apply to you?” In other words you’re basically being asked “is this a bad thing for you” and you need to answer yes or no. Each “bad thing” is given a weight, and at the end if the survey all the “bad things” are tallied up and the system/application with the greatest weight is given the highest priority. The one with the second highest weight is given second priority, so on and so on. One problem. You're trying to quantify the bad and I talk about the perils of doing this in my &lt;/span&gt;&lt;a href="http://buildingsecurecode.blogspot.com/2007/06/keeping-hackers-at-bay-approaches-to.html"&gt;&lt;span style="font-family:arial;"&gt;blog about Input Validation&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now we’re left the best, I think, prioritization system of them all: you. In this article, I’ll show you my own technique that you can use to quickly and systematically determine the priority of security assessments based simply on what you know about your organization (business objectives, processes, data, etc.) not the unknowns (threats, vulnerabilities) and with little to no in-depth security expertise required. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Prioritizing Security Assessments&lt;br /&gt;&lt;/strong&gt;Our objective is to be able to come up with a prioritized list of security assessments to conduct (what), show how they align closely with the prioritization of overall business objectives (why) and easily explain to the person you’re asking budget from how you came to that list.&lt;br /&gt;This method takes only known data about your organization and utilizes the following to prioritize security assessments: &lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Explicit Dependencies.&lt;/strong&gt; Aspects of your organization that without them your organization does not function at all – caput, nada, lights out, etc. &lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Implicit Dependencies.&lt;/strong&gt; Aspects of your organization that without them your organization still continues, but is degraded in some way. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;While it sounds super complex and one beast of a method to execute it’s really not. To get started, all we need to do is start enumerating the following: &lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;Your organization’s business objectives&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;Applications and Systems &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;Data and Information&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Step 1 (Minute 0-5): Enumerate Your Business Objectives&lt;br /&gt;&lt;/strong&gt;In this step simply write down your organization’s business objectives. Your organization will probably have multiple ones like increase revenue through direct sales, become industry leader, etc. Doesn’t matter, just write them down. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Next, rank those business objectives as high, medium and low. It’s up to you to determine what constitutes high, medium or low in the context of your organization (since you know it the best). Some of my customers like to rank business objectives in terms of the amount of revenue that objective represents to the organization but that might not fit your scenario. Here’s the standard ranking that I like to use: &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;HIGH – Business objectives that are critical to your organization. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;MEDIUM – Business objectives that are important to your organization. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;LOW – Business objectives that are minimally important in the context of your organization.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Step 2 (Minutes 5-10): Enumerate Systems and Applications (Explicit Dependencies)&lt;br /&gt;&lt;/strong&gt;After you’ve written down your business objectives and ranked them, write down the systems and applications that fulfill those business objectives. These are what I call explicit dependencies because without these systems and applications your organization stops. For instance, if one of your objectives was to increase direct online sales, an application or system that might fulfill that objective is your procurement web application or database to track sales and collects payments. &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;"&gt;As we did in that last step, rank the processes, systems and applications. Again, you can decide what each system and application gets categorized as, but be sure to keep the same high, medium and low categories.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;HIGH – Explicit dependencies that are critical to the business objective they fulfill. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;MEDIUM – Explicit dependencies that are important to the business objective they fulfill.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;LOW – Explicit dependencies that are minimally important to the business objective they fulfill.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Step 3 (Minutes 10-15): Enumerate Data (Implicit Dependencies)&lt;br /&gt;&lt;/strong&gt;After you’ve finished with systems and applications, now write down the data used by those systems and applications that fulfill the business objectives that you noted in Step 1. These are what I call implicit dependencies because in the absence of them your business still runs, but maybe in a degraded state. It can be data your business generates (accounting records for instance) or data that is given to your business (credit cards for instance). Any data your organization uses, creates or reads in. You get the idea. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now rank the data. Again, it is up to you how you classify what constitutes HIGH, MEDIUM and LOW. I like to use this ranking system: &lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;HIGH – Implicit dependencies that are critical to the explicit dependency that uses it. Sometimes referred to as high business impacta (HBI) data. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;MEDIUM – Implicit dependencies that are important to the explicit dependency that uses it. Sometimes referred to as medium business impacta (MBI) data.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;LOW – Explicit dependencies that are minimally important to the explicit dependency that uses it. Sometimes referred to as low business impacta (LBI) data.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Step 4 (Minutes 15-20): Making Sense of it All, Prioritizing Your Security Assessments&lt;br /&gt;&lt;/strong&gt;The final step now is to tie all that data together and come out with a security assessment prioritization. First step is to take your business objective rankings and order them according to rank. So you should have a HIGH bucket, MEDIUM bucket and a LOW bucket.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now for each bucket, write down the systems/applications (explicit dependencies) that fulfill that business objective. If you have an explicit dependency that fulfills more than one business objective, err on the side of caution and write it down in the bucket with the highest rank. For instance, if you have an application that fulfills both a HIGH business objective and a MEDIUM business objective, then you want to write it down in the HIGH business objective bucket. At this point you have a set of systems/applications that need to be assessed first (the HIGH bucket), second (the MEDIUM bucket) and last (the LOW bucket). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;But what about prioritization within buckets? For instance you know that that all the systems/applications in the HIGH bucket need to be reviewed before the MEDIUM bucket, but in what order do you need to review the systems/applications in the HIGH bucket? To do that you can use the following chart:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://buildingsecurecode.googlepages.com/SecurityAssessmentPrioritizationChar.png"&gt;&lt;span style="font-family:arial;"&gt;&lt;img style="WIDTH: 320px; CURSOR: hand" alt="" src="http://buildingsecurecode.googlepages.com/SecurityAssessmentPrioritizationChar.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;To use this chart, look at the ranking of the explicit dependency and then take the highest ranking of the implicit dependency (your application may use multiple pieces of data all ranked differently) to determine the assessment priority within the business objective bucket. So for instance, say you had a HIGH business objective, and in it you had two explicit dependencies. One ranked HIGH (Application X) and another ranked MEDIUM (Application Y). Say the highest implicit dependency that Application X uses is LOW, so if you look at ROW 1, COLUMN 3 you'll see that it has a PRIORITY 1 rating. Also say that Application Y's highest implicit dependency rates at MEDIUM as well, then by our chart (ROW 2, COLUMN 2) this application has a PRIORITY 2 rating. So our prioritization looks like this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;"For our high business objectives, Application X should be assessed before Application Y ..."&lt;br /&gt;&lt;br /&gt;That’s it! You now have a security assessment prioritization that closely aligns to the prioritization of your organization’s business objectives. So now when you go back to your boss, you can say “here’s a prioritized security assessment for this fiscal year, here’s how they align to our organization’s business objects and here’s why I need the $(some out of this world budget number) budget to pay &lt;/span&gt;&lt;a href="http://www.impactalabs.com/handlers/fwlink.aspx?linkid=00000&amp;amp;msg=Impacta"&gt;&lt;span style="font-family:arial;"&gt;Impacta LLC&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; to do those assessments for us :P”.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Making This Method Work for You&lt;br /&gt;&lt;/strong&gt;You’ll notice that my method is biased towards systems and applications than it is towards data. Does this mean that the data (say social security numbers) is less important than systems and applications? Not at all, the chart above just works well for organizations where availability is more important (think about organizations like eBay, Amazon, MSN, UPS etc.). Now if confidentiality and integrity is more important and the data is king in your line of business (perhaps you’re Experian, TransUnion, or the US Social Security Administration office, etc.) just switches data for the explicit dependencies, and systems/applications to implicit dependencies.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;In this article I showed you an easy way to create a prioritized listing of security assessments to do based on known and well-understood information about your organization. The resulting prioritization was closely aligned to business objectives and allows you to easily justify and explain how you came to that prioritization. The advantage about this method is that it’s lets you (the real expert of your organization) make the call on what is important and what’s not important, but now in a systematic, consistent and standard way. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Next steps are to actually conduct the security assessments and another advantage of the method we just discussed is that most of the data we collected here is the data needed to easily lead into most security assessments. So not only are we not re-inventing the wheel, we’re also streamlining our overall security assessment efforts. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In a later post, I’ll talk about the differences between common security assessment techniques such as &lt;/span&gt;&lt;a href="http://www.google.com/custom?q=penetration+tests&amp;amp;client=pub-8983727083147994&amp;amp;forid=1&amp;amp;ie=ISO-8859-1&amp;amp;oe=ISO-8859-1&amp;amp;cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A1&amp;amp;hl=en"&gt;&lt;span style="font-family:arial;"&gt;penetration tests&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; (rarely, but sometimes referred to as “ethical hacking”), &lt;/span&gt;&lt;a href="http://www.google.com/custom?hl=en&amp;amp;client=pub-8983727083147994&amp;amp;cof=FORID%3A1%3BGL%3A1%3BLBGC%3A336699%3BLC%3A%230000ff%3BVLC%3A%23663399%3BGFNT%3A%230000ff%3BGIMP%3A%230000ff%3BDIV%3A%23336699%3B&amp;amp;ie=ISO-8859-1&amp;amp;oe=ISO-8859-1&amp;amp;q=vulnerability+scanning"&gt;&lt;span style="font-family:arial;"&gt;vulnerability scanning&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; and &lt;/span&gt;&lt;a href="http://www.google.com/custom?hl=en&amp;amp;client=pub-8983727083147994&amp;amp;cof=FORID%3A1%3BGL%3A1%3BLBGC%3A336699%3BLC%3A%230000ff%3BVLC%3A%23663399%3BGFNT%3A%230000ff%3BGIMP%3A%230000ff%3BDIV%3A%23336699%3B&amp;amp;ie=ISO-8859-1&amp;amp;oe=ISO-8859-1&amp;amp;q=security+audits"&gt;&lt;span style="font-family:arial;"&gt;audits&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Notes From the Author&lt;br /&gt;&lt;/strong&gt;Feel free to let me know how this method worked for you either by leaving a comment with this article or at &lt;/span&gt;&lt;a href="mailto:info@impactalabs.com"&gt;&lt;span style="font-family:arial;"&gt;info@impactalabs.com&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;. Hey, who knows … with enough interest, maybe I’ll publish a tool that automates this process for you. Enjoy!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;--Kevin &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-1958101388723777778?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/eoMqzmPXg8E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/1958101388723777778/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=1958101388723777778" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/1958101388723777778?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/1958101388723777778?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2007/09/prioritizing-security-assessments-in-20.html" title="Prioritizing Security Assessments in 20 Minutes or Less!" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DkQDQXY_fyp7ImA9WB5UFU0.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-1246025989523963827</id><published>2007-08-18T20:23:00.001-07:00</published><updated>2007-08-18T23:19:30.847-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-08-18T23:19:30.847-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Testing" /><title>Security Code Scanning with Microsoft PREFast</title><content type="html">&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Overview&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Probably one of the most useful security tools to come out of Microsoft, yet the least known and adopted is the PREFast tool. PREFast is a static source code security scanner, or in other words, PREFast is a scanning tool that takes source code as input and returns a list of potentially vulnerable code that could create risks to you and your customers. In the case of PREFast it takes in C/C++ source code and analyzes that code for common coding defects. Security defects by the way are one of several types of defects this tool can detect, so with PREFast you get more than just security code scanning. Did I also mention it's free? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I knew that would get your attention and now that I have it, it's important to understand that PREFast won't solve all your security problems, no one or even a series of tools can (I'll talk about PREFast's limitations later). What it will get you is an objective, repeatable, low-cost risk control to enforce a baseline that you can include in your security development practices.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Are there other security code scanners we could use to scan C/C++ code? Sure, but the beauty of Microsoft's PREFast is you get an enterprise-strength security code scanner without the enterprise-strength price. &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="fullpost"&gt;&lt;span style="font-family:arial;"&gt;&lt;a href="http://www.google.com/custom?hl=en&amp;client=pub-8983727083147994&amp;amp;cof=FORID%3A1%3BGL%3A1%3BLBGC%3A336699%3BLC%3A%230000ff%3BVLC%3A%23663399%3BGFNT%3A%230000ff%3BGIMP%3A%230000ff%3BDIV%3A%23336699%3B&amp;ie=ISO-8859-1&amp;amp;oe=ISO-8859-1&amp;q=security+code+scanner"&gt;Show me other security code scanners.&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span class="fullpost"&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;In the rest of the article, I'll show you how to get PREFast, how to get started with it, and most importantly how to verify that it's working correctly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Getting Microsoft PREFast Step-By-Step&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;As useful as PREFast is, it's notoriously one of the hardest tools to find (this probably explains its low rate of adoption). PREFast is not available as a standalone download, and in order to get it you need download it as part of the latest Microsoft Windows Driver Kits (WDKs) which itself involves several steps that sadly deters most users. In this section of this article, I'll show you step-by-step how to get your hands on PREFast. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;Before we begin, you'll need a couple things: a DVD burner, a blank DVD-R disk and DVD burning software. Once you have the above ready, follow these steps to get the PREFast tool.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Go to &lt;a href="http://connect.microsoft.com/"&gt;Microsoft Connect website&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Sign in with your Microsoft Live ID account. If you don't have one you can &lt;a href="http://www.live.com/"&gt;sign up for one here&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Click &lt;a href="http://connect.microsoft.com/availableconnections.aspx"&gt;Available Connections&lt;/a&gt; on the left-side navigation bar.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Look for &lt;em&gt;Microsoft Windows Driver Kit (WDK) and Windows Logo Kit (WLK)&lt;/em&gt; link. Click &lt;em&gt;Apply&lt;/em&gt; if you haven't already done so before.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Fill out the registration screen details and click &lt;em&gt;Continue&lt;/em&gt;. &lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rse8EpvCcMI/AAAAAAAAACI/gB2OK8yMK0c/s1600-h/MicrosoftConnectRegistrationScreen.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100251891129020610" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rse8EpvCcMI/AAAAAAAAACI/gB2OK8yMK0c/s320/MicrosoftConnectRegistrationScreen.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; At this stage you should be signed-in and ready to download the appropriate WDK. To start, click the &lt;a href="https://connect.microsoft.com/default.aspx"&gt;Connect Home&lt;/a&gt; link on the upper left side navigation menu.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Click &lt;a href="https://connect.microsoft.com/myparticipation.aspx"&gt;My Participations&lt;/a&gt; also on the left side navigation menu. You should see a table to lists your available connections.&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rse8hpvCcNI/AAAAAAAAACQ/C8xCfOxtAFk/s1600-h/MyParticipationScreen.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100252389345226962" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rse8hpvCcNI/AAAAAAAAACQ/C8xCfOxtAFk/s320/MyParticipationScreen.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Click on the &lt;a href="https://connect.microsoft.com/site/sitehome.aspx?SiteID=148"&gt;Windows Logo Kit (WLK), Windows Driver Kit (WDK) and Windows Driver Framework (WDF)&lt;/a&gt; link. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; On the left hand side navigation menu, click &lt;em&gt;Download&lt;/em&gt;.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Select the appropriate WDK download for your operating system. For example, if you are using Vista, then select the &lt;a href="https://connect.microsoft.com/Downloads/DownloadDetails.aspx?SiteID=148&amp;amp;DownloadID=4606"&gt;Windows Driver Kit RTM (Vista)&lt;/a&gt;.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Click &lt;em&gt;Download&lt;/em&gt;, which starts the Microsoft File Transfer Manager, select a place to save the file and click the &lt;em&gt;Transfer&lt;/em&gt; button.&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rse9NpvCcOI/AAAAAAAAACY/dW9upQg6AYY/s1600-h/MicrosoftFileTransferManager.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100253145259471074" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rse9NpvCcOI/AAAAAAAAACY/dW9upQg6AYY/s320/MicrosoftFileTransferManager.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 12:&lt;/strong&gt; With luck, the transfer should start and once that's done you should have one very large ISO (short for disk image of an ISO 9660 filesystem) file. From here you can use any DVD disk burning software to write the ISO filesystem back onto a DVD disk. After that's done, run the install disk on the machine you wish to install PREFast onto.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 13:&lt;/strong&gt; Install the WDK. PREFast automatically gets installed with the main build environment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://3.bp.blogspot.com/_c6yObubzWd0/Rse9j5vCcPI/AAAAAAAAACg/jPo9zorNI1k/s1600-h/WDKInstall.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100253527511560434" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_c6yObubzWd0/Rse9j5vCcPI/AAAAAAAAACg/jPo9zorNI1k/s320/WDKInstall.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 14:&lt;/strong&gt; Open up a build environment and verify that PREFast was installed correctly. To do this, press the Start Button, then Programs and look for the &lt;strong&gt;Windows Driver Kits&lt;/strong&gt; folder. Click on this folder, then click on the folder &lt;strong&gt;WDK 6000&lt;/strong&gt;, then click on the folder &lt;strong&gt;Build Environments&lt;/strong&gt; and then click on your target operating system. For instance, if I am developing an application for Vista, then I'll want to click on the &lt;strong&gt;Windows Vista and Windows Server Longhorn&lt;/strong&gt; folder. Finally choose the target build environment and a MS-DOS style command prompt should open. For example, if I want to develop for Windows Vista 32 bit, I would select &lt;strong&gt;Windows Vista and Windows Server Longhorn x86 Free Build Environment&lt;/strong&gt; shortcut.&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rse-NpvCcQI/AAAAAAAAACo/Oy8BQP2jA6E/s1600-h/PREFastSTartFolder.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100254244771098882" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rse-NpvCcQI/AAAAAAAAACo/Oy8BQP2jA6E/s320/PREFastSTartFolder.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 1,000,000:&lt;/strong&gt; We're finally at the last step and that is to verify that PREFast installed and is running correctly. To do this, just type &lt;strong&gt;prefast&lt;/strong&gt; then Enter and you should see something like the following:&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_c6yObubzWd0/Rse_NZvCcSI/AAAAAAAAAC4/eDO5MUab5SE/s1600-h/PREFastVerifyInstall.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100255339987759394" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_c6yObubzWd0/Rse_NZvCcSI/AAAAAAAAAC4/eDO5MUab5SE/s320/PREFastVerifyInstall.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;Fortunately we only have to do these steps once, and that we have PREFast installed and running, it's time to run it against some actual code. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Using PREFast&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;Now that we have PREFast installed and running on our system, let's give it a test run with some actual bad code. I've gone ahead and created &lt;a href="http://buildingsecurecode.googlepages.com/PREFastExample.zip"&gt;some example vulnerable code for our discussion here&lt;/a&gt;. In the example pack you find an example of a strcpy buffer overrun (lines 13-22) and a format string vulnerability (lines 32-35), a make file and a sources file.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;To use PREFast, we need to call on top of our compiler. The reason why this is is because PREFast works by "intercepting" calls to the compiler to determine if the code being compiled contains known defects. To do this simply open a build environment window (see Step 14 above), unpack the example files into a directory and from that directory type:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;prefast build -cZ &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;The argument -cZ tells the build command to delete any previous object files (c) and not to check any dependencies (Z). After you give this command, PREFast kicks off, invokes the build command to start building our examples and after a small amount of time you should see something like this: &lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;a href="http://4.bp.blogspot.com/_c6yObubzWd0/RsfDfJvCcUI/AAAAAAAAADI/Itt07Ki1JPc/s1600-h/PREFastRunning.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100260042976948546" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_c6yObubzWd0/RsfDfJvCcUI/AAAAAAAAADI/Itt07Ki1JPc/s320/PREFastRunning.png" border="0" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;To view the results we have two options. View the results through the command line or via a graphical user interface (GUI). To view the results over the command-line, type:&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;prefast list&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_c6yObubzWd0/RsfHw5vCcXI/AAAAAAAAADg/Lecl2O3UspE/s1600-h/PREFastList.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100264745966137714" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_c6yObubzWd0/RsfHw5vCcXI/AAAAAAAAADg/Lecl2O3UspE/s320/PREFastList.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To view the results via the GUI, type:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;prefast view&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_c6yObubzWd0/RsfFJ5vCcVI/AAAAAAAAADQ/osjdf8qsclI/s1600-h/PREFastGUI.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100261876927983954" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_c6yObubzWd0/RsfFJ5vCcVI/AAAAAAAAADQ/osjdf8qsclI/s320/PREFastGUI.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;From the GUI you can double-click on the defect messages and it'll nicely highlight for you the area of code that generated the error and a little explanation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At times you might see lots of defects and you can filter out only the ones you care about by pressing the filter button at the top of the GUI box and selecting the appropriate filters to view. After you've selected the desired defects, hit Apply and the GUI will trim the results to only the ones you care about.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_c6yObubzWd0/RsfFXJvCcWI/AAAAAAAAADY/MDCcNWc5k0A/s1600-h/PREFastFilter.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100262104561250658" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_c6yObubzWd0/RsfFXJvCcWI/AAAAAAAAADY/MDCcNWc5k0A/s320/PREFastFilter.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's it. That was the quick-and-dirty-get-you-up-and-running-now-without-having-to-ready-20-pages-of-documentation introduction to using PREFast! For most users this should be more than enough, but you want more Microsoft has published a &lt;a href="http://download.microsoft.com/download/5/d/6/5d6eaf2b-7ddf-476b-93dc-7cf0072878e6/PREfast_steps_21.doc"&gt;more detailed step-by-step guide to using PREFast&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Verifying PREFast Scans&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There's an old saying in management that goes something like this: if you can't measure it, it never happened. The same goes with code scanning: if you can't verify that the scan ran correctly or at all, it pretty much never happened. I know of one development team that learned this lesson the hard way, actually make that the very hard way. This team was nearing the planned release date of their product and decided to do some last minute due diligence with a security code scanner. Great, and good for them! The team however accidentally ran the code scanner with all checks turned off and so with a false clean bill of health from the scanner the product was released soon after. Not so great. Security researchers, good and bad, jumped all over the product and automated exploits soon followed. Sadly, careers were made (and some ruined) all at the expense of hacked customers.&lt;br /&gt;&lt;br /&gt;Situations like these can be easily avoided. One trick that I use is to temporarily sprinkle the code bases that I am scanning with code that I know is:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Vulnerable and &lt;/li&gt;&lt;li&gt;Can be easily detected. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you're one of my customers, you sometimes might hear me refer to it as beacon code, but the idea is if the code scanner, not just PREFast, doesn't pick up these little beacon code snippets then you know that the scanner is not operating properly. If the code scanner picks it up, then you know that scanner is working correctly and you have at least some level of assurance that the tool ran correctly (that sound you're hearing in the distance is the sound of all the security managers around the world like myself cheering). &lt;/p&gt;So what does vulnerable beacon code look like? &lt;a href="http://buildingsecurecode.googlepages.com/BSC_Beacon.c"&gt;Here's the code I use when am doing C/C++ security assessment work for my customers&lt;/a&gt;. The beacon code is actually an off-by-one buffer overrun (explanation is in the code itself).&lt;br /&gt;&lt;br /&gt;Add this code to as one of the sources (modify the sources file) to compile during code scan runs. It's important that you only include the beacon code during code scans and remove it right after, because if you leave it there some developer may mistakenly reference that code and now we've increased our risk. Granted off-by-one overruns are generally harder to exploit. That doesn't mean it's impossible by why take chances right? Run prefast again and you should see an error message corresponding to our beacon code pop-up.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/RsfJcpvCcYI/AAAAAAAAADo/5jCaLWY7d1A/s1600-h/PREFastBeacon.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5100266597097042306" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/RsfJcpvCcYI/AAAAAAAAADo/5jCaLWY7d1A/s320/PREFastBeacon.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And we're done! We've now verified that PREFast is indeed working and scanning the code!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Before we end our discussion of PREFast, it's important to highlight a couple important points about PREFast so that you know exactly what you are and aren't getting with this tool.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;PREFast is not the best code scanning tool.&lt;/strong&gt; In fact none of the tools available today or in the future are. The question you should be asking is "what are my organization's security requirements, and which tool best meets those requirements?". It's always important to first define those requirements otherwise you have no idea if the tool you're using is adding value or just wasting time. The tool (or tools) that matches those requirements best is the best tool for your organization. PREFast happens to match Microsoft security requirements, but may not necessarily match yours. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;PREFast is just a tool.&lt;/strong&gt; It can and should be used as part of any security process, but it should not be used as a replacement. I like to think of PREFast as steering wheel and a security process as a car. By itself, the steering wheel doesn't make a car, but without it the car won't function very well either.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;PREFast is just a tool, part 2.&lt;/strong&gt; PREFast and any other scanning tool can only detect what it's been designed to detect. So even if PREFast is gives you a clean report and you've verified that it's working you code might still be infested with defects. Hint: did you notice that in our PREFast there was no mention of a format string vulnerability? That's why we mitigate this particular risk with other controls such as expert analyst code review, penetration testing, etc. in case this particular control fails or is inadequate.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;PREFast can be used as a good measuring (and beat) stick.&lt;/strong&gt; If you're building out a security process and you want to first see how well or bad your organization is doing, PREFast is a good way to do that quickly. If you're a little further along and have a security development process and baselines established already, then PREFast is a good way to check and enforce those baselines in an objective, repeatable and efficient way.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;strong&gt;PREFast provides a snapshot at one point in time only.&lt;/strong&gt; PREFast will give you a snapshot of the security posture of your code base at one point in time. As soon as someone adds or removes code from that code base, those results are obsolete and scans need to be redone. If PREFast or other code scanning tools are included in your code release criteria, make sure you're working off the most accurate and up-to-date data!&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With that, happy scanning!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;-Kevin&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-1246025989523963827?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/Tdql1cV77YE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/1246025989523963827/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=1246025989523963827" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/1246025989523963827?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/1246025989523963827?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2007/08/security-code-scanning-with-microsoft.html" title="Security Code Scanning with Microsoft PREFast" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_c6yObubzWd0/Rse8EpvCcMI/AAAAAAAAACI/gB2OK8yMK0c/s72-c/MicrosoftConnectRegistrationScreen.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">5</thr:total></entry><entry gd:etag="W/&quot;C0MCRng8eSp7ImA9WB5SF0o.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-2428498089079886244</id><published>2007-06-12T14:20:00.000-07:00</published><updated>2007-06-13T14:51:07.671-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-06-13T14:51:07.671-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Testing" /><category scheme="http://www.blogger.com/atom/ns#" term="Architecture and Planning" /><category scheme="http://www.blogger.com/atom/ns#" term="Requirements and Analysis" /><title>Keeping Malicious Hackers at Bay: Approaches to Input Validation</title><content type="html">&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In our everyday lives we are constantly validating ‘things’. For instance, before we drink water from a bottle, we make sure that the seal is intact before drinking it. That way we help ensure that by drinking that water we don’t have undesired effects like sickness in our bodies later on. When I go to my favorite Indian restaurant here in the Seattle area, I always verify with the waiter/waitress that my meal is at the lowest level of spice to ensure that it doesn’t have an undesired effect on my body later on (grin). We are constantly validating things in the real-world. Unfortunately in the digital world we aren’t as diligent, and where we are the wrong technique is being employed. As a result malicious hackers are able to do nasty things like steal millions of credit card numbers and compromise our networks.&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;Performing proper and well-placed input validation are absolutely critical first steps in keeping the bad guys out of your enterprise systems, enterprise networks, and especially away from your organization’s sensitive information. While the idea of validating input itself is intuitive and straight forward, properly implementing an input validation strategy however can be hardly that. Without a sound understanding and strategy to validating input, enterprises can spend resources on control mechanisms that are flawed and create a false sensitive of security (arguably worse than not validating input at all). In this article, I’ll show you different approaches on how to validate inputs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Approaches to Input Validation &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Step back into the real-world for a moment. Say we wanted to make sure that a can of soda (input), like Coke or Pepsi, was safe to drink before consuming it into our bodies (system). What are the some of the cues or indicators that would help ensure that can of soda was not tampered with and indeed safe to drink? For starters, you could inspect the can itself for puncture marks to ensure that the can has not been tampered with after leaving the factory. You could also listen for cues like the crack of the lid and the quick wisp of gas being released when you open the can. Any one of these cues help us verify that the drink is safe to consume, and in the digital world there also exists cues or factors that help us verify that input from potentially untrusted sources are safe to consume into our systems. They include:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Type.&lt;/strong&gt; This factor indicates the kinds of input you are expecting from your users. For instance, are you expecting just numbers (0-9) as in the case of credit numbers (i.e. 1234-1234-1234-1234) or letters like the ones used in country abbreviations (i.e. CA or US)?&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Length.&lt;/strong&gt; This factor indicates the amount of data we are expecting. For instance, if the input we are expecting to get is a credit card number, then we can expect the length to be 16 digits.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Format.&lt;/strong&gt; This factor indicates how the data is expected to be arranged. For instance, zip codes in the United States are typically 5 digits so we could use say the expected format is five consecutive digits. Postal codes in Canada however look like this M1P2X3 so we could say the expected format is an uppercase alphabet character followed by a digit, repeated 3 times.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Range.&lt;/strong&gt; This factor indicates the upper and/or lower bounds of the input we are expecting. For instance we could say that we expect alphabetic characters, but only vowels. &lt;/li&gt;&lt;/ul&gt;The more of the above factors you can incorporate into your input validation strategy, the more robust and resilient to attack it will be. How we utilize these represent our input validation approach and in general there are two key approaches you can use:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Black-List Technique.&lt;/strong&gt; The black-list technique is sometimes referred to as the Principle of Exclusions and works by first defining a set of unacceptable or bad inputs into a system. It then checks any input into a system to see if it matches any of those unacceptable input patterns defined earlier in the ‘bad’ set. If a match is found, then the input is considered malicious or a possible threat and rejected. If a match is not found, then the input is assumed to be valid and consumed by the system. I placed emphasis on the word assumed on purpose because as we’ll see later in our discussion I’ll show you how an attacker can circumvent the black-list technique and why this technique should be avoided whenever possible.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;strong&gt;White-List Technique.&lt;/strong&gt; The opposite of the black-listing technique is the white-listing technique. This technique (or sometimes referred to as the Principle of Inclusions) validates inputs into a system by first defining a set of acceptable inputs or expected inputs. It then tries to match any input into that system against the set of acceptable inputs. If a match is found, then the input is valid and the system continues to use or consume that input. Now, if a match is not found, that is the input is not contained in the valid set, then the input must be part of the unacceptable set and therefore is considered a possible threat to the system and rejected.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8PJKf49iI/AAAAAAAAABI/_l9t5PBURtA/s1600-h/whitelistblacklist.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075291955181188642" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8PJKf49iI/AAAAAAAAABI/_l9t5PBURtA/s320/whitelistblacklist.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Choosing the Correct Input Validation Technique&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;We’ve just discussed the inner workings of the black-list and white-list techniques to validating input. What has eluded our discussion so far is the answer to the question of which of the two input validation techniques should we use? I alluded to the answer before, but in case you missed it in general you should use the white-list technique and avoid the black-list technique whenever possible. Here’s why:Our challenge really is being able to reliably tell if an input into a system is good or bad (an attack to the system). Let’s take a look at the two input validation techniques and see how reliably we can make this conclusion.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;We’ll start with the white-list technique. Recall that the white-list technique defines the set of all acceptable inputs to a given system. The set of all acceptable inputs into a system is known and can be concisely defined, that is you could write down everything in this set if you had to. Sure, that set could be very large, but it has a limit and is therefore finite. Since we’re able to map out a complete acceptable set a developer can easily take any input and reliably make the conclusion that if the input does not exist in the acceptable set, it therefore must be part of the unacceptable set and should be rejected. From a scalability perspective, this technique is easy to implement.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This conclusion about the validity of input however cannot be easily or reliably made using the black-list technique. Recall that the black-list technique works in the opposite fashion as the white-list technique, that is it defines the set of all unacceptable inputs (or possible attack inputs) into a given system. The problem here is that we can’t be sure that our unacceptable set is complete because we can’t predict all the possible actions or inputs from an attacker. We could reasonably predict the likely actions, but not all which still leaves us short of a complete set. The unacceptable set is in actuality infinitely large and therefore by definition it is impossible to define all the possible bad inputs into a system. So if a developer tries to make a conclusion about the validity of some input by saying since this input doesn’t exist in the (incomplete) unacceptable set it must be a valid input they’re in hot water. This is because if they (very likely) miss even a single bad input in his or her black-list set then the attacker can mask their attack as a valid input circumventing the security control entirely. I don’t want to mislead and leave you with the impression that the black-list technique is absolutely horrible and should be avoided like the plague, but it’s very difficult to implement correctly. Even if you were able to get your black-list to work in 99% of the cases, if the attacker is able to find the 1% case where it fails, all you’ve really achieved is 100% failure.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_c6yObubzWd0/Rm8Pn6f49jI/AAAAAAAAABQ/Ju3qgNSjH8k/s1600-h/whitelistblacklistfiniteinfinite.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075292483462166066" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_c6yObubzWd0/Rm8Pn6f49jI/AAAAAAAAABQ/Ju3qgNSjH8k/s320/whitelistblacklistfiniteinfinite.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Let’s take a look at an example to illustrate these two important properties of the white-list and black-list technique. The source code for the example is available for download at the end of the article. In our example below, we’ve created program that asks the user to enter in a color. If the color entered is a primary color (red, blue or yellow) then the program will indicate that it is a primary color otherwise that it is not a primary color.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8QYKf49kI/AAAAAAAAABY/ytol1vVq3Fc/s1600-h/primarycolortester.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075293312390854210" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8QYKf49kI/AAAAAAAAABY/ytol1vVq3Fc/s320/primarycolortester.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Our goal as the attacker is to trick this program to saying that a color we entered in is a primary color when really it isn’t.Using the white-list technique our &lt;a href="http://buildingsecurecode.googlepages.com/whitelistcode.txt"&gt;example .NET (C#) validation code might look like this&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;With the white-list technique we defined the colors RED, BLUE, and YELLOW as our acceptable list of inputs. Anything that the user (or attacker) enters that isn’t contained in this list is automatically recognized as non-primary and rejected. Hooray, our program works correctly!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8QoKf49lI/AAAAAAAAABg/wM-7Tk4qwvY/s1600-h/whitelistsuccess.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075293587268761170" style="CURSOR: hand" alt="" src="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8QoKf49lI/AAAAAAAAABg/wM-7Tk4qwvY/s320/whitelistsuccess.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now let’s see what happens when we modify our program to use the black-list technique. The &lt;a href="http://buildingsecurecode.googlepages.com/blacklistcode.txt"&gt;example validation .NET (C#) code would look something like this&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;If an attacker tries to enter in a non-primary color that exists in our black-list, the program correctly recognizes the input as not a primary color. However what happens if the attacker enters in a color that is not in our black-list, but also isn’t a primary color either like ‘puce’? Our program incorrectly concludes that ‘puce’ is a primary color and reports it as one. If this was a real-life scenario with security implications, we’d be sunk so clearly we want to avoid the black-list technique whenever possible.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_c6yObubzWd0/Rm8Q5af49mI/AAAAAAAAABo/1z1D8ey3rto/s1600-h/blacklistfailure.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075293883621504610" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_c6yObubzWd0/Rm8Q5af49mI/AAAAAAAAABo/1z1D8ey3rto/s320/blacklistfailure.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Exceptions to the Rule: When White-Listing Fails&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Earlier I said in general we want to use the white-list technique and avoid the black-list technique; however there will be scenarios where the white-list technique is not sufficient or applicable. This is especially so in situations where input factors such as the type, length, format or ranges are not known ahead of time. For instance, one of our customers that we were helping had a common scenario where users could enter in a description of their entry.&lt;br /&gt;&lt;br /&gt;The description would be posted back on a web page and would be susceptible to potential &lt;a href="http://en.wikipedia.org/wiki/XSS"&gt;cross-site scripting (XSS)&lt;/a&gt; attacks. We don’t know what the user will enter in ahead of time so white-listing is out the door. In this instance we used a concept called defense-in-depth which I’ll write about later to mitigate the overall risk. Briefly, the general idea behind defense-in-depth is you utilize several layers of defense to reduce the probability of some attack from succeeding. For instance, a defense-in-depth approach might be to use input validation as one layer of defense, but also implement another. In our description box scenario we used the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.configuration.pagessection.validaterequest.aspx"&gt;ASP.NET page request validation&lt;/a&gt; at the server as one layer, and the &lt;a href="http://msdn2.microsoft.com/en-us/security/aa973814.aspx"&gt;Microsoft Anti-Cross Site Scripting Library V1.5&lt;/a&gt; that I published when I was at Microsoft as another layer to significantly reduce the probability that a XSS attack would successfully occur.&lt;br /&gt;&lt;br /&gt;There are scenarios where black-listing can be used effectively along with the white-list technique. For instance, white-listing can be implemented using regular expressions (I’ll be discussing this in a later article). One downfall of regular expressions can be that they can be slow if the regular expression is not optimized or excessively large which can lead to overall performance degradation. If there are certain inputs that you know should not be accepted by a system (black-list) you can check for those inputs before incurring the cost of the regular expression (white-list).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;As layers within the enterprise such as the network and host layer become more and more secure, attackers are switching their focus to the application layer, which as of the time of this article continues to be the most neglected and least secured enterprise layer. Failing to validate input from untrusted sources leaves applications in vulnerable states that allow attackers to do things such as stealing credit card information, compromise networks and bring down critical services. What’s worse, failing to properly validate input from untrusted sources continues to leave applications and enterprise systems in vulnerable states, but also with a false sense of security amongst business owners and customers.In this article I discussed different approaches to validating input from untrusted sources, in particular using the white-list and black-list techniques. Unfortunately, knowing the approaches to input validation is one third of the entire story. Business owners still need to understand approaches to when to validate input and what input to validate which will be the topic of future posts.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Downloads&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://buildingsecurecode.googlepages.com/primarycolortester.zip"&gt;PrimaryColorTester.zip&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-2428498089079886244?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/udCtaSAJZw4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/2428498089079886244/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=2428498089079886244" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/2428498089079886244?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/2428498089079886244?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2007/06/keeping-hackers-at-bay-approaches-to.html" title="Keeping Malicious Hackers at Bay: Approaches to Input Validation" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_c6yObubzWd0/Rm8PJKf49iI/AAAAAAAAABI/_l9t5PBURtA/s72-c/whitelistblacklist.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></entry><entry gd:etag="W/&quot;CUUFR34yeip7ImA9WB5SF0o.&quot;"><id>tag:blogger.com,1999:blog-5941784894271123575.post-3472113431025849201</id><published>2007-06-12T13:33:00.000-07:00</published><updated>2007-06-13T15:20:16.092-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-06-13T15:20:16.092-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Testing" /><category scheme="http://www.blogger.com/atom/ns#" term="Architecture and Planning" /><title>How to Display the UAC Shield Icon inside .NET</title><content type="html">&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;When deploying enterprise applications and desktop systems, information technology (IT) administrators are often presented with the challenge of maintaining computer security while still enabling business productivity (usability) – traditionally two opposing forces. If systems and users were deployed in highly secure locked-down states, productivity would typically suffer because applications would cease to function properly in the absence of administrative privileges. In the other direction, if administrators opted for higher usability by granting end-users administrative privileges, systems became highly exposed to the effects of malware that could perform malicious actions such as stealing personal information and making unauthorized system changes. To make matters worse, IT administrators really didn’t have an easy way to balance the two requirements and often resorted to a one-or-the-other approach.&lt;/span&gt;&lt;br /&gt;&lt;span class="fullpost"&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Enter the Microsoft Windows User Account Control (UAC) feature in Microsoft Windows Vista . With UAC IT administrators can easily deploy applications and service components with limited privileges (security) while still maintaining the ability to perform elevated tasks (usability) whenever needed.&lt;br /&gt;More information about the features and benefits of UAC can be found at &lt;/span&gt;&lt;a href="http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx"&gt;&lt;span style="font-family:arial;"&gt;http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;One of the most visible features with UAC is the introduction of “elevated shield icon” decorated buttons that help users to identify actions and applications that require elevation. Take for example the task of changing the local system time on a Microsoft Windows Vista system which requires administrative privileges. Microsoft Windows Vista now indicates this requirement by displaying an elevated shield icon-decorated button in the date and time adjustment dialog.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_c6yObubzWd0/Rm8EFaf49fI/AAAAAAAAAAw/YrR_P3U2Zbg/s1600-h/figure-1-date-and-time-settings-dialog-with-undecorated-and-decorated-elevated-shield-icon-buttons.png"&gt;&lt;span style="font-family:arial;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075279796128773618" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_c6yObubzWd0/Rm8EFaf49fI/AAAAAAAAAAw/YrR_P3U2Zbg/s320/figure-1-date-and-time-settings-dialog-with-undecorated-and-decorated-elevated-shield-icon-buttons.png" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This article shows how .NET developers can enable the same visual cues in their own Microsoft Windows Vista forms-based applications.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Decorating Windows Application Form Buttons with the Elevated Shield Icon in .NET&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In unmanaged code (C/C++), there are several way that you could decorate a button with the elevated shield icon. The first method is to use the &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa361911.aspx"&gt;&lt;span style="font-family:arial;"&gt;Button_SetElevationRequiredState&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; macro and the second method is to send the &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa361904.aspx"&gt;&lt;span style="font-family:arial;"&gt;BCM_SETSHIELD&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; message to the target button control handle. If you take a look under the hood and install the &lt;/span&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c2b1e300-f358-4523-b479-f53d234cdccf&amp;displaylang=en&amp;amp;Hash=NVPGqF6KwIvjcKzaPzsMGOLLN8HqgVMVbx5Hv83zU22SMGxI59n6XOVHZWYlPt%2fg8pTqscSRhznVSMSSULwmhA%3d%3d"&gt;&lt;span style="font-family:arial;"&gt;Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Components&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt;, inside the file CommCtrl.h at line 7900 you’ll find the follow declaration for the Button_SetElevationRequiredState macro: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;#define Button_SetElevationRequiredState(hwnd, fRequired) (LRESULT)SNDMSG((hwnd), BCM_SETSHIELD, 0, (LPARAM)fRequired) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;As we can see, the Button_SetElevationRequiredState macro really just calls &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms644950.aspx"&gt;&lt;span style="font-family:arial;"&gt;user32.dll!SendMessage&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:arial;"&gt; with the BCM_SETSHIELD message. So in the coming example we’ll decorate a button control with an elevated shield icon from within managed code (specifically C#) using only the BCM_SE&lt;span style="font-family:arial;"&gt;TSHIELD message method. A link to the sample code is provided at the end of this article. &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_c6yObubzWd0/Rm8Efqf49gI/AAAAAAAAAA4/HpkiUsaktl4/s1600-h/figure-2-sample-application-with-undecorated-button-control.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075280247100339714" style="CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_c6yObubzWd0/Rm8Efqf49gI/AAAAAAAAAA4/HpkiUsaktl4/s320/figure-2-sample-application-with-undecorated-button-control.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;BCM_SETSHIELD Message MethodExposing the nuts and bolts behind the Button_SetElevationRequiredState macro gives us some useful information about how to use the BCM_SETSHIELD method successfully. A couple things need to happen before we can successful decorate our example button:&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;ul&gt;&lt;li&gt;The target button control’s handle must be passed as the 1st argument to user32.dll!SendMessage. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;The correct BCM_SETSHIELD value must be passed as the 2nd argument to user32.dll!SendMessage. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;The value 0 must be passed as the 3rd argument to user32.dll!SendMessage. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;A pointer to a Boolean true value must be passed as the 4th argument to user32.dll!SendMessage. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;The target button control’s .FlatStyle member needs to be set to the system style. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;The function user32.dll!SendMessage must be called from within our C# code. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Sounds like a colossal pain to implement, but it’s really not. &lt;a href="http://buildingsecurecode.googlepages.com/enableelevateicon_bcm_setshield.txt"&gt;Click here to see the code that does the above.&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;Now to decorate our example button control, we simply need to pass button control as the argument and our handy little EnableElevateIcon_BCM_SETSHIELD method takes care of the rest:&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://1.bp.blogspot.com/_c6yObubzWd0/Rm8FG6f49hI/AAAAAAAAABA/ZMGeOf7a6pk/s1600-h/figure-3-sample-application-with-elevated-shield-icon-decorated-button-control.png"&gt;&lt;img id="BLOGGER_PHOTO_ID_5075280921410205202" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_c6yObubzWd0/Rm8FG6f49hI/AAAAAAAAABA/ZMGeOf7a6pk/s320/figure-3-sample-application-with-elevated-shield-icon-decorated-button-control.png" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;In this article we looked at how we could use the BCM_SETSHIELD message along with .NET P/Invokes to programmatically decorate Windows Vista forms application buttons with elevated shield icons. &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;"&gt;While visual cues are helpful, developing applications to be UAC compliant however involves much more than just decorating buttons – there’s considerations such as file system virtualization, registry virtualization, over-the-shoulder (OTS) credentials, proper elevation methods and application manifests that developers need to consider. To learn more about these UAC aspects, please refer to the additional resources and references section.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;Downloads&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:arial;"&gt;&lt;a href="http://buildingsecurecode.googlepages.com/uacelevatedshieldiconsample.zip"&gt;UACElevatedShieldIconExample.zip&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Additional Resources/References &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa480150.aspx"&gt;Developer Best Practices and Guidelines for Applications in a Least Privileged Environment&lt;/a&gt; &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;a href="http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx"&gt;User Account Control Overview&lt;/a&gt; &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c2b1e300-f358-4523-b479-f53d234cdccf&amp;displaylang=en&amp;amp;Hash=NVPGqF6KwIvjcKzaPzsMGOLLN8HqgVMVbx5Hv83zU22SMGxI59n6XOVHZWYlPt%2fg8pTqscSRhznVSMSSULwmhA%3d%3d"&gt;Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components&lt;/a&gt; &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:Arial;"&gt;&lt;a href="http://technet.microsoft.com/en-us/windowsvista/aa905108.aspx"&gt;Windows Vista: User Account Control&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5941784894271123575-3472113431025849201?l=buildingsecurecode.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/BuildingSecureCode/~4/hBHsLVacetQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://buildingsecurecode.blogspot.com/feeds/3472113431025849201/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=5941784894271123575&amp;postID=3472113431025849201" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/3472113431025849201?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/5941784894271123575/posts/default/3472113431025849201?v=2" /><link rel="alternate" type="text/html" href="http://buildingsecurecode.blogspot.com/2007/06/how-to-display-uac-shield-icon-inside.html" title="How to Display the UAC Shield Icon inside .NET" /><author><name>Kevin Lam (Impacta LLC)</name><uri>http://www.blogger.com/profile/03009075956040877878</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="07743765591236649423" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_c6yObubzWd0/Rm8EFaf49fI/AAAAAAAAAAw/YrR_P3U2Zbg/s72-c/figure-1-date-and-time-settings-dialog-with-undecorated-and-decorated-elevated-shield-icon-buttons.png" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></entry></feed>
