Friday, 9 November 2012

Viewing 'Console Out' messages created inside UserControls (when rendered by VisualStudio's Form Designer)

Now that we have the ability to Add 'Console Out' to VisualStudio IDE as a native Window the question is: "Where can we use Console.WriteLine inside VisualStudio?",  in a way that the written lines/chars show in that Console Out window:




The key to understand the question is to visualize this:

  • The Console Out window is running inside VisualStudio (i.e. in the same process)
  • The Console Out window script captured the VisualStudio process' Console Out (of which there is only one, and the reason why if you open multiple Console Out windows (as shown above) only the last one opened will capture the output
  • To send a message to Console Out window the sender (i.e. the code executed) must be inside the same VisualStudio Process
  • This means that (based on quick tests) VisualStudio scripting engines (like the Immediate Window or the F# interpreter) will not work (since they are running outside the VisualStudio process)
One easy way to trigger an Console.WriteLine is to write it in one of the C# REPL script GUIs (from the O2 VisualStudio Extension) :)


But what would be really useful would be to trigger Console.WriteLine debug messages during normal VisualStudio development, for example when programming WinForms Controls :)

To show how that is possible, lets start with an empty WinForms Application project:


Which comes with default WinForms Form:


Next add a UserControl with a Label:


And add that UserControl to the Form:


The interesting part of what just happened, is that VisualStudio invokes the constructor of the UserControl1.cs (in order to create a live instance of that Control) before adding it to the Form1.cs object.

And that (the UserControl1.cs constructor) is where we can trigger the Console.WriteLine calls.

Open the Code Behind file for the UserControl1.cs file:


Write a Console.Write message and build the project (note the message shown in the Console Out window)


The reason that happened, is because (after a successful build) VisualStudio needs to refresh the controls currently shown in the Form's Designer (for example to take into account any visual changes in those controls)

Here is another way to trigger the Console.WriteLine call (i.e. to trigger the UserControl.cs constructor).

Close Form1.cs from the Form Designer:


And the open it again:


Yet another option is to delete the UserControl1.cs from the Form1.cs:



And add it back again:


Basically, the UserControl1.cs constructor will be invoked every time that control is added (or shown), like in the image below, where another instance of UserControl1.cs was dragged into the Form1.cs:


Interestingly enough, this as a number of security implications, since a security payload/exploit can be triggered just by adding/viewing a UserControl inside the Form Designer. The problem is that the payload will run with the same privileges given to VisualStudio (not the privileges used to run the application)

Adding 'Console Out' to VisualStudio IDE as a native Window

Michael Hidalgo has posted two blog entries where he uses the O2's VisualStudio Extension to open an Console Out window inside VisualStudio, which is then used to help with a quick test on the DateTime object (and making his life easier)

Micheal is using the API_ConsoleOut.cs (which you can read in more detail at API_ConsoleOut.cs – New and InProcess Capture of the Console Output ) to add a 'Console Out' Panel to a Form Window.

Now this Form object is a WinForms control and is not a native VisualStudio Window, which means that we can't add it to the VisualStudio Panes.


A better option is to make this a native VisualStudio Window, which is quite easy to do.

Open the C# REPL - VisualStudio 2010 API (from the REPL menu)



And with the VisualStudio_2010 object:



Create a native VisualStudio window (with a WinForms Panel inside it):


Use the same add_ConsoleOut extension method on the Panel object (the one returned by the open_Panel extension method):



And now the Console Out is now inside a native VisualStudio window, which we can access and manipulate.

Here is an example of changing the base window's width, height, top and left values:


Which of course we can now put anywhere inside VisualStudio's GUI



Next see the Viewing 'Console Out' messages created inside UserControls (when rendered by VisualStudio's Form Designer) for a practical example of using this technique during development.

Thursday, 8 November 2012

LucidChart.com looks like a pretty good Visio online replacement

Although this visualisation of TeamMentor's GitHub dev workflow is pretty good, it was created using Visio, and I really don't want to use Visio again (I'm done using large desktop apps with no web integration/publishing).

The good news is that :

  • Roman found LucidChart.com, 
  • he was able to import that complex Visio diagram into it, and 
  • the end-result looked good enough (after a couple import fixes). 

So I went to LucidChart.com to try it out :)

I have done a LOT of Visio diagrams (in the past), and I have to say that I found Lucid Chart's web interface really easy to use (and learn).

As a test, I imported an image from this blog, and was able to quickly create this:


Not bad for a couple minutes work :)

Is the TeamMentor's OWASP Library content released under an open License?

Following the FLOSSHack TeamMentor thread,  Jerry Hoff asked "Is the content in http://owasp.teammentor.net/teamMentor creative commons?  Can we use it to freely fill out more of the cheat sheets and use in tutorial videos and so forth?"

And the answer is: YES

Here is the repository for the XML files: https://github.com/TeamMentor-OWASP/Library_OWASP

FLOSSHack TeamMentor and the 'sausage making process' that is software/application development

OWASP's FLOSSHack events are a really powerful initiative.

"...Free/Libre Open Source Software Hacking (FLOSSHack) events are designed to bring together individuals interested in learning more about application security with open source projects and organizations in need of low cost or pro bono security auditing. FLOSSHack provides a friendly, but mildly competitive, workshop environment in which participants learn about and search for vulnerabilities in selected software. In turn, selected open source projects and qualified non-profit organizations benefit from additional quality assurance and security guidance...." 

See FLOSSHack_One for the details (and vulnerabilities discovered) of the first event.

OWASP's FLOSSHack is one of those 'magical' spaces where the OWASP's community and its projects can come together and add a lot of value.

Pretty cool visualisation of the 'GitHub based' TeamMentor Development+QA+Release workflow

Roman created this nice Visio diagram with out current 'GitHub based' workflow for TeamMentor:




The difference between being 'Appointed' and being 'Accepted' as an OWASP Leader (of its Fork)

OWASP is a community that really embraces new ideas, new contributors and projects.

For somebody motivated (and with time/energy) there are very few ‘real’ barriers on entry. Even the cases where it ‘feels’ like there are barriers of entry or ‘bureaucracy’, those are mainly artificial and easy bypassed (with the right level of energy and commitment)

The problem is Empowerment

What I found (by observing lots of OWASP projects starting, blossoming and dying) is that what makes the difference is how Empowered is an individual on a particular project/tasks.

Disabling PatchGuard V3 Pdf

Here is a good read (if you're into kernel dev or patching) from the guy who created EasyHook

I while back I did some kernel development where I used the Rasta Ring 0 Debugger to apply direct code patches to user-land dlls. One of the best PoCs was one where I was able to do MSIL patching on loaded .NET assemblies, which were completely invisible to user-land.

Patching the CLR was also very interresting :)

Tuesday, 6 November 2012

Zim-Wiki - a desktop wiki

Serge is using Zim Wiki to document some of his development experiences, and it looks quite an useful tool.

Zim is written in Python and has a nice/clean Gui.



Here is the Windows installer:



Another similar tool is http://keepnote.org/

An interesting and powerful idea is to add TeamMentor Import/Export features to these products so that  we (i.e. TM Users) can use these tools as Article creators/editors. 

Cleaning Data with Google Refine

@austinogilvie posted this nice Cleaning Data with Google Refine entry where it shows the Google Refine (soon to be called OpenRefine) project in action.

Google Refine in their own words is: "...a power tool for working with messy data, cleaning it up, transforming it from one format into another, extending it with web services, and linking it to databases like Freebase...."

Nice visualisation and animation of graph data (from NYTimes)

NYTimes 512 Paths to the White House is a very nice way to present complex data (I wonder if we could use something similar for TeamMentor, OWASP or O2 Platform's content)

Here is the default view:

Improving VisualStudio productivity by compiling and executing code from the IDE

The Real-time Programming C# WinForms Controls in VisualStudio's IDE (i.e. without using F5) blog entry shows how to use the VisualStudio C# REPL - O2 Platform extension to update/fix an existing WinForms control without going through the painful (and slow) process of VisualStudio GUI programming.

What you will see in that example is that I will dynamically compile and execute a WinForms Control, without using VisualStudio's Debug/Run capabilities to see the new changes in action. I was able to compile the modified Source Code file, and using reflection, was able to create a new instance of an WinForm's Control (without leaving the VisualStudio's IDE).


And the best part is that we can code our tests in an REPL environment (think Roslyn), which allows the support for complex (and unit-test like) scenarios.

I can't underestimate how powerful, fast and efficient it is to be able to have this type of REPL environment while coding.

This is what I would like to see on the next version of VisualStudio.

Real-time Programming C# WinForms Controls in VisualStudio's IDE (i.e. without using F5)

Here is an example of using the VisualStudio C# REPL - O2 Platform extension to update/fix an existing  WinForms control without going though the painful (and slow) process of VisualStudio GUI programming, which usually goes something like this:

  • Coding + Compiling + F5 + Wait for App to Load + Going to Control + Testing it + Stopping 
  • Coding + Compiling + F5 + Wait for App to Load + Going to Control + Testing it + Stopping 
  • Coding + Compiling  + ....

We start with the O2 Platform Solution loaded in VisualStudio 2010, with the projects from the O2.FluentSharp and O2.Platform.Projects repositories, and the VisualStudio C# REPL - O2 Platform extension installed (note the extra REPL menu)


From the REPL menu, chose the C# REPL - 'Hello World' menu option:


Which looks like this (it's a good idea to right-click on the code editor to open the context menu, and to select the show Log Viewer option:


Here is a small text change to show the C# REPL environment in action


Now here is the powerful part, this script:

Will create a new popup window with the ascx_Simple_Script_Editor WinForms Control (that was just dynamically compiled from the original source code (note: the ascx_Simple_Script_Editor Control is the one used to create the C# REPL environment))



What is happening is that the ascx_Simple_Script_editor.cs file (whose source code is shown in the background) was dynamically compiled and executed .... without leaving the VisualStudio's IDE.


Just to double-check that we are doing this in real time, lets make a small code change in the  ascx_Simple_Script_editor.cs source code (using VisualStudio's code editor).

The code shown below will create two MessageBox(es). The first was created using the normal .Net MessageBox call syntax,  and the 2nd uses O2's FluentSharp API (which should be easier to read)


Here is the 1st MessageBox:


Here is the 2nd MessageBox:


The ascx_Simple_Script_Editor WinForms Control will appear after the MessageBox(es):



Now that we've proven that we are able to change, compile and execute a C# WinForm's control in a REPL environment, let's do something more interesting.

Moving a ToolStrip Control

One of the O2 Platform user's feature requests that I have received for this control (the one that we are editing), is to move the ToolStrip Control  (the one with the New, Open and Save As buttons) from the bottom of the Control,  to the top (which is where usually ToolStrips are located).

Going back to the VisualStudio document with the ascx_Simple_Script_editor.cs source code, here is the addToolStrip method that 'inserts below' the commandsToExecute Control an ToolStrip Control (the rest of the addToolStrip method adds the TootlStrip items (3x Buttons, 1x Label and 1x TextBox)


To change the location of the ToolStrip Control, we will use the FluentSharp insert_Above Extension Method  (vs the originally used insert_Below Extension Method)  :


Once the change is saved, we can immediately see these changes in action, by using the REPL environment created via the gist script shown above..

Here is the updated version of the ascx_Simple_Script_editor Control with the ToolStrip Control at the top.


Note that I didn't use VisualStudio's Debug/Run capabilities to see the new changes in action. I was able to compile the modifed Source Code file, and using reflection, was able to  create a new instance of that WinForm's Control (with everything done inside VisualStudio's IDE).

Adding a new Button

As a final example, lets add a Run button to the ToolStrip Control.

Here is the updated source code (note the new add_Button line)


Once saved , complied and executed (not by VisualStudio), we can see that there is a Run button on the ToolStrip.

Here is the button being used to execute a test REPL script:



VisualStudio power is still all there

Another benefit of this technique/workflow is that we still have access to the powerful VisualStudio Intellisense and Error detection:



Compiling and executing the Solution

The final step is to compile the Solution file (with the changes made)


And run the O2 Platform executable (now using VisualStudio's F5).

Note how the O2 Platform's native C# REPL editor now has the changes made to the ToolStrip Control (it is above the code-editor and has an extra Run button)



This technique will change the way you code (once you got your head around it)

I can't underestimate how powerful, fast and efficient it is to be able to have this type of  REPL environment while coding (and how painful is the VisualStudio workflow in comparison).

In fact, this REPL environment is a curse, since once you tried it, there is no way back! :)

This is why I say that I develop O2 in O2 :)

TM - Library Manager (with REPL) v1.2.4.exe

Here is a (still quite raw) Library Manager for TeamMentor with REPL support (packaged as an O2 Platform stand-alone exe).

You can download this version from: TM - Library Manager (with REPL) v1.2.4.exe

Monday, 5 November 2012

Using HawkEye to find control to Script (Findings Viewer example)

Here is an O2 Script/API that helps to find the control to script (via the script_Me extension method)

Let's say that you have a script that opens a Findings Viewer:


Which looks like this:


By adding a reference to the API_HackEye.cs you can call the openControlFinder (via the new REPL menu added)


This will open up a popup window with the HawkEye


Drag the eye (i.e. the target icon) on top of a control to see its properties, and click on the 'Open ScriptMe for this control' link:



This will open a script editor, with the selected object passed as a parameter:


Note that this will only work for WinForm controls that exist in the current .NET process.


Source Code:

The best technical history of Windows technologies and APIs

This (long) article is simply spectacular: Turning to the past to power Windows' future: An in-depth look at WinRT

It provides a deep technical analysis of the history of Microsoft's released OSes and APIs, taking into account their technologies and (internal to MS) political ramifications.

Peter Bright also takes a stab at creating a better diagram of Windows 8 Metro vs Desktop apps, which I agree makes more sense:


This diagram adds a couple clues to the questions I asked Windows Store/Metro Apps - A 'client-server' sandbox built using Javascript? and raises a couple more (for Metro Apps):

  • So is the CLR running under the same process of Metro apps?
    • And if so, which CLR? the 4.5?
    • And if C# code is running under that CLR, is that full-trust or partial trust?
    • In that CLR, is the Verifier enabled?
  • And if that C# code (or any other .Net code) is running under full-trust, surely then the only 'limitations' of that code are the ones imposed by the user account and its UAC/privilege-level (since it will be possible to jump into 'unmanaged code')
  • On the topic of UAC, are UAC security boundaries in Windows 8? Since in the past they were not
  • Can we write IL code (i.e. non VS created IL) on Metro Apps?

Why I stopped using Gaug.es (and the problem of being a feature)

As you can see by Gaug.es is Amazing - Just added RealTime website tracking to TeamMentor I was pretty excited about Gaug.es, and since I'm now looking for Website Monitoring Services, a good question is 'Are you still using Gaug.es and can it be used for WebSite monitoring?'

The short answer for the 'Are you still using Gauges' part is that Google Analysis killed it

The short answer for the 'can it be used for WebSite monitoring' part is: NO

Gaug.es had one feature that was really powerful: the real-time visualisation of web traffic (which was really good and I even got for a while a paid subscription)

But once I was able to get the same data from Google Analytics, the value of Gaug.es plummeted.



Since I had such a good experience with Gaug.es (via their customer service and presentation), I did made a bit of an effort to get more value from it, but:
  • the data analysis that they provided on their GUI was very limited, 
  • there was no power-user analysis and 
  • their API support (and language support) was quite limited.
One area that Gaug.es could had entered was the data/website monitoring and analysis (which is what I need now).

For example, they have enough data to identify problems with a particular website. But that would change their current model and I understand why they want to keep providing a simple (and easy to use) service.

The problem is that when you are a feature not a product (as Steve said to Dropbox) you have to make sure you are better than the equivalent features in the products out there (Dropbox will need to keep innovating if they want to stay relevant)

In a way Gaug.es failed to innovate. They were able to get a head start on Google Analytics and should had continued adding features. I think they are owned by github, so maybe the key Gaug.es devs are the ones making GitHub.com even better.

And if I have to choose between a better GitHub vs a better Gaug.es, GitHub will win every time :)

Securing Frames with Html 5 and examples of Html 5 vulns (and fixes)

On the topic of Html 5 , here is a nice How to Safeguard your Site with HTML5 Sandbox article which comes with a https://github.com/writeline/HTML5-Sandbox-Demo sample.

Also really good is the Defense in Depth: HTML5 Sandbox page from Microsoft's IE team which shows a couple vulnerabilities (and how they can be mitigated):


One question I have on these Html 5 protections is: What about ClickJacking?

Sunday, 4 November 2012

Html 5 Sandbox site

Here is a cool site that can be used to try Html 5 (and its security features): http://htmlsandbox.com

Here is the default UI: