PageRenderTime 31ms CodeModel.GetById 12ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/spec/lib/rex/exploitation/powershell_spec.rb

https://github.com/debbiemezyene/metasploit-framework
Ruby | 47 lines | 38 code | 8 blank | 1 comment | 0 complexity | 6d942b11e4cf990a65490c9516818931 MD5 | raw file
 1# -*- coding:binary -*-
 2require 'spec_helper'
 3
 4require 'rex/exploitation/powershell'
 5
 6describe Rex::Exploitation::Powershell do
 7
 8  let(:example_script) do
 9    """function DumpHashes
10{
11    LoadApi
12    $bootkey = Get-BootKey;
13    $hbootKey = Get-HBootKey $bootkey;
14    Get-UserKeys | %{
15        $hashes = Get-UserHashes $_ $hBootKey;
16        \"{0}:{1}:{2}:{3}:::\" -f ($_.UserName,$_.Rid,
17            [BitConverter]::ToString($hashes[0]).Replace(\"-\",\"\").ToLower(),
18            [BitConverter]::ToString($hashes[1]).Replace(\"-\",\"\").ToLower());
19    }
20}
21DumpHashes"""
22  end
23
24  describe "::read_script" do
25    it 'should create a script from a string input' do
26      script = described_class.read_script(example_script)
27      script.should be_a_kind_of Rex::Exploitation::Powershell::Script
28    end
29  end
30
31  describe "::process_subs" do
32    it 'should create an array of substitutions to process' do
33      subs = described_class.process_subs("BitConverter,ParpConverter;$bootkey,$parpkey;")
34      subs.should eq [['BitConverter','ParpConverter'],['$bootkey','$parpkey']]
35    end
36  end
37
38  describe "::make_subs" do
39    it 'should substitute values in script' do
40      script = described_class.make_subs(example_script,[['BitConverter','ParpConverter']])
41      script.include?('BitConverter').should be_false
42      script.include?('ParpConverter').should be_true
43    end
44  end
45
46end
47