{"id":257946,"date":"2022-12-18T08:41:17","date_gmt":"2022-12-18T00:41:17","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=257946"},"modified":"2022-11-25T22:41:55","modified_gmt":"2022-11-25T14:41:55","slug":"linux-sudo-new","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-sudo-new.html","title":{"rendered":"2022 \u5e74 5 \u4e2a\u65b0 sudo \u529f\u80fd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6700\u8fd1\u7684 sudo \u7248\u672c\u589e\u52a0\u4e86\u65b0\u7684\u529f\u80fd\uff0c\u4f7f\u4f60\u80fd\u591f\u89c2\u5bdf\u548c\u63a7\u5236\u4ee5\u524d\u9690\u85cf\u7684\u95ee\u9898\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5f53\u4f60\u60f3\u6388\u4e88\u4f60\u7684\u4e00\u4e9b\u7528\u6237\u7ba1\u7406\u6743\u9650\uff0c\u540c\u65f6\u63a7\u5236\u548c\u68c0\u67e5\u4ed6\u4eec\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u505a\u4ec0\u4e48\u65f6\uff0c\u4f60\u4f1a\u4f7f\u7528 sudo\u3002\u7136\u800c\uff0c\u5373\u4f7f\u662f sudo'\uff0c\u4e5f\u6709\u76f8\u5f53\u591a\u4e0d\u53ef\u63a7\u7684\u5730\u65b9\uff0c\u60f3\u60f3\u7ed9\u4e88 shell \u6743\u9650\u7684\u60c5\u51b5\u5c31\u77e5\u9053\u4e86\u3002\u6700\u8fd1\u7684 sudo \u7248\u672c\u589e\u52a0\u4e86\u4e00\u4e9b\u529f\u80fd\uff0c\u53ef\u4ee5\u8ba9\u4f60\u770b\u5230\u8fd9\u4e9b\u95ee\u9898\uff0c\u751a\u81f3\u63a7\u5236\u5b83\u4eec\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u542f\u7528\u66f4\u8be6\u7ec6\u3001\u66f4\u5bb9\u6613\u5904\u7406\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5e76\u8bb0\u5f55 shell \u4f1a\u8bdd\u4e2d\u6267\u884c\u7684\u6bcf\u4e2a\u547d\u4ee4\u3002
\n\"\"<\/p>\n

\u8fd9\u4e9b\u529f\u80fd\u4e2d\u6709\u4e9b\u662f\u5168\u65b0\u7684\u3002\u6709\u4e9b\u662f\u51fa\u73b0\u5728 1.9.0 \u751a\u81f3\u66f4\u65e9\u7684\u7248\u672c\u4e2d\u7684\u529f\u80fd\u3002\u4f8b\u5982\uff0csudo \u53ef\u4ee5\u8bb0\u5f55\u7ec8\u7aef\u4e0a\u53d1\u751f\u7684\u4e00\u5207\uff0c\u5373\u4f7f\u662f\u5728 1.8 \u7248\u672c\u3002\u7136\u800c\uff0c\u7cfb\u7edf\u5c06\u8fd9\u4e9b\u8bb0\u5f55\u4fdd\u5b58\u5728\u672c\u5730\uff0c\u5b83\u4eec\u5f88\u5bb9\u6613\u88ab\u5220\u9664\uff0c\u7279\u522b\u662f\u90a3\u4e9b\u8bb0\u5f55\u6700\u6709\u7528\u7684\u5730\u65b9\uff1aShell \u4f1a\u8bdd\u30021.9.0 \u7248\u672c\u589e\u52a0\u4e86\u4f1a\u8bdd\u8bb0\u5f55\u96c6\u4e2d\u6536\u96c6\uff0c\u56e0\u6b64\u8bb0\u5f55\u4e0d\u80fd\u88ab\u672c\u5730\u7528\u6237\u5220\u9664\uff0c\u6700\u8fd1\u7684\u7248\u672c\u8fd8\u589e\u52a0\u4e86\u4e2d\u7ee7\u529f\u80fd\uff0c\u4f7f\u6536\u96c6\u529f\u80fd\u66f4\u52a0\u5f3a\u5927\u3002<\/p>\n

\u5982\u679c\u4f60\u53ea\u77e5\u9053 sudo \u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u6216\u8005\u4ee5\u524d\u53ea\u4f7f\u7528\u8fc7 1.8 \u7248\u672c\uff0c\u6211\u5efa\u8bae\u4f60\u9605\u8bfb\u6211\u4ee5\u524d\u7684 \u6587\u7ae0\u3002<\/p>\n

1\u3001JSON \u683c\u5f0f\u7684\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/div>\n

\u6211\u60f3\u4ecb\u7ecd\u7684\u7b2c\u4e00\u4e2a\u65b0\u529f\u80fd\u662f JSON \u683c\u5f0f\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u6211\u662f\u4e00\u4e2a\u65e5\u5fd7\u72c2\u70ed\u8005\uff0812 \u5e74\u524d\u6211\u5c31\u5f00\u59cb\u5728 syslog-ng \u9879\u76ee\u4e0a\u5de5\u4f5c\uff09\uff0c\u800c\u8fd9\u4e2a\u529f\u80fd\u662f\u6211\u5728\u8fd9\u91cc\u53d1\u8868\u6587\u7ae0\u540e\u5f15\u5165\u7684\u7b2c\u4e00\u4e2a\u529f\u80fd\u3002\u542f\u7528\u540e\uff0csudo \u8bb0\u5f55\u4e86\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u5e76\u4e14\u4ee5\u4e00\u79cd\u66f4\u5bb9\u6613\u89e3\u6790\u7684\u65b9\u5f0f\u8fdb\u884c\u3002<\/p>\n

\u4f20\u7edf\u7684 syslog \u4fe1\u606f\u5f88\u77ed\uff0c\u53ea\u5305\u542b\u6700\u5c0f\u7684\u5fc5\u8981\u4fe1\u606f\u91cf\u3002\u8fd9\u662f\u7531\u4e8e\u65e7\u7684 syslog \u5b9e\u73b0\u7684\u9650\u5236\u3002\u8d85\u8fc7 1k \u5927\u5c0f\u7684\u4fe1\u606f\u88ab\u4e22\u5f03\u6216\u622a\u65ad\u3002<\/p>\n

Jan 28 13:56:27 localhost.localdomain sudo[10419]: czanik : TTY=pts\/0 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/bin\/bash<\/pre>\n

\u6700\u8fd1\u7684 syslog \u5b9e\u73b0\u53ef\u4ee5\u5904\u7406\u66f4\u5927\u7684\u4fe1\u606f\u91cf\u3002syslog-ng \u9ed8\u8ba4\u63a5\u53d7 64k \u5927\u5c0f\u7684\u65e5\u5fd7\u4fe1\u606f\uff08\u5f53\u7136\uff0c\u5b83\u53ef\u4ee5\u66f4\u5c0f\u6216\u66f4\u5927\uff0c\u53d6\u51b3\u4e8e\u5b9e\u9645\u914d\u7f6e\uff09\u3002<\/p>\n

\u540c\u6837\u7684\u4e8b\u4ef6\uff0c\u5982\u679c\u4ee5 JSON \u683c\u5f0f\u8bb0\u5f55\uff0c\u5c31\u4f1a\u5305\u542b\u66f4\u591a\u7684\u4fe1\u606f\u3002\u66f4\u591a\u5e76\u4e0d\u610f\u5473\u7740\u66f4\u96be\u5904\u7406\u3002JSON \u683c\u5f0f\u7684\u4fe1\u606f\u66f4\u5bb9\u6613\u88ab\u8bb8\u591a\u65e5\u5fd7\u7ba1\u7406\u8f6f\u4ef6\u5e94\u7528\u89e3\u6790\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n

Jan 28 13:58:20 localhost.localdomain sudo[10518]: @cee:{\"sudo\":{\"accept\":{\"uuid\":\"616bc9efcf-b239-469d-60ee-deb5af8ce6\",\"server_time\":{\"seconds\":1643374700,\"nanoseconds\":222446715,\"iso8601\":\"20220128125820Z\",\"localtime\":\"Jan 28 13:58:20\"},\"submit_time\":{\"seconds\":1643374700,\"nanoseconds\":209935349,\"iso8601\":\"20220128125820Z\",\"localtime\":\"Jan 28 13:58:20\"},\"submituser\":\"czanik\",\"command\":\"\/bin\/bash\",\"runuser\":\"root\",\"runcwd\":\"\/home\/czanik\",\"ttyname\":\"\/dev\/pts\/0\",\"submithost\":\"localhost.localdomain\",\"submitcwd\":\"\/home\/czanik\",\"runuid\":0,\"columns\":118,\"lines\":60,\"runargv\":[\"\/bin\/bash\"],\"runenv\":[\"LANG=en_US.UTF-8\",\"HOSTNAME=localhost.localdomain\",\"SHELL=\/bin\/bash\",\"TERM=xterm-256color\",\"PATH=\/home\/czanik\/.local\/bin:\/home\/czanik\/bin:\/usr\/local\/bin:\/usr\/bin:\/usr\/local\/sbin:\/usr\/sbin\",\"MAIL=\/var\/mail\/root\",\"LOGNAME=root\",\"USER=root\",\"HOME=\/root\",\"SUDO_COMMAND=\/bin\/bash\",\"SUDO_USER=czanik\",\"SUDO_UID=1000\",\"SUDO_GID=1000\"]}}}<\/pre>\n

\u4f60\u53ef\u4ee5\u5728 sudoers \u6587\u4ef6\u4e2d\u542f\u7528 JSON \u683c\u5f0f\u7684\u65e5\u5fd7\u4fe1\u606f\uff1a<\/p>\n

Defaults log_format=json<\/pre>\n

\u4f60\u53ef\u4ee5\u4ece\u6211\u7684 syslog-ng \u535a\u5ba2\u4e2d\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u5982\u4f55\u4ece sudo \u4e2d\u4f7f\u7528 JSON \u683c\u5f0f\u7684\u65e5\u5fd7\u4fe1\u606f\u3002<\/p>\n

2\u3001\u4f7f\u7528 sudo_logsrvd \u96c6\u4e2d\u6536\u96c6\u65e5\u5fd7<\/strong><\/div>\n

1.9.4 \u4e2d\u53e6\u4e00\u4e2a\u4e0e\u65e5\u5fd7\u76f8\u5173\u7684\u529f\u80fd\u662f\u4f7f\u7528 sudo_logsrvd \u6536\u96c6\u6240\u6709 sudo \u65e5\u5fd7\u4fe1\u606f\uff08\u5305\u62ec\u5931\u8d25\u7684\uff09\u3002\u4ee5\u524d\uff0c\u7cfb\u7edf\u53ea\u5728 sudo_logsrvd \u5b9e\u9645\u8fdb\u884c\u8bb0\u5f55\u65f6\u8bb0\u5f55\u6210\u529f\u7684\u4f1a\u8bdd\u3002\u6700\u540e\u4ecd\u7136\u9ed8\u8ba4\u901a\u8fc7 syslog \u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u8fd9\u5f88\u91cd\u8981\uff1f\u9996\u5148\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u5730\u65b9\u6536\u96c6\u4efb\u4f55\u4e0e sudo \u6709\u5173\u7684\u4e1c\u897f\u3002\u65e0\u8bba\u662f\u4f1a\u8bdd\u8bb0\u5f55\u8fd8\u662f\u6240\u6709\u76f8\u5e94\u7684\u65e5\u5fd7\u4fe1\u606f\u3002\u5176\u6b21\uff0c\u5b83\u8fd8\u53ef\u4ee5\u4fdd\u8bc1\u6b63\u786e\u8bb0\u5f55\u6240\u6709\u4e0e sudo \u6709\u5173\u7684\u4e8b\u4ef6\uff0c\u56e0\u4e3a\u5982\u679c sudo_logsrvd \u65e0\u6cd5\u8bbf\u95ee\uff0csudo \u53ef\u4ee5\u62d2\u7edd\u6267\u884c\u547d\u4ee4\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u5728 sudoers \u6587\u4ef6\u4e2d\u901a\u8fc7\u4ee5\u4e0b\u8bbe\u7f6e\u542f\u7528 sudo_logsrvd \u65e5\u5fd7\u8bb0\u5f55\uff08\u5f53\u7136\u8981\u66ff\u6362 IP \u5730\u5740\uff09\uff1a<\/p>\n

Defaults log_servers=172.16.167.150<\/pre>\n

\u5982\u679c\u4f60\u60f3\u8981 JSON \u683c\u5f0f\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u4f60\u9700\u8981\u5728 sudo_logsrvd \u914d\u7f6e\u7684 [eventlog] \u90e8\u5206\u8fdb\u884c\u5982\u4e0b\u8bbe\u7f6e\uff1a<\/p>\n

log_format = json<\/pre>\n

\u5426\u5219\uff0csudo_logsrvd \u4f7f\u7528\u4f20\u7edf\u7684 sudo \u65e5\u5fd7\u683c\u5f0f\uff0c\u5e76\u4f5c\u4e86\u7b80\u5355\u7684\u4fee\u6539\u3002\u5b83\u8fd8\u5305\u62ec\u65e5\u5fd7\u6765\u6e90\u7684\u4e3b\u673a\u7684\u4fe1\u606f\uff1a<\/p>\n

Nov 18 12:40:16 centos8splunk.localdomain sudo[21028]:   czanik : 3 incorrect password attempts ; HOST=centos7sudo.localdomain ; TTY=pts\/0 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/bin\/bash\r\nNov 18 12:40:23 centos8splunk.localdomain sudo[21028]:   czanik : HOST=centos7sudo.localdomain ; TTY=pts\/0 ; PWD=\/home\/czanik ; USER=root ; TSID=00000A ; COMMAND=\/bin\/bash\r\nNov 18 12:40:30 centos8splunk.localdomain sudo[21028]:   czanik : command rejected by I\/O plugin ; HOST=centos7sudo.localdomain ; TTY=pts\/0 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/bin\/bash<\/pre>\n
3\u3001\u4e2d\u7ee7<\/strong><\/div>\n

\u5f53\u6700\u521d\u5f15\u5165 sudo_logsrvd\uff081.9.0 \u7248\uff09\u8fdb\u884c\u4f1a\u8bdd\u8bb0\u5f55\u96c6\u4e2d\u6536\u96c6\u65f6\uff0c\u5ba2\u6237\u7aef\u53ea\u80fd\u76f4\u63a5\u53d1\u9001\u8bb0\u5f55\u30021.9.7 \u7248\u672c\u5f15\u5165\u4e86\u4e2d\u7ee7\u7684\u6982\u5ff5\u3002\u6709\u4e86\u4e2d\u7ee7\uff0c\u4f60\u53ef\u4ee5\u4e0d\u76f4\u63a5\u53d1\u9001\u8bb0\u5f55\uff0c\u800c\u662f\u5c06\u8bb0\u5f55\u53d1\u9001\u5230\u591a\u7ea7\u4e2d\u95f4\u4e3b\u673a\uff0c\u8fd9\u4e9b\u4e2d\u95f4\u4e3b\u673a\u6784\u6210\u4f60\u7684\u7f51\u7edc\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u8fd9\u5f88\u91cd\u8981\uff1f\u9996\u5148\uff0c\u4e2d\u7ee7\u4f7f\u6536\u96c6\u4f1a\u8bdd\u8bb0\u5f55\u6210\u4e3a\u53ef\u80fd\uff0c\u5373\u4f7f\u96c6\u4e2d\u4e3b\u673a\u7531\u4e8e\u7f51\u7edc\u95ee\u9898\u6216\u7ef4\u62a4\u800c\u4e0d\u53ef\u7528\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0csudo \u5728\u65e0\u6cd5\u53d1\u9001\u8bb0\u5f55\u65f6\u62d2\u7edd\u8fd0\u884c\uff0c\u6240\u4ee5\u4e2d\u7ee7\u53ef\u4ee5\u786e\u4fdd\u4f60\u53ef\u4ee5\u5168\u5929\u5019\u4f7f\u7528 sudo\u3002<\/p>\n

\u5176\u6b21\uff0c\u5b83\u8fd8\u5141\u8bb8\u4f60\u5bf9\u7f51\u7edc\u6709\u66f4\u4e25\u683c\u7684\u63a7\u5236\u3002\u4f60\u4e0d\u9700\u8981\u4e3a\u6240\u6709\u7684\u4e3b\u673a\u5411\u4e2d\u5fc3\u7684 sudo_logsrvd \u5f00\u653e\u9632\u706b\u5899\uff0c\u800c\u53ea\u9700\u8981\u5141\u8bb8\u4f60\u7684\u4e2d\u7ee7\u901a\u8fc7\u3002<\/p>\n

\u6700\u540e\uff0c\u5b83\u5141\u8bb8\u4f60\u4ece\u6ca1\u6709\u76f4\u63a5\u4e92\u8054\u7f51\u63a5\u5165\u7684\u7f51\u7edc\u4e2d\u6536\u96c6\u4f1a\u8bdd\u8bb0\u5f55\uff0c\u6bd4\u5982 AWS \u79c1\u6709\u7f51\u7edc\uff0c\u4f60\u53ef\u4ee5\u5728\u7f51\u5173\u4e3b\u673a\u4e0a\u4ee5\u4e2d\u7ee7\u6a21\u5f0f\u5b89\u88c5 sudo_logsrvd\u3002<\/p>\n

\u5f53\u4f60\u4f7f\u7528\u4e2d\u7ee7\u65f6\uff0csudo \u5ba2\u6237\u7aef\u548c\u4e2d\u5fc3\u7684 sudo_logsrvd \u7684\u914d\u7f6e\u4fdd\u6301\u4e0d\u53d8\u3002\u5728\u4e2d\u7ee7\u4e3b\u673a\u4e0a\uff0c\u5728 sudo_logsrvd.conf \u7684 [relay] \u90e8\u5206\u6dfb\u52a0\u4ee5\u4e0b\u4e00\u884c\uff1a<\/p>\n

relay_host = 172.16.167.161<\/pre>\n

\u5982\u679c\u77e5\u9053\u901a\u5f80\u4e2d\u5fc3\u670d\u52a1\u5668\u7684\u7f51\u7edc\u8fde\u63a5\u6709\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u914d\u7f6e\u4e2d\u7ee7\uff0c\u5728\u8f6c\u53d1\u8bb0\u5f55\u4e4b\u524d\u50a8\u5b58\u5b83\uff1a<\/p>\n

store_first = true<\/pre>\n
4\u3001\u8bb0\u5f55\u5b50\u547d\u4ee4<\/strong><\/div>\n

\u4f60\u662f\u5426\u66fe\u7ecf\u60f3\u77e5\u9053\u5728\u901a\u8fc7 sudo \u542f\u52a8\u7684 shell \u4f1a\u8bdd\u4e2d\u53d1\u751f\u4e86\u4ec0\u4e48\uff1f\u662f\u7684\uff0c\u4f1a\u8bdd\u8bb0\u5f55\u662f\u5b58\u5728\u7684\uff0c\u4f46\u662f\u4e3a\u4e86\u770b\u51e0\u4e2a\u547d\u4ee4\u7684\u6267\u884c\u60c5\u51b5\u800c\u770b\u51e0\u4e2a\u5c0f\u65f6\u7684\u8bb0\u5f55\u662f\u5f88\u65e0\u804a\u7684\uff0c\u4e5f\u662f\u5bf9\u65f6\u95f4\u7684\u5de8\u5927\u6d6a\u8d39\u3002\u5e78\u8fd0\u7684\u662f\uff0c1.9.8 \u7248\u672c\u5f15\u5165\u4e86\u5b50\u547d\u4ee4\u65e5\u5fd7\u3002\u73b0\u5728\uff0c\u53ea\u9700\u5b9a\u671f\u68c0\u67e5\u4f60\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5e76\u5728\u53d1\u751f\u53ef\u7591\u60c5\u51b5\u65f6\u624d\u89c2\u770b\u8bb0\u5f55\u3002<\/p>\n

\u4f60\u751a\u81f3\u4e0d\u9700\u8981\u4e00\u4e2a\u5141\u8bb8 shell \u8bbf\u95ee\u7684\u89c4\u5219\uff0c\u53ea\u9700\u8981\u8bbf\u95ee\u4e00\u4e2a\u7f16\u8f91\u5668\u5c31\u53ef\u4ee5\u8bbf\u95ee shell\u3002\u5927\u591a\u6570\u7f16\u8f91\u5668\u53ef\u4ee5\u8fd0\u884c\u5916\u90e8\u547d\u4ee4\u3002\u6211\u6700\u559c\u6b22\u7684\u7f16\u8f91\u5668\u662f JOE\uff0c\u8fd9\u662f\u6211\u901a\u8fc7 sudo \u542f\u52a8\u5b83\u65f6\u53ef\u4ee5\u770b\u5230\u7684\u60c5\u51b5\uff1a<\/p>\n

Aug 30 13:03:00 czplaptop sudo[10150]:   czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/joe<\/pre>\n

\u4e0d\u7528\u5403\u60ca\uff0c\u5c31\u5728\u4e00\u4e2a\u7f16\u8f91\u5668\u91cc\uff0c\u6211\u751f\u6210\u4e00\u4e2a shell \u5e76\u4ece\u8be5 shell \u4e2d\u5220\u9664\u4e00\u4e9b\u6587\u4ef6\u548c\u5206\u533a\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u770b\u5f53\u4f60\u542f\u7528\u5bf9\u5b50\u547d\u4ee4\u8bb0\u5f55\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1a<\/p>\n

Aug 30 13:13:14 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/joe\r\nAug 30 13:13:37 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/bin\/sh -c \/bin\/bash\r\nAug 30 13:13:37 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/bin\/bash\r\nAug 30 13:13:37 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/readlink \/proc\/10889\/exe\r\n[...]\r\nAug 30 13:13:37 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/sed -r s@\/*:|([^\\\\\\\\]):@\\1\\n@g;H;x;s@\/\\n@\\n@\r\nAug 30 13:13:37 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/tty\r\nAug 30 13:13:42 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/id\r\nAug 30 13:13:56 czanik : TTY=pts\/1 ; PWD=\/home\/czanik ; USER=root ; COMMAND=\/usr\/bin\/ls -A -N --color=none -T 0 \/usr\/share\/syslog-ng\/include\/scl\/<\/pre>\n

\u6211\u7701\u7565\u4e86\u51e0\u5341\u884c\u4ee5\u8282\u7701\u4e00\u4e9b\u7a7a\u95f4\uff0c\u4f46\u4f60\u4ecd\u7136\u53ef\u4ee5\u770b\u5230\u6211\u542f\u52a8\u4e86\u4e00\u4e2a shell\uff0cbash_profile \u6267\u884c\u7684\u547d\u4ee4\u4e5f\u53ef\u4ee5\u5728\u65e5\u5fd7\u4e2d\u770b\u5230\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u5728 sudoers \u6587\u4ef6\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u8bbe\u7f6e\u6765\u542f\u7528\u5b50\u547d\u4ee4\u65e5\u5fd7\uff1a<\/p>\n

`Defaults log_subcmds`<\/pre>\n

\u5728\u4f20\u7edf\u7684 sudo \u65e5\u5fd7\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4ece sudo \u8fdb\u7a0b ID \u770b\u5230\u8fd9\u4e9b\u65e5\u5fd7\u6b63\u662f\u6765\u81ea\u540c\u4e00\u4e2a sudo\u4f1a\u8bdd\u3002\u5982\u679c\u4f60\u6253\u5f00 JSON \u683c\u5f0f\u7684\u65e5\u5fd7\uff0c\u5982\u524d\u9762\u6240\u793a\uff0csudo \u5728\u65e5\u5fd7\u4e2d\u8bb0\u5f55\u4e86\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u4f7f\u4e4b\u66f4\u5bb9\u6613\u8fdb\u884c\u5206\u6790\u3002<\/p>\n

5\u3001\u62e6\u622a\u5b50\u547d\u4ee4<\/strong><\/div>\n

\u8bb0\u5f55\u5b50\u547d\u4ee4\u53ef\u4ee5\u6d88\u9664 sudo \u7684\u5927\u90e8\u5206\u9690\u60a3\uff0c\u4f46\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u4e0d\u53ea\u662f\u60f3\u89c2\u5bdf\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff0c\u8fd8\u60f3\u63a7\u5236\u4e8b\u4ef6\u7684\u6d41\u7a0b\u3002\u4f8b\u5982\uff0c\u4f60\u9700\u8981\u7ed9\u4e00\u4e2a\u7528\u6237\u63d0\u4f9b shell \u6743\u9650\uff0c\u4f46\u4ecd\u60f3\u963b\u6b62\u4ed6\u4eec\u8fd0\u884c\u4e00\u4e2a\u7279\u5b9a\u7684\u547d\u4ee4\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u62e6\u622a\u662f\u7406\u60f3\u7684\u9009\u62e9\u3002\u5f53\u7136\uff0c\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\uff0c\u6bd4\u5982\u4f60\u4e0d\u80fd\u9650\u5236 shell \u7684\u5185\u7f6e\u547d\u4ee4\u3002<\/p>\n

\u6bd4\u65b9\u8bf4\uff0cwho \u547d\u4ee4\u5f88\u5371\u9669\u3002\u4f60\u53ef\u4ee5\u5206\u4e24\u6b65\u542f\u7528\u62e6\u622a\u3002\u7b2c\u4e00\u4e2a\u6b65\u9aa4\u662f\u542f\u7528\u5b83\uff0c\u7b2c\u4e8c\u4e2a\u6b65\u9aa4\u662f\u914d\u7f6e\u5b83\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u7684\u7528\u6237\u4e0d\u88ab\u5141\u8bb8\u8fd0\u884c who\uff1a<\/p>\n

Defaults intercept\r\nczanik ALL = (ALL) ALL, !\/usr\/bin\/who<\/pre>\n
\u5f53\u6211\u901a\u8fc7sudo \u542f\u52a8\u4e00\u4e2a root shell \u4f1a\u8bdd\u5e76\u5c1d\u8bd5\u8fd0\u884c who \u65f6\uff0c\u4f1a\u53d1\u751f\u4ee5\u4e0b\u60c5\u51b5\uff1a<\/pre>\n
$ sudo -s\r\n# who\r\nSorry, user czanik is not allowed to execute '\/usr\/bin\/who' as root on czplaptop.\r\nbash: \/usr\/bin\/who: Permission denied<\/pre>\n

\u4f60\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5b8c\u5168\u7981\u7528\u8fd0\u884c shell\uff1a<\/p>\n

Defaults intercept\r\nCmnd_Alias SHELLS=\/usr\/bin\/bash, \/usr\/bin\/sh, \/usr\/bin\/csh\r\nczanik ALL = (ALL) ALL, !SHELLS<\/pre>\n

\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u80fd\u901a\u8fc7 sudo \u542f\u52a8 shell \u4f1a\u8bdd\u3002\u4e0d\u4ec5\u5982\u6b64\uff0c\u4f60\u4e5f\u4e0d\u80fd\u4ece\u7f16\u8f91\u5668\u4e2d\u6267\u884c\u5916\u90e8\u547d\u4ee4\u3002\u5f53\u6211\u8bd5\u56fe\u4ece vi \u4e2d\u542f\u52a8 ls \u547d\u4ee4\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff1a<\/p>\n

$ sudo vi \/etc\/issue\r\nSorry, user czanik is not allowed to execute '\/bin\/bash -c \/bin\/ls' as root on czplaptop.\r\nCannot execute shell \/bin\/bash\r\nPress ENTER or type command to continue<\/pre>\n
\u63a5\u4e0b\u6765\u662f\u4ec0\u4e48\uff1f<\/strong><\/div>\n

\u6211\u5e0c\u671b\u8bfb\u4e86\u6211\u7684\u6587\u7ae0\u540e\uff0c\u81ea\u5df1\u5c1d\u8bd5\u4e00\u4e0b\u8fd9\u4e9b\u65b0\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f60\u7684\u8f6f\u4ef6\u5305\u7ba1\u7406\u5668\u5728\u8bb8\u591a Linux \u53d1\u884c\u7248\u548c UNIX \u53d8\u79cd\u4e0a\u5b89\u88c5\u6700\u65b0\u7684 sudo\uff0c\u6216\u8005\u4f7f\u7528 Sudo \u7f51\u7ad9 \u4e0a\u7684\u4e8c\u8fdb\u5236\u5b89\u88c5\u7a0b\u5e8f\u3002<\/p>\n

\u8fd9\u7bc7\u6587\u7ae0\u53ea\u662f\u4e3a\u4f60\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b0\u7684\u53ef\u80fd\u6027\u7684\u6982\u8ff0\u3002\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u8fd9\u4e9b\u529f\u80fd\u7684\u4fe1\u606f\uff0c\u8bf7\u8bbf\u95ee\u7f51\u7ad9\uff0c\u90a3\u91cc\u6709\u624b\u518c\u9875\u9762\uff0c\u4e5f\u6709 Sudo \u535a\u5ba2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5f53\u4f60\u60f3\u6388\u4e88\u4f60\u7684\u4e00\u4e9b\u7528\u6237\u7ba1\u7406\u6743\u9650\uff0c\u540c\u65f6\u63a7\u5236\u548c\u68c0\u67e5\u4ed6\u4eec\u5728\u4f60\u7684\u7cfb\u7edf\u4e0a\u505a\u4ec0\u4e48\u65f6\uff0c\u4f60\u4f1a\u4f7f\u7528 sudo\u3002\u7136\u800c\uff0c\u5373\u4f7f\u662f su […]<\/p>\n","protected":false},"author":1469,"featured_media":257948,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-257946","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\/257946","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\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=257946"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/257946\/revisions"}],"predecessor-version":[{"id":257949,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/257946\/revisions\/257949"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/257948"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=257946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=257946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=257946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}