Skip to content

Commit 03213e9

Browse files
committed
Merge pull request #2 from PowerShell/master
Syncing with Master
2 parents 7726903 + 53d83b9 commit 03213e9

File tree

77 files changed

+492
-2012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+492
-2012
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# PowerShell Documentation
22

3-
Welcome to the PowerShell-Docs repository, housing the official PowerShell documentation [available on MSDN](https://msdn.microsoft.com/powershell/dsc/overview).
3+
Welcome to the PowerShell-Docs repository, housing the official Windows PowerShell documentation [available on MSDN](https://msdn.microsoft.com/powershell/dsc/overview).
44

5-
> **Note**: right now, this repo is only intended for PowerShell Desired State Configuration (DSC) content and Windows Management Framework (WMF) Release Notes.
6-
In the future, it will be expanded to include a greater set of PowerShell documentation.
5+
> **Note**: Currently, this repository is intended only for PowerShell [Desired State Configuration (DSC)](https://msdn.microsoft.com/en-us/powershell/dsc/overview) content and Windows Management Framework (WMF) release notes.
6+
In the future, the repo will be expanded to include a wider range of PowerShell documentation.
77

88
## Contributing
99

10-
We will be actively merging contributions into this repository via pull request.
11-
Please note that before contributing, you must [sign a Contribution License Agreement](https://cla.microsoft.com/) to ensure that the community is free to use your contributions.
10+
We actively merge contributions into this repository via [pull request](https://help.github.com/articles/using-pull-requests/).
11+
Please note that before you submit a pull request you must [sign a Contribution License Agreement](https://cla.microsoft.com/) to ensure that the community is free to use your submissions.
1212
For more information on contributing, read our [contributions guide](CONTRIBUTING.md).

wmf/TOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
## [PowerShell Module Discovery, Install and Inventory with PowerShellGet](psget_module_overview.md)
7777
### [Register a PowerShell Repository](psget_psrepository.md)
7878
### [Side-by-Side Version Support on PowerShell 5.0 or newer](psget_modulesxsinstall.md)
79-
### [Installtion of Module Dependencies](psget_moduledependency.md)
79+
### [Installation of Module Dependencies](psget_moduledependency.md)
8080
### [PowerShellGet Cmdlets for Module Management](psget_modulecmdlets.md)
8181

8282
## [PowerShell Script Discovery, Install and Management with PowerShellGet](psget_script_overview.md)

wmf/audit_cms.md

Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,76 @@
1-
### Cryptographic Message Syntax (CMS) cmdlets
1+
# Cryptographic Message Syntax (CMS) cmdlets
22

33
The Cryptographic Message Syntax cmdlets support encryption and decryption of content using the IETF standard format for cryptographically protecting messages as documented by [RFC5652](http://tools.ietf.org/html/rfc5652).
4-
4+
```powershell
55
  Get-CmsMessage \[-Content\] <string>
6-
76
  Get-CmsMessage \[-Path\] <string>
8-
97
  Get-CmsMessage \[-LiteralPath\] <string>
10-
118
  Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-Content\] <string> \[\[-OutFile\] <string>\]
12-
139
  Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-Path\] <string> \[\[-OutFile\] <string>\]
14-
1510
  Protect-CmsMessage \[-To\] <CmsMessageRecipient\[\]> \[-LiteralPath\] <string> \[\[-OutFile\] <string>\]
16-
1711
  Unprotect-CmsMessage \[-EventLogRecord\] <EventLogRecord> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
18-
1912
  Unprotect-CmsMessage \[-Content\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
20-
2113
  Unprotect-CmsMessage \[-Path\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
22-
2314
  Unprotect-CmsMessage \[-LiteralPath\] <string> \[\[-To\] <CmsMessageRecipient\[\]>\] \[-IncludeContext\]
24-
15+
```
2516
The CMS encryption standard implements public key cryptography, where the keys used to encrypt content (the *public key*) and the keys used to decrypt content (the *private key*) are separate.
2617

2718
Your public key can be shared widely, and is not sensitive data. If any content is encrypted with this public key, only your private key can decrypt it. For more information about Public Key Cryptography, see: <http://en.wikipedia.org/wiki/Public-key_cryptography>.
2819

2920
To be recognized in Windows PowerShell, encryption certificates require a unique key usage identifier (EKU) to identify them as data encryption certificates (like the identifiers for 'Code Signing', 'Encrypted Mail').
3021

3122
Here is an example of creating a certificate that is good for Document Encryption:
32-
23+
```powershell
3324
(Change the text in **Subject** to your name, email, or other identifier), and put in a file (i.e.: DocumentEncryption.inf):
34-
3525
  \[Version\]
36-
3726
  Signature = "$Windows NT$"
38-
3927
  \[Strings\]
40-
4128
  szOID\_ENHANCED\_KEY\_USAGE = "2.5.29.37"
42-
4329
  szOID\_DOCUMENT\_ENCRYPTION = "1.3.6.1.4.1.311.80.1"
44-
4530
  \[NewRequest\]
46-
4731
  Subject = "<[email protected]>"
48-
4932
  MachineKeySet = false
50-
5133
  KeyLength = 2048
52-
5334
  KeySpec = AT\_KEYEXCHANGE
54-
5535
  HashAlgorithm = Sha1
56-
5736
  Exportable = true
58-
5937
  RequestType = Cert
60-
6138
  KeyUsage = "CERT\_KEY\_ENCIPHERMENT\_KEY\_USAGE | CERT\_DATA\_ENCIPHERMENT\_KEY\_USAGE"
62-
6339
  ValidityPeriod = "Years"
64-
6540
  ValidityPeriodUnits = "1000"
66-
6741
  \[Extensions\]
68-
6942
  %szOID\_ENHANCED\_KEY\_USAGE% = "{text}%szOID\_DOCUMENT\_ENCRYPTION%"
70-
43+
```
7144
Then run:
72-
45+
```powershell
7346
  certreq -new DocumentEncryption.inf DocumentEncryption.cer
74-
47+
```
7548
And you can now encrypt and decrypt content:
76-
77-
> 106 \[C:\\temp\]
78-
> &gt;&gt; $protected = "Hello World" | Protect-CmsMessage -To "\*[email protected]\*[](mailto:*[email protected]*)"
79-
>
80-
> 107 \[C:\\temp\]
81-
> &gt;&gt; $protected
82-
> -----BEGIN CMS-----
83-
> MIIBqAYJKoZIhvcNAQcDoIIBmTCCAZUCAQAxggFQMIIBTAIBADA0MCAxHjAcBgNVBAMMFWxlZWhv
84-
> bG1AbWljcm9zb2Z0LmNvbQIQQYHsbcXnjIJCtH+OhGmc1DANBgkqhkiG9w0BAQcwAASCAQAnkFHM
85-
> proJnFy4geFGfyNmxH3yeoPvwEYzdnsoVqqDPAd8D3wao77z7OhJEXwz9GeFLnxD6djKV/tF4PxR
86-
> E27aduKSLbnxfpf/sepZ4fUkuGibnwWFrxGE3B1G26MCenHWjYQiqv+Nq32Gc97qEAERrhLv6S4R
87-
> G+2dJEnesW8A+z9QPo+DwYU5FzD0Td0ExrkswVckpLNR6j17Yaags3ltNVmbdEXekhi6Psf2MLMP
88-
> TSO79lv2L0KeXFGuPOrdzPAwCkV0vNEqTEBeDnZGrjv/5766bM3GW34FXApod9u+VSFpBnqVOCBA
89-
> DVDraA6k+xwBt66cV84OHLkh0kT02SIHMDwGCSqGSIb3DQEHATAdBglghkgBZQMEASoEEJbJaiRl
90-
> KMnBoD1dkb/FzSWAEBaL8xkFwCu0e1ZtDj7nSJc=
91-
> -----END CMS-----
92-
>
93-
> 108 \[C:\\temp\]
94-
> &gt;&gt; $protected | Unprotect-CmsMessage
95-
> Hello World
96-
49+
```powershell
50+
$protected = "Hello World" | Protect-CmsMessage -To "\*[email protected]\*[](mailto:*[email protected]*)"
51+
$protected
52+
-----BEGIN CMS-----
53+
MIIBqAYJKoZIhvcNAQcDoIIBmTCCAZUCAQAxggFQMIIBTAIBADA0MCAxHjAcBgNVBAMMFWxlZWhv
54+
bG1AbWljcm9zb2Z0LmNvbQIQQYHsbcXnjIJCtH+OhGmc1DANBgkqhkiG9w0BAQcwAASCAQAnkFHM
55+
proJnFy4geFGfyNmxH3yeoPvwEYzdnsoVqqDPAd8D3wao77z7OhJEXwz9GeFLnxD6djKV/tF4PxR
56+
E27aduKSLbnxfpf/sepZ4fUkuGibnwWFrxGE3B1G26MCenHWjYQiqv+Nq32Gc97qEAERrhLv6S4R
57+
G+2dJEnesW8A+z9QPo+DwYU5FzD0Td0ExrkswVckpLNR6j17Yaags3ltNVmbdEXekhi6Psf2MLMP
58+
TSO79lv2L0KeXFGuPOrdzPAwCkV0vNEqTEBeDnZGrjv/5766bM3GW34FXApod9u+VSFpBnqVOCBA
59+
DVDraA6k+xwBt66cV84OHLkh0kT02SIHMDwGCSqGSIb3DQEHATAdBglghkgBZQMEASoEEJbJaiRl
60+
KMnBoD1dkb/FzSWAEBaL8xkFwCu0e1ZtDj7nSJc=
61+
-----END CMS-----
62+
63+
$protected | Unprotect-CmsMessage
64+
Hello World
65+
```
9766
Any parameter of type **CMSMessageRecipient** supports identifiers in the following formats:
98-
99-
- An actual certificate (as retrieved from the certificate provider)
100-
101-
- Path to the a file containing the certificate
102-
103-
- Path to a directory containing the certificate
104-
105-
- Thumbprint of the certificate (used to look in the certificate store)
106-
107-
- Subject name of the certificate (used to look in the certificate store)
108-
109-
To view document encryption certificates in the certificate provider, you can use the -**DocumentEncryptionCert** dynamic parameter:
110-
111-
58 \[Cert:\\currentuser\\my\]
112-
113-
&gt;&gt; dir -DocumentEncryptionCert
67+
- An actual certificate (as retrieved from the certificate provider)
68+
- Path to the a file containing the certificate
69+
- Path to a directory containing the certificate
70+
- Thumbprint of the certificate (used to look in the certificate store)
71+
- Subject name of the certificate (used to look in the certificate store)
72+
73+
To view document encryption certificates in the certificate provider, you can use the **-DocumentEncryptionCert** dynamic parameter:
74+
```powershell
75+
dir -DocumentEncryptionCert
76+
```

wmf/audit_overview.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
## Audit PowerShell Usage using Transcript and Logging
1+
# Audit PowerShell Usage using Transcript and Logging
22

3+
[Enhanced Transcription Options](audit_transcript.md)
4+
[Script Tracing and Loggging](audit_script.md)
5+
[Cryptographic Message Syntax (CMS) cmdlets](audit_cms.md)

wmf/audit_script.md

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Script Tracing and Loggging
1+
# Script Tracing and Loggging
22

33
While Windows PowerShell already has the **LogPipelineExecutionDetails** Group Policy setting to log the invocation of cmdlets, Windows PowerShell’s scripting language has plenty of features that you might want to log and/or audit. The new Detailed Script Tracing feature lets you enable detailed tracking and analysis of Windows PowerShell scripting use on a system. After you enable detailed script tracing, Windows PowerShell logs all script blocks to the ETW event log, **Microsoft-Windows-PowerShell/Operational**. If a script block creates another script block (for example, a script that calls the Invoke-Expression cmdlet on a string), that resulting script block is logged as well.
44

@@ -42,94 +42,58 @@ Percent signs in the invocation message represent structured ETW properties. Whi
4242

4343
Here's an example of how this functionality can help unwrap a malicious attempt to encrypt and obfuscate a script:
4444

45-
> \#\# Malware
46-
>
47-
> function SuperDecrypt
48-
>
49-
> {
50-
>
51-
>     param($script)
52-
>
53-
>     $bytes = \[Convert\]::FromBase64String($script)
54-
>
55-
>                
56-
>
57-
>     \#\# XOR “encryption”
58-
>
59-
>     $xorKey = 0x42
60-
>
61-
>     for($counter = 0; $counter -lt $bytes.Length; $counter++)
62-
>
63-
>     {
64-
>
65-
>         $bytes\[$counter\] = $bytes\[$counter\] -bxor $xorKey
66-
>
67-
>     }
68-
>
69-
>     \[System.Text.Encoding\]::Unicode.GetString($bytes)
70-
>
71-
> }
72-
>
73-
> $decrypted = SuperDecrypt "FUIwQitCNkInQm9CCkItQjFCNkJiQmVCEkI1QixCJkJlQg=="
74-
>
75-
> Invoke-Expression $decrypted 
45+
```powershell
46+
\#\# Malware
47+
function SuperDecrypt
48+
{
49+
    param($script)
50+
    $bytes = \[Convert\]::FromBase64String($script)
51+
              
52+
    \#\# XOR “encryption”
53+
    $xorKey = 0x42
54+
    for($counter = 0; $counter -lt $bytes.Length; $counter++)
55+
    {
56+
        $bytes\[$counter\] = $bytes\[$counter\] -bxor $xorKey
57+
    }
58+
    \[System.Text.Encoding\]::Unicode.GetString($bytes)
59+
}
60+
61+
$decrypted = SuperDecrypt "FUIwQitCNkInQm9CCkItQjFCNkJiQmVCEkI1QixCJkJlQg=="
62+
Invoke-Expression $decrypted 
63+
```
7664

7765
Running this generates the following log entries:
78-
66+
```powershell
7967
Compiling Scriptblock text (1 of 1):
80-
8168
function SuperDecrypt
82-
8369
{
84-
8570
param($script)
86-
8771
$bytes = \[Convert\]::FromBase64String($script)
88-
8972
\#\# XOR "encryption"
90-
9173
$xorKey = 0x42
92-
9374
for($counter = 0; $counter -lt $bytes.Length; $counter++)
94-
9575
{
96-
9776
$bytes\[$counter\] = $bytes\[$counter\] -bxor $xorKey
98-
9977
}
100-
10178
\[System.Text.Encoding\]::Unicode.GetString($bytes)
102-
10379
}
104-
10580
ScriptBlock ID: ad8ae740-1f33-42aa-8dfc-1314411877e3
106-
10781
Compiling Scriptblock text (1 of 1):
108-
10982
$decrypted = SuperDecrypt "FUIwQitCNkInQm9CCkItQjFCNkJiQmVCEkI1QixCJkJlQg=="
110-
11183
ScriptBlock ID: ba11c155-d34c-4004-88e3-6502ecb50f52
112-
11384
Compiling Scriptblock text (1 of 1):
114-
11585
Invoke-Expression $decrypted
116-
11786
ScriptBlock ID: 856c01ca-85d7-4989-b47f-e6a09ee4eeb3
118-
11987
Compiling Scriptblock text (1 of 1):
120-
12188
Write-Host 'Pwnd'
122-
12389
ScriptBlock ID: 5e618414-4e77-48e3-8f65-9a863f54b4c8
90+
```
12491

12592
If the script block length exceeds what ETW is capable of holding in a single event, Windows PowerShell breaks the script into multiple parts. Here is sample code to recombine a script from its log messages:
126-
93+
```powershell
12794
    $created = Get-WinEvent -FilterHashtable @{ ProviderName="Microsoft-Windows-PowerShell"; Id = 4104 } |
128-
12995
        Where-Object { $\_.&lt;...&gt; }
130-
13196
    $sortedScripts = $created | sort { $\_.Properties\[0\].Value }
132-
13397
    $mergedScript = -join ($sortedScripts | % { $\_.Properties\[2\].Value })
134-
98+
```
13599
As with all logging systems that have a limited retention buffer (i.e., ETW logs), one attack against this infrastructure is to flood the log with spurious events to hide earlier evidence. To protect yourself from this attack, ensure that you have some form of event log collection set up (i.e., Windows Event Forwarding, <http://www.nsa.gov/ia/_files/app/Spotting_the_Adversary_with_Windows_Event_Log_Monitoring.pdf>) to move event logs off of the computer as soon as possible.

wmf/audit_transcript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Enhanced Transcription Options
1+
# Enhanced Transcription Options
22

33
Windows PowerShell transcription has been improved to apply to all hosting applications (such as Windows PowerShell ISE) rather than just the console host (powershell.exe).
44

wmf/class_base.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Declare Base Class
1+
# Declare Base Class
22
You can declare a Windows PowerShell class as a base type for another Windows PowerShell class.
33

44
```PowerShell

wmf/class_baseconstructor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Call Base Class Constructor
1+
# Call Base Class Constructor
22

33
To call a base class constructor from a subclass, use the keyword **base**.
44
```PowerShell

wmf/class_basemethod.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Call Base Class Method
1+
# Call Base Class Method
22

33
You can override existing methods in subclasses. To do this, declare methods by using the same name and signature.
44
```PowerShell

wmf/class_interface.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Declare Implemented Interface
1+
# Declare Implemented Interface
22

33
You can declare implemented interfaces after base types, or immediately after a colon (:), if there is no base type specified. Separate all type names by using commas. It’s very similar to C\# syntax.
44

0 commit comments

Comments
 (0)