+ All Categories
Home > Technology > Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional People - DerbyCon 4

Date post: 29-Nov-2014
Category:
Upload: ben-ten-0xa
View: 329 times
Download: 5 times
Share this document with a friend
Description:
The best hackers are those that can write their own tools or modify existing ones. Regardless of whether you are blue team- red team- purple team- white hat- gray hat- or black hat- PowerShell should be in your repository of tools. While I encourage people to learn other languages as well- PowerShell is a dynamic tool and should not be overlooked. This talk is meant to be an introductory (101) session for PowerShell. I will be giving you a crash course in PowerShell scripting that will equip you to create practical PowerShell scripts for defense- offense- and even some fun things to mess around with people. This talk is designed for anyone who has never done any PowerShell or just starting to learn. Bring your laptop with PowerShell 3.0 or later- and your favorite text editor (like SublimeText) installed so you can script along with me. You will be able to write a functioning PowerShell script by the end of this talk! Come see the potential power you can unlock by learning PowerShel.
106
Practical PowerShell Programming for Professional People Ben Ten (@Ben0xA) Slides: http://www.slideshare.net/BenTen0xA DerbyCon 2014
Transcript
Page 1: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programmingfor

Professional People

Ben Ten(@Ben0xA)

Slides: http://www.slideshare.net/BenTen0xA

DerbyCon 2014

Page 2: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

About Me

Ben Ten (0xA)@Ben0xA - twitter

Chicago - #burbsecVice PresidentSecurity OfficerDeveloperPoshSec Framework Developer / CreatorGamerGeek

Page 3: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 4: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 5: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 6: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 7: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 8: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 9: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 10: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 11: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 12: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 13: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 14: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 15: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

SecurityFail

Page 16: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Overview

● Languages and Development● PowerShell Scripting ● Resources● Q&A

● PSA: This is mostly live code scripting in PowerShell. Please code along with me!

Page 17: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Overview

Feel free to interrupt and ask questions!

Page 18: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Before we begin, a bit of a primer!

● Styles of Coding● Syntax● Getting Help● Starting Out

Page 19: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Styles of Coding/Scripting/Development

● Novice● Avid Scripter● Full Time Developer● Code Monkey

Page 20: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Styles of Coding/Scripting/Development

● Novice● Avid Scripter● Full Time Developer● Code Monkey

Page 21: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Syntax

syn•tax (sĭn tăks ) – the rules that govern ˈ ˌhow a script, or program, is developed in a given language.

Page 22: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Syntax

White Space, parens (), commas, periods, quotes (“ vs '), tabs, braces [], curly brackets {}, colons :, semi-colons ;, all play an integral part in the syntax of a language!

Page 23: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Getting Help!

RTF Manual/Docs/Reference

Often times, the documentation will have an answer for what you are trying to accomplish. *NOT ALWAYS THOUGH*

Page 24: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Getting Help!

Interactive Help

● ?● F1● Intellisense (Ctrl+Space)● Get-Help

Page 25: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Getting Help!

Search Engines FTW!

Google is not the end all in searches. For Development I prefer DuckDuckGo!

https://duckduckgo.com

Page 26: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

Page 27: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Languages and Development

@JimmyVo – DuckDuckVo!

Page 28: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Overview

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework.

Page 29: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Overview

PowerShell was designed by :● Jeffrey Snover (@jsnover)● Bruce Payette (@BrucePayette)● James Truher

Initial release was November 14, 2006

Page 30: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Overview

PowerShell is a part of the Windows Management Framework. WMF 5.0 was released on April 3, 2014.

For today's scripting we will be using WMF 3.0.

Page 31: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

You will need:

● Windows Management Framework 3.0● Microsoft .NET Framework 4.5● Text Editor (your choice)

● Sublime Text http://www.sublimetext.com/

● Komodo Edit http://komodoide.com/komodo-edit/

● PowerShell ISE (comes with WMF)

Page 32: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

File Name Extensions

.ps1 – Script Files

.psm1 – Script Module Files

.psd1 – Script Manifest Files

.ps1xml – Formatting and Type Files

.dll - Cmdlet and Provider Assemblies

Page 33: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

File Name Extensions

.ps1 – Script Files

.psm1 – Script Module Files

.psd1 – Script Manifest Files

.ps1xml – Formatting and Type Files

.dll - Cmdlet and Provider Assemblies

Page 34: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Cmdlets, Functions, and Scripts Oh My!

From a functional standpoint, cmdlets, functions, and scripts are practically the same.

They are a way to call a specific block of code.

Page 35: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Cmdlet:

Written in a compiled .NET language.Easier to deploy.Help files are easier to write.Has support for parameter validation.

Page 36: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Function:

Written in a PowerShell language.Has to be deployed with a library.Help is written inside the function.Parameter validation has to be done in the function itself.

Page 37: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Script:

Written in a PowerShell language.Is invoked by calling the .ps1 file.Deployed by itself or in a manifest file.Can contain functions.

Page 38: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Set-ExecutionPolicy

Before you can run your custom scripts you have to set the ExecutionPolicy to RemoteSigned.

In PowerShell type:Set-ExecutionPolicy RemoteSigned

Page 39: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

Page 40: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

PowerShell

HelloWorld.ps1

Enough of the primer! Let's get coding!

This is where you code along with me if you can!

Page 41: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 42: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 43: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 44: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Variable(s):

a symbolic name associated with a value and whose associated value may be changed.

Page 45: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Hard-Coded:

Typing the value directly into your script. Our “Hello World” text was hard-coded.

Page 46: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

PowerShell Variables:

A PowerShell variable is defined with the dollar sign $ followed by the name of the variable.

For example: $message is a variable.

Page 47: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

PowerShell Variables:

Let's rewrite our HelloWorld.ps1 to use a variable $message with our text “Hello World”.

Page 48: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 49: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 50: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 51: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 52: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Quotes! Single vs Double

Double Quotes (“) will attempt to resolve any variables before anything is printed to the screen.

Single Quotes (') will print exactly what is typed between the quotes.

Page 53: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 54: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 55: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 56: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 57: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Backtick `

The backtick, or grave accent, is a special escape character. This means that you want the next character to be printed and not interpreted in anyway.

Page 58: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 59: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 60: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 61: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

HelloWorld.ps1

Page 62: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Getting Input

Write-Output is great. But how do you get information from a user?

Read-Host

Page 63: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Getting Input

Page 64: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Getting Input

Page 65: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Condition is:

a feature of a programming language which perform a different set of computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.

Page 66: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Condition is:

Is the stop light is green? Keep going.Is the stop light is red? Stop.Is the stop light is yellow? Floor it!!!!

Page 67: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Condition expressed:● If - Beginning of the condition.● Else - Evaluates only if preceding condition(s)

is(are) false.● ElseIf – Evaluates if preceding condition(s)

is(are) false with a new condition.

● Switch – Multiple conditions for a single variable or object.

Page 68: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Conditional Operator:

-and = both conditions must be true.

-or = only one of the conditions must be true.

Page 69: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Conditional Operator:

-eq = Equals-lt = Less Than-gt = Greater Than-ne = Not Equal-ge = Great Than or Equal-le = Less Than or Equal

Page 70: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

A Conditional Operator:

-Like-NotLike-Match-NotMatch-Contains-NotContains

-In-NotIn-Replace

Page 71: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 72: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 73: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Operator Precedence:

When operators have equal precedence, Windows PowerShell evaluates them from left to right. The exceptions are the assignment operators, the cast operators, and the negation operators (!, -not, -bnot), which are evaluated from right to left.

Page 74: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Operator Precedence:

You can use enclosures, such as parentheses, to override the standard precedence order and force Windows PowerShell to evaluate the enclosed part of an expression before an unenclosed part.

Page 75: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 76: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 77: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 78: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Conditional Logic

Page 79: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Parameters

A Parameter is:

A variable that allows you to pass an object to a Cmdlet, Function, or Script.

Get-ChildItem

Page 80: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Parameters

Page 81: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Parameters

Get-Help Get-ChildItem

Get-ChildItem [[-Path] <String[]>] [[-Filter] <String>] [-Exclude <String[]>[-Name] [-Recurse] [-UseTransaction [<SwitchParameter>]] [<CommonParameters>

Get-ChildItem [[-Filter] <String>] [-Exclude <String[]>] [-Force] [-Include-LiteralPath <String[]> [-UseTransaction [<SwitchParameter>]] [<CommonParame

Get-ChildItem [-Attributes <FileAttributes]>] [-Directory] [-File] [-Force][-UseTransaction] [<CommonParameters>]

Page 82: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Parameters

Page 83: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Parameters

Page 84: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Objects vs Text

PowerShell is Object Based.

Even if you see text on the screen, that text is actually a “String” object.

You can access the members of the object using the . operator after the variable name.

Page 85: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Objects vs Text

Page 86: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Piping

Piping is:

a way of moving something, unchanged, from one place to another.

Page 87: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Piping

Piping is represented by the | (pipe) character.

A pipe takes the object from the left side and passes it to the right side.

Note: When passing to another cmdlet, $_ is used to reference the passed object.

Page 88: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Piping

Page 89: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Piping

Page 90: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Loops

Loops:

A way to perform the same block of code for a specific number of times, until a specific condition is met, or while a specific condition exists.

Page 91: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Loops

Loops:

● ForEach● ForEach-Object● For● While● Do While● Do Until

Page 92: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Loops

Page 93: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Loops

Page 94: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Loops

Page 95: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Comments

Comments are defined by the # symbol.Block comments are enclosed with <# and #>.

.SYNOPSIS

.DESCRIPTION

.PARAMETER

.EXAMPLE

Page 96: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Comments

Page 97: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Putting it all Together

The final program!

Requirements:● Search all files.● Find the ones that were modified in a specific date range.

● Create a list of those files and display them.

Page 98: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Pitfalls

Don't overuse the Pipe! Not everything has to be done in a single line.

It's more important that you understand the code before you try to condense it to a single line.

Page 99: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Pitfalls

With Loops, start small then open the valve all the way!

You can get more than you wanted, or get stuck in an endless loop.

Especially true when doing File operations!

Page 100: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Resources

Freenode (irc.freenode.net)#PowerShell, #pssec, #poshsec channels.

Learn Windows PowerShell in a Month of Lunches ~ Don Jones

Carlos Perez – PowerShell Workshop at DerbyCon.

Page 101: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Resources

PoshSec – https://github.com/PoshSecPoshSec Framework

PowerSploit – https://github.com/mattifestation/

Posh-SecMod – https://github.com/DarkOperator/

Page 102: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Resources

http://www.slideshare.net/BenTen0xA/

practical-powershell-programming-for-professional-people

Page 103: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Thanks!

@securitymoey@jaysonstreet@DerbyCon@tonikjdk@darkoperator@mattifestation@obscuresec@harmj0y

Page 104: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Contact - Q&A

Ben Ten (0xA)@Ben0xA - twitterhttp://ben0xa.comhttps://[email protected] – LinkedIn, Github, keybase, etc.

irc.freenode.net#burbsec, #poshsec, #pssechttp://www.slideshare.net/BenTen0xA

QUESTIONS?!

Page 105: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Thank You!

Page 106: Practical PowerShell Programming for Professional People - DerbyCon 4

Practical PowerShell Programming for Professional PeopleDerbyCon - Ben Ten (@Ben0xA)

Thank You!


Recommended