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-597478

xstack's questions

Martin Hope
xstack
Asked: 2024-01-28 23:45:21 +0800 CST

试图理解为什么内核尝试验证被禁止的 IP (Debian 10 VPS)

  • 5

我有一台在 VPS 上运行的 Debian 10 服务器。我安装的唯一软件是:tinyproxy(http代理)和fail2ban

我已经包括:

  • 使用nmap进行端口扫描的结果
  • 我在fail2ban jam.local 文件中的具体设置。
  • 我在fail2ban failure2ban.local 文件中的具体设置。
  • 验证日志中的完整样本。
  • fail2ban 日志的完整样本。
  • 我的 IpTables 样本扫描结果。

问题总结:

  • auth.log 显示 192.241.141.43 几乎每分钟都尝试进入
  • fail2ban.log 显示 192.241.141.43 已被禁止
  • iptables显示192.241.141.43被禁止

我认为基于 IP 被阻止,恶意用户将无法尝试登录。然而,内核似乎确实(pam_unix(sshd:auth))允许尝试登录。

我的两个问题:

  1. 为什么内核在禁止恶意用户的情况下仍允许他们尝试登录?
  2. 为什么 Iptables 条目显示“icmp”而不是“tcp”?是的,我知道“ping”是一个 icmp 数据包,但我想阻止 tcp 登录尝试。

非常感谢 !

nmap 扫描结果

# Nmap 7.80 scan initiated Sat Jan 27 15:25:04 2024 as: nmap -sS -oG out.txt 

107.174.156.124

Host: 107.174.156.124 (107-174-156-124-host.colocrossing.com)   
Status: 
Up
Host: 107.174.156.124 (107-174-156-124-host.colocrossing.com)   
Ports: 
139/filtered/tcp//netbios-ssn///, 
445/filtered/tcp//microsoft-ds///, 
8888/open/tcp//sun-answerbook///    
Ignored State: closed (997)

# Nmap done at Sat Jan 27 15:25:06 2024 
-- 1 IP address (1 host up) scanned in 2.20 seconds

这是我在 jam.local 中的条目

请注意,我已将 SSHD 端口移至 63xxx 范围。我用 xxx 遮盖了最后 3 位数字

#
# JAILS
#

#
# SSH servers
#

[sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
enabled = true
mode = aggressive
port = 63xxx
filter = sshd
logpath = /var/log/auth.log
bantime = 2000000
findtime = 7200
maxretry = 2
backend = %(sshd_backend)s
action = iptables-multiport[name=sshd, port="ssh", protocol=tcp]

fail2ban.local

# Options: dbpurgeage
# Notes.: Sets age at which bans should be purged from the database
# Values: [ SECONDS ] Default: 86400 (24hours)
dbpurgeage = 2100000

身份验证日志示例

例如,192.241.141.43 进行了多次尝试,并且几乎每分钟都会重复一次!

Jan 27 15:54:55 racknerd-64d010 sshd[2232]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.241.141.43  user=root
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Failed password for root from 192.241.141.43 port 54798 ssh2
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Received disconnect from 192.241.141.43 port 54798:11: Bye Bye [preauth]
Jan 27 15:54:57 racknerd-64d010 sshd[2232]: Disconnected from authenticating user root 192.241.141.43 port 54798 [preauth]

fail2ban 示例

例如,fail2ban 表示 192.241.141.43 已被禁止

2024-01-27 15:55:50,928 fail2ban.actions        [29992]: WARNING [sshd] 82.102.12.130 already banned
2024-01-27 15:55:50,929 fail2ban.actions        [29992]: WARNING [sshd] 192.241.141.43 already banned
2024-01-27 15:55:50,929 fail2ban.actions        [29992]: WARNING [sshd] 159.75.161.40 already banned

Iptables 扫描的结果

IP 192.241.141.43 被禁止

    0     0 REJECT     all  --  *      *       61.231.64.170        0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  *      *       192.241.141.43       0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  *      *       104.250.34.177       0.0.0.0/0            reject-with icmp-port-unreachable

附加信息1+2,完整规则集

这是完整规则集文件的链接。

  • iptables_o2.txt
  • auth_2024-01-27m_sample.txt

=== 附加信息摘要

我在这里总结了克里斯·戴维斯的重要意见。我这样做是为了让将来阅读本文的人们能够清楚地知道要在监狱.local 文件的 SSHD Jail 部分中添加哪些内容。

我还包括了fail2ban.local 文件中的单行更改文本 - 再次感谢 Chris。

=== 这是jail.local

#
# 监狱
#

#
# SSH 服务器
#

[sshd]

# 要使用更激进的 sshd 模式,请在 Jail.local 中设置过滤器参数“mode”:
# 正常(默认)、ddos、额外或攻击性(全部组合)。
# 有关使用示例和详细信息,请参阅“tests/files/logs/sshd”或“filter.d/sshd.conf”。
#模式=正常
启用=真
模式=激进
端口 = 22
过滤器=sshd
日志路径 = /var/log/auth.log
班时间 = 2000000
查找时间 = 7200
最大重试次数 = 2
后端 = %(sshd_backend)s
banaction_allports = iptables-allports
action_ap = %(banaction_allports)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="% (链)”]
动作 = %(action_ap)s

=== 这是fail2ban.local

# 选项:dbpurgeage
# 注意:设置应从数据库中清除禁令的年龄
# 值:[ SECONDS ] 默认值:86400(24 小时)
数据库清除 = 2100000
fail2ban
  • 1 个回答
  • 124 Views
Martin Hope
xstack
Asked: 2023-12-30 03:17:40 +0800 CST

使用微型http服务器c代码gcc debian编译错误

  • 5

我的发行版是 MX Linux (Debian) GCC 已经随发行版一起安装了。

我正在尝试编译 Nir ​​Lictman 的一些开源代码。他的Minimalist C Web 服务器代码在他的YouTube 视频中编译。

当我使用gcc编译时,出现错误:

servera.c: In function ‘main’:
servera.c:21:13: warning: passing argument 2 of ‘bind’ from incompatible pointer type [-Wincompatible-pointer-types]
   21 |     bind(s, &addr, sizeof(addr));
      |             ^~~~~
      |             |
      |             struct sockaddr_in *
In file included from servera.c:1:
/usr/include/x86_64-linux-gnu/sys/socket.h:112:49: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
  112 | extern int bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)

当我尝试查看 netinet 的手册页时,出现错误:

$ man netinet
No manual entry for netinet

我确实找到了一个netinet包含in.hat的目录/usr/include/netinet。其in.h定义sockaddr_in如下:

/* Structure describing an Internet socket address.  */
struct sockaddr_in
  {
    __SOCKADDR_COMMON (sin_);
    in_port_t sin_port;         /* Port number.  */
    struct in_addr sin_addr;        /* Internet address.  */

    /* Pad to size of `struct sockaddr'.  */
    unsigned char sin_zero[sizeof (struct sockaddr)
               - __SOCKADDR_COMMON_SIZE
               - sizeof (in_port_t)
               - sizeof (struct in_addr)];
  };

不过我想知道编译器是否找到了这个定义。

c
  • 1 个回答
  • 57 Views

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve