day3-selinux+openssl

SElinux強制安全 linux

加密與解密技術 git

CA數字證書服務 算法

       

標準Lunux安全模型 vim

DAC自主訪問控制    Discretionary Access Control    全部都對本身的資源負責 安全

典型的DAC應用 服務器

9位權限碼 網絡

ACL dom

       

SElinux    Security-Enhanced Linux 工具

一套強化Linux安全的MAC擴展模塊 測試

美國國家安全局主導開發

SELinux的動做機制

集成Linux的動做機制

集成到Linux內核——2.6及以上

操做系統提供可定製的策略、管理工具

       

策略

       

SELINUXTYPE=targeted

僅保護最多見/關鍵的網絡服務,其餘不限制

主要軟件包:selinux-policy、selinux-policy-targeted、libselinux-utils、libselinux-utils、conreutils、policycoreutils

       

SELINUXTYPE=mls

提供多層次、全面的安全防禦策略

需擴展軟件包:selinux-policy-mls、msctrans、policycoreutils-newrole

       

禁用/啓用SELinux機制

方法一:修改kernel啓動參數

添加selinux=0爲禁用,改成1爲啓用

方法二:修改文件/etc/selinux/config

設置SELINUX=disabled以禁用

設置SELINUX=permissive寬鬆模式

設置SELINUX=enforcing強制模式

臨時修改:setenforce

1是強制模式,0是寬鬆模式

       

修改SELinux

  1. 文件的上下文環境值(標籤值)

標籤值至關於給文件加了一把鎖。守護進程也有標籤值,該值至關於鑰匙,只有鎖和鑰匙匹配,才能打開文件,讀取內容

修改文件標籤值的方法

方法1:restorecon –Rv /path/to/dir

方法2:chconn –t 標籤值 /path/to/dir

  1. SELinux布爾值

getsebool –a查看全部的布爾值

setsebool –P 布爾值    on    永久修改-P

       

安裝setroubleshoot

yum –y install setroubleshoot*

重啓後生效

有任何的selinux違規行爲,系統都會給出提示和解決方案

若是是圖形界面下,屏幕右上角會彈出消息        能夠用sealert –b 查看

若是是字符終端下,能夠查看/var/log/message

       

得到SELINUX設置幫助     

#man ftpd_selinux

man httpd_selinux

man samba_selinux

有些服務,配置文件中也有說明

vim /etc/samba/smb.conf

   

實驗測試

開啓selinux

[root@localhost test]# grep -v ^# /etc/selinux/config

SELINUX=enforcing

SELINUXTYPE=targeted

   

臨時開啓

[root@localhost test]# getenforce     查看

Enforcing

[root@localhost test]# setenforce 1 開啓 0爲關閉

   

使用FTP服務進行測試

vim /etc/vsftpd/vsftpd

anonymous_enable=YES //開啓匿名訪問

write_enable=YES

anon_umask=022

anon_upload_enable=YES //容許上傳文件

anon_mkdir_write_enable=YES

   

chown ftp /var/ftp/pub

service vsftpd start

   

客戶端使用FTP登陸上去

put一個文件時,能夠上傳,但不能建立文件,全部上傳失敗

須要開啓selinux布爾值

使用setsebool –P allow_ftp_anon_write=1

time setsebool –P allow_ftpd_full_access=1

[root@localhost test]# getsebool -a |grep allow_ftpd

allow_ftpd_anon_write --> on

allow_ftpd_full_access --> on

改完後能夠上傳文件了

若setsebool allow_ftpd_full_access=0時

關閉時

如何從其餘目錄拷貝的文件,沒法去下載或上傳,有繼承關係

       

加密與解密

信息傳遞中的風險

加密

發送方:明文》》密文

接收方:密文》》明文

算法:加密/解密所使用的轉換規則

密鑰:加密/解密所使用的指令或代碼

       

加密方式

單向加密:加密只能向一個方向進行。能夠理解爲輸出明文數據,加密成亂碼。不能將亂碼反推回原始明文數據。可是原始的明文數據一致,生成的亂碼也是同樣的。經常使用的算法MD五、SHA。能夠用於計算文件的完整性和保存加密密碼。

對稱加密: 使用相同的算法和密鑰。對稱密鑰、共享密鑰。

    優勢:加密效率高。缺點:密鑰的傳輸和保管不方便。經常使用的算法有 des/3des/aes

非對稱加密:公鑰加密、私鑰解密。

    優勢:密鑰傳輸和保管方便。缺點加密效率低。經常使用算法RSA/DSA

     

/etc/shadow

$加密類型$隨機數$密碼+隨機數加密後的值

     

保護信息的完整性

信息摘要:基於輸入的信息生成長度較短、位數固定的散列值

對稱加密

DES:Date Encryption Standard

AES:Advanced Encryption Standard

非對稱加密

RSA:Rivest Shamirh Adleman

DSA:Digital Signature Algorithm

信息摘要

MD5:Message Digest Algorithm 5

SHA:Secure Hash Algorithm

     

MD5完整性校驗

使用md5sum工具

從新生成MD5校驗值

與軟件官方提供的校驗值比對

   

當文件內容同樣,使用MD5校驗也徹底同樣

   

GnuPG加密工具

GnuPG:GNU Privacy Guard

最流行的數據加密、數據簽名工具軟件

     

使用GPG加/解密文件

對稱方式

加密操做:--symmetric或-c

解密操做:--decrypt或-d

     

加密操做:gpg –a –c 文件名 (a是ascii碼 –c加密)

解密操做:gpg 文件名

     

yum install –y pinentry-gtk

私鑰簽名:

  1. 身份認證
  2. 數據完整性
  3. 不能否認

   

# gpg -c file2

輸出兩次密碼

在未解密的狀況下,顯示爲亂碼

gpg對稱解密操做

#gpg –d file2.gpg >file2

輸出相對應的密碼,在查看file2文件

   

使用GPG非對稱加密方式保護文件

gpg --gen-key

查看公鑰環

查看私鑰環

# gpg -a --export usera >/tmp/gpg.pub

   

導入GPG

解密gpg –d hehe.txt.gpg>hehe.txt

建立分離式數字簽名

gpg -b 1.tar.gz

GPG驗證

   

OpenSSL及證書服務

加密

解密

 

搭建自有的CA服務器,爲頒發數字證書提供基礎

[ CA_default ]

 

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

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

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

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

#unique_subject = no # Set to 'no' to allow creation of

# several ctificates with same subject.

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

 

certificate = $dir/cacert.pem # The CA certificate

serial = $dir/serial # The current serial number

crlnumber = $dir/crlnumber # the current crl number

# must be commented out to leave a V1 CRL

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

private_key = $dir/private/ca.key # The private key

RANDFILE = $dir/private/.rand # private random number file

 

x509_extensions = usr_cert # The extentions to add to the cert

 

# Comment out the following two lines for the "traditional"

# (and highly broken) format.

name_opt = ca_default # Subject Name options

cert_opt = ca_default # Certificate field options

 

# Extension copying option: use with caution.

# copy_extensions = copy

..

[ req_distinguished_name ]

countryName = Country Name (2 letter code)

countryName_default = CN

countryName_min = 2

countryName_max = 2

 

stateOrProvinceName = State or Province Name (full name)

stateOrProvinceName_default = SH

 

localityName = Locality Name (eg, city)

localityName_default = SH

 

0.organizationName = Organization Name (eg, company)

0.organizationName_default = Default Company Ltd

..

默認CA配置目錄位於/etc/pki/CA/,須要創建初初始化序列文件、索引文件

# cd /etc/pki/CA

[root@localhost CA]# touch index.txt

[root@localhost CA]# echo 01>serial

爲CA服務器建立私鑰,並設置一個私鑰中令進行保護,設置權限爲600

爲CA服務器建立根證書

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息