OWASP O2 Platform Blog

Using OpenPGP to Easily create temp PGP keys for secure file exchange

If you need to quickly create PGP keys that you can distribute for temporary use, take a look at the O2 Script ‘tool – using openpgp to encrypt and decrypt.h2’.

This is what the main GUI looks like:

Go to ‘Create or Edit Keys’ and click on ‘Create’ (this can take a couple seconds since OpenPgp needs to get enough entropy from the local system for key generation)

Now just go to the target folder and send the public key file to your receipient.

This Gui can also be used to encrypt text:

Decrypt text:

and Encrypt/Decypt files

July 15, 2011 Posted by | Interoperability, Windows Tools | Leave a comment

O2 Script: Quick File Viewer

This is the script that I usually write ‘live’ in the training sessions I do about O2.

It is a simple file viewer which gets a list of all files in a folder and shows them in a text box (a variation is to use a sourceCodeViewer instead)

var topPanel = O2Gui.open<Panel>("{name}",800,400);
//var topPanel = panel.clear().add_Panel();
var textViewer = topPanel.add_RichTextBox();  //add_SourceCodeEditor();
var treeView = textViewer.insert_Left<Panel>(200).add_TreeView();
var sourceFolder = treeView.insert_Above<Panel>(20).add_TextBox("Folder:   ","");
var fileFilter = treeView.insert_Above<Panel>(20).add_TextBox("File Filter:","*.cs");

treeView.afterSelect<string>((file)=>textViewer.set_Text(file.fileContents()));
Action<string> loadFiles =
    (folder) =>    {
                    sourceFolder.set_Text(folder);
                    treeView.clear();
                    foreach(var file in folder.files(true, fileFilter.get_Text()))
                        treeView.add_Node(file.remove(folder), file);
                };

Action loadFromSourceFolder =
    ()=>{
            loadFiles(sourceFolder.get_Text());
        };

sourceFolder.onEnter((text)=> loadFiles(text));
fileFilter.onEnter((text)=> loadFromSourceFolder());
sourceFolder.onDrop((folder)=> loadFiles(folder));
treeView.onDrop((folder)=> loadFiles(folder));
textViewer.onDrop((folder)=> loadFiles(folder));
textViewer.set_Text("Drag and Drop folder to open (and list files) into this GUI");
 
loadFiles(PublicDI.config.LocalScriptsFolder);
                      
return "done";               

March 26, 2011 Posted by | Windows Tools | 1 Comment

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 | Leave a comment

O2 Script Sequence: Creating a Windows Registry Viewer

When I was writing the script to Add sites to IE’s trusted zone I found that I needed to have a quick look at the registry. Since opening up RegEdit seemed like too much work, I decided to quickly add a Registry Viewer to O2 (you can find the published version of this script on your local Scripts folder at /O2_Scripts/Utils/Windows/Util – Registry Viewer.h2)

Here is how I created this script:

Step 1: Open a “Quick Development GUI’ window

panel.clear();
var textBox = panel.add_TextBox(true);
textBox.set_Text("hello world");

Step 2:

panel.clear();
RegistryKey currentUserKey = Registry.CurrentUser;
return currentUserKey;
//using Microsoft.Win32

Step 3:

panel.clear();
var subKeys = panel.add_TreeView();
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());return "ok";
//using Microsoft.Win32

Step 4:

panel.clear();
var subKeys = panel.add_TreeView();
RegistryKey currentUserKey = Registry.CurrentUser;subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 5:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                       
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 6:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                            currentNode.add_Node(keyName, currentKey.OpenSubKey(keyName));
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 7:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 8:

panel.clear();
var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 9:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 10:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                     tableList.add_Columns("Name");
                    
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 11:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                     tableList.add_Columns("Name"); 
                     foreach(var name in currentKey.GetValueNames())
                         tableList.add_Row(name);
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 12:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, currentKey.GetValue(name).typeName());
                     }
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 13:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 14:

panel.clear();
var tableList = panel.add_TableList("Registy Values of Selected Key");
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
//registryKeys.add_Node(Registry.ClassesRoot.Name, Registry.ClassesRoot ,true);  // this is quite resource intensive
registryKeys.add_Node(Registry.CurrentConfig.Name, Registry.CurrentConfig ,true);
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
registryKeys.add_Node(Registry.LocalMachine.Name, Registry.LocalMachine ,true);
registryKeys.add_Node(Registry.Users.Name, Registry.Users ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 15:

//panel.clear();
var topPanel =  O2Gui.open<Panel>("Registry Viewer", 600,400);
var tableList = topPanel.add_TableList("Registy Values of Selected Key");
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
//registryKeys.add_Node(Registry.ClassesRoot.Name, Registry.ClassesRoot ,true);  // this is quite resource intensive
//registryKeys.add_Node(Registry.CurrentConfig.Name, Registry.CurrentConfig ,true);
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
//registryKeys.add_Node(Registry.LocalMachine.Name, Registry.LocalMachine ,true);
//registryKeys.add_Node(Registry.Users.Name, Registry.Users ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 16:

This is what it looks like when executed

 

March 4, 2011 Posted by | Windows Tools | 1 Comment

Util – Font Viewer.h2

Here is a simple script that I wrote yesterday when I needed to quickly figure out how each Window’s font’s looked like.

It provides real-time preview of all existing fonts in both a TextBox and Label format.

The Gui looks like this:

 

Here is the source code (also included in O2 at: _Scripts\Utils\Windows\Util – Font Viewer.h2 )

//panel.clear();
//var topPanel = panel.add_Panel();
var bold = false;
var topPanel = O2Gui.open<Panel>("Font Viewer", 800,300); 
var leftPanel = topPanel.insert_Left<Panel>();
leftPanel.splitContainer().splitterDistance(250);  
var listBox = leftPanel.add_ListBox();
listBox.add_Items(System.Drawing.FontFamily.Families);
var fontSizeValue = listBox.insert_Above<Panel>(40).add_TextBox("Font size","10");
var baseText = topPanel.add_GroupBox("Original Text").add_TextArea().wordWrap(false);

var textboxWithSelectedFont = topPanel.insert_Below<Panel>().add_GroupBox("Transformed Text (inside a TextBox and as a Label)").add_TextArea();
var labelWithSelectedFont = textboxWithSelectedFont.insert_Right<Panel>(topPanel.width()/2).add_Label("");

Action showTextWithSelectedFont = 
 ()=>{
   var fontFamily = listBox.selectedItem<FontFamily>();
   textboxWithSelectedFont.font(fontFamily,fontSizeValue.get_Text());  
   labelWithSelectedFont.font(fontFamily,fontSizeValue.get_Text());
   if (bold)
   {
    textboxWithSelectedFont.font_bold();
    labelWithSelectedFont.font_bold();
   }
  }; 
fontSizeValue.parent().add_CheckBox("Bold", 20,0,
       (value)=>{
          bold=value;
          showTextWithSelectedFont();
          });
listBox.SelectedValueChanged+= (sender, e)=> showTextWithSelectedFont();
fontSizeValue.onTextChange((text)=> showTextWithSelectedFont());
 
baseText.onTextChange(
 (text)=>{
    textboxWithSelectedFont.set_Text(text);
    labelWithSelectedFont.set_Text(text);
   });
  
listBox.selectFirst();
//set demo data
baseText.set_Text("This is some text (with real time preview)");


return PublicDI.CurrentScript;

November 2, 2010 Posted by | Windows Tools | Leave a comment