1 #ifdef HAVE_PCRE
2 
3 #ifndef NDPI_RCE_H
4 #define NDPI_RCE_H
5 
6 #endif //NDPI_RCE_H
7 
8 #define N_RCE_REGEX 7
9 
10 /* Compiled regex */
11 static struct pcre_struct *comp_rx[N_RCE_REGEX];
12 
13 static unsigned int initialized_comp_rx = 0;
14 
15 static const char *rce_regex[N_RCE_REGEX] = {
16 /**
17  * https://github.com/SpiderLabs/owasp-modsecurity-crs/blob/v3.3/dev/rules/REQUEST-932-APPLICATION-ATTACK-RCE.conf
18  */
19 
20 /**
21  * [ Unix command injection ]
22  *
23  * This regex detects Unix command injections.
24  * A command injection takes a form such as:
25  *
26  *   foo.jpg;uname -a
27  *   foo.jpg||uname -a
28  *
29  * The vulnerability exists when an application executes a shell command
30  * without proper input escaping/validation.
31  *
32  * This regex is also triggered by an Oracle WebLogic Remote Command Execution exploit: [ Oracle WebLogic vulnerability CVE-2017-10271 - Exploit tested: https://www.exploit-db.com/exploits/43458 ]
33  *
34  * To prevent false positives, we look for a 'starting sequence' that
35  * precedes a command in shell syntax, such as: ; | & $( ` <( >(
36  * Anatomy of the regexp with examples of patterns caught:
37  *
38  * 1. Starting tokens
39  *
40  * ;        ;ifconfig
41  * \{       {ifconfig}
42  * \|       |ifconfig
43  * \|\|     ||ifconfig
44  * &        &ifconfig
45  * &&       &&ifconfig
46  * \n       ;\nifconfig
47  * \r       ;\rifconfig
48  * \$\(     $(ifconfig)
49  * $\(\(    $((ifconfig))
50  * `        `ifconfig`
51  * \${      ${ifconfig}
52  * <\(      <( ifconfig )
53  * >\(      >( ifconfig )
54  * \(\s*\)  a() ( ifconfig; ); a
55  *
56  * 2. Command prefixes
57  *
58  * {        { ifconfig }
59  * \s*\(\s* ( ifconfig )
60  * \w+=(?:[^\s]*|\$.*|\$.*|<.*|>.*|\'.*\'|\".*\")\s+   VARNAME=xyz ifconfig
61  * !\s*     ! ifconfig
62  * \$       $ifconfig
63  *
64  * 3. Quoting
65  *
66  * '        'ifconfig'
67  * \"       "ifconfig"
68  *
69  * 4. Paths
70  *
71  * [\?\*\[\]\(\)\-\|+\w'\"\./\\\\]+/   /sbin/ifconfig, /s?in/./ifconfig, /s[a-b]in/ifconfig etc.
72  *
73  * This regex is case-sensitive to prevent FP ("Cat" vs. "cat").
74  *
75  * An effort was made to combat evasions by shell quoting (e.g. 'ls',
76  * 'l'"s", \l\s are all valid).
77  *
78  * This is the base regex to prevent Unix Command Injection
79  */
80 
81   "(?:;|\\{|\\||\\|\\||&|&&|\\n|\\r|\\$\\(|\\$\\(\\(|`|\\${|<\\(|>\\(|\\(\\s*\\))\\s*(?:{|\\s*\\(\\s*|\\w+=(?:[^\\s]*|\\$.*|\\$.*|<.*|>.*|\\'.*\\'|\\\".*\\\")\\s+|!\\s*|\\$)*\\s*(?:'|\\\")*(?:[\\?\\*\\[\\]\\(\\)\\-\\|+\\w'\\\"\\./\\\\\\\\]+/)?[\\\\\\\\'\\\"]*(?:l[\\\\\\\\'\\\"]*(?:w[\\\\\\\\'\\\"]*p[\\\\\\\\'\\\"]*-[\\\\\\\\'\\\"]*(?:d[\\\\\\\\'\\\"]*(?:o[\\\\\\\\'\\\"]*w[\\\\\\\\'\\\"]*n[\\\\\\\\'\\\"]*l[\\\\\\\\'\\\"]*o[\\\\\\\\'\\\"]*a[\\\\\\\\'\\\"]*d|u[\\\\\\\\'\\\"]*m[\\\\\\\\'\\\"]*p)|r[\\\\\\\\'\\\"]*e[\\\\\\\\'\\\"]*q[\\\\\\\\'\\\"]*u[\\\\\\\\'\\\"]*e[\\\\\\\\'\\\"]*s[\\\\\\\\'\\\"]*t|m[\\\\\\\\'\\\"]*i[\\\\\\\\'\\\"]*r[\\\\\\\\'\\\"]*r[\\\\\\\\'\\\"]*o[\\\\\\\\'\\\"]*r)|s(?:[\\\\\\\\'\\\"]*(?:b[\\\\\\\\'\\\"]*_[\\\\\\\\'\\\"]*r[\\\\\\\\'\\\"]*e[\\\\\\\\'\\\"]*l[\\\\\\\\'\\\"]*e[\\\\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'\\\"]*s|m[\\\\\\\\'\\\"]*o[\\\\\\\\'\\\"]*r[\\\\\\\\'\\\"]*e|r[\\\\\\\\'\\\"]*u[\\\\\\\\'\\\"]*n|s[\\\\\\\\'\\\"]*h)|o[\\\\\\\\'\\\"]*(?:p[\\\\\\\\'\\\"]*e[\\\\\\\\'\\\"]*n[\\\\\\\\'\\\"]*s[\\\\\\\\'\\\"]*s[\\\\\\\\'\\\"]*l|n[\\\\\\\\'\\\"]*i[\\\\\\\\'\\\"]*n[\\\\\\\\'\\\"]*t[\\\\\\\\'\\\"]*r)|w[\\\\\\\\'\\\"]*(?:h[\\\\\\\\'\\\"]*o[\\\\\\\\'\\\"]*(?:a[\\\\\\\\'\\\"]*m[\\\\\\\\'\\\"]*i|(?:\\s|<|>).*)|g[\\\\\\\\'\\\"]*e[\\\\\\\\'\\\"]*t|3[\\\\\\\\'\\\"]*m)|v[\\\\\\\\'\\\"]*i[\\\\\\\\'\\\"]*(?:m[\\\\\\\\'\\\"]*(?:\\s|<|>).*|g[\\\\\\\\'\\\"]*r|p[\\\\\\\\'\\\"]*w)|y[\\\\\\\\'\\\"]*u[\\\\\\\\'\\\"]*m)\\b",
84 
85 /* ********************************** */
86 
87 /**
88  * [ Windows command injection ]
89  *
90  * This regex detects Windows shell command injections.
91  *
92  * A command injection takes a form such as:
93  *
94  *   foo.jpg&ver /r
95  *   foo.jpg|ver /r
96  *
97  * The vulnerability exists when an application executes a shell command
98  * without proper input escaping/validation.
99  *
100  * To prevent false positives, we look for a 'starting sequence' that
101  * precedes a command in CMD syntax, such as: ; | & `
102  *
103  * Anatomy of the regexp:
104  *
105  * 1. Starting tokens
106  *
107  * ;        ;cmd
108  * \{       {cmd
109  * \|       |cmd
110  * \|\|     ||cmd
111  * &        &cmd
112  * &&       &&cmd
113  * \n       \ncmd
114  * \r       \rcmd
115  * `        `cmd
116  *
117  * 2. Command prefixes
118  *
119  * (        (cmd)
120  * ,        ,cmd
121  * @        @cmd
122  * '        'cmd'
123  * "        "cmd"
124  * \s       spacing+cmd
125  *
126  * 3. Paths
127  *
128  * [\w'\"\./]+/                          /path/cmd
129  * [\\\\'\"\^]*\w[\\\\'\"\^]*:.*\\\\     C:\Program Files\cmd
130  * [\^\.\w '\"/\\\\]*\\\\)?[\"\^]*       \\net\share\dir\cmd
131  *
132  * 4. Quoting
133  *
134  * \"       "cmd"
135  * \^       ^cmd
136  *
137  * 5. Extension/switches
138  *
139  * \.[\"\^]*\w+      cmd.com, cmd.exe, etc.
140  * /b                cmd/h
141  *
142  * An effort is made to combat evasions by CMD syntax; for example,
143  * the following strings are valid: c^md, @cmd, "c"md.
144  *
145  * This regex is case-insensitive.
146  */
147 
148   "(?i)(?:;|\\{|\\||\\|\\||&|&&|\\n|\\r|`)\\s*[\\(,@\\'\\\"\\s]*(?:[\\w'\\\"\\./]+/|[\\\\\\\\'\\\"\\^]*\\w[\\\\\\\\'\\\"\\^]*:.*\\\\\\\\|[\\^\\.\\w '\\\"/\\\\\\\\]*\\\\\\\\)?[\\\"\\^]*(?:m[\\\"\\^]*(?:y[\\\"\\^]*s[\\\"\\^]*q[\\\"\\^]*l(?:[\\\"\\^]*(?:d[\\\"\\^]*u[\\\"\\^]*m[\\\"\\^]*p(?:[\\\"\\^]*s[\\\"\\^]*l[\\\"\\^]*o[\\\"\\^]*w)?|h[\\\"\\^]*o[\\\"\\^]*t[\\\"\\^]*c[\\\"\\^]*o[\\\"\\^]*p[\\\"\\^]*y|a[\\\"\\^]*d[\\\"\\^]*m[\\\"\\^]*i[\\\"\\^]*n|s[\\\"\\^]*h[\\\"\\^]*o[\\\"\\^]*w))?|s[\\\"\\^]*(?:i[\\\"\\^]*(?:n[\\\"\\^]*f[\\\"\\^]*o[\\\"\\^]*3[\\\"\\^]*2|e[\\\"\\^]*x[\\\"\\^]*e[\\\"\\^]*c)|c[\\\"\\^]*o[\\\"\\^]*n[\\\"\\^]*f[\\\"\\^]*i[\\\"\\^]*g|g[\\\"\\^]*(?:[\\s,;]|\\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\"\\^]*t[\\\"\\^]*r[\\\"\\^]*i[\\\"\\^]*b|s[\\\"\\^]*s[\\\"\\^]*o[\\\"\\^]*c|z[\\\"\\^]*m[\\\"\\^]*a[\\\"\\^]*n)|l[\\\"\\^]*(?:o[\\\"\\^]*g[\\\"\\^]*(?:e[\\\"\\^]*v[\\\"\\^]*e[\\\"\\^]*n[\\\"\\^]*t|t[\\\"\\^]*i[\\\"\\^]*m[\\\"\\^]*e|m[\\\"\\^]*a[\\\"\\^]*n|o[\\\"\\^]*f[\\\"\\^]*f)|a[\\\"\\^]*b[\\\"\\^]*e[\\\"\\^]*l[\\\"\\^]*(?:[\\s,;]|\\.|/|<|>).*|u[\\\"\\^]*s[\\\"\\^]*r[\\\"\\^]*m[\\\"\\^]*g[\\\"\\^]*r)|b[\\\"\\^]*(?:(?:c[\\\"\\^]*d[\\\"\\^]*(?:b[\\\"\\^]*o[\\\"\\^]*o|e[\\\"\\^]*d[\\\"\\^]*i)|r[\\\"\\^]*o[\\\"\\^]*w[\\\"\\^]*s[\\\"\\^]*t[\\\"\\^]*a)[\\\"\\^]*t|i[\\\"\\^]*t[\\\"\\^]*s[\\\"\\^]*a[\\\"\\^]*d[\\\"\\^]*m[\\\"\\^]*i[\\\"\\^]*n|o[\\\"\\^]*o[\\\"\\^]*t[\\\"\\^]*c[\\\"\\^]*f[\\\"\\^]*g)|h[\\\"\\^]*(?:o[\\\"\\^]*s[\\\"\\^]*t[\\\"\\^]*n[\\\"\\^]*a[\\\"\\^]*m[\\\"\\^]*e|d[\\\"\\^]*w[\\\"\\^]*w[\\\"\\^]*i[\\\"\\^]*z)|j[\\\"\\^]*a[\\\"\\^]*v[\\\"\\^]*a[\\\"\\^]*(?:[\\s,;]|\\.|/|<|>).*|7[\\\"\\^]*z(?:[\\\"\\^]*[ar])?)(?:\\.[\\\"\\^]*\\w+)?\\b",
149 
150 /* ********************************** */
151 
152 /**
153  *This regex is also triggered by an Oracle WebLogic Remote Command Execution exploit:
154  *[ Oracle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t[\\\"\\^]*i[\\\"\\^]*n[\\\"\\^]*g[\\\"\\^]*s|r[\\\"\\^]*s[\\\"\\^]*t[\\\"\\^]*a[\\\"\\^]*t)|n[\\\"\\^]*(?:r[\\\"\\^]*a[\\\"\\^]*r|z[\\\"\\^]*i[\\\"\\^]*p))|q[\\\"\\^]*(?:u[\\\"\\^]*e[\\\"\\^]*r[\\\"\\^]*y[\\\"\\^]*(?:[\\s,;]|\\.|/|<|>).*|p[\\\"\\^]*r[\\\"\\^]*o[\\\"\\^]*c[\\\"\\^]*e[\\\"\\^]*s[\\\"\\^]*s|w[\\\"\\^]*i[\\\"\\^]*n[\\\"\\^]*s[\\\"\\^]*t[\\\"\\^]*a|g[\\\"\\^]*r[\\\"\\^]*e[\\\"\\^]*p)|o[\\\"\\^]*(?:d[\\\"\\^]*b[\\\"\\^]*c[\\\"\\^]*(?:a[\\\"\\^]*d[\\\"\\^]*3[\\\"\\^]*2|c[\\\"\\^]*o[\\\"\\^]*n[\\\"\\^]*f)|p[\\\"\\^]*e[\\\"\\^]*n[\\\"\\^]*f[\\\"\\^]*i[\\\"\\^]*l[\\\"\\^]*e[\\\"\\^]*s)|v[\\\"\\^]*(?:o[\\\"\\^]*l[\\\"\\^]*(?:[\\s,;]|\\.|/|<|>).*|e[\\\"\\^]*r[\\\"\\^]*i[\\\"\\^]*f[\\\"\\^]*y)|x[\\\"\\^]*c[\\\"\\^]*(?:a[\\\"\\^]*c[\\\"\\^]*l[\\\"\\^]*s|o[\\\"\\^]*p[\\\"\\^]*y)|z[\\\"\\^]*i[\\\"\\^]*p[\\\"\\^]*(?:[\\s,;]|\\.|/|<|>).*)(?:\\.[\\\"\\^]*\\w+)?\\b",
158 
159 /* ********************************** */
160 
161 /**
162  * [ Unix shell expressions ]
163  *
164  * Detects the following patterns which are common in Unix shell scripts
165  * and oneliners:
166  *
167  * $(foo)    Command substitution
168  * ${foo}    Parameter expansion
169  * <(foo)    Process substitution
170  * >(foo)    Process substitution
171  * $((foo))  Arithmetic expansion
172  */
173 
174   "(?:\\$(?:\\((?:\\(.*\\)|.*)\\)|\\{.*\\})|[<>]\\(.*\\))",
175 
176 /* ********************************** */
177 
178 /**
179  * [ Windows FOR, IF commands ]
180  *
181  * This regex detects Windows command shell FOR and IF commands.
182  *
183  * Examples:
184  *
185  *   FOR              %a IN (set) DO
186  *   FOR /D           %a IN (dirs) DO
187  *   FOR /F "options" %a IN (text|"text") DO
188  *   FOR /L           %a IN (start,step,end) DO
189  *   FOR /R C:\dir    %A IN (set) DO
190  *
191  *   IF [/I] [NOT] EXIST filename | DEFINED define | ERRORLEVEL n | CMDEXTVERSION n
192  *   IF [/I] [NOT] item1   [==|EQU|NEQ|LSS|LEQ|GTR|GEQ] item2
193  *   IF [/I] [NOT] (item1) [==|EQU|NEQ|LSS|LEQ|GTR|GEQ] (item2)
194  *
195  * http://ss64.com/nt/if.html
196  * http://ss64.com/nt/for.html
197  */
198 
199   "\\b(?:if(?:/i)?(?: not)?(?: exist\\b| defined\\b| errorlevel\\b| cmdextversion\\b|(?: |\\().*(?:\\bgeq\\b|\\bequ\\b|\\bneq\\b|\\bleq\\b|\\bgtr\\b|\\blss\\b|==))|for(?:/[dflr].*)? %+[^ ]+ in\\(.*\\)\\s?do)",
200 
201 /* ********************************** */
202 
203 /**
204  * [ Unix direct remote command execution ]
205  *
206  * Detects Unix commands at the start of a parameter (direct RCE).
207  * Example: foo=wget%20www.example.com
208  *
209  * This case is different from command injection, where a
210  * command string is appended (injected) to a regular parameter, and then
211  * passed to a shell unescaped.
212  *
213  * This regex is also triggered by an Oracle WebLogic Remote Command Execution exploit:
214  * [ Oracle WebLogic vulnerability CVE-2017-10271 - Exploit tested: https://www.exploit-db.com/exploits/43458 ]
215  */
216 
217   "(?:^|=)\\s*(?:{|\\s*\\(\\s*|\\w+=(?:[^\\s]*|\\$.*|\\$.*|<.*|>.*|\\'.*\\'|\\\".*\\\")\\s+|!\\s*|\\$)*\\s*(?:'|\\\")*(?:[\\?\\*\\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\\\"]*d|u[\\\\\\\\'\\\"]*p)|v[\\\\\\\\'\\\"]*i[\\\\\\\\'\\\"]*(?:g[\\\\\\\\'\\\"]*r|p[\\\\\\\\'\\\"]*w)|G[\\\\\\\\'\\\"]*E[\\\\\\\\'\\\"]*T)[\\\\\\\\'\\\"]*(?:\\s|;|\\||&|<|>)"
218 };
219 
220 /* ********************************** */
221 
222 /**
223  * [ Unix shell snippets ]
224  *
225  * Detect some common sequences found in shell commands and scripts.
226  *
227  * This regex is also triggered by an Apache Struts Remote Code Execution exploit:
228  * [ Apache Struts vulnerability CVE-2017-9805 - Exploit tested: https://www.exploit-db.com/exploits/42627 ]
229  *
230  * This regex is also triggered by an Oracle WebLogic Remote Command Execution exploit:
231  * [ Oracle WebLogic vulnerability CVE-2017-10271 - Exploit tested: https://www.exploit-db.com/exploits/43458 ]
232  */
233 
234 static const char *ush_commands[] = {
235   "${CDPATH}",
236   "${DIRSTACK}",
237   "${HOME}",
238   "${HOSTNAME}",
239   "${IFS}",
240   "${OLDPWD}",
241   "${OSTYPE}",
242   "${PATH}",
243   "${PWD}",
244   "$CDPATH",
245   "$DIRSTACK",
246   "$HOME",
247   "$HOSTNAME",
248   "$IFS",
249   "$OLDPWD",
250   "$OSTYPE",
251   "$PATH",
252   "$PWD",
253   "bin/bash",
254   "bin/cat",
255   "bin/csh",
256   "bin/dash",
257   "bin/du",
258   "bin/echo",
259   "bin/grep",
260   "bin/less",
261   "bin/ls",
262   "bin/mknod",
263   "bin/more",
264   "bin/nc",
265   "bin/ps",
266   "bin/rbash",
267   "bin/sh",
268   "bin/sleep",
269   "bin/su",
270   "bin/tcsh",
271   "bin/uname",
272   "dev/fd/",
273   "dev/null",
274   "dev/stderr",
275   "dev/stdin",
276   "dev/stdout",
277   "dev/tcp/",
278   "dev/udp/",
279   "dev/zero",
280   "etc/group",
281   "etc/master.passwd",
282   "etc/passwd",
283   "etc/pwd.db",
284   "etc/shadow",
285   "etc/shells",
286   "etc/spwd.db",
287   "proc/self/",
288   "usr/bin/awk",
289   "usr/bin/base64",
290   "usr/bin/cat",
291   "usr/bin/cc",
292   "usr/bin/clang",
293   "usr/bin/clang++",
294   "usr/bin/curl",
295   "usr/bin/diff",
296   "usr/bin/env",
297   "usr/bin/fetch",
298   "usr/bin/file",
299   "usr/bin/find",
300   "usr/bin/ftp",
301   "usr/bin/gawk",
302   "usr/bin/gcc",
303   "usr/bin/head",
304   "usr/bin/hexdump",
305   "usr/bin/id",
306   "usr/bin/less",
307   "usr/bin/ln",
308   "usr/bin/mkfifo",
309   "usr/bin/more",
310   "usr/bin/nc",
311   "usr/bin/ncat",
312   "usr/bin/nice",
313   "usr/bin/nmap",
314   "usr/bin/perl",
315   "usr/bin/php",
316   "usr/bin/php5",
317   "usr/bin/php7",
318   "usr/bin/php-cgi",
319   "usr/bin/printf",
320   "usr/bin/psed",
321   "usr/bin/python",
322   "usr/bin/python2",
323   "usr/bin/python3",
324   "usr/bin/ruby",
325   "usr/bin/sed",
326   "usr/bin/socat",
327   "usr/bin/tail",
328   "usr/bin/tee",
329   "usr/bin/telnet",
330   "usr/bin/top",
331   "usr/bin/uname",
332   "usr/bin/wget",
333   "usr/bin/who",
334   "usr/bin/whoami",
335   "usr/bin/xargs",
336   "usr/bin/xxd",
337   "usr/bin/yes",
338   "usr/local/bin/bash",
339   "usr/local/bin/curl",
340   "usr/local/bin/ncat",
341   "usr/local/bin/nmap",
342   "usr/local/bin/perl",
343   "usr/local/bin/php",
344   "usr/local/bin/python",
345   "usr/local/bin/python2",
346   "usr/local/bin/python3",
347   "usr/local/bin/rbash",
348   "usr/local/bin/ruby",
349   "usr/local/bin/wget"
350 };
351 
352 /* ********************************** */
353 
354 /**
355  * [ Windows PowerShell, cmdlets and options ]
356  *
357  * Detect some common PowerShell commands, cmdlets and options.
358  * These commands should be relatively uncommon in normal text, but
359  * potentially useful for code injection.
360  */
361 
362 static const char *pwsh_commands[] = {
363   "powershell.exe",
364   "Add-BitsFile",
365   "Add-Computer",
366   "Add-Content",
367   "Add-History",
368   "Add-Member",
369   "Add-PSSnapin",
370   "Add-Type",
371   "Checkpoint-Computer",
372   "Clear-Content",
373   "Clear-EventLog",
374   "Clear-History",
375   "Clear-Item",
376   "Clear-ItemProperty",
377   "Clear-Variable",
378   "Compare-Object",
379   "Complete-BitsTransfer",
380   "Complete-Transaction",
381   "Connect-WSMan",
382   "ConvertFrom-CSV",
383   "ConvertFrom-SecureString",
384   "ConvertFrom-StringData",
385   "Convert-Path",
386   "ConvertTo-CSV",
387   "ConvertTo-Html",
388   "ConvertTo-SecureString",
389   "ConvertTo-XML",
390   "Copy-Item",
391   "Copy-ItemProperty",
392   "Debug-Process",
393   "Disable-ComputerRestore",
394   "Disable-PSBreakpoint",
395   "Disable-PSSessionConfiguration",
396   "Disable-WSManCredSSP",
397   "Disconnect-WSMan",
398   "Enable-ComputerRestore",
399   "Enable-PSBreakpoint",
400   "Enable-PSRemoting",
401   "Enable-PSSessionConfiguration",
402   "Enable-WSManCredSSP",
403   "Enter-PSSession",
404   "Exit-PSSession",
405   "Export-Alias",
406   "Export-Clixml",
407   "Export-Console",
408   "Export-Counter",
409   "Export-CSV",
410   "Export-FormatData",
411   "Export-ModuleMember",
412   "Export-PSSession",
413   "ForEach-Object",
414   "Format-Custom",
415   "Format-List",
416   "Format-Table",
417   "Format-Wide",
418   "Get-Acl",
419   "Get-Alias",
420   "Get-AppLockerFileInformation",
421   "Get-AppLockerPolicy",
422   "Get-AuthenticodeSignature",
423   "Get-BitsTransfer",
424   "Get-ChildItem",
425   "Get-Command",
426   "Get-ComputerRestorePoint",
427   "Get-Content",
428   "Get-Counter",
429   "Get-Credential",
430   "Get-Culture",
431   "Get-Event",
432   "Get-EventLog",
433   "Get-EventSubscriber",
434   "Get-ExecutionPolicy",
435   "Get-FormatData",
436   "Get-History",
437   "Get-Host",
438   "Get-HotFix",
439   "Get-Item",
440   "Get-ItemProperty",
441   "Get-Job",
442   "Get-Location",
443   "Get-Member",
444   "Get-Module",
445   "Get-PfxCertificate",
446   "Get-Process",
447   "Get-PSBreakpoint",
448   "Get-PSCallStack",
449   "Get-PSDrive",
450   "Get-PSProvider",
451   "Get-PSSession",
452   "Get-PSSessionConfiguration",
453   "Get-PSSnapin",
454   "Get-Random",
455   "Get-Service",
456   "Get-TraceSource",
457   "Get-Transaction",
458   "Get-TroubleshootingPack",
459   "Get-UICulture",
460   "Get-Unique",
461   "Get-Variable",
462   "Get-WinEvent",
463   "Get-WmiObject",
464   "Get-WSManCredSSP",
465   "Get-WSManInstance",
466   "Group-Object",
467   "Import-Alias",
468   "Import-Clixml",
469   "Import-Counter",
470   "Import-CSV",
471   "Import-LocalizedData",
472   "Import-Module",
473   "Import-PSSession",
474   "Invoke-Command",
475   "Invoke-Expression",
476   "Invoke-History",
477   "Invoke-Item",
478   "Invoke-TroubleshootingPack",
479   "Invoke-WmiMethod",
480   "Invoke-WSManAction",
481   "Join-Path",
482   "Limit-EventLog",
483   "Measure-Command",
484   "Measure-Object",
485   "Move-Item",
486   "Move-ItemProperty",
487   "New-Alias",
488   "New-AppLockerPolicy",
489   "New-Event",
490   "New-EventLog",
491   "New-Item",
492   "New-ItemProperty",
493   "New-Module",
494   "New-ModuleManifest",
495   "New-Object",
496   "New-PSDrive",
497   "New-PSSession",
498   "New-PSSessionOption",
499   "New-Service",
500   "New-TimeSpan",
501   "New-Variable",
502   "New-WebServiceProxy",
503   "New-WSManInstance",
504   "New-WSManSessionOption",
505   "Out-Default",
506   "Out-File",
507   "Out-GridView",
508   "Out-Host",
509   "Out-Null",
510   "Out-Printer",
511   "Out-String",
512   "Pop-Location",
513   "Push-Location",
514   "Read-Host",
515   "Receive-Job",
516   "Register-EngineEvent",
517   "Register-ObjectEvent",
518   "Register-PSSessionConfiguration",
519   "Register-WmiEvent",
520   "Remove-BitsTransfer",
521   "Remove-Computer",
522   "Remove-Event",
523   "Remove-EventLog",
524   "Remove-Item",
525   "Remove-ItemProperty",
526   "Remove-Job",
527   "Remove-Module",
528   "Remove-PSBreakpoint",
529   "Remove-PSDrive",
530   "Remove-PSSession",
531   "Remove-PSSnapin",
532   "Remove-Variable",
533   "Remove-WmiObject",
534   "Remove-WSManInstance",
535   "Rename-Item",
536   "Rename-ItemProperty",
537   "Reset-ComputerMachinePassword",
538   "Resolve-Path",
539   "Restart-Computer",
540   "Restart-Service",
541   "Restore-Computer",
542   "Resume-BitsTransfer",
543   "Resume-Service",
544   "Select-Object",
545   "Select-String",
546   "Select-XML",
547   "Send-MailMessage",
548   "Set-Acl",
549   "Set-Alias",
550   "Set-AppLockerPolicy",
551   "Set-AuthenticodeSignature",
552   "Set-BitsTransfer",
553   "Set-Content",
554   "Set-Date",
555   "Set-ExecutionPolicy",
556   "Set-Item",
557   "Set-ItemProperty",
558   "Set-Location",
559   "Set-PSBreakpoint",
560   "Set-PSDebug",
561   "Set-PSSessionConfiguration",
562   "Set-Service",
563   "Set-StrictMode",
564   "Set-TraceSource",
565   "Set-Variable",
566   "Set-WmiInstance",
567   "Set-WSManInstance",
568   "Set-WSManQuickConfig",
569   "Show-EventLog",
570   "Sort-Object",
571   "Split-Path",
572   "Start-BitsTransfer",
573   "Start-Job",
574   "Start-Process",
575   "Start-Service",
576   "Start-Sleep",
577   "Start-Transaction",
578   "Start-Transcript",
579   "Stop-Computer",
580   "Stop-Job",
581   "Stop-Process",
582   "Stop-Service",
583   "Stop-Transcript",
584   "Suspend-BitsTransfer",
585   "Suspend-Service",
586   "Tee-Object",
587   "Test-AppLockerPolicy",
588   "Test-ComputerSecureChannel",
589   "Test-Connection",
590   "Test-ModuleManifest",
591   "Test-Path",
592   "Test-WSMan",
593   "Trace-Command",
594   "Undo-Transaction",
595   "Unregister-Event",
596   "Unregister-PSSessionConfiguration",
597   "Update-FormatData",
598   "Update-List",
599   "Update-TypeData",
600   "Use-Transaction",
601   "Wait-Event",
602   "Wait-Job",
603   "Wait-Process",
604   "Where-Object",
605   "Write-Debug",
606   "Write-Error",
607   "Write-EventLog",
608   "Write-Host",
609   "Write-Output",
610   "Write-Progress",
611   "Write-Verbose",
612   "Write-Warning",
613   "-EncodedCommand",
614   "-ExecutionPolicy",
615   "-PSConsoleFile"
616 };
617 
618 #endif //HAVE_PCRE