总结&备忘:history记录的时间
来源:互联网 发布:电视直播软件哪个最好 编辑:程序博客网 时间:2024/05/18 00:42
最近工作中遇到一些疑似黑客入侵的案例:
客户在阿里云上购买了ECS云服务器作为应用服务器,应用运行中收到了阿里云来的异地IP登录警告短信,提示有可能登录密码已被黑客攻破
于是找到我们服务商帮忙分析处理
正常来说我们会先建议看是看该IP是否还在登录,如在就立刻kill掉其登陆会话
[root@iZ9408690vwZ ~]# who
root tty1 2016-06-28 00:08
root pts/0 2016-06-28 00:02 (223.73.58.208)
diyu pts/1 2016-06-28 00:16 (116.23.247.151)
root pts/2 2016-06-28 01:32 (223.73.58.208)
[root@iZ9408690vwZ ~]# ps
PID TTY TIME CMD
14245 pts/2 00:00:00 bash
14282 pts/2 00:00:00 ps
然后就让客户加固一下安全配置(换ssh端口,去除ssh弱算法支持,更换复杂度高一些的密码...)
最后就看异地登录者干了些什么,于是用了history命令打算查看该IP在相应的登录时间里操作了什么命令(当然也有可能已被黑客篡改)
[root@iZ9408690vwZ ~]# last
root pts/2 223.73.58.208 Tue Jun 28 01:32 still logged in
diyu pts/2 116.23.247.151 Tue Jun 28 00:41 - 01:08 (00:26)
diyu pts/2 116.23.247.151 Tue Jun 28 00:28 - 00:41 (00:12)
diyu pts/2 116.23.247.151 Tue Jun 28 00:27 - 00:28 (00:00)
diyu pts/2 116.23.247.151 Tue Jun 28 00:27 - 00:27 (00:00)
diyu pts/2 116.23.247.151 Tue Jun 28 00:18 - 00:27 (00:08)
[root@iZ9408690vwZ ~]# history
7 telnet 127.0.0.1 1234
8 ls
9 service iptables status
10 icmp-type
11 service iptables status
12 service iptables restart
13 service iptables status
14 iptables -t nat -F
15 service iptables status
16 service iptables save
可见客户没设置bash里历史记录的时间
开启bash的历史记录的时间记录方法为:
在用户配置文件中加入命令:
export HISTTIMEFORMAT="`whoami` : %F %T :"
配置了该环境变量后的history输出为:
[root@iZ9408690vwZ ~]# history
10 root : 2016-06-28 01:32:29 :icmp-type
11 root : 2016-06-28 01:32:29 :service iptables status
12 root : 2016-06-28 01:32:29 :service iptables restart
13 root : 2016-06-28 01:32:29 :service iptables status
14 root : 2016-06-28 01:32:29 :iptables -t nat -F
15 root : 2016-06-28 01:32:29 :service iptables status
16 root : 2016-06-28 01:32:29 :service iptables save
...
1006 root : 2016-06-28 01:32:29 :history
1007 root : 2016-06-28 01:32:29 :ps
1008 root : 2016-06-28 02:00:20 :export HISTTIMEFORMAT="`whoami` : %F %T :"
1009 root : 2016-06-28 02:00:23 :history
这样一来就有用户和执行时间显示了,但留意到执行设置该环境变量前的记录都为登录时间
这是因为之前的都在没设置该环境变量时的记录,在~/.bash_history里就没存相应的执行时间数据
#1467043141
less /var/log/messages
#1467043359
logout
#1467043373
export HISTTIMEFORMAT="`whoami` : %F %T :"
#1467043375
history
设置该环境变量后的历史记录前会多出一个时间戳的数据
以上只针对bash类型的shell, history是具体的shell里实现的
其他类型的shell: sh,tcsh,ksh
- 总结&备忘:history记录的时间
- history 命令显示时间记录
- linux 如何让linux的history命令显示时间记录
- centos6 history记录操作者及时间
- linux history记录加时间戳
- Linux History记录加时间戳实用技巧
- linux history 记录 时间 ip 登录用户
- Linux查看History记录加时间
- leetcode 总结,记录,备忘。153
- Linux下查看用户登陆后的操作记录及history命令显示时间
- Linux下查看用户登陆后的操作记录及history命令显示时间
- Linux下查看用户登陆后的操作记录及history命令显示时间
- CentOS-解决CentOS 7 history命令不显示操作记录的时间和用户身份问题
- 近段时间学习的总结记录
- Linux查看History记录加时间戳小技巧
- Linux查看History记录加时间戳小技巧
- 如何给history命令记录加上时间戳
- Linux查看History记录加时间戳小技巧
- 拦截器
- Android 之PackageManager框架
- 可视化文本数据—词云
- Object类&泛型数组列表(Java核心卷1-D5)
- RDMA编程1 建立侦听
- 总结&备忘:history记录的时间
- python类库
- swift:运算型属性和存储型属性
- 内核模块里的一点错误直接导致系统崩溃
- 数控软件Grbl使用系列(1):Grbl编译
- 数控软件Grbl使用系列(2):烧写到Arduino UNO
- 《重构与模式》 Swift 版之创建方法 (绝对大牛思想)
- 设计模式-简单工厂模式
- Java中反转字符串我所知的五种方法