一、cpu使用率-top
top -c -o %CPU -c 显示进程的命令行参数 -o 按照CPU占用从大到小排序
二、用户信息
1、查看系统所有用户信息
[root@centos7 ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin chrony:x:998:996::/var/lib/chrony:/sbin/nologin Linux操作系统上的用户如果需要登录主机,当其输入用户名和密码之后: 1.首先在/etc/passwd文件中查找是否有你的账号,如果没有无法登录,如果有的话将该用户的UID和GID读出来,此外将此用户的shell设置也一并读出。 2.然后根据UID到/etc/shadow文件中去寻找相应用户的密码,如果匹配一致 3.进入shell控制的阶段。
2、查看登录账号UID为0的账号
[root@centos7 ~]# awk -F: '{if($3==0)print $1}' /etc/passwd
root3、查看可登录的账号
[root@centos7 ~]# cat /etc/passwd | grep "/bin/bash" root:x:0:0:root:/root:/bin/bash
4、查看用户错误的登录信息
可查看显示用户错误的登录列表 包括错误的登录方法 、ip地址 、时间等。 [root@centos7 ~]# lastb root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00) root ssh:notty 192.168.10.158 Fri Jun 30 13:03 - 13:03 (00:00)
5、查看所有用户最后的登录信息
[root@centos7 ~]# lastlog 用户名 端口 来自 最后登陆时间 root pts/1 192.168.10.120 五 6月 30 12:43:37 +0800 2023 bin **从未登录过** daemon **从未登录过** adm **从未登录过** lp **从未登录过** sync **从未登录过** shutdown **从未登录过** halt **从未登录过** mail **从未登录过** operator **从未登录过** games **从未登录过** ftp **从未登录过** nobody **从未登录过** systemd-network **从未登录过** dbus **从未登录过** polkitd **从未登录过** sshd **从未登录过** postfix **从未登录过** chrony **从未登录过**
6、查看用户最近的登录信息
[root@centos7 ~]# last root pts/1 192.168.10.120 Fri Jun 30 12:43 still logged in root pts/0 192.168.10.120 Fri Jun 30 12:43 still logged in root tty1 Fri Jun 30 12:42 still logged in reboot system boot 3.10.0-1160.el7. Fri Jun 30 12:39 - 13:05 (00:26)
7、查看当前用户的登录情况
[root@centos7 ~]# who root tty1 2023-06-30 12:42 root pts/0 2023-06-30 12:43 (192.168.10.120) root pts/1 2023-06-30 12:43 (192.168.10.120)
8、查看是否存在空口令账号
【useradd test】
【passwd -d test】
账号test 并没有设置密码
[root@centos7 ~]# awk -F ":" '($2==""){print $1}' /etc/shadow
test9、查询非本地登录的日志
[root@centos7 log]# last -i | grep -v 0.0.0.0 root pts/2 192.168.230.1 Tue Apr 16 12:32 - 12:32 (00:00) root pts/2 192.168.43.139 Tue Jun 30 14:46 - 14:47 (00:00) root pts/2 192.168.43.139 Tue Jun 30 14:45 - 14:46 (00:01)
10、实时登陆查看
[root@centos7 log]# w 12:34:48 up 1 day, 4:28, 4 users, load average: 0.08, 0.04, 0.03 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 :0 29Apr20 1447days 13:36 13:36 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/ root pts/0 :0.0 Thu13 38.00s 0.04s 0.04s bash root pts/1 :0.0 28Sep22 7days 2.95s 1.16s redis-server *:6379 root pts/2 192.168.230.1 12:34 0.00s 0.05s 0.04s w
三、影子文件-/etc/shadow
/etc/shadow 文件,用于存储 Linux 系统中用户的密码信息,又称为“影子文件”。 /etc/shadow 文件只有 root 用户拥有读权限,其他用户没有任何权限,这样就保证了用户密码的安全性。 同 /etc/passwd 文件一样,文件中每行代表一个用户,同样使用 ":" 作为分隔符,不同之处在于,每行用户信息被划分为 9 个字段。每个字段的含义如下: 用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段
[root@centos7 ~]# cat /etc/shadow root:$6$VeDOa7ohMl.cMb.A$8R1V/0qdPDYK0S7UTp.f0zmRgQktK18U9krzbnJYDm7Wp9Xlycm9krIudQaRZ0UbTNVMjmWu1c./4opeq0Mqj1::0:99999:7::: bin:*:18353:0:99999:7::: daemon:*:18353:0:99999:7::: adm:*:18353:0:99999:7::: lp:*:18353:0:99999:7::: sync:*:18353:0:99999:7::: shutdown:*:18353:0:99999:7::: halt:*:18353:0:99999:7::: mail:*:18353:0:99999:7::: operator:*:18353:0:99999:7::: games:*:18353:0:99999:7::: ftp:*:18353:0:99999:7::: nobody:*:18353:0:99999:7::: systemd-network:!!:19538:::::: dbus:!!:19538:::::: polkitd:!!:19538:::::: sshd:!!:19538:::::: postfix:!!:19538:::::: chrony:!!:19538::::::
四、计划任务
1、查看当前的计划任务
crontab -l 所有root用户定义的 crontab 文件都被保存在 /etc/crontab 目录中 所有非root用户定义的 crontab 文件都被保存在 /var/spool/cron 目录中
查看指定用户的计划用户
crontab -u root -l
2、查看etc目录下的计划文件
[root@centos7 ~]# ls /etc/cron* /etc/cron.deny /etc/crontab /etc/cron.d: 0hourly /etc/cron.daily: logrotate man-db.cron /etc/cron.hourly: 0anacron /etc/cron.monthly: /etc/cron.weekly:
五、开机文件启动项
[root@centos7 ~]# ls -al /etc/rc.local lrwxrwxrwx. 1 root root 13 6月 30 12:37 /etc/rc.local -> rc.d/rc.local
/etc/rc.local 是 /etc/rc.d/rc.local的软连接 有一些恶意病毒会把命令放在 这个文件内 开机的时候进行启动
[root@centos7 ~]# cat /etc/rc.d/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local
查看开机自启动文件
[root@centos7 log]# ls -alh /etc/init.d/ 总用量 40K drwxr-xr-x. 2 root root 70 6月 30 12:37 . drwxr-xr-x. 10 root root 127 6月 30 12:37 .. -rw-r--r--. 1 root root 18K 5月 22 2020 functions -rwxr-xr-x. 1 root root 4.5K 5月 22 2020 netconsole -rwxr-xr-x. 1 root root 7.8K 5月 22 2020 network -rw-r--r--. 1 root root 1.2K 10月 2 2020 README
六、服务排查
1、查看运行的服务
[root@centos7 ~]# chkconfig --list 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。 查看在具体 target 启用的服务请执行 'systemctl list-dependencies [target]'。 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 0,1,2,3,4,5,6表示的是等级 0.表示 关机 1表示:单用户模式 2表示:无网络连接的多用户命令行模式 3表示:有网络连接的多用户命令行模式 4表示:不可用 5表示:带图形界面的多用户模式 6表示:重新启动
2、查看自启动列表
[root@centos7 ~]# systemctl list-unit-files --type service UNIT FILE STATE arp-ethers.service disabled auditd.service enabled autovt@.service enabled blk-availability.service disabled brandbot.service static chrony-dnssrv@.service static chrony-wait.service disabled chronyd.service enabled console-getty.service disabled console-shell.service disabled container-getty@.service static cpupower.service disabled crond.service enabled dbus-org.fedoraproject.FirewallD1.service enabled dbus-org.freedesktop.hostname1.service static dbus-org.freedesktop.import1.service static dbus-org.freedesktop.locale1.service static dbus-org.freedesktop.login1.service static enabled:这个daemon将在开机时被执行; disabled:这个daemon在开机时不会被执行; static:这个daemon不可以自己启动(enable不可),不过可能会被其他的enabled 的服务来唤醒(关联属性的服务); mask:这个daemon无论如何都无法被启动,因为已经被强制注销(非删除),可通过systemctlunmask方式改回原本状态;
3、关闭和启动服务
sudo systemctl stop xxx.service //停止服务 sudo systemctl disable xxx.service //禁止服务开机启动 sudo systemctl start xxx.service //启动服务 sudo systemctl enable xxx.service //开机启动服务
七、敏感目录
八、文件排查
find / -name passwd 从/目录寻找名字叫passwd的并展示出来,find参数很多,使用的时候可以百度
1、特殊权限文件查找
[root@centos7 html]# find /var/www/html -perm 777 /var/www/html/phpinfo.php
2、指定关键字查找
find /var/www/html -name "*.php" 将查找这个目录的php文件
3、排查suid程序
[root@centos7 ~]# find / -type f -perm -04000 -ls -uid 0 2>/dev/null 50348512 32 -rwsr-xr-x 1 root root 32096 10月 31 2018 /usr/bin/fusermount 50880946 24 -rws--x--x 1 root root 23968 10月 1 2020 /usr/bin/chfn 50545721 76 -rwsr-xr-x 1 root root 73888 8月 9 2019 /usr/bin/chage 50880949 24 -rws--x--x 1 root root 23880 10月 1 2020 /usr/bin/chsh 50545722 80 -rwsr-xr-x 1 root root 78408 8月 9 2019 /usr/bin/gpasswd 50545725 44 -rwsr-xr-x 1 root root 41936 8月 9 2019 /usr/bin/newgrp 50880981 44 -rwsr-xr-x 1 root root 44264 10月 1 2020 /usr/bin/mount 50880996 32 -rwsr-xr-x 1 root root 32128 10月 1 2020 /usr/bin/su 51096491 144 ---s--x--x 1 root root 147336 10月 1 2020 /usr/bin/sudo 50881000 32 -rwsr-xr-x 1 root root 31984 10月 1 2020 /usr/bin/umount 50934941 60 -rwsr-xr-x 1 root root 57656 8月 9 2019 /usr/bin/crontab 50930063 24 -rwsr-xr-x 1 root root 23576 4月 1 2020 /usr/bin/pkexec 51096456 28 -rwsr-xr-x 1 root root 27856 4月 1 2020 /usr/bin/passwd 273937 36 -rwsr-xr-x 1 root root 36272 4月 1 2020 /usr/sbin/unix_chkpwd 273935 12 -rwsr-xr-x 1 root root 11232 4月 1 2020 /usr/sbin/pam_timestamp_check 360663 12 -rwsr-xr-x 1 root root 11296 10月 13 2020 /usr/sbin/usernetctl 34082483 16 -rwsr-xr-x 1 root root 15432 4月 1 2020 /usr/lib/polkit-1/polkit-agent-helper-1 34082471 60 -rwsr-x--- 1 root dbus 57936 9月 30 2020 /
九、隐藏文件
1、创建隐藏文件
2、隐藏创建时间
Unix 下藏后门必须要修改时间,否则很容易被发现,直接利用 touch 就可以了 比如参考 index.php 的时间,再赋给 webshell.php,结果两个文件的时间就一样了。 查看时间格式: ls -l --time-style '+%Y/%m/%d %H:%M:%S' 利用方法 touch -r index.php webshell.php 或者直接将时间戳修改成某年某月某日。如下 2014 年 01 月 02 日。 touch -t 1401021042.30 webshell.php
十、网络与进程分析
1、查看当前系统的tcp连接情况
[root@centos7 log]# netstat -pantl Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1104/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1448/master tcp 0 0 192.168.10.172:22 192.168.10.120:50775 ESTABLISHED 99867/sshd: root@pt tcp 0 52 192.168.10.172:22 192.168.10.120:52678 ESTABLISHED 30639/sshd: root@pt tcp6 0 0 :::80 :::* LISTEN 50884/httpd tcp6 0 0 :::22 :::* LISTEN 1104/sshd tcp6 0 0 ::1:25 :::* LISTEN 1448/master tcp6 0 0 :::443 :::* LISTEN 50884/httpd tcp6 0 0 :::3306 :::* LISTEN 17598/mysqld
2、进程分析
查看所有进程分析
[root@centos7 log]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 128180 6820 ? Ss 6月30 0:04 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0.0 0.0 0 0 ? S 6月30 0:00 [kthreadd] root 4 0.0 0.0 0 0 ? S< 6月30 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 6月30 0:17 [ksoftirqd/0] root 7 0.0 0.0 0 0 ? S 6月30 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 6月30 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? R 6月30 0:16 [rcu_sched] root 10 0.0 0.0 0 0 ? S< 6月30 0:00 [lru-add-drain] root 11 0.0 0.0 0 0 ? S 6月30 0:00 [watchdog/0] root 13 0.0 0.0 0 0 ? S 6月30 0:00 [kdevtmpfs] root 14 0.0 0.0 0 0 ? S< 6月30 0:00 [netns] root 15 0.0 0.0 0 0 ? S 6月30 0:00 [khungtaskd] root 16 0.0 0.0 0 0 ? S< 6月30 0:00 [writeback] root 17 0.0 0.0 0 0 ? S< 6月30 0:00 [kintegrityd] root 18 0.0 0.0 0 0 ? S< 6月30 0:00 [bioset] root 19 0.0 0.0 0 0 ? S< 6月30 0:00 [bioset] root 20 0.0 0.0 0 0 ? S< 6月30 0:00 [bioset] root 21 0.0 0.0 0 0 ? S< 6月30 0:00 [kblockd] root 22 0.0 0.0 0 0 ? S< 6月30 0:00 [md] root 23 0.0 0.0 0 0 ? S< 6月30 0:00 [edac-poller] root 24 0.0 0.0 0 0 ? S< 6月30 0:00 [watchdogd] root 30 0.0 0.0 0 0 ? S 6月30 0:00 [kswapd0] root 31 0.0 0.0 0 0 ? SN 6月30 0:00 [ksmd] root 32 0.0 0.0 0 0 ? SN 6月30 0:00 [khugepaged] root 33 0.0 0.0 0 0 ? S< 6月30 0:00 [crypto] root 41 0.0 0.0 0 0 ? S< 6月30 0:00 [kthrotld] root 43 0.0 0.0 0 0 ? S< 6月30 0:00 [kmpath_rdacd] root 44 0.0 0.0 0 0 ? S< 6月30 0:00 [kaluad] root 45 0.0 0.0 0 0 ? S< 6月30 0:00 [kpsmoused] root 47 0.0 0.0 0 0 ? S< 6月30 0:00 [ipv6_addrconf] root 60 0.0 0.0 0 0 ? S< 6月30 0:00 [deferwq] root 96 0.0 0.0 0 0 ? S 6月30 0:04 [kauditd] root 274 0.0 0.0 0 0 ? S< 6月30 0:00 [mpt_poll_0] root 275 0.0 0.0 0 0 ? S< 6月30 0:00 [ata_sff]
筛选出具体的pid进程的信息
[root@centos7 log]# ps aux|grep 50884 root 50884 0.0 0.9 422160 17696 ? Ss 6月30 0:05 /usr/sbin/httpd -DFOREGROUND root 59026 0.0 0.0 112824 988 pts/2 R+ 15:31 0:00 grep --color=auto 50884
查看进程树
pstree -p | grep pid
十一、历史命令
history 用来查阅输入的历史命令 攻击者可以可以通过 history -c 来清除记录 我们可以通过 查看 cat .bash_history 来查阅历史记录
十二、系统日志
1、有多少ip爆破主机root账号
[root@centos7 ~]# grep "Failed password for root" /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | more
1 192.168.230.12、有哪些ip在爆破
[root@centos7 ~]# 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 1 192.168.230.1
3、爆破用户名字典
[root@centos7 ~]# grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}'|uniq -c|sort -nr
1 root4、登录成功的ip
[root@centos7 ~]# grep "Accepted " /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | more
2 192.168.230.15、登录成功的用户名、ip
[root@centos7 ~]# grep "Accepted " /var/log/secure | awk '{print $1,$2,$3,$9,$11}'
Jul 2 11:41:41 root 192.168.10.120
Jul 2 12:34:14 root 192.168.10.120
Jul 2 16:53:33 root 192.168.10.1586、查看添加账号信息
[root@centos7 ~]# grep "useradd" /var/log/secure Jul 2 21:52:24 centos7 useradd[42126]: new group: name=test, GID=1000 Jul 2 21:52:24 centos7 useradd[42126]: new user: name=test, UID=1000, GID=1000, home=/home/test, shell=/bin/bash
7、查看删除账号信息
[root@centos7 ~]# grep "userdel" /var/log/secure Jul 2 22:11:57 centos7 userdel[88290]: delete user 'test' Jul 2 22:11:57 centos7 userdel[88290]: removed group 'test' owned by 'test' Jul 2 22:11:57 centos7 userdel[88290]: removed shadow group 'test' owned by 'test'
十三、WEB日志
在对WEB日志进行安全分析时,一般可以按照两种思路展开,逐步深入,还原整个攻击过程。 第一种:确定入侵的时间范围,以此为线索,查找这个时间范围内可疑的日志,进一步排查,最终确定攻击者,还原攻击过程。 第二种:攻击者在入侵网站后,通常会留下后门维持权限,以方便再次访问,我们可以找到该文件,并以此为线索来展开分析。
Apache日志分析技巧
1、列出当天访问次数最多的IP命令:
cut -d- -f 1 access_log|uniq -c | sort -rn | head -20
2、查看当天有多少个IP访问:
awk '{print $1}' access_log|sort|uniq|wc -l
3、查看某一个页面被访问的次数:
grep "/index.php" access_log | wc -l
4、查看每一个IP访问了多少个页面:
awk '{++S[$1]} END {for (a in S) print a,S[a]}' access_log
5、将每个IP访问的页面数进行从小到大排序:
awk '{++S[$1]} END {for (a in S) print S[a],a}' access_log | sort -n
6、查看某一个IP访问了哪些页面:
grep ^111.111.111.111 access_log| awk '{print $1,$7}'
7、去掉搜索引擎统计当天的页面:
awk '{print $12,$1}' access_log | grep ^\"Mozilla | awk '{print $2}' |sort | uniq | wc -l
8、查看2023年7月2日22时这一个小时内有多少IP访问:
awk '{print $4,$1}' access_log | grep 02/Jul/2023:22 | awk '{print $2}'| sort | uniq | wc -l




还没有评论,来说两句吧...