Skip to main content

tcp-send-first-segment-last

Purpose

Not all applications receive data off the network correctly, and they can miss key chunks of data even when they don't mean to. As an example, Python's socket.recv needs to be called repeatedly until all data has been received. But, if the receiving application doesn't properly loop, then it may miss key data later in the buffer.

This library ensures that all data will be in the receiving buffer before the receiving application begins reading the data. It does this by sending the TCP segments out of order; and in particular, it does this by sending the first TCP segment last.

By sending the first TCP segment last, all the later segments will already be waiting in the receiving buffer by the time that the first segment arrives. Then, if the receiving application only calls Python's socket.recv function once, it will still read all of the intended data.

I first encountered this issue while working on the EXP-301 course from OffSec (a course that focuses on exploiting applications via buffer overflows). And I created this library to help solve labs and challenges from this course.

Usage

PyPi project: https://pypi.org/project/tcp-send-first-segment-last/

$ pip install tcp-send-first-segment-last
from tcp_send_first_segment_last.send import send_first_segment_last


payload = b"A" * 5000

send_first_segment_last("127.0.0.1", 4444, payload)

Current Implementation

  • The current implementation waits 5 seconds before sending the final (first) segment, and waits another 5 seconds before closing the connection
  • Payloads are currently broken up into 1000 byte chunks

Known Drawbacks

  • Only supports IP addresses, does not support hostnames
  • Only runs on Linux/Unix
  • Modifies 'iptables' to disable the default RST response from the OS when receiving a response from the target application
  • Chunk size is not currently modifiable
  • Wait time before sending the first packet is not modifiable
  • Must be root to run

Metadata

Release files for tcp-send-first-segment-last 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tcp-send-first-segment-last 0.0.5
File Size Uploaded
tcp_send_first_segment_last-0.0.5.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tcp-send-first-segment-last 0.0.5
File Interpreter ABI Platform
tcp_send_first_segment_last-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / tcp_send_first_segment_last-0.0.5.tar.gz

Download URL tcp_send_first_segment_last-0.0.5.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ef90c518cf37cace2ffdc4b1005d552f13c0c22ec8a90da3c95d5a1555fbc2c0
BLAKE2b-256 checksum
How to use checksums
11282201e9ac1c0e1e9e2250790bdf96ba5d215940ecad32eece3304f825b842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release files / tcp_send_first_segment_last-0.0.5-py3-none-any.whl

Download URL tcp_send_first_segment_last-0.0.5-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48aa47197d6259c247ed88ff0cdb83363ebcde808954c3c8e7ed43af1ef0b927
BLAKE2b-256 checksum
How to use checksums
38991ab9d7a6ed09412147cfb13b34dc134d091fcfb33c6d63c85fc4878cd84f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page