lib/rex/powershell/output.rb
#
# Return a gzip compressed powershell code wrapped in decoder stub
#
# @param eof [String] End of file identifier to append to code
#
# @return [String] Gzip compressed powershell code wrapped in
# decompression stub
Return a gzip compressed powershell code wrapped in decoder stub
Return a gzip compressed powershell code wrapped in decoder stub
def gzip_code(eof = nil)
      compressed_stream = Rex::Text.gzip(code)
      encoded_stream = Rex::Text.encode_base64(compressed_stream)
      psh_expression = '&([scriptblock]::create((New-Object IO.StreamReader('
      psh_expression << 'New-Object IO.Compression.GzipStream('
      psh_expression << '(New-Object IO.MemoryStream(,'
      psh_expression << "[Convert]::FromBase64String('#{encoded_stream}')))"
      psh_expression << ',[IO.Compression.CompressionMode]::Decompress)'
      psh_expression << ')).ReadToEnd()))'
      psh_expression << "echo '#{eof}';" if eof
      @code = psh_expression
    end
def gzip_code ( eof = nil ) compressed_stream = Rex :: Text . gzip ( code ) encoded_stream = Rex :: Text . encode_base64 ( compressed_stream ) psh_expression = '&([scriptblock]::create((New-Object IO.StreamReader(' psh_expression << 'New-Object IO.Compression.GzipStream(' psh_expression << '(New-Object IO.MemoryStream(,' psh_expression << "[Convert]::FromBase64String('#{encoded_stream}')))" psh_expression << ',[IO.Compression.CompressionMode]::Decompress)' psh_expression << ')).ReadToEnd()))' psh_expression << "echo '#{eof}';" if eof @code = psh_expression end
Return a gzip compressed powershell code wrapped in decoder stub
Return a gzip compressed powershell code wrapped in decoder stub
# Compress using the Gzip algorithm # Base64 encode the compressed file contents # Build the powershell expression # Create and execute script lock fed by the IO.StreamReader # Feed StreamREader from a GzipStream # GzipStream operates on the Memory Stream # MemoryStream consists of base64 encoded compressed data # Set the GzipStream to decompress its MemoryStream contents # Read the decoded, decompressed result into scriptblock contents # If eof is set, add a marker to signify end of code output # if (eof && eof.length == 8) then psh_expression += "'#{eof}'" end
Gzip compressed powershell code wrapped in decompression stub
Gzip compressed powershell code wrapped in decompression stub
String
eof
End of file identifier to append to code
End of file identifier to append to code