Module: Rex::Powershell

Defined in:
lib/rex/powershell.rb,
lib/rex/powershell/obfu.rb,
lib/rex/powershell/param.rb,
lib/rex/powershell/output.rb,
lib/rex/powershell/parser.rb,
lib/rex/powershell/script.rb,
lib/rex/powershell/command.rb,
lib/rex/powershell/payload.rb,
lib/rex/powershell/function.rb,
lib/rex/powershell/psh_methods.rb

Defined Under Namespace

Modules: Command, Obfu, Output, Parser, Payload, PshMethods Classes: Function, Param, Script

Class Method Summary collapse

Class Method Details

.make_subs(script, subs) ⇒ String

Insert substitutions into the powershell script If script is a path to a file then read the file otherwise treat it as the contents of a file

Parameters:

  • script (String)

    Script file or path to script

  • subs (Array)

    Substitutions to insert

Returns:

  • (String)

    Modified script file



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rex/powershell.rb', line 34

def self.make_subs(script, subs)
  if ::File.file?(script)
    script = ::File.read(script)
  end

  subs.each do |set|
    script.gsub!(set[0], set[1])
  end

  script
end

.process_subs(subs) ⇒ Array

Return an array of substitutions for use in make_subs

Parameters:

  • subs (String)

    A ; seperated list of substitutions

Returns:

  • (Array)

    An array of substitutions



52
53
54
55
56
57
58
59
60
# File 'lib/rex/powershell.rb', line 52

def self.process_subs(subs)
  return [] if subs.nil? or subs.empty?
  new_subs = []
  subs.split(';').each do |set|
    new_subs << set.split(',', 2)
  end

  new_subs
end

.read_script(script_path) ⇒ Script

Reads script into a Powershell::Script

Parameters:

  • script_path (String)

    Path to the Script File

Returns:

  • (Script)

    Powershell Script object



21
22
23
# File 'lib/rex/powershell.rb', line 21

def self.read_script(script_path)
  Rex::Powershell::Script.new(script_path)
end