Saturday, 9 June 2012

Using/Consuming Cat.Net's engine inside the O2 Platform (and outside VisualStudio)

A key component of the Real time Vulnerability Scanning using Cat.Net and Roslyn (SAST) PoC is the 'Real Time' part :)

The only way to achieve that type scanning speeds was to find a way to directly consume (i.e. access) Cat.Net scanning engine directly (i.e. in-process), instead of the command line (this will also be critical when we try to scan large projects, which will need to sliced, partially scanned and have its results glued/merged).

The document below shows how I did that and the evolution of the scripts.

Note that by these techniques, we have access to the entire Cat.Net scanning engine and can easily control its rules and execution workflow :)

In addition to the sheer fast-prototyping/development speed that we get with O2's REPL Scripting environment, one the key advantages of doing this type of development on top of the O2 Platform is the number of Static-Analysis-focused tools/APIs that already exists. For example note how I was able to easy consume/transform the Cat.Net findings into O2Findings (which can then be consumed/manipulated by the multiple O2Finding's viewers and tools)

asd

Using Roslyn to Load and (quickly) Compile C# Solution files (outside VisualStudio)

Now that we can use Roslyn to compile (and create assemblies) in real-time the next step is to use it to open up and consume C# Solution files (something that I've always wanted to do properly without needing to use VisualStudio or deal with the xml format used by the *.sln files).

Friday, 8 June 2012

Weird Roslyn.Utilities.SerializableDataStorage casting issue when using new version

While writing a couple Roslyn scripts I started having a weird problem when consuming the June 2012 CTP dlls.

I was having the exception:

Unable to cast transparent proxy to type 'Roslyn.Utilities.SerializableDataStorage'. Unable to cast transparent proxy to type 'Roslyn.Utilities.SerializableDataStorage'.

Wednesday, 6 June 2012

Video: Real time Vulnerability Scanning using Cat.Net and Roslyn (SAST)

Here is a pretty cool PoC of creating an environment for developers that helps them to know when they create a security vulnerability (in real time).

Monday, 4 June 2012

Video: Using O2's Roslyn-based C# REPL Script environment

Roslyn is a new Microsoft's C# compiler written in C# (with also a VB flavour)

It is actually quite a spectacular piece of technology and in a way there is a LOT of similarities between the REPL environment I created in the O2 Platform and the one Roslyn is trying to do. In fact I'm thinking of moving some of O2's scripting capabilities from the current SharpDevelop parser to this new Roslyn one since their object model seems to be MUCH more powerful (of course that I'm bias, but I think that the O2's REPL environment as a couple killer features missing in current version of Roslyn REPL, so let's create the best-of-both-worlds REPL environment :) )

I've started using Roslyn in O2, and the first thing to do was to create an REPL environment which you can see in action in this video.



I am documenting the 'scripts evolution' (as drafts), and here are two I just created:
I think there is HUGE potential with this technology, and one area that I'm specially interested in is doing Security-focused Static Analysis, with integration with TeamMentor and Cat.NET (see Video: Injecting TeamMentor into Cat.Net running inside VisualStudio )

You can get Roslyn from O2 (it will install the package from NuGet), but if you want to try the visual studio integration you need to get the Microsoft “Roslyn” October 2011 CTP

If you want to comment this post or video, please use this reddit thread

Some Roslyn References and articles:

Saturday, 2 June 2012

Light Table gets 300k in funding

Congratulations to the Light Table guys, they just got 300k in funding via Kickstarter.

As I mentioned in  Light Table - Amazing PoC of IDE I really think it is a great idea and I wish the them best of luck.

Some comments:

  • This shows that it is possible to gather funding for software development projects (I did tried a half-baked attempt in 2010 which didn't really go anywhere: New funding model for O2's Development)
  • It shows that there is a lot of desire for better IDEs since the main ones we have (VisualStudio and Eclipse) are really showing off their age (and size)
  • It is a great way to build a community and get a list of interested parties. I would say that the current list of backers (all 7317 of them) is as valuable (if not more) as the 300k raised
  • Although there is an OpenSource element of it, they also have a commercial license, which might have helped with the pledges since there is something tangible given in return (notice the different types of pledges)
  • The money is going directly to the developers (from the community) which could be a good model for OWASP since it would be compabible with the concept of Why OWASP can't pay OWASP Leaders 

Big Security challenges with creating APIs for US Gov agencies

So Barack Obama Directs All Federal Agencies to Have an API 

Here is the White house memo (pdf) which mandates the implementation of  "Digital Government: Building a 21st Century Platform to Better Serve the American People" (pdf).

The good news it that at least security and privacy seems to be taken into account (with it's own chapter and focus)

I haven't read the document but after a skim, it looks like there is more focus on the non-secure-application-development 'security side' of these APIs.

And this could be an issue, since creating APIs is usually done by exposing internal systems or WebServices, which will now need to have much higher level of security than before (when they were connected to much less hostile environment).

I also like the use/focus on Privacy, since that will be a good way to drive coding and application changes.

This is a great opportunity for OWASP community to be involved since there is going to be a lot of API developers out there that could do with some help

Friday, 1 June 2012

Video: Injecting C# DLLs into Managed (C#) and Unmanaged (C++) processes

I was finally able to inject O2's REPL scripting environment into other processes (both managed and unmanaged)

Originally I was just trying to inject a managed dll into another .NET process, but the 4.0 .NET Framework will load up a CLR when it is not there, so this technique will also work on unmanaged (i.e. C++ based) applications.

Here is what happens in the video below:
  • Inside O2,  run the Util - Inject O2 into other processes.h2 script (which will provide a nice 'Injection GUI')
    • on the left there is a TreeView with a list of all current processes that have MainWindowHandle != 0 (a requirement at the moment)
    • on the right there is a TreeView with a list of the loaded modules (i.e. dlls) from the selected process
    • if you right-click on the process list you will be able: 
      • bring the process window to front, 
      • refresh the process list and 
      • do the injection into the selected process
  • Open LinqPad using the link from the 'Actions Panel' (on the top)
    • After LinqPad opens, select it on the process list and click on the 'Inject O2 into Process' link (top left)
    • An O2 REPL environment will apear. A number of scripts are dynamically created, showing that we now have complete control over the LinqPad GUI, by for example:
      • injecting a new Tab with another O2 REPL Editor
      • making the entire GUI pink or azure :)
  • Close LinqPad and back in the Util - Inject O2 into other processes.h2 click on the 'Open Calc' link to open Calc.exe (an unmanaged windows app (i.e. no CLR))
    • After Calc opens, select it on the process list and click on the 'Inject O2 into Process' link (top left)
    • A come more scripts are written to show that we are indeed inside the Calc.exe process.
This open up a LOT of interesting integration possibilities, and it is a much more solid solution that the use used before which required O2 dlls to be copied into the target's application folder (see Injecting O2 into IBM Rational AppScan Standard and Creating a Pink version of IBM Rational AppScan Standard)



Related Posts:

ConsolR Compilify and Roslyn

ConsolR is a really nice web-based C# execution environment, here is their description:

ConsolR enables you to execute C# code againt a running .NET 4.0 web application's app domain through a browser. Once installed, ConsolR will automatically configure itself during application start and is accessible through the "/consolr" path. This enables an interactive console session against for instance an application's production environment.

ConsolR is based on the Compilify project which provides the base REPL environment

Compilify uses the Microsoft's Roslyn engine which looks like a very powerful C# code analysis and manipulation (in fact from this Roslyn document I get the feel that I should rewrite O2's REPL Script environment using it)

Note: to install the VisualStudio I had to upgrade to the latest version of NuGet (which in VS 2011 SP1 can only be done after installing this HotFix)

Here it is in action:


Humm.... I wonder how much work it would be to convert this into an web version of O2 REPL environment :)

Thursday, 31 May 2012

Video: Injecting compiled C# script into a Managed Process (using Snoop API)

Following from O2 Script to Inject Snoop into process with WPF control here is the next step where I was able to inject an O2 compiled dll into another .net Process.

Here is the video showing this in action (the script is already on O2's GitHub repository)




Video: O2 Script to Inject Snoop into process with WPF control

Here is a example of using the O2 Platform to consume other tools capabilities.

In this case we are going to use the powerful Snoop API to visualize and manipulate the WPF controls hosted on another process.

Snoop is very powerful and it uses a pretty sweet remote process injection to do its trick. The O2 Script you can see below invokes directly the process injection sequence (after starting a process with a WPF control)

Here is a video that show this in action:


And here is the script:
This next video was created when trying to use Snoop to find VisualStudio's TextEditor WPF control (see Snoop Tips & Tricks #1: Ctrl-Shift Mouse Over  for a much faster way to find an WPF child control):



Related Posts:

Wednesday, 30 May 2012

Video: Injecting TeamMentor into Cat.Net running inside VisualStudio

Here is a pretty cool PoC where I used the O2 VisualStudio 2010 APIs to inject TeamMentor into Cat.NET.

To replicate this you will need:



Here is a video that shows the install process in action, and the extra functionality added to Cat.Net


Superhydrophobic Technology

This is one of the most amazing pieces of technology that I have seen in a while. These guys basically have invented a way to repel any liquid.

Here are the videos where I originally saw this technology




This technology is developed by http://www.neverwet.com who seem to be ready to launch a couple products based on it.

Tuesday, 29 May 2012

Video: Running Chrome Natively in O2 and VisualStudio



UPDATE (Jan/13): See PoC - Selenium - Gui with 3 Hijacked Browser Windows.h2 post for a much better and powerful way to consume Chrome (and IE and Firefox) in another process




Following from Run Chrome inside O2  and Installing and running CefSharp (C# Chrome with WPF Browser) here is the full implementation of running Chrome as a Native C# WinForms and WPF control.

This is pretty powerful since Chrome is FAST. I also like the fact that I can easily embed Chrome in WinForm or WPF control with a couple lines. (take a look at these scripts)

Here is a video showing the PoCs in action (with the examples using WPF doing a 360 rotation, because they can :) )


Monday, 28 May 2012

Video: NodeJS O2 REPL environment (using node.exe)

NodeJS is pretty amazing, I was able to get the node.exe (from here) and run its REPL environment with only that exe (no other installation or dependencies needed!).

Since it was that easy, I added NodeJS support to the O2 Platform and created a couple REPL editor environments which make it easy to consume NodeJS.

Here is a video of these new O2 Scripts (note how easy it was to create an NodeJS webserver :)



Some NodeJS references:

On Fuzzing WebServices

Since Arvind is now ready to start Fuzzing TeamMentor (see Fuzzing TM Webservices…fuzzing anything..?), here are a couple pointers on how to approach it.

Fuzzing is the art of sending unexpected stuff to an application and analysing its result. This is a very important part of making an app resilient since it (the app) should be able to handle unexpected/crazy inputs.

In my view there are 3 key elements that need to be in place when doing a fuzzing session:

  • Execution environment
  • Fuzz payloads/state
  • Fuzz targets/analysis

Lets look at each one in turn:

1) Execution environment: 


Before starting a fuzzing session one must create an environment that will allow us to create automated fuzz sessions. Here are some of the components needed (in this case slightly tweaked for fuzzing TM web-services):

  • Automatically create a clean testing environment/target (with clean database and some test content)
  • Detect when the database has been corrupted, and trigger an rebuild (which in TM means recreating the XML files and/or source-code files)
  • Ability to invoke the target WebServices (which is the Pyhton API that Arvind has been creating)
  • (ideally) Ability to run multiple instances of the target server at the same time (to allow multi-thread requests)
  • Ability to detect abnormal behaviour on the application: weird responses, requests that take too long, large server CPU spikes, non-expected file access (maybe outside the TM directory)
  • Ability to detect when/if the server crashes (ideally running the target app under a debugger)
  • Speed-up or slow-down requests in order to find the maximum request load supported by the server (if you are running a fuzzing session locally you should be able to create more requests than the server can handle it)

2) Fuzz payloads/state:


In terms of Fuzzing Payloads a great place to start is the FuzzDB which is a good base line for fuzzing strings to send to an application.

Once we have a way to consume these payloads, the key is to adjust them to the target methods. Specially the ones that require some state (i.e. we need to provide some valid data or the payload never reaches the app)

So yes, some customisations will be needed on a per WebService method basis, since that is the only way to ensure maximum coverage.

Also very important is to look at the state/data returned from the WebService (with special attention being placed on cases where a payload sent to WebMethod A is returned from a normal request sent to WebMethod B).

Lack of 'understanding state' is the single reason why fuzzing is very hard. But without it we are just doing a  'fuzz-everything-that-moves' strategy (which sometimes works).

Finally, one must differentiate Infrastructure fuzzing vs  Application Fuzzing (although both are very important). Infrastructure fuzzing is when one fuzzes the underlying services like ASP.NET (in TM Case). This type of tests should be done once, and its results taken into consideration (for example fuzzing "GUID values on a method that expects a GUID" or "payloads on Headers" only really needs to be done once)

3) Fuzz targets/analysis:


When fuzzing one must have very specific targets and analysis in mind. 

For example here are a couple Fuzzing Targets:
  • Fuzz all WebService's methods with a small subset of crazy payloads (xss/sqi strings, large strings, negative numbers, large numbers, non ascii chars, weird Unicode chars, etc...)
  • Fuzz all WebService's methods with valid state and all strings replaced with:
    • XSS Payloads
    • SQLi Payloads
    • Directory transversal payloads
  • Fuzz all WebService's methods with valid state and all GUID replaced with
    • Random GUIDS
    • Valid GUIDs that should not be be accepted (for example an existing FolderID used on CreateFolder)
  • Fuzz Authentication methods for authentication specific issues (for example brute force account/passwords attacks)
  • Fuzz content creation methods for XSS data injection
  • Fuzz methods used by multiple users (for example an editor and admin) and see if payloads injected by an editor are shown to admins
  • Fuzz methods in random invocation sequence (to try to detect weird race-conditions created by a particular test sequence)
  • After creating a mapping of what methods can be invoked by what users (a very specific type of fuzzing)
    • Fuzz the methods that should not be accessed by a particular user to see if there are blind spots that (due to a bug/vulnerability) enable that execution to occur
  • Create requests that can be 'consumed' by 3rd party scanners (like Zap, Burp, Netsparker, AppScan, etc...) and:
    • trigger those tests
    • consume its results
  • Fuzz the Fuzz results
    • There will be cases where the fuzz targets will be the fuzz results of previous sessions
These tests will generate a LOT of data, which needs to be:
  • Normalised (with similar responses reported as one)
  • Stored (as raw as possible) to allow later analysis
  • Analysed, taking into account:
    • the expected result for the fuzzed method
    • the type of test being performed
  • Reported (in an easy to consume and replicate format)

It is important to restate that each type target requires a different type of analysis. Taking into account what is being tested and (more importantly) what is the expected method invocation result.

Another very important concept is the need to have a fully automated fuzzing environment. This should be a 'fuzz-and-forget' world where the fuzz tests are executed without any human intervention (don't forget to add a 'stop' button :)  )

Although this sounds like a lot, the harder part is to create the environment required to execute the first couple Fuzzing Targets (as described above). Once that is done, the rest are variations.

Finally, always keep in mind that the objective is to create something that can be added to build environment so that these tests can be executed automatically (with any new 'findings/fixes' reported to the developers)

Reddit
If you have comments or ideas about this post, please add them to this reddit discusion 

Related Posts


Friday, 25 May 2012

Video: Installing and running CefSharp (C# Chrome with WPF Browser)



UPDATE (Jan/13): See PoC - Selenium - Gui with 3 Hijacked Browser Windows.h2 post for a much better and powerful way to consume Chrome (and IE and Firefox) in another process




After we were able to Run Chrome inside O2  here is O2's native support for the CefSharp API (note that the first time that API is used, the install files will be downloaded and unzipped locally (if 7zip is not installed locally, it also will be downloaded and installed)

Here is the video that shows the CefSharp (C# Chrome) WPF and Windows Browser Controls in action:



Related Posts:

Chrome about:about (list of internal pages)

Just found this cool way to access a lot of Chrome's internal information.

Just open: about:about or chrome://about

Here are some examples of these extra pages:

Losing my mojo with Wordpress.com (they're not getting the basics right)

So I've been using wordpress.com for a while to host O2's blog, but it has become more and more painful to use.

It crashes, doesn't load fast, html formatting goes all wild, there is too much stuff going on ... (it's faster to use Blogger than wordpress!!!)

Unfortunately it's another good example of a product/service that keeps adding new features and losing sight of its core functions (i.e. writing a blog).

One key objectives of adding new features is to make things Simpler to use (or keep it as simple as they were before)

I'm really close to start looking at alternatives and maybe even trying to move that blog into a TeamMentor based site!

Thursday, 24 May 2012

Video: Installing O2's VisualStudio 2010 Add-In

Here is a video that shows the steps required to install O2's Visual Studio 2010 Add-in (also described in this post Running O2 REPL Script environment inside Visual Studio 2010)


Video: Under the hood of O2's REPL Script Environment

Here is a video that shows what happens under the hood when you write an O2 Script.

The concept is quite simple: Grab the code in the Editor and insert it inside a full blown C# method inside a class (using comments to indicate extra using and dll references).

This way we have the best of both worlds. Full C# 4.0 coding capabilities (like the new Dynamic objects) in a much nicer/simpler REPL scripting environment.

Here is a video that shows this in action:



Video: O2's DWR support (and two-way Javascript manipulation)

This is an oldie one, but I was talking with an O2 user about O2's ability to send and receive data from Javascript (via the IE object), and this DWR is a great example of that.

Note how in the video the data sent to the DWR test server is manipulated (on the client side) by the Javascript (shown on the left) that is injected into the browser:


Wednesday, 23 May 2012

C# Dynamic capabilities (using ExpandoObject)

This is reallllllllllyyyyyyyyyyyy cool+powerful!


What you have here the dynamic creation (a-la-python) of a variable and a method.

Humm... this opens up a HUGE amount of very interesting scripting capabilities, namely the ability to dramatically simplify the scripting of certain APIs :).

Some references:

Here is the code as a Gist:

Running Chrome inside O2



UPDATE (Jan/13): See PoC - Selenium - Gui with 3 Hijacked Browser Windows.h2 post for a much better and powerful way to consume Chrome (and IE and Firefox) in another process




Here is something that I have been wanting to do for quite a while.

Using the compiled dlls from https://github.com/chillitom/CefSharp/ (which is a wrapper on top of http://code.google.com/p/chromiumembedded/), here is Chrome running inside O2


And here is the code that made this happen: