Last night at 10:30 p.m., I just wanted to quickly lock down port 22 on an old business server, switch it to pure SSH key login, and go to bed.
Who knew that one command opening /var/log/auth.log would completely kill any chance of sleep that night.
Checked the logs before bed and my blood ran cold
The terminal quietly scrolled a string of shocking records: from 01:11 to 09:26 that day, the root account on this machine had been successfully logged into with passwords 75 times, from 4 unfamiliar overseas IPs. Then I checked /tmp, and the temp directory still had leftover .sql database query scripts and brute-force tools that hadn't been cleaned up.
Even more dramatic was what showed up on another monitor.
Just as I was about to investigate how much data had been taken from this machine, I switched to the admin dashboard of another completely independent system I had on hand to glance at monitoring—that system had previously set up login honeypots, fake response decoys, and device/request fingerprint blocking to stop spam.
The log page immediately lit up with a bunch of glaring red labels: Honeypot · Disguised 403, Blocked, Honeypot · Disguised 429.
I checked the timeline and source IPs carefully and instantly woke up: from around 4 to 5 a.m., someone kept rotating IPv6 and overseas nodes to throw in time-based blind SQL injection probes like zz' and pg_sleep(5)[email protected], and stepped right into honeypot beacons (non-browser client intercepted by honeypot), eating several fake 403s. By 09:31:11, a disturbingly familiar IP (45.196.236.41) also showed up on the blocklist—it was one of the main attack sources that had logged into the root account of my other business server and stolen the cloud account key the night before!
And even earlier, at 2:30 a.m., the attacker had already used the admin's real name, backend account, and database username from the business DB's user table to try a round of passwords across systems; by 10:30 the next morning, these scripts were still rotating curl and spoofing Firefox 158, using [email protected] to probe their way in.
Two systems that had nothing to do with each other had a terrifying rendezvous in the red alerts that night: the attacker had already breached the old business server's entry point and, holding the identity and credential puzzle pieces they'd pulled out, was hunting across sites along the developer's public footprint.
Reconstructing the attacker's playbook: no god-tier 0-day, just the keys we handed over ourselves
Too wired to sleep, I lined up Nginx access logs, filesystem atime timestamps, and cloud ActionTrail audit logs line by line overnight. Once the whole attack chain was clear, it felt both terrifying and absurd—they hadn't used any fancy 0-day; almost every step followed clues we'd left behind ourselves:
Act one: pulled the main domain from personal homepage metadata
Back when I was messing with a tech showcase page and GitHub profile, for verification and SEO I'd cross-linked sameAs, canonical, and contact email in page metadata. To normal visitors it's a personal business card, but once automated recon scripts get hold of it, toss the developer identifiers, public email, and public Certificate Transparency logs (CT Log) into a mapping engine, and in a few minutes it can stitch your active main domain and full set of business subdomains into one map.
Act two: the open-source scaffold turned into a pentest signpost
I'd open-sourced a stripped-down scaffold repo for convenience. To make local debugging easier, the gateway config had exposure.include: gateway,health,info by default, and the Nginx example config had a rule specifically to "block /gateway/actuator". To a scanning script, that's basically written in black and white: this microservice stack has Spring Cloud Gateway dynamic routing endpoints enabled by default—the only question is whether the outer Nginx blocks them.
Act three: one missed config on the production gateway, into the internal network in seconds (CVE-2022-22947)
Nginx access logs recorded the exact second of the break-in: just after 12:40 a.m., once they'd locked onto the main domain, they first tried a few client activation endpoints that appeared in public code, all 404. Then, almost without pausing, they turned straight to /gateway/actuator/gateway/routes.
As luck would have it, the production gateway had missed that path block due to historical config changes. One hit, and they used SpEL expression injection to forcibly write a temporary dynamic route, exposing the internal config query endpoint within seconds. A string of HTTP 200s later, they'd cleaned out third-party keys in the system config table, the backend admin account list, and even host clues.
Act four: the most terrifying countdown—the 1:26 a.m. cloud asset inventory
If the server password breach was just one machine falling, what really made my heart skip a beat was the next thing I opened: the cloud platform's ActionTrail audit.
Years ago, to make uploading a few product images easier for the middle platform, someone had shoved a cloud vendor root account AccessKey directly into the database config table. The audit records stated it plainly: at 01:26 a.m. and 05:36 a.m., two overseas IPs had already used this highest-privilege Root Key to hit read-only APIs more than 70 times at high frequency—ECS, RDS, OSS, SLS logs, Function Compute, Container Service under the account were almost all called out one by one.
Thankfully, after checking every write operation event in the last 48 hours one by one: they were still stuck at the "inventory cloud assets" stage and hadn't yet created RAM backdoors, dropped databases, or changed DNS records. If I'd found this half a day later, the whole cloud account probably wouldn't have my name on it anymore.
15-hour full-stack counterstrike: from "cut the water and power" to "origin completely hidden"
With all entry points and exposure surfaces clear, I just went with the highest alert assumption—"assume all old credentials are compromised"—and did a full bomb-defusal pass from the cloud account down to the underlying code:
First, kill the Root lifeline and reset every credential
First thing, I went into the cloud console and disabled all root account AccessKeys (actively called the API to retest—all returned 403 AccessKeyDisabled). Then I created a dedicated RAM sub-account with no console login permission, narrowed policy permissions to read/write only a specified bucket and upload certificates, and tied it hard to an acs:SourceIp condition—even if the key leaks again, requests from anywhere other than the production server's fixed egress IP get rejected outright.
On the host side, I wiped the leftover scripts in /tmp, 36 historical .bak files, and old .env files; disabled SSH password login; regenerated a fresh Ed25519 login keypair and server Host Key; tightened the security group's port 22 to only whitelisted admin IPs. I regenerated and replaced MySQL in local Docker (listening only on 127.0.0.1:3306), Redis (127.0.0.1:6379), the JWT signing key, and TLS private keys for 4 sites, and cleared all historical Redis sessions while I was at it.
Weld the breached door shut at all three layers
- Config layer: hardcode
management.endpoint.gateway.enabled: falseacross all environments, keep onlyhealthinexposure.include, and hide details. - JVM gateway layer: add a global request protection Filter to intercept all
/actuatorrequests except local loopback health, close off bypass variants with matrix parameters;, path traversal.., or double URL encoding, and unconditionally strip externally spoofed internal user headers at the gateway entrance. - Nginx entry layer: add a regex
"(^|/)actuator(/|;|$)"catch-all cutoff, and also block scan probe paths like.env,.git,.sql,.bak,.phpand abandoned old callbacks.
Full-repo minesweep; just cut the high-risk modules that weren't strictly needed
While I was at it, I ran a stricter security baseline across several backend modules and the gateway: changed all the payment and callback signature-skip and empty-key allow settings left over from debugging into Fail-Closed strict validation; added SSRF protection and streaming size limits to remote image sync; expanded full-chain access logs to precise User-Agent and passive request-header fingerprint level, and folded the exception stacks that were flooding the logs across multiple lines online into single readable records.
The most dramatic cut was the AI Agent module built into the system. During static audit, we found another issue in its read-only SQL guard: validation stripped comments first, but execution passed the original string to the database, so MySQL executable comments (/*!50000 ... */) could bypass keyword blocking. Fixed it on the spot, but on second thought, the business backend doesn't really need an Agent with query and ops tools day to day—so I ripped it out root and branch from the backend, gateway, four frontends, and mobile, stopped the service, and cleared the directory. One less high-privilege exposure surface is worth more than ten protection rules stacked in front of it.
The morning counterattack, and finally "hiding the origin in the edge nodes"
After fiddling until past 2 a.m., I barely slept a few hours. At 07:13 the next morning, when I checked the logs, the dramatic scene played out again—that overseas attack IP from last night really did come back for another round, probing /gateway/actuator/gateway/routes 28 times in a row. This time they all got a zero-byte 444 at the first Nginx layer and were cut off, never even touching the gateway. By 10:23 a.m., the bypass system's honeypot was still holding requests rotating between curl and Firefox 158 safely outside at 429.
But as long as the origin's real IP is still exposed on the public internet, they can just switch to a pool of domestic proxies and hit the machine's front door again. So in the morning I went all in and moved the whole site behind Alibaba Cloud ESA (Basic), plus cloud DNS and ECS security groups, for a thorough "origin invisibility" setup:
- Lock the security group down to edge back-to-origin ranges: enabled origin protection in ESA, got 146 official back-to-origin IPv4 ranges, put them into an ECS security group prefix list, allowed only those back-to-origin IPs to access
443, and completely closed public access to port80. Now scanning the origin IP directly just gets packets dropped at the network layer. - 48-character secret header + edge WAF: ESA injects a 48-character random
X-Origin-Authvalidation header on all back-to-origin requests; origin Nginx returns444if it doesn't validate. At the edge, enabled managed WAF rules (27 basic protection rules), common scan probe blocking (.env/.git/wp-login/actuator), edge blocking for traffic outside mainland China (exempting only signed payment callback paths), and CC rate limiting on dynamic APIs. - Reduce search index exposure: added
X-Robots-Tag: noindex, nofollow, noarchiveand full-pathDisallow: /inrobots.txtfor business and admin domains.
In the afternoon I tested /wp-login.php, /.env, and /actuator/health with curl; they all returned 403 right at the edge. Normal business APIs and admin backend all passed, and the server logs finally went completely quiet.
After the terrifying 15 hours, three iron rules I'm keeping for myself
- Never put a root account AK/SK in a business config table: even if it's just for image uploads, create a separate least-privilege RAM sub-account and bind it to source IPs; otherwise one hole on the business side and your entire cloud estate gets wiped.
- Never rely on Nginx alone to block Spring Actuator: miss a semicolon matrix parameter or route prefix and CVE-2022-22947 will skewer the whole stack in one go; the safest approach is always to hard-disable it at both the config layer and a JVM Filter.
- Put more honeypot alerts in bypass systems, and always hide the production origin behind an edge back-to-origin whitelist: often, just as the main business database is being probed, a "honeypot 403 / 429" on a bypass system can sound the life-saving alarm early. Locking the origin security group to only accept edge back-to-origin IPs is what really lets you sleep at night.
本来昨晚十点半,我只是想顺手把一台老业务服务器的 22 端口收紧一下,改完纯 SSH 密钥登录就关电脑睡觉。
谁能想到,一条命令翻开 /var/log/auth.log 之后,这一夜彻底没法睡了。
睡前顺手查了眼日志,后背瞬间凉透
终端屏幕上静静滚着一串触目惊心的纪录:当天凌晨 01:11 到早上 09:26,这台机器的 root 账号竟然被人用密码硬生生成功登录了 75 次,来源一共 4 个陌生海外 IP。紧接着再查 /tmp,临时目录里甚至还躺着没擦干净的 .sql 查库脚本和暴破工具。
更戏剧性的一幕,紧跟着出现在另一块屏幕上。
就在我准备追查这台机器到底被摸走了多少数据时,顺手切到了手头另一套完全独立的系统后台看了一眼监控——那套系统之前为了防刷,自己埋了登录蜜罐、假响应伪装和设备/请求指纹拦截。
结果日志页上直接亮起一片刺眼的红标:蜜罐·伪装 403、被拦截、蜜罐·伪装 429。
仔细一核对时间线和来源 IP,整个人瞬间清醒了:凌晨四点多到五点多,有人一路换着 IPv6 和海外节点扔进来 zz' and pg_sleep(5)[email protected] 这种时间盲注探针,结果一脚踩进蜜罐信标(non-browser client intercepted by honeypot)连吃好几个伪装 403;到了早上 09:31:11,一个熟悉到令人发毛的 IP(45.196.236.41)也赫然出现在拦截清单上——它正是昨晚登录我另一台业务服务器 root 账号、并且盗用云账号 Key 的主力攻击源之一!
而在那之前的深夜两点半,对方甚至已经拿着业务库 user 表里管理员的真实姓名、后台账号和数据库用户名,跨着系统挨个试过一轮密码了;直到次日上午十点半,这批脚本还在切着 curl 和伪装 Firefox 158,拿着 [email protected] 往里探路。
两台原本毫不相干的系统,在凌晨的红灯里完成了惊魂汇合: 攻击者早已打穿了老业务服务器的入口,正揣着拖出来的身份与凭据拼图,沿着开发者的公开足迹一路跨站追杀。
还原对方剧本:没有神级 0-day,全是我们自己递过去的钥匙
顾不上困,连夜把 Nginx 访问日志、文件系统的 atime 时间戳和云平台操作审计(ActionTrail)逐行对齐。看清整条攻击链后,只觉得又惊险又荒诞——对方根本没动用什么高深 0-day,每一步几乎都在照着我们平时自己留下的线索按图索骥:
第一幕:顺着个人主页元数据摸出主域名
早些年折腾技术展示页和 GitHub 主页时,为了做关联验证和 SEO,页面元数据里互相写过 sameAs、canonical 和联系邮箱。对普通访客来说这是个人名片,可一旦被自动化侦察脚本盯上,把开发者标识、公开邮箱和全网公开的证书透明度日志(CT Log)扔进测绘引擎一交叉,几分钟就能把正在服役的主域名和全套业务子域串成一张网。
第二幕:开源脚手架变成了“渗透路标”
以前图省事开源过一个精简版脚手架仓库。为了方便本地调试,网关配置里默认写着 exposure.include: gateway,health,info,Nginx 示例配置里又专门写了一条“挡住 /gateway/actuator”。对于盯上来的脚本而言,这相当于白纸黑字写着:这套微服务默认开着 Spring Cloud Gateway 动态路由端点,全看外层 Nginx 挡没挡住。
第三幕:生产网关一处漏配,几秒钟穿进内网(CVE-2022-22947)
Nginx 访问日志精确到秒记录了当时的突破瞬间:凌晨零点四十分刚过,对方锁定主域名后,先试了公开代码里出现过的几个客户端激活接口,全部吃了 404;紧接着几乎没停顿,调转枪口直扑 /gateway/actuator/gateway/routes。
好巧不巧,线上生产网关偏偏因为历史配置调整漏了这一层的路径拦截。对方一发命中,利用 SpEL 表达式注入强行写入临时动态路由,几秒钟内就把内部配置查询接口暴露了出来,连续一串 HTTP 200 把系统配置表里的第三方密钥、后台账号列表甚至宿主机线索顺了个干净。
第四幕:最惊魂的倒计时——凌晨 01:26 的云资产大清点
如果说服务器密码失守还只是单机沦陷,真正让我当场心跳漏半拍的,是紧接着打开云平台 ActionTrail 操作审计 看到的画面。
当年中台为了给商品上传几张图图省事,数据库配置表里居然直接塞了一把云厂商主账号(Root)的 AccessKey。审计记录黑纸白字记着:凌晨 01:26 和早上 05:36,两个海外 IP 已经拿着这把最高权限的 Root Key,高频调了 70 多次只读接口——名下的 ECS、RDS、OSS、SLS 日志、函数计算、容器服务,几乎被挨个点了一遍名。
万幸逐条核对完近 48 小时的全部写操作事件:对方刚好还卡在“清点云上资产”这一步,还没来得及建 RAM 后门、删库或改 DNS 解析。真要再晚发现半天,整个云账号恐怕就不姓“我”了。
15 小时全栈反杀:从“断水断电”到“源站彻底隐身”
看清了所有入口与泄露面,这一晚索性按“假定所有旧凭据全部失陷”的最高警戒来收口,从云账号到底层代码做了一轮彻底拆弹:
先废掉 Root 命门,所有凭据全部推倒重来
第一时间进云控制台,直接禁用全部主账号 Root AccessKey(主动调用接口复测全数返回 403 AccessKeyDisabled)。随后新建了无控制台登录权限的专用 RAM 子账号,策略权限缩到仅限读写指定存储桶与上传证书,并且死死绑上 acs:SourceIp 条件——哪怕 Key 再次泄露,不在生产服务器固定出口 IP 上照样直接拒签。
主机侧清光 /tmp 残留脚本、36 份历史 .bak 与旧版 .env,禁用 SSH 密码登录,重做全新 Ed25519 登录密钥对和服务器 Host Key,安全组 22 端口收紧到仅限管理端白名单 IP。本机 Docker 里的 MySQL(仅监听 127.0.0.1:3306)、Redis(127.0.0.1:6379)、JWT 签名密钥和 4 个站点的 TLS 私钥全部重新生成替换,顺带清空所有历史 Redis 会话。
把被打穿的门,从三层同时焊死
- 配置层:全环境硬编码
management.endpoint.gateway.enabled: false,exposure.include仅保留health并隐藏详情。 - JVM 网关层:新增全局请求保护 Filter,拦截所有非本机回环 health 的
/actuator请求,封死带矩阵参数;、路径穿越..或双重 URL 编码的变形绕过,并在网关入口无条件剥离外部请求伪造的内部用户头。 - Nginx 入口层:补上正则
"(^|/)actuator(/|;|$)"兜底截断,同时把.env、.git、.sql、.bak、.php等扫描探针路径与废弃老回调一并封死。
全仓大扫雷,干脆砍掉非刚需的高危模块
趁热按更严的安全基线把几个后端模块和网关扫了一遍:把过去调试留下的支付与回调跳过验签、空密钥放行全部改成 Fail-Closed 强校验,远程图片同步补齐防 SSRF 与流式大小上限;同时把全链路访问日志补齐到精确 User-Agent 与被动请求头指纹级别,顺便把线上被拆行刷屏的异常堆栈折叠成单条可读记录。
最有戏剧性的一刀砍在系统原本内置的 AI Agent 模块上。静态审计时,我们在它的只读 SQL 守卫里又揪出一条隐患:校验时先 stripped 掉了注释,执行时却把原串交给数据库,遇到 MySQL 可执行注释(/*!50000 ... */)就能绕过关键词拦截。虽然当场修掉了这个问题,但冷静一想,业务后台日常根本不刚需一个带查询和运维工具的 Agent——干脆从后端、网关、四套前端和移动端里连根拔除、停服清目录。少留一个高权限暴露面,比在前面堆十条防护规则都管用。
早上的回马枪,与最后的“源站藏进边缘节点”
折腾到凌晨两点多刚合眼几个小时,次日早上 07:13 查日志时,戏剧性的一幕果然再次上演——昨晚那个海外攻击 IP 真的杀了个回马枪,连续试探了 28 次 /gateway/actuator/gateway/routes。这一次全部在 Nginx 第一层吃了个零字节 444 直接掐断,连网关的边都没摸到;到了上午 10:23,旁路系统的蜜罐也继续把换着 curl 与 Firefox 158 来探路的请求稳稳挡在 429 之外。
但只要源站真实 IP 还暴露在公网上,对方换批国内代理池照样能打到机器门口。于是上午索性一不做二不休,把全站切进了阿里云 ESA(基础版),配合云解析和 ECS 安全组做了一套彻底的“源站隐身”:
- 安全组彻底锁死回源段:在 ESA 开启源站保护拿到 146 个官方回源 IPv4 网段,写进 ECS 安全组前缀列表,只允许这些回源 IP 访问
443,彻底关闭80端口公网放行。现在直接扫源站 IP,在网络层就直接丢包石沉大海。 - 48 位暗号头 + 边缘 WAF:ESA 回源统一注入 48 位随机
X-Origin-Auth校验头,源站 Nginx 验不过直接444;同时在边缘开启托管 WAF 规则(27 条基础防护规则)、常见扫描探针拦截(.env/.git/wp-login/actuator)、非中国内地流量边缘拦截(仅豁免带签名的支付回调路径),以及动态接口 CC 频控。 - 降低搜索索引暴露:业务与后台域名统一补上
X-Robots-Tag: noindex, nofollow, noarchive与robots.txt全路径Disallow: /。
下午用 curl 实测 /wp-login.php、/.env、/actuator/health,在边缘节点就直接返回 403 拦下;正常业务接口和后台管理全部绿灯通行,服务器日志终于彻底归于平静。
惊魂 15 小时后,留给自己的三条铁律
- 业务配置表里永远别挂主账号 Root AK/SK:哪怕只是传图片,也必须单独开最小权限的 RAM 子账号并绑来源 IP;不然业务侧出个口子,云上家底直接清零。
- 永远别指望只靠 Nginx 挡住 Spring Actuator:分号矩阵参数或路由前缀稍有遗漏就会被 CVE-2022-22947 一串穿糖葫芦,最稳的做法永远是配置层和 JVM Filter 双重硬关。
- 旁路系统多埋蜜罐告警,生产源站务必藏进边缘回源白名单:很多时候主力业务库刚被摸底,旁路系统上一个“蜜罐 403 / 429”就能提前拉响救命警报;把源站安全组锁成只认边缘回源 IP,才是真正能安心睡觉的底气。
Translated by AI from 简体中文Original (简体中文)
还在为IP不纯、平台风控、频繁验证而烦恼? 丽萨主机海外原生IP VPS,双ISP住宅IP,覆盖美国、香港、日本、新加坡、台湾、德国、越南、英国等热门地区,适合跨境电商、社媒运营、AI工具、流媒体及海外业务使用。
2 replies
Sort order