full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Get-DroppedSourceIP.ps1
Get-DroppedSourceIP.ps1
$HashTable = @{} #Empty hashtable Switch -RegEx -File .\pfirewall.log { "DROP\sTCP.+RECEIVE" { $SrcIP = ($_ -Split " ")[4] If ($HashTable.ContainsKey($SrcIP)) { $HashTable.Item($SrcIP) = $HashTable.Item($SrcIP) + 1 } Else { $HashTable.Add($SrcIP,1) } ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Send-EMail.ps1
Send-EMail.ps1
############################################################################## # Script: Send-EMail.ps1 # Date: 23.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Send e-mail using SMTP or SMTPS. # Notes: If multiple addresses to the addressing...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Arrays.ps1
Arrays.ps1
$array = @() # To create an array with some elements in it, separate the elements with commas: $array = @(1,"hello",433.2,"world") # To create an array without explicitly casting it as an array, just use the comma operator, and PowerShell will know it's an array despite the lack of an @-symbol: $array = ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Search-TextLog.ps1
Search-TextLog.ps1
###################################################################################### # Script: Search-TextLog.ps1 # Date: 2.Jun.2012 # Version: 2.1 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Will search every line of a textual log file against every regex # ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Inventory-Applications.ps1
Inventory-Applications.ps1
################################################################################ # Name: Inventory-Applications.ps1 # Purpose: Queries a local or remote computer for information about software # applications installed, then exports the data to a CSV file which # can be opened in a spreadsheet. ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Sort_Object.ps1
Sort_Object.ps1
# To get the smallest file in the root of the C: drive: get-childitem c:\ | sort-object length | select -first 1 # To get the largest file in the root of the C: drive: dir c:\ | sort-object length -descending | select -first 1 # To list the EXE's in the C:\Windows folder, sorted on the Last Access Time ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Event_Logs.ps1
Event_Logs.ps1
# Remember, the -computername parameter requires PowerShell 2.0 or later. # With Vista/2008-R2 and later machines, use Get-WinEvent instead. # To see a list of local event logs and show their important configuration settings: get-eventlog -list # To show the last 20 events from the System log: get-eventlo...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Processing_Text.ps1
Processing_Text.ps1
$droptcp = $dropudp = $dropicmp = 0 $allowtcp = $allowudp = $allowicmp = 0 # Log file is locked, copy it to local folder: copy-item C:\Windows\system32\LogFiles\Firewall\pfirewall.log . switch -regex -file .\pfirewall.log { 'DROP TCP' {$droptcp++} 'DROP UDP' {$dropupd++} 'DROP ICMP' {$dropicmp++} ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Remoting.ps1
Remoting.ps1
# To enable PowerShell remoting on the local machine: Enable-PSRemoting -Force # To connect to a local/remote computer by name: Enter-PSSession -ComputerName LocalHost # To exit a PowerShell remoting session: Exit-PSSession # Or just "exit" by itself. # To execute a set of commands on remo...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/XML.ps1
XML.ps1
$xmldoc = @" <Users> <Person> <FirstName>Leslie</FirstName> <LastName>Cummings</LastName> <Birthdate>20-June-1974</Birthdate> </Person> <Person> <FirstName>Matt</FirstName> <LastName>Shepard</LastName> ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Extended-Type-System.ps1
Extended-Type-System.ps1
########################################################################### # # Different versions of PowerShell support different techniques for # creating objects with custom properties and methods. In general, newer # methods are simpler and faster, but not backwards compatible. # ###########################...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Get-FileHex.ps1
Get-FileHex.ps1
############################################################################## # Script: Get-FileHex.ps1 # Date: 16.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Shows the hex translation of a file, binary or otherwise. The # $width a...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/For_FlowControl.ps1
For_FlowControl.ps1
For ( $i = 0 ; $i -le 20 ; $i++ ) { "Now at $i" } For ( $( $i=0; $j=0; $ps=@(get-process|select-object name)); $( $ps.count -ge ($i + $j) ) ; $( $i += 2 ; $j++ ) ) { $ps[$i] }
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Background-Jobs.ps1
Background-Jobs.ps1
# Background jobs are PowerShell scripts or blocks which run disconnected from # the interactive shell as separate threads, hence, the interactive shell is # not blocked and the user can continue to execute commands in the shell. # Background jobs can be running, completed, blocked or failed, and the output # of a ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Processing_Arrays.ps1
Processing_Arrays.ps1
$stopped = $running = $paused = 0 switch (get-service | select-object status) { {$_.status -like "Running"} {$running++} {$_.status -like "Stopped"} {$stopped++} {$_.status -like "Paused"} {$paused++} } "Services Running = $running" "Services Stopped = $stopped" "Services Paused = $paused"
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Error_Handling.ps1
Error_Handling.ps1
# nosuchfile.txt does not exist, raises an error. xcopy.exe nosuchfile.txt tofile.txt "Succeeded? " + $? "Error Code: " + $LASTEXITCODE # nosuchfile.txt does not exist, raises an error. copy-item nosuchfile.txt tofile.txt $? # Is now False. # To show the properties of the last error object throw...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Subexpressions.ps1
Subexpressions.ps1
"The sum of all workingset sizes is $($x = 0 ; get-process | foreach {$x += $_.workingset} ; $x / 1024 / 1024) MB." @(foreach ($x in get-process) {if ($x.name -like "powershell") {$x}}).count
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Throw.ps1
Throw.ps1
& { $ErrorActionPreference = "stop" throw "Something bad has happened!" dir c:\ trap { "Exception!!!" $_ continue } } # A common use for Throw is to inform coders that certain script or # function parameters are mandatory. In the following snippe...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Trap.ps1
Trap.ps1
& { "Our preference is to " + $ErrorActionPreference nosuch-cmdlet #Causes an exception. dir c:\ trap { "Exception!!!" } } & { $ErrorActionPreference = "stop" nosuch-cmdlet #Causes an exception. dir c:\ #Still executes anyway because of Continue. trap { ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Piping_Input.ps1
Piping_Input.ps1
function auf-deutsch { foreach ($word in $input) { "Das " + $word + "en!"} } # "Train" | auf-deutsch auf-deutsch # Following line is run in a script, not at the prompt: while ($input.movenext()) {"Das " + $input.current + "en!"} function thewayofdata ($p) { $p $args[0] $args[1] f...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/Default_Value.ps1
Default_Value.ps1
function disable-admin { Param ($Password = "SEC505Gr8#4TV!") net.exe user Administrator "$Password" net.exe user Administrator /active:no } disable-admin disable-admin -Password "0v3rr1d3n!" function greet ([String] $word = "Hello", $place = "World") { "!" * 20 $word + " " ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Examples/ErrorActionPreference_Scriptblock.ps1
ErrorActionPreference_Scriptblock.ps1
$ErrorActionPreference = "Continue" dir c:\ ; nosuch-cmdlet ; dir c:\ & { $ErrorActionPreference = "Stop" dir c:\ ; nosuch-cmdlet ; dir c:\ } # Notice that the following lines still execute: $ErrorActionPreference #Unchanged, it's still "Continue". dir c:\ ; nosuch-cmdlet ; dir c:\
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/SigningScripts/Signed-Script-Example.ps1
Signed-Script-Example.ps1
# This is just an example of a digitally-signed PowerShell script. # Run ".\Sign-Script.ps1 -List" to see if you have any cerificates # which can be used to sign other scripts, then sign this file, # e.g., ".\Sign-Script.ps1 -Path .\Signed-Script-Example.ps1". get-process # SIG # Begin signature block...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/SigningScripts/Sign-Script.ps1
Sign-Script.ps1
#################################################################################### #.Synopsis # Digitally signs PowerShell scripts. # #.Description # If you have a code-signing certificate, this script can sign one or # multiple other scripts for the sake of satisfying PowerShell's # execution p...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/SigningScripts/Check-Signature.ps1
Check-Signature.ps1
#################################################################################### #.Synopsis # Display digital signature information for files. # #.Description # The script is just a wrapper for Get-AuthenticodeSignature. Note that if # test-path to a file fails for any reason, that file is not che...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/TrueRNG-Random-Number-Generator.ps1
TrueRNG-Random-Number-Generator.ps1
<# --------------------------------------- Version: 1.0 Updated: 24.Jul.2015 Legal: Public domain, code provided "AS IS" without any warranties or guarantees whatsoever, use at your own risk. Author: Enclave Consulting LLC (www.sans.org/sec505) --------------------------------------- TrueRNG is a hardware-base...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/KeePass-Examples.ps1
KeePass-Examples.ps1
########################################################################### # # The following are examples for scripting KeePass with PowerShell. # # For KeePass object classes, see: # http://keepassps.codeplex.com/SourceControl/latest#keepass.ps1 # # Version: 1.1 # Updated: 19.Aug.2015 # Author: Encla...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/Crypto-Examples-CheeseBall.ps1
Crypto-Examples-CheeseBall.ps1
############################################################################## # # This script is just for fun, it's to implement a block cipher named # "CheeseBall" with permutation, s-boxes, counter mode, and all the fixins. # I'll eventually get around to finishing it. Right now it just has the # permutation...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/KeePass-Run-PowerShell.ps1
KeePass-Run-PowerShell.ps1
<# This code is for running PowerShell commands from within the KeePass password manager app (www.keepass.info) by double-click the URL column for a KeePass entry (or Ctrl-U). The password field from the KeePass entry will be encrypted with DPAPI and passed into a new PowerShell.exe process as a command-line arg....
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/Crypto-Examples-DPAPI.ps1
Crypto-Examples-DPAPI.ps1
############################################################################## # # DPAPI example. # # Windows uses the Data Protection API (DPAPI) for securing many of the # secrets users wish to maintain, such as passwords and encryption keys. # DPAPI encrypts secrets with a key derived from the user's logon pa...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/Protect-CmsMessage_Examples.ps1
Protect-CmsMessage_Examples.ps1
<# This script provides examples of the following cmdlets: Protect-CmsMessage Unprotect-CmsMessage Get-CmsMessage Cryptographic Message Syntax (CMS) is defined by RFC5652 (http://tools.ietf.org/html/rfc5652) and provides for the encryption and/or signing of data using a public key. ***OS an...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/Crypto-Examples-Symmetric.ps1
Crypto-Examples-Symmetric.ps1
############################################################################## # # The following is a variety of examples of doing crypto in PowerShell. # Public key and DPAPI examples are in different scripts. # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # #########################...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day1-PowerShell/Crypto/Crypto-Examples-PublicKey.ps1
Crypto-Examples-PublicKey.ps1
############################################################################## # # The following are some examples of doing public key crypto in PowerShell. # Symmetric key crypto examples are in a different script. # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # ####################...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Minimal-Server-Core.ps1
Minimal-Server-Core.ps1
########################################################################## # Server 2012 and later can run in three modes: Full, Minimal, and Core. # Full = Full graphical interface and graphical management tools. # Minimal = Like Full, but no IE, File Explorer or desktop. # Core = Almost no gr...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/PopUp.ps1
PopUp.ps1
######################################################################################## # Script Name: PopUp-DialogBox.ps1 # Version: 1.0 # Author: Jason Fossen #Last Updated: 25.Jul.2013 # Purpose: Demonstrate the PopUp() method, which displays a graphical dialog box # with user-define...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Get-FeaturesInventory.ps1
Get-FeaturesInventory.ps1
######################################################### # # This is a starter script to query AD for servers and # then inventory the roles and features on each server. # Save the inventory with Export-CliXml. Add error # handling and other polish to use in production. # ######################################...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Java/Configure-JavaBrowserPlugIn.ps1
Configure-JavaBrowserPlugIn.ps1
################################################################################## #.SYNOPSIS # Configures Java SE browser plug-in settings for security. # #.DESCRIPTION # Java 7 update 10 and later supports security options to 1) allow/disallow the # plug-in for Java to run applets in the web browser and...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Java/Disable-JavaInJustInternetExplorer.ps1
Disable-JavaInJustInternetExplorer.ps1
# Actually disabling Java in *just* Internet Explorer, and not in any other locally installed # browser, is ridiculously hard. Most of the following changes will simply be overwritten the # next time the Java Control Panel tool (javacpl.exe) is used to change any browser plug-in # options, hence, it is better to u...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/WindowsFeatureExample.ps1
WindowsFeatureExample.ps1
# This script only runs on Windows Server, not any client OS. # Role names can be seen with Get-WindowsFeature. # Service names can be seen with Get-Service. Configuration TestConfig { Param ([String[]] $ComputerName = "LocalHost") # Import-DscResource –ModuleName PSDesiredStateConfiguration ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/Invoke-ForcedConfigurationApply.ps1
Invoke-ForcedConfigurationApply.ps1
# This script will cause the Local Configuration Manager (LCM) to immediately # reapply the current configuration of the local computer, pulling the # configuration if necessary. $HashTable = ` @{ Namespace = "root/Microsoft/Windows/DesiredStateConfiguration" ClassName = "MSFT_DSCLocalConfigurationMa...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/RegistryTest.ps1
RegistryTest.ps1
# This script is for dot-sourcing with the "." command; for # example, ". .\RegistryTest.ps1" will dot-source this script. Configuration TestConfig { # Import-DscResource –ModuleName PSDesiredStateConfiguration Node LocalHost { Registry RegExample { Ensure = "Pres...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/MofMassProduction.ps1
MofMassProduction.ps1
Param ( [String[]] $ArgsToScript = "LocalHost" ) Configuration TestConfig { Param ( [String[]] $ComputerName = "LocalHost" ) # Import-DscResource –ModuleName PSDesiredStateConfiguration Node $ComputerName { Registry RegExample { Ensure = "Present" ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/Node2MofExpansion.ps1
Node2MofExpansion.ps1
Configuration TestConfig { # Import-DscResource –ModuleName PSDesiredStateConfiguration Node @("LocalHost","Server47","Laptop48") { Registry RegExample { Ensure = "Present" Key = "HKEY_LOCAL_MACHINE\SOFTWARE\AAANewKey" ValueName = "EnableGoo...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/FileExample.ps1
FileExample.ps1
Configuration TestConfig { Param ([String[]] $ComputerName = "LocalHost") # Import-DscResource –ModuleName PSDesiredStateConfiguration Node $ComputerName { File CreateFileExample { DestinationPath = "C:\Temp\SetByDsc.txt" Contents = "This file was c...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/LCM-Settings.ps1
LCM-Settings.ps1
# Manage LCM's own settings, e.g., push/pull mode, refresh frequency, etc. # Requires WMF 5.0 or later. [DSCLocalConfigurationManager()] Configuration ExampleLcmConfig { Param ([String[]] $ComputerName = "LocalHost") Node $ComputerName { Settings { Configuration...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/LocalUserExample.ps1
LocalUserExample.ps1
# THIS SCRIPT DOES NOT WORK ON DOMAIN CONTROLLERS, IT IS ONLY # FOR LOCAL USER ACCOUNTS, NOT GLOBAL ACCOUNTS IN AD. # Microsoft *really* does not want us to put plaintext passwords into scripts, # but this script will show how to do it anyway (it's a bit of a pain). # Be aware that the plaintext password goes i...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/DSC/GroupExample.ps1
GroupExample.ps1
# THIS SCRIPT DOES NOT WORK ON DOMAIN CONTROLLERS, IT IS ONLY # FOR LOCAL GROUPS, NOT "DOMAIN LOCAL GROUPS" IN AD. Configuration TestConfig { Param ([String[]] $ComputerName = "LocalHost") # Import-DscResource –ModuleName PSDesiredStateConfiguration Node $ComputerName { Group Loc...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Service_Recovery_Options/Set-ServiceRecoveryOptions.ps1
Set-ServiceRecoveryOptions.ps1
#################################################################################### #.Synopsis # This script is a wrapper for SC.EXE to modify service recovery options. # #.Description # Windows services can be configured with recovery options in the event of # a service failure (see the Services tool...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/IIS/Error-Pages.ps1
Error-Pages.ps1
# This demos some commands for querying and setting a particular IIS configuration option, namely, # the Error Pages feature setting concerning custom or detailed error pages. Copy and paste # each command into your shell to test it out. # Import IIS module and cmdlets first, then test out the IIS provider. ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/IIS/IIS-Administration-Samples.ps1
IIS-Administration-Samples.ps1
############################################################################## # Script: IIS-Administration-Samples.ps1 # Date: 12.Jun.2008 # Version: 1.0 # Author: Jason Fossen (www.WindowsPowerShellTraining.com) # Purpose: Just shows some commands for IIS7 or later. # Notes: Sometimes you'll need to re-c...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/IIS/Log_Analysis/Search-TextLog.ps1
Search-TextLog.ps1
###################################################################################### # Script: Search-TextLog.ps1 # Date: 2.Jun.2012 # Version: 2.1 # Author: Jason Fossen # Purpose: Will search every line of a textual log file against every regex # pattern provided in a second file, producing a s...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Audit-Service-Creation.ps1
Audit-Service-Creation.ps1
### Recommendations to better audit the creation of new services: ### # # Enable the "Audit System Service Extension" audit policy under the System category. # Audit the creation and deletion of subkeys under HKLM\SYSTEM\CurrentControlSet\Services\. # Audit the execution of sc.exe. # ### # Create and t...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Get-ServicePrivileges.ps1
Get-ServicePrivileges.ps1
# List explicitly-granted privileges for services. Param ($ServiceName = '*') function Get-ServicePrivileges ($ServiceName = '*') { Get-Service -Name $ServiceName | ForEach ` { $output = '' | Select Name,DisplayName,Privileges $output.Name = $_.Name $output.DisplayName = $_...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Get-ServiceIdentity.ps1
Get-ServiceIdentity.ps1
################################################################################## # Name: Get-ServiceIdentity.ps1 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Version: 1.0.1 # Date: 3.May.2013 # Purpose: # Outputs standard Get-Service objects, but with two additional propertie...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Get-ServiceWithWriteRestrictedSAT.ps1
Get-ServiceWithWriteRestrictedSAT.ps1
# Only output services with a write-restricted Security Access Token (SAT). # When a write-restricted-SAT service requires access to a resource, such # as a file, the permissions on that resource must grant permission to the # service explicitly by name. Get-Service | foreach ` { if ((sc.exe qsidtype $_.n...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Group-Managed-Service-Accounts.ps1
Group-Managed-Service-Accounts.ps1
#################################################################################### # Group Managed Service Accounts can be used on Server 2012, Windows 8, and later. # GMSAs can be used across multiple machines and for scheduled jobs. # Requires at least one controller to be running Server 2012 or later. # Requir...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day2-Hardening/Services/Get-InsecureServiceBinaryPath.ps1
Get-InsecureServiceBinaryPath.ps1
# Service binaries should be installed under C:\Windows or C:\Program* # in order to inherit the better NTFS permissions of those folders. # This command lists the service binaries which are installed elsewhere. # Hopefully this command will display nothing on the audited computer. Get-WmiObject Win32_Service |...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/Manage-DAC-Examples.ps1
Manage-DAC-Examples.ps1
############################################################################ # The following are examples of using PowerShell to manage objects # related to Dynamic Access Control in Server 2012 and later. ############################################################################ # To see existing claim type...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/PowerShell-Classifier-Rule-Example.ps1
PowerShell-Classifier-Rule-Example.ps1
####################################################################### # This is an example PowerShell classifier rule as used by the # File Server Resource Manager (FSRM) for the sake of tagging files # for Dynamic Access Control. The GetPropertyValueToApply() function # can be enhanced to examine any aspect of...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/5-CreatePolicyRule.ps1
5-CreatePolicyRule.ps1
# Create the DAC rule named "Only HR Access to Files with PII". # Get SID for the Human_Resources global group (unique per domain). # If there are multiple, just get the first one. Import-Module -Name ActiveDirectory $HR = @( Get-ADGroup -Filter "Name -like 'Human*'" ) $SID = $HR[0].SID.Value # G...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/3-EnableResourceProperties.ps1
3-EnableResourceProperties.ps1
# Enable the five resource property rules mentioned in the # courseware (Department, PII, Discoverability, etc) and add # them to Global Resource Property List. # Disable all current resource properties: Get-ADResourceProperty -Filter {Enabled -eq $True} | Set-ADResourceProperty -Enabled $False # En...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/4-ClassifyTradeSecretsFile.ps1
4-ClassifyTradeSecretsFile.ps1
# Assign classification tags to the TradeSecrets.txt file in C:\Classified-Files. # Ensure that most recent resource properties have been downloaded. Update-FSRMClassificationPropertyDefinition # Create object representing the File Server Resource Manager (FSRM) service. $FSRM = New-Object -com Fsrm...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/6-CreateFileServersPolicy.ps1
6-CreateFileServersPolicy.ps1
# Create new Central Access Policy named "File Servers Policy". New-ADCentralAccessPolicy "File Servers Policy" # And add the HR rule to it. Add-ADCentralAccessPolicyMember -Identity "File Servers Policy" -Member "Only HR Access to Files with PII" # Don't forget, F5 refresh to see it in the GUI if it...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/7-ApplyPolicyToClassifiedFilesFolder.ps1
7-ApplyPolicyToClassifiedFilesFolder.ps1
# Apply the Central Access Policy named "File Servers Policy" to C:\Classified-Files. # Get current NTFS access control list so that it may be restored. $ACL = Get-ACL -Path "C:\Classified-Files" -Audit # Add the 'File Servers Policy' CAP to the folder. Set-ACL -Path "C:\Classified-Files" -AclObject...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/8-CreateClassifierRulesInFSRM.ps1
8-CreateClassifierRulesInFSRM.ps1
# Create some classification rules for File Server Resource Manger (FSRM). # Suggest some demos to perform. # Everything in C:\Classified-Files will get tagged Clearance = Restricted by default. New-FSRMClassificationRule -Name "Folder Classifier" -Property "RequiredClearance_MS" -PropertyValue "3000" -Names...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/1-InstallFileServerResourceManager.ps1
1-InstallFileServerResourceManager.ps1
# Install the File Server Resource Manager (FSRM), or just exit if already installed. if ( $(Get-WindowsFeature -Name FS-Resource-Manager).Installed ) { "FSRM aleady installed!" ; exit } Install-WindowsFeature -Name FS-Resource-Manager -IncludeManagementTools -Restart
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DAC/OnYourComputer/2-CreateClaimTypes.ps1
2-CreateClaimTypes.ps1
# Create the Department and Two-Letter-Country-Name claim types. Import-Module -Name ActiveDirectory function New-ADSuggestedValueEntry ([String] $Value, [String] $DisplayName = "", [String] $Description = "") { if ($DisplayName -eq ""){ $DisplayName = $Value } New-Object Microsoft.ActiveDirectory....
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Get-SuccessfulLogon.ps1
Get-SuccessfulLogon.ps1
#################################################################################### #.Synopsis # Extract successful logon events from the security event log. # #.Description # Extract logon events information from the security event log on # a local or remote Windows Vista, Server 2008 or later compu...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Get-ProcessWithWMI.ps1
Get-ProcessWithWMI.ps1
############################################################################## # Script: Get-ProcessWithWMI.ps1 # Date: 30.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Demo how to retrieve process information through WMI. # Notes: The idle p...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/RebootShutdownLogoff-Computer.ps1
RebootShutdownLogoff-Computer.ps1
############################################################################## # Script: RebootShutdownLogoff-Computer.ps1 # Date: 31.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Name of the script/function is what it does. Note how the $actio...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_NameSpaces.ps1
WMI_NameSpaces.ps1
# To see a list of all the WMI namespaces: get-wmiobject -query "select * from __namespace" -namespace "root" | format-table Name
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_EventCode.ps1
WMI_EventCode.ps1
function Get-LogonFailures ($computer = ".") # A period indicates the local machine. {Ā $query = "SELECT * FROM Win32_NTLogEvent WHERE logfile = 'Security' AND ( EventCode = '529' OR EventCode = '4625' )" Ā get-wmiobject -query $query -computername $computer } # Run the function to query the loca...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WmiEvents-ProcessLaunch.ps1
WmiEvents-ProcessLaunch.ps1
######################################################################### # Purpose: Script demos a WMI events subscription for new process launch. # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Version: 1.0 # Legal: Public domain, no warranties or guarantees, use at own risk. ###...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Terminate-ProcessWithWMI.ps1
Terminate-ProcessWithWMI.ps1
############################################################################## # Script: Terminate-ProcessWithWMI.ps1 # Date: 21.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Demo how to kill processes on remote computers with WMI. # Legal: S...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/SecureString-Theory.ps1
SecureString-Theory.ps1
############################################################################## # Script: SecureString-Theory.ps1 # Date: 24.Sep.2013 # Version: 2.0 # Purpose: Demonstrate how to work with secure string objects. # Notes: Credit for deobfuscation function goes to MoW, The PowerShell Guy: # http://the...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/SecureString-Credentials.ps1
SecureString-Credentials.ps1
$cred = get-credential # Dialog box appears... get-wmiobject -query "SELECT * FROM Win32_BIOS" -computer server3 -credential $cred # Show the so-called secure string password in plaintext: $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.password) [System.Runtime.InteropServ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Create-ProcessWithWMI.ps1
Create-ProcessWithWMI.ps1
############################################################################## # Script: Create-ProcessWithWMI.ps1 # Date: 21.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Demo how to launch processes on remote computers with WMI. # Legal: Sc...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_Sample_GPO_Filters.ps1
WMI_Sample_GPO_Filters.ps1
#******************************************************************************* # Script Name: WMI_Sample_GPO_Filters.ps1 # Version: 1.3 # Author: Jason Fossen (www.sans.org/sec505) #Last Updated: 25.Jan.2015 # Purpose: The following are examples of WMI Filters for Group Policy Objects. # Lega...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_DNS_Server.ps1
WMI_DNS_Server.ps1
# These are just some sample WMI queries related to the Windows DNS server. # List DNS classes from the MicrosoftDNS namespace in WMI. Get-WmiObject -Query "SELECT * FROM META_CLASS" -Namespace "Root/MicrosoftDNS" # Return the MicrosoftDNS_Zone class itself. Get-WmiObject -Query "SELECT * FROM META...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Show-ComputerInfo.ps1
Show-ComputerInfo.ps1
############################################################################## # Script: Show-ComputerInfo.ps1 # Date: 30.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # SANS: Course SEC505 - Securing Windows and PowerShell Automation # Purpose: Demo a...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Inventory-Applications.ps1
Inventory-Applications.ps1
################################################################################ # Name: Inventory-Applications.ps1 # Purpose: Queries a local or remote computer for information about software # applications installed, then exports the data to a CSV file which # can be opened in a spreadsheet. ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/Get-DriverWithWMI.ps1
Get-DriverWithWMI.ps1
############################################################################## # Script: Get-DriverWithWMI.ps1 # Date: 30.May.2007 # Version: 1.0 # Author: Jason Fossen, Enclave Consulting LLC (http://www.sans.org/sec505) # Purpose: Uses WMI to get device driver information. # Legal: Script provided "AS IS...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_Queries.ps1
WMI_Queries.ps1
# To see the objects in a particular class in root\CIMv2 and show all their properties: get-wmiobject -query "select * from Win32_OperatingSystem" -namespace "root\cimv2" | format-list * # Next line does the same thing since CIMv2 is the default. get-wmiobject -query "select * from Win32_OperatingSystem" | ...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/WMI/WMI_Classes.ps1
WMI_Classes.ps1
# To list the classes available in a particular namespace, such as "root\CIMv2": get-wmiobject -query "select * from meta_class" -namespace "root\cimv2"
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DNS/Parse-DnsLog.ps1
Parse-DnsLog.ps1
#################################################################################### #.Synopsis # Parse Windows DNS text log to count which FQDNs were resolved most often # or which client source IP addresses were most often logged. # #.Description # Parse Windows DNS text log to count which FQDNs wer...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DNS/Sinkhole-DNS.ps1
Sinkhole-DNS.ps1
#################################################################################### #.Synopsis # Creates and deletes sinkhole domains in Windows DNS servers. # #.Description # Script takes fully-qualified domain names (FQDNs) and/or simple domain # names, then uses them to create primary zones (not A...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DNS/Add-RootZoneTrustAnchor.ps1
Add-RootZoneTrustAnchor.ps1
################################################################################ # The following command will add the DNSSEC root zone trust anchor information # on Server 2012 and later. Confirm that this information is still current at: # https://data.iana.org/root-anchors/root-anchors.xml # After running t...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/DNS/Update-HostsFile.ps1
Update-HostsFile.ps1
#################################################################################### #.Synopsis # Adds domain names to the HOSTS file for blocking. Find the HOSTS # file at $env:systemroot\system32\drivers\etc\hosts # #.Description # The HOSTS text file is typically used for name resolution before an...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/Kerberos/New-CtmADKrbtgtKeys.ps1
New-CtmADKrbtgtKeys.ps1
<#---------------------------------------------------------------------------------------------------- Version 1.7 Known issues/bugs: - Currently requires English language due to checking text output of rpcping.exe and repadmin.exe Release Notes: v1.7: Author: Jared Poeppelman, Micro...
PowerShellCorpus/Github/NgPecSysAdmin_NgPecSysAdmin/resources/Scripts/SEC505/Day6-Servers/SMB/SMB-Encryption.ps1
SMB-Encryption.ps1
################################################################# # Server 2012, Windows 8 and later support SMB encryption. ################################################################# # To disable SMBv1 or SMBv2: Set-SmbServerConfiguration –EnableSMB1Protocol $False Set-SmbServerConfiguration -EnableSM...
PowerShellCorpus/Github/justacurley_PowerShell/Convertto-SharedMailboxV4.ps1
Convertto-SharedMailboxV4.ps1
Function ConvertTo-SharedMailbox <#PSScriptInfo .Synopsis Converts user mailbox to shared in hybrid exchange environment .Description Connects to Exch Online and MsolService. Set mailbox to Shared and SendAsCopy, remove licenses, update AD attributes .Example Te...
PowerShellCorpus/Github/OPSTest_E2E_Provision_1484816015740/.openpublishing.build.ps1
.openpublishing.build.ps1
param( [string]$buildCorePowershellUrl = "https://opbuildstoragesandbox2.blob.core.windows.net/opps1container/.openpublishing.buildcore.ps1", [string]$parameters ) # Main $errorActionPreference = 'Stop' # Step-1: Download buildcore script to local echo "download build core script to local with source u...
PowerShellCorpus/Github/raoconnor_Get-StorageByDatacenter/Get-StorageByDataCenter.ps1
Get-StorageByDataCenter.ps1
<# Get-storageInfoByCluster .Description Get cluster LUN info russ 05/04/2017 .Example ./Get-StorageByCluster #> # Get datacenter info and populate $vms $datacenter = Get-datacenter $countDC = 0 Write-Output " " Write-Output "Datacenters: " Write-Output " " foreach...
PowerShellCorpus/Github/obs0lete_Get-DirSize/Get-DirSize.ps1
Get-DirSize.ps1
function Get-DirSize { $ErrorActionPreference = 'SilentlyContinue' $startfolder = Read-Host "Please provide a folder path" $startFolder = $startfolder -Replace '"', "" $getSize = @() $folders = GCI $startfolder | Where {$_.PSiscontainer -eq "True"} Write-Host "Getting folder sizes for $startfolder..." -f "yellow...
PowerShellCorpus/Github/jkells_xamarin-android-crashlytics-binding/default.ps1
default.ps1
properties { $base_dir = resolve-path . $nuget_bin = "$base_dir\tools\.nuget\nuget.exe" $7zip_bin = "$base_dir\tools\7zip\7za.exe" } Framework "4.0" task default -depends Clean, Download, Package task Clean { remove-item -force "$base_dir\crashlytics-devtools.zip" -ErrorAction SilentlyContinue ...
PowerShellCorpus/Github/jkells_xamarin-android-crashlytics-binding/psake.ps1
psake.ps1
# Helper script for those who want to run psake without importing the module. # Example: # .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0" # Must match parameter definitions for psake.psm1/invoke-psake # otherwise named parameter binding fails param( [Parameter(Position=0,Mandatory=0)] [string]$buil...
PowerShellCorpus/Github/fraszkaa_ZTW2/BootstrapSite1/packages/EntityFramework.6.0.0/tools/init.ps1
init.ps1
param($installPath, $toolsPath, $package, $project) if (Get-Module | ?{ $_.Name -eq 'EntityFramework' }) { Remove-Module EntityFramework } Import-Module (Join-Path $toolsPath EntityFramework.psd1) # SIG # Begin signature block # MIIarwYJKoZIhvcNAQcCoIIaoDCCGpwCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQ...
PowerShellCorpus/Github/fraszkaa_ZTW2/BootstrapSite1/packages/EntityFramework.6.0.0/tools/install.ps1
install.ps1
param($installPath, $toolsPath, $package, $project) Initialize-EFConfiguration $project Add-EFProvider $project 'System.Data.SqlClient' 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' Write-Host Write-Host "Type 'get-help EntityFramework' to see all available Entity Framework comma...
PowerShellCorpus/Github/fraszkaa_ZTW2/BootstrapSite1/packages/Modernizr.2.6.2/Tools/uninstall.ps1
uninstall.ps1
param($installPath, $toolsPath, $package, $project) . (Join-Path $toolsPath common.ps1) # Update the _references.js file Remove-Reference $scriptsFolderProjectItem $modernizrFileNameRegEx
PowerShellCorpus/Github/fraszkaa_ZTW2/BootstrapSite1/packages/Modernizr.2.6.2/Tools/install.ps1
install.ps1
param($installPath, $toolsPath, $package, $project) . (Join-Path $toolsPath common.ps1) if ($scriptsFolderProjectItem -eq $null) { # No Scripts folder Write-Host "No Scripts folder found" exit } # Update the _references.js file AddOrUpdate-Reference $scriptsFolderProjectItem $modernizrFileName...