|
| 1 | +require 'rex/post/meterpreter/packet' |
| 2 | +require 'rex/post/meterpreter/packet_parser' |
| 3 | + |
| 4 | + |
| 5 | +describe Rex::Post::Meterpreter::PacketParser do |
| 6 | + subject{ |
| 7 | + Rex::Post::Meterpreter::PacketParser.new |
| 8 | + } |
| 9 | + before(:each) do |
| 10 | + @req_packt = Rex::Post::Meterpreter::Packet.new( |
| 11 | + Rex::Post::Meterpreter::PACKET_TYPE_REQUEST, |
| 12 | + "test_method") |
| 13 | + @raw = @req_packt.to_r |
| 14 | + @sock = double('Socket') |
| 15 | + @sock.stub(:read) do |arg| |
| 16 | + @raw.slice!(0,arg) |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + it "should respond to cipher" do |
| 21 | + subject.should respond_to :cipher |
| 22 | + end |
| 23 | + |
| 24 | + it "should respond to raw" do |
| 25 | + subject.should respond_to :raw |
| 26 | + end |
| 27 | + |
| 28 | + it "should respond to reset" do |
| 29 | + subject.should respond_to :reset |
| 30 | + end |
| 31 | + |
| 32 | + it "should respond to recv" do |
| 33 | + subject.should respond_to :recv |
| 34 | + end |
| 35 | + |
| 36 | + it "should respond to hdr_length_left" do |
| 37 | + subject.should respond_to :hdr_length_left |
| 38 | + end |
| 39 | + |
| 40 | + it "should respond to payload_length_left" do |
| 41 | + subject.should respond_to :payload_length_left |
| 42 | + end |
| 43 | + |
| 44 | + it "should initialise with expected defaults" do |
| 45 | + subject.send(:raw).should == "" |
| 46 | + subject.send(:hdr_length_left).should == 8 |
| 47 | + subject.send(:payload_length_left).should == 0 |
| 48 | + end |
| 49 | + |
| 50 | + it "should parse valid raw data into a packet object" do |
| 51 | + while @raw.length >0 |
| 52 | + parsed_packet = subject.recv(@sock) |
| 53 | + end |
| 54 | + parsed_packet.class.should == Rex::Post::Meterpreter::Packet |
| 55 | + parsed_packet.type.should == Rex::Post::Meterpreter::PACKET_TYPE_REQUEST |
| 56 | + parsed_packet.method?("test_method").should == true |
| 57 | + end |
| 58 | + |
| 59 | +end |
0 commit comments