Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 May 2008 22:17:52 GMT
From:      Victor Hugo Bilouro <bilouro@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 142608 for review
Message-ID:  <200805302217.m4UMHqc0003280@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=142608

Change 142608 by bilouro@bilouro_tcptest on 2008/05/30 22:17:46

	This version send SYN, receive SYN+ACK, send ACK
	But, after send the ACK the server(passive open) aswer with a RESET. I don't why yet!

Affected files ...

.. //depot/projects/soc2008/bilouro_tcptest/src/scripts/tcpconnect.py#3 edit

Differences ...

==== //depot/projects/soc2008/bilouro_tcptest/src/scripts/tcpconnect.py#3 (text+ko) ====

@@ -45,13 +45,14 @@
     #
     # creating a durty-code ether-ip-tcp-syn packet 
     #
+    import random
 
     ip = ipv4.ipv4()
 
     ip.version = 4                 # 0100 max 1111 15 *caution* :)
     ip.hlen = 5                 # 0101 0 ->  min 0101 (20 bytes) 
     ip.tos = 0     
-    ip.id = 1                     #time of day
+    ip.id = random.randrange(1,(1<<16)-1)
     ip.flags = 0                 #study on book
     ip.offset = 0
     ip.ttl = 64
@@ -64,7 +65,7 @@
 
     tcppkt.sport = int(options.source_port )
     tcppkt.dport = int(options.destination_port)
-    tcppkt.sequence = 300 
+    tcppkt.sequence = random.randrange(1,(1<<32)-1)   
     tcppkt.ack_number = 0
     tcppkt.offset = 5                           #header length
     tcppkt.urgent = 0
@@ -73,7 +74,7 @@
     tcppkt.reset = 0
     tcppkt.syn = 1
     tcppkt.fin = 0
-    tcppkt.window = 65535
+    tcppkt.window = (1<<16)-1
     tcppkt.urg_point = 0
     #tcppkt.options
 
@@ -89,22 +90,120 @@
     ether.dst = ethernet.ether_atob(options.ether_destination)
     ether.type = 0x800
 
+    print "\n syn---------------------------------"
+    print tcppkt 
+    print "---------------------------------"
+
     packet = pcs.Chain([ether, ip, tcppkt])
     
     output = pcs.PcapConnector(options.interface)
 
+    # SYN SENT
     out = output.write(packet.bytes, len(packet.bytes))
 
+
+
+
+
     reply = output.read()
     reply = output.read()
 
     packet = ethernet.ethernet(reply)
-    print "\n---------------------------------"
-    print packet 
-    print packet.data
+    print "\n syn+ack-----------------------------"
+    print packet.data.data
     print "---------------------------------"
-    print packet.data.data
+
+    #
+    # this commented piece dont work.. don't ask me why. (now) 
+    #
+
+    #tcpreply = packet.data.data
+
+    #import copy
+    #ipack = copy.deepcopy(ip)    
+    #ipack.id = ip.id + 1
+
+    #tcpack = copy.deepcopy(tcppkt)    
+
+    #tcpack.sequence = 0 
+    #tcpack.ack_number = tcpreply.sequence + 1
+    #tcpack.ack = 1
+    #tcpack.syn = 0
+    #tcpack.checksum = tcp_cksum(tcpack , ipack)
+    
+    # important, only calcs the ip checksum after fill length field
+    #ipack.checksum = ip_cksum(ipack)
+    
+    #packetreply = pcs.Chain([ether, ipack, tcpack])
+    #out = output.write(packetreply.bytes, len(packetreply.bytes))
+
+    #
+    # ANOTHER. this worked! (please don't pay attention in how it was wrote, it's a very durty test, ok?)
+    #
+
+    ipack = ipv4.ipv4()
+
+    ipack.version = 4                 # 0100 max 1111 15 *caution* :)
+    ipack.hlen = 5                 # 0101 0 ->  min 0101 (20 bytes) 
+    ipack.tos = 0     
+    ipack.id = ip.id + 1
+    ipack.flags = 0                 #study on book
+    ipack.offset = 0
+    ipack.ttl = 64
+    ipack.protocol = pcs.IPPROTO_TCP                 #1 ICMP #6 TCP
+    ipack.src = pcs.inet_atol(options.ip_source)
+    ipack.dst = pcs.inet_atol(options.ip_target)
+
+    tcpreply = packet.data.data
+    tcpack = tcp.tcp()
+
+    tcpack.sport = int(options.source_port )
+    tcpack.dport = int(options.destination_port)
+    tcpack.sequence = 0
+    tcpack.ack_number = tcpreply.sequence + 1
+    tcpack.offset = 5                           #header length
+    tcpack.urgent = 0
+    tcpack.ack = 1
+    tcpack.push = 0
+    tcpack.reset = 0
+    tcpack.syn = 0
+    tcpack.fin = 0
+    tcpack.window = (1<<16)-1
+    tcpack.urg_point = 0
+    #tcpack.options
+
+    tcpack.checksum = tcp_cksum(tcpack , ipack)
+
+    ipack.length = len(ipack.bytes) + len(tcpack.bytes) 
+
+    # important, only calcs the ip checksum after fill length field
+    ipack.checksum = ip_cksum(ipack)
+
+    etherack = ethernet.ethernet()
+    etherack.src = ethernet.ether_atob(options.ether_source)
+    etherack.dst = ethernet.ether_atob(options.ether_destination)
+    etherack.type = 0x800
+
+    packetack = pcs.Chain([etherack, ipack, tcpack])
+    out = output.write(packetack.bytes, len(packetack.bytes))
+
+    print "\n ack---------------------------------"
+    print tcpack 
     print "---------------------------------"
+    # /ANOTHER
+
+    reply = output.read()
+    while 1: 
+	try: 
+		reply = output.read()
+    		packet = ethernet.ethernet(reply)
+		if packet.data.data.sport == 22022:
+    			print "\n-----------------------------"
+    			print packet.data.data
+    			print "---------------------------------"
+	except:
+		pass
+
 
 def tcp_cksum(self, ip, data = ""):  #TODO: add this method to pcs tcp.py
     """return tcpv4 checksum"""



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805302217.m4UMHqc0003280>