AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-409772

DevOpsSauce's questions

Martin Hope
DevOpsSauce
Asked: 2021-12-15 12:09:12 +0800 CST

使用参数启用 systemd 服务

  • 1

我有一个systemd带有参数的服务。它工作得很好。但是,我无法在没有参数的情况下启动它。

该参数看起来像systemctl start [email protected],其中1-0将由 php 脚本解析。php 脚本的默认值为1-0,但我无法以systemctl start [email protected]. 它告诉我:

Failed to start [email protected]: Unit name [email protected] is missing the instance name.

我用 成功启用了它systemctl enable [email protected],但它会在启动时失败吗?如果是这样,我怎么能告诉它以默认值开始,1-0如果没有指定其他内容?

service systemd
  • 1 个回答
  • 385 Views
Martin Hope
DevOpsSauce
Asked: 2021-12-14 06:18:38 +0800 CST

无法使用 Ansible 命令模块执行 sqlite 语句 - [Errno 2] 没有这样的文件或目录:b'sqlite3'"

  • 0

我正在尝试在许多服务器上运行一个简单的查询。我知道 100% 有问题的文件和目录存在。

我可以执行简单的命令,例如ls、pwd、whoami等,并且可以sqlite在远程主机本身上运行命令。

剧本任务:

- name: Do a test SELECT statement
  become: yes
  become_user: root
  command: sqlite3 /usr/local/share/sqlite/dbfile.sqlite3 "SELECT * FROM db WHERE hostname="{{ db_server_prompt }}""
  register: query_result

- debug: var=query_result.stdout_lines

我收到的错误是 "msg": "[Errno 2] No such file or directory: b'sqlite3'",.

我的语法有问题吗?为什么在使用 sqlite3 命令时它告诉我有“ No such file or directory”?我已经尝试了可执行文件 ( /usr/bin/sqlite3) 的绝对路径,但我得到了同样的错误。

更新我试图根据这个答案chdir用作参数,但我得到了。我还尝试了with的绝对路径。这些都不起作用。Unable to change directory before executionsqlite/usr/bin/sqlite3

ansible
  • 0 个回答
  • 435 Views
Martin Hope
DevOpsSauce
Asked: 2021-07-27 18:48:12 +0800 CST

通过 CNAME 和 Nginx Docker 容器将安全域重定向到另一个域

  • 1

更新:我在这篇文章的底部附加了第二次尝试。它正在“工作”,但我想让我最初的想法发挥作用。

我正在尝试通过重定向服务器将域的 https 请求重定向到另一个域。

我将使用https://website.com,https://website2.com和https://myredirectserver.com作为示例。

我购买了一个 SSL 证书website.com,它的 DNS 是 CNAMEDwww到的myredirectserver.com。也有一个 SSL 证书mywebsite2.com,它目前位于服务器上。一切都很好作为一个独立的域。

myredirectserver.com有两个指向两个 IP 地址的流量管理 A 记录(高可用性)。

这两个 IP 地址在防火墙中通过 NAT 转换为代理服务器。

在该代理服务器上,有一个运行 Alpine/Nginx 的 Docker 容器。

容器的 Dockerfile:

FROM nginx:1.17.7-alpine    
RUN apk add --no-cache tzdata    
ENV TZ America/Chicago    
RUN rm /etc/nginx/conf.d/default.conf    
COPY myredirectserver.com.conf /etc/nginx/conf.d/myredirectserver.com.conf
RUN rm /etc/nginx/nginx.conf    
COPY nginx.conf /etc/nginx/nginx.conf    
COPY myredirectserver.com.crt /etc/nginx/ssl/myredirectserver.com.crt    
COPY myredirectserver.com.key /etc/nginx/ssl/myredirectserver.com.key    
COPY proxy_params /etc/nginx/proxy_params

启动它的docker run部分(通过后端代码安装了用于动态配置文件创建的卷):

docker run --name=myredirectserver --restart always --log-opt max-size=50m --log-opt max-file=5 -d -v /etc/nginx/myredirectserverBuild:/etc/nginx/myredirectserverBuild -v /etc/nginx/myredirectserverSSL:/etc/nginx/myredirectserverSSL -p 8224:443 -p 8223:80 myredirectserver

在该 Docker 容器中,Nginx 配置文件位于/etc/nginx/conf.d/myredirectserver.com.conf:

 #I DO NOT KNOW IF THIS IS CORRECT FOR WHAT I NEED
    server {
                listen 443 ssl;
    
                server_name myredirectserver.com www.myredirectserver.com;
                ssl_certificate /etc/nginx/ssl/myredirectserver.com.crt;
                ssl_certificate_key /etc/nginx/ssl/myredirectserver.com.key;
            }
            server {
                listen 80;
                server_name myredirectserver.com www.myredirectserver.com;
                return 301 https://www.myredirectserver.com$request_uri;
            }
    
    include /etc/nginx/myredirectserverBuild/*.conf;

最后的包含文件包含原始请求的域,mywebsite.com.conf:

 ## www.mywebsite.com virtual host
        server {
            listen 443 ssl;

            server_name mywebsite.com www.mywebsite.com;
            ssl_certificate /etc/nginx/myredirectwebsiteSSL/mywebsite.com.crt;
            ssl_certificate_key /etc/nginx/myredirectwebsiteSSL/mywebsite.com.key;               
        }
        server {
            listen 80;
            server_name mywebsite.com www.mywebsite.com;
            return 301 https://www.mywebsite2.com$request_uri; <--- The redirect
        }
        

该website2.com域位于主机服务器上,我可以正常请求该域。我只是无法弄清楚我哪里出错了。我觉得它在我的 Nginx 配置中,但我的 Nginx 语法并不是最好的。为什么我return 301不工作并将我重定向到域?

故障排除期间的几点注意事项:

wget 0.0.0.0:8223返回:

  --2021-07-26 23:44:19--  http://0.0.0.0:8223/
Connecting to 0.0.0.0:8223... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.mywebsite2.com/ [following]
--2021-07-25 23:44:19--  https://www.mywebsite2.com/
Resolving www.mywebsite2.com (www.mywebsite2.com)... XX.XXX.XXX.XXX
Connecting to www.mywebsite2.com (www.mywebsite2.com)|XX.XXX.XXX.XXX|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html                                               [ <=>                                                                                                                  ]  37.56K   231KB/s    in 0.2s    

2021-07-25 23:44:20 (231 KB/s) - ‘index.html’ saved [38461]

curl --resolve www.myredirectserver.com:8223:0.0.0.0 http://www.myredirectserver.com/返回超时,浏览器也是如此。

在本地网络上,在地址栏 ( 192.168.69.140:8223) 中输入 Docker 容器的 IP 会将我带到https://www.website2.com.

输入https://192.168.69.140:8224会将我带到安全飞溅警告页面。单击proceed,它给了我一个404.

我不知所措,因为当请求到达 CNAME 的 IP 时,我不知道如何处理它myredirectserver.com。如何告诉 Nginx 查看原始请求的域website.com?

更新(第二次尝试):

我停止了 Docker 容器,并将DNSCNAME中的www级别更改为指向一个已经存在的高可用 IP。我会打电话destinationserver.net的。所以基本上:

`mywebsite.com`
|
|---> CNAME 'destinationserver.net'

`destinationserver.net`
|
|----> A XX.XXX.XXX.XXX --> Firewall --> Proxy

|----> A XX.XXX.XXX.XXX --> Firewall --> Proxy

在destinationserver.net服务器上,我在 Nginx 配置中有以下内容website.com:

# ## www.mywebsite.com virtual host
        server {
            listen 8222 ssl;

            server_name mywebsite.com www.mywebsite.com;
            ssl_certificate /etc/nginx/ssl/mywebsite.com.crt;
            ssl_certificate_key /etc/nginx/ssl/mywebsite.com.key;
            return 301 http://www.mywebsite2.com$request_uri;
        }
        server {
            listen 8221;
            server_name mywebsite.com www.mywebsite.com;
            return 301 https://www.mywebsite2$request_uri;
        } 

正如我在问题第一行的“更新”中所述,这是“有效的”,但在单独的空间中处理这些重定向会很好,因此是 Docker 容器的想法。

proxy redirect cname-record nginx docker
  • 1 个回答
  • 736 Views
Martin Hope
DevOpsSauce
Asked: 2021-07-13 12:07:35 +0800 CST

Logrotate 不写入新的 .log 文件

  • 0

我有 4 个自定义 systemd 服务写入自定义日志/var/log/。我设置了一个logrotate配置文件,但它没有写入最新的日志。它仍在写入旧.log.1文件。新的已创建,只是没有数据。

这是我的 logrotate 配置:

/var/log/dealer*.log {
        daily
        missingok
        rotate 7
        delaycompress
        notifempty
        su root root
        postrotate
        /bin/systemctl reload dealer*.service > /dev/null 2>/dev/null || true
        endscript
        create 0644 root root

}

最新的日志文件是空的:

-rw-r--r--  1 root      root               0 Jul 12 11:39 dealerF2f.log
-rw-r--r--  1 root      root               0 Jul 12 11:39 dealerOutbound.log
-rw-r--r--  1 root      root               0 Jul 12 11:39 dealerTimeout.log
-rw-r--r--  1 root      root               0 Jul 12 11:39 dealerWeb.log

它仍在写信给.log.1:

-rw-r--r--  1 root      root             36M Jul 12 12:52 dealerOutbound.log.1
-rw-r--r--  1 root      root            9.2M Jul 12 12:52 dealerF2f.log.1
-rw-r--r--  1 root      root             19M Jul 12 12:52 dealerWeb.log.1
-rw-r--r--  1 root      root            171M Jul 12 12:52 dealerTimeout.log.1
systemd logrotate
  • 1 个回答
  • 965 Views
Martin Hope
DevOpsSauce
Asked: 2021-07-03 07:33:51 +0800 CST

如何从具有多个服务的新贵脚本创建 systemd“全部启动”模板单元文件?

  • 0

我正在将所有自定义新贵脚本迁移到 systemd。我遇到了一个使用多种服务的脚本。我无法弄清楚处理这个问题的正确语法,或者我是否需要.service为每个文件创建单独的单元文件。这可以用于模板吗?SystemD单元文档没有给我太多信息,除了如何创建模板文件(附加@到名称)以及如何使用%i来表示实例。

最初的暴发户dealer-start-all.conf

console log
start on dealer-start
script
    declare -a dealers=("TimeZone" "Timeout" "Inquiry" "Refuse")

    for type in "${dealers[@]}"
    do
        if initctl list | grep "^dealer ($type)"
        then
            stop dealer type=$type
        fi
        start dealer type=$type
        echo "dealer$type started"
    done
end script

它的另一部分dealer.conf,应该通过%i在该ExecStart部分中使用而被很好地切割和干燥,例如:

ExecStart=/usr/bin/php -f /path/to/dealer%i.php

console log

instance $type

stop on dealer-stop

script
        sudo -u root php -f /path/to/dealer$type.php
end script

post-stop script

if [ -z "$UPSTART_STOP_EVENTS" ]
    then
        echo "dealer$type stopped at `date +"%F %T.%N"` Run 'initctl emit dealer-stop' then 'initctl emit dealer-start' on `hostname` to get it running again." | mail -s "dealer$type Stopped" [email protected]
    else
        echo "dealer$type was manually stopped at `date +"%F %T"`."
fi
end script

我只是不明白如何将第一个中的数组转换为 systemd 版本?我应该把这些分解成单独的单元文件吗?如果是这样,那么这不是问题并且可以轻松完成。我只是不确定语法(如果存在)来做第一个正在做的事情。

ubuntu systemd upstart
  • 1 个回答
  • 243 Views
Martin Hope
DevOpsSauce
Asked: 2021-03-17 08:26:56 +0800 CST

Fail2ban 禁止不在日志中的奇数 IP 地址(0.0.0.4、0.0.0.5 等)

  • 0

服务器:Nginx

Fail2ban 版本:v0.9.3

似乎无论我尝试什么,我都无法让 fail2ban 始终从日志条目中找到正确的主机。

/etc/fail2ban/filter/expanse-bot.conf:

[Definition]
failregex = ^(\d{2}|\d{3}) \| <HOST> \| .*\"Expanse indexes the network.*

^(\d{2}|\d{3})捕获端口 80 或 443。我最初在行的开头尝试了一个通配符,^.*<HOST>但没有奏效。

日志条目:

443 | 34.77.162.32 | - | [14/Mar/2021:11:08:23 -0500] | redacted-domain.com | "GET / HTTP/1.1" | 200 | 144126 | "-" | "Expanse indexes the network perimeters of our customers. If you have any questions
 or concerns, please reach out to: [email protected]" | - | 123.45.67.89:1234

在/var/log/fail2ban.log中,它显示了日志中不存在的这些奇数 IP 地址:

2021-03-14 11:07:02,716 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 0.0.0.3
2021-03-14 11:07:03,656 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 0.0.0.4
2021-03-14 11:07:03,865 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 0.0.0.5
2021-03-14 11:07:04,075 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 0.0.0.6

但是,那么它是否正确禁止?:

2021-03-14 11:13:48,075 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.13
2021-03-14 11:13:51,288 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.27
2021-03-14 11:15:19,595 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.16
2021-03-14 11:16:30,884 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.12
2021-03-14 11:18:14,208 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.18
2021-03-14 11:19:39,513 fail2ban.actions        [10818]: NOTICE  [expanse-bot] Ban 34.77.162.11

我的配置/etc/fail2ban/jail.local:

[expanse-bot]
enabled = true
filter = expanse-bot
logpath = /var/log/nginx/access.log
port = http,https
maxretry = 1
findtime = 3
bantime = 86400
action = iptables-allports[name=expanse-bot]

一旦它通过那些奇怪的 IP 地址,它就会按预期进行。我只是不明白 0.0.0.* 在日志中不存在时的含义是什么?我在主要配置中缺少什么吗?

ubuntu nginx regex fail2ban
  • 1 个回答
  • 499 Views
Martin Hope
DevOpsSauce
Asked: 2021-02-20 16:49:10 +0800 CST

新的 SSL 证书现在显示在浏览器中的 Postfix(Ubuntu、Namecheap)

  • 0

我是一个新手,在我们的系统管理员离开后试图将其打开。我需要更新我们的通配符证书并将其复制到我们的邮件服务器上。

我在 Namecheap 更新了证书,下载了它,并将它安装在我们的网络服务器上。网站浏览器中的一切都显示良好。但是,当导航到我们邮件服务器的浏览器门户时,它仍然显示旧证书。我重新启动了 Postfix,但没有任何改变。

在我的 /etc/postfix/main.cf 中:

# TLS parameters
smtpd_tls_cert_file = /etc/ssl/certs/wc2_mydomain.com.combined.crt
smtpd_tls_key_file = /etc/ssl/private/wc2_mydomain.com.key
smtpd_use_tls=yes

但是,在浏览器中,即使过了postfix reload(应该是 2022 年),它仍然显示旧的过期日期:

Issued On   Wednesday, February 20, 2019 at 6:00:00 PM
Expires On  Saturday, February 20, 2021 at 5:59:59 PM

我错过了什么?如果星期六下午 6:00 不能正确显示,那将是非常糟糕的。

ubuntu postfix email-server ssl-certificate ssl-certificate-renewal
  • 1 个回答
  • 128 Views
Martin Hope
DevOpsSauce
Asked: 2021-01-21 08:48:01 +0800 CST

Rsyslog 旋转,但仍记录到旧日志

  • 0

服务器:Ubuntu 服务器 14.04

我有一个 Watchguard Firebox 记录到服务器。它应该每天轮换,但是,当轮换发生时,它不会写入新日志。它一直写到前一个。

里面的配置/etc/logrotate.d/

/var/log/watchguard
{
    rotate 14
    daily
    missingok
    create 640 syslog adm
    compress
    delaycompress
    sharedscripts
    su root syslog
    postrotate
            /usr/sbin/service rsyslog reload >/dev/null 2>&1 || true
    endscript
}

如您所见,轮换正在发生,但最新日志未写入:

-rw-r----- 1 syslog    adm        20 Jan 17 02:30 watchguard.3.gz
-rw-r----- 1 syslog    adm        20 Jan 18 02:30 watchguard.2.gz
-rw-r----- 1 syslog    adm         0 Jan 20 02:30 watchguard <---- SHOULD CONTAIN DATA
-rw-r----- 1 syslog    adm      3.0G Jan 20 10:34 watchguard.1 <--- ROTATED, BUT STILL GETTING DATA

就好像它不关心文件的名称一样。它只是继续写。我的logrotate配置语法不正确吗?

rsyslog logrotate watchguard ubuntu-14.04
  • 1 个回答
  • 520 Views
Martin Hope
DevOpsSauce
Asked: 2020-12-24 14:21:05 +0800 CST

IPTables 导致与 Fail2Ban 冲突

  • 1

操作系统:Ubuntu 服务器 18.04

Fail2ban:v0.10.2

我正在尝试了解我的 Fail2ban 安装的错误(我相信是我自己制作的)。我有一个使用预定义列表填充 iptables 的 cron 作业:

iptables -A INPUT -s <ip address> -j DROP
iptables -A INPUT -s <ip address> -j DROP
etc
etc

在此脚本的开头,它运行:

iptables -F INPUT刷新 INPUT 链。在我安装 Fail2ban 以动态禁止不良行为者之前,该 cron 作业已存在于服务器上。但是,我注意到我开始收到很多通知,说明特定 IP 是already banned. 当我停止运行 iptables cron 作业时,此错误消失了,并且一直在运行,没有任何问题。

我的问题是:我iptables -F INPUT在 Fail2ban 仍在运行时运行会产生什么样的冲突?这个命令不应该没问题,因为被禁止的 IP 被放入了它们各自的f2b-<jail>链中,还是我误解了?如果这个 iptables 脚本需要运行,我是否也应该对 Fail2ban 数据库做一些事情(清除等)?

谢谢你。

iptables fail2ban
  • 1 个回答
  • 184 Views
Martin Hope
DevOpsSauce
Asked: 2020-11-12 07:06:22 +0800 CST

Nginx:未知的日志格式错误

  • 0

我有一个代理设置,它使用 UDP 流量来负载平衡内部 DNS。它正在将流量正确路由到我的后端 DNS 服务器,但我似乎无法让日志格式正常工作。

我收到的错误是:

nginx[32103]: nginx: [emerg] unknown log format "dns" in /etc/nginx/nginx.conf:23

我在 http 块中有日志格式,并在stream-->server块中定义它。我试图在stream-->server块中设置 log_format,但没有一个变量可以工作。

    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    events {
            worker_connections 768;
            # multi_accept on;
    }
    stream {
    
      upstream dns_servers {
        least_conn;
        server 192.168.3.222:53 fail_timeout=10s;
        server 192.168.70.80:53 fail_timeout=10s;
        server 192.168.70.81:53 fail_timeout=10s;
      }
      server { 
        listen 53 udp;
        proxy_pass dns_servers;
        proxy_responses 1;
        proxy_timeout 1s;
        access_log /var/log/nginx/access.log dns;
    
      }
    }
    
    http {
    
            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            keepalive_timeout 65;
            types_hash_max_size 2048;
    
            include /etc/nginx/mime.types;
            default_type application/octet-stream;
    
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
            ssl_prefer_server_ciphers on; 
    
            log_format dns '[$time_local] | $remote_addr | $remote_user | $server_name $host to: $upstream_addr | '
                               '"$request" | $status | upstream_response_time $upstream_response_time msec '
                               '$msec | request_time $request_time';
    
            access_log /var/log/nginx/access.log dns;
            error_log /var/log/nginx/error.log;
}

我试图放置log_format在流块中,但我开始得到unknown <variable name> variable.

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}
stream {
 log_format dns '[$time_local] | $remote_addr | $remote_user | $server_name $host to: $upstream_addr | '
                           '"$request" | $status | upstream_response_time $upstream_response_time msec '
                           '$msec | request_time $request_time';

  upstream dns_servers {
    least_conn;
    server 192.168.3.222:53 fail_timeout=10s;
    server 192.168.70.80:53 fail_timeout=10s;
    server 192.168.70.81:53 fail_timeout=10s;
  }
  server { 
    listen 53 udp;
    proxy_pass dns_servers;
    proxy_responses 1;
    proxy_timeout 1s;
    access_log /var/log/nginx/access.log dns;

  }
}

这根本不是 Web 服务器。它只会充当 DNS 流量的代理。如何正确使日志记录正常运行?这是一个默认的 nginx.conf 文件,除了流块。

logging udp nginx proxypass
  • 2 个回答
  • 5577 Views
Martin Hope
DevOpsSauce
Asked: 2019-05-18 07:07:21 +0800 CST

Fail2ban 禁止 IP,但直到它已经有数百个请求

  • 1

我有一个使用特定用户代理的监狱。它最终禁止了它,但它仍然得到了数百个请求。

以下是相关信息(除非需要其他任何信息):

/etc/fail2ban/jail.conf 中的禁止操作

banaction = iptables-allports

这是 /etc/fail2ban/jail.local 中的条目

[domaincrawler-bot]
enabled = true
filter = domaincrawler-bot
logpath = /var/log/nginx/*access.log
port = 8221,8222,8231,8232
maxretry = 1
findtime = 10
bantime = -1
action = iptables-allports[name=domaincrawler-bot]

我有一个 shell 脚本,它按 IP 地址将最常见的点击组合在一起,它仍然设法在禁止之前获得数百个请求:

Count    IP Address    User Agent String

543 80.248.225.168 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/***************************.com)" "-"
455 80.248.225.79 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/********.com)" "-"
282 80.248.225.4 | "DomainCrawler/3.0 ([email protected]; http://www.domaincrawler.com/********************.com)" "-"

我可以验证它最终是否会发送到 iptables:

root@****:/var/log/nginx# iptables -L -vn | grep 80.248.225.4
0     0 REJECT     all  --  *      *       80.248.225.4         0.0.0.0/0            reject-with icmp-port-unreachable

这是我在 /etc/fail2ban/filter.d/domaincrawler-bot.conf 中的正则表达式条目

[Definition]
failregex = ^\d{4} <HOST> .*DomainCrawler.*

执行正则表达式测试会产生数千条匹配的行:

root@****:/var/log/nginx# fail2ban-regex --print-all-matched access.log "^\d{4} <HOST> .*DomainCrawler.*"



 Running tests
=============

Use   failregex line : ^\d{4} <HOST> .*DomainCrawler.*
Use         log file : access.log
Use         encoding : UTF-8


Results
=======

Failregex: 2222 total
|-  #) [# of hits] regular expression
|   1) [2222] ^\d{4} <HOST> .*DomainCrawler.*
`-

Ignoreregex: 0 total

Date template hits:
|- [# of hits] date format
|  [80276] Day(?P<_sep>[-/])MON(?P=_sep)Year[ :]?24hour:Minute:Second(?:\.Microseconds)?(?: Zone offset)?
`-

Lines: 80276 lines, 0 ignored, 2222 matched, 78054 missed [processed in 7.69 sec] 

我还在 regex101.com 上验证了它确实找到了这些字符:

正则表达式101_image

这是检查监狱状态时的输出:

    root@****:/var/log/nginx# fail2ban-client status domaincrawler-bot
Status for the jail: domaincrawler-bot
|- Filter
|  |- Currently failed: 1
|  |- Total failed: 31178
|  `- File list:    /var/log/nginx/access.log
`- Actions
   |- Currently banned: 12
   |- Total banned: 12
   `- Banned IP list:   176.74.192.36 176.74.192.40 176.74.192.42 185.6.8.3 185.6.8.7 185.6.8.9 194.68.17.5 80.248.225.142 80.248.225.168 80.248.225.4 80.248.225.7 80.248.225.79

这个特定的服务器获得了大量的流量,所以在解析访问日志时它可能稍微落后了?我还能做些什么来提高性能吗?正如我所说,它最终确实会禁止 IP,但在收到数百(有时数千)不同监狱的请求之前不会。

谢谢你们。

nginx
  • 1 个回答
  • 927 Views
Martin Hope
DevOpsSauce
Asked: 2018-11-10 06:58:34 +0800 CST

Fail2ban 不禁止尝试的 sql 注入

  • 3

我每天都会收到大量看起来相似的 sql 注入尝试。访问日志的片段显示:

8222 24.247.182.172 - - [09/Nov/2018:08:47:25 -0600] ***************.com "GET /Add_Product.php?strPhotoID=VA1209&price_selected=2+union+select+0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526--&page_id=912 HTTP/1.1" 302 0 "https://www.***************.com/Add_Product.php?strPhotoID=VA1209&price_selected=2+union+select+0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526,0x5e2526--&page_id=912" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" "-"

这是 jail.local 中的配置:

[sql-union-select-attack]
enabled = true
filter = sql-union-select-attack
logpath = /var/log/nginx/*access.log
port = 8221,8222,8231,8232
maxretry = 1
findtime = 10
bantime = -1
action = iptables-allports[name=sqlUnionSelect]

这是过滤器(sql-union-select-attack.conf):

#The SQL Injection attempt with "union+select+" in the URL
[Definition]
failregex = ^\d{4} <HOST> -.*\"(GET|POST).*/Add_Product.php.*union

然而我在这里,没有得到任何禁令,如图所示

fail2ban-client status sql-union-select-attack

    root@web4:/etc/fail2ban# fail2ban-client status sql-union-select-attack
    Status for the jail: sql-union-select-attack
    |- Filter
    |  |- Currently failed: 0
    |  |- Total failed: 0
    |  `- File list:    /var/log/nginx/**************.access.log /var/log/nginx/access.log
    `- Actions
       |- Currently banned: 0
       |- Total banned: 0
       `- Banned IP list:   

这里发生了什么?我的 jail.local 配置有问题吗?

编辑

感谢迈克尔汉普顿的回答,它现在似乎正在工作。我有一个 bash 脚本,可以让我选择一个监狱来获取状态:

root@web4:/etc/fail2ban# get_jail_status 
http-get-dos
http-post-dos
magento-url
megaindex-crawler-spam
nginx-499
nginx-aspx-url
sql-directory-attempt
sql-union-select-attack
sshd
Please enter the jail you would like to check: 
sql-union-select-attack
Status for the jail: sql-union-select-attack
|- Filter
|  |- Currently failed: 0
|  |- Total failed: 2
|  `- File list:    /var/log/nginx/**************.access.log /var/log/nginx/access.log
`- Actions
   |- Currently banned: 5
   |- Total banned: 5
   `- Banned IP list:   142.163.212.50 217.61.108.219 37.59.8.29 207.228.228.8 162.144.126.204

如果我选择其中一个 IP 地址并在 iptables 中检查它,它会出现:

root@web4:/etc/fail2ban# iptables -L -v -n | grep 142.163.212.50
0     0 REJECT     all  --  *      *       142.163.212.50       0.0.0.0/0            reject-with icmp-port-unreachable

所以它似乎正在工作!

nginx
  • 1 个回答
  • 3041 Views
Martin Hope
DevOpsSauce
Asked: 2018-10-12 05:02:12 +0800 CST

奇怪的服务器访问日志

  • -2

每天早上,我都会监控访问日志以过滤掉机器人程序和恶意入侵尝试。我一直注意到这种相同类型的日志。

示例输出(网站和 IP 地址被隐藏):

8232 xxx.xxx.xx.xx - - [11/Oct/2018:04:14:11 -0500] <thewebsite>.com "GET /util/login.aspx HTTP/1.1" 302 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0" "-"

首先,/util/login.aspx 不存在,因此它们被重定向。这看起来不像典型的爬虫,因为它们正在尝试访问登录页面。

有人可以阐明一个典型的脚本小子可能在做什么吗?它始终是完全相同的文件路径 (/util/login.aspx)。我有适当的工具来缓解这种情况,但我想知道是否有人见过这种类型的活动,看起来像是典型的 ASP.NET 登录页面。我们使用 Linux 服务器。

ubuntu
  • 1 个回答
  • 56 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve