{"id":127892,"date":"2018-11-28T08:22:54","date_gmt":"2018-11-28T00:22:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=127892"},"modified":"2018-11-26T10:25:56","modified_gmt":"2018-11-26T02:25:56","slug":"linux-nfs-server-secrity","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-nfs-server-secrity.html","title":{"rendered":"\u5982\u4f55\u52a0\u56falinux NFS \u670d\u52a1\u5b89\u5168\u7684\u65b9\u6cd5"},"content":{"rendered":"

NFS\uff08Network File System\uff09\u662f FreeBSD \u652f\u6301\u7684\u4e00\u79cd\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u5141\u8bb8\u7f51\u7edc\u4e2d\u7684\u8ba1\u7b97\u673a\u4e4b\u95f4\u901a\u8fc7 TCP\/IP \u7f51\u7edc\u5171\u4eab\u8d44\u6e90\u3002\u4e0d\u6b63\u786e\u7684\u914d\u7f6e\u548c\u4f7f\u7528 NFS\uff0c\u4f1a\u5e26\u6765\u5b89\u5168\u95ee\u9898\u3002<\/p>\n

\n
\n
\n
\n
\n
\u6982\u8ff0<\/strong><\/div>\n

NFS \u7684\u4e0d\u5b89\u5168\u6027\uff0c\u4e3b\u8981\u4f53\u73b0\u4e8e\u4ee5\u4e0b 4 \u4e2a\u65b9\u9762:<\/p>\n

    \n
  • \u7f3a\u5c11\u8bbf\u95ee\u63a7\u5236\u673a\u5236<\/li>\n
  • \u6ca1\u6709\u771f\u6b63\u7684\u7528\u6237\u9a8c\u8bc1\u673a\u5236\uff0c\u53ea\u9488\u5bf9 RPC\/Mount \u8bf7\u6c42\u8fdb\u884c\u8fc7\u7a0b\u9a8c\u8bc1<\/li>\n
  • \u8f83\u65e9\u7248\u672c\u7684 NFS \u53ef\u4ee5\u4f7f\u672a\u6388\u6743\u7528\u6237\u83b7\u5f97\u6709\u6548\u7684\u6587\u4ef6\u53e5\u67c4<\/li>\n
  • \u5728 RPC \u8fdc\u7a0b\u8c03\u7528\u4e2d, SUID \u7a0b\u5e8f\u5177\u6709\u8d85\u7ea7\u7528\u6237\u6743\u9650<\/li>\n<\/ul>\n
    \u52a0\u56fa\u65b9\u6848<\/strong><\/div>\n

    \u4e3a\u6709\u6548\u5e94\u5bf9\u4ee5\u4e0a\u5b89\u5168\u9690\u60a3\uff0c\u63a8\u8350\u60a8\u4f7f\u7528\u4e0b\u8ff0\u52a0\u56fa\u65b9\u6848\u3002<\/p>\n

    \u914d\u7f6e\u5171\u4eab\u76ee\u5f55\uff08\/etc\/exports\uff09<\/strong><\/span><\/div>\n

    \u4f7f\u7528 anonuid\uff0canongid \u914d\u7f6e\u5171\u4eab\u76ee\u5f55\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u6302\u8f7d\u5230 NFS \u670d\u52a1\u5668\u7684\u5ba2\u6237\u673a\u4ec5\u5177\u6709\u6700\u5c0f\u6743\u9650\u3002\u4e0d\u8981\u4f7f\u7528 no_root_squash\u3002
    \n\u4f7f\u7528\u7f51\u7edc\u8bbf\u95ee\u63a7\u5236
    \n\u4f7f\u7528\u00a0\u5b89\u5168\u7ec4\u7b56\u7565\u00a0\u6216 iptable \u9632\u706b\u5899\u9650\u5236\u80fd\u591f\u8fde\u63a5\u5230 NFS \u670d\u52a1\u5668\u7684\u673a\u5668\u8303\u56f4\u3002<\/p>\n

    iptables -A INPUT -i eth0 -p TCP -s 192.168.0.0\/24 --dport 111 -j ACCEPT\r\niptables -A INPUT -i eth0 -p UDP -s 192.168.0.0\/24 --dport 111 -j ACCEPT\r\niptables -A INPUT -i eth0 -p TCP -s 140.0.0.0\/8 --dport 111 -j ACCEPT\r\niptables -A INPUT -i eth0 -p UDP -s 140.0.0.0\/8 --dport 111 -j ACCEPT\r\n<\/pre>\n
    \u8d26\u53f7\u9a8c\u8bc1<\/strong><\/span><\/div>\n

    \u4f7f\u7528 Kerberos V5 \u4f5c\u4e3a\u767b\u5f55\u9a8c\u8bc1\u7cfb\u7edf\uff0c\u8981\u6c42\u6240\u6709\u8bbf\u95ee\u4eba\u5458\u4f7f\u7528\u8d26\u53f7\u767b\u5f55\uff0c\u63d0\u9ad8\u5b89\u5168\u6027\u3002<\/p>\n

    \u8bbe\u7f6e NFSD \u7684 COPY \u6570\u76ee<\/strong><\/span><\/div>\n

    \u5728 Linux \u4e2d\uff0cNFSD \u7684 COPY \u6570\u76ee\u5b9a\u4e49\u5728\u542f\u52a8\u6587\u4ef6 \/etc\/rc.d\/init.d\/nfs \u4e2d\uff0c\u9ed8\u8ba4\u503c\u4e3a 8\u3002<\/p>\n

    \u6700\u4f73\u7684 COPY \u6570\u76ee\u4e00\u822c\u53d6\u51b3\u4e8e\u53ef\u80fd\u7684\u5ba2\u6237\u673a\u6570\u76ee\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u6d4b\u8bd5\u6765\u627e\u5230 COPY \u6570\u76ee\u7684\u8fd1\u4f3c\u6700\u4f73\u503c\uff0c\u5e76\u624b\u52a8\u8bbe\u7f6e\u8be5\u53c2\u6570\u3002<\/p>\n

    \u9009\u62e9\u4f20\u8f93\u534f\u8bae<\/strong><\/span><\/div>\n

    \u5bf9\u4e8e\u4e0d\u540c\u7684\u7f51\u7edc\u60c5\u51b5\uff0c\u6709\u9488\u5bf9\u5730\u9009\u62e9 UDP \u6216 TCP \u4f20\u8f93\u534f\u8bae\u3002\u4f20\u8f93\u534f\u8bae\u53ef\u4ee5\u81ea\u52a8\u9009\u62e9\uff0c\u4e5f\u53ef\u4ee5\u624b\u52a8\u8bbe\u7f6e\u3002<\/p>\n

    mount -t nfs -o sync,tcp,noatime,rsize=1024,wsize=1024 EXPORT_MACHINE:\/EXPORTED_DIR \/DIR<\/pre>\n

    UDP \u534f\u8bae\u4f20\u8f93\u901f\u5ea6\u5feb\uff0c\u975e\u8fde\u63a5\u4f20\u8f93\u65f6\u4fbf\u6377\uff0c\u4f46\u5176\u4f20\u8f93\u7a33\u5b9a\u6027\u4e0d\u5982 TCP\uff0c\u5f53\u7f51\u7edc\u4e0d\u7a33\u5b9a\u6216\u8005\u9ed1\u5ba2\u5165\u4fb5\u65f6\u5f88\u5bb9\u6613\u4f7f NFS \u6027\u80fd\u5927\u5e45\u964d\u4f4e\uff0c\u751a\u81f3\u5bfc\u81f4\u7f51\u7edc\u762b\u75ea\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 TCP \u7684 NFS \u6bd4\u8f83\u7a33\u5b9a\uff0c\u4f7f\u7528 UDP \u7684 NFS \u901f\u5ea6\u8f83\u5feb\u3002<\/p>\n

      \n
    • \u5728\u673a\u5668\u8f83\u5c11\uff0c\u7f51\u7edc\u72b6\u51b5\u8f83\u597d\u7684\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 UDP \u534f\u8bae\u80fd\u5e26\u6765\u8f83\u597d\u7684\u6027\u80fd\u3002<\/li>\n
    • \u5f53\u673a\u5668\u8f83\u591a\uff0c\u7f51\u7edc\u60c5\u51b5\u590d\u6742\u65f6\uff0c\u63a8\u8350\u4f7f\u7528 TCP \u534f\u8bae\uff08V2 \u53ea\u652f\u6301 UDP \u534f\u8bae\uff09\u3002<\/li>\n
    • \u5728\u5c40\u57df\u7f51\u4e2d\u4f7f\u7528 UDP \u534f\u8bae\u8f83\u597d\uff0c\u56e0\u4e3a\u5c40\u57df\u7f51\u6709\u6bd4\u8f83\u7a33\u5b9a\u7684\u7f51\u7edc\u4fdd\u8bc1\uff0c\u4f7f\u7528 UDP \u53ef\u4ee5\u5e26\u6765\u66f4\u597d\u7684\u6027\u80fd\u3002<\/li>\n
    • \u5728\u5e7f\u57df\u7f51\u4e2d\u63a8\u8350\u4f7f\u7528 TCP \u534f\u8bae\uff0cTCP \u534f\u8bae\u80fd\u8ba9 NFS \u5728\u590d\u6742\u7684\u7f51\u7edc\u73af\u5883\u4e2d\u4fdd\u6301\u6700\u597d\u7684\u4f20\u8f93\u7a33\u5b9a\u6027\u3002<\/li>\n<\/ul>\n
      \u9650\u5236\u5ba2\u6237\u673a\u6570\u91cf<\/strong><\/span><\/div>\n

      \u4fee\u6539 \/etc\/hosts.allow \u548c \/etc \/hosts.deny \u6765\u9650\u5236\u5ba2\u6237\u673a\u6570\u91cf\u3002<\/p>\n

      \/etc\/hosts.allow\r\nportmap: 192.168.0.0\/255.255.255.0 : allow\r\nportmap: 140.116.44.125 : allow\r\n\/etc\/hosts.deny\r\nportmap: ALL : deny<\/pre>\n
      \u6539\u53d8\u9ed8\u8ba4\u7684 NFS \u7aef\u53e3<\/strong><\/span><\/div>\n

      NFS \u9ed8\u8ba4\u4f7f\u7528\u7684\u662f 111 \u7aef\u53e3\uff0c\u4f7f\u7528 port \u53c2\u6570\u53ef\u4ee5\u6539\u53d8\u8fd9\u4e2a\u7aef\u53e3\u503c\u3002\u6539\u53d8\u9ed8\u8ba4\u7aef\u53e3\u503c\u80fd\u591f\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u589e\u5f3a\u5b89\u5168\u6027\u3002<\/p>\n

      \u914d\u7f6e nosuid \u548c noexec<\/strong><\/span><\/div>\n

      SUID (Set User ID) \u6216 SGID (Set Group ID) \u7a0b\u5e8f\u53ef\u4ee5\u8ba9\u666e\u901a\u7528\u6237\u4ee5\u8d85\u8fc7\u81ea\u5df1\u6743\u9650\u6765\u6267\u884c\u3002\u5f88\u591a SUID\/SGID \u53ef\u6267\u884c\u7a0b\u5e8f\u662f\u5fc5\u987b\u7684\uff0c\u4f46\u4e5f\u53ef\u80fd\u88ab\u4e00\u4e9b\u6076\u610f\u7684\u672c\u5730\u7528\u6237\u5229\u7528\uff0c\u83b7\u53d6\u672c\u4e0d\u5e94\u6709\u7684\u6743\u9650\u3002<\/p>\n

      \u5c3d\u91cf\u51cf\u5c11\u6240\u6709\u8005\u662f root\uff0c\u6216\u662f\u5728 root \u7ec4\u4e2d\u5374\u62e5\u6709 SUID\/SGID \u5c5e\u6027\u7684\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u5220\u9664\u8fd9\u6837\u7684\u6587\u4ef6\u6216\u66f4\u6539\u5176\u5c5e\u6027\uff0c\u5982\uff1a<\/p>\n

      \u4f7f\u7528 nosuid \u9009\u9879\u7981\u6b62 set-UID \u7a0b\u5e8f\u5728 NFS \u670d\u52a1\u5668\u4e0a\u8fd0\u884c\uff0c\u53ef\u4ee5\u5728 \/etc\/exports \u52a0\u5165\u4e00\u884c\uff1a<\/p>\n

      \/www www.abc.com(rw, root_squash, nosuid)<\/pre>\n

      \u4f7f\u7528 noexec \u7981\u6b62\u76f4\u63a5\u6267\u884c\u5176\u4e2d\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

      NFS\uff08Network File System\uff09\u662f FreeBSD \u652f\u6301\u7684\u4e00\u79cd\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u5141\u8bb8\u7f51\u7edc\u4e2d\u7684\u8ba1\u7b97\u673a\u4e4b […]<\/p>\n","protected":false},"author":643,"featured_media":127903,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-127892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=127892"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127892\/revisions"}],"predecessor-version":[{"id":128981,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/127892\/revisions\/128981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/127903"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=127892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=127892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=127892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}