SlideShare ist ein Scribd-Unternehmen logo
1 von 55
GET-HELP
An intro to PowerShell and how to use it for evil
PS C:>WHOAMI
 Jared Haight
 Security Engineer with the CLT team at Gotham Digital Science
 Former Sysadmin
 Hobbyist Developer
 Corgi Enthusiast
 @jaredhaight
WHY AREWE HERE?
 I think PowerShell is pretty awesome
 I want you to think PowerShell is pretty awesome
 I’m going to give you a bunch of reasons that PowerShell is pretty
awesome
WHY SHOULDYOU CARE
ABOUT POWERSHELL
Or “How I justified this talk to BSides Charleston”
REDTEAMS
 PowerShell is what the admins use to manage their infrastructure
 Microsoft is pushing more and more tasks into PowerShell
 Standard onWindows 7 and up
 Robust, object oriented scripting language with access to a wide range of
things on the computer
 Access to entire .NET andWMI frameworks
 Lots of very interesting offensive projects going on
 BlueTeams aren’t typically looking for it
BLUETEAMS
 It’s what the bad guys are using.. like.. real ones.
 There’s some really cool DFIR stuff going on with Powershell
WHAT DO I NEED TO KNOW
TO USE POWERSHELL?
Scripting for people whose idea of server administration is next > next > finish
VOCABULARY
 String – Any combination of letters and numbers that are surrounded by
quotation marks (single or double). Used for printing stuff.
 Example: “a”, “abc”, “abc123”, “123”
 Integer – A number without quotes. Used for math.
 Example: 1, 2, 3, 5
 Boolean –True or False, represented in PS as $True or $False
 Variable – A reference to a value that can be assigned over the course of a
script/program. Declared in PowerShell with as $[word], ex: $foo
OBJECTS
 An object is a type of “something”.
 As an object of a specific type, it inherits properties and methods related to
it’s object type
 Properties – Information about the object
 Methods – Code that interacts with the object
 For example, strings have properties for length and methods to change the
case of their letters.
ARRAYS
 A list of objects separated by commas
 Example: “one”,”two”,”three”
 You can access specific items in the array by using index numbers
 Index starts at zero
CMDLETS
 Primary way of getting things done in PowerShell
 Always in a “verb-noun” format
 Examples
 write-host – print something to screen
 get-process – get running processes
 set-clipboard – copy something to clipboard
 get-eventlog – get contents of eventlog
POWERSHELL SPECIFICS
 Most everything is tab completable
 Cmdlets
 Parameters
 ParameterValues
 PowerShell ISE
 “Integrated Scripting Editor” installed by default with PowerShell
 IncludesVisual Studio like auto-completion (intellisense)
 Sidebar featuring all available cmdlets
POWERSHELL ISE
BUNNY BREAK
MAKING STUFF DO STUFF
FOR LOOPS
Code
1 $list = "one", "two", "three"
2 forEach ($item in $list)
3 {
4 write-host * $item
5 }
Output
* one
* two
* three
FOR LOOPS – PRACTICAL EXAMPLE CODE
1 $dirs = Get-ChildItem C:
2 forEach ($dir in $dirs)
3 {
4 write-host $dir.FullName
5 write-host "-----”
6 $acl = $dir.GetAccessControl()
7 write-host $acl.AccessToString
8 write-host
9 }
FOR LOOPS – PRACTICAL EXAMPLE OUTPUT
[...]
C:repos
-----
BUILTINAdministrators Allow FullControl
NT AUTHORITYSYSTEM Allow FullControl
BUILTINUsers Allow ReadAndExecute, Synchronize
NT AUTHORITYAuthenticated Users Allow Modify,
Synchronize
NT AUTHORITYAuthenticated Users Allow -536805376
C:Sandbox
-----
NT AUTHORITYAuthenticated Users Allow FullControl
Everyone Allow FullControl
[...]
LOGIC
 Logic in programming amounts to “if foo is true, do bar”
 You can compare things in PowerShell with:
 -lt – Less than
 -le – Less than or equal to
 -eq – Equal to
 -ne – Not equal to
 -ge – Greater than or equal to
 -gt – Greater than
LOGIC – IF/ELSE STATEMENTS
1 $nums = 1,2,3,4,5,6,7,8,9,10
2 forEach ($num in $nums)
3 {
4 if ($num -eq 4)
5 {
6 write-host $num is four.
7 }
8 else
9 {
10 write-host $num is not four.
11 }
12 }
Output
1 is not four.
2 is not four.
3 is not four.
4 is four.
5 is not four.
6 is not four.
7 is not four.
8 is not four.
9 is not four.
10 is not four.
Code
LOGIC –WHILE LOOPS
Code
1 $i = 1
2 while ($i -le 4)
3 {
4 write-host $i
5 $i = $i + 1
6 }
Output
1
2
3
4
FIGURING STUFF OUT
 Get-Command [Search term]
 Example: get-command “*clipboard”
 Get-Help “Command”
 It gets help.
 Example: get-help write-host
 Example: get-help write-host –examples
 Get-Member
 Pipe an object to it to find out the objects properties and methods
 Example $dir | get-member
GET-MEMBER OUTPUT
PS C:> $dir | Get-Member
TypeName: System.IO.FileInfo
Name MemberType
---- ---------- ----------
Mode CodeProperty System.String Mode{get=Mode;}
AppendText Method System.IO.StreamWriter[...]
CopyTo Method System.IO.FileInfo[...]
Create Method System.IO.FileStream Create()
CreateObjRef Method System.Runtime.Remoting[...]
CreateText Method System.IO.StreamWriter[...]
Decrypt Method void Decrypt()
Delete Method void Delete()
[...]
BUNNY BREAK
PUTTING IT ALL TOGETHER
PUTTING IT ALLTOGETHER
1 1 $dirs = Get-ChildItem C:
2 ForEach ($dir in $dirs)
3 {
4 $i = 0
5 $acl = $dir.GetAccessControl()
6 while ($acl.Access[$i] -ne $Null)
[...]
PUTTING IT ALLTOGETHER (BREAK DOWN)
[...]
9 $ace = $acl.Access[$i]
10 if ($ace.IdentityReference.Value.contains("Everyone"))
11 {
12 write-host $dir.FullName
13 write-host "-----“
14 write-host $ace.IdentityReference.Value:
$ace.FileSystemRights.toString()
15 write-host
16 }
17 $i = $i + 1
[...]
1 $dirs = Get-ChildItem C:
2 ForEach ($dir in $dirs)
3 {
4 $i = 0
5 $acl = $dir.GetAccessControl()
6 while ($acl.Access[$i] -ne $Null)
8 {
9 $ace = $acl.Access[$i]
10 if ($ace.IdentityReference.Value.contains("Everyone"))
11 {
12 write-host $dir.FullName
13 write-host "-----“
14 write-host $ace.IdentityReference.Value:
$ace.FileSystemRights.toString()
15 write-host
16 }
17 $i = $i + 1
18 }
19 }
PUTTING IT ALLTOGETHER (OUTPUT)
C:Sandbox
-----
Everyone : FullControl
C:Users
-----
Everyone : ReadAndExecute, Synchronize
DOING FUN STUFF WITH
POWERSHELL
I may have a strange definition of “fun”
REGISTRY FUN – REGISTRY AS A DRIVE
PS C:> cd HKCU:
PS HKCU:> cd .SOFTWARE
PS HKCU:SOFTWARE> dir Micro*
Hive: HKEY_CURRENT_USERSOFTWARE
Name Property
---- --------
Microsoft
Microsoft Corporation
Microsoft Studios
REGISTRY FUN – CREATING ENTRIES
# Does the key exist?
PS HKCU:SOFTWARE> test-path "BSidesCHS"
False
# Create key
PS HKCU:SOFTWARE> new-item "BSidesCHS"
Hive: HKEY_CURRENT_USERSOFTWARE
Name Property
---- --------
BSidesCHS
# Create item in key
PS HKCU:SOFTWARE> New-ItemProperty -path .BSidesCHS -Name Demo
-PropertyType String -Value "TextGoesHere"
REMOTE FUN
 Most (all?) cmdlets understand UNC paths
 test-path serversharetest.txt
 A lot of cmdlets support the –ComputerName parameter.
 stop-service spooler –ComputerName demo-dc01
 WinRM makes everything better
 Microsofts Remote Management service
 enter-pssession demo-dc01
 invoke-command –ComputerName demo-dc01 “{code}”
PUPPY BREAK
EVIL
WHAT CAN WE BREAK?
 There is a lot of really impressive work going into offensive PowerShell
frameworks.
 Recon
 Backdoors
 Shellcode
 Exfiltration
 Privesc
 Lots of very smart and devious people working on PowerShell frameworks
 Big focus on “in memory” attacks.
 Don’t touch the disk, don’t trip AV.
USING A FRAMEWORK
 Clone the repo
 Run “Import-Module $repo”
POWERSPLOIT
 https://github.com/PowerShellMafia/PowerSploit
 Modules
 AV Bypass
 Code Execution
 Exfiltration
 Mayhem
 Persistence
 Recon
 Script Modification
COOLTHINGS IN POWERSPLOIT
 Exfiltration
 Invoke-NinjaCopy – Copies a file from NTFS by reading the raw volume
and parsing NTFS structures
 Inoke-Mimikatz – Loads Mimikatz into memory and runs it. Doesn’t
touch disk when run against a remote computer.
 Get-GPPPassword – Browses Group Policy and finds passwords
 Code Execution
 Invoke-Shellcode – Inject shellcode into a specified process
 Mayhem
 Set-MasterBootRecord –Writes a string to the MBR
 Set-CriticalProcess - BSOD
VEIL POWERTOOLS
 https://github.com/PowerShellEmpire/PowerTools
 Part of the Empire Framework now
 Components
 PewPewPew – Run commands against a list of servers without touching
the HDD
 PowerBreach – Offers a variety of ways to trigger backdoor code
 PowerPick – Allows the execution of PS code without powershell.exe
 PowerUp – Assists with local escalation
 PowerView – Network awareness tool
COOL STUFF IN POWERTOOLS
 PowerView
 Invoke-StealthUserHunter – Finds Home Directory server and checks for active sessions
from specific users accounts
 Invoke-FindLocalAdminAccess – Finds machines that the current account has admins
rights on
 Get-ExploitableSystems – Cross references systems against common metasploit
payloads
 PowerBreach
 Invoke-DeadUserBackdoor –Triggers a payload if a given user account is deleted
 Invoke-EventLogBackdoor –Triggers a payload if a specific user fails an RDP login
 PewPewPew
 Invoke-MassCommand – Runs a given command against a bunch of servers
 Invoke-MassMimikatz – Runs mimikatz against all the things.
NISHANG
 https://github.com/samratashok/nishang
 Modules
 Backdoors
 Escalation
 Gather
 Pivot
 Scans
 Shells
 Client
COOLTHINGS ABOUT NISHANG
 Client
 Out-Word – Creates a word file (or infect an existing one) with a macro
that downloads and runs a PowerShell script
 Also see: Out-Excel, Out-HTA, Out-CHM, Out-Shortcut and Out-Java
 Backdoors
 DNS_Txt_Pwnage – A backdoor that receives commands through DNS
TXT queries
 Gupt-Backdoor – A backdoor that receives commands fromWLAN SSIDs
(without connecting)
.DESCRIPTION
Gupt looks for a specially crafted Wireless
Network Name/SSID from list of all available
networks. It matches first four characters of
each SSID with the parameter MagicString. On a
match, if the 5th character is a 'c', rest of the
SSID name is considered to be a command and
executed. If the 5th character is a 'u', rest of
the SSID is considered the id part of Google URL
Shortener and a script is downloaded and
executed in memory from the URL.
DEMO
Our demo gods, which art in conferences..
EMPIRE
A MagnumOpus of attacking with PowerShell
EMPIRE
 http://www.powershellempire.com/
 Pure PowerShell post-exploitation agent
 Cryptographically secure communications
 Flexible “phone-home” architecture
 Think Meterpreter, but native PowerShell
 Combines a lot of the modules present in other frameworks into an easy to
use reverse shell
USING EMPIRE
 Obtain a Linux server
 git clone https://github.com/powershellempire/empire && cd
empire/config && ./install.sh
 Setup listeners (HTTP/S endpoints) on the server
 Generate launchers (PowerShell code that runs on clients that makes
them phone home)
 Run launchers client side
 Receive shells
FURTHER INFO
BLUETEAMS
 PoshSecFramework (https://github.com/PoshSec/PoshSecFramework)
 PowerShell Console for Incident Response
 Invoke-IR (http://www.invoke-ir.com/)
 PowerForensics
 Uproot (IDS in Powershell)
 Kansa
 Information gathering and baseline
LEARNING MORE POWERSHELL
 MicrosoftVirtual Academy (https://mva.microsoft.com/)
 LearnWindows Powershell in a Month of Lunches (it’s a book)
 Google
 Get your hands dirty
 Spin up a lab and play
 Find stuff to Powershellify on the job
PEOPLETO FOLLOW
 @sixdub – PowerTools, Empire
 @harmj0y – PowerTools, Empire
 @enigma0x3 – Empire
 @mattifestation – PowerSploit
 @nikhil_mitt – Nishang
 @jaredcatkinson – Invoke-IR
 @ben0xa – PoshSecFramework
THE END
THE END
 Questions?
 @jaredhaight
 jhaight@gdssecurity.com
 Charlotte Hackers – http://www.charlottehackers.com
 Gotham Digital Science – http://www.gdssecurity.com

Weitere ähnliche Inhalte

Was ist angesagt?

Catch Me If You Can: PowerShell Red vs Blue
Catch Me If You Can: PowerShell Red vs BlueCatch Me If You Can: PowerShell Red vs Blue
Catch Me If You Can: PowerShell Red vs BlueWill Schroeder
 
Adventures in Asymmetric Warfare
Adventures in Asymmetric WarfareAdventures in Asymmetric Warfare
Adventures in Asymmetric WarfareWill Schroeder
 
PSConfEU - Building an Empire with PowerShell
PSConfEU - Building an Empire with PowerShellPSConfEU - Building an Empire with PowerShell
PSConfEU - Building an Empire with PowerShellWill Schroeder
 
Obfuscating The Empire
Obfuscating The EmpireObfuscating The Empire
Obfuscating The EmpireRyan Cobb
 
How to do everything with PowerShell
How to do everything with PowerShellHow to do everything with PowerShell
How to do everything with PowerShellJuan Carlos Gonzalez
 
Getting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingGetting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingRavikanth Chaganti
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Daniel Bohannon
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016Russel Van Tuyl
 
Kautilya: Teensy beyond shell
Kautilya: Teensy beyond shellKautilya: Teensy beyond shell
Kautilya: Teensy beyond shellNikhil Mittal
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationWill Schroeder
 
A Case Study in Attacking KeePass
A Case Study in Attacking KeePassA Case Study in Attacking KeePass
A Case Study in Attacking KeePassWill Schroeder
 
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)Rob Fuller
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell ModulesJune Blender
 
Power of linked list
Power of linked listPower of linked list
Power of linked listPeter Hlavaty
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Daniel Bohannon
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkChris Gates
 

Was ist angesagt? (20)

Catch Me If You Can: PowerShell Red vs Blue
Catch Me If You Can: PowerShell Red vs BlueCatch Me If You Can: PowerShell Red vs Blue
Catch Me If You Can: PowerShell Red vs Blue
 
Pwnstaller
PwnstallerPwnstaller
Pwnstaller
 
Adventures in Asymmetric Warfare
Adventures in Asymmetric WarfareAdventures in Asymmetric Warfare
Adventures in Asymmetric Warfare
 
Wielding a cortana
Wielding a cortanaWielding a cortana
Wielding a cortana
 
PSConfEU - Building an Empire with PowerShell
PSConfEU - Building an Empire with PowerShellPSConfEU - Building an Empire with PowerShell
PSConfEU - Building an Empire with PowerShell
 
Obfuscating The Empire
Obfuscating The EmpireObfuscating The Empire
Obfuscating The Empire
 
How to do everything with PowerShell
How to do everything with PowerShellHow to do everything with PowerShell
How to do everything with PowerShell
 
Getting Started With PowerShell Scripting
Getting Started With PowerShell ScriptingGetting Started With PowerShell Scripting
Getting Started With PowerShell Scripting
 
Defending Your "Gold"
Defending Your "Gold"Defending Your "Gold"
Defending Your "Gold"
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016PowerShell for Cyber Warriors - Bsides Knoxville 2016
PowerShell for Cyber Warriors - Bsides Knoxville 2016
 
A Year in the Empire
A Year in the EmpireA Year in the Empire
A Year in the Empire
 
Kautilya: Teensy beyond shell
Kautilya: Teensy beyond shellKautilya: Teensy beyond shell
Kautilya: Teensy beyond shell
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
 
A Case Study in Attacking KeePass
A Case Study in Attacking KeePassA Case Study in Attacking KeePass
A Case Study in Attacking KeePass
 
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
Power of linked list
Power of linked listPower of linked list
Power of linked list
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
 
Attacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit FrameworkAttacking Oracle with the Metasploit Framework
Attacking Oracle with the Metasploit Framework
 

Andere mochten auch

Try harder or go home
Try harder or go homeTry harder or go home
Try harder or go homejaredhaight
 
Fundamentals of Linux Privilege Escalation
Fundamentals of Linux Privilege EscalationFundamentals of Linux Privilege Escalation
Fundamentals of Linux Privilege Escalationnullthreat
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)Will Schroeder
 
Building an Empire with PowerShell
Building an Empire with PowerShellBuilding an Empire with PowerShell
Building an Empire with PowerShellWill Schroeder
 
Privilege Escalation And Misconfigurations
Privilege Escalation And MisconfigurationsPrivilege Escalation And Misconfigurations
Privilege Escalation And MisconfigurationsCaleb Sima
 
ColdFusion for Penetration Testers
ColdFusion for Penetration TestersColdFusion for Penetration Testers
ColdFusion for Penetration TestersChris Gates
 
Drilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerToolsDrilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerToolsWill Schroeder
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsConcentrated Technology
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secretChris Conte
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationConcentrated Technology
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functionsmikepfeiffer
 

Andere mochten auch (20)

Try harder or go home
Try harder or go homeTry harder or go home
Try harder or go home
 
Fundamentals of Linux Privilege Escalation
Fundamentals of Linux Privilege EscalationFundamentals of Linux Privilege Escalation
Fundamentals of Linux Privilege Escalation
 
PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)PSConfEU - Offensive Active Directory (With PowerShell!)
PSConfEU - Offensive Active Directory (With PowerShell!)
 
Building an Empire with PowerShell
Building an Empire with PowerShellBuilding an Empire with PowerShell
Building an Empire with PowerShell
 
Privilege Escalation And Misconfigurations
Privilege Escalation And MisconfigurationsPrivilege Escalation And Misconfigurations
Privilege Escalation And Misconfigurations
 
Bridging the Gap
Bridging the GapBridging the Gap
Bridging the Gap
 
Powershell Demo Presentation
Powershell Demo PresentationPowershell Demo Presentation
Powershell Demo Presentation
 
ColdFusion for Penetration Testers
ColdFusion for Penetration TestersColdFusion for Penetration Testers
ColdFusion for Penetration Testers
 
Drilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerToolsDrilling deeper with Veil's PowerTools
Drilling deeper with Veil's PowerTools
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
 
Ive got a powershell secret
Ive got a powershell secretIve got a powershell secret
Ive got a powershell secret
 
PowerShell and the Future of Windows Automation
PowerShell and the Future of Windows AutomationPowerShell and the Future of Windows Automation
PowerShell and the Future of Windows Automation
 
PS scripting and modularization
PS scripting and modularizationPS scripting and modularization
PS scripting and modularization
 
PowerShell custom properties
PowerShell custom propertiesPowerShell custom properties
PowerShell custom properties
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
 
Meet Windows PowerShell
Meet Windows PowerShellMeet Windows PowerShell
Meet Windows PowerShell
 
PowerShell 8tips
PowerShell 8tipsPowerShell 8tips
PowerShell 8tips
 
No-script PowerShell v2
No-script PowerShell v2No-script PowerShell v2
No-script PowerShell v2
 
Best free tools for win database admin
Best free tools for win database adminBest free tools for win database admin
Best free tools for win database admin
 
PowerShell and WMI
PowerShell and WMIPowerShell and WMI
PowerShell and WMI
 

Ähnlich wie Get-Help: An intro to PowerShell and how to Use it for Evil

Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Ilya Haykinson
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
Power shell training
Power shell trainingPower shell training
Power shell trainingDavid Brabant
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellSalaudeen Rajack
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersBoulos Dib
 
Post exploitation using powershell
Post exploitation using powershellPost exploitation using powershell
Post exploitation using powershellMihir Shah
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Binh Nguyen
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)Concentrated Technology
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009rsnarayanan
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetAchieve Internet
 
Intro to php
Intro to phpIntro to php
Intro to phpSp Singh
 
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...DevOps_Fest
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)ÇözümPARK
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellPhan Hien
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidMatthew Johnson
 

Ähnlich wie Get-Help: An intro to PowerShell and how to Use it for Evil (20)

Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 
Powershell notes
Powershell notesPowershell notes
Powershell notes
 
Post exploitation using powershell
Post exploitation using powershellPost exploitation using powershell
Post exploitation using powershell
 
Ansible
AnsibleAnsible
Ansible
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
Powershell Tech Ed2009
Powershell Tech Ed2009Powershell Tech Ed2009
Powershell Tech Ed2009
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Intro to php
Intro to phpIntro to php
Intro to php
 
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
DevOps Fest 2019. Сергей Марченко. Terraform: a novel about modules, provider...
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
NIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShellNIIT ISAS Q5 Report - Windows PowerShell
NIIT ISAS Q5 Report - Windows PowerShell
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 

Kürzlich hochgeladen

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Get-Help: An intro to PowerShell and how to Use it for Evil

  • 1. GET-HELP An intro to PowerShell and how to use it for evil
  • 2. PS C:>WHOAMI  Jared Haight  Security Engineer with the CLT team at Gotham Digital Science  Former Sysadmin  Hobbyist Developer  Corgi Enthusiast  @jaredhaight
  • 3. WHY AREWE HERE?  I think PowerShell is pretty awesome  I want you to think PowerShell is pretty awesome  I’m going to give you a bunch of reasons that PowerShell is pretty awesome
  • 4.
  • 5. WHY SHOULDYOU CARE ABOUT POWERSHELL Or “How I justified this talk to BSides Charleston”
  • 6. REDTEAMS  PowerShell is what the admins use to manage their infrastructure  Microsoft is pushing more and more tasks into PowerShell  Standard onWindows 7 and up  Robust, object oriented scripting language with access to a wide range of things on the computer  Access to entire .NET andWMI frameworks  Lots of very interesting offensive projects going on  BlueTeams aren’t typically looking for it
  • 7. BLUETEAMS  It’s what the bad guys are using.. like.. real ones.  There’s some really cool DFIR stuff going on with Powershell
  • 8. WHAT DO I NEED TO KNOW TO USE POWERSHELL? Scripting for people whose idea of server administration is next > next > finish
  • 9. VOCABULARY  String – Any combination of letters and numbers that are surrounded by quotation marks (single or double). Used for printing stuff.  Example: “a”, “abc”, “abc123”, “123”  Integer – A number without quotes. Used for math.  Example: 1, 2, 3, 5  Boolean –True or False, represented in PS as $True or $False  Variable – A reference to a value that can be assigned over the course of a script/program. Declared in PowerShell with as $[word], ex: $foo
  • 10. OBJECTS  An object is a type of “something”.  As an object of a specific type, it inherits properties and methods related to it’s object type  Properties – Information about the object  Methods – Code that interacts with the object  For example, strings have properties for length and methods to change the case of their letters.
  • 11. ARRAYS  A list of objects separated by commas  Example: “one”,”two”,”three”  You can access specific items in the array by using index numbers  Index starts at zero
  • 12. CMDLETS  Primary way of getting things done in PowerShell  Always in a “verb-noun” format  Examples  write-host – print something to screen  get-process – get running processes  set-clipboard – copy something to clipboard  get-eventlog – get contents of eventlog
  • 13. POWERSHELL SPECIFICS  Most everything is tab completable  Cmdlets  Parameters  ParameterValues  PowerShell ISE  “Integrated Scripting Editor” installed by default with PowerShell  IncludesVisual Studio like auto-completion (intellisense)  Sidebar featuring all available cmdlets
  • 17. FOR LOOPS Code 1 $list = "one", "two", "three" 2 forEach ($item in $list) 3 { 4 write-host * $item 5 } Output * one * two * three
  • 18. FOR LOOPS – PRACTICAL EXAMPLE CODE 1 $dirs = Get-ChildItem C: 2 forEach ($dir in $dirs) 3 { 4 write-host $dir.FullName 5 write-host "-----” 6 $acl = $dir.GetAccessControl() 7 write-host $acl.AccessToString 8 write-host 9 }
  • 19. FOR LOOPS – PRACTICAL EXAMPLE OUTPUT [...] C:repos ----- BUILTINAdministrators Allow FullControl NT AUTHORITYSYSTEM Allow FullControl BUILTINUsers Allow ReadAndExecute, Synchronize NT AUTHORITYAuthenticated Users Allow Modify, Synchronize NT AUTHORITYAuthenticated Users Allow -536805376 C:Sandbox ----- NT AUTHORITYAuthenticated Users Allow FullControl Everyone Allow FullControl [...]
  • 20. LOGIC  Logic in programming amounts to “if foo is true, do bar”  You can compare things in PowerShell with:  -lt – Less than  -le – Less than or equal to  -eq – Equal to  -ne – Not equal to  -ge – Greater than or equal to  -gt – Greater than
  • 21. LOGIC – IF/ELSE STATEMENTS 1 $nums = 1,2,3,4,5,6,7,8,9,10 2 forEach ($num in $nums) 3 { 4 if ($num -eq 4) 5 { 6 write-host $num is four. 7 } 8 else 9 { 10 write-host $num is not four. 11 } 12 } Output 1 is not four. 2 is not four. 3 is not four. 4 is four. 5 is not four. 6 is not four. 7 is not four. 8 is not four. 9 is not four. 10 is not four. Code
  • 22. LOGIC –WHILE LOOPS Code 1 $i = 1 2 while ($i -le 4) 3 { 4 write-host $i 5 $i = $i + 1 6 } Output 1 2 3 4
  • 23. FIGURING STUFF OUT  Get-Command [Search term]  Example: get-command “*clipboard”  Get-Help “Command”  It gets help.  Example: get-help write-host  Example: get-help write-host –examples  Get-Member  Pipe an object to it to find out the objects properties and methods  Example $dir | get-member
  • 24. GET-MEMBER OUTPUT PS C:> $dir | Get-Member TypeName: System.IO.FileInfo Name MemberType ---- ---------- ---------- Mode CodeProperty System.String Mode{get=Mode;} AppendText Method System.IO.StreamWriter[...] CopyTo Method System.IO.FileInfo[...] Create Method System.IO.FileStream Create() CreateObjRef Method System.Runtime.Remoting[...] CreateText Method System.IO.StreamWriter[...] Decrypt Method void Decrypt() Delete Method void Delete() [...]
  • 26. PUTTING IT ALL TOGETHER
  • 27. PUTTING IT ALLTOGETHER 1 1 $dirs = Get-ChildItem C: 2 ForEach ($dir in $dirs) 3 { 4 $i = 0 5 $acl = $dir.GetAccessControl() 6 while ($acl.Access[$i] -ne $Null) [...]
  • 28. PUTTING IT ALLTOGETHER (BREAK DOWN) [...] 9 $ace = $acl.Access[$i] 10 if ($ace.IdentityReference.Value.contains("Everyone")) 11 { 12 write-host $dir.FullName 13 write-host "-----“ 14 write-host $ace.IdentityReference.Value: $ace.FileSystemRights.toString() 15 write-host 16 } 17 $i = $i + 1 [...]
  • 29. 1 $dirs = Get-ChildItem C: 2 ForEach ($dir in $dirs) 3 { 4 $i = 0 5 $acl = $dir.GetAccessControl() 6 while ($acl.Access[$i] -ne $Null) 8 { 9 $ace = $acl.Access[$i] 10 if ($ace.IdentityReference.Value.contains("Everyone")) 11 { 12 write-host $dir.FullName 13 write-host "-----“ 14 write-host $ace.IdentityReference.Value: $ace.FileSystemRights.toString() 15 write-host 16 } 17 $i = $i + 1 18 } 19 }
  • 30. PUTTING IT ALLTOGETHER (OUTPUT) C:Sandbox ----- Everyone : FullControl C:Users ----- Everyone : ReadAndExecute, Synchronize
  • 31. DOING FUN STUFF WITH POWERSHELL I may have a strange definition of “fun”
  • 32. REGISTRY FUN – REGISTRY AS A DRIVE PS C:> cd HKCU: PS HKCU:> cd .SOFTWARE PS HKCU:SOFTWARE> dir Micro* Hive: HKEY_CURRENT_USERSOFTWARE Name Property ---- -------- Microsoft Microsoft Corporation Microsoft Studios
  • 33. REGISTRY FUN – CREATING ENTRIES # Does the key exist? PS HKCU:SOFTWARE> test-path "BSidesCHS" False # Create key PS HKCU:SOFTWARE> new-item "BSidesCHS" Hive: HKEY_CURRENT_USERSOFTWARE Name Property ---- -------- BSidesCHS # Create item in key PS HKCU:SOFTWARE> New-ItemProperty -path .BSidesCHS -Name Demo -PropertyType String -Value "TextGoesHere"
  • 34. REMOTE FUN  Most (all?) cmdlets understand UNC paths  test-path serversharetest.txt  A lot of cmdlets support the –ComputerName parameter.  stop-service spooler –ComputerName demo-dc01  WinRM makes everything better  Microsofts Remote Management service  enter-pssession demo-dc01  invoke-command –ComputerName demo-dc01 “{code}”
  • 36. EVIL
  • 37. WHAT CAN WE BREAK?  There is a lot of really impressive work going into offensive PowerShell frameworks.  Recon  Backdoors  Shellcode  Exfiltration  Privesc  Lots of very smart and devious people working on PowerShell frameworks  Big focus on “in memory” attacks.  Don’t touch the disk, don’t trip AV.
  • 38. USING A FRAMEWORK  Clone the repo  Run “Import-Module $repo”
  • 39. POWERSPLOIT  https://github.com/PowerShellMafia/PowerSploit  Modules  AV Bypass  Code Execution  Exfiltration  Mayhem  Persistence  Recon  Script Modification
  • 40. COOLTHINGS IN POWERSPLOIT  Exfiltration  Invoke-NinjaCopy – Copies a file from NTFS by reading the raw volume and parsing NTFS structures  Inoke-Mimikatz – Loads Mimikatz into memory and runs it. Doesn’t touch disk when run against a remote computer.  Get-GPPPassword – Browses Group Policy and finds passwords  Code Execution  Invoke-Shellcode – Inject shellcode into a specified process  Mayhem  Set-MasterBootRecord –Writes a string to the MBR  Set-CriticalProcess - BSOD
  • 41. VEIL POWERTOOLS  https://github.com/PowerShellEmpire/PowerTools  Part of the Empire Framework now  Components  PewPewPew – Run commands against a list of servers without touching the HDD  PowerBreach – Offers a variety of ways to trigger backdoor code  PowerPick – Allows the execution of PS code without powershell.exe  PowerUp – Assists with local escalation  PowerView – Network awareness tool
  • 42. COOL STUFF IN POWERTOOLS  PowerView  Invoke-StealthUserHunter – Finds Home Directory server and checks for active sessions from specific users accounts  Invoke-FindLocalAdminAccess – Finds machines that the current account has admins rights on  Get-ExploitableSystems – Cross references systems against common metasploit payloads  PowerBreach  Invoke-DeadUserBackdoor –Triggers a payload if a given user account is deleted  Invoke-EventLogBackdoor –Triggers a payload if a specific user fails an RDP login  PewPewPew  Invoke-MassCommand – Runs a given command against a bunch of servers  Invoke-MassMimikatz – Runs mimikatz against all the things.
  • 43. NISHANG  https://github.com/samratashok/nishang  Modules  Backdoors  Escalation  Gather  Pivot  Scans  Shells  Client
  • 44. COOLTHINGS ABOUT NISHANG  Client  Out-Word – Creates a word file (or infect an existing one) with a macro that downloads and runs a PowerShell script  Also see: Out-Excel, Out-HTA, Out-CHM, Out-Shortcut and Out-Java  Backdoors  DNS_Txt_Pwnage – A backdoor that receives commands through DNS TXT queries  Gupt-Backdoor – A backdoor that receives commands fromWLAN SSIDs (without connecting)
  • 45. .DESCRIPTION Gupt looks for a specially crafted Wireless Network Name/SSID from list of all available networks. It matches first four characters of each SSID with the parameter MagicString. On a match, if the 5th character is a 'c', rest of the SSID name is considered to be a command and executed. If the 5th character is a 'u', rest of the SSID is considered the id part of Google URL Shortener and a script is downloaded and executed in memory from the URL.
  • 46. DEMO Our demo gods, which art in conferences..
  • 47. EMPIRE A MagnumOpus of attacking with PowerShell
  • 48. EMPIRE  http://www.powershellempire.com/  Pure PowerShell post-exploitation agent  Cryptographically secure communications  Flexible “phone-home” architecture  Think Meterpreter, but native PowerShell  Combines a lot of the modules present in other frameworks into an easy to use reverse shell
  • 49. USING EMPIRE  Obtain a Linux server  git clone https://github.com/powershellempire/empire && cd empire/config && ./install.sh  Setup listeners (HTTP/S endpoints) on the server  Generate launchers (PowerShell code that runs on clients that makes them phone home)  Run launchers client side  Receive shells
  • 51. BLUETEAMS  PoshSecFramework (https://github.com/PoshSec/PoshSecFramework)  PowerShell Console for Incident Response  Invoke-IR (http://www.invoke-ir.com/)  PowerForensics  Uproot (IDS in Powershell)  Kansa  Information gathering and baseline
  • 52. LEARNING MORE POWERSHELL  MicrosoftVirtual Academy (https://mva.microsoft.com/)  LearnWindows Powershell in a Month of Lunches (it’s a book)  Google  Get your hands dirty  Spin up a lab and play  Find stuff to Powershellify on the job
  • 53. PEOPLETO FOLLOW  @sixdub – PowerTools, Empire  @harmj0y – PowerTools, Empire  @enigma0x3 – Empire  @mattifestation – PowerSploit  @nikhil_mitt – Nishang  @jaredcatkinson – Invoke-IR  @ben0xa – PoshSecFramework
  • 55. THE END  Questions?  @jaredhaight  jhaight@gdssecurity.com  Charlotte Hackers – http://www.charlottehackers.com  Gotham Digital Science – http://www.gdssecurity.com

Hinweis der Redaktion

  1. This won’t be in depth Don’t really expect people to leave here and be able code in PS My goal here is to show you how easy it is to get started with PS and do some really cool stuff. Also want to highlight some of the awesome stuff going on in infosec
  2. * I’m not a developer. * I tend to get my vocabulary mixed up. I apologize in advance. * The stuff I make works though, so that’s good.
  3. Deep Panda – Attacked National Security Think Tanks using Powershell as scheduled tasks to download and execute RATs APT 29 – Twitter based C2 that got powershell commands from tweets
  4. Primary thing you do in PS is run cmdlets. You can write your own cmdlets, usually written in C#
  5. Comparisons are the same as bash
  6. The directory object has a method called “GetAccessControl”, which returns an ACL object
  7. Test-path for KEY New-item for KEY New-ItemProperty for Value
  8. WinRM is a SOAP based API for managing Windows WinRM default install on 2008+, but must be enabled.
  9. * Offensive community is driven by a lot of mature pentesters.
  10. * $repo can be a folder, ps1 file or psm1 file.
  11. * There’s a LOT to Nishang. Very active, robust framework.
  12. Description of Grupt-Backdoor from the PS file.
  13. Log in as helpdesk to demo-client1 Invoke-Userhunter (find MrAdmin on demo-client2) invoke-mimikatz –demo-client2 Start new PS instance as MrAdmin Import-module C:\repos\PowerTools\Powerview Get-netDomainController Import-Module C:\repos\Powersploit Invoke-ninjacopy –Path C:\windows\ntds\ntds.dit –ComputerName demo-dc01 –LocalDest C:\repos Start new admin PS instance Import-Module C:\repos\Powersploit Set-masterbootrecord “l33th4x0r” Restart-computer
  14. Empire is the magnum opus of offensive powershell
  15. As part of the setup, a unique string is generated. This is used to encrypt the powershell code for the launchers Launchers phone home (not constant connection)