{"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":"
\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 |