powershell shenanigans

14
POWERSHELL SHENANIGANS KIERAN JACOBSEN HP ENTERPRISE SERVICES

Post on 18-Oct-2014

244 views

Category:

Technology


0 download

DESCRIPTION

Powershell is something that is becoming the must-have tool for system administrators in the Microsoft world. However it has long been overlooked by those in the field, including security staff. In this talk Kieran will introduce Powershell, discuss Microsoft’s aim and rationale for its existence, and show how Microsoft’s best intentions can be turned against them by demonstrating how this automation platform can become an attack automation platform.

TRANSCRIPT

Page 1: PowerShell Shenanigans

POWERSHELL SHENANIGANSKIERAN JACOBSEN

HP ENTERPRISE SERVICES

Page 2: PowerShell Shenanigans

WHAT IS POWERSHELL?

• Developed by Microsoft in 2006

• Cross between a shell script and C#

• Replacement for VBScript

• Significant number of commands (called CMDLets)

• Runs on .NET Framework

Page 3: PowerShell Shenanigans

CHALLENGE

• Move from social engineered workstation to domain controller

• Where possible use only PowerShell code

• Demo environment will be a “corporate like” environment

Page 4: PowerShell Shenanigans

ADVANTAGES AS AN ATTACK PLATFORM

• Code is very easy to develop

• Windows integration

• Remote execution offerings

• Often overlooked by AV

• Easily hidden from administrators

• Installed by DEFAULT

Page 5: PowerShell Shenanigans

MY POWERSHELL MALWARE

• Single Script – SystemInformation.ps1

• Runs as a schedule task, every 5 minutes

• Script:

• Collects system information and more

• Connects to C2 infrastructure, downloads a task list and executes tasks

• Executes each task, if successful, task will not be rerun

• Tasks can be restricted to individual computers

Page 6: PowerShell Shenanigans

DEMO: THE ENTRY

Page 7: PowerShell Shenanigans

WINDOWS POWERSHELL REMOTING AND WINRM

• PowerShell Remoting is based upon WinRM, Microsoft’s WS-Management implementation

• Supports execution in 3 ways:

• Remote enabled commands

• Remotely executed script blocks

• Remote sessions

• Security Model = Trusted Devices + User Credentials

• WinRM is required for the Windows Server Manager

• WinRM is enabled by DEFAULT on domain 2012(R2) joined servers

Page 8: PowerShell Shenanigans

DEMO: THE DC

Page 9: PowerShell Shenanigans

POWERSHELL SECURITY FEATURES

• Administrative rights

• UAC

• Code Signing

• Local or Remote source using zone.identifier alternate data stream

• PowerShell Execution Policy

Page 10: PowerShell Shenanigans

EXECUTION POLICY

There are 6 states for the execution policy

• Unrestricted All scripts can run

• Remote Signed No unsigned scripts from the Internet can run

• All Signed No unsigned scripts can run

• Restricted No scripts are allowed to run

• Undefined (Default) If no policy defined, then default to restricted

• Bypass Policy processor is bypassed

Page 11: PowerShell Shenanigans

BYPASSING EXECUTION POLICY

• Simply ask PowerShell: powershell.exe –executionpolicy unrestricted

• Switch the files zone.idenfier back to local:unblock-file yourscript.ps1

• Read the script in and then execute it (may fail depending on script)

• Get/Steal a certificate, sign script, run script

Page 12: PowerShell Shenanigans

DEMO: THE HASHES

Page 13: PowerShell Shenanigans

OTHER CONSIDERATIONS

• PowerShell Web Access

• Desired State Configuration

Page 14: PowerShell Shenanigans

LINKS AND QUESTIONS

• Twitter: @kjacobsen

• Blog: http://aperturescience.su

• Code on GitHub: http://j.mp/1i33Zrk

• QuarksPWDump: http://j.mp/1kF30e9

• PowerSploit: http://j.mp/1gJORtF

• Microsoft PowerShell/Security Series:

• http://j.mp/OOyftt

• http://j.mp/1eDYvA4

• http://j.mp/1kF3z7T

• http://j.mp/NhSC0X

• http://j.mp/NhSEpy

• Practical Persistence in PowerShell:http://j.mp/1mU6fQq