69

security 02: 加密与解密 、 扫描与抓包 、 总结和答疑 、 SELinux安全防护-技术-51C...

 6 years ago
source link: http://blog.51cto.com/13478354/2067028
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

security 02: 加密与解密 、 扫描与抓包 、 总结和答疑 、 SELinux安全防护

day01
一、selinux安全防护
二、数据 加密 解密
三、抓包与扫描
++++++++++++++++++++++++++++++
一、selinux安全防护
1.1 selinux 介绍
1.2 linux安全保护模型?
1.3 查看当前系统selinux的状态
[root@svr7 ~]# sestatus

1.4 selinux配置文件
[root@host50 ~]# cat /etc/selinux/config

1.5 查看安全上下文
查看进程 ps aux -Z
ps aux -Z | grep -i 进程名

查看文件 ls -lZ 文件名

查看目录 ls -ldZ 目录名

1.6 安全上下文的组成?
system_u:object_r:passwd_file_t:s0
system_u:object_r:net_conf_t:s0
用户:角色:访问类型:参数

1.7 常见的访问类型?

1.8 SELinux启用后的一般操作规律?
创建新文件时,新文件继承父目录的安全上下文。
移动文件时,保持原有的安全上下文不变
拷贝文件时,继承目标目录的安全上下文
1.9 修改访问类型?
]# chcon -R -t 访问类型 目录名 //递归修改
]# chcon -t 访问类型 文件名
]# chcon -t httpd_sys_content_t /var/www/html/test1.html
1.10 恢复文件访问类型?
]# restorecon -R 目录名 //递归恢复
]# restorecon 文件名
]# restorecon /var/www/html/test2.html
练习文件selinux 访问类型的修改 (以网站服务文件为例)

1.11 selinux布尔值 (功能开关)
查看bool值
#getsebool -a
#getsebool -a | grep -i ftp

修改bool值
#setsebool -P 选项=1|0
#setsebool -P 选项 on|off
环境准备,启动vsftpd服务,配置允许匿名ftp用户, 可以上传和下载文件到/var/ftp/shardir目录里。
[root@host50 ~]# sed -n '29p' /etc/vsftpd/vsftpd.conf
anon_upload_enable=YES
[root@host50 ~]#
[root@host50 ~]# mkdir /var/ftp/shardir
[root@host50 ~]# chmod o+w /var/ftp/shardir
[root@host50 ~]# systemctl restart vsftpd
592 setsebool -P ftpd_anon_write=1
593 setsebool -P ftpd_full_access on
594 getenforce -a | grep -i ftp
597 setenforce 1

客户端:
yum -y install ftp

lcd 切换到本机目录
get 下载
put 上传
+++++++++++++++++++++++++++++++++++++
启用selinux日志程序记录报错信息:
启用selinux 后,修改网站服务使用的端口号为8090。

[root@host50 ~]# cat /var/log/messages | grep -n -i setroubleshoot | tail -1
37272:Jan 28 22:38:31 host50 setroubleshoot: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8090. For complete SELinux messages. run sealert -l a9db74ee-ff0d-45c7-8a4d-34d4bf5bc3c4

[root@host50 ~]# sealert -l a9db74ee-ff0d-45c7-8a4d-34d4bf5bc3c4

]# semanage port -a -t http_port_t -p tcp 8090

+++++++++++++++++++++++++++++++
二、数据 加密 解密
2.1 为什么要加密?
2.2 什么加密? 什么是解密?
发送方 加密 接收方 解密
2.3 什么是算法? 加/解密计算规则
秘钥(公钥加密 私钥解密)
|——> 可以是指令 或 一段代码

2.4 加密方式?
对称加密: 加密和解密使用相同的计算规则
非对称加密:加密和解密使用不相同的计算规则

对称加密算法: DES AES
非对称加密算法: RSA DSA

Hash散列技术,保证数据的完整性。 md5 sha
++++++++++++++++++++++++++++++

gpg 对称加密 -c -d

发 收
usera -------------- > userb

usera 加密 gpg -c 文件名

userb 解密 gpg -d 文件名

++++++++++++++++++++++++++
gpg 非对称加密(使用密钥对)
公钥 加密
私钥 解密
发 收
usera -------------- > userb
userb(解密 )
1 创建密钥对 ~/.gnupg/
#gpg --gen-key
#ls ~/.gnupg/
2 导出公钥 并把公钥文件传给usera
[userb@room9pc17 ~]$ gpg --export -a > /tmp/userb.pub
[userb@room9pc17 ~]$ cat /tmp/userb.pub
usera(加密)
1 导入公钥文件~/.gnupg
[usera@room9pc17 ~]$ gpg --import /tmp/userb.pub
[usera@room9pc17 ~]$ ls ~/.gnupg
2 使用公钥加密文件 ,把加密后的文件给userb
[usera@room9pc17 ~]$ gpg -e -r usera b.txt
[usera@room9pc17 ~]$ mv b.txt.gpg /tmp/
3 userb解密
调用私钥解密 解密文件
[userb@room9pc17 ~]$ gpg -d /tmp/b.txt.gpg > u.txt
cat u.txt
++++++++++++++++++++++++++++++++++
gpg数字签名 功能验证数据完整性
-b --verify --fingerprint
userb
私钥签名
26 vim c.txt
28 gpg -b c.txt
ls c.
30 cp c.
/tmp/
33 gpg --fingerprint
usera
公钥验证签名
#gpg --verify /tmp/c.txt.sig
#cat /tmp/c.txt
root# sed -i '1s/^/aaa/' /tmp/c.txt
usera
#cat /tmp/c.txt
#gpg --verify /tmp/c.txt.sig
+++++++++++++++++++++++++++++++
三、抓包与扫描
3.1 扫描nmap
3.2 抓包tcpdump
3.3 协议分析软件的使用wireshark

3.1 扫描nmap
180 which nmap
181 rpm -qf /bin/nmap
182 rpm -q nmap

man nmap

语法格式
#nmap [扫描类型] [选项] <ip地址>

扫描类型有哪些? -sS -sT -sU -sP
选项有哪些? -A -n -p

ip地址表示方式?
192.168.4.53
192.168.4.100-200
192.168.4.53,57,68

#nmap -sP 172.40.55.122
185 nmap -sP 172.40.55.122
186 nmap -sP 172.40.55.180
187 nmap 172.40.55.180
188 nmap -n -sT -p 80 172.40.55.180
189 nmap -n -sT -p 25,80 172.40.55.180
190 nmap -n -sT -p 21-100,3306 172.40.55.180
191 nmap -n -A 172.40.55.180

nmap -n -sP 172.40.55.100-200 --exclude 172.40.55.143,172.40.55.158

#vim /root/ip.txt
172.40.55.143
172.40.55.158
172.40.55.180
:wq

nmap -n -sP 172.40.55.100-200 --excludefile /root/ip.txt

vim /root/web.sh
#/bin/bash
for ip in 180 143 158
do
nmap -n -sS -p 80 172.40.55.$ip | grep -q open
if [ $? -eq 0 ];then
echo " 172.40.55.$ip 80 open"
else
echo " 172.40.55.$ip 80 closed"
fi
done
:wq
+++++++++++++++++++++++++++++
#mkdir /myself
#mv /root/web.sh /myself/checkweb
#chmod +x /myself/checkweb

#vim /etc/profile
....
export PATH=/myself:$PATH
:wq

#resource /etc/profile
#echo $PATH
#cd /usr/local/
#checkweb

++++++++++++++++++++++++++++++++++++
#checkweb 3306 112 130 129
#checkweb 11211 112 130 129

3.2 抓包tcpdump
tcpdump [选项] [过滤条件]

选项
-i 网络接口名 //不指定接口名时,默认抓eth0 接口进出的包
-c 数字 //指定抓包个数,不指定的话会一直抓包
-A //以可阅读的方式抓取数据包
-w 文件名.cap //把抓到的数据信息存储到文件里。默认会输出到屏幕上。
-r 文件名.cap //读取抓包文件的内容

110 tcpdump
112 tcpdump -i br1
113 tcpdump -i br1 -c 2
114 tcpdump -i br1 -c 2 -A
115 tcpdump -i br1 -c 2 -A -w /tmp/tcpdump.cap
116 tcpdump -A -r /tmp/tcpdump.cap

过滤条件: 抓包时,不加过滤条件,会抓所有到达的数据包。反之,只抓复合条件的数据包。

[root@host50 ~]# tcpdump -i eth0 -A

[root@host50 ~]# tcpdump -i eth0 -A tcp port 8090

[root@host50 ~]# tcpdump -i eth0 -A tcp port 8090 and host 192.168.4.53

[root@host50 ~]#tcpdump -i eth0 -A tcp port 22 and net 192.168.4.0/24

[root@host50 ~]#tcpdump -i eth0 -A tcp port 22 and not host 192.168.4.53

[root@host50 ~]#tcpdump -i eth0 -A
tcp port 8090 and host 192.168.4.53 or host 192.168.4.54

[root@host50 ~]#tcpdump -i eth0 -A
tcp port 8090 and (host 192.168.4.53 or host 192.168.4.54)

[root@host52 ~]#tcpdump -i eth0 -A tcp port 25 -w /tmp/mail2.cap

[root@host52 ~]#tcpdump -A -r /tmp/mail2.cap

[root@host52 ~]# scp /tmp/mail2.cap 192.168.4.254:/root/

3.3 协议分析软件的使用wireshark (宿主机)
安装软件包

yum -y install wireshark wireshark-gnome

rpm -q wireshark wireshark-gnome

打开图形界面
应用程序->互联网->软件名 ---> 文件菜单->打开文件/root/mail2.cap

tcp 传输协议 标记位
SYN 新连接
ACK 确认连接
FIN 断开连接
push( P) 传输数据
RST 重新建立连接

应用层 http smtp ftp
传输层 tcp upd
网络层 ip包
物理层 数据流 (0101)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK