Fail2ban配合Docker使用解决暴力破解
fail2ban 正常使用可以参考 使用Fail2ban抵御暴力破解和cc攻击,但是对于使用了 Docker host 网络的容器来说是不生效的。原因最后说, 我们先复原一下部署情况 环境现状服务器是我自己的服务器,使用 Nginx 做入口,反向代理到不同的后端,后端服务和 Nginx 都是运行在 Docker 里,使用 Docker 的自定义网络进行互联。其中 Nginx 容器使用的是 Host 网络 配置 fail2ban确定 Docker 版 Nginx 日志路径Linux 内一切皆文件,Docker 会将日志写入到主机的一个日志文件中。通过 1docker inspect nginx --format "{{.LogPath}}" 可以查看到容器的日志位置 创建配置文件 /etc/fail2ban/jail.d/nginx-cc.conf123456789[nginx-cc]enabled = trueport = http,httpsfilter = nginx-ccaction =...
使用Fail2ban抵御暴力破解和cc攻击
fail2ban 是一款防止暴力破解和 cc 攻击的开源工具,采用 Python 编写。 常用组件 工具 作用 fail2ban-client 客户端工具 fail2ban-regex 验证正则匹配 1234567891011# 查看启用的规则fail2ban-client status# 查看规则详情fail2ban-client status sshd# 重新加载配置fail2ban-client reload# 手动解禁IPfail2ban-client set sshd unbanip 192.168.1.1 配置文件目录 作用 /etc/fail2ban/jail.d ban 的规则,如多少次触发,触发后封禁多久等 /etc/fail2ban/filter.d 过滤规则,匹配日志的正则配置 规则测试创建配置文件 /etc/fail2ban/jail.d/nginx-cc.conf 123456789[nginx-cc]enabled = trueport =...
Hyper-V 自动创建虚拟机快照
首先要允许 PowerShell 执行本地脚本文件: 1Set-ExecutionPolicy RemoteSigned PowerShell 脚本内容:(文件需要保存成 GB2312 编码,不然中文乱码,执行报错。) 12345678910111213141516171819202122232425262728293031323334353637$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)# 如果不是管理员,以管理员身份重新运行脚本if (-not $isAdmin) { Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File...
Windows下运行服务的几种方式
原生命令 sc微软官方文档: https://learn.microsoft.com/zh-cn/windows-server/administration/windows-commands/sc-create 第三方工具 winsw 2.xhttps://github.com/winsw/winsw/releases/tag/v2.11.0 需要将 winsw 可执行文件和配置文件放在同一目录, 一般放在程序同级目录. 同样以 frpc 为例: service.xml 12345678910111213141516171819202122232425262728293031323334353637383940414243<service> <id>frpc</id> <!-- Display name of the service --> <name>frpc Service (powered by WinSW)</name> <!-- Service description...
Python遍历文件或文件夹
说明root: 当前遍历到的目录, 也就是所在的目录, 字符串dirs: 当前目录下的子目录列表files: 当前目录下的文件列表 比如文件结构 /tmp/1/ : 123451├── file1├── file2├── folder1└── folder2 脚本内容: 1234for root, dirs, files in os.walk("/tmp/1/"): print("root", root) print(dirs) print(files) 输出结果 123456789101112131415161718# 当前的root是/tmp/1/# root下的目录列表为:['folder2', 'folder1']# root下的文件列表为['file2', 'file1']# 遍历到的下一个root, 里面的文件和目录都为空./tmp/1/folder2[][]#...
Python读写文件
使用 Python 读写文件很方便,有多种方法,但是读写大文件还是需要优化的。 python open...
gpg使用记录
要了解什么是 GPG,就要先了解 PGP。 1991 年,程序员 Phil Zimmermann 为了避开政府监视,开发了加密软件 PGP。这个软件非常好用,迅速流传开来,成了许多程序员的必备工具。但是,它是商业软件,不能自由使用。所以,自由软件基金会决定,开发一个 PGP 的替代品,取名为 GnuPG。这就是 GPG 的由来。 GPG 有许多用途,本文主要介绍文件加密。至于邮件的加密,不同的邮件客户端有不同的设置。 当前我的系统环境是 Ubuntu 22.04 gpg 版本是 gpg (GnuPG) 2.2.27。 Key 管理Key ID: 该 GPG Key 的唯一标识,值为主公钥的指纹,支持多种格式 (Fingerprint, Long key ID, Short key ID)。UID: 1 个或多个,每个 UID 由 name、email、comment 组成,email 和 comment 可以为空。Expire: 过期时间,可以为永久。主秘钥和主公钥(Primary Key)、子秘钥和子公钥(Sub Key)都是成对出现的,其用途也是一致的。每一对都包含一个...
使用PowerShell操作Windows Defender
首先需要使用到管理员权限运行 PowerShell 查看排除列表12$WDAVprefs = Get-MpPreference$WDAVprefs.ExclusionPath 排除指定文件夹12345# 两种写法,Set-MpPreference 是直接修改,会覆盖之前的规则powershell.exe -Command 'Set-MpPreference -ExclusionPath "C:\xxx", "D:\yyy"'# Add-MpPreference 是追加配置。Add-MpPreference -ExclusionPath "C:\Program Files (x86)\WinAgent\*" 12# 查看是否生效(Get-MpPreference).ExclusionPath | Select-String "C:\Program Files (x86)\WinAgent\*"
CentOS7更新内核版本
确认当前内核版本1uname -r 安装内核仓库 仓库的官方地址是: http://elrepo.org/tiki/HomePage 12rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.orgyum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm 查看可用的内核列表1yum --disablerepo="*" --enablerepo="elrepo-kernel" list available 安装 LTS 版内核1yum --enablerepo=elrepo-kernel install kernel-lt-devel kernel-lt kernel-lt-tools kernel-lt-tools-libs-devel -y 查看当前系统可用的内核1awk -F\' '$1=="menuentry " {print...
备份MySQL脚本-shell版
备份数据库, 并排除系统库, 使用 mysqldump 1234567891011#!/bin/bashset -euo pipefailmysql_host=10.0.0.187mysql_user=rootmysql_passwd=passwordexclude_databases=information_schema|performance_schema|sys|mysqlecho "开始备份数据库……"mysql -h"${mysql_host}" -u"${mysql_user}" -p"${mysql_passwd}" -N -e "show databases;" | grep -Ev "${exclude_databases}" | xargs mysqldump -h"${mysql_host}"...