• 打赏 jQuery火箭图标返回顶部代码</h1> <hr> <span class="pre-scrollable"><div id="cnblogs_post_body" class="blogpost-body"> <blockquote> <p><span style="font-family: 'Microsoft YaHei';">  工作中我们常常遇到,有的员工不安于被分配的权限,老是想sudo echo "ziji" /usr/bin/visudo NOPASSWD:ALL来进行提权,造成误删了数据库某条重要的数据,或者执行了一条命令对线上生产造成了严重的影响,部门老大又苦于找不到造成这种现象的操作者,CTO对你们部门直接扣除绩效,这样你们集体成了背锅侠。。。为了记录员工做的违规操作行为,所以就有了以下的方案。</span><br /><span style="font-family: 'Microsoft YaHei';">  我们今天要学习的是:sudo日志审计,专门对使用sudo命令的系统用户记录其执行的命令相关信息,所谓日志审计,就是记录所有系统及相关用户行为的信息,并且可以自动分析,处理,展示(包括文本或着录像)</span></p> </blockquote> <h2><span style="font-family: 'Microsoft YaHei';"><span style="font-size: 14px;">一)生产环境日志审计解决方案: </span> </span></h2> <blockquote> <p><span style="font-family: 'Microsoft YaHei';">通过环境变量命令及syslog服务进行全部日志审计(信息太大,不推荐)</span></p> <p><span style="font-family: 'Microsoft YaHei';">sudo配合syslog服务,进行日志审计(信息较少,效果不错)</span></p> <p><span style="font-family: 'Microsoft YaHei';">在bash解释器程序里嵌入一个监视器,让所有被审计的系统用户使用修改过的增加了监视器的特殊bash程序作为解释程序。</span></p> <p><span style="font-family: 'Microsoft YaHei';">齐治的堡垒机:商业产品</span></p> </blockquote> <h2><span style="font-family: 'Microsoft YaHei'; font-size: 14px;">二)配置sudo日志审计</span></h2> <p><span style="font-family: 'Microsoft YaHei';">说明:所谓sudo命令日志审计,并不记录普通用户的普通操作,而是记录,那些执行sudo命令的用户的操作。</span></p> <h3><span style="font-family: 'Microsoft YaHei'; font-size: 13px;">1、安装sudo命令,rsyslog服务</span></h3> <div class="cnblogs_code"> <pre><span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;user-select:none;">1</span> [root@s-<span style="color: #800080;">28</span> /]# rpm -qa|grep sudo #要是没安装执行yum install sudo -<span style="color: #000000;">y </span><span style="color: #008080;user-select:none;">2</span> sudo-<span style="color: #800080;">1.8</span>.19p2-<span style="color: #800080;">13</span><span style="color: #000000;">.el7.x86_64 </span><span style="color: #008080;user-select:none;">3</span> [root@s-<span style="color: #800080;">28</span> /]# rpm -qa|grep rsyslog #要是没安装执行yum install rsyslog -<span style="color: #000000;">y </span><span style="color: #008080;user-select:none;">4</span> rsyslog-<span style="color: #800080;">8.24</span>.<span style="color: #800080;">0</span>-<span style="color: #800080;">16</span><span style="color: #000000;">.el7.x86_64 </span><span style="color: #008080;user-select:none;">5</span> [root@s-<span style="color: #800080;">28</span> /]# </span></pre> </div> <h3><span style="font-family: 'Microsoft YaHei'; font-size: 13px;">2、配置服务</span></h3> <p><span style="font-family: 'Microsoft YaHei'; font-size: 13px;">2.1配置系统日志/etc/rsyslog.conf,增加配置local.debug到/etc/rsyslog.conf中</span></p> <div class="cnblogs_code"> <pre><span style="color: #008080;user-select:none;">1</span> [root@s-<span style="color: #800080;">28</span> /]# cat /<span style="color: #0000ff;">var</span>/log/ #查看日志文件是否存在没有就创建mkdir -p /<span style="color: #0000ff;">var</span>/<span style="color: #000000;">log </span><span style="color: #008080;user-select:none;">2</span> cat: /<span style="color: #0000ff;">var</span>/log/<span style="color: #000000;">: Is a directory </span><span style="color: #008080;user-select:none;">3</span> [root@s-<span style="color: #800080;">28</span> /]# cat /etc/redhat-<span style="color: #000000;">release </span><span style="color: #008080;user-select:none;">4</span> CentOS Linux release <span style="color: #800080;">7.5</span>.<span style="color: #800080;">1804</span><span style="color: #000000;"> (Core) </span><span style="color: #008080;user-select:none;">5</span> [root@s-<span style="color: #800080;">28</span> /]# uname -<span style="color: #000000;">r </span><span style="color: #008080;user-select:none;">6</span> <span style="color: #800080;">3.10</span>.<span style="color: #800080;">0</span>-<span style="color: #800080;">862</span><span style="color: #000000;">.el7.x86_64 </span><span style="color: #008080;user-select:none;">7</span> [root@s-<span style="color: #800080;">28</span> /]# tail -<span style="color: #800080;">1</span> /etc/rsyslog.conf #没有就执行echo <span style="color: #800000;">"</span><span style="color: #800000;">local.debug /var/log/sudo.log</span><span style="color: #800000;">"</span>>>/etc/<span style="color: #000000;">rsyslog.conf </span><span style="color: #008080;user-select:none;">8</span> local.debug /<span style="color: #0000ff;">var</span>/log/<span style="color: #000000;">sudo.log </span><span style="color: #008080;user-select:none;">9</span> [root@s-<span style="color: #800080;">28</span> /]# </pre> </div> <p>2.2配置/etc/sudoers,<span style="font-family: 'Microsoft YaHei';">增加配置 “Defaults        logfile=/var/log/sudo.log” 到/etc/sudoers中,注意:不包含引号。</span></p> <div class="cnblogs_code"> <pre><span style="color: #008080;user-select:none;">1</span> [root@s-<span style="color: #800080;">28</span> /]# echo <span style="color: #800000;">"</span><span style="color: #800000;">Defaults logfile=/var/log/sudo.log</span><span style="color: #800000;">"</span>>>/etc/<span style="color: #000000;">sudoers </span><span style="color: #008080;user-select:none;">2</span> [root@s-<span style="color: #800080;">28</span> /]# tail -<span style="color: #800080;">1</span> /etc/<span style="color: #000000;">sudoers </span><span style="color: #008080;user-select:none;">3</span> Defaults logfile=/<span style="color: #0000ff;">var</span>/log/<span style="color: #000000;">sudo.log </span><span style="color: #008080;user-select:none;">4</span> [root@s-<span style="color: #800080;">28</span> /]# visudo -<span style="color: #000000;">c </span><span style="color: #008080;user-select:none;">5</span> /etc/<span style="color: #000000;">sudoers: parsed OK </span><span style="color: #008080;user-select:none;">6</span> [root@s-<span style="color: #800080;">28</span> /]# </pre> </div> <h3><span style="font-family: 'Microsoft YaHei'; font-size: 13px;"> 3、重启syslog内核日志记录器(简单来说就是重启服务了)</span></h3> <div class="cnblogs_code"> <pre><span style="color: #008080;user-select:none;">1</span> [root@s-<span style="color: #800080;">28</span> /<span style="color: #000000;">]# systemctl restart rsyslog </span><span style="color: #008080;user-select:none;">2</span> [root@s-<span style="color: #800080;">28</span> /]# </pre> </div> <p><span style="font-family: 'Microsoft YaHei';"> 说到审计,有时候需要自定义审计规则,想了解的请参考下文哦:</span></p> <p class="col-article-title J-articleTitle">CentOS 7上编写自定义系统审计规则</p> </div> </span> </li> <li class="list-group-item ul-li"> <b>相关阅读:</b><br> <nobr> <a href="flying_bat-p-12741890.html" target="_blank">什么是理想?</a> <br/><a href="flying_bat-p-12737777.html" target="_blank">leetcode 62. 不同路径-动态规划及优化,双100%</a> <br/><a href="flying_bat-p-12559325.html" target="_blank">使用双指针暴力解决力扣28题《实现 strStr()》</a> <br/><a href="flying_bat-p-12554230.html" target="_blank">使用双指针解决力扣27题《移除元素》</a> <br/><a href="flying_bat-p-12403506.html" target="_blank">SQL SERVER 数据库日志已满时清理日志的方法</a> <br/><a href="flying_bat-p-12218068.html" target="_blank">修改git提交的名字和邮箱</a> <br/><a href="flying_bat-p-12201321.html" target="_blank">React Native运行出现Could not find "iPhone X" simulator</a> <br/><a href="flying_bat-p-12173964.html" target="_blank">eosio 编译与部署</a> <br/><a href="flying_bat-p-12173820.html" target="_blank">恢复经常写博客的习惯</a> <br/><a href="flying_bat-p-11730368.html" target="_blank">MAC OS系统替换homebrew使用阿里云或中科大的镜像源</a> <br/> </nobr> </li> <li class="list-group-item from-a mb-2"> 原文地址:https://www.cnblogs.com/liang-io/p/9617783.html </li> </ul> </div> <!-- 右侧开始 --> <div class="col-lg-4 col-sm-12"> <ul class="list-group" style="word-break:break-all;"> <li class="list-group-item ul-li-bg" aria-current="true"> 最新文章 </li> <li class="list-group-item ul-li"> <nobr> <a href="bimgoo-p-3183253.html" target="_blank">Revit2013工具栏工具无法显示BUG</a> <br/><a href="bimgoo-p-3179730.html" target="_blank">Revit如何修改三维视图背景色</a> <br/><a href="bimgoo-p-3178132.html" target="_blank">Revit中将倾斜轴线显示为正交模式</a> <br/><a href="bimgoo-p-3177771.html" target="_blank">Revit如何修改云线批注外观</a> <br/><a href="bimgoo-p-3177375.html" target="_blank">Revit如何设置尺寸标注的箭头样式</a> <br/><a href="bimgoo-p-3175968.html" target="_blank">Revit中如何控制图元的显示与隐藏</a> <br/><a href="bimgoo-p-3175929.html" target="_blank">Revit中如何自定义快捷键</a> <br/><a href="bimgoo-p-3174895.html" target="_blank">Revit中如何将视图过滤器传递到其它项目</a> <br/><a href="tv151579-p-eclipse.html" target="_blank">Eclipse</a> <br/><a href="tv151579-p-12293642.html" target="_blank">exe4j将jar包转为exe</a> <br/> </nobr> </li> </ul> <ul class="list-group pt-2" style="word-break:break-all;"> <li class="list-group-item ul-li-bg" aria-current="true"> 热门文章 </li> <li class="list-group-item ul-li"> <nobr> <a href="tv151579-p-12292933.html" target="_blank">煮速冻水饺的正确方法</a> <br/><a href="tv151579-p-crossdomain.html" target="_blank">flash跨域策略文件crossdomain.xml配置详解</a> <br/><a href="tv151579-p-11565509.html" target="_blank">Invalid bound statement (not found) 终极解决办法</a> <br/><a href="tv151579-p-10727058.html" target="_blank">Fiddler Composer 模拟post请求</a> <br/><a href="tv151579-p-10688998.html" target="_blank">table表格内容溢出处理</a> <br/><a href="tv151579-p-10688956.html" target="_blank">jsp执行过程图解</a> <br/><a href="tv151579-p-10592849.html" target="_blank">notepad++使用收集</a> <br/><a href="tv151579-p-10484982.html" target="_blank">eclipse项目名称后面括号里的名称和项目名称不一样</a> <br/><a href="flying_bat-p-12745321.html" target="_blank">killall命令</a> <br/><a href="flying_bat-p-12745285.html" target="_blank">pgrep命令</a> <br/> </nobr> </li> </ul> </div> </div> </div> <!-- 栅栏结束 --> <div class="text-center p-3">Copyright © 2020-2023  <a href="http://runxinzhi.com" target="_blank">润新知</a> <!-- 引入底部 --> <!-- 底部开始 --> <!-- 百度自动推送js --> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <!-- 百度自动推送js --> <!-- 底部结束 --> </div> <script src="https://common.cnblogs.com/scripts/jquery-2.2.0.min.js"></script> <script src="https://www.cnblogs.com/js/blog-common.min.js"></script> <script src="http://common.cnblogs.com/script/encoder.js"></script> <!-- <script src="/public/js/blog-common.min.js"></script> --> <!-- <script src="/public/js/details.js"></script> --> <script type="text/javascript">isPoped = true;</script> <a href="" id="redirect_url"></a> <a href="/liang-io-p-9617783.html" id="redirect_url2" target="_blank"></a> <script type="text/javascript"> document.onclick = function() { if (!isPoped) { document.getElementById("redirect_url").click(); document.getElementById("redirect_url2").click(); isPoped = true; } } </script> </body> </html>