[轉載] Linux 網絡安全技巧

顯示結果從第 1 筆 到 2 筆,共計 2 筆
  1. #1
    會員 塵緣 的大頭照
    註冊日期
    2001-05-05
    討論區文章
    258

    [轉載] Linux 網絡安全技巧

    作者會員名﹕wangsb  Email:[email protected]


      網絡安全是一個非常重要的課題,基本上你運行的服務後台越多,你就可能打開更多的安全漏洞.
    如果配置的恰當的話,Linux本身是非常安全可靠的,假使在Linux系統中有某個安全缺陷,
    由於Linux的源碼是開放的,有成千上萬的誌願者會立刻發現並修補它。
    本文旨在介紹用來增強你的網絡安全性的常用技巧,以Redhat Linux作為操作環境。

    1.操作系統內部的log file是檢測是否有網絡入侵的重要線索,
    當然這個假定你的logfile不被侵入者所破壞,如果你有台服務器用專線直接連到Internet上,
    這意味著你的IP地址是永久固定的地址,你會發現有很多人對你的系統做telnet/ftp登錄嘗試,
    試著運行#more /var/log/secure | grep refused 去檢查。

    2. 限製具有SUID權限標誌的程序數量,具有該權限標誌的程序以root身份運行,是一個潛在的安全漏洞,
    當然,有些程序是必須要具有該標誌的,象passwd程序。

    3.BIOS安全。設置BIOS密碼且修改引導次序禁止從軟盤啟動系統。

    4. 用戶口令。用戶口令是Linux安全的一個最基本的起點,很多人使用的用戶口令就是簡單的‘password,
    這等於給侵入者敞開了大門,雖然從理論上說沒有不能確解的用戶口令,只要有足夠的時間和資源可以利用。
    比較好的用戶口令是那些只有他自己能夠容易記得並理解的一串字符,並且絕對不要在任何地方寫出來。

    5./etc/exports 文件。如果你使用NFS網絡文件系統服務,那麼確保你的/etc/exports
    具有最嚴格的存取權限設置,這意味著不要使用任何通配符,不允許root寫權限,mount成只讀文件系統。
    編輯文件/etc/exports並且加﹕例如﹕
      /dir/to/export host1.mydomain.com(ro,root_squash)
      /dir/to/export host2.mydomain.com(ro,root_squash)
      /dir/to/export 是你想輸出的目錄,host.mydomain.com是登錄這個目錄的機器名,
    ro意味著mount成只讀系統,root_squash禁止root寫入該目錄。
      為了讓上面的改變生效,運行/usr/sbin/exportfs -a

    6.確信/etc/inetd.conf的所有者是root,且文件權限設置為600 。
    [root@deep]# chmod 600 /etc/inetd.conf
    ENSURE that the owner is root.
    [root@deep]# stat /etc/inetd.conf
    File: "/etc/inetd.conf"
    Size: 2869 Filetype: Regular File
    Mode: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
    Device: 8,6 Inode: 18219 Links: 1
    Access: Wed Sep 22 16:24:16 1999(00000.00:10:44)
    Modify: Mon Sep 20 10:22:44 1999(00002.06:12:16)
    Change:Mon Sep 20 10:22:44 1999(00002.06:12:16)
    編輯/etc/inetd.conf禁止以下服務﹕
    ftp, telnet, shell, login, exec, talk, ntalk, imap, pop-2, pop-3, finger, auth, etc.
    除非你真的想用它。特別是禁止那些r命令.如果你用ssh/scp,那麼你也可以禁止掉telnet/ftp。
    為了使改變生效,運行#killall -HUP inetd 你也可以運行#chattr +i /etc/inetd.conf使該文件具有
    不可更改屬性。只有root 才能解開,用命令 #chattr -i /etc/inetd.conf

    7. TCP_WRAPPERS
    默認地,Redhat Linux允許所有的請求,用TCP_WRAPPERS增強你的站點的安全性是舉手之勞,你可以放入
    “ALL: ALL”到/etc/hosts.deny中禁止所有的請求,然後放那些明確允許的請求到/etc/hosts.allow中,
    如: sshd: 192.168.1.10/255.255.255.0 gate.openarch.com
    對IP地址192.168.1.10和主機名gate.openarch.com,允許通過ssh連接。配置完了之後,用tcpdchk檢查
    [root@deep]# tcpdchk
    tcpchk是TCP_Wrapper配置檢查工具,它檢查你的tcp wrapper配置並報告所有發現的潛在/存在的問題。

    8. 別名文件aliases
    編輯別名文件/etc/aliases(也可能是/etc/mail/aliases),移走/注釋掉下面的行。
    # Basic system aliases -- these MUST be present.
    MAILER-DAEMON: postmaster
    postmaster: root
    # General redirections for pseudo accounts.
    bin: root
    daemon: root
    #games: root ?remove or comment out.
    #ingres: root ?remove or comment out.
    nobody: root
    #system: root ?remove or comment out.
    #toor: root ?remove or comment out.
    #uucp: root ?remove or comment out.
    # Well-known aliases.
    #manager: root ?remove or comment out.
    #dumper: root ?remove or comment out.
    #operator: root ?remove or comment out.
    # trap decode to catch security attacks
    #decode: root
    # Person who should get roots mail
    #root: marc
    最後更新後不要忘記運行/usr/bin/newaliases,使改變生效。

    9.阻止你的系統響應任何從外部/內部來的ping請求。
    既然沒有人能ping通你的機器並收到響應,你可以大大增強你的站點的安全性。
    你可以加下面的一行命令到/etc/rc.d/rc.local,以使每次啟動後自動運行。
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

    10. 不要顯示出操作系統和版本信息。
    如果你希望某個人遠程登錄到你的服務器時不要顯示操作系統和版本信息,你能改變
    /etc/inetd.conf中的一行象下面這樣﹕
    telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd -h
    加-h標誌在最後使得telnet後台不要顯示系統信息,而僅僅顯示login:

    11.The /etc/host.conf file
    編輯host.conf文件(vi /etc/host.conf)且加下面的行﹕
    # Lookup names via DNS first then fall back to /etc/hosts.
    order bind,hosts
    # We don have machines with multiple IP addresses on the same card
    (like virtual server,IP Aliasing).
    multi off
    # Check for IP address spoofing.
    nospoof on
    IP Spoofing: IP-Spoofing is a security exploit that works by tricking
    computers in a trust relationship that you are someone that you really aren .

    12. The /etc/securetty file
    該文件指定了允許root登錄的tty設備,/etc/securetty被/bin/login程序讀取,
    它的格式是一行一個被允許的名字列表,如你可以編輯/etc/securetty且注釋出下面的行。
    tty1
    #tty2
    #tty3
    #tty4
    #tty5
    #tty6
    #tty7
    #tty8
    -意味著root僅僅被允許在tty1終端登錄。

    13. 特別的帳號
    禁止所有默認的被操作系統本身啟動的且不需要的帳號,當你第一次裝上系統時就應該做此檢查,
    Linux提供了各種帳號,你可能不需要,如果你不需要這個帳號,就移走它,你有的帳號越多,
    就越容易受到攻擊。
    為刪除你系統上的用戶,用下面的命令﹕
    [root@deep]# userdel username
    為刪除你系統上的組用戶帳號,用下面的命令﹕
    [root@deep]# groupdel username
    在終端上打入下面的命令刪掉下面的用戶。
    [root@deep]# userdel adm
    [root@deep]# userdel lp
    [root@deep]# userdel sync
    [root@deep]# userdel shutdown
    [root@deep]# userdel halt
    [root@deep]# userdel mail
    如果你不用sendmail服務器,procmail.mailx,就刪除這個帳號。
    [root@deep]# userdel news
    [root@deep]# userdel uucp
    [root@deep]# userdel operator
    [root@deep]# userdel games
    如果你不用X windows 服務器,就刪掉這個帳號。
    [root@deep]# userdel gopher
    [root@deep]# userdel ftp
    如果你不允許匿名FTP,就刪掉這個用戶帳號。
    ===
    打入下面的命令刪除組帳號
    [root@deep]# groupdel adm
    [root@deep]# groupdel lp
    [root@deep]# groupdel mail
    如不用Sendmail服務器,刪除這個組帳號
    [root@deep]# groupdel news
    [root@deep]# groupdel uucp
    [root@deep]# groupdel games
    如你不用X Windows,刪除這個組帳號
    [root@deep]# groupdel dip
    [root@deep]# groupdel pppusers
    [root@deep]# groupdel popusers
    如果你不用POP服務器,刪除這個組帳號
    [root@deep]# groupdel slipusers
    ====
    用下面的命令加需要的用戶帳號
    [root@deep]# useradd username
    用下面的命令改變用戶口令
    [root@deep]# passwd username
    用chattr命令給下面的文件加上不可更改屬性。
    [root@deep]# chattr +i /etc/passwd
    [root@deep]# chattr +i /etc/shadow
    [root@deep]# chattr +i /etc/group
    [root@deep]# chattr +i /etc/gshadow

    14. 阻止任何人su作為root.
    如果你不想任何人能夠su作為root,你能編輯/etc/pam.d/su加下面的行﹕
    auth sufficient /lib/security/pam_rootok.so debug
    auth required /lib/security/pam_wheel.so group=isd
    意味著僅僅isd組的用戶可以su作為root. 然後,如果你希望用戶admin能su作為root.就運行下面的命令。
    [root@deep]# usermod -G10 admin

    16. 資源限製
    對你的系統上所有的用戶設置資源限製可以防止DoS類型攻擊(denial of service attacks)如最大進程數,
    內存數量等。例如,對所有用戶的限製象下面這樣﹕
    編輯/etc/security/limits.con加﹕
    * hard core 0
    * hard rss 5000
    * hard nproc 20
    你也必須編輯/etc/pam.d/login文件加/檢查這一行的存在。
    session required /lib/security/pam_limits.so
    上面的命令禁止core files“core 0”,限製進程數為“nproc 50“,且限製內存使用
    為5M“rss 5000”。

    17. The /etc/lilo.conf file
    a) Add: restricted
    加這一行到每一個引導映像下面,就這表明如果你引導時用(linux single),則需要一個password.
    b) Add: password=some_password
    當與restricted聯合用,且正常引導時,需要用戶輸入密碼,你也要確保lilo.conf
    文件不能被不屬於root的用戶可讀,也免看到密碼明文。下面是例子﹕
    編輯/etc/lilo.conf加﹕
    ====
    boot=/dev/sda
    map=/boot/map
    install=/boot/boot.b
    prompt
    timeout=50
    Default=linux
    restricted ?add this line.
    password=some_password ?add this line.
    image=/boot/vmlinuz-2.2.12-20
    label=linux
    initrd=/boot/initrd-2.2.12-10.img
    root=/dev/sda6
    read-only
    [root@deep]# chmod 600 /etc/lilo.conf (不再能被其他用戶可讀).
    [root@deep]# /sbin/lilo -v (更新lilo配置).
    [root@deep]# chattr +i /etc/lilo.conf(阻止該文件被修改)

    18. 禁止 Control-Alt-Delete 重啟動機器命令
    [root@deep]# vi /etc/inittab
    ca::ctrlaltdel:/sbin/shutdown -t3 -r now
    To
    #ca::ctrlaltdel:/sbin/shutdown -t3 -r now
    [root@deep]# /sbin/init q

    19. 重新設置/etc/rc.d/init.d/目錄下所有文件的許可權限
    [root@deep]# chmod -R 700 /etc/rc.d/init.d/*
    僅僅root可以讀,寫,執行上述所有script file.

    20. The /etc/rc.d/rc.local file
    默認地,當你login到linux server時,它告訴你linux版本名,內核版本名和服務器主機名。
    它給了你太多的信息,如果你就希望得到提示login: ,編輯/etc/rc.d/rc.local放#在下面的行前面﹕
    --
    # This will overwrite /etc/issue at every boot. So, make any changes you
    # want to make to /etc/issue here or you will lose them when you reboot.
    #echo "" > /etc/issue
    #echo "$R" >> /etc/issue
    #echo "Kernel $(uname -r) on $a $(uname -m)" >> /etc/issue
    #
    #cp -f /etc/issue /etc/issue.net
    #echo >> /etc/issue
    --
    然後,做下面的事情:
    [root@deep]# rm -f /etc/issue
    [root@deep]# rm -f /etc/issue.net
    [root@deep]# touch /etc/issue
    [root@deep]# touch /etc/issue.net

    21. 被root擁有的程序的位。
    移走那些被root擁有程序的s位標誌,當然有些程序需要這個,用命令‘chmod a-s’完成這個。
    注﹕前面帶(*)號的那些程序一般不需要擁有s位標誌。
    [root@deep]# find / -type f ( -perm -04000 -o -perm -02000 ) -exec ls 每lg {} ;
    -rwsr-xr-x 1 root root 33120 Mar 21 1999 /usr/bin/at
    *-rwsr-xr-x 1 root root 30560 Apr 15 20:03 /usr/bin/chage
    *-rwsr-xr-x 1 root root 29492 Apr 15 20:03 /usr/bin/gpasswd
    -rwsr-xr-x 1 root root 3208 Mar 22 1999 /usr/bin/disable-paste
    -rwxr-sr-x 1 root man 32320 Apr 9 1999 /usr/bin/man
    -r-s--x--x 1 root root 10704 Apr 14 17:21 /usr/bin/passwd
    -rws--x--x 2 root root 517916 Apr 6 1999 /usr/bin/suidperl
    -rws--x--x 2 root root 517916 Apr 6 1999 /usr/bin/sperl5.00503
    -rwxr-sr-x 1 root mail 11432 Apr 6 1999 /usr/bin/lockfile
    -rwsr-sr-x 1 root mail 64468 Apr 6 1999 /usr/bin/procmail
    -rwsr-xr-x 1 root root 21848 Aug 27 11:06 /usr/bin/crontab
    -rwxr-sr-x 1 root slocate 15032 Apr 19 14:55 /usr/bin/slocate
    *-r-xr-sr-x 1 root tty 6212 Apr 17 11:29 /usr/bin/wall
    *-rws--x--x 1 root root 14088 Apr 17 12:57 /usr/bin/chfn
    *-rws--x--x 1 root root 13800 Apr 17 12:57 /usr/bin/chsh
    *-rws--x--x 1 root root 5576 Apr 17 12:57 /usr/bin/newgrp
    *-rwxr-sr-x 1 root tty 8392 Apr 17 12:57 /usr/bin/write
    -rwsr-x--- 1 root squid 14076 Oct 7 14:48 /usr/lib/squid/pinger
    -rwxr-sr-x 1 root utmp 15587 Jun 9 09:30 /usr/sbin/utempter
    *-rwsr-xr-x 1 root root 5736 Apr 19 15:39 /usr/sbin/usernetctl
    *-rwsr-xr-x 1 root bin 16488 Jul 6 09:35 /usr/sbin/traceroute
    -rwsr-sr-x 1 root root 299364 Apr 19 16:38 /usr/sbin/sendmail
    -rwsr-xr-x 1 root root 34131 Apr 16 18:49 /usr/libexec/pt_chown
    -rwsr-xr-x 1 root root 13208 Apr 13 14:58 /bin/su
    *-rwsr-xr-x 1 root root 52788 Apr 17 15:16 /bin/mount
    *-rwsr-xr-x 1 root root 26508 Apr 17 20:26 /bin/umount
    *-rwsr-xr-x 1 root root 17652 Jul 6 09:33 /bin/ping
    -rwsr-xr-x 1 root root 20164 Apr 17 12:57 /bin/login
    *-rwxr-sr-x 1 root root 3860 Apr 19 15:39 /sbin/netreport
    -r-sr-xr-x 1 root root 46472 Apr 17 16:26 /sbin/pwdb_chkpwd
    [root@deep]# chmod a-s /usr/bin/chage
    [root@deep]# chmod a-s /usr/bin/gpasswd
    [root@deep]# chmod a-s /usr/bin/wall
    [root@deep]# chmod a-s /usr/bin/chfn
    [root@deep]# chmod a-s /usr/bin/chsh
    [root@deep]# chmod a-s /usr/bin/newgrp
    [root@deep]# chmod a-s /usr/bin/write
    [root@deep]# chmod a-s /usr/sbin/usernetctl
    [root@deep]# chmod a-s /usr/sbin/traceroute
    [root@deep]# chmod a-s /bin/mount
    [root@deep]# chmod a-s /bin/umount
    [root@deep]# chmod a-s /bin/ping
    [root@deep]# chmod a-s /sbin/netreport

    你可以用下面的命令查找所有帶s位標誌的程序﹕
    [root@deep]# find / -type f ( -perm -04000 -o -perm -02000 ) -exec ls -lg {} ;
    > suid-sgid-results
    把結果輸出到文件suid-sgid-results中。
    為了查找所有可寫的文件和目錄,用下面的命令﹕
    [root@deep]# find / -type f ( -perm -2 -o -perm -20 ) -exec ls -lg {} ; > ww-files-results
    [root@deep]# find / -type d ( -perm -2 -o -perm -20 ) -exec ls -ldg {} ; > ww-directories-results
    用下面的命令查找沒有擁有者的文件﹕
    [root@deep]# find / -nouser -o -nogroup > unowed-results
    用下面的命令查找所有的.rhosts文件﹕
    [root@deep]# find /home -name .rhosts > rhost-results



  2. #2
    會員
    註冊日期
    2001-11-26
    討論區文章
    47
    ^^think you ..

類似的主題

  1. 【新聞】微軟已在大陸成立資訊安全技術中心
    作者:TAIWAN 所在討論版:-- 防 駭 / 防 毒 版
    回覆: 3
    最後發表: 2004-01-25, 01:52 AM
  2. 【轉貼】新式攻擊需以新安全技術因應 (CNET)
    作者:天氣預報 所在討論版:-- 防 駭 / 防 毒 版
    回覆: 0
    最後發表: 2003-11-18, 07:29 PM
  3. 【求助】關於"IE的安全技術"之文章
    作者:xyzk1 所在討論版:-- 網 路 軟 體 討 論 一 版 (Browser,Email
    回覆: 2
    最後發表: 2002-11-01, 09:09 PM
  4. 綠盟科技.網路安全技術探討.簡體
    作者:iget 所在討論版:-- 優 質 網 站 分 享
    回覆: 0
    最後發表: 2001-05-17, 06:07 PM

 

此網頁沒有從搜尋引擎而來的訪客

發表文章規則

  • 不可以發表新主題
  • 不可以回覆文章
  • 不可以上傳附加檔案
  • 不可以編輯自己的文章
  •