gpt4 book ai didi

java - python和java之间的socket响应不同

转载 作者:行者123 更新时间:2023-12-02 09:27:38 25 4
gpt4 key购买 nike

我正在发送一个SMB数据包,不同语言的响应有所不同,但只有一个字节的差异,它与python添加了0D

00 00 00 55 FF 53 4D 42 72 00 00 00 00 98 01 28 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2F 4B 00 00 C5 5E 11 03 00 03 0D 0A 00 01 00 04 11 00 00 00 00 01 00 00 00 00 00 FD E3 00 80 12 E5 E0 59 36 7A D5 01 88 FF 00 10 00 B0 44 B3 6C 20 08 11 44 A9 84 31 87 23 FC C7 45

Python:

buffersize = 1024
timeout = 5.0
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(timeout)
client.connect((ip, port))
client.send(negotiate_proto_request())
tcp_response = client.recv(buffersize)

Java:

Socket s = new Socket(ip, port);
OutputStream out = s.getOutputStream();
out.write(negotiate_proto_request().getBytes());
out.flush();

InputStream input = s.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
tcp_response = "";
int i = 0;
tcp_response += (char) reader.read();
tcp_response += (char) reader.read();
tcp_response += (char) reader.read();
int len = reader.read();
tcp_response += (char) len;
while (i < len) {
tcp_response += (char) reader.read();
i++;
}
out.close();
s.close();

最佳答案

不完全是答案...手动解析了 Python 响应后,某些字段值看起来有点古怪。 PDU 的逻辑末尾后面还有一个字节。我的结论是额外的字节 0d 被错误地插入,但我不能说出原因。

根据响应格式,这是 SMB,而不是 CIFS。

SMB specification

Python 响应

00 00 00 55 

header

FF 53 4D 42 protocol identifier
72 negprot
00 00 00
00 status
98 flags (response + others)
01 28 flags2
00 00 pid high
00 00
00 00 00 00
00 00 security features
00 00 rsvd
00 00 tid
2F 4B pid low
00 00 uid
C5 5E mid

params

11 word count (17)
03 00 dialect index 3
03 security mode
0D 0A max mpx (2573 ?!)
00 01 max vcs (256 ?!)
00 04 11 00 max buff size (1,115,136‬ ?!)
00 00 00 01 max raw size (1 ?!)
00 00 00 00 session key
00 FD E3 00 capabilities
80 12 E5 E0
59 36 7A D5 server time
01 88 server tz (34817 ?!)
FF challenge len (255 ?!)

data
00
10 byte count
00 B0 44
B3 6C 20 08
11 44 A9 84
31 87 23 FC
C7 server guid

45 fell off the end
or maybe I have forgotten
the SMB alignment rules

一些数字字段的数字完全不可信;用“?!”标记它们。

Java 响应

 00 00 00 55

header (same as before)

FF 53 4D 42
72 00 00 00
00 98 01 28
00 00 00 00
00 00 00 00
00 00 00 00
00 00 2F 4B
00 00 C5 5E

params

11 word count (17)
03 00 dialect index 3
03 security mode
0A 00 max mpx (10)
01 00 max vcs (1)
04 11 00 00 max buffer (4356)
00 00 01 00 max raw (64k)
00 00 00 00 session key
FD E3 00 80 capabilities
12 E5 E0 59 server time
36 7A D5 01
88 FF server tz (-120)
00 challenge len

data
10
00 byte count (16)
B0 44 B3
6C 20 08 11
44 A9 84 31
87 23 FC C7
45

这些字段在 Java 版本中更有意义。

所以这是我尝试实际回答隐含问题 - Python 版本是错误的;由于某种原因,它决定插入一个额外的字节。额外的字节是 0D,可以解释为 ASCII CR,并且位于恰好具有值 0A 的字节之前,该值可以(错误)解释为 ASCII LF。因此,我们可能会猜测这是一些错误的文本转换例程,它吞噬了非文本数据。

==尾声==

呃,有一个更简单的方法来判断哪个是错误的。 SMB 的长度从消息的第一个字开始应该是 0x55 (85)。 Java版本有85字节,Python版本有86字节。量子ED。

关于java - python和java之间的socket响应不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58227561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com