Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Selenium WebDriver support and "PoC - Selenium - Gui with 3 Hij…
…acked Browser Windows.h2" New Extension methods and bug fixes on Handle-Hijack GUI/API
- Loading branch information
Showing
15 changed files
with
546 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} | ||
|
200 changes: 200 additions & 0 deletions
200
3rdParty/Selenium/PoC - Selenium - Gui with 3 Hijacked Browser Windows.h2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<int, Process> getProcessWithParentHandle = | ||
(processId)=>{ | ||
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<IntPtr, IWebDriver> setup_Firefox = | ||
(targetHandle)=> { | ||
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<IntPtr, IWebDriver> setup_Chrome = | ||
(targetHandle)=>{ | ||
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<IntPtr, IWebDriver> setup_IE = | ||
(targetHandle)=>{ | ||
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( | ||
()=>{ | ||
firefoxProcess.stop(); | ||
chromeDriverProcess.stop(); | ||
ieDriverProcess.stop(); | ||
"Selenium_ChromeDriver".o2Cache(null); | ||
"Selenium_FirefoxDriver".o2Cache(null); | ||
"Selenium_InternetExplorerDriver".o2Cache(null); | ||
}); | ||
|
||
/*targetPanel.insert_ActionPanel() | ||
.add_Link("close",()=>{ | ||
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)=>{ | ||
ieHandle.resizeWindowToControlSize(iePanel,0,0); | ||
chromeHandle.resizeWindowToControlSize(chromePanel,0,0); | ||
firefoxHandle.resizeWindowToControlSize(fireFoxPanel,0,0); | ||
}; | ||
|
||
|
||
var codeSnippet = | ||
@"Action<string> openInAllBrowsers = | ||
(url)=> { | ||
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> |
Oops, something went wrong.