# 应急响应笔记(Linux）【通过】

**URL:** <https://forum.90sec.com/t/topic/400>\
**Category:** 账号审核\
**Created:** [2019 年9 月 13 日 07:16 UTC](https://forum.90sec.com/t/topic/400 "2019-09-13T07:16:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

作者： ![Ascotbe](https://forum.90sec.com/user_avatar/forum.90sec.com/ascotbe/32/2662_2.png) [@Ascotbe](https://forum.90sec.com/u/Ascotbe)\
发布日期： [2019 年9 月 13 日 07:16 UTC](https://forum.90sec.com/t/topic/400/1 "2019-09-13T07:16:30Z")

</div>

## A、日志分析

 ![](https://forum.90sec.com/uploads/default/original/2X/e/edb3431af02027be189b66832f8e442f05c2ba9f.png)

### 1、除root之外，是否还有其它特权用户(uid 为0)

```
awk -F: '$3==0{print $1}' /etc/passwd
```

### 2、可以远程登录的帐号信息

```
awk '/\$1|\$6/{print $1}' /etc/shadow
```

### 3、查看登录失败信息

```
grep -o "Failed password" /var/log/secure|uniq -c
```

### 4、输出登录爆破的第一行和最后一行，确认爆破时间范围

```
grep "Failed password" /var/log/secure|head -1
grep "Failed password" /var/log/secure|tail -1
```

### 5、进一步定位有哪些IP在爆破？

```
grep "Failed password" /var/log/secure|grep -E -o  
"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" 
|uniq -c | sort -nr 

```

### 6、爆破用户名字典都有哪些？

```
grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}'|uniq -c|sort -nr
```

### 7、登录成功的日期、用户名、IP

```
grep "Accepted " /var/log/secure | awk '{print $1,$2,$3,$9,$11}' 
```

### 8、统计一下登录成功的IP有哪些

```
grep "Accepted " /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | more
```

### 9、除root帐号外，其他帐号是否存在sudo权限。如非管理需要，普通帐号应删除sudo权限

```
more /etc/sudoers | grep -v "^#\|^$" | grep "ALL=(ALL)"
```

### 10、禁用或删除多余及可疑的帐号

```
    usermod -L user 禁用帐号，帐号无法登录，/etc/shadow第二栏为!开头
	userdel user 删除user用户
	userdel -r user 将删除user用户，并且将/home目录下的user目录一并删除
```

### 11、增加一个用户kali日志

```
grep "useradd" /var/log/secure 
```

### 12、删除用户kali日志

```
grep "userdel" /var/log/secure
```

### 13、sudo授权执行

```
查看谁有sudo授权执行权限(权限级别)
sudo -l
```

### 14、服务器日志

```
/var/log/httpd/
/www/wwwroot/
```

### 15、基础信息查看

```
who 查看当前登录用户（tty本地登陆 pts远程登录）
w 查看系统信息，想知道某一时刻用户的行为
uptime 查看登陆多久、多少用户，负载
```

## B、历史命令查询

通过.bash\_history查看帐号执行过的系统命令

### 1、root的历史命令

```
histroy
```

### 2、打开/home各帐号目录下的.bash\_history，查看普通帐号的历史命令

```
为历史的命令增加登录的IP地址、执行命令时间等信息：
1）保存1万条命令
sed -i 's/^HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile
2）在/etc/profile的文件尾部添加如下行数配置信息：
######jiagu history xianshi#########
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
if ["$USER_IP" = ""]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP `whoami` "
shopt -s histappend
export PROMPT_COMMAND="history -a"
######### jiagu history xianshi ##########
3）source /etc/profile让配置生效

生成效果： 1 2018-07-10 19:45:39 192.168.204.1 root source /etc/profile
```

### 3、历史操作命令清除

```
history -c
但此命令并不会清除保存在文件中的记录，因此需要手动删除.bash_profile文件中的记录。
```

### 4、入侵排查：
进入用户目录下

```
cat .bash_history >> history.txt
```

## C、检查异常端口

### 1、使用netstat 网络连接命令，分析可疑端口、IP、PID

```
netstat -antlp|more
!net
lsof -i:80 查看指定端口
netstat -anp|grep 158.x.x.x 从连接的IP来定位PID，如果是瞬时建立的才找不到

```

### 2、查看下pid所对应的进程文件路径

```
运行
ls -l /proc/$PID/exe
file /proc/$PID/exe（$PID 为对应的pid 号）
```

## D、检查异常进程

```
使用ps命令，分析进程
ps aux | grep pid (pid表示要查询的关键字)
```

## F、定时任务

### 1、查看定时任务

```
crontab -l 表面上查看定时任务
cat /etc/crontab 查看定时任务的文件里面是否存在定时任务
ls -al /var/spool/cron/\*        
cat /var/spool/cron/\* 查看文件夹里面是否有其他定时任务的文件	
ls -al /etc/cron.d/\*
for u in \`cat /etc/passwd |cut -d ":" -f1\`;do crontab -l -u $u; done
```

### 2、删除定时任务

```
crontab -r 表面上删除定时任务
```

### 2、编辑定时任务

```
crontab -e 
定时任务解读：
前面5个星分别代表分-时-天-月-星期 后面跟命令
 \* \*	\*	\*	\*	command
\*/15	\*	\*	\*	\*	command（表示每15分钟运行一次）

```

## F、杂项

### 查看ssh秘钥

```
cat .ssh/authorized_keys 查看命令
/root/.ssh/authorized_keys ssh秘钥文件所在路径
```

### 查看CPU运行

```
top
```

### 结束进程

```
kill PID
kill -9 PID 彻底杀死进程
kill -KILL PID 强制杀死进程
```

### 查看进程

```
ps -a 列出的是当前控制终端启动的进程
ps -A 系统全部启动进程
ps auxf 查看父进程关联的子进程
pstree 查看进程树
```

### 开机启动的一些路径

```
/etc/rc.d/rc
/etc/rc
/etc/rc.local
/etc/rc.d/rc.local
/etc/rc.d/rc
/etc/rc$runlevel.d/ 该目录下都是链接的可执行文件，也可以自己添加可执行程序
/etc/ld.so.cache   
/etc/ld.so.preload 
/usr/local/lib/libioset.so
/etc/init.d
另外一个添加启动项的地方在 /etc/profile里面，还有 /etc/profile.d/目录下以sh结尾的文件
```

### 封禁IP
参数-I是表示Insert（添加），-D表示Delete（删除）。后面跟的是规则，INPUT表示入站，1.1.1.1表示要封停的IP，DROP表示放弃连接。

```
iptables -I INPUT -s 1.1.1.1 -j DROP 封禁IP进口
iptables -I OUTPUT -s 1.1.1.1/24 -j DROP	封禁IP出口
iptables -I INPUT -s 1.1.1.1/24 -j DROP 封禁IP段
iptables --list 查看规则
```

对IP限制后保存信息

```
yum install iptables-services
chkconfig iptables on
service iptables save
cat /etc/sysconfig/iptables
service iptables start
iptables -nL
```

### 查看系统服务

如果删除了计划任务，还有文件删除不了 可以查看系统服务是否存在病毒

```
chkconfig –list #列出所有的系统服务
chkconfig –add httpd #增加httpd服务
chkconfig –del httpd #删除httpd服务
```

### 文件下载
如果关闭了FTP，又无法使用xftp访问卡原始用scp命令下载

```
scp -r 目标文件路径 root@1.1.1.1:/home/
```

### 查看运行文件所在路径

```
ll /proc/PID 查看程序对应的启动位置
which XXXX 查看程序在哪个文件夹 XXXX表示程序名 
lsof /usr/bin/\* 查看某个路径下的运行中的进程列表
pidof /usr/bin/\* 查看某个路径下运行进程的 pid
```

### 对文件进行限制

```
chmod 000 /usr/bin/XXXXXX 设置一个文件权限为空(就是什么权限都没有
chattr +i /usr/bin 限制对/usr/bin路径修改
chattr -i /usr/bin 开放对/usr/bin路径修改

```

## 工具篇

### 1、Rootkit查杀
chkrootkit 网址：http://www.chkrootkit.org

```
使用方法：
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
tar zxvf chkrootkit.tar.gz
cd chkrootkit-0.52
make sense
#编译完成没有报错的话执行检查
./chkrootkit
```

rkhunter 网址：http://rkhunter.sourceforge.net

```
使用方法：
wget https://jaist.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.6/rkhunter-1.4.6.tar.gz
tar xzvf rkhunter
cd rkhunter
./installer.sh --layout /usr --install
rkhunter --update
rkhunter -C
```

### 2、病毒查杀

ClamAV的官方下载地址为：[http://www.clamav.net/download.html](http://www.clamav.net/download.html)

### 3、webshell查杀
linux版： 河马webshell查杀：http://www.shellpub.com 深信服Webshell网站后门检测工具：http://edr.sangfor.com.cn/backdoor\_detection.html

---

<div class="post-metadata">

作者： ![popxp1kaju](https://forum.90sec.com/user_avatar/forum.90sec.com/popxp1kaju/32/3379_2.png) [@popxp1kaju](https://forum.90sec.com/u/popxp1kaju)\
发布日期： [2019 年10 月 7 日 06:37 UTC](https://forum.90sec.com/t/topic/400/2 "2019-10-07T06:37:35Z")

</div>

#tql  
学习了 😇
