如何让Netcat显示数据包的Payload [英] How to make Netcat display Payload of packet

查看:92
本文介绍了如何让Netcat显示数据包的Payload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否可行,但我想知道?

我正在使用 Scapy 和 Netcat 进行一些内部渗透测试,我创建了一个带有有效负载测试"的 TCP 数据包.我想使用以下示例代码将有效负载内容通过管道传输到 Netcat 的侦听端口:

test = IP(src="192.168.4.134")/TCP(dport=1234)/"testing"发送(测试)

但所有打印出来的是:

<预><代码>.发送 1 个数据包

这是 Scapy 在发送数据包后吐出的内容.我一直在试图弄清楚我需要在我的代码中使用什么来显示这一点.我知道 Netcat 使用了 stdin 和 stdout,但我还不知道如何用 Python 编写代码,我只是在练习!

有人可以帮忙吗?问候,

解决方案

TCP 是基于会话的.想要通信的机器必须首先彼此同步(设置会话).

这个过程就是所谓的 3 次握手,使用步骤:SYN、SYN-ACK、ACK.

1.) 机器 A ====SYN====>机器 B(机器 A,运行 scapy,尝试与 B 同步,运行 netcat)2.) 机器 B == SYN-ACK==>机器 A(机器 B 与机器 A 的 ACK 和 SYN)3.) 机器 A ====ACK====>机器 B(机器 A 确认来自机器 B 的 SYN-ACK)

机器现在有一个会话(连接)并且可以互相发送数据.

在侦听机器上运行 netcat 并尝试从 scapy 向它发送单个数据包失败,因为您的机器 (A) 无法与运行 netcat 的机器 (B) 同步.

IP 10.22.4.45.20 >10.1.2.3:1234:标志 [S],seq 0:7,获胜 8192,长度 7IP 10.1.2.3:1234 >10.22.4.45:20:标志 [S.],seq 2668993358,ack 1,win 14600,选项 [mss 1460],长度 0IP 10.22.4.45:20 >10.1.2.3:1234:标志 [R],seq 1,获胜 0,长度 0

如您所见,机器 B (netcat) 尝试与您的机器同步确认,但由于您只是向它发送了一个数据包并且没有监听返回的 SYN-ACK,您的机器会生成一个 RST(重置)) 并且尝试的连接在 3 次握手完成之前关闭.

有两种选择.要么使用无连接且不需要此连接设置的 UDP,要么执行完整的 TCP 握手.如果您选择后者,Scapy 有几种方法可以帮助您管理 TCP 会话的创建:http://trac.secdev.org/scapy/wiki/TCP

I don't know if this is possible but I am wondering?

I am doing some internal pentesting and using Scapy and Netcat, and I created a TCP packet with the payload "testing". I want to get the payload content piped into Netcat's listening port, using this example code:

test = IP(src="192.168.4.134")/TCP(dport=1234)/"testing"
send(test)

but all that ever prints is:

.
Sent 1 packets

Which is what Scapy spits out after its sent the packet. I've been trying to figure out what I need to use in my code to show this. I know Netcat used stdin and stdout, but I don't properly know how to code in Python yet, I'm just practising!

Can anyone help? Regards,

解决方案

TCP is session based. Machines that want to communicate, must first synchronize (setup a session) with one another.

This process is whats called a 3-way-handshake using the steps: SYN, SYN-ACK, ACK.

1.) Machine A ====SYN====> Machine B (Machines A, running scapy, tries to synch with B, running netcat)
2.) Machine B ==SYN-ACK==> Machine A (Machine B ACKs and SYNs with Machine A)
3.) Machine A ====ACK====> Machine B (Machine A ACKs the SYN-ACK from Machine B)

The machines now have a session (connection) and can send data to one another.

Running netcat on a listening machine and trying to send it a single packet from scapy fails because your machine (A) fails to sync with machine (B) running netcat.

IP 10.22.4.45.20 > 10.1.2.3:1234: Flags [S], seq 0:7, win 8192, length 7
IP 10.1.2.3:1234 > 10.22.4.45:20: Flags [S.], seq 2668993358, ack 1, win 14600, options [mss 1460], length 0
IP 10.22.4.45:20 > 10.1.2.3:1234: Flags [R], seq 1, win 0, length 0

As you can see, machine B (netcat) tries to syn-ack with your machine, but since you just sent it a single packet and aren't listening for the returning SYN-ACK, your machine generates a RST (Reset) and the attempted connection is shutdown before the 3-way-handshake was completed.

There are two options. Either use UDP which is connectionless and doesn't require this connection setup, or do a complete TCP handshake. Scapy has a few ways to help you manage the TCP session creation should you choose the latter: http://trac.secdev.org/scapy/wiki/TCP

这篇关于如何让Netcat显示数据包的Payload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆