bool Signature::quirkPast( const Packet &p ) const { //Checks for options after EOL bool eol = false; if( p.inetIs< IPv4 >( 0 ) && p.transIs< TCP >( 0 ) ) { IPv4 ip = p.getInet<IPv4>( 0 ); TCP tcp = p.getTrans<TCP>( 0 ); std::vector< SmartPtr< TCPOption > > options = tcp.options(); for( int i = 0; i < options.size(); ++i ) { TCPOption * opt = options[i]; if( !eol && opt->kind() == TCPOption::END_OF_LIST ) { eol = true; } else if( eol && opt->kind() != TCPOption::END_OF_LIST ) { return true; } } } return false; }
void Signature::setFromPacket( const Packet &p ) { if( p.inetIs< IPv4 >( 0 ) && p.transIs< TCP >( 0 ) ) { IPv4 ip = p.getInet<IPv4>( 0 ); TCP tcp = p.getTrans<TCP>( 0 ); std::vector< SmartPtr< TCPOption > > options = tcp.options(); uint32_t quirks = 0; //set IP stuff setDontFragment( ip.dontFragment() ); setTtl( ip.ttl() ); //set TCP stuff setWindowSize( tcp.windowSize() ); //set TCP options std::vector< uint8_t > tcpOptions; std::vector< SmartPtr< TCPOption > >::iterator itr; for( itr = options.begin(); itr != options.end(); ++itr ) { uint8_t kind = (*itr)->kind(); if( kind == TCPOption::MAXIMUM_SEGMENT_SIZE ) { MSSOption* mss = static_cast<MSSOption*>((*itr).data()); mss_ = mss->mss(); } checkForQuirks( p ); tcpOptions.push_back( kind ); } setTcpOptions( tcpOptions ); } }
TEST_F(TCPTest, SpoofedOptions) { TCP pdu; uint8_t a[] = { 1,2,3,4,5,6 }; pdu.add_option( TCP::option(TCP::SACK, 250, a, a + sizeof(a)) ); pdu.add_option( TCP::option(TCP::SACK, 250, a, a + sizeof(a)) ); pdu.add_option( TCP::option(TCP::SACK, 250, a, a + sizeof(a)) ); // probably we'd expect it to crash if it's not working, valgrind plx EXPECT_EQ(3U, pdu.options().size()); EXPECT_EQ(pdu.serialize().size(), pdu.size()); }
bool Signature::quirkT2( const Packet &p ) const { if( p.inetIs< IPv4 >( 0 ) && p.transIs< TCP >( 0 ) ) { TCP tcp = p.getTrans<TCP>( 0 ); std::vector< SmartPtr< TCPOption > > options = tcp.options(); for( int i = 0; i < options.size(); ++i ) { if( options[i]->kind() == TCPOption::TIME_STAMP_OPTION ) { TimeStampOption* tsopt = static_cast<TimeStampOption*>(options[i].data()); if( tsopt->tsecr() != 0 ) return true; } } } return false; }