<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.stageing.freitagsrunde.org//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=84.59.52.179</id>
	<title>FreitagsrundenWiki - Benutzerbeiträge [de]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stageing.freitagsrunde.org//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=84.59.52.179"/>
	<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//Spezial:Beitr%C3%A4ge/84.59.52.179"/>
	<updated>2026-11-02T07:20:19Z</updated>
	<subtitle>Benutzerbeiträge</subtitle>
	<generator>MediaWiki 1.45.6</generator>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5783</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5783"/>
		<updated>2005-10-15T20:33:58Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* netdate-example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (&lt;br /&gt;
                         fwt_ip.IFACE_B, &lt;br /&gt;
                         ip_udp_pkt_ba, &lt;br /&gt;
                         filterA=FILTER_A, &lt;br /&gt;
                         filterB=FILTER_B, &lt;br /&gt;
                         timeoutA=500, &lt;br /&gt;
                         timeoutB=0&lt;br /&gt;
                   )&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (&lt;br /&gt;
                         fwt_ip.IFACE_A, &lt;br /&gt;
                         ip_udp_pkt_ab,  &lt;br /&gt;
                         filterA=FILTER_A, &lt;br /&gt;
                         filterB=FILTER_B, &lt;br /&gt;
                         timeoutA=0, &lt;br /&gt;
                         timeoutB=500&lt;br /&gt;
                   )&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (&lt;br /&gt;
                              fwt_ip.IFACE_B, &lt;br /&gt;
                              ip_udp_pkt_ba, &lt;br /&gt;
                              filterA=FILTER_A, &lt;br /&gt;
                              filterB=FILTER_B, &lt;br /&gt;
                              timeoutA=500, &lt;br /&gt;
                              timeoutB=0&lt;br /&gt;
                        )&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-function == &lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending the packets from source to destination. For a better understanding of the transceive-function we need to answer some questions:&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
A typical call of the transceive-function is listed below:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the interface from which the packet is send, followed by the complete UDP/IP-packet (here from bchen to achen or generaly from source to destination). The third and fourth defines the filters for achen and bchen, followed by the timeouts for achen and bchen.&lt;br /&gt;
&lt;br /&gt;
=== Which result is returned by transceive? ===&lt;br /&gt;
After transceive send the packet, it returns a python-dictionary with the values of the packet received on the other side.&lt;br /&gt;
In our netdate-example the first received packet is stored in result[1], so we can check if a packet is arrived or not by validating result[1].&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5782</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5782"/>
		<updated>2005-10-15T20:31:46Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (&lt;br /&gt;
                         fwt_ip.IFACE_A, &lt;br /&gt;
                         ip_udp_pkt_ab,  &lt;br /&gt;
                         filterA=FILTER_A, &lt;br /&gt;
                         filterB=FILTER_B, &lt;br /&gt;
                         timeoutA=0, &lt;br /&gt;
                         timeoutB=500&lt;br /&gt;
                   )&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (&lt;br /&gt;
                              fwt_ip.IFACE_B, &lt;br /&gt;
                              ip_udp_pkt_ba, &lt;br /&gt;
                              filterA=FILTER_A, &lt;br /&gt;
                              filterB=FILTER_B, &lt;br /&gt;
                              timeoutA=500, &lt;br /&gt;
                              timeoutB=0&lt;br /&gt;
                        )&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-function == &lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending the packets from source to destination. For a better understanding of the transceive-function we need to answer some questions:&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
A typical call of the transceive-function is listed below:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the interface from which the packet is send, followed by the complete UDP/IP-packet (here from bchen to achen or generaly from source to destination). The third and fourth defines the filters for achen and bchen, followed by the timeouts for achen and bchen.&lt;br /&gt;
&lt;br /&gt;
=== Which result is returned by transceive? ===&lt;br /&gt;
After transceive send the packet, it returns a python-dictionary with the values of the packet received on the other side.&lt;br /&gt;
In our netdate-example the first received packet is stored in result[1], so we can check if a packet is arrived or not by validating result[1].&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5781</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5781"/>
		<updated>2005-10-15T20:29:00Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* transceive-function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-function == &lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending the packets from source to destination. For a better understanding of the transceive-function we need to answer some questions:&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
A typical call of the transceive-function is listed below:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the interface from which the packet is send, followed by the complete UDP/IP-packet (here from bchen to achen or generaly from source to destination). The third and fourth defines the filters for achen and bchen, followed by the timeouts for achen and bchen.&lt;br /&gt;
&lt;br /&gt;
=== Which result is returned by transceive? ===&lt;br /&gt;
After transceive send the packet, it returns a python-dictionary with the values of the packet received on the other side.&lt;br /&gt;
In our netdate-example the first received packet is stored in result[1], so we can check if a packet is arrived or not by validating result[1].&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript&amp;diff=5512</id>
		<title>Benutzer:Grey/UDP-Testskript</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript&amp;diff=5512"/>
		<updated>2005-10-15T20:25:18Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* transceive-Funktion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-Testskript = &lt;br /&gt;
&lt;br /&gt;
== Versuchsaufbau ==&lt;br /&gt;
Es gibt verschiedene Varianten des Aufrufs von FWTEST und FWAGENT, näheres hier: [[Benutzer:Grey/Security_Tool_Developement_Projekt#Wie_sieht_der_Versuchsaufbau_f.FCr_ein_Testskript_aus.3F|Versuchsaufbauten]]&lt;br /&gt;
&lt;br /&gt;
== netdate-Beispiel ==&lt;br /&gt;
An Hand eines Beispiels wollen wir die Implementation eines Testskripts darstellen. &lt;br /&gt;
Wir wollen zum Beipiel den netdate-Dienst von www.heise.de in Anspruch nehmen (wir nehmen den Dienst von Heise nicht wirklich in Anspruch, sondern simulieren lediglich den Traffic) und uns die aktuelle Uhrzeit zurückgeben lassen. Netdate funktioniert auf verschiedenen Protokollen, wir nehmen mal die Variante mit UDP-Paketen.&lt;br /&gt;
&lt;br /&gt;
Wenn man also mit Ethereal oder tcpdump den Verkehr belauschen würde, sollen die Pakete so aussehen als wären sie echt und nicht von uns erstellt (mehr dazu unter: [[Benutzer:Grey/Security_Tool_Developement_Projekt#Grenzen_von_Tests|Grenzen von Tests]]).&lt;br /&gt;
&lt;br /&gt;
Im Grunde arbeiten wir folgende Punkte nacheinander ab:&lt;br /&gt;
# default IP-Paket(Achen -&amp;gt; Bchen) erstellen&lt;br /&gt;
# default IP-Paket(Bchen -&amp;gt; Achen) erstellen&lt;br /&gt;
# default UDP-Paket(Achen -&amp;gt; Bchen) erstellen&lt;br /&gt;
# default UDP-Paket(Bchen -&amp;gt; Achen) erstellen&lt;br /&gt;
# IP-Pakete anpassen&lt;br /&gt;
# UDP-Pakete anpassen&lt;br /&gt;
# IP- und UDP-Pakete zusammenfügen&lt;br /&gt;
# UDP/IP-Pakete mittels transceive-Funktion versenden&lt;br /&gt;
# Auswertung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nun wollen wir uns das Testskript im detail anschauen und von Anfang an aufbauen, am Ende ist der Link zum kompletten Source-Code vom netdate-Skript.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Als erstes müssen wir unsere wrapper-Klassen(mit dem Präfix &#039;&#039;fwt_&#039;&#039; benannt) und andere benötigte Klassen importieren:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Danach definieren wir lediglich zum Debuggen zwei Variablen. &#039;&#039;dry_run&#039;&#039; ist für einen sogenannten Trockenlauf, der das Paketerstellen durchführt, aber das endgültige Absenden der Pakete ausläßt.&lt;br /&gt;
&lt;br /&gt;
Die Zweite bewirkt, daß nur Bchen die Antwort an Achen schickt. Achen schickt also nicht erst eine Anfrage, so daß Bchen antwortet.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Als Grundlage brauchen wir natürlich unser IP-Paket, daß wir hier generieren. Wir können unsere wrapper-Klasse &#039;&#039;fwt_ip&#039;&#039; bemühen und erstellen damit ein defaultPacket.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da bei unserem defaultPacket noch nicht das Protokoll spezifiziert ist, passen wir es mit der &#039;&#039;set&#039;&#039;-Funktion unserer wrapper-Klasse &#039;&#039;fwt_ip&#039;&#039; an. Alle [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | Felder ]] des IP-Paket können mit der &#039;&#039;set&#039;&#039;-Funktion geändert werden.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da zum Beispiel das Berechnen der &#039;&#039;IHL(Internet Header Length)&#039;&#039; und der &#039;&#039;Header Checksum&#039;&#039; nicht durchgeführt wurden, lassen wir das von unserer FIXUP-Funktion erledigen. Die FIXUP-Funktion wird von unserer wrapper-Klasse zur Verfügung gestellt. Das FIXUP_ALL bewirkt, daß alle Felder(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) korrigiert oder angepaßt werden. Unser IP-Paket wird später noch zum Beispiel mit der SourceIP und der DestinationIP bestückt.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Momentan haben wir ein IP-Paket als Grundlage für beide UDP-Paket, benötigen aber noch die UDP-Pakete selbst. Wir definieren uns mit Hilfe unserer wrapper-Klasse zwei UDP-Pakete, einmal von Achen nach Bchen und zurück. Diese Pakete werden später der Payload der IP-Pakete sein und haben momentan nur Grundeinstellungen.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zwar sind die Grundeinstellungen schon ganz gut, aber trotzdem müssen wir einige Änderungen vornehmen. Als erstes beim UDP-Paket von Achen nach Bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
...und dann von Bchen nach Achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Achten Sie darauf, daß wenn Sie einen bestimmten Dienst eines Servers oder Rechners in Anspruch nehmen, an den korrekten Destinationport das Paket zu schicken. Den Payload eines UDP-Paketes müssen Sie hardcoden in Hexadezimal.&lt;br /&gt;
&lt;br /&gt;
Wie bei dem IP-Paket machen wir ebenfalls ein FIXUP_ALL beider UDP-Pakete, was die Länge und die &#039;&#039;Header Checksum&#039;&#039; korrigiert oder anpaßt.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;br /&gt;
&lt;br /&gt;
Die transceive-Funktion ist im Grunde das Herzstück unseres Testskripts. Es ist zuständig für das Versenden von Paketen von Source-IP zu Destination-IP. Um ein besseres Verständnis über die transceive-Funktion zu bekommen, sollten wir uns einige Fragen stellen:&lt;br /&gt;
&lt;br /&gt;
=== Was macht die transceive-Funktion genau? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Welche Parameter werden von der transceive-Funktion erwartet? ===&lt;br /&gt;
&lt;br /&gt;
Ein typischer Aufruf der transceive-Funktion wäre zum Beispiel:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Der erste Parameter definiert das Interface von wo aus das Paket gesendet wird, gefolgt vom UDP/IP-Paket(hier von Bchen zu Achen oder genreller gesagt von Source-IP zur Destination-IP). Der Dritte und vierte definiert die Filter für Achen und Bchen, gefolgt von den Timeout für Achen und Bchen.&lt;br /&gt;
&lt;br /&gt;
=== Was wird von von der transceive-Funktion zurückgeliefert? ===&lt;br /&gt;
Nachdem transceive das Paket sendete, wird ein python-dictionary zurückgegeben, das die Werte von dem auf der anderen Seite empfangenen Paket enthält.&lt;br /&gt;
In unserem netdate-Beispiel ist das erste empfangene Paket in result[1] gespeichert, so daß wir prüfen können, ob ein Paket angekommen ist.&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5780</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5780"/>
		<updated>2005-10-15T19:57:32Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* Which result is returned by transceive? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-function == &#039;&#039;&#039;TODO:&#039;&#039;&#039;kopieren in dt. Teil&lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending the packets from source to destination. For a better understanding of the transceive-function we need to answer some questions:&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
A typical call of the transceive-function is listed below:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the interface from which the packet is send, followed by the complete UDP/IP-packet (here from bchen to achen or generaly from source to destination). The third and fourth defines the filters for achen and bchen, followed by the timeouts for achen and bchen.&lt;br /&gt;
&lt;br /&gt;
=== Which result is returned by transceive? ===&lt;br /&gt;
After transceive send the packet, it returns a python-dictionary with the values of the packet received on the other side.&lt;br /&gt;
In our netdate-example the first received packet is stored in result[1], so we can check if a packet is arrived or not by validating result[1].&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5779</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5779"/>
		<updated>2005-10-15T19:50:25Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* Which result is return by transceive? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-function == &#039;&#039;&#039;TODO:&#039;&#039;&#039;kopieren in dt. Teil&lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending the packets from source to destination. For a better understanding of the transceive-function we need to answer some questions:&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
A typical call of the transceive-function is listed below:&lt;br /&gt;
&lt;br /&gt;
 result = fwt_ip.transceive (&lt;br /&gt;
                fwt_ip.IFACE_B, &lt;br /&gt;
                ip_udp_pkt_ba, &lt;br /&gt;
                filterA=FILTER_A, &lt;br /&gt;
                filterB=FILTER_B, &lt;br /&gt;
                timeoutA=500, &lt;br /&gt;
                timeoutB=0&lt;br /&gt;
         )&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the interface from which the packet is send, followed by the complete UDP/IP-packet (here from bchen to achen or generaly from source to destination). The third and fourth defines the filters for achen and bchen, followed by the timeouts for achen and bchen.&lt;br /&gt;
&lt;br /&gt;
=== Which result is returned by transceive? ===&lt;br /&gt;
After transceive send the packet, it returns a python-dictionary with the values of the packet received on the other side.&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5774</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5774"/>
		<updated>2005-10-15T17:38:38Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* transceive-Funktion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;br /&gt;
The transceive-function is mostly the core of our testscript. It is responsable for sending all the packets from source to destination. &lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
=== Which result is return by transceive? ===&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5773</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5773"/>
		<updated>2005-10-15T17:30:33Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* transceive-Funktion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;br /&gt;
&lt;br /&gt;
=== What does the transceive-function exactly? ===&lt;br /&gt;
&lt;br /&gt;
=== Which parameters are expected of the transceive-function? ===&lt;br /&gt;
&lt;br /&gt;
=== Which result is return by transceive? ===&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/Security_Tool_Developement_Projekt_EN&amp;diff=5762</id>
		<title>Benutzer:Grey/Security Tool Developement Projekt EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/Security_Tool_Developement_Projekt_EN&amp;diff=5762"/>
		<updated>2005-10-15T17:27:26Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* Which language is used to implement a testscript? And why this language? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Documentation =&lt;br /&gt;
&lt;br /&gt;
== HowTo ==&lt;br /&gt;
&lt;br /&gt;
=== For what do we need the testscript? ===&lt;br /&gt;
For testing a firewall, we need the ability to generate and send different packets through our firewall.&lt;br /&gt;
Our testscript ist here the manager, who administer to the sending and generating of the packets, while using the [[Benutzer:Grey/wrapper-klassen_EN|wrapper-classes]].&lt;br /&gt;
The testscript is refered in the commandline(the path to the script is refered) to FWTEST, so that FWTEST has not be compiled again for using another testscript.&lt;br /&gt;
&lt;br /&gt;
=== Which language is used to implement a testscript? And why this language? ===&lt;br /&gt;
Python.&lt;br /&gt;
&lt;br /&gt;
Python has many advantages:&lt;br /&gt;
* simple syntax and easy to learn&lt;br /&gt;
* no memory management required &#039;&#039;&#039;TODO:&#039;&#039;&#039;in den dt. teil übernehmen&lt;br /&gt;
* no type declaration of variables &#039;&#039;&#039;TODO:&#039;&#039;&#039;in den dt. teil übernehmen&lt;br /&gt;
* a mighty programming library&lt;br /&gt;
* simple to integrate in C and reversed&lt;br /&gt;
* platformindependent&lt;br /&gt;
&lt;br /&gt;
=== What abilities has a testscript? ===&lt;br /&gt;
* default packets&lt;br /&gt;
* IP-packets&lt;br /&gt;
* UDP-packets&lt;br /&gt;
* TCP-packets&lt;br /&gt;
* ICMP-packets&lt;br /&gt;
* sending packets&lt;br /&gt;
* everything that Python can&lt;br /&gt;
&lt;br /&gt;
=== How does a breadboard construction for a testscript looking? ===&lt;br /&gt;
As a basic principle we can say that FWTEST has two agents- and one FWTEST-process.&lt;br /&gt;
&lt;br /&gt;
We have two mostly used breadboard constructions.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;variation 1:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We have three computers: the firewall, agent a(achen) and agent b(bchen).&lt;br /&gt;
On achen and bchen is running an instance of our agent, additionaly is an instance of fwtest running on one of our agents (achen or bchen).&lt;br /&gt;
So one agent adopts the function of fwtest.&lt;br /&gt;
&lt;br /&gt;
A possible construction could be:&lt;br /&gt;
&lt;br /&gt;
http://www.freitagsrunde.org/~grey/sonstiges/std/versuchsaufbau1.png&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;variation 2:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The ohther variation is based on four computers, two computers are functioning as agents and the third adopts the function of the controller (so FWTEST). The fourth, the firewall, is untouched.&lt;br /&gt;
&lt;br /&gt;
A possible construction could be:&lt;br /&gt;
&lt;br /&gt;
http://www.freitagsrunde.org/~grey/sonstiges/std/versuchsaufbau2.png&lt;br /&gt;
&lt;br /&gt;
=== How am I writing my own testscripts? ===&lt;br /&gt;
&lt;br /&gt;
Implementing a testscript is easy as breathing air.&lt;br /&gt;
For example let us take a look at implementing a simple UDP-packet.&lt;br /&gt;
At first the generation of a default ip-packet and its field modifications is done.&lt;br /&gt;
After that a default UDP-packet is genrated, independently from the default IP-packet.&lt;br /&gt;
We also have to modify the fields content of the UDP-packet, so that we meet our needs.&lt;br /&gt;
&lt;br /&gt;
To finish, the default packets have to be melted together.&lt;br /&gt;
We take the UDP-packet as payload for the IP-packet, followed by FIXUP, so that the chekcsum is corrected.&lt;br /&gt;
&lt;br /&gt;
Now with the transceive-function the UDP/IP-packet can be send.&lt;br /&gt;
&lt;br /&gt;
A detailed discription of writing a UDP-testscript can be found here:&lt;br /&gt;
[[Benutzer:Grey/UDP-Testskript_EN|UDP-testscript]]&lt;br /&gt;
&lt;br /&gt;
=== Limits of tests ===&lt;br /&gt;
&lt;br /&gt;
Testscripts shall simulate the traffic and as a sequence representing a realistic packet exchange.&lt;br /&gt;
&lt;br /&gt;
For example, in our netdate-example we have a restriction.&lt;br /&gt;
&lt;br /&gt;
We don&#039;t really use the www.heise.de Server, but our agent take place of the Server, so that of course the IP-address from our agent b(bchen) is taken and shown in the IP-packet.&lt;br /&gt;
&lt;br /&gt;
It is not really a restriction of the testscript, but of the breadboard construction. Is bchen www.heise.de the restriction is obsolete.&lt;br /&gt;
&lt;br /&gt;
Another restriction is the complex emulation of a connection (road section), as the construction of ICMP Fragmentation Needed shows. &lt;br /&gt;
We don&#039;t have all servers and computer that are needed for the reality, but that is not the point. We don&#039;t need them to test the firewall in a realistic way. &lt;br /&gt;
We only want to test the firewall, if it has weak points or misconfigurations.&lt;br /&gt;
&lt;br /&gt;
So only the packets, which pass the firewall are important.&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5772</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5772"/>
		<updated>2005-10-15T16:27:37Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* netdate-example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* For printing the received packets a print-function(&#039;&#039;printResult&#039;&#039;) is needed. The function checks if achen or bchen received any packet and print it on the standard out otherwise an error(&#039;&#039;timeout&#039;&#039;) is returned.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the dry_run option is 1, the packets are printed out to the console.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* At this point it gets more serious and the packets will be send&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* If the second variable(response_only) is 1 only the packet from bchen to achen will be send by the [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-function]], the packet from achen to bchen is skipped. The received packet is stored in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* Otherwise the UDP/IP-packet from achen to bchen is send and than the packet from bchen to achen. The received packet are stored again in &#039;&#039;result&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  complete code of netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5771</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5771"/>
		<updated>2005-10-15T15:52:50Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* netdate-example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After we created our default IP-packet and our modified default UDP-packets, we want to merge these packets to an UDP/IP-packet froma achen to bchen and reverse. The IP-packet listed befor act as a template for the UDP/IP-packet from achen to bchen. The constructor get the IP-packet as a dictionary and retruns a UDP/IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The UDP/IP-packet needs a destination- and source-IP. As the payload, mentioned above, we refer the UDP-packet(as string).&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Yet we have set the IP-packet with the destination- and source-IP, but the &#039;&#039;Header Checksum&#039;&#039; must be generate as once again. This will do the FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The same must be done for the UDP-packet from bchen to achen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5770</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5770"/>
		<updated>2005-10-15T15:24:31Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* netdate-example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
Pay attention that you take the right Destination Port of the service you will use. The payload of the UDP-packet have to be hardcode-implemented in hex. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Likewise a FIXUP of both UDP-packets have to be done, like the IP-packets. So the length and the &#039;&#039;Header Checksum&#039;&#039; will be corrected or changed:&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5769</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5769"/>
		<updated>2005-10-15T14:05:40Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so, we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | fields]] of the IP-packet can be set by the &#039;&#039;set&#039;&#039;-function.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The next step is to calculate the &#039;&#039;IHL(Internet Header Length)&#039;&#039; and the &#039;&#039;Header Checksum&#039;&#039;. An easy way to do it is to call the FIXUP-function of our wrapper-class. THe FIXUP corrects the fields(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) of IP-packet. Our IP-packet will be loaded later with the SourceIP and the DestinationIP. &lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Currently we have an IP-packet as basis for both UDP-packets, but be also need the UDP-packets itself. We define with our wrapper-class two UDP-packets, the one for the way from achen to bchen and one for the reversed way. Each of these UDP-packets will be the payload for the IP-packets. They also have now only the base preferences, which have to be modified.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The base preferences are good beginning, but the UDP-packets get to be modified now, e.g.: sourceport, destinationport. At first we modify the UDP-packet from achen to bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
* ...and then from bchen to achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Achten Sie darauf, daß wenn Sie einen bestimmten Dienst eines Servers oder Rechners in Anspruch nehmen, an den korrekten Destinationport das Paket zu schicken. Den Payload eines UDP-Paketes müssen Sie hardcoden in Hexadezimal.&lt;br /&gt;
&lt;br /&gt;
Wie bei dem IP-Paket machen wir ebenfalls ein FIXUP_ALL beider UDP-Pakete, was die Länge und die &#039;&#039;Header Checksum&#039;&#039; korrigiert oder anpaßt.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5768</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5768"/>
		<updated>2005-10-15T11:57:53Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* netdate-example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* The default IP-packet has to be modified, e.g. the correct protocol is not set. To do so we use the &#039;&#039;set&#039;&#039;-funcition of our wrapper-class &#039;&#039;fwt_ip&#039;&#039;. All [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | Felder ]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da bei unserem defaultPacket noch nicht das Protokoll spezifiziert ist, passen wir es mit der &#039;&#039;set&#039;&#039;-Funktion unserer wrapper-Klasse &#039;&#039;fwt_ip&#039;&#039; an. Alle [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | Felder ]] des IP-Paket können mit der &#039;&#039;set&#039;&#039;-Funktion geändert werden.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da zum Beispiel das Berechnen der &#039;&#039;IHL(Internet Header Length)&#039;&#039; und der &#039;&#039;Header Checksum&#039;&#039; nicht durchgeführt wurden, lassen wir das von unserer FIXUP-Funktion erledigen. Die FIXUP-Funktion wird von unserer wrapper-Klasse zur Verfügung gestellt. Das FIXUP_ALL bewirkt, daß alle Felder(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) korrigiert oder angepaßt werden. Unser IP-Paket wird später noch zum Beispiel mit der SourceIP und der DestinationIP bestückt.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Momentan haben wir ein IP-Paket als Grundlage für beide UDP-Paket, benötigen aber noch die UDP-Pakete selbst. Wir definieren uns mit Hilfe unserer wrapper-Klasse zwei UDP-Pakete, einmal von Achen nach Bchen und zurück. Diese Pakete werden später der Payload der IP-Pakete sein und haben momentan nur Grundeinstellungen.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zwar sind die Grundeinstellungen schon ganz gut, aber trotzdem müssen wir einige Änderungen vornehmen. Als erstes beim UDP-Paket von Achen nach Bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
...und dann von Bchen nach Achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Achten Sie darauf, daß wenn Sie einen bestimmten Dienst eines Servers oder Rechners in Anspruch nehmen, an den korrekten Destinationport das Paket zu schicken. Den Payload eines UDP-Paketes müssen Sie hardcoden in Hexadezimal.&lt;br /&gt;
&lt;br /&gt;
Wie bei dem IP-Paket machen wir ebenfalls ein FIXUP_ALL beider UDP-Pakete, was die Länge und die &#039;&#039;Header Checksum&#039;&#039; korrigiert oder anpaßt.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5767</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5767"/>
		<updated>2005-10-15T11:53:11Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: /* breadboard constructions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| breadboard constructions]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da bei unserem defaultPacket noch nicht das Protokoll spezifiziert ist, passen wir es mit der &#039;&#039;set&#039;&#039;-Funktion unserer wrapper-Klasse &#039;&#039;fwt_ip&#039;&#039; an. Alle [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | Felder ]] des IP-Paket können mit der &#039;&#039;set&#039;&#039;-Funktion geändert werden.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da zum Beispiel das Berechnen der &#039;&#039;IHL(Internet Header Length)&#039;&#039; und der &#039;&#039;Header Checksum&#039;&#039; nicht durchgeführt wurden, lassen wir das von unserer FIXUP-Funktion erledigen. Die FIXUP-Funktion wird von unserer wrapper-Klasse zur Verfügung gestellt. Das FIXUP_ALL bewirkt, daß alle Felder(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) korrigiert oder angepaßt werden. Unser IP-Paket wird später noch zum Beispiel mit der SourceIP und der DestinationIP bestückt.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Momentan haben wir ein IP-Paket als Grundlage für beide UDP-Paket, benötigen aber noch die UDP-Pakete selbst. Wir definieren uns mit Hilfe unserer wrapper-Klasse zwei UDP-Pakete, einmal von Achen nach Bchen und zurück. Diese Pakete werden später der Payload der IP-Pakete sein und haben momentan nur Grundeinstellungen.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zwar sind die Grundeinstellungen schon ganz gut, aber trotzdem müssen wir einige Änderungen vornehmen. Als erstes beim UDP-Paket von Achen nach Bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
...und dann von Bchen nach Achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Achten Sie darauf, daß wenn Sie einen bestimmten Dienst eines Servers oder Rechners in Anspruch nehmen, an den korrekten Destinationport das Paket zu schicken. Den Payload eines UDP-Paketes müssen Sie hardcoden in Hexadezimal.&lt;br /&gt;
&lt;br /&gt;
Wie bei dem IP-Paket machen wir ebenfalls ein FIXUP_ALL beider UDP-Pakete, was die Länge und die &#039;&#039;Header Checksum&#039;&#039; korrigiert oder anpaßt.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
	<entry>
		<id>wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5766</id>
		<title>Benutzer:Grey/UDP-Testskript EN</title>
		<link rel="alternate" type="text/html" href="wiki.stageing.freitagsrunde.org//index.php?title=Benutzer:Grey/UDP-Testskript_EN&amp;diff=5766"/>
		<updated>2005-10-15T11:49:23Z</updated>

		<summary type="html">&lt;p&gt;84.59.52.179: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= UDP-testscript = &lt;br /&gt;
&lt;br /&gt;
== breadboard constructions ==&lt;br /&gt;
There are different variations of breadboard constructions for FWTEST and the FWAGENT, see here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#How_does_a_breadboard_construction_for_a_testscript_looking.3F| Versuchsaufbauten]]&lt;br /&gt;
&lt;br /&gt;
== netdate-example ==&lt;br /&gt;
On the basis of an example we want to illustrate an implementation of a testscript.&lt;br /&gt;
For example, we want to make a draft on the netdate-service of www.heise.de (we don&#039;t really to make a draft on www.heise.de, but we only simulate the traffic) for getting the actual time.&lt;br /&gt;
Netdate exists for UDP and TCP, we take here the UDP-variation.&lt;br /&gt;
&lt;br /&gt;
if we would eavesdrop the traffic with etereal or tcpdump, the packets should look like that they are real and not generated(more to this topic here: [[Benutzer:Grey/Security_Tool_Developement_Projekt_EN#Limits_of_tests| Limits of tests]]).&lt;br /&gt;
&lt;br /&gt;
Basically we are processing following credits:&lt;br /&gt;
# creating default IP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default IP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# creating default UDP-packet(achen -&amp;gt; bchen) &lt;br /&gt;
# creating default UDP-packet(bchen -&amp;gt; achen) &lt;br /&gt;
# adjusting IP-packet &lt;br /&gt;
# adjusting UDP-packet &lt;br /&gt;
# merging IP- and UDP-packets &lt;br /&gt;
# sending UDP/IP-packets via transceive-function &lt;br /&gt;
# evaluation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Now we take a closer look at the testscript, at the end will be the link to the complete source code of the netdate-script:&lt;br /&gt;
* At first we have to import our wrapper-classes (with prefix &#039;&#039;fwt_&#039;&#039;) and other needed classes:&lt;br /&gt;
&lt;br /&gt;
 import fwt_ip      # wrapper-Klasse zum erstellen/ändern von IP-Paketen&lt;br /&gt;
 import fwt_udp     # wrapper-Klasse zum erstellen/ändern von UDP-Paketen&lt;br /&gt;
 import fwt_tcp     # wrapper-Klasse zum erstellen/ändern von TCP-Paketen&lt;br /&gt;
 import posix       # &#039;&#039;&#039;TODO&#039;&#039;&#039;: Erklärung&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* After that we define two variables for debugging. &#039;&#039;dry_run&#039;&#039; is for run called dry-run, which do the packet creation, but the finally sending is skipped. The second effects, that only bchen will send their packets, packets from achen are skipped.&lt;br /&gt;
&lt;br /&gt;
 dry_run=0	    # if set the transceive function is skipped&lt;br /&gt;
 response_only=0    # send time protocol response only&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039; Wir müssen die Beiden Agenten Achen und Bchen mit einer IP-Adresse festlegen. &lt;br /&gt;
&lt;br /&gt;
 ACHEN=&#039;10.000.2.2&#039;&lt;br /&gt;
 BCHEN=&#039;10.128.2.2&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 FILTER_A=&amp;quot;not tcp port 1500 and src &amp;quot; + BCHEN + &amp;quot; and dst &amp;quot; + ACHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
 FILTER_B=&amp;quot;not tcp port 1500 and src &amp;quot; + ACHEN + &amp;quot; and dst &amp;quot; + BCHEN + &amp;quot; or icmp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As basis we need our IP-packet as we generated here. We can use our wrapper-class &#039;&#039;fwt_ip&#039;&#039; to create the default IP-packet.&lt;br /&gt;
&lt;br /&gt;
 ip_packet = fwt_ip.Packet(fwt_ip.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da bei unserem defaultPacket noch nicht das Protokoll spezifiziert ist, passen wir es mit der &#039;&#039;set&#039;&#039;-Funktion unserer wrapper-Klasse &#039;&#039;fwt_ip&#039;&#039; an. Alle [[Benutzer:Grey/Security_Tool_Developement_Projekt/set-Funktion-IP | Felder ]] des IP-Paket können mit der &#039;&#039;set&#039;&#039;-Funktion geändert werden.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.set ({&lt;br /&gt;
     fwt_ip.HEADER_PROTOCOL: 17,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da zum Beispiel das Berechnen der &#039;&#039;IHL(Internet Header Length)&#039;&#039; und der &#039;&#039;Header Checksum&#039;&#039; nicht durchgeführt wurden, lassen wir das von unserer FIXUP-Funktion erledigen. Die FIXUP-Funktion wird von unserer wrapper-Klasse zur Verfügung gestellt. Das FIXUP_ALL bewirkt, daß alle Felder(&#039;&#039;&#039;TODO: WELCHE?&#039;&#039;&#039;) korrigiert oder angepaßt werden. Unser IP-Paket wird später noch zum Beispiel mit der SourceIP und der DestinationIP bestückt.&lt;br /&gt;
&lt;br /&gt;
 ip_packet.fixup (fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Momentan haben wir ein IP-Paket als Grundlage für beide UDP-Paket, benötigen aber noch die UDP-Pakete selbst. Wir definieren uns mit Hilfe unserer wrapper-Klasse zwei UDP-Pakete, einmal von Achen nach Bchen und zurück. Diese Pakete werden später der Payload der IP-Pakete sein und haben momentan nur Grundeinstellungen.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
 udp_pkt_ba = fwt_udp.Packet(fwt_udp.defaultPacket)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zwar sind die Grundeinstellungen schon ganz gut, aber trotzdem müssen wir einige Änderungen vornehmen. Als erstes beim UDP-Paket von Achen nach Bchen...&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   53,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     37,&lt;br /&gt;
     fwt_udp.PAYLOAD:	         &#039;\x0a&#039;&lt;br /&gt;
 })&lt;br /&gt;
...und dann von Bchen nach Achen.&lt;br /&gt;
 udp_pkt_ba.set({&lt;br /&gt;
     fwt_udp.HEADER_CHECKSUM:      0,&lt;br /&gt;
     fwt_udp.HEADER_SOURCEPORT:   37,&lt;br /&gt;
     fwt_udp.HEADER_DESTPORT:     53,&lt;br /&gt;
     fwt_udp.PAYLOAD: &#039;\x69\xdc\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x03\x77\x77\x77\x05\x68\x65\x69\x73\x65\x02\x64\x65\x00\x00\x01\x00\x01&#039;,&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Achten Sie darauf, daß wenn Sie einen bestimmten Dienst eines Servers oder Rechners in Anspruch nehmen, an den korrekten Destinationport das Paket zu schicken. Den Payload eines UDP-Paketes müssen Sie hardcoden in Hexadezimal.&lt;br /&gt;
&lt;br /&gt;
Wie bei dem IP-Paket machen wir ebenfalls ein FIXUP_ALL beider UDP-Pakete, was die Länge und die &#039;&#039;Header Checksum&#039;&#039; korrigiert oder anpaßt.&lt;br /&gt;
&lt;br /&gt;
 udp_pkt_ab.fixup(fwt_udp.FIXUP_ALL, ACHEN, BCHEN);&lt;br /&gt;
 udp_pkt_ba.fixup(fwt_udp.FIXUP_ALL, BCHEN, ACHEN);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Nachdem wir nun unser IP-Grundpaket und unseren UDP-Pakete von Achen nach Bchen und zurück erstellt haben, wollen wir die Pakete vereinen.&lt;br /&gt;
Das IP-Paket von oben dient uns als Vorlage für unser UDP/IP-Paket von Achen nach Bchen. Wir übergeben unserem Konstruktor das IP-Paket als Dictionary. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das UDP/IP-Paket braucht natürlich das Ziel, daß es ansteuern soll und der Empfänger muß auch wissen wohin er die Antwort schicken müßte. Als Payload, wie schon weiter oben erwähnt, übergeben wir das UDP-Paket in Form eines String. &lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ab.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	ACHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	BCHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ab.as_str()&lt;br /&gt;
 })&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Da jetzt im IP-Paket die SourceIP- und die DestinationIP-Adresse gesetzt wurde, muß auch die &#039;&#039;Header Checksum&#039;&#039; neu berechnet werden. Genau das machen wir mit unserem FIXUP.&lt;br /&gt;
 &lt;br /&gt;
 ip_udp_pkt_ab.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Das gleiche müsssen wir nun mit dem UDP-Paket von Bchen nach Achen machen.&lt;br /&gt;
&lt;br /&gt;
 ip_udp_pkt_ba = fwt_ip.Packet(ip_packet.as_dict())&lt;br /&gt;
 ip_udp_pkt_ba.set({&lt;br /&gt;
     fwt_ip.HEADER_SOURCEIP:	BCHEN,&lt;br /&gt;
     fwt_ip.HEADER_DESTIP:	ACHEN,&lt;br /&gt;
     fwt_ip.PAYLOAD: udp_pkt_ba.as_str()&lt;br /&gt;
 })&lt;br /&gt;
 ip_udp_pkt_ba.fixup(fwt_ip.FIXUP_ALL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Zum Ausgeben der empfangenen Pakete brauchen wir eine print-Funktion (&#039;&#039;printResult&#039;&#039;). Sie prüft, ob an Achen oder Bchen ein Paket ankam und gibt es aus, andernfalls wenn gar kein Paket ankam, wird der Fehler &#039;&#039;Timeout&#039;&#039; ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 def printResult (result):&lt;br /&gt;
     if result[0] is not None:&lt;br /&gt;
          print &#039;Received on A:\n%r\n&#039; % result[0]&lt;br /&gt;
     if result[1] is not None:&lt;br /&gt;
          print &#039;Received on B:\n%r\n&#039; % result[1]&lt;br /&gt;
     if result[0] is None and result[1] is None:&lt;br /&gt;
          print &#039;Timeout&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wir schauen, ob die Option dry_run gleich 1 ist. Sollte sie 1 sein, werden lediglich die Pakete auf der Konsole ausgegeben.&lt;br /&gt;
&lt;br /&gt;
 if dry_run == 1:&lt;br /&gt;
     print &#039;dry_run: skip all transceive functions&#039;&lt;br /&gt;
     print &#039;Would send IP packet a-&amp;gt;b:\n%s\n&#039; % repr(ip_udp_pkt_ab.as_dict())&lt;br /&gt;
     print &#039;Would send IP packet b-&amp;gt;a:\n%s\n&#039; % repr(ip_udp_pkt_ba.as_dict())&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ab diesem Punkt wird es ernst und die Pakete werden wirklich gesendet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 else:&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_A, [ (&amp;quot;10.000.0.2&amp;quot;, &amp;quot;10.127.255.255&amp;quot;)])&lt;br /&gt;
     fwt_ip.set_coarse_filter_and_arp (fwt_ip.IFACE_B, [ (&amp;quot;10.128.0.2&amp;quot;, &amp;quot;10.255.255.255&amp;quot;)])&lt;br /&gt;
&lt;br /&gt;
Auch hier kommt eine der Zwei Variablen von oben ins Spiel, so daß bei response_only gleich 1 nur das UDP/IP-Paket von Bchen nach Achen gesendet wird. Mittels [[Benutzer:Grey/UDP-Testskript#transceive-Funktion|transceive-Funktion]] wird dann unser UDP/IP-Paket von Bchen nach Achen versendet. Das angekommene Paket wird in &#039;&#039;result&#039;&#039; an die erste Stelle gespeichert und ausgegeben.&lt;br /&gt;
&#039;&#039;&#039;TODO&#039;&#039;&#039;:an welche stelle wird paket in result gespeichert?&lt;br /&gt;
&lt;br /&gt;
     if response_only == 1:&lt;br /&gt;
          print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
 &lt;br /&gt;
Andernfalls wird erst das UDP/IP-Paket von Achen nach Bchen und dann zurück gesendet. Die Ergebnissse werden ebenfalls in &#039;&#039;result&#039;&#039; gespeichert.&lt;br /&gt;
&lt;br /&gt;
     else:&lt;br /&gt;
          print &#039;Will send IP packet a-&amp;gt;b:\n%r\n&#039; % ip_udp_pkt_ab&lt;br /&gt;
          result = fwt_ip.transceive (fwt_ip.IFACE_A, ip_udp_pkt_ab,  filterA=FILTER_A, filterB=FILTER_B, timeoutA=0, timeoutB=500)&lt;br /&gt;
          printResult (result)&lt;br /&gt;
          if result[1] is not None:&lt;br /&gt;
               print &#039;Will send IP packet b-&amp;gt;a:\n%r\n&#039; % ip_udp_pkt_ba&lt;br /&gt;
               result = fwt_ip.transceive (fwt_ip.IFACE_B, ip_udp_pkt_ba, filterA=FILTER_A, filterB=FILTER_B, timeoutA=500, timeoutB=0)&lt;br /&gt;
               printResult (result)&lt;br /&gt;
          else:&lt;br /&gt;
               print &#039;Lost origin packet -- Skip sending answer&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.freitagsrunde.org/~grey/sonstiges/std/netdate.py  kompletter Code von netdate].&lt;br /&gt;
&lt;br /&gt;
== transceive-Funktion ==&lt;/div&gt;</summary>
		<author><name>84.59.52.179</name></author>
	</entry>
</feed>