惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
Jina AI
Jina AI
I
InfoQ
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
V
Visual Studio Blog
L
LangChain Blog
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tor Project blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Recorded Future
Recorded Future
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
O
OpenAI News
Google DeepMind News
Google DeepMind News
S
Schneier on Security
C
Check Point Blog
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
T
Tenable Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
Cyberwarzone
Cyberwarzone
月光博客
月光博客
The Last Watchdog
The Last Watchdog
B
Blog
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Hacker News: Ask HN
Hacker News: Ask HN
H
Heimdal Security Blog
美团技术团队

日常系列 on 打工人日志

Proxmox VE(PVE) 更新到最新版本 iStoreOS(旁路由)使用openclash实现dns劫持 openwrt 硬盘扩容 搭建ip地址检索服务 通知:《打工人日报》迁移到独立板块 黑群晖最新安装教程 推荐一下 容器云资源 2010年的天涯神贴聊房价 如何礼貌回绝不合理的需求 github 国内代理访问下载 逆境和成长-2022年终总结 优雅的使用Conda管理python环境 shell功能脚本集合 Cloudflare Zero Trust 内网穿透 headscale 部署使用 羊了个羊小程序 破解通关 RocketMQ k8s部署 4主4从集群 linux服务器 删除空间却未释放 VSCode插件推荐=> Code Runner ant build.xml 编写 记录一次上门打散工 Ant中如何添加第三方jar包依赖 linux 网络测速 网心云挂机教程 | 轻松实现睡后收入~ Proxmox VE 在线扩容磁盘分区 centos7.9 网络配置 RocketMQ 安装和启动 安装 minIO Azure S3网关 logrotate 日志滚动的使用 安装配置 Terraform rsync 文件同步 获取用户浏览器默认语言设置,自动判断跳转不同网站 linux系统开启root权限 163企业邮箱设置教程 2021年第50周记 自建服务器内网穿透 树莓派搭建k3s 优秀英语教材的选择
异常流量分析:图片库服务黑客入侵
2025-03-25 · via 日常系列 on 打工人日志

背景

最近这两天prometheus一直再对服务器的下行带宽告警,检查告警发现是一台图片服务器,这台图片服务器是很早部署的一台nginx反向代理本地静态文件的服务器,当时没有做任何的安全防护,只是简单做了一个上传接口暴露给外网,导致这台服务器被黑客入侵,上传了大量文件,同时对这些文件有大量的下载请求,导致服务器的带宽被打满,同时也导致了prometheus的告警。

发现

  1. 发现这台服务器的带宽被打满了,所以只能先从这台服务器开始排查。先检查nginx所有大量请求的日志
1cd /var/log/nginx
2awk '{print $7}' access.log | sort | uniq -c | sort -nr | head -n 10

server-log

  1. 这个是一个图片服务器,看起来都是图片的请求,好像没有发现异常的请求。但是这个图片为什么有那么高的流量呢?检查这个图片,发现图片无法打开,所以我换二进制的方式打开图片
    hex-open

发现图片的二进制头部是 FFmpeg, 所以这是一个伪装成图片的视频文件

解决

  1. 检查nginx的配置文件,上传接口拒绝所有外部请求
server{
    location /upload {
        proxy_pass http://192.168.1.1:8080;

        # 拒绝所有外部请求
        allow 192.168.1.0/24;
        deny all;
    }
}
  1. 查找最早上传的文件,创建python文件,并在图片服务器执行
import os

# 查找最早包含 FFmpeg 的 JPG 文件
def find_earliest_jpg_with_ffmpeg(directory):
    earliest_file = None
    earliest_timestamp = float('inf')

    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.lower().endswith('.jpg'):
                file_path = os.path.join(root, file)
                try:
                    with open(file_path, 'rb') as f:
                        file_header = f.read(55)
                        print(file_header)
                        f.close()
                        if b'FFmpeg\tService01' in file_header:
                            timestamp = os.path.getmtime(file_path)
                            if timestamp < earliest_timestamp:
                                earliest_timestamp = timestamp
                                earliest_file = file_path
                except Exception as e:
                    print(f"Error processing file {file_path}: {e}")

    if earliest_file:
        print(f"最早的包含 FFmpeg 的 JPG 文件是: {earliest_file}")

# 调用函数并传入目录路径
find_earliest_jpg_with_ffmpeg('/var/www/html/images/')
  1. 删除这些FFmpeg文件,创建python文件,并在图片服务器执行
import os

# 检查文件头是否包含 FFmpeg
def delete_file_if_header_contains_ffmpeg(file_path):
    try:
        with open(file_path, 'rb') as file:
            file_header = file.read(55)
            print(f"检查文件: {file_path},文件头: {file_header}")
            file.close()
            if b'FFmpeg\tService01' in file_header:
                os.remove(file_path)
                print(f"文件 {file_path} 已被删除")
            else:
                print(f"文件 {file_path} 不符合删除条件")
    except FileNotFoundError:
        print(f"文件 {file_path} 找不到")
    except Exception as e:
        print(f"发生错误: {e}")

# 遍历目录并删除 JPG 文件
def traverse_and_delete_jpg_files(directory):
    try:
        for root, dirs, files in os.walk(directory):
            for file in files:
                if file.lower().endswith('.jpg'):
                    file_path = os.path.join(root, file)
                    delete_file_if_header_contains_ffmpeg(file_path)
    except Exception as e:
        print(f"遍历目录时发生错误: {e}")

# 调用函数并传入目录路径
traverse_and_delete_jpg_files('/var/www/html/images/')

总结

大家一定要增加服务器权限的管控,开放到外部的接口,一定要做好访问权限控制,避免被有心人利用。