Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jul 2010 13:56:09 GMT
From:      Gabriel Silva <gsilva@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 181049 for review
Message-ID:  <201007161356.o6GDu9iT048140@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@181049?ac=10

Change 181049 by gsilva@gsilva on 2010/07/16 13:55:53

	Added support to replay a pcap dump file generated by an earlier fuzzing session.

Affected files ...

.. //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/fuzzer.py#6 edit
.. //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/__init__.py#3 edit

Differences ...

==== //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/fuzzer.py#6 (text+ko) ====

@@ -83,8 +83,7 @@
     """
     The main fuzzer class
     """
-
-    def __init__(self, interface, channel, state, mode, dump):
+    def __init__(self, interface, channel, state = 1, mode = "random", dump = False, replay = None):
         """initialize the fuzzer"""
         self.interface = interface
         self.channel = channel
@@ -92,6 +91,7 @@
         self.mode = mode
         self.frame_number = 0
         self.dump = dump
+        self.replay = replay
 
         self.output = PcapConnector(self.interface, wireless = True)
 
@@ -112,7 +112,7 @@
     def send_frame(self, frame):
         """send a generated frame, dumping if requested"""
         if self.dump:
-            self.output_dump.write(frame)
+            self.output_dump.write(frame.__repr__())
 
         out = self.output.write(frame.bytes, len(frame.bytes))
         self.frame_number += 1
@@ -120,14 +120,32 @@
         print "Frame %d was sent." % self.frame_number 
         
     def start(self):
-        """start the fuzzing"""
-        print "Starting a state %d fuzzing on interface %s, channel %s" % (self.state, self.interface, self.channel)
-        print "Press CTRL+C to stop.\n"
+        """start the fuzzing or replay"""
+        if self.replay:
+            print "Starting the replay of frames from file %s on interface %s, channel %s" % \
+                (self.replay, self.interface, self.channel)
+
+            replay = PcapReplayConnector(self.replay)
+            frame_counter = 0
+    
+            while True:
+                frame = replay.read()
 
-        while 1:
-            frame = self.generate_frame();
-            self.send_frame(frame);
+                if frame == None:
+                    break
 
+                self.send_frame(frame)
+                frame_counter += 1
+                print "Replaying frame %d." % frame_counter
+    
+            replay.close() 
+        else:
+            print "Starting a state %d fuzzing on interface %s, channel %s" % (self.state, self.interface, self.channel)
+            print "Press CTRL+C to stop.\n"
+    
+            while 1:
+                frame = self.generate_frame()
+                self.send_frame(frame)
 
 def main():
     usage = "usage: %prog [options] interface"
@@ -147,14 +165,26 @@
     parser.add_option("-d", "--dump",
                       dest="dump", default=False, action="store_true",
                       help="Dump the injected frames to a file for reproduction. [default %default]")
+
+    parser.add_option("-r", "--replay",
+                      dest="replay", default=None,
+                      help="Specify a pcap dump file to replay.")
     
     (options, args) = parser.parse_args()
 
     if len(args) != 1:
         parser.error("Must provide at least the interface to inject the frames.")
 
-    fuzzer = Fuzzer(args[0], options.channel, options.state, options.mode, options.dump)
+    if options.replay and options.dump:
+        parser.error("When specifying the option -r, the -d is not allowed.")
+
+    if options.replay:
+        fuzzer = Fuzzer(args[0], options.channel, replay = options.replay)
+    else:
+        fuzzer = Fuzzer(args[0], options.channel, options.state, options.mode, options.dump)
+    
     fuzzer.start()
+    
 
 if __name__ == "__main__":
     main()

==== //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/__init__.py#3 (text+ko) ====

@@ -2039,6 +2039,29 @@
 
     make_bpf_program = staticmethod(make_bpf_program)
 
+class PcapReplayConnector(Connector):
+    """A connector for replaying packets from a file
+    """
+
+    def __init__(self, replayfile = None):
+        """initialize the pcap replay connector"""
+        from pcap import pcap
+        try:
+            self.file = pcap(dumpfile = replayfile, dumptype = None)
+        except:
+            raise
+
+        self.dloff = self.file.dloff
+        self.setfilter = self.file.setfilter
+
+    def read(self):
+        """read the dumpfile"""
+        return self.file.next()[1]
+
+    def close(self):
+        """close the dumpfile"""
+        self.file.dump_close()
+
 class PcapDumpConnector(Connector):
     """A connector for dumping packets to a file for later re-use.
 



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