|
1 | 1 | require 'rex/post/meterpreter/packet'
|
2 | 2 |
|
3 | 3 | describe Rex::Post::Meterpreter::Tlv do
|
4 |
| - subject{Rex::Post::Meterpreter::Tlv.new(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test")} |
| 4 | + subject{ |
| 5 | + Rex::Post::Meterpreter::Tlv.new( |
| 6 | + Rex::Post::Meterpreter::TLV_TYPE_STRING, |
| 7 | + "test" |
| 8 | + ) |
| 9 | + } |
5 | 10 |
|
6 | 11 | it "should respond to type" do
|
7 | 12 | subject.should respond_to :type
|
|
48 | 53 | subject.value.should == "test"
|
49 | 54 | end
|
50 | 55 |
|
51 |
| - context "the type? method" do |
| 56 | + context "#type?" do |
52 | 57 | it "should return true for STRING" do
|
53 | 58 | subject.type?(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == true
|
54 | 59 | end
|
|
58 | 63 | end
|
59 | 64 | end
|
60 | 65 |
|
61 |
| - context "the value? method" do |
| 66 | + context "#value?" do |
62 | 67 | it "should return true for the correct value" do
|
63 | 68 | subject.value?("test").should == true
|
64 | 69 | end
|
|
68 | 73 | end
|
69 | 74 | end
|
70 | 75 |
|
71 |
| - context "the inspect method" do |
| 76 | + context "#inspect" do |
72 | 77 | it "should return a string representation of the TLV" do
|
73 | 78 | tlv_to_s = "#<Rex::Post::Meterpreter::Tlv type=STRING meta=STRING value=\"test\">"
|
74 | 79 | subject.inspect.should == tlv_to_s
|
75 | 80 | end
|
76 | 81 | end
|
77 | 82 |
|
78 |
| - context "the to_r method" do |
| 83 | + context "#to_r" do |
79 | 84 | it "should return the raw bytes of the TLV to send over the wire" do
|
80 | 85 | tlv_bytes = "\x00\x00\x00\r\x00\x01\x00\ntest\x00"
|
81 | 86 | subject.to_r.should == tlv_bytes
|
82 | 87 | end
|
83 | 88 | end
|
84 | 89 |
|
85 |
| - context "the from_r method" do |
| 90 | + context "#from_r" do |
86 | 91 | it "should adjust the tlv attributes from the given raw bytes" do
|
87 | 92 | subject.from_r("\x00\x00\x00\r\x00\x01\x00\ntes2\x00")
|
88 | 93 | subject.value.should == "tes2"
|
|
91 | 96 | end
|
92 | 97 |
|
93 | 98 | context "A Method TLV" do
|
94 |
| - subject{Rex::Post::Meterpreter::Tlv.new(Rex::Post::Meterpreter::TLV_TYPE_METHOD,"test")} |
95 |
| - it "should return true when checked for a meta type of String" do |
| 99 | + subject{ |
| 100 | + Rex::Post::Meterpreter::Tlv.new( |
| 101 | + Rex::Post::Meterpreter::TLV_TYPE_METHOD, |
| 102 | + "test" |
| 103 | + ) |
| 104 | + } |
| 105 | + it "should have a meta type of String" do |
96 | 106 | subject.meta_type?(Rex::Post::Meterpreter::TLV_META_TYPE_STRING).should == true
|
97 | 107 | end
|
98 | 108 |
|
|
112 | 122 | end
|
113 | 123 |
|
114 | 124 | describe Rex::Post::Meterpreter::GroupTlv do
|
115 |
| - subject{Rex::Post::Meterpreter::GroupTlv.new(Rex::Post::Meterpreter::TLV_TYPE_CHANNEL_DATA_GROUP)} |
| 125 | + subject{ |
| 126 | + Rex::Post::Meterpreter::GroupTlv.new( |
| 127 | + Rex::Post::Meterpreter::TLV_TYPE_CHANNEL_DATA_GROUP |
| 128 | + ) |
| 129 | + } |
116 | 130 |
|
117 | 131 | it "should respond to tlvs" do
|
118 | 132 | subject.should respond_to :tlvs
|
|
178 | 192 | subject.tlvs.should == []
|
179 | 193 | end
|
180 | 194 |
|
181 |
| - context "the add_tlv method" do |
| 195 | + context "#add_tlv" do |
182 | 196 | it "should add to the tlvs array when given basic tlv paramaters" do
|
183 | 197 | subject.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test")
|
184 | 198 | subject.tlvs.first.type.should == Rex::Post::Meterpreter::TLV_TYPE_STRING
|
|
200 | 214 | end
|
201 | 215 | end
|
202 | 216 |
|
203 |
| - context "the add_tlvs method" do |
| 217 | + context "#add_tlvs" do |
204 | 218 | it "should be able to add an array of type-value hashes" do
|
205 | 219 | tlv_array = [
|
206 | 220 | {'type' => Rex::Post::Meterpreter::TLV_TYPE_STRING, 'value' => "test"},
|
|
254 | 268 | end
|
255 | 269 |
|
256 | 270 |
|
257 |
| - context "the from_r method" do |
| 271 | + context "#from_r" do |
258 | 272 | it "should build the TLV group when given the propper raw bytes" do
|
259 | 273 | subject.reset
|
260 | 274 | subject.from_r( @raw_group)
|
|
265 | 279 | end
|
266 | 280 |
|
267 | 281 |
|
268 |
| - context "the get_tlvs method" do |
| 282 | + context "#get_tlvs" do |
269 | 283 | it "should return all TLVs of the supplied type" do
|
270 | 284 | tlvs = subject.get_tlvs(Rex::Post::Meterpreter::TLV_TYPE_STRING)
|
271 | 285 | tlvs.count.should == 2
|
|
287 | 301 | end
|
288 | 302 | end
|
289 | 303 |
|
290 |
| - context "the get tlv_method" do |
| 304 | + context "#get_tlv" do |
291 | 305 | it "should return the first TLV of the specified type by default" do
|
292 | 306 | subject.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == subject.tlvs.first
|
293 | 307 | subject.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_UINT).should == subject.tlvs.last
|
|
306 | 320 | end
|
307 | 321 | end
|
308 | 322 |
|
309 |
| - context "the get_tlv_value method" do |
| 323 | + context "#get_tlv_value" do |
310 | 324 | it "should return the value of the first TLV with the given type" do
|
311 | 325 | subject.get_tlv_value(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == subject.tlvs.first.value
|
312 | 326 | end
|
|
324 | 338 | end
|
325 | 339 | end
|
326 | 340 |
|
327 |
| - context "the get_tlv_values method" do |
| 341 | + context "#get_tlv_values" do |
328 | 342 | it "should return an array of values for the designated TLV types" do
|
329 | 343 | subject.get_tlv_values(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == ["test", "test2"]
|
330 | 344 | end
|
|
334 | 348 | end
|
335 | 349 | end
|
336 | 350 |
|
337 |
| - context "the has_tlv? method" do |
| 351 | + context "#has_tlv?" do |
338 | 352 | it "should return true if the TLV Type is present" do
|
339 | 353 | subject.has_tlv?(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == true
|
340 | 354 | end
|
|
348 | 362 |
|
349 | 363 | describe Rex::Post::Meterpreter::Packet do
|
350 | 364 | context "Request Packet" do
|
351 |
| - subject{Rex::Post::Meterpreter::Packet.new(Rex::Post::Meterpreter::PACKET_TYPE_REQUEST, "test_method")} |
| 365 | + subject{ |
| 366 | + Rex::Post::Meterpreter::Packet.new( |
| 367 | + Rex::Post::Meterpreter::PACKET_TYPE_REQUEST, |
| 368 | + "test_method" |
| 369 | + ) |
| 370 | + } |
352 | 371 |
|
353 | 372 | it "should respond to created_at" do
|
354 | 373 | subject.should respond_to :created_at
|
|
426 | 445 | end
|
427 | 446 |
|
428 | 447 | context "a response packet" do
|
429 |
| - subject{Rex::Post::Meterpreter::Packet.new(Rex::Post::Meterpreter::PACKET_TYPE_RESPONSE, "test_method")} |
| 448 | + subject{ |
| 449 | + Rex::Post::Meterpreter::Packet.new( |
| 450 | + Rex::Post::Meterpreter::PACKET_TYPE_RESPONSE, |
| 451 | + "test_method" |
| 452 | + ) |
| 453 | + } |
430 | 454 | before(:all) do
|
431 | 455 | subject.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_RESULT, "a-ok")
|
432 | 456 | end
|
|
0 commit comments