al0ne / linuxcheck Goto Github PK
View Code? Open in Web Editor NEWLinux应急处置/信息搜集/漏洞检测工具,支持基础配置/网络流量/任务计划/环境变量/用户信息/Services/bash/恶意文件/内核Rootkit/SSH/Webshell/挖矿文件/挖矿进程/供应链/服务器风险等13类70+项检查
License: MIT License
Linux应急处置/信息搜集/漏洞检测工具,支持基础配置/网络流量/任务计划/环境变量/用户信息/Services/bash/恶意文件/内核Rootkit/SSH/Webshell/挖矿文件/挖矿进程/供应链/服务器风险等13类70+项检查
License: MIT License
root@k:~/LinuxCheck# ./LinuxCheck.sh
[+]系统改动
直接使用curl或者运行sh脚本,直接这么提示,然后就结束了?也没个报错或者log输出之类的
执行./LinuxCheck.sh 时 总爆/usr/bin/env: "bash\r": 没有那个文件或目录 。
自检脚本功能陈列(非源码、仓库说明顺序,仅个人写作方便),以及个人对该脚本处理执行意义推测(括号内):
/usr/src/ofa_kernel/default/compat/mlx_compat.ko
(通过modinfo mlx_compat
的回显来看,大概是兼容、移植用的。)history -a
从缓存中取出历史记录。)/etc/rc.local
(**是/etc/rc.d/rc.local
的软连接,查看自启服务的;**默认没有执行权限,需手动修改。)/etc/profile
(全局的环境变量配置文件,这里修改会对所有用户起作用。)$HOME/.profile
(对当前用户的家目录的有用,修改后,source
更新)~/.bash_profile
(它只能登入的时候执行一次。)~/.bashrc
(同~/.bash_profile
,最大区别:shell script每次都会执行。)export PROMPT_COMMAND="echo Hello"
查看异常的命令导入)/etc/ld.so.preload
,可以自定义程序运行前优先加载的动态链接库).*wget、.*curl、.*openssl、.*mysql
,可以理解为黑客植入程序脚本的伪装)#!/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
一方面,在日常的应急项目中,希望能够快速导出当前机器的审查结果。
另一方面,有些情况下没有办法传递脚本,希望可以能出一个包含所有测试项的表格,可以更加方便记录工作量。
表格中提供测试大项描述、小项描述、具体执行命令、结果截图。
一方面,在日常的应急项目中,希望能够快速导出当前机器的审查结果。
另一方面,有些情况下没有办法传递脚本,希望可以能出一个包含所有测试项的表格,可以更加方便记录工作量。
表格中提供测试大项描述、小项描述、具体执行命令、结果截图。
你好。
工具目前很全面。很好。
但是如果能够批量检测,最主要是异常结果汇总到一个页面就完美了。
优化后的代码如下:
wget --timeout=10 --no-check-certificate https://github.com/al0ne/LinuxCheck/raw/master/rkhunter.tar.gz -O /tmp/rkhunter.tar.gz >/dev/null 2>&1
cmdline=(
"net-tools"
"telnet"
"nc"
"lrzsz"
"wget"
"strace"
"htop"
"tar"
"lsof"
"tcpdump"
"the_silver_searcher"
"silversearcher-ag"
"rkhunter"
)
yum install rkhunter -y 是可以成功的。。
内存占用排序,应该是 -k4,应该是忘记改参数了
Line 141 in 833beaf
另外,提个小建议:
代码中有很多输出字体颜色标记,可以封装成 print_msg 函数,这样可以简化代码,增加可读性,类似于如下。
#!/bin/bash
print_msg() {
echo -e "\e[00;31m[+]$1\e[00m"
}
print_msg 'hello'
last but not least,很棒的实现,学到很多,shell 6 的起飞 🛫
因为在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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.