Linux运维知识之linux 安全应用 2
小标 2018-10-26 来源 : 阅读 1052 评论 0

摘要:本文主要向大家介绍了Linux运维知识之linux 安全应用 2,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

本文主要向大家介绍了Linux运维知识之linux 安全应用 2,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

一、selinux安全防护

DAC自主访问控制(rwx/acl用户自己可以修改)

MAC强制访问控制(管理员对所有的资源负责)

TCSEC标准定义的 MLS 多级安全

SELinux*

1.1 selinux介绍

美国国家安全局主导开发,

一套强化Linux安全的MAC扩展模块

集成到Linux内核(2.6及以上)

操作系统提供可定制的策略、管理工具

主要软件包:

selinux-policy

selinux-policy-targeted、

libselinux-utils、libselinux-utils、

coreutils、policycoreutils

SELINUXTYPE=targeted

推荐,仅保护最常见/关键的网络服务,其他不限制

SELINUXTYPE=mls

提供多层次、全面的安全防护策略

需扩展软件包:

selinux-policy-mls、mcstrans、

policycoreutils-newrole

启用selinux

vim /etc/sysconfig/selinux

SELINUX=enforcing

SELINUXTYPE=targeted

:wq

reboot

[aliyunzixun@xxx.com ~]# sestatus

SELinux status: enabled

SELinuxfs mount:/selinux

Current mode:enforcing

Mode from config file: enforcing

Policy version: 24

Policy from config file:targeted

[aliyunzixun@xxx.com ~]# getenforce

Enforcing

[aliyunzixun@xxx.com ~]#

————————————————————————————————————————————————

上面的总结

————————————————————————————————————————————————

selinux是基于linux内核版本在2.6及以上的一种内核安全防护扩展模块,由美国国家安全局研发出来的.

[aliyunzixun@xxx.com html]# uname -r

2.6.32-573.el6.x86_64

MAC 强制访问控制(管理员管理资源)

DAC自主访问控制(用户管理资源)rwx/acl

[aliyunzixun@xxx.com html]# rpm -qa |grep -i selinux(查看系统是否有selinux安全防护)

1.3 查看当前系统selinux状态

默认会有一个配置文件/etc/selinux/config,和链接/etc/sysconfig/selinux

6 SELINUX=permissive (一般都是设置成这种,宽松警告)

6 SELINUX=disabled

6 SELINUX=enforcing

10 SELINUXTYPE=strict

10 SELINUXTYPE=targeted(一般这种,仅保护最常见/关键的网络服务,其他不限制)

[aliyunzixun@xxx.com ~]# getenforce

Permissive

[aliyunzixun@xxx.com ~]# setenforce 1

[aliyunzixun@xxx.com ~]# getenforce

Enforcing

[aliyunzixun@xxx.com ~]# sestatus

SELinux status: enabled

SELinuxfs mount:/selinux

Current mode:enforcing

Mode from config file: permissive

Policy version: 24

Policy from config file:targeted

查看安全上下文

文件ll-Z文件名 ll-Z/etc/passwd

目录ll -dZ 目录名 ll-dZ/

进程ps aux -Z| grep httpd

[aliyunzixun@xxx.com ~]# ls -Zd /root

dr-xr-x---. root root system_u:object_r:admin_home_t:s0 /root

[aliyunzixun@xxx.com ~]# ls -Zd /var/www/html

drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html

[aliyunzixun@xxx.com ~]# ls -Zd /tmp

drwxrwxrwt. root root system_u:object_r:tmp_t:s0/tmp

[aliyunzixun@xxx.com ~]# ls -Zd /var/ftp/

drwxr-xr-x. root root system_u:object_r:public_content_t:s0 /var/ftp/

用户:角色:访问类型:选项...

system_u:object_r:root_t:s0

一般操作规律

移动的文件,原有的上下文属性不变

复制的文件,自动继承目标位置的上下文

创建继承上级目录属性

++创建继承上级目录属性++

[aliyunzixun@xxx.com ~]# mkdir my

[aliyunzixun@xxx.com ~]# touch 1.txt

[aliyunzixun@xxx.com ~]# ll -Zd 1.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 1.txt

[aliyunzixun@xxx.com ~]# ll -Zd /root/my

drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 /root/my

[aliyunzixun@xxx.com ~]# ll -Zd /root/

dr-xr-x---. root root system_u:object_r:admin_home_t:s0 /root/

+++复制的文件,自动继承目标位置的上下文 (保持属性拷贝也没用 还是会继承目标的属性)+++

[aliyunzixun@xxx.com ~]# cp /root/1.txt /tmp/

[aliyunzixun@xxx.com ~]# cp -r /root/my /tmp/

[aliyunzixun@xxx.com ~]# ll -Zd /tmp

drwxrwxrwt. root root system_u:object_r:tmp_t:s0/tmp

[aliyunzixun@xxx.com ~]# ll -Zd /tmp/1.txt

-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/1.txt

[aliyunzixun@xxx.com ~]# ll -Zd /tmp/my

drwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/my

[aliyunzixun@xxx.com ~]# rm -fr /tmp/1.txt

[aliyunzixun@xxx.com ~]# cp -p /root/1.txt /tmp/

[aliyunzixun@xxx.com ~]# ll -Zd /tmp/1.txt

-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/1.txt

+++移动的文件目录,保持原来的上下文属性不变+++

[aliyunzixun@xxx.com ~]# rm -fr /tmp/1.txt

[aliyunzixun@xxx.com ~]# rm -fr /tmp/my

[aliyunzixun@xxx.com ~]# mv /root/1.txt /tmp/

[aliyunzixun@xxx.com ~]# mv /root/my /tmp/

[aliyunzixun@xxx.com ~]# ll -Zd /tmp/1.txt

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /tmp/1.txt

[aliyunzixun@xxx.com ~]# ll -Zd /tmp/my

drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 /tmp/my

[aliyunzixun@xxx.com ~]# ll -Zd /tmp

drwxrwxrwt. root root system_u:object_r:tmp_t:s0/tmp

————————————

[aliyunzixun@xxx.com ~]# ll -Z /var/www/html

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 file.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 link.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 test.html

[aliyunzixun@xxx.com ~]# firefox httpd:192.168.4.254:/test.html (能打开)

[aliyunzixun@xxx.com ~]# firefox httpd:192.168.4.254:/file.html (不能打开) 不是网页内容属性文件

修改文件的安全上下文可以用chcon和restorecon 效果一样。

chcon 修改工具

[aliyunzixun@xxx.com ~]# chcon -t httpd_sys_content_t /var/www/html/file.html

[aliyunzixun@xxx.com ~]# ll -Z /var/www/html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 1.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 a.txt

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 file.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 link.php

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 test.php

restorecon 恢复工具

[aliyunzixun@xxx.com ~]# ll -Z /var/www/html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 1.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 a.txt

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 file.html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 link.php

-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 pp.html

[aliyunzixun@xxx.com ~]# cd /var/www/html/

[aliyunzixun@xxx.com html]# restorecon pp.html

[aliyunzixun@xxx.com html]# ll -Z /var/www/html

-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 pp.html

————————————————————————

修改文件的安全上下文

chcon 工具

-t,指定访问类型

-u、-r,分别用来指定用户、角色

-R,递归修改

chcon-t 访问类型 文件名#修改某个文件的安全上下文

chcon -R-t 访问类型 目录名 #批量修改安全上下文 (把目录下文件的都修改了上下文)

chcon -t httpd_sys_content_t /var/www/html/c2.html

恢复文件的安全上下文

restorecon 工具 恢复为所在位置的默认上下文属性

-R,递归修改

restorecond.html#把这个文件恢复成当前父目录的上下文属性

restorecon目录名/d.html

————————————————————————————————————————————————

1.4 SELinux布尔值 (功能开关)

getsebool-a #列出所有的bool值

修改布尔值

setsebool-P选项 on#启用

setsebool-P选项 off#关闭

setsebool-P选项=1#启用

setsebool-P选项=0#关闭

setsebool-Pallow_ftpd_anon_write on

setsebool-P allow_ftpd_full_accesson

安装selinux排错工具

[aliyunzixun@xxx.com ftp]# yum -y install setroubleshoot-server

setroubleshoot-plugins setroubleshoot

[aliyunzixun@xxx.com ftp]# rpm -qa | grep setroubleshoot

setroubleshoot-server-3.0.47-9.1.el6.x86_64

setroubleshoot-3.0.47-9.1.el6.x86_64

setroubleshoot-plugins-3.0.40-2.el6.noarch

[aliyunzixun@xxx.com ftp]#

[aliyunzixun@xxx.com ftp]#reboot

调出图形工具抓取报错信息

应用程序->系统工具->selinx .....

sealter -b

查看日志 执行命令,获取错误信息

tail-f/var/log/message

Jun 29 09:51:57 room3pc31 setroubleshoot: SELinux is

preventing /usr/sbin/vsftpd from write access on the

directory pubdir. For complete SELinux messages. run

sealert -l 933b8efd-0743-48c3-b7b0-b95233747cbc

[aliyunzixun@xxx.com ftp]#sealert -l 933b8efd-0743-48c3-b7b0-

b95233747cbc

+++++++++++++++++++++++++++++++++++

二、加密、解密

2.1 为什么要给数据加密?(机密性 完整性)

(发送方)加密明文 -> 密文 (加密就是把明文加密成密问)

(接收方)解密密文 -> 明文(解密就是把密问解密成明文)

加密算法明文 变成 密文的 转换 规则

算法可以是 一种计算规则 、 指令 或 代码 (加密算法:可以是指令也可以是代码)

2.2 加密方式

对称加密: 加密/解密用同一个密钥 (对称:加解密使用相同的算法) 简单不安全

算法有:DES,Data Encryption Standard

AES,Advanced Encryption Standard

非对称加密 加密/解密用不同的密钥(密钥对) (非对称加密:加解密使用不同算法 有密钥对)

公钥和私钥

加解

算法:RSA,Rivest Shamirh Adleman

DSA,Digital Signature Algorithm

加解密工具:

gpg(开源的软件包 gnupg这个包提供) 对称加密解密 非对称加解密 数字签名

[aliyunzixun@xxx.com ~]# which gpg

/usr/bin/gpg

[aliyunzixun@xxx.com ~]# rpm -qf /usr/bin/gpg

gnupg2-2.0.14-8.el6.x86_64

[aliyunzixun@xxx.com ~]# gpg --help 查帮助(支持的算法 选项)

————————

1.对称加密解密 (lucy和tom,都是真机上用户密码都是123, 切到lucy和tom时候只能ssh -X aliyunzixun@xxx.com 不能su - tom,因为环境不对。)

————————

加密(发送方)lucy:

解密(接受方)tom:

[aliyunzixun@xxx.com ~]# ssh -X aliyunzixun@xxx.com"localhost"

aliyunzixun@xxx.com's password:

/usr/bin/xauth: creating new authority file /home/lucy/.Xauthority

[aliyunzixun@xxx.com ~]$

[aliyunzixun@xxx.com ~]$ pwd

/home/lucy

[aliyunzixun@xxx.com ~]$ echo 123456 >lucy.txt

[aliyunzixun@xxx.com ~]$ ls

lucy.txt

[aliyunzixun@xxx.com ~]$ gpg -c lucy.txt

gpg: 已创建目录‘/home/lucy/.gnupg’

gpg: 新的配置文件‘/home/lucy/.gnupg/gpg.conf’已建立

gpg: 警告:在‘/home/lucy/.gnupg/gpg.conf’里的选项于此次运行期间未被使用

gpg: 钥匙环‘/home/lucy/.gnupg/pubring.gpg’已建立

can't connect to `/home/lucy/.gnupg/S.gpg-agent': 没有那个文件或目录

gpg-agent[11856]: 已创建目录‘/home/lucy/.gnupg/private-keys-v1.d’

[aliyunzixun@xxx.com ~]$ ls

lucy.txt lucy.txt.gpg

[aliyunzixun@xxx.com ~]$ cp lucy.txt.gpg /tmp/

[aliyunzixun@xxx.com 桌面]# ssh -X aliyunzixun@xxx.com

aliyunzixun@xxx.com's password:

/usr/bin/xauth: creating new authority file /home/tom/.Xauthority

[aliyunzixun@xxx.com ~]$

[aliyunzixun@xxx.com ~]$ pwd

/home/tom

[aliyunzixun@xxx.com ~]$ cd /tmp

[aliyunzixun@xxx.com tmp]$ ls

1.txt orbit-gdm

da orbit-root

evince-9817pulse-2UwZ1k19YbcT

gedit.root.3964521678 pulse-5sTJqfwYxhm6

keyring-rOpg63 user.txt

keyring-vP2cP1 virtual-root.lwcQAF

lu VMwareDnD

lucy.txt.gpgvmware-root

my wireshark_2_interfaces_20170226094957_f2G8IO

myvm.xmlyum_save_tx-2017-03-07-11-11_INSzh.yumtx

[aliyunzixun@xxx.com tmp]$ gpg -d lucy.txt.gpg

gpg: 已创建目录‘/home/tom/.gnupg’

gpg: 新的配置文件‘/home/tom/.gnupg/gpg.conf’已建立

gpg: 警告:在‘/home/tom/.gnupg/gpg.conf’里的选项于此次运行期间未被使用

gpg: 钥匙环‘/home/tom/.gnupg/secring.gpg’已建立

gpg: 钥匙环‘/home/tom/.gnupg/pubring.gpg’已建立

gpg: 3DES 加密过的数据

can't connect to `/home/tom/.gnupg/S.gpg-agent': 没有那个文件或目录

gpg-agent[11903]: 已创建目录‘/home/tom/.gnupg/private-keys-v1.d’

gpg: 以 1 个密码加密

123456

gpg: 警告:报文未受到完整的保护

————————

2.非对称加解密:【(lucy和tom,都是真机上用户密码都是123, 切到lucy和tom时候只能ssh -X aliyunzixun@xxx.com 不能su - tom,因为环境不对。)要图形界面】

————————

1)lucy

-传建密钥对

-导出公钥

2)tom

导入lucy的公钥

使用公钥加密发送文件

lucy使用私钥解密

实验:

[aliyunzixun@xxx.com ~]$ rm -fr .gnupg/ (有就一般都先删掉 等创建公钥时会自动生成)

[aliyunzixun@xxx.com ~]$ gpg --gen-key

gpg: 钥匙环‘/home/lucy/.gnupg/secring.gpg’已建立

请选择您要使用的密钥种类:

(1) RSA and RSA (default)

(2) DSA and Elgamal

(3) DSA (仅用于签名)

(4) RSA (仅用于签名)

您的选择?

.....(一路默认 名字那里做个区分写真实的,后面还会用到)

.....

真实姓名:panglj

电子邮件地址:plj

注释:O

您选定了这个用户标识:

“panglj (O) <aliyunzixun@xxx.com>”

更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)?o

您需要一个密码来保护您的私钥。(输入密码,记住这个密码)等它生成

.................

密钥指纹 = 87F8 DE00 93C6 3D6A 6AF8 1B16 94CD FC50 73FA C552

uid panglj (O) <aliyunzixun@xxx.com>

sub2048R/86A8B557 2017-03-07

公钥和私钥已经生成并经签名。(生成)

[aliyunzixun@xxx.com .gnupg]$ pwd

/home/lucy/.gnupg

[aliyunzixun@xxx.com .gnupg]$ ls

gpg.confpubring.gpgrandom_seed trustdb.gpg

private-keys-v1.d pubring.gpg~ secring.gpg

[aliyunzixun@xxx.com .gnupg]$ gpg -a --export >/tmp/lucy.pub (把公钥拷贝到公共目录。让tom拷贝)

[aliyunzixun@xxx.com ~]$ rm -fr .gnupg/(tom用户先把自己的这个目录删了,把lucy公钥拷贝到自己加下会自动生成该目录)

[aliyunzixun@xxx.com ~]$ gpg --import /tmp/lucy.pub (拷贝lucy公钥)

.............

[aliyunzixun@xxx.com ~]$ ls -a

..bash_history .bash_profile .gnome2 .mozilla

.. .bash_logout.bashrc.gnupg.Xauthority

[aliyunzixun@xxx.com ~]$ cd .gnupg/

[aliyunzixun@xxx.com .gnupg]$ ls

gpg.conf pubring.gpg pubring.gpg~ secring.gpg trustdb.gpg

[aliyunzixun@xxx.com .gnupg]$ echo "1234567890" >tom.txt (tom写一个文件)

[aliyunzixun@xxx.com .gnupg]$ gpg -e -r panglj tom.txt 把该文件加密(用户名是做密钥对时的留的用户名)

........................(输入yes 按提示)

[aliyunzixun@xxx.com .gnupg]$ ls

gpg.conf pubring.gpg~ secring.gpg tom.txt.gpg

pubring.gpg random_seedtom.txt trustdb.gpg

[aliyunzixun@xxx.com .gnupg]$ cp tom.txt.gpg /tmp/(将加密好的复制到公共目录下,让lucy读取)

[aliyunzixun@xxx.com ~]$ gpg -d /tmp/tom.txt.gpg (在页面上显示解密后的内容,需要输做密钥时设的密码)

[aliyunzixun@xxx.com ~]$ gpg -d /tmp/tom.txt.gpg >/home/lucy/t.txt (把解密后的内容定向到一个文件中再查看)

[aliyunzixun@xxx.com ~]$ ls

lucy.txt lucy.txt.gpg t.txt

[aliyunzixun@xxx.com ~]$ cat t.txt

1234567890

3.数字签名(私钥签名,公钥验证签名)

lucy tom

lucy:

使用私钥对文件做数字签名

把签名文件和源文件发送给对方

tom

使用公钥验证签名文件

验证文件是否是声称持有者发送过来的

[aliyunzixun@xxx.com ~]$ echo "1212" >lu.txt

[aliyunzixun@xxx.com ~]$ gpg -b lu.txt(输入之前设置的密码做成签名)

您需要输入密码,才能解开这个用户的私钥:“panglj (O) <aliyunzixun@xxx.com>”

2048 位的 RSA 密钥,钥匙号 73FAC552,建立于 2017-03-07

can't connect to `/home/lucy/.gnupg/S.gpg-agent': 没有那个文件或目录

[aliyunzixun@xxx.com ~]$ ls

lucy.txt lucy.txt.gpg lu.txt lu.txt.sig t.txt

[aliyunzixun@xxx.com ~]$ cp lu.txt /tmp/ (把文件和文件签名放到公共目录下)

[aliyunzixun@xxx.com ~]$ cp lu.txt.sig /tmp

[aliyunzixun@xxx.com ~]$ cat /tmp/lu.txt(tom可以看到文件内容和从文件签名看是否有损坏,内容是否有更改)

1212

[aliyunzixun@xxx.com ~]$ gpg --verify /tmp/lu.txt.sig

gpg: 于 2017年03月07日 星期二 15时29分17秒 CST 创建的签名,使用 RSA,钥匙号 73FAC552

gpg: 完好的签名,来自于“panglj (O) <aliyunzixun@xxx.com>”

gpg: 警告:这把密钥未经受信任的签名认证!

gpg:没有证据表明这个签名属于它所声称的持有者。

主钥指纹: 87F8 DE00 93C6 3D6A 6AF8 1B16 94CD FC50 73FA C552

————————————————————————————————————————————

——————————————————————————————————————

使用md5sum校验工具验证文件完整性 特点:当文件内容没变时md5生成的校验值一值保持同样长度不变,否则变化。(md5和gpg数字签名相比只能验证文件内容是否有更改,不能验证是谁发的)

[aliyunzixun@xxx.com html]# cat a.txt

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

[aliyunzixun@xxx.com html]# md5sum a.txt

2acf01edaaee1079d83086a3ed3305a1 a.txt

[aliyunzixun@xxx.com html]# md5sum a.txt

2acf01edaaee1079d83086a3ed3305a1 a.txt

[aliyunzixun@xxx.com html]# echo "123" >>a.txt

[aliyunzixun@xxx.com html]# md5sum a.txt

4795332faee87af3d9685ac07b05bc56 a.txt

[aliyunzixun@xxx.com html]# echo abc

abc

[aliyunzixun@xxx.com html]# echo abc |md5sum

0bee89b07a248e27c83fc3d5951213c1 -

[aliyunzixun@xxx.com html]# echo abc |md5sum

0bee89b07a248e27c83fc3d5951213c1 -

[aliyunzixun@xxx.com html]# echo abc |md5sum

0bee89b07a248e27c83fc3d5951213c1 -

[aliyunzixun@xxx.com html]# echo abcd |md5sum

f5ac8127b3b6b85cdc13f237c6005d80 -

保护信息的完整性

信息摘要:基于输入的信息生成长度较短、位数固定的散列值

Hash散列技术,用于信息摘要

MD5,Message Digest Algorithm 5

SHA,Secure Hash Algorithm

sha1sum a.txt

md5sum a.txt

gnupg介绍

GnuPG,GNU Privacy Guard

最流行的数据加密、数字签名工具软件

[aliyunzixun@xxx.com ~]# which gpg

/usr/bin/gpg

[aliyunzixun@xxx.com ~]# rpm -qf /usr/bin/gpg

gnupg2-2.0.14-8.el6.x86_64

[aliyunzixun@xxx.com ~]#

gpg --help 查帮助(支持的算法 选项)

对称加/解密过程 (加/解密 使用相同密钥)

加密

head -2 /etc/passwd> a.txt

gpg -c a.txt(提示输入密码)

ls a.txt.gpg 加密后的文件

rm -rf a.txt

解密

gpg -d a.txt.gpg> /tmp/user.txt (提示输入密码)

cat /tmp/user.txt

++++++++++++++++++++++++++++++

非对称加/解密过程 (公钥加密/私钥解密)

userB 要 userA 使用非对称方式加密传输数据

1 userB生成密钥对

gpg --gen-key (生成私钥时要求输入相关信息)

ls ~/.gnupg/

dd if=/dev/zero of=/dev/nullbs=1M count=500

2 userB 导出自己的公钥

gpg -a --export>/tmp/UserB.pub

suerB 把 公钥 给 userA (不同机器间传输数据)

3 userA 导入userB的公钥

gpg --import /tmp/UserB.pub

ls ~/.gnupg/

4 userA 使用公钥加密文件

echo 12344555 > /tmp/clear.txt

gpg -e -r 真实姓名/tmp/clear.txt

panglj

userA 把加密文件 传给 userB (不同机器间传输数据)

5 userB 使用自己的私钥解密

gpg -d /tmp/clear.txt.gpg > dclear.txt

cat dclear.txt

+++++++++++++++++++++++++++++++++++

GPG软件签名与验证

软件签名与验证过程

软件官方以私钥对软件包执行数字签名

用户下载软件包、软件官方的公钥

以官方公钥验证软件包签名,确保软件完整性

gpg -b 生成一份分离的签名

gpg --verify验证签名

gpg --fingerprint 列出密钥和指纹

userB

head -3 /etc/passwd> userb.txt

gpg -b userb.txt

ls userb.txt.sig (签名文件)

mvuserb.txt userb.txt.sig/tmp/

userA

cd/tmp/

gpg --verifyuserb.txt.sig

[aliyunzixun@xxx.com tmp]$ gpg --verify user2.txt.sig

gpg: 于 2016年06月29日 星期三 14时59分43秒 PHT 创建的

签名,使用 RSA,钥匙号 A6D34AA0

gpg: 完好的签名,来自于“panglj (teacher)

<aliyunzixun@xxx.com>”

gpg: 警告:这把密钥未经受信任的签名认证!

gpg:没有证据表明这个签名属于它所声称的持有者。

主钥指纹: 87AB 6994 3F35 E6EA 4EA7 502B CCA6

5CA3 A6D3 4AA0

[aliyunzixun@xxx.com tmp]$

echo aaaa >> user2.txt

[aliyunzixun@xxx.com tmp]$ gpg --verify user2.txt.sig

gpg: 于 2016年06月29日 星期三 14时59分43秒 PHT 创建的

签名,使用 RSA,钥匙号 A6D34AA0

gpg: 已损坏的签名,来自于“panglj (teacher)

<aliyunzixun@xxx.com>”

[aliyunzixun@xxx.com tmp]$

[aliyunzixun@xxx.com ~]$ gpg --fingerprint

/home/userB/.gnupg/pubring.gpg

------------------------------

pub2048R/A6D34AA0 2016-06-29

密钥指纹 = 87AB 6994 3F35 E6EA 4EA7 502B CCA6

5CA3 A6D3 4AA0

uid panglj (teacher) <aliyunzixun@xxx.com>

sub2048R/6CD5F831 2016-06-29

[aliyunzixun@xxx.com ~]$

主钥指纹: 87AB 6994 3F35 E6EA 4EA7 502B CCA6

5CA3 A6D3 4AA0

密钥指纹 = 87AB 6994 3F35 E6EA 4EA7 502B CCA6

5CA3 A6D3 4AA0

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++

搭建CA服务器

1CA 介绍 (CA,Certificate Authority)

数字证书授权中心

被通信双方信任的、独立的第三方机构

负责证书颁发、验证、撤销等管理工作

国内常见的CA机构

中国金融认证中心(CFCA)

中国电信安全认证中心(CTCA)

北京数字证书认证中心(BJCA)

CA用来给服务器颁发数字证书

一般也可自己搭建一个私有CA服务器

openssl 加密工具

#openssl enc -des3 -e -in f1.txt -out f1.txt.enc 加密

# openssl enc -des3 -d -in f1.txt.enc -out f1.txt 解密

2 CA做什么(发数字证书的机构)

PKI体系的基本组成

权威认证机构(CA)

数字证书库、密钥备份及恢复系统

证书作废系统、应用接口

对称加密

enc 算法 -e -in 输入文件 -out 输出文件

enc 算法 -d -in 输入文件 -out 输出文件

[aliyunzixun@xxx.com ~]# openssl enc -des3 -e -in f1.txt -out

f1.txt.enc

enter des-ede3-cbc encryption password:

//设置口令

Verifying - enter des-ede3-cbc encryption password:

[aliyunzixun@xxx.com ~]# openssl enc -des3 -d -in f1.txt.enc -

out f1.txt

enter des-ede3-cbc decryption password:

————————————————————————————————————————

————————————————————————————————————————

CA机构(CA服务器)是用来给公司服务器颁发数字证书的。有权威的也有私有自己搭建的。

使用IP地址是X.X.X.88主机做CA服务器

整体部署思路

第一步:配置CA签署环境(给客户端发证的默认配置)

/etc/pki/tls/openssl.cnf

第二步:为CA服务器生成私钥(创建密钥对)

第三步:为CA服务器创建根证书 (生成自己的根证书文件)

第四步:发布根证书文件(把自己的根证书共享给客户端)

第五步:客户端下载根证书

[aliyunzixun@xxx.com CA]# man openssl

++++++++++++++++++++++++++++++++

1.部署签发环境:(做一个私有CA服务器用,来给别的公司服务器发数字证书)192.168.4.99

[aliyunzixun@xxx.com ~]# ls /etc/pki/tls/openssl.cnf

/etc/pki/tls/openssl.cnf

[aliyunzixun@xxx.com ~]# rpm -qf /etc/pki/tls/openssl.cnf

openssl-1.0.1e-42.el6.x86_64

[aliyunzixun@xxx.com ~]# cd /etc/pki/CA/

[aliyunzixun@xxx.com CA]# touch index.txt(证书的内容保存文件)

[aliyunzixun@xxx.com CA]# ls

certs crl index.txt newcerts private

[aliyunzixun@xxx.com CA]# echo 01 > serial

[aliyunzixun@xxx.com CA]# cat serial (创建一个文件用来记录证书的个数,做第二个证书的时候会自动加)

01

[aliyunzixun@xxx.com CA]# ls

certs crl index.txt newcerts private serial

[ CA_default ]

41

42 dir = /etc/pki/CA# Where everything is kept

43 certs= $dir/certs# Where the issued certs are kept

44 crl_dir = $dir/crl # Where the issued crl are kept

45 database= $dir/index.txt# database index file.

48 new_certs_dir= $dir/newcerts # default place for new certs.

50 certificate = $dir/my-ca.crt# The CA certificate

51 serial = $dir/serial# The current serial number

52 crlnumber= $dir/crlnumber# the current crl number

54 crl = $dir/crl.pem # The current CRL

55 private_key = $dir/private/my-ca.key # The private key

56 RANDFILE= $dir/private/.rand# pri

130 countryName_default = CN

135 stateOrProvinceName_default = beijing

141 0.organizationName_default = tarena

148 organizationalUnitName_default = ope

2.创建私钥文件:/etc/pki/CA/private/my-ca.key

[aliyunzixun@xxx.com private]# pwd

/etc/pki/CA/private

[aliyunzixun@xxx.com private]# openssl genrsa -des3 2048 >my-ca.key (创建私钥,并导入到私钥文件,记住密码)

Generating RSA private key, 2048 bit long modulus

......................+++

..+++

e is 65537 (0x10001)

Enter pass phrase:

Verifying - Enter pass phrase:

3.使用私钥创建根证书文件

[aliyunzixun@xxx.com private]# cd /etc/pki/CA

[aliyunzixun@xxx.com CA]# openssl req -new -x509 -key /etc/pki/CA/private/my-ca.key -days 365 > my-ca.crt(使用私钥创建根证书文件-x509格式)

[aliyunzixun@xxx.com CA]# ls

certs crl index.txt my-ca.crt newcerts private serial

[aliyunzixun@xxx.com CA]# cat my-ca.crt (证书生成)

-----BEGIN CERTIFICATE-----

MIID1zCCAr+gAwIBAgIJALAPCx/Wdm/lMA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD

VQQGEwJDTjEQMA4GA1UECAwHYmVpa

-----END CERTIFICATE-----

4.把证书文件共享给客户端 (就是把CA私有机构给服务器做的根证书发给该服务 但这里CA服务器和认证的一台,效果是一样的把根证书文件共享到服务器的目录下)

[aliyunzixun@xxx.com CA]# yum -y install httpd

[aliyunzixun@xxx.com CA]# mkdir /var/www/html/ca

[aliyunzixun@xxx.com CA]# cp my-ca.crt /var/www/html/ca/

[aliyunzixun@xxx.com CA]# ls /var/www/html/ca/my-ca.crt

/var/www/html/ca/my-ca.crt

[aliyunzixun@xxx.com CA]# ls /var/www/html/ca/my-ca.crt -l

-rw-r--r--. 1 root root 1391 3月6 23:37 /var/www/html/ca/my-ca.crt

[aliyunzixun@xxx.com CA]# service httpd start

[aliyunzixun@xxx.com CA]# chkconfig httpd on

5.客户端下载根证书

[aliyunzixun@xxx.com ~]$ ping 192.168.4.99

[aliyunzixun@xxx.com ~]$ firefox //192.168.4.99/ca

在打开的页面中 下载证书。

——————————————————————————————————————————————————————————————————————

___________________________________________________________________________________________________________________________________________________________

一 配置网站HTTP SSL (192.168.4.100)

网站服务器:

1.运行网站服务

# yum -y install httpd

# service httpd restart

# chkconfig httpd on

2.创建私钥文件

# cd /etc/pki/tls/private/

# openssl genrsa 2048 > www.key (生成私钥,什么服务私钥就起什么名好记,记住密码) 1生成密码字符最好是1024的整数倍

# ls

www.key

# cat www.key

-----BEGIN RSA PRIVATE KEY-----

MIIEowIBAAKCAQEApgz2xBeEs151p3dMGmj13pbicS5JGd1cMWiMryUjaRgJPRWF

..

3.创建证书请求文件

#cd /etc/pki/tls/private/

# openssl req -new -key www.key > /root/www.csr

.........

Common Name (eg, your name or your server's hostname) []:stu.tedu.cn (填的一定是公司服务器主机名 /etc/sysconfig/network 所对应的)

........

4.把证书请求文件上传给CA服务器

[aliyunzixun@xxx.com private]# scp /root/www.csr aliyunzixun@xxx.com:/root/

二.CA服务器:(192.168.4.99)

签收数据证书

[aliyunzixun@xxx.com ~]# ls /root/www.csr

/root/www.csr

[aliyunzixun@xxx.com ~]# cd /etc/pki/CA/

[aliyunzixun@xxx.com CA]# ls

certs crl index.txt my-ca.crt newcerts private serial

[aliyunzixun@xxx.com CA]# cat index.txt

[aliyunzixun@xxx.com CA]# cat serial

01

[aliyunzixun@xxx.com CA]# cd certs/

[aliyunzixun@xxx.com certs]# ls

[aliyunzixun@xxx.com certs]# openssl ca -in /root/www.csr > www.crt (输入密码 按y)

[aliyunzixun@xxx.com CA]# cat serial

02

[aliyunzixun@xxx.com CA]# cat index.txt

V180306163836Z01unknown/C=CN/ST=beijing/O=tarena/OU=ope

[aliyunzixun@xxx.com certs]# ls

www.csr

[aliyunzixun@xxx.com certs]# cat www.crt

Certificate:

..............

三.把证书下发给web服务器(192.168.4.99)

[aliyunzixun@xxx.com certs]# scp www.crt aliyunzixun@xxx.com:/root/

四.给网站加密:(web服务器192.168.4.100)

#netstat -utnalp | grep :443(此时没有443端口)

#rpm -q mod_ssl

#yum -y install mod_ssl

#vim /etc/httpd/conf.d/ssl.conf

18Listen 443

<VirtualHost _default _:443>

SSLEngine on

105 SSLCertificateFile /etc/pki/tls/certs/www.crt

112 SSLCertificateKeyFile /etc/pki/tls/private/www.key

</VirtualHost>

:wq

#mv /root/www.crt /etc/pki/tls/certs/

# service httpd stop

# service httpd stop

# service httpd start

#netstat -utnalp | grep :443 (能够查看到443端口)

#netstat -utnalp | grep :80 (能够查看到80端口)

# echo "123" >/var/www/html/test.html


五(客户机测试192.168.4.254)

[aliyunzixun@xxx.com 桌面]# vim /etc/hosts

192.168.4.100 stu.tedu.cnstud

[aliyunzixun@xxx.com 桌面]# firefox //stu.tedu.cn/test.html (能打开)

[aliyunzixun@xxx.com 桌面]# firefox //192.168.4.100/test.html (能打开)

[aliyunzixun@xxx.com 桌面]# firefox https://stu.tedu.cn/test.html (能打开,让先下证书)

(生产工作中,客户访问web加密网站,下载根证书在CA下或在本地web下,是程序员在网页代码中写的,运维只需把服务搭出来。就像客户在淘宝支付时,需要下一个认证/插件,在哪个位置下一样,这是程序员指定的)

六.客户机测试 (192.168.4.254)

1 从CA下载根证书 (//CA-ip/ca)

[aliyunzixun@xxx.com 桌面]#firefox //192.168.4.99/ca

2访问

[aliyunzixun@xxx.com 桌面]# firefox https://stu.tedu.cn/test.html(不用再在这下载证书,直接打开,打开的是https)

[aliyunzixun@xxx.com 桌面]# firefox //stu.tedu.cn/test.html (也直接打开打开的是http)

{80 //web-ip/test.html

443 https://web-ip/test.html}

七.地址重写:(web网站192.168.4.100)

配置网站服务器 把接收到的访问80端口的请求自动重定向到443端口 (http---->https)

vim /etc/httpd/conf/httpd.conf(也可在 /etc/httpd/conf/ssl.conf写,都一样)

.....

<IfModule ssl_module>

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

</IfModule>

RewriteEngine on

RewriteCond %{SERVER_PORT} !^443$

RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]

:wq

/etc/init.d/httpd restart

八.客户机测试 (192.168.4.254)

[aliyunzixun@xxx.com 桌面]# firefox https://stu.tedu.cn/test.html(打开的是https)

[aliyunzixun@xxx.com 桌面]# firefox //stu.tedu.cn/test.html (打开的是http)

——————————————————————————————————————————————————————————————————————————————

2.邮件服务TLS/SSL (192.168.4.101)

邮件服务器的配置

2.1运行收邮件的服务 service dovecot start

2.2运行发邮件的服务 service postfix start

2.3测发能否收发本地域的邮件 localhost

aliyunzixun@xxx.com 发件人

aliyunzixun@xxx.com 收件人

2.4传建私钥文件 mail.key

#openssl genrsa 2048 > mail.key

2.5创建证书请求文件 mail.csr

2.6把证书请求文件上传给CA服务器

CA服务器的配置

1 签发数字证书 mail.crt

2 把证书下发给mail服务器

3 设置邮件服务器在运行时加载私钥文件和数字文件

3.1配置收邮件服务 110143 995993

pop3 imap pop3s imaps

3.2配置发邮件服务 stmp 25

3.3重启服务

4配置客户端

在客户端软件里配置连接邮件服务时,选择使用的端口号

+++++++++++++

实验:

[aliyunzixun@xxx.com conf.d]# yum -y install postfix dovecot

[aliyunzixun@xxx.com conf.d]# rpm -q postfix

postfix-2.6.6-6.el6_5.x86_64

[aliyunzixun@xxx.com conf.d]# rpm -q dovecot

dovecot-2.0.9-19.el6.x86_64

[aliyunzixun@xxx.com ~]# vim /etc/postfix/main.cf

419 home_mailbox = Maildir/

[aliyunzixun@xxx.com conf.d]# pwd

/etc/dovecot/conf.d

[aliyunzixun@xxx.com conf.d]# vim 10-mail.conf

24 mail_location = maildir:~/Maildir

[aliyunzixun@xxx.com ~]# service postfix start

[aliyunzixun@xxx.com ~]# service dovecot start

[aliyunzixun@xxx.com ~]# netstat -anptu |grep :25

tcp0 0 127.0.0.1:250.0.0.0:*LISTEN 1765/master

tcp0 0 ::1:25 :::*LISTEN 1765/master

[aliyunzixun@xxx.com ~]# netstat -anptu |grep dovecot

tcp0 0 0.0.0.0:993 imaps(加密后)0.0.0.0:*LISTEN 2872/dovecot

tcp0 0 0.0.0.0:995 pop3s0.0.0.0:*LISTEN 2872/dovecot

tcp0 0 0.0.0.0:110(pop3) 0.0.0.0:*LISTEN 2872/dovecot

tcp0 0 0.0.0.0:143 (imap)0.0.0.0:*LISTEN 2872/dovecot

tcp0 0 :::993 :::*LISTEN 2872/dovecot

tcp0 0 :::995 :::*LISTEN 2872/dovecot

tcp0 0 :::110 :::*LISTEN 2872/dovecot

tcp0 0 :::143 :::*LISTEN 2872/dovecot

[aliyunzixun@xxx.com ~]# cd /etc/dovecot/

[aliyunzixun@xxx.com dovecot]# cd conf.d/

[aliyunzixun@xxx.com conf.d]# vim 10-mail.conf

[aliyunzixun@xxx.com conf.d]# vim 10-ssl.conf

[aliyunzixun@xxx.com conf.d]# sed -n '12,13p' 10-ssl.conf

ssl_cert = </etc/pki/dovecot/certs/dovecot.pem

ssl_key = </etc/pki/dovecot/private/dovecot.pem

[aliyunzixun@xxx.com conf.d]# ls /etc/pki/dovecot/certs/

dovecot.pem

[aliyunzixun@xxx.com conf.d]# ls /etc/pki/dovecot/private/

dovecot.pem

[aliyunzixun@xxx.com conf.d]# useradd tom

[aliyunzixun@xxx.com conf.d]# useradd jim

[aliyunzixun@xxx.com conf.d]# echo 123 |passwd --stdin tom

更改用户 tom 的密码 。

passwd: 所有的身份验证令牌已经成功更新。

[aliyunzixun@xxx.com conf.d]# echo 123 |passwd --stdin jim

更改用户 jim 的密码 。

passwd: 所有的身份验证令牌已经成功更新。

[aliyunzixun@xxx.com conf.d]# yum -y install telnet (下载连接邮件服务器工具)

[aliyunzixun@xxx.com conf.d]# telnet localhost 25 (发邮件 jim)

Trying ::1...

Connected to localhost.

[aliyunzixun@xxx.com ~]# telnet localhost 110(接邮件 tom)

Trying ::1...

Connected to localhost.

Escape character is '^]'.

+OK Dovecot ready.

user tom

+OK

pass 123

+OK Logged in.

list

+OK 0 messages:

.

quit

[aliyunzixun@xxx.com ~]# openssl genrsa 2048 > mail.key (传建私钥文件)

[aliyunzixun@xxx.com ~]# openssl req -new -key mail.key > mail.csr (生成证书请求文件)

[aliyunzixun@xxx.com ~]# cd /etc/pki/CA/

[aliyunzixun@xxx.com CA]# cat serial

02

[aliyunzixun@xxx.com certs]# openssl ca -in /root/mail.csr> mail.crt

[aliyunzixun@xxx.com CA]# cat index.txt

V180306163836Z01unknown/C=CN/ST=beijing/O=tarena/OU=ope/CN=stu.tedu.cn/aliyunzixun@xxx.com

V180307190945Z02unknown/C=CN/ST=beijing/O=tarena/OU=ope/CN=stu.tedu.cn/aliyunzixun@xxx.com

[aliyunzixun@xxx.com CA]# cat serial

03

[aliyunzixun@xxx.com certs]# scp mail.crt aliyunzixun@xxx.com:/root/(把证书请求文件上传给CA服务器)

[aliyunzixun@xxx.com ~]# vim /etc/dovecot/conf.d/10-ssl.conf

12 ssl_cert = </etc/pki/dovecot/certs/mail.crt

13 ssl_key = </etc/pki/dovecot/private/mail.key

[aliyunzixun@xxx.com ~]# sed -n '12,13p' /etc/dovecot/conf.d/10-ssl.conf

ssl_cert = </etc/pki/dovecot/certs/mail.crt

ssl_key = </etc/pki/dovecot/private/mail.key

[aliyunzixun@xxx.com ~]# cp /root/mail.key /etc/pki/dovecot/private/

[aliyunzixun@xxx.com ~]# cp /root/mail.crt /etc/pki/dovecot/certs

[aliyunzixun@xxx.com ~]# service dovecot restart

停止 Dovecot Imap:[确定]

正在启动 Dovecot Imap:[确定]

[aliyunzixun@xxx.com ~]# netstat -anptu |grep dovecot

[aliyunzixun@xxx.com ~]# postconf (查看帮助,配置项怎么写) 发信

[aliyunzixun@xxx.com ~]# vim /etc/postfix/main.cf

675 readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

676

677 smtpd_use_tls = yes

678 smtpd_tls_key_file = /etc/pki/tls/private/mail.key

679 smtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt

————————————————————————————————————————————————————

3扫描与抓包

3.1端口扫描(nmap)

3.2抓包(tcpdump)

3.3协议分析工具(wireshark)

扫描方式:scan主动探测 sniff被动监听 capture 数据包抓包

1.常用格式:(扫描)

[aliyunzixun@xxx.com 桌面]# yum -y install nmap

[aliyunzixun@xxx.com 桌面]# which nmap

/usr/bin/nmap

[aliyunzixun@xxx.com 桌面]# man nmap

[aliyunzixun@xxx.com 桌面]# nmap -sP 172.40.55.244

Starting Nmap 5.51 ( //nmap.org ) at 2017-03-08 14:22 CST

Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn(检查这台主机是否在现,没有)

Nmap done: 1 IP address (0 hosts up) scanned in 0.44 seconds

[aliyunzixun@xxx.com 桌面]# nmap -sP 172.40.55.127 (检查这台主机是否在现)

Starting Nmap 5.51 ( //nmap.org ) at 2017-03-08 14:19 CST

Nmap scan report for 172.40.55.127

Host is up (0.00019s latency). (检查这台主机是否在现)

MAC Address: FC:AA:14:CD:F5:AC (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

[aliyunzixun@xxx.com 桌面]# ping 172.40.55.127

PING 172.40.55.127 (172.40.55.127) 56(84) bytes of data.

64 bytes from 172.40.55.127: icmp_seq=1 ttl=64 time=0.928 ms

^C

--- 172.40.55.127 ping statistics ---

[aliyunzixun@xxx.com 桌面]# nmap -A 172.40.55.127 (整台扫描)

[aliyunzixun@xxx.com 桌面]# namp -sT -p 80 172.40.55.127 172.40.55.104

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 20-80,443 172.40.55.127 172.40.55.104

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 20-80,443 172.40.55.104-110

[aliyunzixun@xxx.com 桌面]# nmap -sU -p 20-80,443 172.40.55.0/24

[aliyunzixun@xxx.com 桌面]# nmap -sP172.40.55.0/24

[aliyunzixun@xxx.com 桌面]# nmap -sP -iL ip.txt(ip.txt 中先写入ip)

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 110 -iL ip.txt

[aliyunzixun@xxx.com 桌面]# nmap -sP172.40.55.100-130 --exclude 172.40.55.103-105

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 80,110172.40.55.100-130 --exclude 172.40.55.103-105

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 80,110172.40.55.100-130 --excludefile ip.txt (不扫描这个文件中的)

[aliyunzixun@xxx.com 桌面]# nmap -sT -p 80 172.40.55.119 |grep open

80/tcp open http

ip地址 172.40.55.$ip

重复执行的操作:

vim httpd.sh

#!/bin/bash

while :

do

x=0

for ip in 103 105 107 127 110 102

do

nmap -sT -p 80 172.40.55.$ip | grep -q open

if [ $? -eq 0 ];then

echo "172.40.55.$ipweb is ok"

else

echo "172.40.55.$ip web is stop"

echo "172.40.55.$ip >> /tmp/ipdown.txt

let x++

fi

done

mail -s "weberror" root < /tmp/ipdown.txt

echo "web down host is $x"

sleep 600

done

chmod +x httpd.sh

httpd.sh &;

+++++++++++++++++++++++++++

vim httpd.sh

#!/bin/bash

x=0

echo "web down is " > /tmp/ipdown.txt

for ip in 103 105 107 127 110 102

do

nmap -sT -p 80 172.40.55.$ip | grep -q open

if [ $? -eq 0 ];then

echo "172.40.55.$ipweb is ok"

else

echo "172.40.55.$ip web is stop"

echo "172.40.55.$ip >> /tmp/ipdown.txt

let x++

fi

done

lines=`wc -l /tmp/ipdown.txt |awk '{print $1}' `

if [ $lines -gt 1 ];then

mail -s "weberror" root < /tmp/ipdown.txt

fi

echo "web down host is $x"

rm -rf /tmp/ipdown.txt

:wq

chmod +x httpd.sh

cron -e

*/10 * * * * /root/httpd.ssh

service crond restart

查看邮件:

[aliyunzixun@xxx.com 桌面]# vim /etc/postfix/main.cf

419 home_mailbox = Maildir/

[aliyunzixun@xxx.com 桌面]# mail -f /home/httpadmin/

.bash_logout.bashrcMaildir/

.bash_profile .gnome2/.mozilla/

[aliyunzixun@xxx.com 桌面]# mail -f /home/httpadmin/Maildir/

Heirloom Mail version 12.4 7/29/08. Type ? for help.

"/home/httpadmin/Maildir/": 1 message 1 new

>N 1 root Wed Mar 8 20:00 20/589"weberror"

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2.TCPDUMP抓包(tcpdump)

[aliyunzixun@xxx.com 桌面]# which tcpdump

/usr/sbin/tcpdump

[aliyunzixun@xxx.com 桌面]# rpm -qf /usr/sbin/tcpdump

tcpdump-4.0.0-5.20090921gitdf3cb4.2.el6.x86_64

[aliyunzixun@xxx.com 桌面]# yun -y install tcpdump

[aliyunzixun@xxx.com 桌面]# man tcpdump

[aliyunzixun@xxx.com 桌面]# tcpdump (开始抓整个)

[aliyunzixun@xxx.com 桌面]# tcpdump -A (抓的显示出屏幕上)

[aliyunzixun@xxx.com 桌面]# tcpdump -A -w /tmp/a.cap (抓 w保存文件里)

[aliyunzixun@xxx.com 桌面]# tcpdump -A -r /tmp/a.cap(r读出来)

-i-A-w-r

[aliyunzixun@xxx.com 桌面]# tcpdump -A -w /tmp/1.txt tcp port 110

[aliyunzixun@xxx.com 桌面]# tcpdump -A -r /tmp/1.txt |grep -i --color user

[aliyunzixun@xxx.com 桌面]# tcpdump -A -r /tmp/1.txt |grep -i --color pass

[aliyunzixun@xxx.com 桌面]# tcpdump -A tcp portrange 20-21

[aliyunzixun@xxx.com 桌面]# tcpdump -A tcp portrange 20-21 and host 192.168.4.101 (只抓101这台)

____________________________________________________________________________________________________________________________________________________________

————————————————————————————————————————————————————————————————————————

抓包实验,192.168.4.101开启抓包,让192.168.4.7访问它ftp抓把。保存在文件中。

[aliyunzixun@xxx.com ~]# tcpdump -A -w /tmp/t.txt tcp portrange 20-21

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

^C36 packets captured

[aliyunzixun@xxx.com opt]# ftp 192.168.4.101

Connected to 192.168.4.101 (192.168.4.101).

220 (vsFTPd 2.2.2)

Name (192.168.4.101:root): ftp

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

227 Entering Passive Mode (192,168,4,101,197,237).

150 Here comes the directory listing.

-rw-r--r--1 004 Mar 08 00:48 1.txt

drwxr-xr-x2 004096 Mar 06 2015 pub

226 Directory send OK.

ftp> get 1.txt

local: 1.txt remote: 1.txt

227 Entering Passive Mode (192,168,4,101,106,217).

150 Opening BINARY mode data connection for 1.txt (4 bytes).

226 Transfer complete.

4 bytes received in 0.000489 secs (8.18 Kbytes/sec)

ftp> quit

221 Goodbye.

[aliyunzixun@xxx.com ~]# tcpdump -A -w /tmp/t.txt tcp portrange 20-21

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

(按ctrl+c,保存退出)

^C36 packets captured

36 packets received by filter

0 packets dropped by kernel

[aliyunzixun@xxx.com ~]# tcpdump -A -r /tmp/t.txt (把抓到的在屏幕中显示)

reading from file /tmp/t.txt, link-type EN10MB (Ethernet)

09:00:17.542583 IP 192.168.4.7.58623 > 192.168.4.101.ftp:

E..<aliyunzixun@xxx.com@..........e.......?......9............

............

...........................................

[aliyunzixun@xxx.com ~]# tcpdump -A -r /tmp/t.txt |grep -i --color pass (在抓包文件中检索密码)

reading from file /tmp/t.txt, link-type EN10MB (Ethernet)

.i......331 Please specify the password.

...0.i..PASS ftp

.i.....y227 Entering Passive Mode (192,168,4,101,197,237).

.i.D....227 Entering Passive Mode (192,168,4,101,106,217).

————————————————————————————————————————————————————————————————

____________________________________________________________________________________________________________________________________________________

网络中用来抓包,协议分析工具是用wireshark,俗称网络鲨鱼,装好后。在应用程序里可以把这个软件打开,是用图形界面显示的,所以装的时候要有图形。抓到包后,这图形上面显示抓到的包,下面显示这个包经过的物理层,数据链路层,网络层和传输层。最下面显示的是点开哪一层,都会详细信息。(公司生产环境中抓包,一般抓的是装防火墙的这台服务器。

3.3协议分析工具(wireshark)(网络鲨鱼)

[aliyunzixun@xxx.com 桌面]# yum -y install wireshark wireshark-gnome

[aliyunzixun@xxx.com 桌面]# rpm -qa |grep shark

wireshark-gnome-1.8.10-17.el6.x86_64

wireshark-1.8.10-17.el6.x86_64

osi(开放系统互联) 物理层(网卡) 数据链路层(交换) 网络层(路由,三层) 传输层 (udp视频音频适合tcp ) 会话表示层 应用 http ftp smtp

IP包里都包含哪些信息:目标地址 源地址 目标端口 源端口

tcp标记位 : 建立连接SYN 确认ACK断开FIN 发送数据PUSH重新连接RST

tcp/ip 四层:

物理层(比特流) 网络层(包) 传输层(段) 应用层(协议层)

为什么给ip包分段:因为数据包可能比较大,路由过不去只能分段,每个数据包会有tcp标记,。

ftp(下载20 主动) ftp(访问21 被动)

CA机构(CA服务器)是用来给公司服务器颁发数字证书的。有权威的也有私有自己搭建的。

使用IP地址是X.X.X.88主机做CA服务器

整体部署思路

第一步:配置CA签署环境(给客户端发证的默认配置)

/etc/pki/tls/openssl.cnf

第二步:为CA服务器生成私钥(创建密钥对)

第三步:为CA服务器创建根证书 (生成自己的根证书文件)

第四步:发布根证书文件(把自己的根证书共享给客户端)

第五步:客户端下载根证书

1

[aliyunzixun@xxx.com ~]# rpm -qf/etc/pki/tls/openssl.cnf

openssl-1.0.1e-42.el6.x86_64

[aliyunzixun@xxx.com ~]#

vim/etc/pki/tls/openssl.cnf

40 [ CA_default ]

42 dir = /etc/pki/CA

43 certs= $dir/certs

45 database= $dir/index.txt

50 certificate = $dir/my-ca.crt

55 private_key = $dir/private/my-ca.key

84 [ policy_match ]

85 countryName = match

86 stateOrProvinceName = match

87 organizationName= match

88 organizationalUnitName = optional

89 commonName = supplied

90 emailAddress= optional

128 [ req_distinguished_name ]

130 countryName_default = CN

135 stateOrProvinceName_default = beijing

138 localityName_default= beijing

141 0.organizationName_default = tarena

148 organizationalUnitName_default = ope

:wq

touch /etc/pki/CA/index.txt

echo 01 > /etc/pki/CA/serial

2

cd /etc/pki/CA/private/

]# openssl genrsa -des3 2048 > my-ca.key

chmod 600 my-ca.key

3

cd/etc/pki/CA/private/

openssl req-new -x509 -key my-ca.key -days 365 >

../my-ca.crt

[aliyunzixun@xxx.com private]# openssl req-new -x509 -key

my-ca.key -days 365 > ../my-ca.crt

Enter pass phrase for my-ca.key:

You are about to be asked to enter information that will

be incorporated

into your certificate request.

What you are about to enter is what is called a

Distinguished Name or a DN.

There are quite a few fields but you can leave some

blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [beijing]:

Locality Name (eg, city) [beijing]:

Organization Name (eg, company) [tarena]:

Organizational Unit Name (eg, section) [ope]:

Common Name (eg, your name or your server's

hostname) []:ca.tedu.cn

Email Address []:aliyunzixun@xxx.com

[aliyunzixun@xxx.com private]#

[aliyunzixun@xxx.com CA]# ls /etc/pki/CA/my-ca.crt

/etc/pki/CA/my-ca.crt

[aliyunzixun@xxx.com CA]#

4

rpm -q httpd || yum -y install httpd

mkdir /var/www/html/certs/

cp /etc/pki/CA/my-ca.crt/var/www/html/certs/

servicehttpdstart

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved