This project is read-only.

The insides of CATScan

How does CATScan work?

In three steps,
  1. Each build calls CAT.NET tool as an MsBuild task.
  2. CAT.NET scans all the binaries built by Team Build to produce a security code review report in xml and html format.
  3. Custom console application uses WSS List web service to upload the security code review scan report file(s) to the Team portal belonging to the Team Project.

What modifications are required on Team Build?

Visual Studio Team Build targets file Microsoft.TeamFoundation.Build.targets is called whenever a build is executed in Team Build.
  • This file is injected with the CAT.NET task information for calling like this
_<!-- Cat.Net declarations--->
<UsingTask TaskName="CatNetScan" AssemblyFile="$(ProgramFiles)\Microsoft\Cat.Net\TeamBuildCATNET.dll"/>_
* *EnableSecurityAnalysis* flag is used to check if CAT.NET scanning is turned *on*. This variable can be set from each TFSBuild.proj file and modifying this targets file is not essential.
_<!--Security Code analysis check-->
* I then override the AfterDropBuild target with the conditional check for EnableSecurityAnalysis flag to call the CAT.NET task
<!-- Override the target *AfterDropBuild* to execute custom tasks after copying files to the drop location -->
Condition=" '$(EnableSecurityAnalysis)'=='true' "
Directories="$(DropLocation)\$(BuildNumber)\Reports" />
Message="Creating Reports folder"
Status="Succeeded" />
<CatNetScanFiles Include="$(DropLocation)\$(BuildNumber)\**\*.dll;$(DropLocation)\$(BuildNumber)\**\*.exe" />
Message="Calling Cat.Net"
<Output TaskParameter="Id" PropertyName="StepId"/>
Message="Cat.Net scan"
Status="Succeeded" />
<OnError ExecuteTargets="MarkBuildStepFailed"/>
<Target Name="MarkBuildStepFailed" >
Message="Cat.Net scan failed"
Status="Failed" />
There is not much up there although you may see a large number of statements. To break it up:
  • I use built in task MakeDir to create a Reports folder in the drop share to copy all the CATScan report files. This is not essential but just neater so the reports are available on the drop share as well as WSS. There is some logic here which I will explain later.
  • Next I collect all the binaries i.e. exe and dlls from the drop location folder in an itemgroup CatNetScanFiles,
  • Setup CAT.NET configuration paramters using PropertyGroup and
  • Call CatNetScan task with the relevant config parameters.
  • I also use a series of BuildStep tasks for tracking the status of each task so there is a visible indication of each task executing in the build summary screen in VSTFS client.

What does the WSSLists console application look like?
Finally, I call a custom console application WSSLists.exe which is nothing but a simple wrapper to call the TFS WSS lists.asmx
  • MSDN Webcast: Software Security with Static Code Analysis Using CAT.NET (Level 200)
  • AntiXSS Library V3.0 - this is the proposed solution for most of the problems reported by CAT.NET

    Use the above script to get your Team Build to scan all your code and report your findings. Let me know if you encounter any issues. The full source code with complete working sample will be uploaded shortly.

  • Last edited Apr 13, 2010 at 6:13 AM by yogz, version 2


    No comments yet.