XEP-0065: SOCKS5 Bytestreams

本文介绍SOCKS5 ByteStreams (S5B) 协议的工作原理,包括直接连接与中介连接两种场景下的协商流程、TCP及SOCKS5连接建立过程、数据交换方式等关键信息。
[b]SOCKS5 Bytestreams ("S5B")
out-of-band bytestream[/b]

[b]Requester[/b]
The entity that starts a bytestream negotiation with a Target. [7]
[b]Target[/b]
The entity with which the Requester is attempting to establish a bytestream.
[b]Proxy[/b]
An entity that is willing to be a middleman for the bytestream between the Requester and the Target.
[b]StreamHost[/b]
The system that the Target connects to and that is "hosting" the bytestream; the Streamhost can be either the Requester or a Proxy.
[b]StreamID[/b]
A relatively unique Stream ID for this connection; this is generated by the Requester for tracking purposes and MUST be less than 128 characters in length.

* "----" ... communications over XMPP
* "____" ... communications over TCP
* "\\\\" and "////" ... communications over SOCKS 5
* "====" ... communications over the bytestream itself


[b]Direct Connections[/b]
In this situation, the StreamHost is the Requester
Requester                           Target
| |
| Send S5B initiation request |
| -------------------------------> |
| |
| Open TCP socket |
| <_______________________________ |
| |
| Request SOCKS 5 connection |
| <\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
| |
| Acknowledge SOCKS 5 connection |
| ///////////////////////////////> |
| |
| Send S5B acceptance |
| <------------------------------- |
| |
| Exchange data over S5B |
| <==============================> |
|


1. Requester Initiates S5B Negotiation
<iq from='requester@example.com/foo'
id='hu3vax16'
to='target@example.org/bar'
type='set'>
<query xmlns='http://jabber.org/protocol/bytestreams'
sid='vxf9n471bn46'>
<streamhost
jid='requester@example.com/foo'
host='192.168.4.1'
port='5086'/>
</query>
</iq>


2. the Target attempts to open a standard TCP socket on the network address of the StreamHost/Requester.

3. Target Establishes SOCKS5 Connection with StreamHost
CMD = X'01'
ATYP = X'03'
DST.ADDR = SHA1 Hash of: (SID + Requester JID + Target JID)
DST.PORT = 0


4. StreamHost Acknowledges Connection
STATUS = X'00'


5. Target Notifies Requester of Bytestream
<iq from='target@example.org/bar'
id='hu3vax16'
to='requester@example.com/foo'
type='result'>
<query xmlns='http://jabber.org/protocol/bytestreams'
sid='vxf9n471bn46'>
<streamhost-used jid='requester@example.com/foo'/>
</query>
</iq>


[b]Mediated Connections[/b]
In this situation, the StreamHost is not the Requester but a Proxy, which means that the Requester needs to discover the network address of the StreamHost before sending the initiation request to the Target, needs to negotiate a connection with the StreamHost in the same way that the Target does, and needs to ask the StreamHost to activate the bytestream before it can be used.

1. Requester Initiates Negotiation
<iq from='requester@example.com/foo'
id='npq71g53'
to='target@example.org/bar'
type='set'>
<query xmlns='http://jabber.org/protocol/bytestreams'
sid='vxf9n471bn46'>
<streamhost
host='24.24.24.1'
jid='streamer.example.com'
port='7625'/>
</query>
</iq>


2. the Target attempts to open a standard TCP socket on the network address of the Proxy.

3. Target Establishes SOCKS5 Connection with StreamHost
CMD = X'01'
ATYP = X'03'
DST.ADDR = SHA1 Hash of: (SID + Requester JID + Target JID)
DST.PORT = 0


4. StreamHost Acknowledges Connection
STATUS = X'00'


5. Target Acknowledges Bytestream
<iq from='target@example.org/bar'
id='npq71g53'
to='requester@example.com/foo'
type='result'>
<query xmlns='http://jabber.org/protocol/bytestreams'
sid='vxf9n471bn46'>
<streamhost-used jid='streamer.example.com'/>
</query>
</iq>


6. Requester Establishes SOCKS5 Connection with StreamHost
CMD = X'01'
ATYP = X'03'
DST.ADDR = SHA1 Hash of: (SID + Requester JID + Target JID)
DST.PORT = 0


7. StreamHost Acknowledges Connection to Requester
STATUS = X'00'


8. Requester Requests Activation of Bytestream
<iq from='requester@example.com/foo'
id='oqx6t1c9'
to='streamer.example.com'
type='set'>
<query xmlns='http://jabber.org/protocol/bytestreams'
sid='vxf9n471bn46'>
<activate>target@example.org/bar</activate>
</query>
</iq>


9. Proxy Informs Requester of Activation
<iq from='streamer.example.com'
id='oqx6t1c9'
to='requester@example.com/foo'
type='result'/>
[root@yfw ~]# cd /www/wwwroot/szrengjing.com/kefu [root@yfw kefu]# ll total 96 -rw-r--r-- 1 www www 136 Nov 7 05:23 cookie_7e7nd77j1ft9lmlimsodkbu5f0.txt drwxr-xr-x 2 www www 4096 Nov 6 23:14 cookies drwxr-xr-x 2 www www 4096 Nov 6 20:21 css -rw-r--r-- 1 www www 861 Nov 6 18:51 error.log -rwxr-xr-x 1 www www 1229 Nov 6 23:43 http-bind.php drwxr-xr-x 2 www www 4096 Nov 6 17:38 images -rw-r--r-- 1 www www 1756 Nov 6 17:11 index.html drwxr-xr-x 2 www www 4096 Nov 6 17:12 js -rw-r--r-- 1 www www 1830 Nov 6 20:09 kefu_auth.php -rw-r--r-- 1 www www 424 Nov 6 19:26 kefu_history.php -rw-r--r-- 1 www www 3199 Nov 6 19:51 kefu_login.html -rw-r--r-- 1 www www 948 Nov 6 20:20 kefu_save_history.php -rw-r--r-- 1 www www 418 Nov 6 19:25 kefu_users.php -rw-r--r-- 1 www www 8456 Nov 6 20:18 kefu_workbench.html drwxr-xr-x 2 www www 4096 Nov 6 23:14 logs -rw-r--r-- 1 root root 20 Nov 7 10:45 phpinfo.php -rw-r--r-- 1 www www 3571 Nov 6 22:44 proxy.php drwxr-xr-x 2 www www 4096 Nov 6 17:08 sound drwxr-xr-x 2 www www 4096 Nov 6 17:38 WEB-INF -rwxr-xr-x 1 www www 2405 Nov 7 03:26 widget.js -rw-r--r-- 1 root root 1038 Nov 7 10:42 xmpp_test.log -rwxr-xr-x 1 www www 3323 Nov 6 19:09 xmpp_test.sh [root@yfw kefu]# 根据测文件 从新创建用户 来进行测试 #!/bin/bash set -e # 配置参数 OPENFIRE_URL="https://yfw.szrengjing.com:7443/http-bind/" USER="test" PASSWORD="test123" DOMAIN="yfw.szrengjing.com" COOKIE_FILE="cookies.txt" INIT_RID=100000 rm -f $COOKIE_FILE xmpp_test.log echo "===== 开始XMPP自动化测试 =====" | tee -a xmpp_test.log # 步骤1:建立会话 echo -e "\n[步骤1/4] 建立会话..." | tee -a xmpp_test.log RID=$((INIT_RID + 1)) SESSION_RESPONSE=$(curl -k -s -c $COOKIE_FILE -X POST $OPENFIRE_URL \ -H "Content-Type: text/xml; charset=utf-8" \ -d '<?xml version="1.0"?><body rid="'$RID'" xmlns="http://jabber.org/protocol/httpbind" to="'$DOMAIN'" xml:lang="en" wait="60" hold="1" content="text/xml; charset=utf-8" ver="1.6" xmpp:version="1.0" xmlns:xmpp="urn:xmpp:xbosh"/>' ) echo "会话响应: $SESSION_RESPONSE" | tee -a xmpp_test.log SID=$(echo "$SESSION_RESPONSE" | xmllint --xpath "string(//@sid)" - 2>/dev/null) if [ -z "$SID" ]; then echo "错误:无法提取sid" | tee -a xmpp_test.log exit 1 fi echo "获取到sid: $SID" | tee -a xmpp_test.log # 步骤2:认证 echo -e "\n[步骤2/4] 执行认证..." | tee -a xmpp_test.log RID=$((RID + 1)) PLAIN_AUTH=$(echo -ne "\0$USER\0$PASSWORD" | base64) AUTH_RESPONSE=$(curl -k -s -b $COOKIE_FILE -X POST $OPENFIRE_URL \ -H "Content-Type: text/xml; charset=utf-8" \ -d '<?xml version="1.0"?><body rid="'$RID'" sid="'$SID'" xmlns="http://jabber.org/protocol/httpbind"><auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">'$PLAIN_AUTH'</auth></body>' ) echo "认证响应: $AUTH_RESPONSE" | tee -a xmpp_test.log if ! echo "$AUTH_RESPONSE" | grep -q "<success"; then echo "认证失败" | tee -a xmpp_test.log exit 1 fi echo "认证成功" | tee -a xmpp_test.log # 步骤3:绑定资源(修复命名空间解析问题) echo -e "\n[步骤3/4] 绑定资源..." | tee -a xmpp_test.log RID=$((RID + 1)) BIND_RESPONSE=$(curl -k -s -b $COOKIE_FILE -X POST $OPENFIRE_URL \ -H "Content-Type: text/xml; charset=utf-8" \ -d '<?xml version="1.0"?><body rid="'$RID'" sid="'$SID'" xmlns="http://jabber.org/protocol/httpbind"><iq type="set" id="bind1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>webclient</resource></bind></iq></body>' ) echo "绑定响应: $BIND_RESPONSE" | tee -a xmpp_test.log # 忽略命名空间,直接提取jid文本(兼容解析问题) JID=$(echo "$BIND_RESPONSE" | grep -oP '<jid>\K[^<]+') if [ -z "$JID" ]; then echo "错误:资源绑定失败" | tee -a xmpp_test.log exit 1 fi echo "资源绑定成功,JID: $JID" | tee -a xmpp_test.log # 步骤4:自动发送消息(脚本内执行,无超时问题) echo -e "\n[步骤4/4] 发送测试消息..." | tee -a xmpp_test.log RID=$((RID + 1)) MESSAGE_RESPONSE=$(curl -k -s -b $COOKIE_FILE -X POST $OPENFIRE_URL \ -H "Content-Type: text/xml; charset=utf-8" \ -d '<?xml version="1.0"?><body rid="'$RID'" sid="'$SID'" xmlns="http://jabber.org/protocol/httpbind"><message from="'$JID'" to="admin@'$DOMAIN'" type="chat"><body>自动化测试消息</body></message></body>' ) echo "消息发送响应: $MESSAGE_RESPONSE" | tee -a xmpp_test.log if echo "$MESSAGE_RESPONSE" | grep -q "<body"; then echo "消息发送成功" | tee -a xmpp_test.log else echo "消息发送失败" | tee -a xmpp_test.log fi echo -e "\n===== 测试完成 =====" | tee -a xmpp_test.log
最新发布
11-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值