首页 > 系统相关 >netdot webapi发布centos stream 9 被dos攻击

netdot webapi发布centos stream 9 被dos攻击

时间:2024-07-06 20:09:59浏览次数:12  
标签:webapi centos stream ip app nginx systemctl proxy context

前言-刚刚发布一个demo一直被一个叼毛攻击,不停的扫描端口,弄得接口一访问就是503错误

99元买了一个2核2g的服务器,1元钱买了一个服务器,有个人一直扫描我的端口

安装一个 nginx

dnf install nginx

安装完成后启动nginx服务

# 启动
systemctl start nginx 
 
# 设置开机自启动
systemctl enable nginx
 
# 重启
systemctl restart nginx
 
# 查看状态
systemctl status nginx
 
# 停止服务
systemctl stop nginx

打开etc\nginx\nginx.conf文件

      server {
            listen 80;
            server_name _;

            # 拒绝访问带有 .html 扩展名的文件
            location ~* \.html$ {
                return 403;
            }



            # 将其他请求代理到本地的 5000 端口
            location / {
                proxy_pass http://192.168.100.149:5000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection keep-alive;
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
            }
        }

webapi程序program里面改一下

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
//    app.UseSwagger();
//    app.UseSwaggerUI();
//}
 
app.UseAuthorization();

app.MapControllers();

app.Use(async (context, next) =>
{
    var requestedUrl = context.Request.Path.Value;

    if (!IsValidUrl(requestedUrl))
    { 
        if (requestedUrl.Contains(".html"))
        {
            logger.Debug($"{GetClientIp(context)}--{context.Request.Path}");
        }
        context.Response.StatusCode = StatusCodes.Status400BadRequest;
        await context.Response.WriteAsync(" ");
        return;
    }

    await next();
});
 
app.Run();

bool IsValidUrl(string url)
{
    // 这里可以实现你的URL验证逻辑
    // 例如,只允许某些路径
    var allowedUrls = new[] {"/home" };
    return allowedUrls.Contains(url.ToLower());
}


 string GetClientIp(HttpContext context)
{
    // 尝试从 X-Forwarded-For 头获取 IP 地址
    string ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();

    if (string.IsNullOrEmpty(ip))
    {
        // 如果 X-Forwarded-For 头为空,则获取直接连接的 IP 地址
        ip = context.Connection.RemoteIpAddress.ToString();
    }

    return ip;
}
如果前面前面的nginx被功能0进入到这里,直接记录ip
然后在管理后台限制ip访问

把允许改成拒绝,把掉毛的ip加进去

如果还是大量攻击那就上高防服务器,那种服务器打不死

我的服务器99元买的为什么非要打我,日了狗

 

标签:webapi,centos,stream,ip,app,nginx,systemctl,proxy,context
From: https://www.cnblogs.com/axyls/p/18287667

相关文章

  • CentOS 7 防火墙限制ip访问指令
    查看默认区域[root@localhost~]#firewall-cmd--get-default-zonepublic#如果不是public,改为publicfirewall-cmd--set-default-zone=public关闭端口访问此处区域中的端口如果开放,是所有ip都可以进行访问。全部删掉#查询打开的端口firewall-cmd--zone=public--list......
  • 在没有网络的情况,mac如何与vmware中的linux系统通信,例如在mac上ping通centos系统
    1.配置Host-Only网络在VMware中配置Host-Only网络:打开VMware并选择您的CentOS虚拟机。关闭虚拟机(如果它正在运行)。点击虚拟机的设置(Settings)。在设置窗口中,选择“网络适配器”(NetworkAdapter)。选择“Host-Only”网络连接类型。保存设置并启动您的虚拟机。2.配置CentO......
  • centos7.9 yum mysql8
    centos7.9mysql8安装CentOS7.9上安装MySQL8.0的步骤如下:下载MySQL官方的YumRepository:wgethttps://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm添加MySQLYumRepository到你的系统:sudorpm-Uvhmysql80-community-release-el7-3.noarch.rpm安......
  • centos7服务器yum安装MySQL数据库,以及报错的解决方案
    文章目录1、数据库能做什么?2、数据库由来3、数据库-系统结构4、版本二、部署1、官网地址3.点击[DOCUMENTATION](https://dev.mysql.com/doc/)4.mysql的yum仓库[UsingtheMySQLYumRepository](https://dev.mysql.com/doc/refman/8.4/en/linux-installation-yum-repo......
  • centos7 安装openssl
    1.下载openssl官网地址:https://www.openssl.org/source/wgethttps://www.openssl.org/source/openssl-3.0.14.tar.gztar-zxvfopenssl-3.0.14.tar.gzcdopenssl-3.0.142.编译安装yum-yinstallperl-IPC-Cmd./config--prefix=/usr/local/opensslmakemakeinstall3......
  • Mysql 8.4 安装(Centos7.9)
    前置准备root环境下执行#关闭selinuxvi/etc/selinux/config#SELINUX=enforcing=>SELINUX=disabled#开通防火墙3306/tcpfirewall-cmd--permanent--add-port=3306/tcp下载链接获取https://dev.mysql.com/downloads/file/?id=529414下载&安装下载mkdir-p......
  • 制作CentOS7.9的U盘系统启动盘超详细操作教程
    1、下载centos7.9操作系统阿里云镜像源https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/?spm=a2c6h.25603864.0.0.7ed1f5ad877Uus2、制作u盘注意事项:制作u盘会让直接格式化u盘里面的所有数据,已有数据的u盘需要做好备份,建议购买新的u盘格式化操作。2.1格式化u盘,选......
  • java中stream流的操作详解
    1.Java8之后引入的Stream流为我们提供了便捷的集合数据处理方式一,常用方法1.filter;过滤集合中符合条件的数据2.distinct();过滤掉集合中重复的元素,过滤的是所有元素都相同的对象3.sorted();对集合中元素进行排序,用来排序的元素类型必须是int才行4.limit(longn);返回前n个......
  • Centos 7 离线安装docker及docker-compose
    一、docker安装下载docker安装包地址:https://download.docker.com/linux/static/stable/x86_64/选择需要用到的版本进行下载百度网盘docker-26.1.4.tgz安装包地址:https://pan.baidu.com/s/1mdCjdQnI_aFQ2CgGl7ILEA提取码:7h4d上传服务器并解压tar-zxvfdocker-26.......
  • CentOS 7 nginx 安装 sticky模块
    一、安装准备        首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装yuminstallgcc-c++  安装下面命令的目的是确保系统上安装了这些......