当前位置:网站首页>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记录完整性破坏的难度。
边栏推荐
- MySQL from basic to entry to high availability
- IP课笔记(4)
- leetcode剑指offer jz5 替换空格字符串
- Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)
- Leetcode sword finger offer jz42 maximum sum of continuous subarrays
- Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
- Leetcode does not add, subtract, multiply, divide, and calculate the number of 1 in binary
- Dameng database_ Small matters needing attention during use
- Simple three-step fast intranet penetration
- TensorFlow-GPU 安装 -- 056
猜你喜欢

A batch of interview questions and answers_ 20180403 latest arrangement

IP class notes (5)
![Public access intranet IIS website server [no public IP required]](/img/e5/45d7c59ed30bbf901f793f25e229e2.png)
Public access intranet IIS website server [no public IP required]

IP notes (12)

【217】#!/ The meaning of usr/bin/env

Data set and pre training model

Homework in the second week

IP notes (6)

IP job (2) rip

LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
随机推荐
MySQL forgot to exit and close the window directly. How to delete the entire folder now
mysql 忘记退出直接关闭窗口现在要删除整个文件夹如何删除
Jenkins automated unattended operation (up / down)
迭代器与生成器
Set up a WordPress personal blog locally and launch it through the intranet (22)
Do not rent servers, build your own personal business website (3)
IP notes (7)
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
Remember 20 classic interview questions of performance test in three minutes
利用内网穿透,实现公网访问内网
Leetcode sword finger offer jz73 flip word sequence
Simple three-step fast intranet penetration
Interview questions for Test Manager / test team leader / Test Supervisor
MySQL数据库—SQL汇总(记得关注我!中国加油!)
Process and planned task management
IP作业(6)
Getting started with Lunix commands - user and file permissions (Chmod details)
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
进行挂载永久挂载后无法开机
Do not rent servers, build your own personal business website (2)