/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 -*-
  2. require 'spec_helper'
  3. require 'rex/exploitation/powershell'
  4. describe Rex::Exploitation::Powershell do
  5. let(:example_script) do
  6. """function DumpHashes
  7. {
  8. LoadApi
  9. $bootkey = Get-BootKey;
  10. $hbootKey = Get-HBootKey $bootkey;
  11. Get-UserKeys | %{
  12. $hashes = Get-UserHashes $_ $hBootKey;
  13. \"{0}:{1}:{2}:{3}:::\" -f ($_.UserName,$_.Rid,
  14. [BitConverter]::ToString($hashes[0]).Replace(\"-\",\"\").ToLower(),
  15. [BitConverter]::ToString($hashes[1]).Replace(\"-\",\"\").ToLower());
  16. }
  17. }
  18. DumpHashes"""
  19. end
  20. describe "::read_script" do
  21. it 'should create a script from a string input' do
  22. script = described_class.read_script(example_script)
  23. script.should be_a_kind_of Rex::Exploitation::Powershell::Script
  24. end
  25. end
  26. describe "::process_subs" do
  27. it 'should create an array of substitutions to process' do
  28. subs = described_class.process_subs("BitConverter,ParpConverter;$bootkey,$parpkey;")
  29. subs.should eq [['BitConverter','ParpConverter'],['$bootkey','$parpkey']]
  30. end
  31. end
  32. describe "::make_subs" do
  33. it 'should substitute values in script' do
  34. script = described_class.make_subs(example_script,[['BitConverter','ParpConverter']])
  35. script.include?('BitConverter').should be_false
  36. script.include?('ParpConverter').should be_true
  37. end
  38. end
  39. end