Changes between Version 1 and Version 2 of zzuf/tutorial


Ignore:
Timestamp:
05/18/08 01:34:39 (5 years ago)
Author:
sam
Comment:

random seed, different applications, file creation

Legend:

Unmodified
Added
Removed
Modified
  • zzuf/tutorial

    v1 v2  
    1 = Zzuf tutorial = 
     1This tutorial is a hands-on guide to the most important `zzuf` features. It starts with the working principles but goes on with very advanced uses of the tool. 
    22 
    3 '''WARNING''': this tutorial requires `zzuf` version 0.11 or later. 
     3Warning: this tutorial requires `zzuf` version 0.11 or later. 
    44 
    5 == Basics == 
     5= Basic `zzuf` usage = 
    66 
    7 Let’s start with a simple command that reads data from a file. We choose `hd`, the hexadecimal dump command, and tell it to read 32 bytes from `/dev/zero`: 
     7`zzuf`’s behaviour is configured through the command line. A comprehensive list of flags and their meaning is given in the `zzuf` manual page. Just run '''`man zzuf`''' on your system to see it. 
     8 
     9== Launching `zzuf` == 
     10 
     11Let’s start with a simple command that reads data from a file. We choose `hd`, the hexadecimal dump command, so that we get a chance to observe what exactly happens to the data. 
     12 
     13We tell `hd` to read 32 bytes from `/dev/zero`: 
    814 
    915{{{ 
     
    3743We get exactly the same output. This is a very important property of `zzuf`: its behaviour is '''reproducible'''. 
    3844 
    39 == Altering the fuzzing ratio == 
     45== Invoking different programs == 
     46 
     47Let’s fuzz the `cat` utility instead of `hd`, but read the final output with `hd` nonetheless: 
     48 
     49{{{ 
     50% zzuf cat /dev/zero | hd -vn 32 
     5100000000  00 00 02 00 00 00 00 00  00 00 00 00 00 00 00 00  |................| 
     5200000010  00 00 00 00 00 02 00 00  00 00 00 00 00 00 00 00  |................| 
     5300000020 
     54% 
     55}}} 
     56 
     57Now instead of calling `hd`, let’s try `od`, the octal dumper: 
     58{{{ 
     59% zzuf od -vN 32 /dev/zero 
     600000000 000000 000002 000000 000000 000000 000000 000000 000000 
     610000020 000000 000000 001000 000000 000000 000000 000000 000000 
     620000040 
     63% 
     64}}} 
     65 
     66If you understand octal dumps as fluently as hexadecimal dumps, you noticed that the data has been fuzzed exactly like with `hd`. 
     67 
     68This is another very important property of `zzuf`: '''data is fuzzed the same way regardless of the fuzzed application'''. 
     69 
     70== The fuzzing ratio == 
    4071 
    4172The '''fuzzing ratio''' is the proportion of bits that `zzuf` changes. It is specified with the '''`-r` flag'''. The default fuzzing ratio is 0.004, meaning "fuzz 0.4% of the bits". 32 bytes is 256 bits, and 0.4% of 256 bits is approximately 1. `zzuf` should have fuzzed 1 bit, but since it fuzzes bits at random, 2 bits is not surprising. 
     
    74105% 
    75106}}} 
     107 
     108== The random seed == 
     109 
     110`zzuf`’s behaviour is reproducible, but we might not be satisfied with the output. Or we may simply want to fuzz in several different ways, but still using the same fuzzing ratio. This is done by changing the '''random seed''' with the '''`-s` flag'''. The random seed is the initial value of `zzuf`’s random number generator. The default seed is 0, so let’s try with other values: 
     111 
     112{{{ 
     113% zzuf -s 2 hd -vn 32 /dev/zero 
     11400000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................| 
     11500000010  00 00 00 00 80 00 00 00  00 00 00 00 00 00 00 00  |................| 
     11600000020 
     117% zzuf -s 79432 hd -vn 32 /dev/zero   
     11800000000  00 00 00 00 00 00 00 20  00 00 00 00 00 00 00 00  |....... ........| 
     11900000010  00 00 00 00 00 02 00 00  00 00 00 00 00 00 00 00  |................| 
     12000000020 
     121% 
     122}}} 
     123 
     124As can be seen, each seed value initiates a different behaviour of the random number generator. 
     125 
     126== Creating fuzzed files == 
     127 
     128It is possible to fuzz files directly, without calling applications at all. 
     129 
     130To do so, simply call `zzuf` with no application argument. It will fuzz its standard input by default: 
     131 
     132{{{ 
     133% cat /dev/zero | zzuf | hd -vn32           
     13400000000  00 00 02 00 00 00 00 00  00 00 00 00 00 00 00 00  |................| 
     13500000010  00 00 00 00 00 02 00 00  00 00 00 00 00 00 00 00  |................| 
     13600000020 
     137% 
     138}}} 
     139 
     140`zzuf` can be used to create files: 
     141 
     142{{{ 
     143% dd if=/dev/zero bs=1 count=32 | zzuf > output.file 
     14432+0 records in 
     14532+0 records out 
     14632 bytes (32 B) copied, 9.1129e-05 s, 351 kB/s 
     147% hd -v output.file 
     14800000000  00 00 02 00 00 00 00 00  00 00 00 00 00 00 00 00  |................| 
     14900000010  00 00 00 00 00 02 00 00  00 00 00 00 00 00 00 00  |................| 
     15000000020 
     151% 
     152}}} 
     153 
     154This may be useful if a given application is not supported by `zzuf`, but it is especially useful to generate files that reproduce `zzuf`’s behaviour without requiring `zzuf`. 
     155