Reference

Usage

<aside> 💡 該流程於 2022.09.17 Windows10 系統上測試。

</aside>

<aside> 💡 該流程於 2023.09.17 Windows10 系統上測試。其實防毒軟體本身就會阻擋了。

</aside>

  1. Github release 下載 IPBan-Windows-x64

  2. 解壓縮到 C:/ 目錄下。

  3. 目錄中的 DigitalRuby.IPBan.exe 可以直接執行,會開啟一個 command line 顯示日誌。但我們需要讓他在背景執行。可使用指令設定系統服務,有以下兩種方法。

    1. 使用 Command Prompt

      sc.exe create IPBAN type=own start=delayed-auto binPath=c:\\IPBan\\DigitalRuby.IPBan.exe DisplayName=IPBAN
      sc.exe description IPBAN "Automatically builds firewall rules for abusive login attempts: <https://github.com/DigitalRuby/IPBan>"
      sc.exe start IPBAN
      
    2. 使用 Powershell

      New-Service -Name "IPBAN" -BinaryPathName "c:\\path\\to\\service\\DigitalRuby.IPBan.exe" -StartupType automatic -DisplayName "IPBAN" -Description "Automatically builds firewall rules for abusive login attempts: <https://github.com/DigitalRuby/IPBan>"
      Get-WmiObject win32_service -Filter "name='IPBAN'"
      Start-Service IPBAN
      sc.exe config IPBAN start= delayed-auto
      
  4. 接著可在 windows 搜尋 service,查看 IPBAN 服務是否已開啟,此時即開始於背景執行程式。

  5. 程式的相關設定可以在 ./ipban.config 修改,常見設定如下。

    <!-- 登入失敗幾次進行封鎖 -->
    <add key="FailedLoginAttemptsBeforeBan" value="5"/>
    
    <!-- 封鎖時間,格式 日:時:分:秒 -->
    <add key="BanTime" value="01:00:00:00"/>
    
    <!-- 最後一次登入失敗後要記住的時間,格式 日:時:分:秒 -->
    <add key="ExpireTime" value="01:00:00:00"/>
    
    <!-- 手動封鎖或解除封鎖的生效時間,格式 日:時:分:秒 -->
    <add key="CycleTime" value="00:00:00:15"/>
    
    <!-- 設定使用者名稱的白名單,正常情況下應該要保持空白 -->
    <!-- 除非白名單中的使用者密碼強度足夠 -->
    <add key="UserNameWhitelist" value=""/>
    
  6. 當系統檢測到多次登入失敗的事件,會在日誌上看到訊息,或是可以直接查看 ./logfile.txt 的內容。如來源 IP、嘗試登入的帳號名稱以及次數。

    Get-Content .\\logfile.txt -Tail 10 -wait
    

    Untitled

  7. 如要設定白名單,需要建立一個文字檔,放在 ./unban.txt,裡面放上要解鎖的 IP。會在 15 秒內完成設定,這個白名單也可以用來解除封鎖。輪詢的時間從設定檔中的 CycleTime 設定。

    192.168.0.100
    192.168.0.101
    
  8. 如要手動封鎖,需要建立一個文字檔,放在 ./ban.txt,裡面放上要封鎖的 IP。

    192.168.0.102
    192.168.0.103