|
86 | 86 |
|
87 | 87 | describe "#parse_args" do
|
88 | 88 |
|
| 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 | + |
89 | 97 | context "with unexpected options" do
|
90 | 98 | 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) |
94 | 100 | end
|
95 | 101 | end
|
96 | 102 |
|
97 | 103 | context "with missing required arg" do
|
98 | 104 | %w! --platform -a -b -c -f -p -n -s -i -x !.each do |required_arg|
|
99 | 105 | 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) |
103 | 107 | end
|
104 | 108 | end
|
105 | 109 | end
|
|
113 | 117 | end
|
114 | 118 |
|
115 | 119 | context "with --options" do
|
| 120 | + |
116 | 121 | context "and a payload" do
|
117 | 122 | let(:args) { %w! -o -p windows/meterpreter/reverse_tcp ! }
|
118 |
| - |
119 | 123 | 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 |
123 | 125 | output = stderr.string
|
124 | 126 | output.should include("LHOST")
|
125 | 127 | output.should include("LPORT")
|
126 | 128 | end
|
127 | 129 | end
|
| 130 | + |
128 | 131 | context "and an invalid payload" do
|
129 | 132 | let(:args) { %w! -o -p asdf! }
|
130 | 133 | 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) |
134 | 135 | end
|
135 | 136 | end
|
136 | 137 |
|
137 | 138 | end
|
138 | 139 |
|
| 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 | + |
139 | 162 | end
|
140 | 163 |
|
141 | 164 | describe "#generate" do
|
142 | 165 | include_context 'Msf::Util::Exe'
|
143 | 166 |
|
144 | 167 | before { venom.parse_args(args) }
|
145 | 168 |
|
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 |
156 | 170 | let(:args) { %w!-f exe -p windows/shell_reverse_tcp LPORT=asdf! }
|
157 | 171 | it "should fail validation" do
|
158 | 172 | expect { venom.generate }.to raise_error(Msf::OptionValidateError)
|
159 | 173 | end
|
160 | 174 | end
|
161 | 175 |
|
162 | 176 | context "without required datastore option" do
|
| 177 | + # Requires LHOST |
163 | 178 | let(:args) { %w!-f exe -p windows/shell_reverse_tcp ! }
|
164 | 179 | it "should fail validation" do
|
165 | 180 | expect { venom.generate }.to raise_error(Msf::OptionValidateError)
|
|
168 | 183 |
|
169 | 184 | @platform_format_map.each do |plat, formats|
|
170 | 185 | formats.each do |format_hash|
|
| 186 | + # Need a new context for each so the let() will work correctly |
171 | 187 | context "with format=#{format_hash[:format]} platform=#{plat} arch=#{format_hash[:arch]}" do
|
172 | 188 | # This will build executables with no payload. They won't work
|
173 | 189 | # of course, but at least we can see that it is producing the
|
|
0 commit comments