欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

shell 安全腳本的實(shí)現(xiàn)

 更新時(shí)間:2023年01月12日 09:01:31   作者:THE FOOL295  
本文主要介紹了shell 安全腳本的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

題目:

將密碼輸入錯(cuò)誤超過4次的IP地址通過firewalld防火墻阻止訪問

1.初始配置

首先使用systemctl工具啟用firewalld服務(wù):

?[root@localhost ~]# systemctl enable firewalld

如果已經(jīng)啟用了,我們現(xiàn)在可以通過執(zhí)行以下命令啟動(dòng)firewalld:

[root@localhost ~]# systemctl start firewalld

且可以通過運(yùn)行以下命令驗(yàn)證firewalld的狀態(tài)并且以下輸出確認(rèn)了firewalld啟動(dòng)了并且在運(yùn)行:

[root@localhost ~]# systemctl status firewalld

在這里插入圖片描述

2.分析

1、需要知道ssh遠(yuǎn)程訪問記錄在哪個(gè)文件中/var/log/secure
2、模擬遠(yuǎn)程訪問輸錯(cuò)密碼,查看日志文件:

cat /var/log/secure

在這里插入圖片描述

3、了解firewalld添加富規(guī)則的知識(shí):

[root@localhost ~]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.210.133/24" service name="ssh" reject'
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	rule family="ipv4" source address="192.168.210.133/24" service name="ssh" reject

4、回到192.168.210.133上進(jìn)行測(cè)試:

[root@localhost ~]# ssh root@192.168.210.128
ssh: connect to host 192.168.210.128 port 22: Connection refused

5、測(cè)試后將添加的富規(guī)則刪除:

[root@localhost ~]# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.210.133/24" service name="ssh" reject'
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

3.編寫腳本

[root@localhost shell]# vim deny_ip.sh

#!/bin/bash
#*************************************************************
#Author:czc
#Date:  2023-01-09
#FileName: deny_ip.sh
#*************************************************************
serc_log=/avr/log/secure
ip_list=`awk '/Failed password/ {IP[$(NF-3)]++} END{for (k in IP){if (IP[k]>=4) {print k} }}' /var/log/secure`
for ip in `echo $ip_list`
do
        denyed_ip=`firewall-cmd --list-all | awk -F'[= ]' '/rule family/ && $NF="reject" && $(NF-1)~/ssh/ {print $6}' | awk -F'["/]' '{print $2}'`
        echo $denyed_ip | grep -q $ip
        [ $? -ne 0 ] && firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="$ip" service name="ssh" reject"
done

firewall-cmd --reload

[root@localhost shell]# chmod a+rx deny_ip.sh

4.測(cè)試

由于此時(shí)192.168.210.133只輸錯(cuò)密碼3次,因此執(zhí)行腳本后,并未添加富規(guī)則。

在這里插入圖片描述

在這里插入圖片描述

此時(shí)再到192.168.210.133上對(duì)本機(jī)進(jìn)行訪問,累計(jì)達(dá)到4次錯(cuò)誤及以上:[root@localhost ~]# ssh

root@192.168.210.128
root@192.168.210.128's password: 
Permission denied, please try again.
root@192.168.210.128's password: 
Permission denied, please try again.
root@192.168.210.128's password: 

可以看到現(xiàn)在的輸入密碼錯(cuò)誤次數(shù)累計(jì)達(dá)到5次:

在這里插入圖片描述

#此時(shí)在192.168.210.128上執(zhí)行腳本
[root@localhost shell]# ./deny_ip.sh
success
success
[root@localhost shell]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	rule family="ipv4" source address="192.168.210.133" service name="ssh" reject


#再回到192.168.210.133上進(jìn)行測(cè)試

[root@localhost ~]# ssh root@192.168.210.128
ssh: connect to host 192.168.210.128 port 22: Connection refused

至此,腳本的編寫和測(cè)試就完成了。更多相關(guān)shell 安全腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 如何利用shell開發(fā)keepalived啟動(dòng)腳本

    如何利用shell開發(fā)keepalived啟動(dòng)腳本

    Keepalived軟件起初是專為L(zhǎng)VS負(fù)載均衡軟件設(shè)計(jì)的,用來管理并監(jiān)控LVS集群系統(tǒng)中各個(gè)服務(wù)節(jié)點(diǎn)的狀態(tài),后來又加入了可以實(shí)現(xiàn)高可用的VRRP功能。這篇文章主要介紹了使用shell開發(fā)keepalived啟動(dòng)腳本,需要的朋友可以參考下
    2020-03-03
  • Linux shell 實(shí)現(xiàn)用for循環(huán)100次的方法

    Linux shell 實(shí)現(xiàn)用for循環(huán)100次的方法

    今天小編就為大家分享一篇Linux shell 實(shí)現(xiàn)用for循環(huán)100次的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • linux?shell字符串截取的詳細(xì)總結(jié)(實(shí)用!)

    linux?shell字符串截取的詳細(xì)總結(jié)(實(shí)用!)

    在開發(fā)的時(shí)候經(jīng)常會(huì)自行寫一些小的腳本,其中就用到截取字符串的操作,這篇文章主要給大家介紹了關(guān)于linux?shell字符串截取的詳細(xì)方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • Linux命令ifconfig報(bào)錯(cuò)command not found的解決方法

    Linux命令ifconfig報(bào)錯(cuò)command not found的解決方法

    最近在安裝Vmware CentOS,輸入ifconfig查看VM的IP地址,提示command not found,發(fā)現(xiàn)沒安裝命令包,此篇文章記錄整個(gè)問題解決方法,有和小編遇到一樣的問題的小伙伴可以參考閱讀本文
    2023-08-08
  • 淺談shell的一些循環(huán)格式

    淺談shell的一些循環(huán)格式

    這篇文章主要介紹了淺談shell的一些循環(huán)格式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Linux shell腳本全面學(xué)習(xí)入門

    Linux shell腳本全面學(xué)習(xí)入門

    這篇文章主要為大家分享下Linux shell腳本相關(guān)的資料,對(duì)于linux系統(tǒng)中,shell腳本非常實(shí)用并強(qiáng)大
    2013-10-10
  • 在linux shell腳本中root切換到普通用戶執(zhí)行腳本或命令的方法

    在linux shell腳本中root切換到普通用戶執(zhí)行腳本或命令的方法

    今天小編就為大家分享一篇在linux shell腳本中root切換到普通用戶執(zhí)行腳本或命令的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • 高級(jí)開發(fā)運(yùn)維測(cè)試必須掌握的envsubst命令使用詳解

    高級(jí)開發(fā)運(yùn)維測(cè)試必須掌握的envsubst命令使用詳解

    這篇文章主要為大家介紹了高級(jí)開發(fā)運(yùn)維測(cè)試必須掌握的envsubst命令使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • Shell中的for和while循環(huán)詳細(xì)總結(jié)

    Shell中的for和while循環(huán)詳細(xì)總結(jié)

    這篇文章主要介紹了Shell中的for和while循環(huán)詳細(xì)總結(jié),本文講解了for循環(huán)的數(shù)字段形式、詳細(xì)列出、對(duì)文件進(jìn)行循環(huán),while循環(huán)的三種使用場(chǎng)合等內(nèi)容,需要的朋友可以參考下
    2015-05-05
  • linux下數(shù)據(jù)壓縮的幾種方法與查看方式(示例代碼)

    linux下數(shù)據(jù)壓縮的幾種方法與查看方式(示例代碼)

    這篇文章主要介紹了linux下數(shù)據(jù)壓縮的幾種方法與查看方式,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-10-10

最新評(píng)論