{"id":2970,"date":"2016-11-26T22:09:12","date_gmt":"2016-11-26T14:09:12","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2970"},"modified":"2016-11-26T22:09:12","modified_gmt":"2016-11-26T14:09:12","slug":"linux%e7%9a%84pam%e7%9b%b8%e5%85%b3%e7%9f%a5%e8%af%86%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2970.html","title":{"rendered":"Linux\u7684PAM\u76f8\u5173\u77e5\u8bc6\u5b66\u4e60"},"content":{"rendered":"<p>=Start=<\/p>\n<h4>\u7f18\u7531\uff1a<\/h4>\n<p>\u4e4b\u524d\u5bf9Linux\u7cfb\u7edf\u7684PAM\u673a\u5236\u548c\u5b83\u7684\u4f5c\u7528\u6ca1\u6709\u4e00\u4e2a\u6bd4\u8f83\u76f4\u89c2\u7684\u8ba4\u8bc6\uff0c\u53ea\u662f\u77e5\u9053\u6709\u8fd9\u4e48\u4e2a\u4e1c\u897f\u8d77\u5230\u8ba4\u8bc1\u7ba1\u7406\u7684\u4f5c\u7528\uff0c\u76f4\u5230\u540e\u6765\u5728\u300c\u5982\u4f55\u76d1\u63a7Linux\u7cfb\u7edf\u7684\u7528\u6237\u767b\u5f55\u60c5\u51b5\u300d\u4e00\u6587\u4e2d\u4e86\u89e3\u5230PAM\u673a\u5236\u53ef\u4ee5\u8d77\u5230\u7684\u4f5c\u7528\uff0c\u7136\u540e\u5c31\u5230\u5904\u53bb\u627e\u8d44\u6599\u5b66\u4e60\u3001\u4e86\u89e3PAM\u673a\u5236\u3002<\/p>\n<p>\u627e\u4e86\u4e00\u5806\u8d44\u6599\u540e\u53d1\u73b0\uff0c\u9664\u4e86<a href=\"http:\/\/www.linux-pam.org\/Linux-PAM-html\/Linux-PAM_SAG.html\">\u5b98\u65b9\u6587\u6863<\/a>\u4e4b\u5916\uff0c\u4e2d\u6587\u7684\u5c31\u5c5e\u4e4b\u524dWooYun\u77e5\u8bc6\u5e93\u4e2d\u7684\u300c<a href=\"http:\/\/anquan.us\/static\/drops\/tips-1288.html\">Linux PAM&amp;&amp;PAM\u540e\u95e8<\/a>\u300d\u8fd9\u7bc7\u6587\u7ae0\u5199\u5f97\u6700\u4e3a\u5168\u9762\u548c\u7ec6\u81f4\u4e86\u7684\uff08\u6b64\u5916InfoQ\u4e0a\u4e5f\u6709\u51e0\u7bc7\u8bb2PAM\u5185\u5bb9\u7684\u6587\u7ae0\u4e5f\u5f88\u597d\uff0c\u8be6\u60c5\u89c1\u6700\u540e\u7684\u53c2\u8003\u94fe\u63a5\uff09\uff0c\u5176\u5b83\u7684\u4e00\u822c\u5c31\u662f\u9488\u5bf9\u67d0\u4e2aPAM\u6a21\u5757\u7684\u8bb2\u89e3\uff0c\u53ef\u4ee5\u5728\u9700\u8981\u7684\u65f6\u5019\u81ea\u884c\u53c2\u8003\u3001\u5b66\u4e60\u3002<\/p>\n<h4>\u6b63\u6587\uff1a<\/h4>\n<h5>0x00 PAM\u7b80\u4ecb<\/h5>\n<p>PAM \uff08Pluggable Authentication Modules \uff09\u662f\u7531Sun\u63d0\u51fa\u7684\u4e00\u79cd\u8ba4\u8bc1\u673a\u5236\u3002\u5b83\u901a\u8fc7\u63d0\u4f9b\u4e00\u4e9b\u52a8\u6001\u94fe\u63a5\u5e93\u548c\u4e00\u5957\u7edf\u4e00\u7684API\uff0c\u5c06\u7cfb\u7edf\u63d0\u4f9b\u7684\u670d\u52a1\u548c\u8be5\u670d\u52a1\u7684\u8ba4\u8bc1\u65b9\u5f0f\u5206\u5f00\uff0c\u4f7f\u5f97\u7cfb\u7edf\u7ba1\u7406\u5458\u53ef\u4ee5\u7075\u6d3b\u5730\u6839\u636e\u9700\u8981\u7ed9\u4e0d\u540c\u7684\u670d\u52a1\u914d\u7f6e\u4e0d\u540c\u7684\u8ba4\u8bc1\u65b9\u5f0f\u800c\u65e0\u9700\u66f4\u6539\u670d\u52a1\u7a0b\u5e8f\uff0c\u540c\u65f6\u4e5f\u4fbf\u4e8e\u5411\u7cfb\u7edf\u4e2d\u6dfb\u52a0\u65b0\u7684\u8ba4\u8bc1\u624b\u6bb5\u3002PAM\u6700\u521d\u662f\u96c6\u6210\u5728Solaris\u4e2d\uff0c\u76ee\u524d\u5df2\u79fb\u690d\u5230\u5176\u5b83\u7cfb\u7edf\u4e2d\uff0c\u5982Linux\u3001SunOS\u3001HP-UX 9.0\u7b49\u3002<\/p>\n<h5>0x01 PAM\u5de5\u4f5c\u6d41\u7a0b<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3056 size-full\" src=\"http:\/\/127.0.0.1\/wp-content\/uploads\/2016\/11\/Linux-PAM.png\" alt=\"linux-pam\" width=\"992\" height=\"604\" \/><\/p>\n<p>&amp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/875cbdce43106bf508c10961ba76b307ba38d92a.jpg\" alt=\"NewImage\" width=\"351\" height=\"311\" border=\"0\" \/><\/p>\n<h5>0x02 PAM\u914d\u7f6e\u6587\u4ef6\u8bed\u6cd5<\/h5>\n<hr \/>\n<pre class=\"lang:default decode:true highlight\">module-type control-flag module_path optional<\/pre>\n<p><strong><span style=\"color: #ff0000;\">\u5728<code>\/etc\/pam.d\/<\/code>\u4e0b\u7684\u6587\u4ef6\u4e2d\uff0c\u4e0e\u670d\u52a1\u540d\u79f0\u76f8\u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u4e3a\u8be5\u670d\u52a1\u7684pam\u9a8c\u8bc1\u6587\u4ef6<\/span><\/strong>\uff0c\u4f8b\u5982\u670d\u52a1\u4e3asshd\uff0c\u5219\u5728<code>\/etc\/pam.d<\/code>\u4e0b\u5b58\u5728sshd\u8fd9\u4e2a\u6587\u4ef6\uff0c\u91cc\u9762\u5305\u542bsshd\u9a8c\u8bc1\u89c4\u5219\u3002<span style=\"color: #ff0000;\">\u5176\u4e2d\u6709\u4e2a\u4e00\u7279\u6b8a\u7684\u6587\u4ef6\u4e3aother\uff0c\u5982\u679c\u6709\u7684\u670d\u52a1\u4e0e\u4e4b\u6ca1\u6709\u5411\u5bf9\u5e94\u7684\u6587\u4ef6\uff0c\u5219\u5bf9\u5e94other<\/span>\u3002<\/p>\n<h6>module-type<\/h6>\n<p>\u670d\u52a1\u7c7b\u578b\uff0c\u5373 auth\u3001account\u3001session \u6216 password\u3002<\/p>\n<pre class=\"highlight\">\u9a8c\u8bc1\u6a21\u5757(auth)\u7528\u4e8e\u9a8c\u8bc1\u7528\u6237\u6216\u8bbe\u7f6e\/\u9500\u6bc1\u51ed\u8bc1\u3002\n\u5e10\u6237\u7ba1\u7406\u6a21\u5757(account)\u5c06\u6267\u884c\u4e0e\u8bbf\u95ee\u3001\u5e10\u6237\u53ca\u51ed\u8bc1\u6709\u6548\u671f\u3001\u5bc6\u7801\u9650\u5236\/\u89c4\u5219\u7b49\u6709\u5173\u7684\u64cd\u4f5c\u3002\n\u4f1a\u8bdd\u7ba1\u7406\u6a21\u5757(session)\u7528\u4e8e\u521d\u59cb\u5316\u548c\u7ec8\u6b62\u4f1a\u8bdd\u3002\n\u5bc6\u7801\u7ba1\u7406\u6a21\u5757(passwd)\u5c06\u6267\u884c\u4e0e\u5bc6\u7801\u66f4\u6539\/\u66f4\u65b0\u6709\u5173\u7684\u64cd\u4f5c\u3002\n<\/pre>\n<h6>control-flag<\/h6>\n<p><span style=\"color: #ff0000;\">\u7528\u4e8e\u6307\u660e\u5728\u786e\u5b9a\u670d\u52a1\u7684\u96c6\u6210\u6210\u8d25\u8fc7\u7a0b\u4e2d\u6a21\u5757\u6240\u8d77\u7684\u4f5c\u7528\u3002<\/span>\u6709\u6548\u7684\u63a7\u5236\u6807\u5fd7\u5305\u62ec include\u3001optional\u3001required\u3001requisite \u548c sufficient\u3002<\/p>\n<pre class=\"highlight\">required \u8868\u793a\u672c\u6a21\u5757\u5fc5\u987b\u8fd4\u56de\u6210\u529f\u624d\u80fd\u901a\u8fc7\u8ba4\u8bc1\uff0c\u4f46\u662f\u5982\u679c\u8be5\u6a21\u5757\u8fd4\u56de\u5931\u8d25\u7684\u8bdd\uff0c\u5931\u8d25\u7ed3\u679c\u4e5f\u4e0d\u4f1a\u7acb\u5373\u901a\u77e5\u7528\u6237\uff0c\u800c\u662f\u8981\u7b49\u5230\u540c\u4e00stack \u4e2d\u7684\u6240\u6709\u6a21\u5757\u5168\u90e8\u6267\u884c\u5b8c\u6bd5\u518d\u5c06\u5931\u8d25\u7ed3\u679c\u8fd4\u56de\u7ed9\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e00\u4e2a\u5fc5\u8981\u6761\u4ef6\u3002\nrequisite \u4e0erequired\u7c7b\u4f3c\uff0c\u8be5\u6a21\u5757\u5fc5\u987b\u8fd4\u56de\u6210\u529f\u624d\u80fd\u901a\u8fc7\u8ba4\u8bc1\uff0c\u4f46\u662f\u4e00\u65e6\u8be5\u6a21\u5757\u8fd4\u56de\u5931\u8d25\uff0c\u5c06\u4e0d\u518d\u6267\u884c\u540c\u4e00stack\u5185\u7684\u4efb\u4f55\u6a21\u5757\uff0c\u800c\u662f\u76f4 \u63a5\u5c06\u63a7\u5236\u6743\u8fd4\u56de\u7ed9\u5e94\u7528\u7a0b\u5e8f\u3002\u662f\u4e00\u4e2a\u5fc5\u8981\u6761\u4ef6\u3002\nsufficient \u8868\u660e\u672c\u6a21\u5757\u8fd4\u56de\u6210\u529f\u5df2\u7ecf\u8db3\u4ee5\u901a\u8fc7\u8eab\u4efd\u8ba4\u8bc1\u7684\u8981\u6c42\uff0c\u4e0d\u5fc5\u518d\u6267\u884c\u540c\u4e00stack\u5185\u7684\u5176\u5b83\u6a21\u5757\uff0c\u4f46\u662f\u5982\u679c\u672c\u6a21\u5757\u8fd4\u56de\u5931\u8d25\u7684\u8bdd\u53ef\u4ee5 \u5ffd\u7565\u3002\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e00\u4e2a\u5145\u5206\u6761\u4ef6\u3002\noptional\u8868\u660e\u672c\u6a21\u5757\u662f\u53ef\u9009\u7684\uff0c\u5b83\u7684\u6210\u529f\u4e0e\u5426\u4e00\u822c\u4e0d\u4f1a\u5bf9\u8eab\u4efd\u8ba4\u8bc1\u8d77\u5173\u952e\u4f5c\u7528\uff0c\u5176\u8fd4\u56de\u503c\u4e00\u822c\u88ab\u5ffd\u7565\u3002\n<\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/anquan.us\/static\/drops\/full\/19796fbecf84a3ef8787a6f946459754b8d08e93.jpg\" alt=\"enter image description here\" \/><\/p>\n<h6>module-path<\/h6>\n<p><span style=\"color: #ff0000;\">\u7528\u4e8e\u5b9e\u73b0\u670d\u52a1\u7684\u5e93\u5bf9\u8c61\u7684\u8def\u5f84\uff0c\u4e00\u822c\u90fd\u53ea\u5199\u5e93\u540d<\/span>\uff0c\u5e93\u7684\u8def\u5f84\u4e00\u822c\u4e3a\/lib\/security(32\u4f4d)\uff0c\/lib64\/security(64\u4f4d)<\/p>\n<h6>module-options<\/h6>\n<p>\u4f20\u9012\u7ed9\u670d\u52a1\u6a21\u5757\u7684\u9009\u9879\uff0c\u53ef\u9009\u3002<\/p>\n<p>\u51e0\u4e2a\u516c\u7528\u7684\u53c2\u6570\uff1a<\/p>\n<pre class=\"highlight\">debug \u8be5\u6a21\u5757\u5e94\u5f53\u7528syslog()\u5c06\u8c03\u8bd5\u4fe1\u606f\u5199\u5165\u5230\u7cfb\u7edf\u65e5\u5fd7\u6587\u4ef6\u4e2d\u3002\nno_warn \u8868\u660e\u8be5\u6a21\u5757\u4e0d\u5e94\u628a\u8b66\u544a\u4fe1\u606f\u53d1\u9001\u7ed9\u5e94\u7528\u7a0b\u5e8f\u3002\nuse_first_pass \u8868\u660e\u8be5\u6a21\u5757\u4e0d\u80fd\u63d0\u793a\u7528\u6237\u8f93\u5165\u5bc6\u7801\uff0c\u800c\u5e94\u4f7f\u7528\u524d\u4e00\u4e2a\u6a21\u5757\u4ece\u7528\u6237\u90a3\u91cc\u5f97\u5230\u7684\u5bc6\u7801\u3002\ntry_first_pass \u8868\u660e\u8be5\u6a21\u5757\u9996\u5148\u5e94\u5f53\u4f7f\u7528\u524d\u4e00\u4e2a\u6a21\u5757\u4ece\u7528\u6237\u90a3\u91cc\u5f97\u5230\u7684\u5bc6\u7801\uff0c\u5982\u679c\u8be5\u5bc6\u7801\u9a8c\u8bc1\u4e0d\u901a\u8fc7\uff0c\u518d\u63d0\u793a\u7528\u6237\u8f93\u5165\u65b0\u7684\u5bc6\u7801\u3002\nuse_mapped_pass \u8be5\u6a21\u5757\u4e0d\u80fd\u63d0\u793a\u7528\u6237\u8f93\u5165\u5bc6\u7801\uff0c\u800c\u662f\u4f7f\u7528\u6620\u5c04\u8fc7\u7684\u5bc6\u7801\u3002\nexpose_account \u5141\u8bb8\u8be5\u6a21\u5757\u663e\u793a\u7528\u6237\u7684\u5e10\u53f7\u540d\u7b49\u4fe1\u606f\uff0c\u4e00\u822c\u53ea\u80fd\u5728\u5b89\u5168\u7684\u73af\u5883\u4e0b\u4f7f\u7528\uff0c\u56e0\u4e3a\u6cc4\u6f0f\u7528\u6237\u540d\u4f1a\u5bf9\u5b89\u5168\u9020\u6210\u4e00\u5b9a\u7a0b\u5ea6\u7684\u5a01\u80c1\u3002\n<\/pre>\n<h5>0x03 PAM \u5806\u6808\u5de5\u4f5c\u539f\u7406<\/h5>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/6b2acfaa064f52024e6a757a0091b9da8352c0f1.jpg\" alt=\"NewImage\" width=\"455\" height=\"535\" border=\"0\" \/><\/p>\n<p style=\"text-align: center;\">\u56fe1:PAM\u5f62\u6210\u5806\u6808\u7684\u8fc7\u7a0b(solaris\uff0c\u6709\u7684linux\u4e0d\u5305\u542b)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/c7e42f9a775d4ccff41c1a3a8a735fe9ddc93c74.jpg\" alt=\"NewImage\" width=\"413\" height=\"429\" border=\"0\" \/><\/p>\n<p style=\"text-align: center;\">\u56fe2\uff1aPAM\u5982\u4f55\u786e\u5b9a\u6700\u7ec8\u7684\u8fd4\u56de\u503c(solaris)<\/p>\n<h5>0x04 \u5e38\u7528PAM\u6a21\u5757<\/h5>\n<p>\u4ece\u5b98\u65b9\u6587\u6863\u7ffb\u8bd1\u51fa\u6765\u7684(<code>\/usr\/share\/doc\/pam-1.1.1<\/code>)\uff0c\u7ffb\u8bd1\u53ef\u80fd\u6709\u4e0d\u5bf9\u7684\u5730\u65b9\u3002<\/p>\n<h6>1\u3001pam_securetty.so<\/h6>\n<p>\u7c7b\u578b\uff1aauth<br \/>\n\u4f5c\u7528\uff1a\u53ea\u5bf9root\u6709\u9650\u5b9a\uff0c\u9650\u5b9aroot\u767b\u9646\u7684\u7ec8\u7aef\uff0c\u7cfb\u7edf\u9ed8\u8ba4\u7684\u201c\u5b89\u5168\u201d\u7ec8\u7aef\u4fdd\u5b58\u5728\/etc\/securetty\u4e2d\u3002<\/p>\n<h6>2\u3001pam_access.so<\/h6>\n<p>\u7c7b\u578b\uff1aaccount<br \/>\n\u4f5c\u7528\uff1a\u57fa\u4e8e\u767b\u5f55\u540d\uff0c\u4e3b\u673a\u540d\u6216\u8005\u6240\u5c5e\u57df\uff0cip\u5730\u5740\u6216\u8005\u7f51\u7edc<br \/>\n\u7ec8\u7aef\u7f16\u53f7(\u7c7b\u4f3c\u4e8e\/etc\/securetty)\u3002\u9ed8\u8ba4\u7684\u914d\u7f6e\u6587\u4ef6\u4e3a\/etc\/security\/access.conf<\/p>\n<h6>3\u3001pam_tally2.so<\/h6>\n<p>\u7c7b\u578b\uff1aauth<br \/>\n\u4f5c\u7528\uff1a\u5f53\u7528\u6237\u8f93\u5165\u5bc6\u7801\u7684\u9519\u8bef\u6b21\u6570\u8d85\u8fc7\u6307\u5b9a\u6b21\u6570\u65f6\uff0c\u9501\u5b9a\u8d26\u6237\u7b49\u3002<br \/>\n\u53c2\u6570\uff1a<\/p>\n<p>onerr=[fail|succeed]:<\/p>\n<p>file=\/path\/to\/counter:\u5f53\u767b\u9646\u8d85\u8fc7\u5141\u8bb8\u6b21\u6570\u65f6\uff0c\u65e5\u5fd7\u4fdd\u5b58\u7684\u5730\u65b9\u3002\u9ed8\u8ba4\u7684\u4e3a\/var\/log\/tallylog\u3002\u5f53\u5f00\u542f\u7684\u65f6\u5019\uff0c\u6bcf\u5f53\u767b\u9646\u5931\u8d25\u4e00\u6b21\uff0c\u5219\u4f1a\u5199\u5165\u4e00\u6b21\uff0c\u4f7f\u7528pam_tally2 \u53ef\u4ee5\u8bfb\u51fa<\/p>\n<pre class=\"highlight\">audit : \u5982\u679c\u7528\u6237\u627e\u4e0d\u5230\uff0c\u5219\u628a\u6b64\u7528\u6237\u540d\u8bb0\u5f55\u5230\u65e5\u5fd7\u4e2d\nsilent : \u4e0d\u8f93\u51fa\u4efb\u4f55\u4fe1\u606f\nno_log_info : \u4e0d\u8fdb\u884c\u65e5\u5fd7\u8bb0\u5f55\n<\/pre>\n<p>deny=N\uff1a\u5f53\u7528\u6237\u8fde\u7eed\u8f93\u9519n\u6b21\u662f\uff0c\u5728\u7b2cn+1\u6b21\u9501\u5b9a\u8be5\u7528\u6237\uff0c\u6ca1\u6709 \u8bbe\u5b9a\u89e3\u9501\u89e3\u9501\u65f6\u95f4\uff0c\u5219\u9501\u5b9a\u4e4b\u540e\u9700\u8981\u624b\u5de5\u89e3\u9501\u3002<\/p>\n<pre class=\"highlight\">pam_tally.so -u username --reset\n\nlock_time=n\uff1a\u5f53\u8f93\u5165\u5bc6\u7801\u9519\u8bef\u4e00\u6b21\u65f6\uff0c\u5728N\u79d2\u5185\u4e0d\u80fd\u518d\u6b21\u767b\u9646\u8be5\u8d26\u6237\u3002\n<\/pre>\n<p>unlock_time=n\uff1a\u89e3\u9501\u65f6\u95f4\uff0c\u5f53\u8d26\u6237\u88ab\u9501\u5b9a\u65f6\uff0c\u8fc7n\u79d2\u65f6\uff0c\u8be5\u8d26\u6237\u88ab\u89e3\u9664\u9501\u5b9a(\u6e05\u7a7a\/var\/log\/tallylog\u4e2d\u7684\u76f8\u5173\u4fe1\u606f)\uff0c\u914d\u5408deny\u53c2\u6570\u4f7f\u7528 magic_root\uff1a\u5f53uid=0\u65f6\uff0c\u4e0d\u4f1a\u5f80\/var\/log\/tallylog\u4e2d\u5199\u5165\u8ba1\u6570\uff0c\u5373\u8fd9\u4e2aPAM\u4e0d\u751f\u6548 even_deny_root\uff1a\u5bf9root\u7528\u6237\u751f\u6548(\u4e0d\u52a0magic_root\u53c2\u6570\uff0c\u5bf9 root\u4e5f\u662f\u4e0d\u5904\u7406\u7684) root_unlock_time=n:\u662f\u9488\u5bf9even_deny_root\u7684\uff0croot\u7528\u6237\u7684\u89e3\u9501\u65f6\u95f4 \u6bcf\u5f53\u7528\u6237\u6210\u529f\u767b\u9646\u8fc7\u4e00\u6b21\u540e\uff0c\/var\/log\/tallylog\u4e2d\u5173\u4e8e\u8fd9\u4e2a\u7528 \u6237\u7684\u8bb0\u5f55\u5c31\u4f1a\u6e05\u7a7a<\/p>\n<h6>4\u3001pam_cracklib<\/h6>\n<p>\u7c7b\u578b\uff1apassword<br \/>\n\u4f5c\u7528\uff1a\u9650\u5b9a\u66f4\u6539\u5bc6\u7801\u7684\u957f\u5ea6\uff0c\u590d\u6742\u5ea6\u7b49\u7b49\u3002<br \/>\n\u53c2\u6570\uff1a<\/p>\n<pre class=\"highlight\">dubug:\u628a\u4fee\u6539\u5bc6\u7801\u7684\u884c\u4e3a\u8bb0\u5f55\u5230\u65e5\u5fd7\u4e2d\nretry=N:\u4fee\u6539\u5bc6\u7801\u65f6\uff0c\u5141\u8bb8\u9519\u8bef\u7684\u6b21\u6570\uff0c\u9ed8\u8ba4\u662f1\u6b21\ndifok=N\uff1a\u65b0\u5bc6\u7801\u4e0e\u65e7\u5bc6\u7801\u4e0d\u540c\u7684\u4f4d\u6570\u3002\u5982\u679c\u8d85\u8fc7\u4e00\u534a\u4e0d\u540c\uff0c\u5219\u901a\u8fc7\u9a8c\u8bc1\uff0c\u5219\u5ffd\u7565difok\u7684\u8bbe\u7f6e\nminlen=N:\u5bc6\u7801\u7684\u6700\u77ed\u957f\u5ea6\ndcredit=N:\u81f3\u5c11\u6709N\u7684\u6570\u5b57\nucredit=N\uff1a\u81f3\u5c11\u6709N\u7684\u5927\u5199\u5b57\u7801\nlcredit=N:\u81f3\u5c11\u6709N\u4e2a\u5c0f\u5199\u5b57\u6bcd\nocredit=N:\u81f3\u5c11\u6709N\u4e2a\u7279\u6b8a\u5b57\u7b26\nminclass=N:\u5bc6\u7801\u7ec4\u6210\u7684\u8303\u56f4(\u6570\u5b57\uff0c\u5927\u5c0f\u5199\u5b57\u6bcd\uff0c\u7279\u6b8a\u5b57\u7b26)\nmaxrepeat=N:\u6700\u591a\u4e0e\u4e0a\u4e00\u4e2a\u5bc6\u7801\u91cd\u590d\n<\/pre>\n<h6>5\u3001pam_limits.so<\/h6>\n<p>\u7c7b\u578b\uff1asession<br \/>\n\u4f5c\u7528\uff1a\u9650\u5236\u8d44\u6e90\u7684\u4f7f\u7528\uff0c\u9ed8\u8ba4\u7684\u914d\u7f6e\u6587\u4ef6\u4e3a\/etc\/security\/limits.conf\u662f\u5168\u5c40\u7684\uff0c\/etc\/security\/limits.d\/\u4e0b\u5b58\u653e\u5404\u4e2a\u5b50\u6587\u4ef6\u3002<\/p>\n<h6>6\u3001pam_listfile<\/h6>\n<p>\u7c7b\u578b\uff1aauth<br \/>\n\u4f5c\u7528\uff1a\u9a8c\u8bc1\u7528\u6237\u662f\u5426\u80fd\u591f\u767b\u9646<br \/>\n\u53c2\u6570\uff1a<\/p>\n<pre class=\"highlight\">item=[tty|user|rhost|ruser|group|shell]:\u63a7\u5236\u7684\u5bf9\u8c61\nsense=[allow|deny]\uff1a\u63a7\u5236\u7684\u65b9\u6cd5\nfile=\/path\/filename:\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u6bcf\u4e2a\u5360\u4e00\u884c\nonerr=[succeed|fail]\uff1a\u6307\u5b9a\u67d0\u7c7b\u4e8b\u4ef6\u53d1\u751f\u65f6\u7684\u8fd4\u56de\u503c\u3002\n\u5b9e\u4f8b\uff1a\nauthrequired pam_listfile.soonerr=succeed item=user sense=deny file=\/etc\/ftpusers\n\u4fdd\u5b58\u5728\/etc\/ftpusers\u4e2d\u7684\u7528\u6237\uff0c\u662f\u4e0d\u5141\u8bb8\u7684\u3002\n<\/pre>\n<h6>7\u3001pam_nologin.so<\/h6>\n<p>\u7c7b\u578b\uff1aauth<br \/>\n\u4f5c\u7528\uff1a\u7528\u4e8e\u62d2\u7edd\u9664root\u5916\u7684\u4e0d\u540c\u7528\u6237\u7684\u767b\u9646(\u5f53\/etc\/nologin\u5b58\u5728\uff0c\u6216\u8005\u91cd\u65b0\u5236\u5b9afile\u7684\u60c5\u51b5\u4e0b)<br \/>\n\u53c2\u6570\uff1aauth<br \/>\nfile=\/path\/nologin\uff1a\u5982\u679c\u6587\u4ef6\u5b58\u5728\uff0c\u5f53\u62d2\u7edd\u7528\u6237\u767b\u9646\u7684\u65f6\u5019\uff0c\u540c\u65f6\u4f1a\u8f93\u51fa\u8be5\u6587\u4ef6\u4e2d\u4fdd\u5b58\u7684\u5185\u5bb9\u3002\u9ed8\u8ba4\u6587\u4ef6\u4e3a\/etc\/nologin\u3002<\/p>\n<h5>0x05 PAM\u540e\u95e8<\/h5>\n<p>\u6d4b\u8bd5\u73af\u5883CentOS 6.2 64\u4f4d<\/p>\n<h5>0x05a \u67e5\u8be2\u672c\u673a\u7684PAM\u7248\u672c<\/h5>\n<pre class=\"highlight\">rpm \u2013aq | grep pam\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/dcee3893163bb43e5dd2fc2015a0947890354842.jpg\" alt=\"NewImage\" width=\"273\" height=\"106\" border=\"0\" \/><\/p>\n<p>\u4e0b\u8f7d\u5bf9\u5e94\u7684\u7248\u672c<br \/>\n\u4e0b\u8f7d\u5730\u5740\uff1a<\/p>\n<pre class=\"highlight\">http:\/\/www.linux-pam.org\/library\/\nhttps:\/\/fedorahosted.org\/releases\/l\/i\/linux-pam\/\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/24990f91ef5ab8b5cc9b1f3e33212057d12bd3af.jpg\" alt=\"NewImage\" width=\"347\" height=\"90\" border=\"0\" \/><\/p>\n<h5>0x05b \u4fee\u6539\u6e90\u4ee3\u7801<\/h5>\n<pre class=\"brush:bash\">vim \/mnt\/Linux-PAM-1.1.1\/modules\/pam_unix\/pam_unix_auth.c\n\u5728PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags,int argc, const char **argv)\u4e2d\u5b9a\u4e49FILE *fp;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/6e69f29dd4814037e37927dfc1f3904eb1d0f9b4.jpg\" alt=\"NewImage\" width=\"463\" height=\"356\" border=\"0\" \/><\/p>\n<p>PS\uff1a\u7f51\u4e0a\u7684\u90a3\u79cd\u540e\u95e8\u8865\u4e01\u4e5f\u5c31\u662f\u4fee\u6539\u8fd9\u4e9b<\/p>\n<h5>0x05c \u7f16\u8bd1\u6e90\u4ee3\u7801<\/h5>\n<p>\u89e3\u51b3\u4f9d\u8d56\u6027<\/p>\n<pre class=\"brush:bash\">yum install gcc make flex \u2013y\nconfigure&amp;&amp;make\n<\/pre>\n<p>\u7f16\u8bd1\u51fa\u6765\u7684pam_unix.so\u5728<\/p>\n<pre class=\"highlight\">\/mnt\/Linux-PAM-1.1.1\/modules\/pam_unix\/.libs\n<\/pre>\n<p>\u5bf9\/lib64\/security\u4e2d\u7684\u6587\u4ef6\u8fdb\u884c\u66ff\u6362(32\u4f4d\u7cfb\u7edf\u653e\u5165\/lib\/security)<\/p>\n<h5>0x05d \u767b\u5f55\u6d4b\u8bd5<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/30b648c199aca5202be0b111a9d1c353a58b2c14.jpg\" alt=\"NewImage\" width=\"335\" height=\"289\" border=\"0\" \/><\/p>\n<h5>0x05e \u4f7f\u7528touch \u2013r\u6765\u66f4\u6539\u65f6\u95f4<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/4bc3ec68f8438905bfd2ae6010972f0a841022da.jpg\" alt=\"NewImage\" width=\"482\" height=\"446\" border=\"0\" \/><\/p>\n<p>PS:\u4f46\u662f\u4e24\u4e2a\u6587\u4ef6\u7684\u5927\u5c0f\u662f\u4e0d\u540c\u7684<\/p>\n<p>\u5bf9\u4e8e\u8fd9\u79cd\u4fee\u6539\u7684\u65b9\u6cd5\uff0c\u5728\/var\/log\/secure\u4e2d\u548c\u6b63\u5e38\u767b\u5f55\u7684\u662f\u6709\u5dee\u8ddd<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/4078b496de0e400170014df5eadc4675395e0ba3.jpg\" alt=\"NewImage\" width=\"932\" height=\"106\" border=\"0\" \/><\/p>\n<h5>0x05f \u4f18\u5316\u4e00\u4e0b\u4e0b<\/h5>\n<pre class=\"brush:bash\">vim \/mnt\/Linux-PAM-1.1.1\/modules\/pam_unix\/pam_unix_auth.c\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/6de825013e295c7786fa8208f14729962bd8ba38.jpg\" alt=\"NewImage\" width=\"479\" height=\"305\" border=\"0\" \/><\/p>\n<pre class=\"brush:bash\">vim \/mnt\/Linux-PAM-1.1.1\/modules\/pam_unix\/support.c\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/39dab9c8ab9d1a3aa320e4a8afa25127261367c1.jpg\" alt=\"NewImage\" width=\"465\" height=\"180\" border=\"0\" \/><\/p>\n<p>\u767b\u5f55\u6d4b\u8bd5\u540e\u7684\u65e5\u5fd7<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/5e07f54e65784afd390b00261537c137ab82253b.jpg\" alt=\"NewImage\" width=\"673\" height=\"109\" border=\"0\" \/><\/p>\n<p>\u4e00\u81f4\u4e86\uff0co(\u2229_\u2229)o<\/p>\n<h5>0x05g \u8fd8\u6709\u4e00\u79cd\u7325\u7410\u7684\u65b9\u6cd5\uff0c\u76f4\u63a5\u4fee\u6539\/etc\/pam.d\/sshd\u6587\u4ef6\uff0c\u8f93\u5165\u4ec0\u4e48\u90fd\u80fd\u767b\u5f55\u7684<\/h5>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/cc7e2e6dcf936eb06eea08cfd89cea37454ee1a3.jpg\" alt=\"NewImage\" width=\"613\" height=\"227\" border=\"0\" \/><\/p>\n<p>\u6b63\u5e38\u65e5\u5fd7<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"NewImage.png\" src=\"http:\/\/anquan.us\/static\/drops\/full\/110f6964d638cc8702a5023fec6eb0aec34482e1.jpg\" alt=\"NewImage\" width=\"825\" height=\"58\" border=\"0\" \/><\/p>\n<p>PS\uff1a\u4e3a\u4ec0\u4e48\u80fd\u767b\u5f55\uff0c\u597d\u597d\u770b\u524d\u9762\u7684\u57fa\u7840\u90e8\u5206\u5c31\u77e5\u9053\u4e86<\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/www.linux-pam.org\/Linux-PAM-html\/sag-overview.html\">http:\/\/www.linux-pam.org\/Linux-PAM-html\/sag-overview.html<\/a><\/li>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/19710725\">https:\/\/zhuanlan.zhihu.com\/p\/19710725<\/a><\/li>\n<li><a href=\"http:\/\/drops.wooyun.org\/tips\/1288\">http:\/\/drops.wooyun.org\/tips\/1288<\/a><\/li>\n<li><a href=\"http:\/\/anquan.us\/static\/drops\/tips-1288.html\">http:\/\/anquan.us\/static\/drops\/tips-1288.html<\/a><\/li>\n<li><a href=\"https:\/\/wiki.archlinux.org\/index.php\/PAM_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)\">https:\/\/wiki.archlinux.org\/index.php\/PAM_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)<\/a><\/li>\n<li><a href=\"https:\/\/linux.die.net\/man\/8\/pam\">https:\/\/linux.die.net\/man\/8\/pam<\/a><\/li>\n<li><a href=\"http:\/\/www.infoq.com\/cn\/articles\/wjl-linux-pluggable-authentication-module\">http:\/\/www.infoq.com\/cn\/articles\/wjl-linux-pluggable-authentication-module<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u4e4b\u524d\u5bf9Linux\u7cfb\u7edf\u7684PAM\u673a\u5236\u548c\u5b83\u7684\u4f5c\u7528\u6ca1\u6709\u4e00\u4e2a\u6bd4\u8f83\u76f4\u89c2\u7684\u8ba4\u8bc6\uff0c\u53ea\u662f\u77e5\u9053\u6709\u8fd9\u4e48\u4e2a\u4e1c\u897f [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,25],"tags":[30,671,37],"class_list":["post-2970","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-security","tag-linux","tag-pam","tag-security"],"views":9521,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2970"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2970\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}