Skip to content

Commit a1c7551

Browse files
author
HD Moore
committed
Add spec coverage for appender, fix injector
1 parent 607cc8f commit a1c7551

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require 'spec_helper'
2+
require 'msf/core/exe/segment_appender'
3+
4+
describe Msf::Exe::SegmentAppender do
5+
6+
let(:opts) do
7+
option_hash = {
8+
:template => File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..", "data", "templates", "template_x86_windows.exe"),
9+
:payload => "\xd9\xeb\x9b\xd9\x74\x24",
10+
:arch => :x86
11+
}
12+
end
13+
subject(:injector) { Msf::Exe::SegmentInjector.new(opts) }
14+
15+
it { should respond_to :payload }
16+
it { should respond_to :template }
17+
it { should respond_to :arch }
18+
it { should respond_to :processor }
19+
it { should respond_to :buffer_register }
20+
21+
it 'should return the correct processor for the arch' do
22+
injector.processor.class.should == Metasm::Ia32
23+
injector.arch = :x64
24+
injector.processor.class.should == Metasm::X86_64
25+
end
26+
27+
context '#create_thread_stub' do
28+
it 'should use edx as a default buffer register' do
29+
injector.buffer_register.should == 'edx'
30+
end
31+
32+
context 'when given a non-default buffer register' do
33+
let(:opts) do
34+
option_hash = {
35+
:template => File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..", "data", "templates", "template_x86_windows.exe"),
36+
:payload => "\xd9\xeb\x9b\xd9\x74\x24",
37+
:arch => :x86,
38+
:buffer_register => 'eax'
39+
}
40+
end
41+
it 'should use the correct buffer register' do
42+
injector.buffer_register.should == 'eax'
43+
end
44+
end
45+
end
46+
47+
describe '#generate_pe' do
48+
it 'should return a string' do
49+
injector.generate_pe.kind_of?(String).should == true
50+
end
51+
52+
it 'should produce a valid PE exe' do
53+
expect {Metasm::PE.decode(injector.generate_pe) }.to_not raise_exception
54+
end
55+
56+
context 'the generated exe' do
57+
let(:exe) { Metasm::PE.decode(injector.generate_pe) }
58+
it 'should be the propper arch' do
59+
exe.bitsize.should == 32
60+
end
61+
62+
it 'should have 5 sections' do
63+
exe.sections.count.should == 5
64+
end
65+
66+
it 'should have all the right original section names' do
67+
s_names = []
68+
exe.sections.collect {|s| s_names << s.name}
69+
s_names[0,4].should == [".text", ".rdata", ".data", ".rsrc"]
70+
end
71+
72+
it 'should have the last section set to RWX' do
73+
exe.sections.last.characteristics.should == ["CONTAINS_CODE", "MEM_EXECUTE", "MEM_READ", "MEM_WRITE"]
74+
end
75+
76+
it 'should have an entrypoint that points to the last section' do
77+
exe.optheader.entrypoint.should == exe.sections.last.virtaddr
78+
end
79+
end
80+
end
81+
end
82+

spec/lib/msf/core/exe/segment_injector_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
injector.processor.class.should == Metasm::X86_64
2525
end
2626

27-
context '#payload_as_asm' do
28-
it 'should return the payload as declare byte instructions' do
29-
injector.payload_as_asm.should == "db 0xd9\ndb 0xeb\ndb 0x9b\ndb 0xd9\ndb 0x74\ndb 0x24\n"
30-
end
31-
end
32-
3327
context '#create_thread_stub' do
3428
it 'should use edx as a default buffer register' do
3529
injector.buffer_register.should == 'edx'

0 commit comments

Comments
 (0)