Showing posts with label Testing. Show all posts
Showing posts with label Testing. Show all posts

Sunday, 16 October 2016

Presenting "Surrogate dependencies" at London LSCC on 20th of October (Thursday)

Here is the description of this presentation:
Don't mock internal functions and methods, mock external dependencies. How to do that? This presentation will present a framework and practical example of creating Surrogate dependencies (think custom proxies, similar to WireMock). They are based on data collected from Integration tests to create environments where target applications can be executed offline and be subject to advanced security, quality and performance testing. All data is stored natively (JSON, XML) and Git is used for content versioning and simulation.
You can register at https://skillsmatter.com/meetups/8431-lscc-meetup (here is the meetup page)

This is going to be an variation of the Surrogate dependencies presentations delivered last month at the Owasp London Chapter

Thursday, 22 September 2016

"Turning TDD upside down - For bugs, always start with a passing test" - v0.5 Sep 2016

Here is the presentation I delivered at LSCC (London Software Craftsmanship Community) on the 22nd Sep 2016

Title: Turning TDD upside down - For bugs, always start with a passing test
Description: Common workflow on TDD is to write failed tests. The problem with this approach is that it only works for a very specific scenario (when fixing bugs). This presentation will present a different workflow which will make the coding and testing of those tests much easier, faster, simpler, secure and thorough'


Saturday, 24 January 2015

Real-Time code coverage in NodeJS app using Atom

Here is my current dev environment on Atom's Editor where I am able to have quasi-real-time (i.e. in about 1s to 2s) feedback on the test executed and its code coverage

For example here is what I see when there is a test failing:
  • note the red dots on the left (after line 44)
  • note the error message right (where '1.2' is not'1.3')
  • code coverage is at 92.50%

Monday, 10 December 2012

Testing an WCF Rest Service directly and via a local instance created by WebServiceHost

Here is an example of a simple REST based WebService which is tested using 3 techniques:

  • IIS
  • Direct object creation
  • Locally hosted instance of the WCF service (using .Net's WebServiceHost class)


Friday, 30 November 2012

Simple Unit Test to detect XSS using FuzzDB and IE automation

Here is an example of a simple Unit Test written in the Write and Execute Unit Tests v1.0.exe tool which will check for XSS on AltoroMutual website

The idea is that when the Red Boxes go Green, the vulnerability is fixed.

Write and Execute Unit Tests v1.0.exe

Here is a nice util to quickly write NUnit tests. This is designed for fast prototyping of UnitTests, which when stable can be moved into a wider set of tests (executed by NUnit)

You can download this tool from: Write and Execute Unit Tests v1.0.exe

Monday, 28 May 2012

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


Monday, 7 May 2012

Documenting how to test WebServices using scripts - the story so far

Here is the chronological consolidation of the  efforts (by Arvind and me) to write a detailed story of the steps required to create a Security / QA test suite for TeamMentor

These are my posts with analysis of what is going on, key concepts, extra briefing notes, and links to relevant Arvind's posts:

These are Arvind's posts with his efforts, ideas, problems, solutions and scripts:

Thursday, 3 May 2012

Creating a spreadsheet with WebService's Authorization Mappings

As per the Roadmap for Testing an WebService's Authorization Model and What is the formula for the WebServices Authentication mappings?

One of the assets that we need is the official mapping of TeamMentor's WebServices Authorization Rules. This is the mapping according to the 'Business Logic', and must be independent from what actually is happening at the live website (and within the code).

Our current solution is to have a shared GoogleDoc spreadsheet which these mappings.

Here are two screenshots of what it looks like (see the spreadsheet is here)




These mappings represent what is expected to happen, so for example if one of the methods marked with NO (in light red) can be invoked by that type of user (like an Reader), then that is a vulnerability.

What is very powerful about this mapping, is that it allows us (on the security camp) to have a proper 'conversation' with the business owners and key developers/architects (and we will get a lot of kudos if we are the ones that created this (or enabled its creation))

Basically what we are asking them is: Tell me how you expect your app to behave, so that I can tell you what actually happens.

Although this is a great step forward, there is still a lot to do:

  • Feed this data to a Dynamic or Static analysis script/tool (so that it takes into account the expected behaviour)
  • Once we have results, create a diff view of this data
  • Map this script with the actual WSDL so that any WSDL changes can be detected and fixed ASAP (for example when methods are added, edited or removed)
  • Find a way to store and map this data over time
These mappings are the key to the discovery of security issues and (in their absence) to provide assurance to the business that the application is behaving the way it should.

The interesting question is: how is it possible to perform an Authorization security analysis without this information? :)

Wednesday, 2 May 2012

Roadmap for Testing an WebService's Authorization Model

Now that Arvind is asking THE real questions (see What is the formula for the WebServices Authentication mappings?) , it's time to define the roadmap.

Here is what I think needs to happen when testing and visualizing an application's Authorization Mode, in a WebServices driven application like TeamMentor:

  • Create UnitTest that are able to invoke the WebServices methods with valid state: (i.e. be able to successfully invoke all methods)
    • This is not just a case of having good enough data (which in a lot of cases is dynamic (i.e. Method B needs data retrieved via method A))
    • ...one also needs to take into account the cases where the data will be destroyed or corrupted (remember that If you not blowing up the database, you're not testing the whole app )
    • ..which means that the execution order is very important, since we will need to support a solid set-up,  tear-down and restore workflow 
  • Invoke those methods with different users and roles:
    • You will need at least two user accounts per different role, so that you can test what happens between user A and user B (of the same role) and user A and user C (with different roles)
    • The data created needs to be exported into a format that can be consumed by a visualization script
  • Analyse the Source-Code and extract the real formula: (using static analysis technology) 
    • This should be in a format that can be cross-checked with the Web Method's tests
    • There could also be a 'hard-coded' mapping file that defines what are the values that are currently accepted by the application's bussiness logic (think of this as a consumable version of the Application's technical-spec/architecture)
    • Note that that sometimes we can already find Authorization vulnerabilities by reviewing these static mappings
  • Cross-Check the Static Mappings with the Dynamically collected data
    • First step is to make sure that the current code assumptions are actually happening in the real world (note that while the static analysis represents what the developers would like to happen, the dynamic analysis represents what actually happens!)
    • Find blind spots and create ways to codify them
  • Fuzz it!
    • Using something like the FuzzDB, add abuse cases  (i.e. payloads on valid method's invocations) and check that the expected rules and mappings still apply (also keeping an eye for other weird behaviours and vulnerabilities)
  • When vulnerabilities are found, integrate them with current bug tracking system
    • In some cases each type of vuln will need to created (or updated) as an individual issue
    • In other cases, we will need to consolidated them so that we don't create too many bugs
    • We will also need go get a risk analysis from the application owner, since some vulnerabilities might be more dangerous than others
  • Apply a fix and (quickly) confirm it via the created scripts
    • Ensure the developer can invoke one (or all tests) from their IDE
    • The scripts created must be able to reflect code fixes
  • Integrate these tests into the build/release process
    • So that they run whenever needed (every day, on git push, on release, etc...)
    • Note that that the tests will need to be executed on the multiple development, QA and production environments (with an easy way to diff the results)
  • Package visualization created and empower developers
    • Make sure the developers can access the visualization/mappings created
    • Hand-over and train developers in how to access, use and maintain those scripts, so that it is the developers (or QA's) responsibility to make sure they keep running and reflect code changes
  • Create visualizations of data collected over time

Now you might think that this is it and that we can stop here. The reality is that this workflow is still very inefficient, slow and hard to use by all relevant parties.

The way we should be creating these Authorization models, is by:
  • Creating a DSL (Domain Specific Language) that represents the current Application Business Logic and its Authorization rules
  • Getting the Application's business owner(s) to write the rules in the DSL language created (which they should understand and be comfortable with)
  • Feed those rules to the Static and Dynamic analysis tools/scripts
  • Analyse the data created and integrate the results into the SDL
Now THAT'S how Authorization models should be created, visualized, tested and enforced :)

Finally, for a great introduction to DSL and how to use it in C#, please take a look at this book: DSLs in Boo: Domain-Specific Languages in .NET (specially the chapter where the author talks about a Security-focused DSL)

Related Posts:

What is the formula for the WebServices Authentication mappings?

ahh... that's THE Question :)

Arvind's journey stared with the need to First you create Tests for WebServices, then you add the abuse/security cases . He then started coding  Python scripts and Unit tests on his journey into testing WebServices in a developer friendly way with some interesting side effects: If you not blowing up the database, you're not testing the whole app.

After that he wrote:

and then asked me the "...humm, where can I get the Authorization mappings? (so that I can check my results against them)"

I was waiting for this question because that is one of the signs that a security test is going on the right direction (btw, if you have commissioned a security assessment and did not get that question you should be worried! ).

Basically what he wants is a mapping of TeamMentor's Authorization Rules, namely which functions should be accessed by the multiple security roles (Anonymous, Reader, Editor and Admin).

And this 'simple question' just happens to be one that very few applications and developers have!  (tip: if you find the answer and share it with the developers, you will move from being a TAX into being a 'visualization engine')

Usually when we (the security guys) ask this question, we get some old document that explained what they where trying to do, or some guy with pen+whiteboard doing a big diagram :)

My view is that it is impossible to have any type of decent assurance that an application doesn't have authorization blind spots without these mappings. One important factor is that they (the mappings) need to be created in a consumable way, so that they can be verified via automated scripts like the ones Arvind is writing (or by 3rd party scanning tools/services)

So where are this mappings?

Well ...  they exist in the application's source code code and (sometimes) in its data (like config-files or database tables).

Here is another example of why automated tools will never be able to have good coverage until they are customized.

In the case of TeamMentor the formula is exclusively in the code, since it uses .NET CAS (CodeAccessSecurity) permissions to issue a Security Demand before security sensitive actions are performed.

What is going to happen next, is that I'm going to use O2's Static Analysis engine to parse the code and extract the current formula into a format that Arvind can consume it.


Related Posts:



Sunday, 29 April 2012

A journey into testing WebServices in a developer friendly way

Following from the workflows that I described in First you create Tests for WebServices, then you add the abuse/security cases , Arvind has now started to blog about his efforts, challenges and solutions.

I asked him to start from the beginning since I think his history and evolution will be very relevant and interesting to others trying to implement similar solutions:

What is very interesting about this series of posts (with many more to come) is that Arvind is really capturing the thinking (and evolution) that needs to happen when doing Authorisation Security testing on an application like TeamMentor.

I also really like the honesty of Arvind's voice and some of his funny comments :)

I hope you enjoy reading his journey

Monday, 23 April 2012

First you create Tests for WebServices, then you add the abuse/security cases

I'm currently working with Arvind (contracted by SI) on creating test cases for TeamMentor Webservices.

Since he is Linux/Python based, he can't reuse the C# test cases that I created a while back (see Testing TeamMentor 2.0 security using O2) which is not a problem since this will help to expand TeamMentor testability into the Linux/OSx world.