GithubHelp home page GithubHelp logo

al0ne / linuxcheck Goto Github PK

View Code? Open in Web Editor NEW
1.6K 46.0 362.0 585 KB

Linux应急处置/信息搜集/漏洞检测工具,支持基础配置/网络流量/任务计划/环境变量/用户信息/Services/bash/恶意文件/内核Rootkit/SSH/Webshell/挖矿文件/挖矿进程/供应链/服务器风险等13类70+项检查

License: MIT License

Shell 100.00%
linux rkhunter shell-script check

linuxcheck's Issues

运行后的一点小问题

root@k:~/LinuxCheck# ./LinuxCheck.sh

=========================================================
\ Linux信息搜集脚本 V1.2 /

支持Centos、Debian系统检测

author:al0ne

[+]系统改动

直接使用curl或者运行sh脚本,直接这么提示,然后就结束了?也没个报错或者log输出之类的

大佬,我这样理解Linuxcheck.sh自检项目,有什么理解上的问题吗?有的话,麻烦大佬指正一下。

LinuxCheck自检脚本功能陈列

自检脚本功能陈列(非源码、仓库说明顺序,仅个人写作方便),以及个人对该脚本处理执行意义推测(括号内):

检查内容分解 上

  • 部分类型的挖矿木马检测、常规挖矿进程检测
  • Python3 pip 检测(推测是脚本自身用到的依赖项检测,以及python也挺普遍的,二者都有吧)
  • JSP、PHP webshell查杀 (常规,杀软河马查杀也有效果)
  • Redis弱密码检测 (数据库缓存服务暴露在公网上,服务没设置密码,攻破后导致数据随意访问)
  • SSH检查:SSH key显示罗列(比对用的)、SSH inetd(特权提升)、软连接后门、SSH暴破IP统计
  • Rootkit检查:
    • lsmod可疑模块罗列(认为可疑的逻辑:控制系统内存,以及类似增强型功能的支持扩展,可能造成系统不稳定。)
    • Rootkit 内核模块(病毒样本的模块吧)
    • /usr/src/ofa_kernel/default/compat/mlx_compat.ko (通过modinfo mlx_compat的回显来看,大概是兼容、移植用的。)

检查内容分解 中

  • Bash配置检查:
    • History (history -a 从缓存中取出历史记录。
    • /etc/rc.local (**是/etc/rc.d/rc.local的软连接,查看自启服务的;**默认没有执行权限,需手动修改。)
    • /etc/profile全局的环境变量配置文件,这里修改会对所有用户起作用。)
    • $HOME/.profile对当前用户的家目录的有用,修改后,source更新
    • ~/.bash_profile它只能登入的时候执行一次。
    • ~/.bashrc (~/.bash_profile,最大区别:shell script每次都会执行。)
    • bash反弹shell(简单粗糙的理解就是,我执行的shell,传到你机器上执行。
  • 环境变量检查:
    • PATH
    • LD_PRELOAD(抓关键句快速了解:它允许你定义在程序运行前优先加载的动态链接库,另一方面,我们也可以以向别人的程序注入程序,从而达到特定的目的。
    • LD_ELF_PRELOAD、LD_AOUT_PRELOAD (ELF,简单理解,参与程序的调度连接与执行。(涉及汇编知识)
    • PROMPT_COMMAND (export PROMPT_COMMAND="echo Hello" 查看异常的命令导入)
    • ld.so.preload (通过配置/etc/ld.so.preload,可以自定义程序运行前优先加载的动态链接库)
  • 服务信息检查与任务检查:(主要问题点是隐藏后门,植入一般用户不了解的模块、运行编辑器附加命令、系统回显截断机制。
    • 正在运行的Service
    • 最近添加的Service
    • Crontab
    • Crontab Backdoor

检查内容分解 下

  • 文件检查:
    • 系统文件修改时间
    • 7天内改动文件、大于200M文件
    • 可疑黑客文件(.*wget、.*curl、.*openssl、.*mysql,可以理解为黑客植入程序脚本的伪装)
    • 敏感文件 (识别机制:Nikto、ettercap文件名等黑客工具,以及miner挖矿之类文件等)
    • 隐藏文件与临时目录/tmp
    • alias (检查建立过的别名)
    • SUID:/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache (简单理解为有suid授权的用户,等同于持有文件权限的尚方宝剑)
    • lsof +L1 (寻找本地断开的打开文件,网上文章不少表示“显示所有打开的链接数小于1的文件”,真是看不明白...)
  • 基础配置检查:
    • 系统配置信息、登陆用户、hosts
    • CPU使用率/CPU TOP15/内存占用 TOP15、内存占用/硬盘剩余空间
    • 硬盘挂载、常用软件
  • 网络/流量检查
    • ifconfig、网卡混杂模式(网络抓包工具就是网卡的混杂模式)、TCP连接类别
    • 对外开放端口、端口监听(百度百科-端口监听:我们都知道远程访问一台机器的共享目录实际是访问139端口,那么只要对本机139的监听就可以察觉对远程的访问请求。)
    • 网络连接、网络流量、路由表、路由转发(即路由中继)
    • DNS、ARP、IPTABLES
  • 用户信息检查:可登陆用户、登录信息、密码文件修改日期、sudoers(特权提升文件)

系统文件检查在Ubuntu中运行情况有异常

  • 首先,感谢写出这么好的工具,谢谢!
  • 目前版本还存在一些小瑕疵,以下是我的修改建议,供参考。
  • 系统文件检查部分的代码是指定命令的绝对路径,这在Centos类Linux里执行是OK的,但在Ubuntu里,因部分命令路径是不对的,所以运行会有异常。
  • 以下代码我加入which先得到命令路径,同时为了更直观对比系统编译时间,增加输出系统的版本和编译日期。
  • 另外加入文件大小和file格式检查内容。
    CmdFileCheck.txt
#!/bin/bash

# 设置保存文件
ipaddress=$(ip address | grep -oP '(?<=inet )\d+\.\d+\.\d+\.\d+(?=\/2)' | head -n 1)
filename=$ipaddress'_'$(hostname)'_'$(whoami)'_'$(date +%s)_CmdFileCheck_log'.md'

print_msg() {
  echo -e "$1\n" | tee -a $filename
}

print_msg "## 文件检查"

cmdline=(
  "which"
  "ifconfig"
  "ls"
  "login"
  "netstat"
  "top"
  "ps"
  "find"
  "grep"
  "passwd"
  "shadow"
  "curl"
  "wget"
)

# 获取内核版本信息
#kernel_version=$(cat /proc/version)
kernel_version=$(uname -v)
print_msg "系统内核版本及编译日期:$kernel_version"

print_msg "### 系统文件修改时间和大小"
for cmd in "${cmdline[@]}"; do
  # 使用which获取命令的实际路径
  full_path=$(which $cmd)
  if [ -n "$full_path" ]; then
    # 如果命令存在,获取修改时间并格式化
    mod_time=$(stat -c %y "$full_path" | cut -c1-19)
    # formatted_time=$(date -d "$mod_time" "+%Y-%m-%d %H:%M:%S")
    file_size=$(du -sh "$full_path" | cut -f1)
    print_msg "文件:$full_path\t修改日期:$mod_time\t文件大小:$file_size"
  else
    # 如果命令不存在,打印消息
    print_msg "命令 $cmd 不存在"
  fi
done

# 检查是否有file命令,如果有,获取文件类型信息
if command -v file >/dev/null 2>&1; then
  print_msg "### 系统文件类型"
  for cmd in "${cmdline[@]}"; do
    full_path=$(which $cmd)
    if [ -n "$full_path" ]; then
      file_type=$(file -b "$full_path")
    print_msg "文件:$full_path\t\t文件类型:$file_type"
  else
    print_msg "命令 $cmd 不存在"
  fi
done
else
  print_msg "系统无file命令,未检查系统文件类型。"
fi

能否增加报告导出功能?

一方面,在日常的应急项目中,希望能够快速导出当前机器的审查结果。
另一方面,有些情况下没有办法传递脚本,希望可以能出一个包含所有测试项的表格,可以更加方便记录工作量。
表格中提供测试大项描述、小项描述、具体执行命令、结果截图。

【建议】能否增加报告导出功能?

一方面,在日常的应急项目中,希望能够快速导出当前机器的审查结果。
另一方面,有些情况下没有办法传递脚本,希望可以能出一个包含所有测试项的表格,可以更加方便记录工作量。
表格中提供测试大项描述、小项描述、具体执行命令、结果截图。

small fix & suggestion

内存占用排序,应该是 -k4,应该是忘记改参数了

cpu=$(ps aux | grep -v ^'USER' | sort -rn -k3 | head -15) 2>/dev/null

另外,提个小建议:
代码中有很多输出字体颜色标记,可以封装成 print_msg 函数,这样可以简化代码,增加可读性,类似于如下。

#!/bin/bash

print_msg() {
  echo -e "\e[00;31m[+]$1\e[00m"
}

print_msg 'hello'

last but not least,很棒的实现,学到很多,shell 6 的起飞 🛫

centos 和debian安装silver_searcher的差异

因为在centos 重复执行脚本的时候,老是提示: silversearcher-ag没有安装,其实已经安装了,是the_silver_searcher,centos 仅需:yum install -y the_silver_searcher
同样,在Debian 重复执行的时候,老是提示:the_silver_searcher 没有安装,其实已经安装了,是silversearcher-ag,Debian仅需:apt install -y silversearcher-ag

所以简单调整了一下代码

安装应急必备工具

cmdline=(
"net-tools"
"telnet"
"nc"
"lrzsz"
"wget"
"strace"
"htop"
"tar"
"lsof"
"tcpdump"
"rkhunter"
)
for prog in "${cmdline[@]}"; do

if [ $OS = 'Centos' ]; then
soft=$(rpm -q "$prog")
if echo "$soft" | grep -E '没有安装|未安装|not installed' >/dev/null 2>&1; then
echo -e "$prog 安装中......"
yum install -y "$prog" >/dev/null 2>&1
yum install -y the_silver_searcher >/dev/null 2>&1
fi
else
if dpkg -L $prog | grep 'does not contain any files' >/dev/null 2>&1; then
echo -e "$prog 安装中......"
apt install -y "$prog" >/dev/null 2>&1
apt install -y silversearcher-ag >/dev/null 2>&1
fi

fi
done

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.