Skip to content

Commit

Permalink
Added Selenium WebDriver support and "PoC - Selenium - Gui with 3 Hij…
Browse files Browse the repository at this point in the history
…acked Browser Windows.h2"

New Extension methods and bug fixes on Handle-Hijack GUI/API
  • Loading branch information
DinisCruz committed Jan 22, 2013
1 parent a23daf3 commit 7162dcf
Show file tree
Hide file tree
Showing 15 changed files with 546 additions and 115 deletions.
92 changes: 55 additions & 37 deletions 3rdParty/Nikto/Install_Firefox.cs
@@ -1,38 +1,56 @@
using System;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;
using O2.DotNetWrappers.Windows;

//O2File:Tool_API.cs

namespace O2.XRules.Database.APIs
{
public class Install_Firefox : Tool_API
{
public Install_Firefox()
{
ToolName = "Firefox";
Version = "Firefox 3.6.10";
Install_File = "Firefox Setup 3.6.10.exe";
Install_Dir = @"C:\Program Files\Mozilla Firefox";
VersionWebDownload = "";

}


public bool install()
{
return installFromMsi_Web();
}

public bool uninstall()
{
var uninstallExe = Install_Dir.pathCombine(@"\uninstall\helper.exe");
Processes.startProcess(uninstallExe,"");
// check if this also deletes the firefox folder
return isInstalled();
}

}
using System;
using System.Diagnostics;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;
using O2.DotNetWrappers.Windows;

//O2File:Tool_API.cs

namespace O2.XRules.Database.APIs
{
public class Install_Firefox_Test
{
public void install()
{
new Install_Firefox().start();
}
}
public class Install_Firefox : Tool_API
{
public Install_Firefox()
{
ToolName = "Firefox";
Version = "Firefox 17.0.1";
Install_File = "Firefox setup 17.0.1.exe";
Install_Uri = "http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/17.0.1/win32/en-US/Firefox setup 17.0.1.exe".uri();
Install_Dir = ProgramFilesFolder.pathCombine("Mozilla Firefox");
Executable = Install_Dir.pathCombine("Firefox.exe");
VersionWebDownload = "";
this.InstallProcess_Arguments = "-ms";
installFromMsi_Web();
}


/*public bool install()
{
return installFromMsi_Web();
}*/

public bool uninstall()
{
var uninstallExe = Install_Dir.pathCombine(@"\uninstall\helper.exe");
Processes.startProcess(uninstallExe,"");
// check if this also deletes the firefox folder
return isInstalled();
}

public Process start()
{
if (isInstalled())
return Executable.startProcess();
return null;
}

}
}
25 changes: 13 additions & 12 deletions 3rdParty/Nikto/Tool_API.cs
Expand Up @@ -24,16 +24,17 @@ namespace O2.XRules.Database.APIs
// this calls exists to simplify the creation of new Tool APIs
public class Tool_API
{
public string ToolName {get; set;}
public string Version {get; set;}
public string VersionWebDownload {get;set;}
public string Install_File {get;set;}
public Uri Install_Uri {get;set;}
public string Install_Dir {get;set;}
public string DownloadedInstallerFile {get; set;}
public string Executable { get;set;}
public string Executable_Name { get; set; }
public string ToolsDir { get; set; }
public string ToolName { get; set; }
public string Version { get; set; }
public string VersionWebDownload { get; set; }
public string Install_File { get; set; }
public Uri Install_Uri { get; set; }
public string Install_Dir { get; set; }
public string DownloadedInstallerFile { get; set; }
public string Executable { get; set; }
public string Executable_Name { get; set; }
public string ToolsDir { get; set; }
public string InstallProcess_Arguments { get; set; }
//public string toolsDir = PublicDI.config.O2TempDir.pathCombine("..\\_ToolsOrAPIs").createDir();
public string localDownloadsDir = PublicDI.config.O2TempDir.pathCombine("..\\_O2Downloads").createDir();
public string s3DownloadFolder = "http://s3.amazonaws.com/O2_Downloads/";
Expand Down Expand Up @@ -138,7 +139,7 @@ public virtual bool isInstalled(bool showLogMessage)
public virtual bool installFromMsi_Local(string pathToMsi)
{
if (isInstalled(false).isFalse() && pathToMsi.fileExists())
Processes.startProcess(pathToMsi).WaitForExit();
Processes.startProcess(pathToMsi, this.InstallProcess_Arguments).WaitForExit();
return isInstalled();
}

Expand All @@ -150,7 +151,7 @@ public virtual bool startInstaller_FromMsi_Web()
public virtual bool startInstaller_FromMsi_Local(string pathToMsi)
{
if (isInstalled(false).isFalse() && pathToMsi.fileExists())
Install_Process = Processes.startProcess(pathToMsi);
Install_Process = Processes.startProcess(pathToMsi,this.InstallProcess_Arguments);
return isInstalled();
}

Expand Down
43 changes: 43 additions & 0 deletions 3rdParty/Selenium/API_Selenium.cs
@@ -0,0 +1,43 @@
// 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.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using O2.Kernel;
using O2.DotNetWrappers.ExtensionMethods;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using OpenQA.Selenium;

//O2File:SeleniumWebDrivers_Setup.cs

namespace O2.XRules.Database.APIs
{
public class API_Selenium
{
public IWebDriver WebDriver {get;set;}

}
public static class API_Selenium_ExtensionMethods
{
public static API_Selenium setTarget_Chrome(this API_Selenium selenium)
{
selenium.WebDriver = "Selenium_ChromeDriver".o2Cache<IWebDriver>(SeleniumWebDrivers_Setup.ChromeDriverSetUp);
return selenium;
}

public static API_Selenium setTarget_Firefox(this API_Selenium selenium)
{
selenium.WebDriver = "Selenium_FirefoxDriver".o2Cache<IWebDriver>(() => new FirefoxDriver());
return selenium;
}

public static API_Selenium setTarget_IE(this API_Selenium selenium)
{
selenium.WebDriver = "Selenium_InternetExplorerDriver".o2Cache<IWebDriver>(SeleniumWebDrivers_Setup.IEDriverSetUp);
return selenium;
}
}
}

@@ -0,0 +1,200 @@
<?xml version="1.0"?>
<H2>
<SourceCode>//var selectQuery = new SelectQuery("Win32_Process");

IntPtr firefoxHandle = default(IntPtr);
IntPtr chromeHandle = default(IntPtr);
IntPtr ieHandle = default(IntPtr);
Process firefoxProcess = null;
Process chromeDriverProcess = null;
Process ieDriverProcess = null;

Func&lt;int, Process&gt; getProcessWithParentHandle =
(processId)=&gt;{
var selectQuery = "Select ProcessId from Win32_Process Where ParentProcessId = {0}".format(processId);;
foreach(var proc in new ManagementObjectSearcher(selectQuery).Get())
{
var procId = (int)(UInt32)proc["ProcessId"];
var foundProcess = procId.process_WithId();
"foundProcess: {0}".debug(foundProcess);
return foundProcess;
};
"Failed to find process with id: {0}".error(processId);
return null;
};

Func&lt;IntPtr, IWebDriver&gt; setup_Firefox =
(targetHandle)=&gt; {
var selenium = new API_Selenium();
selenium.setTarget_Firefox();
firefoxProcess = "firefox".process_WithName();
firefoxHandle = firefoxProcess.MainWindowHandle;
firefoxHandle.setParent(targetHandle);
WinAPI.ShowWindow(firefoxHandle, WinAPI.ShowWindowCommands.ShowMaximized);
return selenium.WebDriver;
};


Func&lt;IntPtr, IWebDriver&gt; setup_Chrome =
(targetHandle)=&gt;{
var selenium = new API_Selenium();
selenium.setTarget_Chrome();
chromeDriverProcess = "ChromeDriver".process_WithName();
chromeHandle= getProcessWithParentHandle(chromeDriverProcess.Id).MainWindowHandle;
chromeHandle.setParent(targetHandle);
WinAPI.ShowWindow(chromeHandle, WinAPI.ShowWindowCommands.ShowMaximized);
return selenium.WebDriver;
};
Func&lt;IntPtr, IWebDriver&gt; setup_IE =
(targetHandle)=&gt;{
var selenium = new API_Selenium();
selenium.setTarget_IE();
ieDriverProcess = "IEDriverServer".process_WithName();
ieHandle= getProcessWithParentHandle(ieDriverProcess.Id).MainWindowHandle;
ieHandle.setParent(targetHandle);
WinAPI.ShowWindow(ieHandle, WinAPI.ShowWindowCommands.ShowMaximized);
return selenium.WebDriver;
};

//"Selenium_InternetExplorerDriver".o2Cache(null);
"Selenium_ChromeDriver".o2Cache(null);
"Selenium_FirefoxDriver".o2Cache(null);
"Selenium_InternetExplorerDriver".o2Cache(null);

var targetPanel = "hijack".popupWindow(1000,600);

targetPanel.onClosed(
()=&gt;{
firefoxProcess.stop();
chromeDriverProcess.stop();
ieDriverProcess.stop();
"Selenium_ChromeDriver".o2Cache(null);
"Selenium_FirefoxDriver".o2Cache(null);
"Selenium_InternetExplorerDriver".o2Cache(null);
});

/*targetPanel.insert_ActionPanel()
.add_Link("close",()=&gt;{
fireFoxHandle.setParent(IntPtr.Zero);
chromeHandle.setParent(IntPtr.Zero);

targetPanel.parentForm().close();
});
*/

var fireFoxPanel = targetPanel.insert_Left(150,"Firefox");
var chromePanel = targetPanel.insert_Right(150,"Chrome");
var iePanel = targetPanel.title("Chrome").add_Panel();
var script = targetPanel.insert_Script();

targetPanel.parentForm().alwaysOnTop();

targetPanel.Resize+=(sender,e)=&gt;{
ieHandle.resizeWindowToControlSize(iePanel,0,0);
chromeHandle.resizeWindowToControlSize(chromePanel,0,0);
firefoxHandle.resizeWindowToControlSize(fireFoxPanel,0,0);
};


var codeSnippet =
@"Action&lt;string&gt; openInAllBrowsers =
(url)=&gt; {
chrome.Navigate().GoToUrl(url);
firefox.Navigate().GoToUrl(url);
ie.Navigate().GoToUrl(url);
};
openInAllBrowsers(""http://www.google.com"");
//openInAllBrowsers(""http://www.whatismybrowser.com/"");
//openInAllBrowsers(""http://localhost:12121/"");

return ""done"";
//O2Ref:Selenium\net40\WebDriver.dll
";



var ieDriver = setup_IE(iePanel.handle());
var firefoxDriver = setup_Firefox(fireFoxPanel.handle());
var chromeDriver = setup_Chrome(chromePanel.handle());

script.set_Code(codeSnippet);
script.add_InvocationParameter("chrome", chromeDriver);
script.add_InvocationParameter("firefox", firefoxDriver);
script.add_InvocationParameter("ie", ieDriver);

return "done";

/*

var driverProcessName = "Firefox";
var ieDriver = driverProcessName.process_WithName();
if (ieDriver.isNull())
return "ieDriver was null";



var panelHandle = targetPanel.Handle;

fireFoxHandle = ieDriver.MainWindowHandle;
"panelHandle: {0} : {1}".info(panelHandle, panelHandle.get_Parent());
"firefoxHandle: {0} : {1}".info(fireFoxHandle, fireFoxHandle.get_Parent());
fireFoxHandle.setParent(panelHandle);
fireFoxHandle.window_Redraw();
fireFoxHandle.window_Redraw();
WinAPI.ShowWindow(fireFoxHandle, WinAPI.ShowWindowCommands.ShowMaximized);
return "firefox";
*/
/*
var selectQuery = "Select ProcessId from Win32_Process Where ParentProcessId = {0}".format(ieDriver.Id);;



foreach(var proc in new ManagementObjectSearcher(selectQuery).Get())
{
var procId = (int)(UInt32)proc["ProcessId"];
"process id:{0}".info(procId);
var process = procId.process_WithId();
var ieHandle = process.MainWindowHandle;
var ieParentHandle = ieHandle.get_Parent();


"panelHandle: {0} : {1}".info(panelHandle, panelHandle.get_Parent());

"ieHandle: {0} : {1}".info(ieHandle, ieHandle.get_Parent());


ieHandle.setParent(panelHandle);
ieHandle.window_Redraw();
panelHandle.window_Redraw();

WinAPI.ShowWindow(ieHandle, WinAPI.ShowWindowCommands.ShowMaximized);
}
*/
//using System.Management
//O2Ref:System.Management.dll

//"IEDriverServer".process_WithName().details();
return "done";

//var topPanel = "{name}".popupWindow(700,400);
//var selenium = new API_Selenium();
//selenium.setTarget_Chrome();
//selenium.setTarget_IE();
//selenium.setTarget_Firefox();



//driver.Navigate().GoToUrl("http://localhost:3187");
//driver.details();
//return driver;

//using System.Diagnostics

//O2File:API_WinAPI.cs
//O2File:API_WinAPI_ExtensionMethods.cs
//using OpenQA.Selenium
//O2File:API_Selenium.cs
//O2File:SeleniumWebDrivers_Setup.cs
//O2Ref:Selenium\net40\WebDriver.dll</SourceCode>
<ReferencedAssemblies />
</H2>

0 comments on commit 7162dcf

Please sign in to comment.