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

推荐订阅源

D
DataBreaches.Net
T
Threatpost
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
V2EX - 技术
V2EX - 技术
D
Docker
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
T
Troy Hunt's Blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
量子位
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
F
Full Disclosure
B
Blog
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
博客园 - 聂微东
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Recorded Future
Recorded Future
IT之家
IT之家
Project Zero
Project Zero
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
SecWiki News
SecWiki News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

日常 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/')

总结

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