2012-12-05 20:39:29 +00:00
|
|
|
require 'rex/post/meterpreter/packet'
|
|
|
|
|
|
|
|
describe Rex::Post::Meterpreter::Tlv do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:tlv) {
|
2012-12-12 16:12:42 +00:00
|
|
|
Rex::Post::Meterpreter::Tlv.new(
|
|
|
|
Rex::Post::Meterpreter::TLV_TYPE_STRING,
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
}
|
2012-12-05 20:39:29 +00:00
|
|
|
|
|
|
|
it "should respond to type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :type
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :value
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to compress" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :compress
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to inspect" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :inspect
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to meta_type?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :meta_type?
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to type?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :type?
|
|
|
|
end
|
2012-12-05 20:39:29 +00:00
|
|
|
|
|
|
|
it "should respond to value?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :value?
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to to_r" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :to_r
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to from_r" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.should respond_to :from_r
|
2012-12-05 20:39:29 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 21:44:03 +00:00
|
|
|
context "A String TLV" do
|
|
|
|
it "should return the correct TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.type.should == Rex::Post::Meterpreter::TLV_TYPE_STRING
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the correct value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.value.should == "test"
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#type?" do
|
2012-12-05 21:44:03 +00:00
|
|
|
it "should return true for STRING" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.type?(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == true
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for UINT" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.type?(Rex::Post::Meterpreter::TLV_TYPE_UINT).should == false
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#value?" do
|
2012-12-05 21:44:03 +00:00
|
|
|
it "should return true for the correct value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.value?("test").should == true
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for an incorrect value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.value?("fake").should == false
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#inspect" do
|
2012-12-05 21:44:03 +00:00
|
|
|
it "should return a string representation of the TLV" do
|
|
|
|
tlv_to_s = "#<Rex::Post::Meterpreter::Tlv type=STRING meta=STRING value=\"test\">"
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.inspect.should == tlv_to_s
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#to_r" do
|
2012-12-05 21:44:03 +00:00
|
|
|
it "should return the raw bytes of the TLV to send over the wire" do
|
|
|
|
tlv_bytes = "\x00\x00\x00\r\x00\x01\x00\ntest\x00"
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.to_r.should == tlv_bytes
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#from_r" do
|
2012-12-05 21:44:03 +00:00
|
|
|
it "should adjust the tlv attributes from the given raw bytes" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.from_r("\x00\x00\x00\r\x00\x01\x00\ntes2\x00")
|
|
|
|
tlv.value.should == "tes2"
|
2012-12-05 21:44:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-05 23:55:28 +00:00
|
|
|
context "A Method TLV" do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:tlv) {
|
2012-12-12 16:12:42 +00:00
|
|
|
Rex::Post::Meterpreter::Tlv.new(
|
|
|
|
Rex::Post::Meterpreter::TLV_TYPE_METHOD,
|
|
|
|
"test"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
it "should have a meta type of String" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.meta_type?(Rex::Post::Meterpreter::TLV_META_TYPE_STRING).should == true
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should show the correct type and meta type in inspect" do
|
|
|
|
tlv_to_s = "#<Rex::Post::Meterpreter::Tlv type=METHOD meta=STRING value=\"test\">"
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.inspect.should == tlv_to_s
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "A String TLV with a number value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:tlv) {
|
|
|
|
Rex::Post::Meterpreter::Tlv.new(Rex::Post::Meterpreter::TLV_TYPE_STRING,5)
|
|
|
|
}
|
2012-12-05 23:55:28 +00:00
|
|
|
it "should return the string version of the number" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlv.value.should == "5"
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Rex::Post::Meterpreter::GroupTlv do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:group_tlv) {
|
2012-12-12 16:12:42 +00:00
|
|
|
Rex::Post::Meterpreter::GroupTlv.new(
|
|
|
|
Rex::Post::Meterpreter::TLV_TYPE_CHANNEL_DATA_GROUP
|
|
|
|
)
|
|
|
|
}
|
2012-12-05 23:55:28 +00:00
|
|
|
|
|
|
|
it "should respond to tlvs" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :tlvs
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|
|
|
|
|
2012-12-06 00:19:12 +00:00
|
|
|
it "should respond to each" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :each
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to each_tlv" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :each_tlv
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to each_with_index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :each_with_index
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to each_tlv_with_index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :each_tlv_with_index
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to get_tlvs" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :get_tlvs
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to add_tlv" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :add_tlv
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to add_tlvs" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :add_tlvs
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to get_tlv" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :get_tlv
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to get_tlv_value" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :get_tlv_value
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to get_tlv_values" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :get_tlv_values
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to has_tlv?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :has_tlv?
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to reset" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :reset
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to to_r" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :to_r
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to from_r" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.should respond_to :from_r
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
2012-12-05 23:55:28 +00:00
|
|
|
it "should return an empty array for tlvs by default" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.tlvs.should == []
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#add_tlv" do
|
2012-12-06 00:19:12 +00:00
|
|
|
it "should add to the tlvs array when given basic tlv paramaters" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test")
|
|
|
|
group_tlv.tlvs.first.type.should == Rex::Post::Meterpreter::TLV_TYPE_STRING
|
|
|
|
group_tlv.tlvs.first.value.should == "test"
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should replace any existing TLV of the same type when the replace flag is set to true" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test")
|
|
|
|
group_tlv.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test2", true)
|
|
|
|
group_tlv.tlvs.count.should == 1
|
|
|
|
group_tlv.tlvs.first.value.should == "test2"
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should add both if replace is set to false" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test")
|
|
|
|
group_tlv.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,"test2", false)
|
|
|
|
group_tlv.tlvs.first.value.should == "test"
|
|
|
|
group_tlv.tlvs.last.value.should == "test2"
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#add_tlvs" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should be able to add an array of type-value hashes" do
|
|
|
|
tlv_array = [
|
|
|
|
{'type' => Rex::Post::Meterpreter::TLV_TYPE_STRING, 'value' => "test"},
|
|
|
|
{'type' => Rex::Post::Meterpreter::TLV_TYPE_STRING, 'value' => "test2"}
|
|
|
|
]
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlvs(tlv_array)
|
|
|
|
group_tlv.tlvs.count.should == 2
|
|
|
|
group_tlv.tlvs.first.value.should == "test"
|
|
|
|
group_tlv.tlvs.last.value.should == "test2"
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise an error when given something other than nil or an array" do
|
|
|
|
pending "RM #7598"
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlvs("bad value").should raise_error
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise an error when given an array of objects other than hashes" do
|
|
|
|
pending "RM #7598"
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlvs([1,2,3]).should raise_error
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
2012-12-06 00:19:12 +00:00
|
|
|
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should raise an error when any of the hashes are missing a key" do
|
|
|
|
pending "RM #7598"
|
|
|
|
tlv_array = [
|
|
|
|
{:type => Rex::Post::Meterpreter::TLV_TYPE_STRING, :value => "test"},
|
|
|
|
{:type => Rex::Post::Meterpreter::TLV_TYPE_STRING}
|
|
|
|
]
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlvs(tlv_array).should raise_error
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with TLVs added" do
|
2012-12-06 23:59:07 +00:00
|
|
|
before(:each) do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.reset
|
2012-12-06 23:59:07 +00:00
|
|
|
tlv_array = [
|
|
|
|
{'type' => Rex::Post::Meterpreter::TLV_TYPE_STRING, 'value' => "test"},
|
|
|
|
{'type' => Rex::Post::Meterpreter::TLV_TYPE_STRING, 'value' => "test2"},
|
|
|
|
{'type' => Rex::Post::Meterpreter::TLV_TYPE_UINT, 'value' => 5}
|
|
|
|
]
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.add_tlvs(tlv_array)
|
2012-12-06 23:59:07 +00:00
|
|
|
@raw_group = "\x00\x00\x00/@\x00\x005\x00\x00\x00\r\x00\x01\x00\ntest\x00\x00\x00\x00\x0E\x00\x01\x00\ntest2\x00\x00\x00\x00\f\x00\x02\x00\v\x00\x00\x00\x05"
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
2012-12-06 23:59:07 +00:00
|
|
|
|
|
|
|
it "should empty the array of TLV when reset is called" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.reset
|
|
|
|
group_tlv.tlvs.should == []
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert to raw bytes when to_r is called" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.to_r.should == @raw_group
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#from_r" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should build the TLV group when given the propper raw bytes" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.reset
|
|
|
|
group_tlv.from_r( @raw_group)
|
|
|
|
group_tlv.tlvs[0].inspect.should == "#<Rex::Post::Meterpreter::Tlv type=STRING meta=STRING value=\"test\">"
|
|
|
|
group_tlv.tlvs[1].inspect.should == "#<Rex::Post::Meterpreter::Tlv type=STRING meta=STRING value=\"test2\">"
|
|
|
|
group_tlv.tlvs[2].inspect.should == "#<Rex::Post::Meterpreter::Tlv type=UINT meta=INT value=5>"
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#get_tlvs" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should return all TLVs of the supplied type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlvs = group_tlv.get_tlvs(Rex::Post::Meterpreter::TLV_TYPE_STRING)
|
2012-12-06 23:59:07 +00:00
|
|
|
tlvs.count.should == 2
|
|
|
|
tlvs.first.value.should == "test"
|
|
|
|
tlvs.last.value.should == "test2"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return all TLVs when supplied the ANY TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
tlvs = group_tlv.get_tlvs(Rex::Post::Meterpreter::TLV_TYPE_ANY)
|
|
|
|
tlvs.count.should == group_tlv.tlvs.count
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return an empty array for a TLV type that isn't present" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlvs(Rex::Post::Meterpreter::TLV_TYPE_BOOL).should == []
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return an empty array for a nonexistant TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlvs(55555555).should == []
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#get_tlv" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should return the first TLV of the specified type by default" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == group_tlv.tlvs.first
|
|
|
|
group_tlv.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_UINT).should == group_tlv.tlvs.last
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the correct TLV of the specified type for the given index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,1).should == group_tlv.tlvs[1]
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if given an out of bounds index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_STRING,5).should == nil
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if given a non-present TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv(Rex::Post::Meterpreter::TLV_TYPE_BOOL).should == nil
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#get_tlv_value" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should return the value of the first TLV with the given type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_value(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == group_tlv.tlvs.first.value
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the correct TLV value of the specified type for the given index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_value(Rex::Post::Meterpreter::TLV_TYPE_STRING,1).should == group_tlv.tlvs[1].value
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if given an out of bounds index" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_value(Rex::Post::Meterpreter::TLV_TYPE_STRING,5).should == nil
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return nil if given a non-present TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_value(Rex::Post::Meterpreter::TLV_TYPE_BOOL).should == nil
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#get_tlv_values" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should return an array of values for the designated TLV types" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_values(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == ["test", "test2"]
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return an empty array for a non-present TLV type" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.get_tlv_values(Rex::Post::Meterpreter::TLV_TYPE_BOOL).should == []
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 16:12:42 +00:00
|
|
|
context "#has_tlv?" do
|
2012-12-06 23:59:07 +00:00
|
|
|
it "should return true if the TLV Type is present" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.has_tlv?(Rex::Post::Meterpreter::TLV_TYPE_STRING).should == true
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if the TLV type is not present" do
|
2013-04-25 15:24:36 +00:00
|
|
|
group_tlv.has_tlv?(Rex::Post::Meterpreter::TLV_TYPE_BOOL).should == false
|
2012-12-06 23:59:07 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Rex::Post::Meterpreter::Packet do
|
|
|
|
context "Request Packet" do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:packet) {
|
2012-12-12 16:12:42 +00:00
|
|
|
Rex::Post::Meterpreter::Packet.new(
|
2013-04-25 15:24:36 +00:00
|
|
|
Rex::Post::Meterpreter::PACKET_TYPE_REQUEST,
|
2012-12-12 16:12:42 +00:00
|
|
|
"test_method"
|
|
|
|
)
|
|
|
|
}
|
2012-12-06 23:59:07 +00:00
|
|
|
|
2012-12-07 18:32:34 +00:00
|
|
|
it "should respond to created_at" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :created_at
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to response?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :response?
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
2012-12-06 23:59:07 +00:00
|
|
|
|
2012-12-07 18:32:34 +00:00
|
|
|
it "should respond to method?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :method?
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to method" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :method
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to result?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :result?
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to result=" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :result=
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to result" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :result
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond to rid" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.should respond_to :rid
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for response?" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.response?.should == false
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should evaluate the method correctly" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.method?("test_method").should == true
|
|
|
|
packet.method?("blah").should == false
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should accept new methods" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.method= "test_method2"
|
|
|
|
packet.method?("test_method2").should == true
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the correct method" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.method.should == "test_method"
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not have a result" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.result.should == nil
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return a valid request id" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.rid.should =~ /\A\d{32}\Z/
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be created when Packet.create_request is called" do
|
|
|
|
req = Rex::Post::Meterpreter::Packet.create_request("test_method")
|
|
|
|
req.class.should == Rex::Post::Meterpreter::Packet
|
|
|
|
req.response?.should == false
|
|
|
|
req.method?("test_method").should == true
|
|
|
|
end
|
2012-12-07 18:51:53 +00:00
|
|
|
|
|
|
|
it "should return the correct raw byte form of the packet" do
|
2013-04-25 15:24:36 +00:00
|
|
|
rid = packet.rid
|
|
|
|
meth = packet.method
|
|
|
|
raw = packet.to_r
|
|
|
|
packet.from_r(raw)
|
|
|
|
packet.rid.should == rid
|
|
|
|
packet.method.should == meth
|
2012-12-07 18:51:53 +00:00
|
|
|
end
|
2012-12-06 00:19:12 +00:00
|
|
|
end
|
|
|
|
|
2012-12-07 18:32:34 +00:00
|
|
|
context "a response packet" do
|
2013-04-25 15:24:36 +00:00
|
|
|
subject(:packet) {
|
2012-12-12 16:12:42 +00:00
|
|
|
Rex::Post::Meterpreter::Packet.new(
|
2013-04-25 15:24:36 +00:00
|
|
|
Rex::Post::Meterpreter::PACKET_TYPE_RESPONSE,
|
2012-12-12 16:12:42 +00:00
|
|
|
"test_method"
|
|
|
|
)
|
|
|
|
}
|
2013-04-25 15:24:36 +00:00
|
|
|
before(:each) do
|
|
|
|
packet.add_tlv(Rex::Post::Meterpreter::TLV_TYPE_RESULT, "a-ok")
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return the correct result" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.result.should == "a-ok"
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should evaluate result correctly" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.result?("a-ok").should == true
|
|
|
|
packet.result?("5by5").should == false
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
2012-12-06 00:19:12 +00:00
|
|
|
|
2012-12-07 18:32:34 +00:00
|
|
|
it "should accept a new result" do
|
2013-04-25 15:24:36 +00:00
|
|
|
packet.result = "test2"
|
|
|
|
packet.result.should == "test2"
|
2012-12-07 18:32:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be created when Packet.create_response is called" do
|
|
|
|
resp = Rex::Post::Meterpreter::Packet.create_response
|
|
|
|
resp.class.should == Rex::Post::Meterpreter::Packet
|
|
|
|
resp.response?.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-12-05 23:55:28 +00:00
|
|
|
end
|