Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Created November 30, 2012 03:28
Show Gist options
  • Select an option

  • Save DinisCruz/4173602 to your computer and use it in GitHub Desktop.

Select an option

Save DinisCruz/4173602 to your computer and use it in GitHub Desktop.
O2 Script - Example of UnitTest to test for XSS on AltoroMutual
// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;
using O2.XRules.Database.APIs;
//O2Ref:nunit.framework.dll
using NUnit.Framework;
//O2File:WatiN_IE_ExtensionMethods.cs
//O2Ref:WatiN.Core.1x.dll
//O2File:API_FuzzDB.cs
namespace O2.XRules.Database.UnitTests
{
[TestFixture]
public class SimpleUnitTest
{
public static WatiN_IE ie;
public SimpleUnitTest()
{
}
[Test]
public string openIE()
{
ie = "IE Execution".popupWindow().add_IE();
ie.open("http://demo.testfire.net");
return "Opening IE";
}
public bool search(string text)
{
ie.field("txtSearch").value(text);
ie.button("Go").click();
var html = ie.IE.Html;
return html.contains(text);
}
[Test]
public void searchIsWorking()
{
var term = "a value";
Assert.That(search(term) , "Html didn't contain term");
}
[Test]
public void XSS_SimplePayload()
{
var payload = "<h1> shouldn't match";
Assert.That(search(payload) , "payload was there");
}
[Test]
public void XSS_FuzzDb()
{
var alerts = ie.getAlertsHandler();
alerts.reset();
var payloads = new API_FuzzDB().payloads_Xss().take(5);
foreach(var payload in payloads)
search(payload.info());
Assert.That(alerts.Count == 0, "There were {0} alerts".format(alerts.Count));
}
[Test]
public string closeIE()
{
ie.HostControl.parentForm().close();
return "Closing IE";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment