OWASP O2 Platform Blog

O2 Script: Testing for RDP server

This script will test if an RDP server is available and will take a couple screenshots if it is (note that the in version or mstsc.exe provided in Windows 2008 there doesn’t seem to be a way to connect first to the server and then provide the account details (it would be better to take a screenshot from the actual RDP session)

This script shows quite a number of O2 scripting techniques, so please use the comment’s section if you have any questions or want more details on how it works

//var topPanel = panel.clear().add_Panel();
var topPanel = O2Gui.open<Panel>("Test RDP Server", 700,400);
var ie = topPanel.add_IE();
ie.showMessage("Testing if an RDP server is alive");

var rdpServer = "What TS do you want to test?".askUser();
if (rdpServer.isNull())
{
    ie.showMessage("No TS server provided");
    return "no TS provided";
}   

var terminalServicesClient = Processes.startProcess("mstsc.exe");
var guiAutomation = new API_GuiAutomation(terminalServicesClient);
var window = guiAutomation.window("Remote Desktop Connection");
window.textBox("Computer:").set_Text(rdpServer);
var screenshot1 = window.screenshot().save();

window.button("Connect").mouse().click();
 
//return guiAutomation.windows();
var loginWindow = guiAutomation.window("Windows Security",3);

if (loginWindow.notNull())
{   
    var screenshot2 =  window.screenshot().save();
    var htmlCode =  "<html><body><h1>Found TS</h1>".line() +
                    "   <img src='{0}'/>".format(screenshot1) .line() +
                    "   <img src='{0}'/>".format(screenshot2) .line() +
                    "</body></html>";
    ie.set_Html(htmlCode);   
}
else
    ie.set_Html( "<html><body><h1>NO TS Found</h1>".line() +
                 "</body></html>");
                
terminalServicesClient.close();

return "done";

//using O2.XRules.Database.Utils.O2
//O2File:API_GuiAutomation.cs
//O2Ref:White.Core.dll
//O2File:API_Cropper.cs
//O2File:WatiN_IE_ExtensionMethods.cs
//O2Ref:WatiN.Core.1x.dll

 This is what it looks like in the beggining:

this is what happens when it finds an TS:

this is what happens when it doesnt:

March 8, 2011 - Posted by | WatiN, Windows Tools

No comments yet.

Leave a comment