Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An application that utilizes fast AF_XDP Linux sockets to generate and send network packets. Used for penetration testing including Denial of Service (DoS) and network monitoring. Made by@gamemann!

License

NotificationsYou must be signed in to change notification settings

Packet-Batch/Program

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Packet Batch AF_XDP Build WorkflowPacket Batch AF_XDP Run Workflow

Packet Batch is a collection of high-performance applications and tools designed for generating and sending network packets. It serves two main purposes: penetration testing, which involves assessing network security by simulating various attacks likeDenial of Service (DoS); and network monitoring, which involves analyzing and inspecting network traffic.

Features

  • The ability to send multiple network packets in a chain via sequences and multiple payloads inside of a single sequence coming from the same source.
  • Support for sending from randomized source IPs within range(s) indicated by CIDR.
  • Support for randomized payload data within a specific range in length.
  • UDP, TCP, and ICMP layer 4 protocols supported.
  • Optional layer 3 and 4 checksum calculation in the event you want the NIC's hardware to calculate checksums for generated outgoing packets.

Note Regarding Seeding/Randomness

When generating randomness in a packet (e.g. random source IPs, ports, payload(s), etc.), by default, we try to use nanoseconds since boot usingtimespec as the seed when passing torand_r() for example. However, I've found this isn't completely random, especially since the seed variable (unsigned int) andtimespec nanoseconds variable (long) do not match in size.

Therefore, I added the constantVERY_RANDOM that can be uncommented. When this constant is defined, thegetrandom() function is used to fill the seed with random bytes. This results in more randomness, but thegetrandom() function adds a bit more overhead than retrieving the nanoseconds since system boot from my testing.

Disclaimer

I doNOT support using these tools maliciously or as a part of a targeted attack. I've made these tools to perform penetration tests against my own firewalls along with occasionally debugging network issues such as packets not arriving to their destination correctly.

Showcase

These are just a couple of basic tests I performed between two virtual machines on my home server.

Test One

Test Two

NOTE - Since the above demos, there was a change in Packet Batch that allows for more precise/randomized IPs/ports via seedinghere (using the seed, nanoseconds since boot, instead of the UNIX timestamp which is shown above). Therefore, Packet Batch will now send from a more randomized IP/port than what is shown above!

AF_XDP

This is a special version of Packet Batch that utilizesAF_XDPsockets instead ofAF_PACKETv3 (which is what the standard version uses). I recommend using this version over the standard version due to performance improvements, but you must keep in mind the following.

  1. AF_XDP sockets require amore recent Linux kernel.
  2. The TCPcooked andoneconnection settings areNOT available in this version due to no cooked sockets support in AF_XDP.

The above is why we aren't utilizing AF_XDP sockets in the standard version.

From the benchmarks I've concluded on my home server running Proxmox VMs, AF_XDP sockets send around 5 - 10% more packets per second than the standard version and the amount of packets per second it is sending is a lot more consistent (regardless of the batch size option explained below). I won't have solid benchmarks until I perform these tests on full dedicated hardware which should happen in early 2022.

Building And Installing

Building and installing this project is fairly easy and just like the standard version. It includes building the Packet Batch Common repository which requiresJSON-C. As long as you use the--recursive flag withgit, it should retrieve all of the required submodules automatically located in themodules/ directory. Otherwise, you will need to go into the Common repository and execute thegit submodule update --init command. We usemake to build and install the application.

The following commands should work for Ubuntu/Debian-based systems. However, you should be able to install this on other Linux distros with a few adjustments as well.

# Update apt.sudo apt update# Install Git if it isn't already installed.sudo apt install -y git# Clone this repository along with its submodules.git clone --recursive https://github.com/Packet-Batch/PB-AF-XDP.git# Install build essentials/tools and needed libaries for JSON-C.sudo apt install -y build-essential clang cmake pkgconf# Install LibELF for BPF.sudo apt install -y libelf-dev# Change the current working directory to PB-AF-XDP/.cd PB-AF-XDP/# Execute ./build.sh file to build and install dependencies and main project which requires sudo privileges.# WARNING - If you don't have sudo available on your system, please look at the ./build.sh file and execute make commands as root in order.# NOTE - You may also look at the .github/workflows/build.yml.# NOTE - The first argument represents the amount of threads to use with make. 0 uses the amount of available threads on the system and supplying no argument uses 1 thread../build.sh 0# You may use the following to clean the build. You must run this as root or sudo because of the Common's cleanup.sudo make clean

Install GIF

Installation Video!

Click here to watch!

Warning! - The installation video is a bit outdated, but should show most of the installation process. Since the video was made, we've switched tojson-c fromlibyaml and use a build script to build the project and its dependencies (./build.sh).

After installing, the executable is copied to the/usr/bin/ directory which should be included in your$PATH. Therefore, you may use the application globally (in any directory).

For example.

pcktbatch -c /path/to/conf.json

Command Line Usage

Basic

Basic command line usage may be found below.

Usage: pcktbatch -c<configfile> [-v-h]-c --cfg => Path to the config file.-l --list => Print basic information about sequences.-v --verbose => Provide verbose output.-h --help => Print outhelp menu andexit program.

First Sequence Override

If you wanted to quickly send packets and don't want to create a config file, you may specify command line options to override the first sequence. You must also specify the-z or--cli flag in order to do this.

The following command line options are available to override the first sequence.

-z --cli => Enables the first sequence/packet override.--interface => The interface to send out of.    --block => Whether toenable blocking mode (0/1).       --track => Track packet and byte statistics and print at the end (0/1). Will impact performance!--maxpckts => The maximum amount of packets to send during this sequence before exiting.--maxbytes => The maximum amount of bytes to send during this sequence before exiting.--pps => The amount of packets per second to limit this sequence to (0 = disabled).--bps => The amount of bytes per second to limit this sequence to (0 = disabled)--delay => The delay in-between sending packets on each thread.--threads => The amount of threads and sockets to spawn (0 = CPU count).--l4csum => Whether to calculate the layer-4 checksum (TCP, UDP, and ICMP) (0/1).--smac => The ethernetsource MAC address to use.--dmac => The ethernet destination MAC address to use.--minttl => The minimum IP TTL to use.--maxttl => The maximum IP TTL to use.--minid => The minimum IP ID to use.--maxid => The maximum IP ID to use.--sip => Thesource IP (one range is supportedin CIDR format).--dip => The destination IP.--protocol => The protocol to use (TCP, UDP, or ICMP).--tos => The IP TOS to use.--l3csum => Whether to calculate the IP header checksum or not (0/1).--usport => The UDPsource port.--udport => The UDP destination port.--tsport => The TCPsource port.--tdport => The TCPsource port.--syn => Set the TCP SYN flag (0/1).--ack => Set the TCP ACK flag (0/1).--psh => Set the TCP PSH flag (0/1).--rst => Set the TCP RST flag (0/1).--fin => Set the TCP FIN flag (0/1).--urg => Set the TCP URG flag (0/1).--ece => Set the TCP ECE flag (0/1).--cwr => Set the TCP CWR flag (0/1).--pmin => The minimum payload data.--pmax => The maximum payload data.--pstatic => Use static payload (0/1).--pexact => The exact payload string.--pfile => Whether to parse a file as the'pexact' string instead.--pstring => Parse the'pexact' string or file as a string instead of hexadecimal.

AF_XDP

There is additional command line usage with the AF_XDP version which may be found below.

--queue => If set, all AF_XDP/XSK sockets are bound to this specific queue ID.--nowakeup => If set, all AF_XDP/XSK sockets are bound without the wakeup flag.--sharedumem => If set, all AF_XDP/XSK sockets use the same UMEM area.--batchsize => How many packets to send at once (default 1).--forceskb => If set, all AF_XDP/XSK sockets are bound using the SKB flag instead of DRV mode.--zerocopy => If set, all AF_XDP/XSK sockets are attempted to be bound with zero copy mode.--copy => If set, all AF_XDP/XSK sockets are bound with copy mode.

NOTE - Thebatch size indicates how many packets to send at the same time, but this is thesame packet data. This may or may not speed up performance, but personally I didn't see much of an impact.

NOTE - By default, each socket is created in a separate thread specified in the config and is bound to a separate queue ID (incremented by 1). With that said, shared UMEM is not supported by default and each socket has its own UMEM area. The XDP wakeup flag is also specified by default which should improve performance.

Configuration File

If you want to use more than one sequence or more control, you will need to specify sequences inside of a config file using theJSON syntax.

Before continuing, here is information on the types used below with the config.

NameLength (Bytes)UnsignedDescription
stringN/AN/AA string terminated by\0.
byte1yesA single byte integer.
boolean1yesA singletrue (1) orfalse (0) value.
ushort2yesAn unsigned short.
short2noA short.
uint4yesAn unsigned integer.
int4noAn integer.
ulong8yesAn unsigned long.
long8noA long.

Here is the full config file format.

KeyTypeDefaultDescription
interfacestringnullThe default interface to send packets out of.
sequencesArraySequence Object[]An array of sequences to use (see below).
ExamplesBasic config.
{"interface":"devint","sequences": [        {...        },        {...        }    ]}

Sequence Object

The sequence object has the following fields.

KeyTypeDefaultDescription
interfacestringnullThe interface to use when sending out of this sequence.
blockbooleantrueWhether to block the main thread/other sequences until this sequence is completed.
trackbooleanfalseTracks total packets/bytes including average per second for the sequence and prints before the program exits. This will impact performance!
maxpcktsulong0If above 0, the sequence will exit after hitting this amount of total packets sent.
maxbytesulong0If above 0, the sequence will exit after hitting this amount of total bytes sent.
ppsulong0If above 0, will limit the sequence to this amount of packets per second.
bpsulong0If above 0, will limit the sequence to this amount of bytes per second.
timeulong0If above 0, will limit the sequence to this amount of time in seconds before exiting.
threadsushort0If 0, will spawnx amount of threads for this sequence. Otherwise, uses CPU count.
delayulong1000000The delay between each iteration (sent packet) in the sequence in microseconds.
l4csumbooleantrueWhether to calculate the layer-4 checksum in the program.
ethEthernet Object{}The ethernet header object (see below).
ipIP Object{}The IP header object (see below).
udpUDP Object{}The UDP header object (see below).
tcpTCP Object{}The TCP header object (see below).
icmpICMP Object{}The ICMP header object (see below).
payloadsArrayPayload Object[]The payloads array (see below).
Examples

The following sends packets out of thedev interface. It blocks the thread and only runs for 20 seconds. There is a 100000 microsecond delay in-between sending packets on the main sequence.

{"interface":"dev","block":true,"time":20,"delay":100000,"eth": {...    },"ip": {...    },"tcp": {...    },"udp": {...    },"icmp": {...    },"payloads": [...    ]}

The following sends packets out of thedev interface. It blocks the thread and only runs until 3000 packets sent. there is no delay between sending packets, so it will send packets as fast as it can.

{"interface":"dev","block":true,"maxpckts":3000,"time":0,"delay":0,"eth": {...    },"ip": {...    },"tcp": {...    },"udp": {...    },"icmp": {...    },"payloads": [...    ]}

The following sends packets out of thedev interface. It blocks the thread and runs until you hit CTRL + C or use another method to kill the process. The sequence is limited to sending 300 packets per second.

{"interface":"dev","block":true,"pps":300,"time":0,"delay":0,"eth": {...    },"ip": {...    },"tcp": {...    },"udp": {...    },"icmp": {...    },"payloads": [...    ]}

Ethernet Object

The ethernet object contains the following fields.

KeyTypeDefaultDescription
smacstringnullThe source MAC address to use. If not set, will attempt to retrieve the source MAC address automatically.
dmacstringnullThe destination MAC address to use. If not set, will attempt to retrieve the destination MAC address automatically via gateway.
Examples

The following sends packets from09:EB:23:AB:2D:B1 to08:EC:4B:23:F2:E3.

{"smac":"09:EB:23:AB:2D:B1","dmac":"08:EC:4B:23:F2:E3"}

IP Object

The IP object contains the following fields.

KeyTypeDefaultDescription
sipstringnullThe source IP to send from.
dipstringnullThe destination IP to send to.
protocolstringnullThe layer-4 protocol. Available options includetcp,udp, andicmp.
tosbyte0The Type of Server (ToS) to use.
csumbooleantrueWhether to calculate the IP header checksum.
ttlTTL Object{}The TTL object (see below).
idID Object{}The ID object (see below).
rangesArrayString{}An array of IP ranges that should be in the<ip>/<cidr> format.
Examples

Here's an example that sends packets from192.168.2.2 to192.168.2.3. The protocol is TCP.

{"sip":"192.168.2.2","dip":"192.168.2.3","protocol":"tcp","csum":true,"ttl": {...    },"id": {...    },"ranges": [...    ]}

Here's another example that sends packets from random IPs within the10.4.0.0/24 and10.5.0.0/24 ranges to10.3.0.2. The protocol used is UDP.

{"sip":null,"dip":"10.3.0.2","protocol":"udp","csum":true,"ranges": ["10.4.0.0/24","10.5.0.0/24"    ]}
TTL Object

The TTL object contains the following fields.

KeyTypeDefaultDescription
minbyte64The minimum TTL to use.
maxbyte64The maximum TTL to use.
Examples

Here's an example of generating a TTL between64 and128 every time we generate a packet.

{"min":64,"max":128}
ID Object

The ID object contains the following.

KeyTypeDefaultDescription
minbyte0The minimum ID to use.
maxbyte64000The maximum ID to use.
Examples

Here's an example of generating an ID between4000 and9000 every time we generate a packet.

{"min":4000,"max":9000}

TCP Object

The TCP object contains the following fields.

KeyTypeDefaultDescription
sportushort0The TCP source port to use. If 0, will generate a random port.
dportushort0The TCP destination port to use. If 0, will generate a random port.
synbooleanfalseSets the TCP SYN flag.
pshbooleanfalseSets the TCP PSH flag.
finbooleanfalseSets the TCP FIN flag.
ackbooleanfalseSets the TCP ACK flag.
rstbooleanfalseSets the TCP RST flag.
urgbooleanfalseSets the TCP URG flag.
ecebooleanfalseSets the TCP ECE flag.
cwrbooleanfalseSets the TCP CWR flag.
Examples

Here's an example of sending packets with the SYN flag set to port80.

{"dport":80,"syn":true}

UDP Object

The UDP object contains the following.

KeyTypeDefaultDescription
sportushort0The UDP source port to use. If 0, will generate a random port.
dportushort0The UDP destination port to use. If 0, will generate a random port.
Examples

Here's an example of sending packets from UDP source port27005 to destination port27015.

{"sport":27005,"dport":27015}

ICMP Object

The ICMP object contains the following fields.

KeyTypeDefaultDescription
codebyte0The ICMP code to set.
typebyte0The ICMP type to set.
Examples

Here's an example of sending an ICMP echo request (type 8 and code 0).

{"code":0,"type":8}

Payload Object

The payload object contains the following fields.

KeyTypeDefaultDescription
exactstringnullThe exact payload in hexadecimal.
isstaticbooleanfalseWhether the payload is static (shouldn't change). Ifexact isn't set, it will generate payload once and reuse that payload each time.
isfilebooleanfalseWhetherexact should act as the path to the file and read as is.
isstringbooleanfalseWhether to parseexact as a string instead of hexadecimal.
lengthLength Object{}The length object (see below).
Examples

This example sends packets with the payload0x01 0xFB 0x02 0xFC (4 bytes in payload size).

{"exact":"01 FB 02 FC"}

This example sends packets with a random payload between 0 and 5 bytes.

{"length": {"min":0,"max":5    }}

This example parses./mypayload.txt as hexadecimal and uses that as the payload.

{"exact":"./mypayload.txt","isfile":true}

This example parsesGET / HTTP/1.0\r\nHost: 1.2.3.4\r\n\r\n as a string and uses that as the payload.

{"exact":"GET / HTTP/1.0\r\nHost: 1.2.3.4\r\n\r\n","isstring":true}
Length Object

The length object contains the following fields.

KeyTypeDefaultDescription
minushort0The minimum length.
maxushort0The maximum length.

If you are looking for full examples, please check outthis repository.

NOTE - The default config path is/etc/pcktbatch/conf.json. This may be changed via the-c and--cfg flags as explained under the Command Line Usage section below.

Credits

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp