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

推荐订阅源

V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
月光博客
月光博客
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
NISL@THU
NISL@THU
爱范儿
爱范儿
S
Securelist
博客园 - 叶小钗
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
G
GRAHAM CLULEY
P
Proofpoint News Feed
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
博客园 - 【当耐特】
H
Help Net Security
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss

jobcher on 打工人日志

2023-12-21 打工人日报 2023-12-20 打工人日报 2023-12-19 打工人日报 2023-12-18 打工人日报 2023-12-17 打工人日报 2023-12-16 打工人日报 2023-12-15 打工人日报 2023-12-14 打工人日报 2023-12-13 打工人日报 2023-12-12 打工人日报 2023-12-11 打工人日报 2023-12-10 打工人日报 2023-12-09 打工人日报 2023-12-08 打工人日报 2023-12-07 打工人日报 2023-12-06 打工人日报 2023-12-05 打工人日报 2023-12-04 打工人日报 2023-12-03 打工人日报 2023-12-02 打工人日报 2023-12-01 打工人日报 2023-11-30 打工人日报 2023-11-29 打工人日报 2023-11-28 打工人日报 2023-11-27 打工人日报 2023-11-26 打工人日报 2023-11-25 打工人日报 2023-11-24 打工人日报 2023-11-23 打工人日报 2023-11-22 打工人日报 2023-11-21 打工人日报 2023-11-20 打工人日报 2023-11-19 打工人日报 2023-11-17 打工人日报 2023-11-16 打工人日报 2023-11-15 打工人日报 2023-11-14 打工人日报 2023-11-13 打工人日报 2023-11-12 打工人日报 2023-11-11 打工人日报 2023-11-10 打工人日报 2023-11-09 打工人日报 2023-11-08 打工人日报 2023-11-07 打工人日报 2023-11-06 打工人日报 2023-11-05 打工人日报 2023-11-04 打工人日报 2023-11-03 打工人日报 2023-11-02 打工人日报 2023-11-01 打工人日报 2023-10-31 打工人日报 2023-10-30 打工人日报 2023-10-29 打工人日报 2023-10-28 打工人日报 2023-10-27 打工人日报 2023-10-26 打工人日报 2023-10-25 打工人日报 2023-10-24 打工人日报 2023-10-23 打工人日报 2023-10-22 打工人日报 2023-10-21 打工人日报 2023-10-20 打工人日报 2023-10-19 打工人日报 2023-10-18 打工人日报 2023-10-17 打工人日报 2023-10-16 打工人日报 2023-10-15 打工人日报 2023-10-14 打工人日报 2023-10-13 打工人日报 2023-10-12 打工人日报 2023-10-11 打工人日报 2023-10-10 打工人日报 2023-10-09 打工人日报 2023-10-07 打工人日报 2023-10-06 打工人日报 2023-10-05 打工人日报 2023-10-04 打工人日报 2023-10-03 打工人日报 2023-10-02 打工人日报 2023-10-01 打工人日报 2023-09-30 打工人日报 2023-09-29 打工人日报 2023-09-28 打工人日报 2023-09-27 打工人日报 2023-09-26 打工人日报 2023-09-25 打工人日报 2023-09-24 打工人日报 2023-09-23 打工人日报 2023-09-22 打工人日报 2023-09-21 打工人日报 2023-09-20 打工人日报 2023-09-19 打工人日报 2023-09-18 打工人日报 2023-09-17 打工人日报 2023-09-16 打工人日报 2023-09-15 打工人日报 2023-09-14 打工人日报 2023-09-13 打工人日报 2023-09-12 打工人日报 2023-09-11 打工人日报
异常流量分析:图片库服务黑客入侵
2025-03-25 · via jobcher 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/')

总结

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