0x01 前言
在红队HW中通过前期的打点获得shell后通常下一步就是对内网进行横向,获得shell进想要行横向的前提是我们必须有代理可以访问内网中的资产,这时候我们就需要通过拿到shell的那台机器权限,在此台机上传代理工具进行配置搭建内网代理,目的达到内网出网的效果,使我们能够进行下一步的内网横向渗透。在hw中经常用到的代理工具有很多,根据不同之需和个人不同的使用习惯选择不同工具进行使用,本文主要对NPS这款代理工具进行介绍。
0x02 简介nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。目前支持tcp、udp流量转发,可支持任何tcp、udp上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还支持内网http代理、内网socks5代理、p2p等,并带有功能强大的web管理端。
工具获取:https://github.com/ehang-io/nps
特点:
支持多种协议,兼容几乎所有常用协议,例如tcp,udp,http(s),socks5,p2p,http代理…
全面的平台兼容性(Linux,Windows,MacOS,Synology等),仅支持将安装作为系统服务进行。
全面控制,允许客户端和服务器控制。
Https集成,支持将后端代理和Web服务转换为https,并支持多个证书。
只需在Web ui上进行简单配置即可完成大多数要求。
完整的信息显示,例如流量,系统信息,实时带宽,客户端版本等。
强大的扩展功能,一切可用(缓存,压缩,加密,流量限制,带宽限制,端口重用等)
域名解析具有诸如自定义标题,404页面配置,主机修改,站点保护,URL路由和全景解析之类的功能。
服务器上的多用户和用户注册支持。
0x03 实验环境NPS代理需要借助VPS进行中转,首先我们要根据VPS的系统和内网客户端系统下载对应的nps程序。这里我使用腾讯云的VPS作为服务端,系统为Ubuntu 18.04,内网分别采用VMware中centOS 7和Windows 7进行模拟,将内网代理到本地。
环境模拟1-客户端配置文件模式环境拓扑:
1.服务端部署
根据vps的系统下载服务端程序并上传至vps,本文中使用的腾讯云Ubuntu18.04作为vps下载使用了安装包linux_amd64_server.tar.gz
解压文件包结构如下:
linux_amd64_server/
– conf ##配置文件目录
– web ##web文件目录
– nps ##nps运行文件
进入conf目录,可编辑nps.conf配置文件对部分选项进行配置,默认运行不需要进行任何配置即可运行
默认配置运行nps服务端启动会占用80,8080,8024端口,可根据需求对配置进行修改。
appname = nps
#Boot mode(dev|pro)
#启动模式
runmode = dev
#HTTP(S) proxy port, no startup if empty
#HTTP(S)代理端口,如果为空则不启动
http_proxy_ip=0.0.0.0
http_proxy_port=8081 #http监听端口,默认80
https_proxy_port=443
https_just_proxy=true
#default https certificate setting
#默认HTTPS证书设置
https_default_cert_file=conf/server.pem
https_default_key_file=conf/server.key
##bridge
##桥接
bridge_type=tcp
bridge_port=8024 ##客户端与服务端连接端口
bridge_ip=0.0.0.0
# Public password, which clients can use to connect to the server
# 公共密码,客户端可以使用它连接到服务器
# After the connection, the server will be able to open relevant ports and parse related domain names according to its own configuration file.
# 连接完成后,服务器就可以打开相关端口,根据自己的配置文件解析相关域名。
public_vkey=123
#Traffic data persistence interval(minute)
#流量数据持续时间间隔(分钟)
#Ignorance means no persistence
#flow_store_interval=1
# log level LevelEmergency->0 LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
# 日志等级设置
log_level=7
#log_path=nps.log
#Whether to restrict IP access, true or false or ignore
#是否限制IP访问,true、false或ignore
#ip_limit=true
#p2p代理
#p2p_ip=127.0.0.1
#p2p_port=6000
#web
web_host= ##web管理端登录地址URL
web_username=admin ##web管理端登录名
web_password=123 ##web管理端登录密码(注:正式环境建议更改)
web_port = 8080 ##web管理端访问端口
web_ip=0.0.0.0 ##web管理端登录地址默认0.0.0.0不需要修改
web_base_url= ##管理端web路径,默认不需要指定
web_open_ssl=false #管理端是否开启ssl
web_cert_file=conf/server.pem
web_key_file=conf/server.key
# if web under proxy use sub path. like need this.
#web_base_url=/nps
#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
#Remove comments if needed
#auth_key=test
auth_crypt_key =1234567812345678
#allow_ports=9001-9009,10001,11000-12000
#Web management multi-user login
#Web管理多用户登录
allow_user_login=false
allow_user_register=false
allow_user_change_username=false
#extension
allow_flow_limit=false
allow_rate_limit=false
allow_tunnel_num_limit=false
allow_local_proxy=false
allow_connection_num_limit=false
allow_multi_ip=false
system_info_display=false
#cache
http_cache=false
http_cache_length=100
#get origin ip
http_add_origin_header=false
#pprof debug options
#pprof_ip=0.0.0.0
#pprof_port=9999
#client disconnect timeout
#客户端断开连接超时
disconnect_timeout=60
运行服务端
./nps