GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - secureworks/flowsynth: a network packet capture compiler

BranchesTags
Open more actions menu

Latest commit

 

History

61 Commits
61 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
scripts
scripts
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
requirements.txt
requirements.txt
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 

Repository files navigation

Flowsynth

Flowsynth is a tool for rapidly modeling network traffic. Flowsynth can be used to generate text-based hexdumps of packets as well as native libpcap format packet captures.

Installation and Usage Overview

Flowsynth has been tested on Python 2.7 and Python 3.

pip install flowsynth to install the wheel.

Python Script

Usage:

usage: flowsynth.py [-h] [-f OUTPUT_FORMAT] [-w OUTPUT_FILE] [-q] [-d]
                    [--display {text,json}] [--no-filecontent]
                    [--seed SEED] [--start-time START_TIME]
                    input

positional arguments:
  input                 input files

optional arguments:
  -h, --help            show this help message and exit
  -f OUTPUT_FORMAT      Output format. Valid output formats include: hex, pcap
  -w OUTPUT_FILE        Output file.
  -q                    Run silently
  -d                    Run in debug mode
  --display {text,json}
                        Display format
  --no-filecontent      Disable support for the filecontent attribute
  --seed SEED           Seed for random values (MACs, TCP ISNs, 'any' ports). Also fixes packet
                        timestamps, so the same input and seed give an identical pcap.
  --start-time START_TIME
                        Timestamp of the first packet, as epoch seconds or ISO-8601 (UTC unless an
                        offset is given); later packets follow at 1ms intervals. Default with --seed:
                        2000-01-01T00:00:00Z. Without --seed or --start-time, timestamps are the build time.

Reproducible output

By default, values Flowsynth picks itself (default MAC addresses, TCP initial sequence numbers, any ports) are random, and packet timestamps are the time of the build. Passing --seed N (or seed=N to Model) seeds those random values and also replaces the wall-clock timestamps with fixed ones: the first packet is stamped 2000-01-01 00:00:00 UTC and each following packet 1 ms later. The same input file and seed then produce a byte-for-byte identical pcap (for a given Flowsynth, Scapy and Python version).

To start somewhere other than 2000-01-01, add --start-time (or start_time= to Model) with epoch seconds or an ISO-8601 date/time, e.g. --seed 7 --start-time 2026-11-14T10:00:00Z. A time without an offset is taken as UTC; Model also accepts a datetime. It must fall between 1970 and 2106, the range a pcap timestamp can hold. --start-time can be used without --seed too, in which case the timestamps are fixed but the random values are not.

Host names in flow declarations are resolved at build time and can resolve to different addresses from one build to the next; use IP addresses for reproducible output.

Python Module

Example usage:

import flowsynth
fsmodel = flowsynth.Model(input="my.synth", output_file="out.pcap", output_format="pcap")
fsmodel.build()

The Model class function build() executes flowsynth and the class constructor takes the same arguments as the script (see above):

class Model():
    def __init__(self, input, output_format="pcap", output_file="", quiet=False, debug=False, display="text", no_filecontent=False, seed=None, start_time=None):
    ...

Note: Because of the current less-than-ideal use of global variables instead of class variables, if more than one Model object is used concurrently, there will be issues. Hopefully this limitation will be remedied in a future release.

If the module is installed, Flowsynth can be invoked from the command line and run like a script, e.g.:

python3 -m flowsynth -f pcap -w out.pcap my.synth

How it works

Flowsynth uses a syntax language to describe network flows. The syntax language is made up of individual instructions that are parsed by the application and are grouped into events, which are a logical representation of the instructions in the network domain. After all instructions have been parsed, the events are iterated over and converted into packets, which are the real-world representation of the traffic on the wire.

These three phases are referred to as the parsing phase, rendering phase, and the output phase.

Take the following synfile as an example:

flow default tcp myhost.corp.acme.net:12323 > google.com:80 (   tcp.initialize; );
default > ( content:"GET / HTTP/1.1\x0d\x0a"; content:"Host: google.com\x0d\x0a\x0d\x0a"; );
default < ( content:"HTTP/1.1 200 OK"; );

This sample contains two types of instructions: Flow declarations and event declarations. The first line (flow default tcp...) declares to Flowsynth that a flow is being tracked between myhost.corp.acme.net and google.com. The flow name is default. All events that apply to this flow will use this name (default) to identify which flow they apply to. The third argument specifies which protocol the flow will use. In this case it's tcp. Next we specify the source and destination addresses and ports. Finally, an optional attributes section is included at the end. The tcp.initialize attribute is included, which tells Flowsynth to automatically generate a three-way handshake for this flow. It's worth nothing that each attribute and line should be closed with a semicolon (;), as shown above. When this flow declaration instruction is parsed by Flowsynth the application will automatically generate event entries in the compiler timeline to establish a three way handshake.

Next, Flowsynth will parse the event declaration default > ( content .... Flowsynth will immediately identify that this event declaration belongs to the 'default' flow that was just declared. Once this event is associated with the flow any protocol specific values (like TCP SEQ and ACK numbers) will automatically be applied to the event. The directionality for this specific event is '>', or TO_SERVER. Once the parent flow and directionality have been established Flowsynth will parse the optional attributes section. Just like the flow declaration, each optional attribute must be closed with a semicolon (;). The two 'content' attributes are used to specify the packet's payload. In this case, a HTTP request is being rendered. Flowsynth will read these instructions and generate an entry in the compiler timeline for this event.

The last event declaration that is parsed by the application shows the server's response to the client. Using the same methods described above, Flowsynth will parse the event declaration and add it to the compiler timeline.

Once all the instructions have been parsed and processed, Flowsynth iterates over the compiler timeline and renders any events to native packets. In this phase of the application several important things happen:

  1. Protocol-specific intelligence, like TCP SEQ/ACK calculations, and ACK generation take place.
  2. Specific features of attributes, like converting '\x3A' to ':' take place.

Once all of the events have been rendered to native pcaps the output phase occurs. During the output phase the native packets are delivered to the user in one of the two output formats, as a hexdump, or as a native PCAP file.

Usage

flowsynth.py input.syn

In this most basic example, Flowsynth will read input.syn and output the resulting hexdump to the screen. By default Flowsynth will use 'hex' format.

flowsynth.py input.syn -f pcap -w /tmp/test.pcap

In this example, Flowsynth reads input.syn and outputs a libpcap formatted .pcap file to /tmp/test.pcap

Syntax

All Flowsynth syntax files are plain-text files. Currently three types of instructions are supported.

  • Comments
  • Flow Declarations
  • Event Declarations

As new features are added, this syntax reference will be updated.

Comments

Comments are supported using the # symbol.

# This is a synfile comment

Flows

Declaring a Flow

You can declare a flow using the following syntax:

flow [flow name] [proto] [src]:[srcport] [directionality] [dst]:[dstport] ([flow options]);

src and dst can be IPv4 addresses, IPv6 addresses, or resolvable domain names. For IPv6, the address(es) must be enclosed in square brackets ('[' and ']').

The following flow declaration would describe a flow going from a computer to google.com:

flow my_connection tcp mydesktop.corp.acme.com:44123 > google.com:80 (tcp.initialize;);

The following flow declaration would describe a flow going from a computer to a DNS server:

flow dns_request udp  mydesktop.corp.acme.com:11234 > 8.8.8.8:53;

The following flow declaration would describe a flow using IPv6 addresses:

flow default tcp [2600:1337:2800:1:248:1893:25c8:d1]:31337 > [2600:1337:2800::f1]:80 (tcp.initialize;);

For the interim, directionality should always be specified as to server: >

If a DNS record is specified in the flow declaration (instead of an explicit IP address) then Flowsynth will resolve the DNS entry at the time of the flow's declaration. The first A record returned for DNS entry will be used as the IP address throughout the session. The DNS query and response is not included in the output.

A port may be given as any, in which case a random port between 1024 and 65000 is chosen and used for the life of the flow.

Declaring a flow with a name that is already in use starts a new flow under that name (Flowsynth logs a warning). Events after the new declaration belong to the new flow; events before it keep the earlier one.

Flow Attributes

The following flow attributes are currently supported:

tcp.initialize

The tcp.initialize attribute informs Flowsynth that the flow should have an autogenerated TCP three-way handshake included in the output. The handshake is always added relative to the location of the flow declaration in the synfile. The client and server initial sequence numbers are random 32-bit values unless tcp.client_isn and tcp.server_isn set them.

usage:

(tcp.initialize; );

tcp.client_isn and tcp.server_isn

The tcp.client_isn and tcp.server_isn attributes set the client's and the server's initial sequence numbers (0 to 4294967295) instead of random ones. With tcp.initialize, the SYN and SYN/ACK carry them, so data starts one higher. Without it, they are where each side's sequence numbers start.

Before version 1.5.0, tcp.initialize always used 10 and 100. A synfile that sets absolute tcp.seq or tcp.ack values worked out from those can add them back:

usage:

(tcp.initialize; tcp.client_isn: 10; tcp.server_isn: 100; );

src_mac

The src_mac attribute explicitly sets the MAC address for packets from the flow source. If no MAC is supplied, the source host's MAC from another flow that sets one explicitly is used (the first, if several do), wherever that flow is in the synfile. Otherwise a random unicast, locally administered MAC is chosen once for the host and reused across all flows.

usage: (tcp.initialize; src_mac: 36:16:3a:4e:6a:12; );

dst_mac

The dst_mac attribute explicitly sets the MAC address for packets from the flow destination. If no MAC is supplied, the destination host's MAC from another flow that sets one explicitly is used (the first, if several do), wherever that flow is in the synfile. Otherwise a random unicast, locally administered MAC is chosen once for the host and reused across all flows.

usage: (tcp.initialize; dst_mac: 36:16:3a:4e:6a:13; );

Events

Transferring Data

Data can be transferred between hosts using two methods. The example below outlines a data exchange between a client and a webserver:

my_connection > (content:"GET / HTTP/1.1\x0d\x0aHost:google.com\x0d\x0aUser-Agent: DogBot\x0d\x0a\x0d\x0a";);
my_connection < (content:"HTTP/1.1 200 OK\x0d\x0aContent-Length: 300\x0d\x0a\x0d\x0aWelcome to Google.com!";);

In this example, the flow my_connection must have been previously declared. A single packet with the content specified will be transmitted from the client to the server. The following method is also accepted, however, this may change in the future as the syntax is formalized.:

my_connection.to_server (content:"GET / HTTP/1.1\x0d\x0aHost:google.com\x0d\x0aUser-Agent: DogBot\x0d\x0a\x0d\x0a";);
my_connection.to_client (content:"HTTP/1.1 200 OK\x0d\x0aContent-Length: 300\x0d\x0a\x0d\x0aWelcome to Google.com!";);

Each content keyword within the () should be closed by a semicolon. Each line should also be closed with a semicolon. Failure to do so will generate a lexer error. Multiple content matches can also be used to logically seperate parts of the response, for example:

# the commands below describe a simple HTTP request
my_connection > (content:"GET / HTTP/1.1\x0d\x0aHost:google.com\x0d\x0a\x0d\x0a";);
my_connection < (content:"HTTP/1.1 200 OK\x0d\x0aContent-Type: text/html\x0d\x0a\x0d\x0a"; content:"This is my response body.";);

Event Attributes

The following event attributes are currently supported:

  • content
  • filecontent
  • tcp.seq
  • tcp.ack
  • tcp.noack
  • tcp.flags.syn
  • tcp.flags.ack
  • tcp.flags.synack
  • tcp.flags.fin
  • tcp.flags.rst
Content Attribute

The content attribute is used to specify the payload of a packet. Content attributes must be enclosed in double quotes. UTF-8 is supported and arbitrary bytes can be expressed with the "\xHH" notation where "HH" is the hexidecimal representation of the byte. For example, a carriage return (ASCII 0x0D) followed by a line feed (ASCII 0x0A) can be defined like this: \x0D\x0A. This translation takes place during the render phase.

Example:

default > ( content: "GET / HTTP/1.1\x0d\x0a"; );
Filecontent Attribute

The filecontent attribute is used to specify a file that can be used as the payload of a packet. The value of a filecontent attribute is the file that will be read into the payload.

Example:

default > ( content: "HTTP/1.1 200 OK\x0d\x0a\x0d\x0a"; filecontent: "index.html"; );
tcp.seq Attribute

The tcp.seq attribute lets you set the sequence number for the event's packet. If the content is split into several segments, they follow on from it. Values wrap at 2^32.

What happens next depends on where the value falls:

  • On a side's first packet or a SYN, the side's stream starts there.
  • When the packet carries data (or a SYN or FIN) and ends past what that side has sent so far, later packets from that side follow on from it.
  • When the packet falls within data already sent (a retransmission or an overlapping segment), later packets continue from the end of the stream.

The other side acknowledges data the way a real receiver does: up to the first byte it hasn't received. A packet that leaves a hole gets a duplicate ACK for the start of the hole, and once the hole is filled, the ACK covers everything received.

Example:

default > (content:"abc"; tcp.seq: 1000;);
default > (content:"de";);
default > (content:"AB"; tcp.seq: 1000;);
default > (content:"jk"; tcp.seq: 1009;);
default > (content:"fghi"; tcp.seq: 1005;);
  • "abc" goes at 1000 and "de" at 1003; the server acknowledges 1003, then 1005.
  • "AB" resends bytes 1000-1001 with different content; the server acknowledges 1005 again.
  • "jk" at 1009 leaves a hole at 1005-1008, so the server acknowledges 1005 again.
  • "fghi" fills the hole, and the server acknowledges 1011. A packet without tcp.seq would go next at 1011.

A flow's initial sequence numbers are random unless tcp.client_isn and tcp.server_isn set them. An absolute tcp.seq or tcp.ack value only means something against a known sequence, so set both attributes on flows that use them. (A tcp.seq on a side's very first packet also sets its sequence, but the automatic ACK of the other side's data counts as a packet.) Flowsynth logs a warning when a value is compared with a random sequence number.

tcp.ack Attribute

The tcp.ack attribute lets you set the acknowledgement number for the event's packets (every segment, if the content is split by the MSS). It only affects that event; the flow's sequence tracking is unchanged.

tcp.noack Attribute

The tcp.noack attribute tells Flowsynth to not generate an ACK for this event.

Flowsynth generates an ACK from the other side only for packets that carry data or a FIN. Other packets without payload, such as a bare tcp.flags.ack event, get no automatic ACK. (Before version 1.5.0 they did, so synths with such events now produce fewer packets.)

tcp.flags.syn Attribute

The tcp.flags.syn attribute tells Flowsynth to force the packet to be a SYN packet. If the event's content is split by the MSS, only the first segment is a SYN.

A SYN consumes one sequence number, so a second SYN event follows on from the first. To send a retransmitted SYN, give it the same tcp.seq as the first; the same goes for a retransmitted FIN.

tcp.flags.ack Attribute

The tcp.flags.ack attribute tells Flowsynth to force the packet to be an ACK packet.

tcp.flags.synack Attribute

The tcp.flags.synack attribute tells Flowsynth to force the packet to be a SYN/ACK packet (the first segment only, if the content is split by the MSS).

A SYN/ACK carries no data, so it gets no automatic ACK. When you write a handshake yourself, add the client's ACK as its own event:

default > (tcp.flags.syn;);
default < (tcp.flags.synack;);
default > (tcp.flags.ack;);
tcp.flags.fin Attribute

The tcp.flags.fin attribute tells Flowsynth to send a FIN (with ACK) to close that side of the connection. If the event also has content, the FIN is set on the last data segment. Like a SYN, a FIN consumes one sequence number: the other side's ACK acknowledges it, and any later packets from the closing side continue after it.

A four-way close, with the client closing first:

default > (tcp.flags.fin;);
default < (tcp.flags.fin;);

This produces FIN/ACK, ACK, FIN/ACK, ACK. To have the server's FIN carry the ACK of the client's FIN (a three-packet close), add tcp.noack to the first FIN:

default > (tcp.flags.fin; tcp.noack;);
default < (tcp.flags.fin;);
tcp.flags.rst Attribute

The tcp.flags.rst attribute tells Flowsynth to force the packet to be a RST packet.

Authors

  • Will Urbanski (will dot urbanski at gmail dot com)

Contributors

  • David Wharton
  • @2xyo
  • @bhaan
  • Brad Crittenden (@bac)

About

a network packet capture compiler

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

206 stars

Watchers

18 watching

Forks

31 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.