SlideShare uma empresa Scribd logo
1 de 14
POWERSHELL
SHENANIGANS
KIERAN JACOBSEN
HP ENTERPRISE SERVICES
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
CHALLENGE
• Move from social engineered workstation to domain controller
• Where possible use only PowerShell code
• Demo environment will be a “corporate like” environment
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
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
DEMO: THE ENTRY
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
DEMO: THE DC
POWERSHELL SECURITY FEATURES
• Administrative rights
• UAC
• Code Signing
• Local or Remote source using zone.identifier alternate data stream
• PowerShell Execution Policy
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
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
DEMO: THE HASHES
OTHER CONSIDERATIONS
• PowerShell Web Access
• Desired State Configuration
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

Mais conteúdo relacionado

Destaque

Global Azure Bootcamp 2016 - Azure Automation Invades Your Data Centre
Global Azure Bootcamp 2016 - Azure Automation Invades Your Data CentreGlobal Azure Bootcamp 2016 - Azure Automation Invades Your Data Centre
Global Azure Bootcamp 2016 - Azure Automation Invades Your Data Centrekieranjacobsen
 
DirectAccess, do’s and don’ts
DirectAccess, do’s and don’tsDirectAccess, do’s and don’ts
DirectAccess, do’s and don’tskieranjacobsen
 
Infrastructure Saturday 2011 - Understanding PKI and Certificate Services
Infrastructure Saturday 2011 - Understanding PKI and Certificate ServicesInfrastructure Saturday 2011 - Understanding PKI and Certificate Services
Infrastructure Saturday 2011 - Understanding PKI and Certificate Serviceskieranjacobsen
 
Azure automation invades your data centre
Azure automation invades your data centreAzure automation invades your data centre
Azure automation invades your data centrekieranjacobsen
 
Dev Breakfast: Level up to DevSecOps
Dev Breakfast: Level up to DevSecOpsDev Breakfast: Level up to DevSecOps
Dev Breakfast: Level up to DevSecOpskieranjacobsen
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellConcentrated Technology
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingConcentrated Technology
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationJason Stangroome
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functionsmikepfeiffer
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and UsesConcentrated Technology
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsConcentrated Technology
 

Destaque (18)

Global Azure Bootcamp 2016 - Azure Automation Invades Your Data Centre
Global Azure Bootcamp 2016 - Azure Automation Invades Your Data CentreGlobal Azure Bootcamp 2016 - Azure Automation Invades Your Data Centre
Global Azure Bootcamp 2016 - Azure Automation Invades Your Data Centre
 
DirectAccess, do’s and don’ts
DirectAccess, do’s and don’tsDirectAccess, do’s and don’ts
DirectAccess, do’s and don’ts
 
Infrastructure Saturday 2011 - Understanding PKI and Certificate Services
Infrastructure Saturday 2011 - Understanding PKI and Certificate ServicesInfrastructure Saturday 2011 - Understanding PKI and Certificate Services
Infrastructure Saturday 2011 - Understanding PKI and Certificate Services
 
Azure automation invades your data centre
Azure automation invades your data centreAzure automation invades your data centre
Azure automation invades your data centre
 
Dev Breakfast: Level up to DevSecOps
Dev Breakfast: Level up to DevSecOpsDev Breakfast: Level up to DevSecOps
Dev Breakfast: Level up to DevSecOps
 
PowerShell crashcourse
PowerShell crashcoursePowerShell crashcourse
PowerShell crashcourse
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
 
PowerShell crashcourse for sharepoint
PowerShell crashcourse for sharepointPowerShell crashcourse for sharepoint
PowerShell crashcourse for sharepoint
 
PowerShell 8tips
PowerShell 8tipsPowerShell 8tips
PowerShell 8tips
 
Managing enterprise with PowerShell remoting
Managing enterprise with PowerShell remotingManaging enterprise with PowerShell remoting
Managing enterprise with PowerShell remoting
 
PowerShell v4 Desired State Configuration
PowerShell v4 Desired State ConfigurationPowerShell v4 Desired State Configuration
PowerShell v4 Desired State Configuration
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
 
Managing SQLserver
Managing SQLserverManaging SQLserver
Managing SQLserver
 
Automating ad with powershell
Automating ad with powershellAutomating ad with powershell
Automating ad with powershell
 
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and UsesVDI-in-a-Box:  Microsoft Desktop Virtualization for Smaller Businesses and Uses
VDI-in-a-Box: Microsoft Desktop Virtualization for Smaller Businesses and Uses
 
PowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint adminsPowerShell crashcourse for Sharepoint admins
PowerShell crashcourse for Sharepoint admins
 
PowerShell custom properties
PowerShell custom propertiesPowerShell custom properties
PowerShell custom properties
 
PowerShell crash course
PowerShell crash coursePowerShell crash course
PowerShell crash course
 

Mais de kieranjacobsen

The Boring Security Talk - Azure Global Bootcamp Melbourne 2019
The Boring Security Talk - Azure Global Bootcamp Melbourne 2019The Boring Security Talk - Azure Global Bootcamp Melbourne 2019
The Boring Security Talk - Azure Global Bootcamp Melbourne 2019kieranjacobsen
 
CrikeyCon VI - The Boring Security Talk
CrikeyCon VI - The Boring Security TalkCrikeyCon VI - The Boring Security Talk
CrikeyCon VI - The Boring Security Talkkieranjacobsen
 
The Boring Security Talk
The Boring Security TalkThe Boring Security Talk
The Boring Security Talkkieranjacobsen
 
The Boring Security Talk
The Boring Security TalkThe Boring Security Talk
The Boring Security Talkkieranjacobsen
 
Secure Azure Deployment Patterns
Secure Azure Deployment PatternsSecure Azure Deployment Patterns
Secure Azure Deployment Patternskieranjacobsen
 
Ransomware 0, Admins 1
Ransomware 0, Admins 1Ransomware 0, Admins 1
Ransomware 0, Admins 1kieranjacobsen
 
DecSecOps in 10 minutes
DecSecOps in 10 minutesDecSecOps in 10 minutes
DecSecOps in 10 minuteskieranjacobsen
 
Infrastructure Saturday - Level Up to DevSecOps
Infrastructure Saturday - Level Up to DevSecOpsInfrastructure Saturday - Level Up to DevSecOps
Infrastructure Saturday - Level Up to DevSecOpskieranjacobsen
 
DevSecOps - CrikeyCon 2017
DevSecOps - CrikeyCon 2017DevSecOps - CrikeyCon 2017
DevSecOps - CrikeyCon 2017kieranjacobsen
 

Mais de kieranjacobsen (10)

The Boring Security Talk - Azure Global Bootcamp Melbourne 2019
The Boring Security Talk - Azure Global Bootcamp Melbourne 2019The Boring Security Talk - Azure Global Bootcamp Melbourne 2019
The Boring Security Talk - Azure Global Bootcamp Melbourne 2019
 
CrikeyCon VI - The Boring Security Talk
CrikeyCon VI - The Boring Security TalkCrikeyCon VI - The Boring Security Talk
CrikeyCon VI - The Boring Security Talk
 
The Boring Security Talk
The Boring Security TalkThe Boring Security Talk
The Boring Security Talk
 
The Boring Security Talk
The Boring Security TalkThe Boring Security Talk
The Boring Security Talk
 
Secure Azure Deployment Patterns
Secure Azure Deployment PatternsSecure Azure Deployment Patterns
Secure Azure Deployment Patterns
 
Ransomware 0, Admins 1
Ransomware 0, Admins 1Ransomware 0, Admins 1
Ransomware 0, Admins 1
 
Ransomware 0 admins 1
Ransomware 0 admins 1Ransomware 0 admins 1
Ransomware 0 admins 1
 
DecSecOps in 10 minutes
DecSecOps in 10 minutesDecSecOps in 10 minutes
DecSecOps in 10 minutes
 
Infrastructure Saturday - Level Up to DevSecOps
Infrastructure Saturday - Level Up to DevSecOpsInfrastructure Saturday - Level Up to DevSecOps
Infrastructure Saturday - Level Up to DevSecOps
 
DevSecOps - CrikeyCon 2017
DevSecOps - CrikeyCon 2017DevSecOps - CrikeyCon 2017
DevSecOps - CrikeyCon 2017
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
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
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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
 
🐬 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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
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
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

PowerShell Shenanigans

  • 2. 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
  • 3. CHALLENGE • Move from social engineered workstation to domain controller • Where possible use only PowerShell code • Demo environment will be a “corporate like” environment
  • 4. 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
  • 5. 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
  • 7. 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
  • 9. POWERSHELL SECURITY FEATURES • Administrative rights • UAC • Code Signing • Local or Remote source using zone.identifier alternate data stream • PowerShell Execution Policy
  • 10. 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
  • 11. 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
  • 13. OTHER CONSIDERATIONS • PowerShell Web Access • Desired State Configuration
  • 14. 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

Notas do Editor

  1. Hi Everyone, I am Kieran Jacobsen, I work at HP Enterprise services as a system engineer, I have never worked directly in a security role but have been fortunate to cross into that space on a few occasions. My aim today is to show you how you can turn something that was designed to reduce administration costs into a really interesting and very devious attack platform.
  2. Does everyone know what PowerShell is? Quick hands up who doesn’t know what it is? <If they all know>Well let’s skip this slide, as you all know.<If people don’t>Let’s quickly talk about that it is. PowerShell, simply put, is a cross between a shell scripting language, like BASH and a formal programming language like C#. PowerShell will be replacing VBScript, in the new future, VBScript will become unsupported, and at some point be removed from Windows. Microsoft has spent a significant amount of time in its development, resulting in a huge number of built in functions and features. PowerShell runs on top of the Microsoft .Net framework, so you have full access to .Net functions and libraries. So there it is, Powershell in a nutshell.
  3. To show you how PowerShell can be turned to mischievous use, I am going to work through a challenge I was previously given by a friend. His challenge was simple, in a corporate like environment, move from a “social engineered” infection on a workstation, to the domain controller and when there, extract the active directory hashes. To make matters more interesting, I was to use PowerShell where possible, today, I am down to pretty much two piece of non PowerShell code, working with schedule tasks and working with the AD database. The network that I will be showing this all on, is a fairly typical environment. We have a client, running windows 8.1, a server running Windows Server 2012 R2 which is also a domain controller, and a firewall from a fairly reputable vendor. I have setup a few things like we would expect, there is a management service running on all of the devices, unfortunately the service account it is running on is a member of the domain admins. This is something that I still see far to often. SCCM agents running as domain admin, even though Microsoft tells you not to, happens far to often. The Firewall is running with the default configuration, and it only allows HTTP, HTTPS and DNS outbound. Everything else is pretty much the default configuration, the client, the domain, the lot are all default settings. The only change really in this challenge over the past few years is around UAC, where as in 7, it was typically switched off, more and more organisations are leaving it on. UAC state isn’t a huge issue though for us today, so we don’t need to worry about it.
  4. So why use PowerShell as an attack platform? To begin with, PowerShell code is easy to develop and easy to understand, allowing us to rapidly develop attack code and customise our attacks for our intended targets. Next, PowerShell’s deep windows integration and remote execution options like PowerShell remoting provides us with a lot of easy to use, ready to use code, which we can run on a large number of machines in a very quick manner. PowerShell’s aim for administration and management automation makes it’s a very good security and attack automation platform. What about our security products? AV products typically do not look at our PowerShell scripts. Right now, PowerShell code, apart from one or two cases, hasn’t been used maliciously in a significant way in the wild. Our security vendors typically do not provide many checks or balances on PowerShell scripts and modules. Another thing to consider is the human element. Your system administrators are off writing PowerShell scripts, they expect to see them on servers and workstations, they might not notice one more running on a system.Importantly though, its there by default. In Windows Vista and onwards, PowerShell has been installed by default. This gives it a pretty good reach as an attack tool within a corporate environment.
  5. So I made a little script, I suppose it could be called malware, which will run on a system and allow you to have remote control over the system. If I have time, I will show you, but I am not going to go into specifics today as the code will be put up onto GitHub for you to take a look. The script is cleverly called SystemInformation.ps1, in the hope users and administrators don’t work out what it is. The script will be setup to run as a scheduled task, running as local system, every 5 minutes. There is a number of different ways we could manage to set this up, in the demo it will be occurring through an Excel macro, however you could use almost anything, as long as the script is downloaded, and the task is created. When the script executes, it will do a few things. Firstly, it will collect system information and some poorly secured credentials, it also connects to the command and control infrastructure and downloads a list of tasks to execute. Tasks can be any valid PowerShell expression, a PowerShell expression, an executable, as long as it is a valid expression. Tasks, if successfully executed will only be run once, they can also be limited to executing on a single PC.
  6. So there have been some interesting changes in terms of security with the introduction of Windows PowerShell Remoting, and WinRM. PowerShell remoting allows us to remotely execute PowerShell code on one or more remote systems, based upon the WinRM or Windows Remote Management Interface. WinRM is based upon the WS-Management protocol. Remoting gives administrators a number of execution options, firstly, a large number of powershell commands have been extended to allow for their execution against remote devices directly. Next administrators can also run a powershell script block remotely, in an experience much like rexec or using ssh to run a remote command. Finally, administrators could start a remote session, much like connecting into a full blown ssh session.Security for WinRM is governed by two things, firstly, only trusted devices are allowed to connect, in a domain joined environment this is all domain members. Secondly you need the appropriate rights, typically local administrator rights. Now for the kicker of it all. Windows Server 2012, and 2012R2 introduces a new unified Windows Server Manager, trumpeted by Microsoft as an advancement of server administration, it introduces a critical flaw. The entire thing runs on WinRM, and to make things easier, Microsoft made the wonderfully helpful decision to setup, configure WinRM for you, whenever you join a server to a domain. Everytime you join a server to the domain, WinRM will be configured to allow WinRM connections from any domain member, as long as the user has admin rights. This is a huge difference from previous versions, where the enablement of WinRM required administrator intervention. Now when you join your new Windows Server 2012 R2 machine to the domain, your opening it up to any lacky with admin rights. Whilst it sounds innocent, it provides a brilliant mechanism for large scale network infections.
  7. In terms of security features, it follows the usual windows security pattern. As expected, Administrative rights and UAC govern what we can and cannot do. As expected if you needed admin rights before, you will still need them, and the same goes with UAC elevation.You can protect your scripts and modules with Code Signing. Signing scripts has been made easier over the last few years, however the usual vulnerabilities still apply.An interesting aspect is that PowerShell is that it will look at the NTFS zone.identifier alternate data stream to determine the source for a script or module. This is the same functionality that causes that prompt for confirmation when you run that setup executable you downloaded off the internet.If you combine the source identification and code signing, then you have PowerShell’s Execution Policy feature. The execution policy is a feature within PowerShell that allows an administrator to control what scripts execute and what modules can be loaded into a session. It is Microsoft’s attempt at preventing malicious code. Different policy states allow and disallow scripts to run and modules to be loaded. Policy can be specified at a session, user and computer level, via the registry or group policy. Let’s take at the different policy states.
  8. There are 6 different states.First we have unrestricted, this is the least secure state and allows us to run any script, no matter where it came from. Then we have remote signed, with remote signed, if a script came from a source other than the local pc, it must be signed; any script from say the internet, which is signed, will be executed. Then we have all signed, here we will not run any script, no matter the source, unless it has been signed. Then there is restricted, in this state, no scripts can run.There are two special states, undefined, which is the policy if none has been set, this actually defaults to the restricted policy, and finally bypass, which is primarily used when calling PowerShell scripts from applications, in bypass the policy processer is, well, bypassed.So, you are probably thinking, well this looks like decent security…what if I told you, I can get a script to run, no matter the execution policy specified?
  9. So how can I run a PowerShell script without changing the computer or user defined policy?Well firstly, if the administrators haven’t used group policy to specify a particular policy, we can simply ask powershell to use a different one when we run it.If an administrator has specified remote signed, then we can set the zone identifier to say it hasn’t come from the internet, in effect bypassing his control.If that doesn’t work, say they set all signed or restricted. Then simply read the file in, turn it into a single executable expression, that is, not multiple lines, and then run that.Finally, and probably easier for some, simply obtain or steal a certificate.I am going to say this. Whilst administrators are probably setting one of these levels for their workstations, they probably are not doing this on their servers. Pretty much ever server I come across, will have the policy of unrestricted. I would almost bet that there is one in everyone's windows server environment.
  10. Before we finish up, just two more things that should be considered.Firstly, PowerShell Web Access. This is one of the most interesting things Microsoft has done in a while. PowerShell web access allows you to connect to a server using a web browser and open a PowerShell console, with a user experience much like shell-in-a-box. Web Access gives us some interesting options, especially during the testing of externally facing windows servers. Imagine being able to install the web access on a public facing web server?Next we have Desired State Configuration. DCS is a mechanism for pushing or pulling configuration and settings on a server. This can be once off our scheduled. DCM allows you to install and configure Windows roles and features, and much more. Whilst I haven’t been fortunate to spend much time looking at DCM, it does look like an interesting persistence option, and even another possible method of gaining more privileges on a corporate network.