This talk was about the powerful ability to perform advanced tasks through PowerShell and how you can utilize PowerShell on penetration tests.
Splunk enables you to search, report, monitor and analyze streaming and historical data from any source across your entire IT infrastructure. Plus, a Splunk PowerShell snap-in.
I’ve been working with OData and decided to build, and make available on CodePlex, an OData PowerShell Explorer that let’s you access and drill down on a service from either the command line or the GUI.
The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today.
One of the many interesting parts of this open source module is, it is a GUI written in PowerShell built on top of PowerShell code. You can either use the GUI to navigate the data or do it directly at the command line. Both are driven by the OData PowerShell module.
Another interesting note is the GUI’s ‘Drill Down’ buttons dynamically change depending on which service and collection you are viewing.
Same goes for the command line objects. The objects methods are dynamically built on the fly as you navigate the details of a collection and drill down.
Using the PowerShell WPK GUI with OData Services
Using the PowerShell Command Line with OData Services
Great Automation Story
Using the OData PowerShell module at the command line blends the power of Open Data Protocol for sharing and PowerShell’s great range of cmdlets to slice, dice, transform and store data.
In a few lines of PowerShell you can fetch information from several data services and then export them to Excel, Databases, XML and more.
Query Options
The PowerShell OData module also supports OData query options like $expand, $filter, $top, $skip and more. So for example you could do this:
Import-ModuleC:\CodePlex\psodata\trunk\modules\OData.psm1$netflix=New-ODataService"http://odata.netflix.com/Catalog"$netflix.People("`$filter=endswith(Name, 'Abbott')")# ResultsId Name
-- ----
189 Bruce Abbott
190 Bud Abbott
196 George Abbott
20006674 Mark Abbott
20013692 Philip Abbott
20017929 John Abbott
20018086 David Abbott
20031575 Abdul Malik Abbott
20038388 Diahnne Abbott
20045891 Annie Abbott
20057657 Jennifer Abbott
20057988 Norman Abbott
.....
There are many ways to subset the data. This is faster because there is less data returned from the remote server. An alternative would eliminate the $filter query option and use PowerShell’s Where-Object {$_.name.EndsWith(‘Abbott’)}. The tradeoff being that all the data is fetched from the server and then subsetted.
Summary
I’ll continue to grow the PowerShell module to encompass additional features and surface them in the GUI as well.
Meanwhile grab the code and let me know what you think.
Note the New-Object Net.WebClient. Tapping into the .NET framework
Notice the 5th line of the first version, the one with the .Split(‘|’), showing off PowerShell’s ability to assign variables in succession
Both versions return an array of objects (.NET objects), each object has two properties. CountryCode, CountryName
# ResultsCountryName CountryCode
----------- -----------
AF Afghanistan
AL Albania
DZ Algeria
AS American Samoa
AD Andorra
AO Angola
AI Anguilla
AQ Antarctica
It’s safe to say that with C# and System.Net it’s just a bit longer. Not that much longer – but you’d have to have a pretty practiced hand to get through the "machine noise" that begins to creep in. – Rob Conery
Code blocks and closures are nothing new to programming – you can find them in most OO (object oriented) languages – Rob Conery
PowerShell has them too
What we call scriptblocks in PowerShell are called anonymous functions or sometimes lambda expressions in other languages. A number of languages, including Python and dialects of LISP, still use lambda as a language keyword.
This example shows how to use PowerShell scriptblocks to reduce repetitive code. It is also the application of the DRY Principle, Don’t Repeat Yourself.
The code works but it’s not pretty and repeats itself. Also, say you were to change the name of the dataset from ChinookDataSet to TempDataset you’d have to do it in two places. Let’s improve it.
Here we are calling the Parse-Key function and passing in the name of the key we want, Artist. We are also passing in a scriptblock. In the ForEach, we use the call operator & to execute that scriptblock and leverage closures. The $_is evaluated in the context of the ForEach in Parse-key function.
A closure is a first-class function with free variables that are bound in the lexical environment.
$url="http://api.nytimes.com/svc/politics/v3/us/legislative/congress/111/house/members/leaving?api-key=$apiKey"$wc=New-ObjectNet.Webclient$xml=[xml]($wc.DownloadString($url))$xml.result_set.results.members.member|groupparty-NoElement# ResultsCount Name
----- ----
26 D
22 R
The company I was with for the last 3 years went bananas. Seems they merged with a new company and migrated their client base.
The migration was less than optimal. Slower network and they lost a bunch of my data. Every interaction with customer support was turned around saying I had a browser problem, cookie issues or network delays on my side.
is my new home. Their sales people responded to all my inquires and their performance/customer support is great so far. They responded in under 5 minutes on a Sunday morning, accurately pointing me to information.
I heard the same thing about VBScript years ago, about C++ a decade earlier, and being aware that I am dating myself here, about C, Pascal, Windows Programming, VI, Emacs, punch cards, VT100 terminals and about rubbing two sticks together to start a fire.
Based on the ancient art of origami, the sheets are edged by foil actuators–thin, solid-state motors–that contract or expand when they receive an electric current from flexible electronic circuits embedded in the sheets. After they achieve their preprogrammed shape, the sheets are held in place by tiny magnets on the edges of the fold joints.
MSDN Webcast: geekSpeak: PowerShell for .NET Developers with Doug Finke Read more ...
About
Doug Finke is a Microsoft Most Valuable Professional (MVP) for PowerShell. He lives and works in New York City building applications for the financial industry. Read more about Doug...