亚洲成无码人在线观看丨久久精品国产亚洲77777丨亚洲不卡av一区二区三区丨69麻豆天美精东蜜桃传媒潘甜甜丨久久综合之久久綜合

行業動態

了解最新公司動態及行業資訊

當前位置:首頁>新聞中心>行業動態
全部 4191 公司動態 1055 行業動態 3136

有人會為新安裝的服務器立即設置保護,確保只有你能夠進入

時間:2022-04-28   訪問量:2370

很少有人會立即為新安裝的服務器設置保護,但我們生活的世界使它成為必需品。那么為什么這么多人要等到最后才設置保護呢?我也做過同樣的事情,通常歸結為想要直接去做有趣的事情。希望本文向您展示了保護服務器比您想象的要容易得多,并且當攻擊開始時從堡壘往下看會很有趣。

這篇文章是為 12.04.2 LTS 寫的,但是你可以在其他 Linux 發行版上做類似的事情。

我從哪里開始?

如果服務器已經有公共 IP,您將需要立即鎖定 root 訪問權限。實際上,您需要完全鎖定 SSH 訪問權限,以便只有您可以進入。添加一個新用戶并將這個新用戶添加到一個管理組(在 /etc/ 中預先設置了 sudo 訪問權限)。

## 添加用戶組 admin(譯者注)
$ sudo addgroup admin
Adding group 'admin' (GID 1001)
Done.
## 添加用戶 spenserj(譯者注)
$ sudo adduser spenserj
Adding user `spenserj' ...
Adding new group `spenserj' (1002) ...
Adding new user `spenserj' (1001) with group `spenserj' ...
Creating home directory `/home/spenserj' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for spenserj
Enter the new value, or press ENTER for the default
    Full Name []: Spenser Jones
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n] y
## 追加用戶 spenserj 到用戶組 admin 中(譯者注)
$ sudo usermod -a -G admin spenserj

您還需要在您的計算機上創建一個私鑰并在服務器上禁用密碼驗證。

(公鑰也要加到服務器.sshd文件中,詳見文末參考鏈接第三步。譯者注)

## 本地主機用戶主目錄下新建 .ssh 文件,并將公鑰追加到 authorized_keys(譯者注)
$ mkdir ~/.ssh
$ echo "ssh-rsa [your public key]" > ~/.ssh/authorized_keys
PermitRootLogin no
PermitEmptyPasswords no
PasswordAuthentication no
AllowUsers spenserj

重新加載 SSH 以應用更改,然后嘗試登錄新會話以確保一切正常。如果您無法登錄,您仍然可以使用原始會話來解決問題。

## 重啟 ssh(譯者注)
$ sudo service ssh restart
ssh stop/waiting
ssh start/running, process 1599

更新服務器

現在只有你可以訪問服務器服務器運維,不用擔心黑客潛入,又可以正常呼吸了。您的服務器很可能有一些更新,所以現在開始運行它們。

## 服務器更新(譯者注)
$ sudo apt-get update
...
Hit http://ca.archive.ubuntu.com precise-updates/universe Translation-en_CA
Hit http://ca.archive.ubuntu.com precise-updates/universe Translation-en
Hit http://ca.archive.ubuntu.com precise-backports/main Translation-en
Hit http://ca.archive.ubuntu.com precise-backports/multiverse Translation-en
Hit http://ca.archive.ubuntu.com precise-backports/restricted Translation-en
Hit http://ca.archive.ubuntu.com precise-backports/universe Translation-en
Fetched 3,285 kB in 5s (573 kB/s)
Reading package lists... Done
## 服務器升級(譯者注)
$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
  linux-headers-generic-lts-quantal linux-image-generic-lts-quantal
The following packages will be upgraded:
  accountsservice apport apt apt-transport-https apt-utils aptitude bash ...
73 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Need to get 61.0 MB of archives.
After this operation, 151 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
...
Setting up libisc83 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up libdns81 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up libisccc80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up libisccfg82 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up libbind9-80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up liblwres80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up bind9-host (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up dnsutils (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Setting up iptables (1.4.12-1ubuntu5) ...
...

安裝防火墻

現在正在運行最新的軟件?這很好。繼續構建防火墻,只允許你現在需要的東西。您可以在之后添加一個例外,幾分鐘的額外工作不會讓您崩潰。它是預裝在的,所以先給它設置一些規則。

$ sudo mkdir /etc/iptables
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
# Accept any related or established connections
-I INPUT  1 -m state --state RELATED,ESTABLISHED -j ACCEPT
-I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
# Allow all traffic on the loopback interface
-A INPUT  -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
# Allow outbound DHCP request - Some hosts (Linode) automatically assign the primary IP
#-A OUTPUT -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# Outbound DNS lookups
-A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT
# Outbound PING requests
-A OUTPUT -p icmp -j ACCEPT
# Outbound Network Time Protocol (NTP) request
-A OUTPUT -p udp --dport 123 --sport 123 -j ACCEPT
# SSH
-A INPUT  -i eth0 -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
# Outbound HTTP
-A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
COMMIT

通過 -apply 應用超時規則集,如果連接丟失,請修復規則并在繼續之前重試。

$ sudo iptables-apply /etc/iptables/rules
Applying new ruleset... done.
Can you establish NEW connections to the machine? (y/N) y
... then my job is done. See you next time.

使用以下內容創建文件 /etc//if-pre-up.d/。這將在啟動服務器時自動加載規則。

#!/bin/sh
iptables-restore < /etc/iptables/rules

現在給它執行權限并執行文件以確保它正確加載。

$ sudo chmod +x /etc/network/if-pre-up.d/iptables
$ sudo /etc/network/if-pre-up.d/iptables

想當黑客的人

在安全性方面我最喜歡的工具之一,因為它會監控您的日志文件并暫時禁止濫用資源的用戶,例如強制 SSH 連接或破壞您的網絡服務器。

## 安裝 fail2ban(譯者注)
$ sudo apt-get install fail2ban
[sudo] password for sjones:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  gamin libgamin0 python-central python-gamin python-support whois
Suggested packages:
  mailx
The following NEW packages will be installed:
  fail2ban gamin libgamin0 python-central python-gamin python-support whois
0 upgraded, 7 newly installed, 0 to remove and 2 not upgraded.
Need to get 254 kB of archives.
After this operation, 1,381 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
...

安裝了默認配置(/etc//jail.conf),但我們想在 /etc//jail.local 中進行更改,所以將其復制到那里。

## 拷貝配置(譯者注)
sudo cp /etc/fail2ban/jail.{conf,local}

配置

將線路更改為您的 IP 并決定阻止多長時間(默認為 10 分鐘)。您還需要設置一個,我通常將其設置為我的電子郵件地址并輸入@.de。 .de 是一個跟蹤并自動報告黑客試圖濫用其連接的 IP 的系統。

[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
bantime  = 600
maxretry = 3
# "backend" specifies the backend used to get files modification. Available
# options are "gamin", "polling" and "auto".
# yoh: For some reason Debian shipped python-gamin didn't work as expected
#      This issue left ToDo, so polling is default backend for now
backend = auto
#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = root@localhost,fail2ban@blocklist.de

雖然默認設置就足夠了,但還有一些其他設置需要檢查,因此請快速查看該部分的文件。

允許您對惡意活動做出反應,但默認為禁止,我們希望它禁止并發送電子郵件。幸運的是服務器運維,有一個預配置的可以完成這項工作。

# Choose default action.  To change, just override value of 'action' with the
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_mwl)s

監獄

為了讓它發揮作用,它需要知道該看什么。這是在配置的 Jails 部分中配置的,有許多實例被預加載和禁用。由于到目前為止您只啟用了 SSH 訪問,我們將只啟用 SSH 和 SSH-DDoS 監獄,但您需要為安裝在該服務器上的每個可公開訪問的服務添加一個新的監獄。

[ssh]
enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6
[ssh-ddos]
enabled  = true
port     = ssh
filter   = sshd-ddos
logpath  = /var/log/auth.log
maxretry = 6

應用更改

現在我們已經配置好了,您將重新加載它并確保它向其中添加了適當的規則。

$ sudo service fail2ban restart
 * Restarting authentication failure monitor fail2ban
   ...done.
$ sudo iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
fail2ban-ssh-ddos  tcp  --  anywhere             anywhere             multiport dports ssh
fail2ban-ssh  tcp  --  anywhere             anywhere             multiport dports ssh
...
Chain fail2ban-ssh (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere
Chain fail2ban-ssh-ddos (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

您可以隨時使用 sudo -L 列出您的規則,然后是當前禁止 IP 的列表。目前正在處理兩個惡意IP:

DROP       all  --  204.50.33.22         anywhere
DROP       all  --  195.128.126.114      anywhere

控制世界

現在您的服務器已鎖定并準備就緒,這并不是您安全之旅的終點。密切關注更新(首先在非生產環境中進行測試),始終關閉不需要的端口,定期檢查日志,并了解服務器內外發生的情況。

跟蹤

有一些很好的評論,如果您對不同的視角和更高的安全性感興趣,我建議您閱讀它們。本文旨在作為初學者的安全指南,結束本文并不意味著您的服務器是無懈可擊的。使用本指南快速鎖定新服務器并根據您的獨特情況在其上進行構建。您可能想探索 IPV6 安全性、更改 SSH 端口(通過隱藏)、內核安全性(和 )、跟蹤系統更改并進行全面審核(如果您的服務器曾經不安全,或者已經在線很長時間)。服務器有數百個入口點,您安裝的每個應用程序都可能引入另一個漏洞,但使用正確的工具,您可以放心上床。

參考鏈接:阮一峰Linux服務器的初步配置過程

上一篇:中國5大新型IT技術社區,你都知道哪些?

下一篇:湖北IT公司客服外包智能客服招聘簡章(10月21日)

發表評論:

評論記錄:

未查詢到任何數據!

在線咨詢

點擊這里給我發消息 售前咨詢專員

點擊這里給我發消息 售后服務專員

在線咨詢

免費通話

24小時免費咨詢

請輸入您的聯系電話,座機請加區號

免費通話

微信掃一掃

微信聯系
返回頂部
主站蜘蛛池模板: 雷山县| 天峨县| 介休市| 龙里县| 和静县| 金溪县| 兰考县| 昌吉市| 秀山| 苗栗市| 宁城县| 鄂温| 永善县| 林芝县| 平凉市| 彩票| 犍为县| 曲沃县| 吉木乃县| 屯留县| 汕头市| 法库县| 泗水县| 嘉祥县| 随州市| 太湖县| 沙洋县| 万山特区| 红原县| 息烽县| 长沙县| 海淀区| 平远县| 镇赉县| 嘉义县| 修水县| 株洲县| 云霄县| 三门峡市| 客服| 田林县|