如何发送自定义的“TCP”数据包,无需sudo权限和三次握手。

huangapple go评论86阅读模式
英文:

How to send a custom 'TCP' packet, without sudo - without three-way handshake

问题

我正在尝试发送一个不使用原始套接字、不经过三次握手并且不使用sudo的TCP(以及后续的ICMP)数据包。我已经尝试了Python的scapy模块和socket模块的各种方法,但都没有成功。

我知道没有经过三次握手,TCP实际上就是UDP,但我正在测试从网络中窃取数据的各种方法,这可能不会被检测到。

以下是一个可用的UDP版本,我需要一个可用的ICMP和TCP版本,它们不使用原始套接字,因此不需要管理员/根权限。

首选的解决方案是GO或Python,最理想的情况是在MacOS、Linux和(主要是)Windows上运行。

UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Data to exfiltrate"

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

英文:

I am trying to send a TCP (and later an ICMP) packet that does not use raw sockets, does not go through the three-way handshake, and does not use sudo. I have tried various methods in python's scapy module, and in python's socket module, without success.

I understand that without the three-way handshake, TCP isn't necessarily TCP - it is basically UDP, but I am testing various ways to exfiltrate data from a network, that may go undetected.

Basically this is the working UDP version, I need working ICMP and TCP versions that do not use a raw socket, and therefore do not require admin/root privileges.

A solution in GO or Python is preferable, ideally I need to run on MacOS, Linux, and (mainly) Windows.

UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Data to exfiltrate"

sock = socket.socket(socket.AF_INET, # Internet
             socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))

答案1

得分: 4

简而言之,你无法在Linux下这样做。

你试图发送一个数据包,而不遵守TCP的状态机。内核不会允许你这样做,除非你使用数据包套接字(直接使用或通过诸如pcapscapy的库),而原始套接字需要CAP_NET_RAW权限,通常只授予超级用户。

英文:

In short — you cannot, at least not under Linux.

You are trying to send a packet without obeying TCP's state machine. The kernel will not allow you to do that without using a packet socket (either directly or through a library such as pcap or scapy), and raw sockets require the CAP_NET_RAW capability, which is normally only granted to the superuser.

答案2

得分: 0

TCP是一种面向连接的协议。为了建立TCP连接,你必须执行三次握手。在连接建立之前,你的操作系统中的TCP模块不会发送数据,而且任何接收到针对不存在连接的TCP段的设备都会忽略它。

没有连接的TCP不是TCP,但也不是UDP。TCP和UDP具有不同的协议头部。你会注意到TCP头部比UDP头部有更多的字段,并且其中许多字段将由握手过程中的信息填充。

RFC 793,传输控制协议

> TCP头部格式
>
>
> 0 1 2 3
> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 源端口 | 目的端口 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 序列号 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 确认号 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 数据 | |U|A|P|R|S|F| |
> | 偏移 | 保留 |R|C|S|S|Y|I| 窗口 |
> | | |G|K|H|T|N|N| |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 校验和 | 紧急指针 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 选项 | 填充 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | 数据 |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>
> TCP头部格式

RFC 768,用户数据报协议

> 格式
>
>
> 0 7 8 15 16 23 24 31
> +--------+--------+--------+--------+
> | 源端口 | 目的端口 |
> | 端口 | 端口 |
> +--------+--------+--------+--------+
> | | |
> | 长度 | 校验和 |
> +--------+--------+--------+--------+
> |
> | 数据字节 ...
> +---------------- ...
>
> 用户数据报头部格式

英文:

TCP is a connection-oriented protocol. In order to establish a TCP connection, you must perform a three-way handshake. The TCP module in you OS will not send data until a connection is established, and any device receiving a TCP segment for a non-existent connection will ignore it.

TCP without the connection is not TCP, but neither is it UDP. TCP and UDP have different protocol headers. You will notice that the TCP header has more fields than the UDP header, and many of those fields will be populated by information from the handshake.

RFC 793, Transmission Control Protocol:

> TCP Header Format
>
>
> 0 1 2 3
> 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Source Port | Destination Port |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Sequence Number |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Acknowledgment Number |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Data | |U|A|P|R|S|F| |
> | Offset| Reserved |R|C|S|S|Y|I| Window |
> | | |G|K|H|T|N|N| |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Checksum | Urgent Pointer |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | Options | Padding |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> | data |
> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
>
> TCP Header Format

RFC 768, User Datagram Protocol:

> Format
>
>
> 0 7 8 15 16 23 24 31
> +--------+--------+--------+--------+
> | Source | Destination |
> | Port | Port |
> +--------+--------+--------+--------+
> | | |
> | Length | Checksum |
> +--------+--------+--------+--------+
> |
> | data octets ...
> +---------------- ...
>
> User Datagram Header Format

huangapple
  • 本文由 发表于 2017年7月11日 22:07:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/45036882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定