From ee6db8794e10d37407318544ee4e4d69c16c3663 Mon Sep 17 00:00:00 2001 From: David Maloney Date: Thu, 27 Dec 2012 17:19:37 -0600 Subject: [PATCH] Basic specs for meterpreter packet parser --- .../post/meterpreter/packet_parser_spec.rb | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/spec/lib/rex/post/meterpreter/packet_parser_spec.rb b/spec/lib/rex/post/meterpreter/packet_parser_spec.rb index 8b31b53f2f..4fefeebe76 100644 --- a/spec/lib/rex/post/meterpreter/packet_parser_spec.rb +++ b/spec/lib/rex/post/meterpreter/packet_parser_spec.rb @@ -1,4 +1,59 @@ +require 'rex/post/meterpreter/packet' require 'rex/post/meterpreter/packet_parser' +describe Rex::Post::Meterpreter::PacketParser do + subject{ + Rex::Post::Meterpreter::PacketParser.new + } + before(:each) do + @req_packt = Rex::Post::Meterpreter::Packet.new( + Rex::Post::Meterpreter::PACKET_TYPE_REQUEST, + "test_method") + @raw = @req_packt.to_r + @sock = double('Socket') + @sock.stub(:read) do |arg| + @raw.slice!(0,arg) + end + end + it "should respond to cipher" do + subject.should respond_to :cipher + end + + it "should respond to raw" do + subject.should respond_to :raw + end + + it "should respond to reset" do + subject.should respond_to :reset + end + + it "should respond to recv" do + subject.should respond_to :recv + end + + it "should respond to hdr_length_left" do + subject.should respond_to :hdr_length_left + end + + it "should respond to payload_length_left" do + subject.should respond_to :payload_length_left + end + + it "should initialise with expected defaults" do + subject.send(:raw).should == "" + subject.send(:hdr_length_left).should == 8 + subject.send(:payload_length_left).should == 0 + end + + it "should parse valid raw data into a packet object" do + while @raw.length >0 + parsed_packet = subject.recv(@sock) + end + parsed_packet.class.should == Rex::Post::Meterpreter::Packet + parsed_packet.type.should == Rex::Post::Meterpreter::PACKET_TYPE_REQUEST + parsed_packet.method?("test_method").should == true + end + +end