@@ -360,31 +360,99 @@ function Get-PoSHPHPContent {
360360
361361 . EXAMPLE
362362
363- Get-PoSHPHPContent -File "C:\test.php" -QueryString "&" -PHPCgiPath "C:\php.exe"
363+ Get-PoSHPHPContent -PHPCgiPath "C:\php.exe" -File "C:\test.php" -PoSHPHPGET "test=value"
364+
365+ . EXAMPLE
366+
367+ Get-PoSHPHPContent -PHPCgiPath "C:\php.exe" -File "C:\test.php" -PoSHPHPPOST "test=value"
364368
365369#>
366370
367371[CmdletBinding (SupportsShouldProcess = $true )]
368372param (
369373
374+ [Parameter (
375+ Mandatory = $true ,
376+ HelpMessage = ' PHP-Cgi Path' )]
377+ [string ]$PHPCgiPath ,
378+
370379 [Parameter (
371380 Mandatory = $true ,
372381 HelpMessage = ' File Path' )]
373382 [string ]$File ,
374383
375384 [Parameter (
376385 Mandatory = $false ,
377- HelpMessage = ' Query String' )]
378- [string ]$QueryString ,
386+ HelpMessage = ' PHP GET String' )]
387+ [string ]$PoSHPHPGET ,
379388
380389 [Parameter (
381- Mandatory = $true ,
382- HelpMessage = ' PHP-Cgi Path ' )]
383- [string ]$PHPCgiPath
390+ Mandatory = $false ,
391+ HelpMessage = ' PHP POST String ' )]
392+ [string ]$PoSHPHPPOST
384393)
385394
386- $PHPOutput = & $PHPCgiPath -f " $File " " $QueryString "
387- $PHPOutput
395+ # Set PHP Environment
396+ $env: GATEWAY_INTERFACE = " CGI/1.1"
397+ $env: SCRIPT_FILENAME = " $File "
398+ $env: REDIRECT_STATUS = " 200"
399+ $env: SERVER_PROTOCOL = " HTTP/1.1"
400+ $env: HTTP_ACCEPT = " text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
401+ $env: CONTENT_TYPE = " application/x-www-form-urlencoded"
402+
403+ if ($PoSHPHPPOST )
404+ {
405+ # Set PHP POST Environment
406+ $env: REQUEST_METHOD = " POST"
407+ $PHP_CONTENT_LENGTH = $PoSHPHPPOST.Length
408+ $env: CONTENT_LENGTH = " $PHP_CONTENT_LENGTH "
409+
410+ # Get PHP Content
411+ $PHPOutput = " $PoSHPHPPOST " | & $PHPCgiPath
412+ }
413+ else
414+ {
415+ # Set PHP GET Environment
416+ $env: REQUEST_METHOD = " GET"
417+ $env: QUERY_STRING = " $PoSHPHPGET "
418+
419+ # Get PHP Content
420+ $PHPOutput = & $PHPCgiPath
421+ }
422+
423+ # Get PHP Header Line Number
424+ $PHPHeaderLineNumber = ($PHPOutput | Select-String - Pattern " ^$" )[0 ].LineNumber
425+
426+ # Get PHP Header
427+ $PHPHeader = $PHPOutput | Select - First $PHPHeaderLineNumber
428+
429+ # Get Redirection Location
430+ $GetPHPLocation = $PHPHeader | Select-String " Location:"
431+
432+ # Check Redirection Location
433+ if ($GetPHPLocation )
434+ {
435+ $GetPHPLocation = $GetPHPLocation -match ' Location: (.*)/?'
436+ if ($GetPHPLocation -eq $True ) { $PHPRedirectionURL = $Matches [1 ] } else { $PHPRedirectionURL = $Null ; }
437+ }
438+
439+ # Redirect to Location
440+ if ($PHPRedirectionURL )
441+ {
442+ # Redirection Output
443+ $PHPRedirection = ' <html>'
444+ $PHPRedirection += ' <script type="text/javascript">'
445+ $PHPRedirection += ' window.location = "' + $PHPRedirectionURL + ' "'
446+ $PHPRedirection += ' </script>'
447+ $PHPRedirection += ' </html>'
448+ $PHPRedirection
449+ }
450+ else
451+ {
452+ # Output PHP Content
453+ $PHPOutput = $PHPOutput | Select - Skip $PHPHeaderLineNumber
454+ $PHPOutput
455+ }
388456}
389457
390458function Get-PoSHPostStream {
@@ -511,46 +579,6 @@ param (
511579 }
512580}
513581
514- function Get-PoSHPHPQuery {
515-
516- <#
517- . SYNOPSIS
518-
519- Function to get php query
520-
521- . EXAMPLE
522-
523- Get-PoSHPHPQuery -Request $Request
524-
525- #>
526-
527- [CmdletBinding (SupportsShouldProcess = $true )]
528- param (
529-
530- [Parameter (
531- Mandatory = $false ,
532- HelpMessage = ' PHP GET String' )]
533- [string ]$PoSHPHPGET ,
534-
535- [Parameter (
536- Mandatory = $false ,
537- HelpMessage = ' PHP POST String' )]
538- [string ]$PoSHPHPPOST
539- )
540-
541- if ($PoSHPHPGET )
542- {
543- $PHPQueryString = $PoSHPHPGET
544- $PHPQueryString
545- }
546-
547- if ($PoSHPHPPOST )
548- {
549- $PHPQueryString = $PoSHPHPPOST
550- $PHPQueryString
551- }
552- }
553-
554582function Get-PoSHWelcomeBanner {
555583
556584<#
0 commit comments