Skip to main content

Send the first TCP segment last for large payloads

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tcp_send_first_segment_last-0.0.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tcp_send_first_segment_last-0.0.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file tcp_send_first_segment_last-0.0.5.tar.gz.

File metadata

File hashes

Hashes for tcp_send_first_segment_last-0.0.5.tar.gz
Algorithm Hash digest
SHA256 ef90c518cf37cace2ffdc4b1005d552f13c0c22ec8a90da3c95d5a1555fbc2c0
MD5 43ceee73386222dbd658e880e99b9c16
BLAKE2b-256 11282201e9ac1c0e1e9e2250790bdf96ba5d215940ecad32eece3304f825b842

See more details on using hashes here.

File details

Details for the file tcp_send_first_segment_last-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for tcp_send_first_segment_last-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 48aa47197d6259c247ed88ff0cdb83363ebcde808954c3c8e7ed43af1ef0b927
MD5 6c3254054b325b5baf08b85d37586b44
BLAKE2b-256 38991ab9d7a6ed09412147cfb13b34dc134d091fcfb33c6d63c85fc4878cd84f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page