当前位置:网站首页>history命令历史记录中加时间
history命令历史记录中加时间
2022-07-24 05:23:00 【踩坑之路】
Linux系统下可通过history命令查看用户所有的历史操作记录,但默认情况下,history命令只能查看用户历史操作记录,并不能区分用户以及操作时间,不便于审计分析。
当然,一些不好的操作习惯也可能通过命令历史泄露敏感信息。
命令历史记录中加时间
通过设置export HISTTIMEFORMAT=’\%F \%T ‘,让历史记录中带上命令执行时间。
这个配置可以写在/etc/profile中,当然如果要对指定用户做配置,这个配置可以写在/home/\$USER/.bash_profile中。
unset i
unset -f pathmunge
export HISTTIMEFORMAT='%F %T '要使配置立即生效请执行source /etc/profile,再查看history记录,可以看到记录中带上了命令执行时间。
1012 2021-03-22 13:59:10 vim /etc/profile
1013 2021-03-22 13:59:18 source /etc/profile
1014 2021-03-22 13:59:22 history如果想要实现更细化的记录,比如登陆过系统的用户、IP地址、操作命令以及操作时间一一对应,可以通过在/etc/profile里面加入以下代码实现。
export HISTTIMEFORMAT="%F %T `who -u 2>/dev/null | awk '{print $NF}'|sed 's/[()]//g'` `whoami` "修改/etc/profile并加载后,history记录如下,时间、IP、用户及执行的命令都一一对应
1042 2021-03-22 14:20:39 124.193.98.180 root vim /etc/profile
1043 2021-03-22 14:20:52 124.193.98.180 root source /etc/profile
1044 2021-03-22 14:20:53 124.193.98.180 root history通过以上配置,我们基本上可以满足日常的审计工作了,但了解系统的朋友应该很容易看出来,这种方法只是设置了环境变量,攻击者unset掉这个环境变量,或者直接删除命令历史,对于安全应急来说,这无疑是一个灾难。
针对这样的问题,我们应该通过修改bash源码,让history记录通过syslog发送到远程logserver中,大大增加了攻击者对history记录完整性破坏的难度。
边栏推荐
- [251] common test tools
- Maximum value of jz47 gifts (dynamic planning ideas)
- 【测试工具】
- 剑指offer JZ10斐波那契数列
- Heap overflow of kernel PWN basic tutorial
- Homework in the second week
- Simple three-step fast intranet penetration
- Flink time stream processing
- Mysql database - SQL summary (remember to pay attention to me! Come on in China!)
- Do not rent servers, build your own personal business website (2)
猜你喜欢
随机推荐
NTP error: no server suitable for synchronization found
Pycharm set code template
API流程和代码结构
JSP tag
IP class notes (5)
【222】内存溢出及定位
力扣986.区间列表的交集
Flink checkpoint configuration details
Flink state use
Life warning Maxim
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
leetcode剑指offer JZ73 翻转单词序列
[222] memory overflow and location
LVM与磁盘配额
Interview questions for Test Manager / test team leader / Test Supervisor
leetcode剑指offer JZ23:链表中环的入口节点
Ia class summary (2)
MySQL from basic to entry to high availability
Ia note 1









