Class: Inspec::Resources::VBScript

Inherits:
Powershell show all
Defined in:
lib/inspec/resources/vbscript.rb

Overview

This resource allows users to run vbscript on windows machines. We decided not to use scriptcontrol, due to the fact that it works on 32 bit systems only: $script = new-object -comobject MSScriptControl.ScriptControl $script.language = “vbscript” $script.ExecuteStatement($Cmd)

For that reason, we call csript.exe directy with the script. Vbscript is embedded in Powershell to ease the file transfer and reuse powershell encodedCommand since train does not allow file upload yet.

We run cscript with /nologo option to get the expected output only with the version information.

Since Windows does not delete tmp files automatically, we remove the VBScript after we executed it

Instance Attribute Summary

Attributes inherited from Cmd

#command

Instance Method Summary collapse

Methods inherited from Powershell

#exist?, #strip

Methods inherited from Cmd

#exist?, #exit_status, #stderr, #stdout

Constructor Details

#initialize(vbscript) ⇒ VBScript

Returns a new instance of VBScript.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inspec/resources/vbscript.rb', line 35

def initialize(vbscript)
  @seperator = SecureRandom.uuid
  cmd = <<~EOH
    $vbscript = @"
    #{vbscript}
    Wscript.Stdout.Write "#{@seperator}"
    "@
    $filename = [System.IO.Path]::GetTempFileName() + ".vbs"
    New-Item $filename -type file -force -value $vbscript | Out-Null
    cscript.exe /nologo $filename
    Remove-Item $filename | Out-Null
  EOH
  super(cmd)
end

Instance Method Details

#resource_idObject

vbscript can be of multiple lines so that can’t be used as UUID so using the hardcoded string.



55
56
57
# File 'lib/inspec/resources/vbscript.rb', line 55

def resource_id
  "Windows VBScript"
end

#resultObject



50
51
52
# File 'lib/inspec/resources/vbscript.rb', line 50

def result
  @result ||= parse_stdout
end

#to_sObject



59
60
61
# File 'lib/inspec/resources/vbscript.rb', line 59

def to_s
  "Windows VBScript"
end