Skip to content

Commit 8a13dc5

Browse files
committed
Add a couple more tests
1 parent e330916 commit 8a13dc5

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

spec/msfvenom_spec.rb

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,24 @@
8686

8787
describe "#parse_args" do
8888

89+
context "help" do
90+
it "should raise UsageError" do
91+
expect { venom.parse_args(%w! -h !) }.to raise_error(MsfVenom::UsageError)
92+
expect { venom.parse_args(%w! --help !) }.to raise_error(MsfVenom::UsageError)
93+
expect { venom.parse_args(%w! --help-formats !) }.to raise_error(MsfVenom::UsageError)
94+
end
95+
end
96+
8997
context "with unexpected options" do
9098
it "should raise" do
91-
expect {
92-
venom.parse_args(%w! --non-existent-option !)
93-
}.to raise_error(MsfVenom::UsageError)
99+
expect { venom.parse_args(%w! --non-existent-option !) }.to raise_error(MsfVenom::UsageError)
94100
end
95101
end
96102

97103
context "with missing required arg" do
98104
%w! --platform -a -b -c -f -p -n -s -i -x !.each do |required_arg|
99105
it "#{required_arg} should raise" do
100-
expect {
101-
venom.parse_args([required_arg])
102-
}.to raise_error(MsfVenom::UsageError)
106+
expect { venom.parse_args([required_arg]) }.to raise_error(MsfVenom::UsageError)
103107
end
104108
end
105109
end
@@ -113,53 +117,64 @@
113117
end
114118

115119
context "with --options" do
120+
116121
context "and a payload" do
117122
let(:args) { %w! -o -p windows/meterpreter/reverse_tcp ! }
118-
119123
it "should print options" do
120-
expect {
121-
venom.generate_raw_payload
122-
}.to_not raise_error
124+
expect { venom.generate_raw_payload }.to_not raise_error
123125
output = stderr.string
124126
output.should include("LHOST")
125127
output.should include("LPORT")
126128
end
127129
end
130+
128131
context "and an invalid payload" do
129132
let(:args) { %w! -o -p asdf! }
130133
it "should raise" do
131-
expect {
132-
venom.generate_raw_payload
133-
}.to raise_error(MsfVenom::UsageError)
134+
expect { venom.generate_raw_payload }.to raise_error(MsfVenom::UsageError)
134135
end
135136
end
136137

137138
end
138139

140+
context "building an elf with linux/x86/shell_bind_tcp" do
141+
let(:args) { %w! -f elf -p linux/x86/shell_bind_tcp ! }
142+
# We're not encoding, so should be testable here
143+
it "should contain /bin/sh" do
144+
output = venom.generate_raw_payload
145+
# usually push'd, so it's not all strung together
146+
output.should include("/sh")
147+
output.should include("/bin")
148+
end
149+
end
150+
151+
context "with a raw linux/x86/shell_bind_tcp" do
152+
let(:args) { %w! -f raw -p linux/x86/shell_bind_tcp ! }
153+
# We're not encoding, so should be testable here
154+
it "should contain /bin/sh" do
155+
output = venom.generate_raw_payload
156+
# usually push'd, so it's not all strung together
157+
output.should include("/sh")
158+
output.should include("/bin")
159+
end
160+
end
161+
139162
end
140163

141164
describe "#generate" do
142165
include_context 'Msf::Util::Exe'
143166

144167
before { venom.parse_args(args) }
145168

146-
context "with 'exe' format" do
147-
let(:args) { %w!-f exe -p windows/shell_reverse_tcp LHOST=192.168.0.1! }
148-
it "should print an exe to stdout" do
149-
expect { venom.generate }.to_not raise_error
150-
output = stdout.string
151-
output[0,2].should == "MZ"
152-
end
153-
end
154-
155-
context "with incorrect datastore option format" do
169+
context "with invalid datastore option" do
156170
let(:args) { %w!-f exe -p windows/shell_reverse_tcp LPORT=asdf! }
157171
it "should fail validation" do
158172
expect { venom.generate }.to raise_error(Msf::OptionValidateError)
159173
end
160174
end
161175

162176
context "without required datastore option" do
177+
# Requires LHOST
163178
let(:args) { %w!-f exe -p windows/shell_reverse_tcp ! }
164179
it "should fail validation" do
165180
expect { venom.generate }.to raise_error(Msf::OptionValidateError)
@@ -168,6 +183,7 @@
168183

169184
@platform_format_map.each do |plat, formats|
170185
formats.each do |format_hash|
186+
# Need a new context for each so the let() will work correctly
171187
context "with format=#{format_hash[:format]} platform=#{plat} arch=#{format_hash[:arch]}" do
172188
# This will build executables with no payload. They won't work
173189
# of course, but at least we can see that it is producing the

0 commit comments

Comments
 (0)