{"id":160409,"date":"2019-10-20T10:17:59","date_gmt":"2019-10-20T02:17:59","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=160409"},"modified":"2019-09-28T11:19:13","modified_gmt":"2019-09-28T03:19:13","slug":"layout-linux-randomization","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/layout-linux-randomization.html","title":{"rendered":"\u7b80\u8ff0ASLR\u4fdd\u62a4 Linux \u7cfb\u7edf\u514d\u53d7\u7f13\u51b2\u533a\u6ea2\u51fa\u653b\u51fb\u7684\u539f\u7406"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5730\u5740\u7a7a\u95f4\u968f\u673a\u5316\uff08ASLR\uff09\u662f\u4e00\u79cd\u5185\u5b58\u653b\u51fb\u7f13\u89e3\u6280\u672f\uff0c\u53ef\u4ee5\u7528\u4e8e Linux \u548c Windows \u7cfb\u7edf\u3002\u4e86\u89e3\u4e00\u4e0b\u5982\u4f55\u8fd0\u884c\u5b83\u3001\u542f\u7528\/\u7981\u7528\u5b83\uff0c\u4ee5\u53ca\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5730\u5740\u7a7a\u95f4\u968f\u673a\u5316Address Space Layout Randomization\uff08ASLR\uff09\u662f\u4e00\u79cd\u64cd\u4f5c\u7cfb\u7edf\u7528\u6765\u62b5\u5fa1\u7f13\u51b2\u533a\u6ea2\u51fa\u653b\u51fb\u7684\u5185\u5b58\u4fdd\u62a4\u673a\u5236\u3002\u8fd9\u79cd\u6280\u672f\u4f7f\u5f97\u7cfb\u7edf\u4e0a\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684\u5185\u5b58\u5730\u5740\u65e0\u6cd5\u88ab\u9884\u6d4b\uff0c\u4f7f\u5f97\u4e0e\u8fd9\u4e9b\u8fdb\u7a0b\u6709\u5173\u7684\u6f0f\u6d1e\u53d8\u5f97\u66f4\u52a0\u96be\u4ee5\u5229\u7528\u3002<\/p>\n

ASLR \u76ee\u524d\u5728 Linux\u3001Windows \u4ee5\u53ca MacOS \u7cfb\u7edf\u4e0a\u90fd\u6709\u4f7f\u7528\u3002\u5176\u6700\u65e9\u51fa\u73b0\u5728 2005 \u7684 Linux \u7cfb\u7edf\u4e0a\u30022007 \u5e74\uff0c\u8fd9\u9879\u6280\u672f\u88ab Windows \u548c MacOS \u90e8\u7f72\u4f7f\u7528\u3002\u5c3d\u7ba1 ASLR \u5728\u5404\u4e2a\u7cfb\u7edf\u4e0a\u90fd\u63d0\u4f9b\u76f8\u540c\u7684\u529f\u80fd\uff0c\u5374\u6709\u7740\u4e0d\u540c\u7684\u5b9e\u73b0\u3002<\/p>\n

ASLR \u7684\u6709\u6548\u6027\u4f9d\u8d56\u4e8e\u6574\u4e2a\u5730\u5740\u7a7a\u95f4\u5e03\u5c40\u662f\u5426\u5bf9\u4e8e\u653b\u51fb\u8005\u4fdd\u6301\u672a\u77e5\u3002\u6b64\u5916\uff0c\u53ea\u6709\u7f16\u8bd1\u65f6\u4f5c\u4e3a\u4f4d\u7f6e\u65e0\u5173\u53ef\u6267\u884c\u6587\u4ef6Position Independent Executable\uff08PIE\uff09\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u624d\u80fd\u5f97\u5230 ASLR \u6280\u672f\u7684\u6700\u5927\u4fdd\u62a4\uff0c\u56e0\u4e3a\u53ea\u6709\u8fd9\u6837\uff0c\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6240\u6709\u4ee3\u7801\u8282\u533a\u624d\u4f1a\u88ab\u52a0\u8f7d\u5728\u968f\u673a\u5730\u5740\u3002PIE \u673a\u5668\u7801\u4e0d\u7ba1\u7edd\u5bf9\u5730\u5740\u662f\u591a\u5c11\u90fd\u53ef\u4ee5\u6b63\u786e\u6267\u884c\u3002<\/p>\n

ASLR \u7684\u5c40\u9650\u6027<\/strong><\/div>\n

\u5c3d\u7ba1 ASLR \u4f7f\u5f97\u5bf9\u7cfb\u7edf\u6f0f\u6d1e\u7684\u5229\u7528\u66f4\u52a0\u56f0\u96be\u4e86\uff0c\u4f46\u5176\u4fdd\u62a4\u7cfb\u7edf\u7684\u80fd\u529b\u662f\u6709\u9650\u7684\u3002\u7406\u89e3\u5173\u4e8e ASLR \u7684\u4ee5\u4e0b\u51e0\u70b9\u662f\u5f88\u91cd\u8981\u7684\uff1a<\/p>\n

\u5b83\u4e0d\u80fd\u89e3\u51b3\u6f0f\u6d1e\uff0c\u800c\u662f\u589e\u52a0\u5229\u7528\u6f0f\u6d1e\u7684\u96be\u5ea6<\/p>\n

\u5e76\u4e0d\u8ffd\u8e2a\u6216\u62a5\u544a\u6f0f\u6d1e<\/p>\n

\u4e0d\u80fd\u5bf9\u7f16\u8bd1\u65f6\u6ca1\u6709\u5f00\u542f ASLR \u652f\u6301\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u63d0\u4f9b\u4fdd\u62a4<\/p>\n

\u4e0d\u80fd\u907f\u514d\u88ab\u7ed5\u8fc7<\/p>\n

ASLR \u662f\u5982\u4f55\u5de5\u4f5c\u7684<\/strong><\/div>\n

\u901a\u8fc7\u5bf9\u653b\u51fb\u8005\u5728\u8fdb\u884c\u7f13\u51b2\u533a\u6ea2\u51fa\u653b\u51fb\u65f6\u6240\u8981\u7528\u5230\u7684\u5185\u5b58\u5e03\u5c40\u4e2d\u7684\u504f\u79fb\u505a\u4e86\u968f\u673a\u5316\uff0cASLR \u52a0\u5927\u4e86\u653b\u51fb\u6210\u529f\u7684\u96be\u5ea6\uff0c\u4ece\u800c\u589e\u5f3a\u4e86\u7cfb\u7edf\u7684\u63a7\u5236\u6d41\u5b8c\u6574\u6027\u3002<\/p>\n

\u901a\u5e38\u8ba4\u4e3a ASLR \u5728 64 \u4f4d\u7cfb\u7edf\u4e0a\u6548\u679c\u66f4\u597d\uff0c\u56e0\u4e3a 64 \u4f4d\u7cfb\u7edf\u63d0\u4f9b\u4e86\u66f4\u5927\u7684\u71b5\uff08\u53ef\u968f\u673a\u7684\u5730\u5740\u8303\u56f4\uff09\u3002<\/p>\n

ASLR \u662f\u5426\u6b63\u5728\u4f60\u7684 Linux \u7cfb\u7edf\u4e0a\u8fd0\u884c\uff1f<\/strong><\/div>\n

\u4e0b\u9762\u5c55\u793a\u7684\u4e24\u6761\u547d\u4ee4\u90fd\u53ef\u4ee5\u544a\u8bc9\u4f60\u7684\u7cfb\u7edf\u662f\u5426\u542f\u7528\u4e86 ASLR \u529f\u80fd\uff1a<\/p>\n

$ cat \/proc\/sys\/kernel\/randomize_va_space\r\n2\r\n$ sysctl -a --pattern randomize\r\nkernel.randomize_va_space = 2<\/pre>\n

\u4e0a\u65b9\u6307\u4ee4\u7ed3\u679c\u4e2d\u7684\u6570\u503c\uff082\uff09\u8868\u793a ASLR \u5de5\u4f5c\u5728\u5168\u968f\u673a\u5316\u6a21\u5f0f\u3002\u5176\u53ef\u80fd\u4e3a\u4e0b\u9762\u7684\u51e0\u4e2a\u6570\u503c\u4e4b\u4e00\uff1a<\/p>\n

0 = Disabled\r\n1 = Conservative Randomization\r\n2 = Full Randomization<\/pre>\n

\u5982\u679c\u4f60\u5173\u95ed\u4e86 ASLR \u5e76\u4e14\u6267\u884c\u4e0b\u9762\u7684\u6307\u4ee4\uff0c\u4f60\u5c06\u4f1a\u6ce8\u610f\u5230\u524d\u540e\u4e24\u6761 ldd \u7684\u8f93\u51fa\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002ldd \u547d\u4ee4\u4f1a\u52a0\u8f7d\u5171\u4eab\u5bf9\u8c61\u5e76\u663e\u793a\u5b83\u4eec\u5728\u5185\u5b58\u4e2d\u7684\u5730\u5740\u3002<\/p>\n

$ sudo sysctl -w kernel.randomize_va_space=0    < == disable\r\n[sudo] password for shs:\r\nkernel.randomize_va_space = 0\r\n$ ldd \/bin\/bash\r\n        linux-vdso.so.1 (0x00007ffff7fd1000) <== same addresses\r\n        libtinfo.so.6 => \/lib\/x86_64-linux-gnu\/libtinfo.so.6 (0x00007ffff7c69000)\r\n        libdl.so.2 => \/lib\/x86_64-linux-gnu\/libdl.so.2 (0x00007ffff7c63000)\r\n        libc.so.6 => \/lib\/x86_64-linux-gnu\/libc.so.6 (0x00007ffff7a79000)\r\n        \/lib64\/ld-linux-x86-64.so.2 (0x00007ffff7fd3000)\r\n$ ldd \/bin\/bash\r\n        linux-vdso.so.1 (0x00007ffff7fd1000) < == same addresses\r\n        libtinfo.so.6 => \/lib\/x86_64-linux-gnu\/libtinfo.so.6 (0x00007ffff7c69000)\r\n        libdl.so.2 => \/lib\/x86_64-linux-gnu\/libdl.so.2 (0x00007ffff7c63000)\r\n        libc.so.6 => \/lib\/x86_64-linux-gnu\/libc.so.6 (0x00007ffff7a79000)\r\n        \/lib64\/ld-linux-x86-64.so.2 (0x00007ffff7fd3000)<\/pre>\n

\u5982\u679c\u5c06\u5176\u91cd\u65b0\u8bbe\u7f6e\u4e3a 2 \u6765\u542f\u7528 ASLR\uff0c\u4f60\u5c06\u4f1a\u770b\u5230\u6bcf\u6b21\u8fd0\u884c ldd\uff0c\u5f97\u5230\u7684\u5185\u5b58\u5730\u5740\u90fd\u4e0d\u76f8\u540c\u3002<\/p>\n

$ sudo sysctl -w kernel.randomize_va_space=2    < == enable\r\n[sudo] password for shs:\r\nkernel.randomize_va_space = 2\r\n$ ldd \/bin\/bash\r\n        linux-vdso.so.1 (0x00007fff47d0e000) <== first set of addresses\r\n        libtinfo.so.6 => \/lib\/x86_64-linux-gnu\/libtinfo.so.6 (0x00007f1cb7ce0000)\r\n        libdl.so.2 => \/lib\/x86_64-linux-gnu\/libdl.so.2 (0x00007f1cb7cda000)\r\n        libc.so.6 => \/lib\/x86_64-linux-gnu\/libc.so.6 (0x00007f1cb7af0000)\r\n        \/lib64\/ld-linux-x86-64.so.2 (0x00007f1cb8045000)\r\n$ ldd \/bin\/bash\r\n        linux-vdso.so.1 (0x00007ffe1cbd7000) < == second set of addresses\r\n        libtinfo.so.6 => \/lib\/x86_64-linux-gnu\/libtinfo.so.6 (0x00007fed59742000)\r\n        libdl.so.2 => \/lib\/x86_64-linux-gnu\/libdl.so.2 (0x00007fed5973c000)\r\n        libc.so.6 => \/lib\/x86_64-linux-gnu\/libc.so.6 (0x00007fed59552000)\r\n        \/lib64\/ld-linux-x86-64.so.2 (0x00007fed59aa7000)<\/pre>\n
\u5c1d\u8bd5\u7ed5\u8fc7 ASLR<\/strong><\/div>\n

\u5c3d\u7ba1\u8fd9\u9879\u6280\u672f\u6709\u5f88\u591a\u4f18\u70b9\uff0c\u4f46\u7ed5\u8fc7 ASLR \u7684\u653b\u51fb\u5e76\u4e0d\u7f55\u89c1\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u7c7b\uff1a<\/p>\n

\u5229\u7528\u5730\u5740\u6cc4\u9732<\/p>\n

\u8bbf\u95ee\u4e0e\u7279\u5b9a\u5730\u5740\u5173\u8054\u7684\u6570\u636e<\/p>\n

\u9488\u5bf9 ASLR \u5b9e\u73b0\u7684\u7f3a\u9677\u6765\u731c\u6d4b\u5730\u5740\uff0c\u5e38\u89c1\u4e8e\u7cfb\u7edf\u71b5\u8fc7\u4f4e\u6216 ASLR \u5b9e\u73b0\u4e0d\u5b8c\u5584\u3002<\/p>\n

\u5229\u7528\u4fa7\u4fe1\u9053\u653b\u51fb<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

ASLR \u6709\u5f88\u5927\u7684\u4ef7\u503c\uff0c\u5c24\u5176\u662f\u5728 64 \u4f4d\u7cfb\u7edf\u4e0a\u8fd0\u884c\u5e76\u88ab\u6b63\u786e\u5b9e\u73b0\u65f6\u3002\u867d\u7136\u4e0d\u80fd\u907f\u514d\u88ab\u7ed5\u8fc7\uff0c\u4f46\u8fd9\u9879\u6280\u672f\u7684\u786e\u4f7f\u5f97\u5229\u7528\u7cfb\u7edf\u6f0f\u6d1e\u53d8\u5f97\u66f4\u52a0\u56f0\u96be\u4e86\u3002\u8fd9\u4efd\u53c2\u8003\u8d44\u6599\u53ef\u4ee5\u63d0\u4f9b \u5728 64 \u4f4d Linux \u7cfb\u7edf\u4e0a\u7684\u5b8c\u5168 ASLR \u7684\u6709\u6548\u6027 \u7684\u66f4\u591a\u6709\u5173\u7ec6\u8282\uff0c\u8fd9\u7bc7\u8bba\u6587\u4ecb\u7ecd\u4e86\u4e00\u79cd\u5229\u7528\u5206\u652f\u9884\u6d4b \u7ed5\u8fc7 ASLR \u7684\u6280\u672f\u3002<\/p>\n

via: https:\/\/www.networkworld.com\/article\/3331199\/linux\/what-does-aslr-do-for-linux.html<\/p>\n

\u4f5c\u8005\uff1aSandra Henry-Stocker \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1aleommxj \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5730\u5740\u7a7a\u95f4\u968f\u673a\u5316Address Space Layout Randomization\uff08ASLR\uff09\u662f\u4e00\u79cd\u64cd\u4f5c\u7cfb\u7edf\u7528 […]<\/p>\n","protected":false},"author":1482,"featured_media":9401,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-160409","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\/160409","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\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=160409"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160409\/revisions"}],"predecessor-version":[{"id":160431,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/160409\/revisions\/160431"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/9401"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=160409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=160409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=160409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}