Ejemplo n.º 1
0
    def testResetFromSyncStateEstablished(self):
        
        """
           RFC 793 - Section 3.4 Establishing a Connection
           Page 37 - Reset Generation  
    
           3.  If the connection is in a synchronized state (ESTABLISHED,
            FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT),
            any unacceptable segment (out of window sequence number or
            unacceptible acknowledgment number) must elicit only an empty
            acknowledgment segment containing the current send-sequence number
            and an acknowledgment indicating the next sequence number expected
            to be received, and the connection remains in the same state.
        
            If an incoming segment has a security level, or compartment, or
            precedence which does not exactly match the level, and compartment,
            and precedence requested for the connection,a reset is sent and
            connection goes to the CLOSED state.  The reset takes its sequence
            number from the ACK field of the incoming segment.

           Sent an unacceptable ACK to an established connection.
        """

        #(1)establish a connection
        tcptest.threewayhandshakenoopt(self, self.tcb, self.thisside, self.thatside)
        
        (ip, tcp) = tcptest.createoutofwindowack(self, self.tcb, self.thisside, self.thatside) 
        tcptest.createwritepacket(self, self.tcb, ip, tcp, self.thisside, self.thatside)   
        
        (iprst, tcprst) = tcptest.receive(self, self.tcb, self.thisside, self.thatside) 
        tcptest.assertReset(self, self.tcb, tcprst, self.thisside, self.thatside, tcp)
Ejemplo n.º 2
0
    def testResetFromNonSyncStateSynReceived(self):
        """
           RFC 793 - Section 3.4 Establishing a Connection
           Page 36 - Reset Generation  
    
           2.  If the connection is in any non-synchronized state (LISTEN,
           SYN-SENT, SYN-RECEIVED), and the incoming segment acknowledges
           something not yet sent (the segment carries an unacceptable ACK), or
           if an incoming segment has a security level or compartment which
           does not exactly match the level and compartment requested for the
           connection, a reset is sent.

           Sent an ACK without any other previous sent.
        """

        self.resetTcb(self.tcb)

        (ipsyn, tcpsyn) = tcptest.createsyn(self, self.tcb, self.thisside,
                                            self.thatside)
        tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside,
                                  self.thatside)

        (ipsynack, tcpsynack) = tcptest.receive(self, self.tcb, self.thisside,
                                                self.thatside)

        #Create a tcp segment with only ack bit set, and a fake ack_number
        (ip, tcp) = tcptest.createoutofwindowack(self, self.tcb, self.thisside,
                                                 self.thatside)
        tcptest.createwritepacket(self, self.tcb, ip, tcp, self.thisside,
                                  self.thatside)

        (iprst, tcprst) = tcptest.receive(self, self.tcb, self.thisside,
                                          self.thatside)
        tcptest.assertReset(self, self.tcb, tcprst, self.thisside,
                            self.thatside, tcp)
Ejemplo n.º 3
0
    def testSendSyn4BroadcastAddress(self):

        #THISSIDE
        (ipsyn, tcpsyn) = tcptest.createsyn(self, self.tcb, self.thisside, \
            self.thatside)
        tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside,\
                                                           self.thatside)

        print tcpsyn
        print ipsyn

        #
        #Receiving SYN+ACK
        #

        # adjusting tcb
        # I sent to broadcast, I don't wait for an answer,  but if there was
        # one,it probability wiil have the receiver ip address as source address
        #todo:"think about enhance receive method, to receive more one case, may be tcb[]?!"
        self.tcb.ip[self.thatside] = pcs.inet_atol("10.211.55.220")

        #Receivinig anything
        (ipsynack, tcpsynack) = tcptest.receive(self, self.tcb, self.thisside, \
          self.thatside)
Ejemplo n.º 4
0
    def testSendSyn4BroadcastAddress(self):
        #THISSIDE
        (ipsyn, tcpsyn) = tcptest.createsyn(self, self.tcb, self.thisside, self.thatside)
                              
        tcptest.createwritepacket(self, self.tcb, ipsyn, tcpsyn, self.thisside, self.thatside)
                                                           
        
        
        #THATHSIDE
        #Receiving SYN (unfurtunately this time we are receiving from 
        #the same board)
        (ipsynreceived, tcpsynreceived) = tcptest.receive(self, self.tcb, self.thatside, self.thisside)
                                                                    

        self.assertEqual(ipsyn, ipsynreceived)
        self.assertEqual(tcpsyn, tcpsynreceived)
        print ipsynreceived 
        print tcpsynreceived 


    #
    #Receiving SYN+ACK
    #
        #THISSIDE
        #Receivinig SYN + ACK
        (ipsynack, tcpsynack) = tcptest.receive(self, self.tcb, self.thisside, self.thatside) 
                               

    	#Some blackmagic to use assertSequenceAcknowledgmentOK at SYN
        self.tcb.tcpsequence[ self.thatside ] = tcpsynack.sequence  
        tcptest.assertSequenceAcknowledgmentOK(self, self.tcb, tcpsynack, \
                    self.thisside, self.thatside)

        tcptest.assertSynPresent(self, tcpsynack)

        #OK Its a SYN+ACK --> SYN consumes a sequence
        self.tcb.tcpsequence[ self.thatside ] = tcpsynack.sequence + 1
        print tcpsynack 


    #
    #Sending ACK
    #
        #THISSIDE
        (ipack, tcpack) = tcptest.createip(self, self.tcb, self.thisside, \
                             self.thatside)

        tcptest.createwritepacket(self, self.tcb, ipack, tcpack, self.thisside, \
                                                           self.thatside)
        print tcpack 

        #THATHSIDE
        #Receiving SYN (unfurtunately this time we are receiving from the same board) 
	(ipackreceived, tcpackreceived) = tcptest.receive(self, self.tcb, self.thatside, self.thisside)
                                                                    
        #Different values then 0 and 1 to tcpflags TODO
        #self.assertEqual(ipack, ipackreceived)
        #self.assertEqual(tcpack, tcpackreceived)


    #
    #Sending FIN
    #
        #THISSIDE
        (ipfin, tcpfin) = tcptest.createfin(self, self.tcb, self.thisside, self.thatside)
        tcptest.createwritepacket(self, self.tcb, ipfin, tcpfin, self.thisside, \
                                                           self.thatside)
        print tcpfin 

        #THATHSIDE
        #Receiving SYN (unfurtunately this time we are receiving from the same board) 
        (ipfinreceived, tcpfinreceived) = tcptest.receive(self, self.tcb, self.thatside, \
                                                                    self.thisside)
        #Different values then 0 and 1 to tcpflags TODO
        #self.assertEqual(ipfin, ipfinreceived)
        #self.assertEqual(tcpfin, tcpfinreceived)
        
    #
    #Receiving ACK from FIN sent
    #
 #	pdb.set_trace()       

        #THISSIDE
        #Receiving ACK 
        (ipfinack, tcpfinack) = tcptest.receive(self, self.tcb, self.thisside, self.thatside) 
        tcptest.assertSequenceAcknowledgmentOK(self, self.tcb, tcpfinack, self.thisside, self.thatside)

        print tcpfinack 

    #
    #Receiving FIN
    #
        #test if FIN was sent in the same segment
        if (tcpfinack.fin == None or tcpfinack.fin == 0):
            
         #TODO same attribute used (ipfinack, tcpfinack)
            (ipfinack, tcpfinack) = tcptest.receive(self, self.tcb, self.thisside, self.thatside)
                                  
            tcptest.assertSequenceAcknowledgmentOK(self, self.tcb, tcpfinack, \
                    self.thisside, self.thatside)
        
        tcptest.assertFin(self, tcpfinack)

        print tcpfinack 
        
        #Fin consumes a sequence
        self.tcb.tcpsequence[ self.thatside ] += 1
             
    #
    #Sending ACK
    #

        #THISSIDE
        (ipackfin, tcpackfin) = tcptest.createip(self, self.tcb, self.thisside,
                               self.thatside)
        tcptest.createwritepacket(self, self.tcb, ipackfin, tcpackfin, \
                self.thisside, self.thatside)
        print tcpackfin 

        #THATHSIDE
        #Receiving SYN (receiving from the same board) 
        (ipackfinreceived, tcpackfinreceived) = tcptest.receive(self, self.tcb, \
                    self.thatside, self.thisside)