关于网络安全:SeedLab-PublicKey-Infrastructure-Lab

13次阅读

共计 4283 个字符,预计需要花费 11 分钟才能阅读完成。

筹备试验

SeedLab 16 版本试验 Public-Key Infrastructure Lab.

试验领导 https://seedsecuritylabs.org/Labs_16.04/PDF/Crypto_PKI.pdf

T1 Becoming a Certification Authority (CA)

在这个试验中, 咱们须要创立 digital certificates, 咱们本人做本人的 CA. 而后应用这个 CA 来给别的什么货色提供验证服务.

The Configuration File

有一个文件 openssl.conf.
这里有一个问题: 就是 OpenSSL 是什么.
须要现有 openssl.conf 文件, 而后应用 OpenSSL 生成 certificates.

ATC 咱们可能须要解决一下 openssl 这玩意

openssl 一共有三个命令: ca, req, x509.
/usr/lib/ssl/openssl.cnf 能够提供这样的配置文件, 能够复制他.

而后在 openssl.cnf 所在的目录下, 创立几个子目录与文件.

mkdir demoCA demoCA/certs demoCA/crl demoCA/newcerts
echo > demoCA/index.txt
echo 1000 > demoCA/serial

index.txt 内容为空. 特地留神, 可能关上 index.txt 文件的软件 (例如 gedit) 肯定要用 tab 替换成 backspace.
serial 能够填入其余的数字, 他的性能应该就是个计数器.

Certificate Authority (CA)

这一步如同是创立 Certifate Authority

openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf

下面的指令取得两个输入文件: ca.key (私钥证书) 和 ca.crt (公钥证书)

T2 Creating a Certification for SEEDPKILab2018.com

当初咱们有能力给出 digital certificates. 第一个公司叫做 SEEDPKILab2018.com.

T1.1 Generate public/private key pair

咱们须要有公钥和私钥对. RSA.

openssl genrsa -aes128 -out server.key 1024

应用 aes128 encryption algorithm. 秘钥存在在 server.key. 另一条指令能够将 server.key 转成文本, 不便浏览.

openssl rsa -in server.key -text

指令 openssl rsa -in server.key -out server.key.unsecure 能够取得免密的 server key.

T1.2 Generate a Certificate Signing Request (CSR)

CSR 也就是证书签名申请? 蕴含了企业的公钥?
CSR 会被送给 CA, CA 将生成秘钥的证书.

# 这一步中要在 common_name 一条中输出 seedpkilab2018.com 绑定站点, 其余内容能够不填
openssl req -new -key server.key -out server.csr -config openssl.cnf

根据形容, certificate signing request 和 certificate authority 是一对的.

T1.3 Generating Certificates

CSR file 须要有 CA 的签名能力产出证书.
在试验最开始的时候, 咱们就有了本人的 CA.

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

试验领导中给出了如果 CA 回绝生成证书的解决方案.

T3 Deploying Certificate in an HTTPS Web Server

这一步, 咱们将 public-key 用在网站上. 应用 openssl 内建的 web 服务器去建设一个 HTTPS 的站点.

T3.1 Configuring DNS

配置 DNS, 批改 /etc/hosts, 配置 127.0.0.1 SEEDPKILab2018.com

T3.2 Configuring the web server

配置 web 服务器.

cp server.key server.pem
cat server.crt >> server.pem
openssl s_server -cert server.pem -www

当初, 服务将会监听 4433 端口. 应用 https://SEEDPKILab2018.com:4433/ 来拜访.
不出意外的话, 咱们会收到一份来自浏览器的错误信息. 大略是说以后的网站没有非法的证书.

T3.3 Getting the browser to accept our CA Certificate

让浏览器承受 CA 证书. 有两种形式:

  1. 申请 Mozilla 去蕴含咱们的 CA 证书在 FireFox 软件, 用屁股想都晓得这不可能.
  2. 让浏览器加载 ca.crt (公钥证书) Edit -> Preference-> Privacy & Security -> View Certificates

T3.4 Testing our HTTPS website

测试咱们的 HTTPS 网站. 从新操作 Step2.

而后咱们须要反复接下来的工作:

  1. 仅仅批改 server.pem 中的一位, 重启服务器, 重载 URL, (请先备份 server.pem) 另外, 如果服务起不来, 可能是 server.pem 不该改的地位被改了. 并不会有什么影响.
  2. 尝试应用 https://localhost:4433 , 浏览器会显示是一个没有认证过的网站, 不容许拜访. 本地 CA 没有对 localhost 进行受权.

T4 Deploying Certificate in an Apache-Based HTTPS Website

在一个 Apache-Based HTTPS website 中应用证书. 在这个试验中, 咱们建设了一个实在的 HTTPS web server based on Apache.

试验领导给出了 example.com 的参考, 而后咱们须要对 SEEDPKILab2018.com 也做一遍.

部署一个小我的项目

先在 Apache 的目录下部署一个我的项目:

  1. 在门路 /var/www/ 增加 pki 文件夹
  2. pki 文件夹内增加 index.html, html 内容随便.

应用 HTTP 浏览我的项目

批改 /etc/apache2/site-available/000-default.conf, 增加

<VirtualHost *:80>
    ServerName SEEDPKILab2018.com
    DocumentRoot /var/www/pki
</VirtualHost>

当初重启 apache2 的 service, 并拜访 http://seedpkilab2018.com 应该能够看见 index.html 中内容.

应用 HTTPS 浏览我的项目

批改 /etc/apache2/site-available/default-ssl.conf, 增加

<VirtualHost *:443>
    ServerName SEEDPKILab2018.com
    DocumentRoot /var/www/pki
    DirectoryIndex index.html

    SSLEngine On
    SSLCertificateFile /home/seed/Desktop/server.pem
    SSLCertificateKeyFile /home/seed/Desktop/server.pem 
</VirtualHost>
sudo apachectl configtest
sudo a2enmod ssl
sudo a2ensite default-ssl
sudo service apache2 restart

应用 HTTPS 协定拜访 https://seedpkilab2018.com 应该再次能够看见 index.html 中内容.

T5 Launching a Man-In-The-Middle Attack

这一步次要展现: PKI 如何战胜中间人攻打.

如果没有 PKI, 用户在拜访 example.com 的时候就须要获取 server 的 public key.
Alice 将会生成一个 secert, 而后应用 server 的 public key 去编码这个 secert. 而后再发给 Server.

攻击者可能拦挡 Server 给出的 public key 而后替换成本人的 public key 再发给 用户. 如此攻击者是有能力读取用户收回的数据.

这个试验的次要目标就是帮忙学生了解 PKI 如何战胜这样的中间人攻打. 在这个攻打中, 咱们将会模仿一个这样的 MITM 攻打, 而后看 PKI 如何击败它.

首先咱们须要抉择一个 website. 讲道理, example 是一个不错的抉择, 然而这里更加倡议应用一个事实的站点?

这里须要作出一个假如, 用户理论拜访的是 example.com 这个 web server. 然而, 咱们伪装动员了一次 DNS 缓存毒化攻打, 将 hosts 批改为 那个什么 2018 的 网站 ip, 也就是攻击者的网站 IP. 这样就创立了 attacker 与 victim 之间的通信.

T5.1 Setting up malicious websites

这里的操作会模拟 T4 中的内容.

咱们的指标是这样的: 当一个用户打算拜访 example.com 的时候, 咱们把他引到本人的 server, hosts 了一个假的 website for example.com. 而后他们可能在者之间写些什么货色.

模拟 T4 中的操作, 创立一个 www.apple.com 的 ssl server.

T5.2 Becoming the man in the middle

成为那个中间人. 能够攻打路由或者攻打 DNS. 这一步, 咱们抉择 DNS 攻打. 为了简化操作, 咱们间接批改受害者的 /etc/hosts. 去模仿一个 DNS 缓存毒化攻打.
<IP_Address> example.com
这里的 IP_Address 应该是 malicious server 的 ip.

10.0.2.14  www.apple.com

T5.3 Browse the target website

从新浏览指标网站, 看看本人的浏览器说了什么.

浏览器示意: “ 正告: 面临潜在的平安危险.” 没有任何 CA 对咱们本人的 www.apple.com ssl server 颁发证书.

T6 Launching a Man-In-The-Middle Attack with a Compromised CA

这里做出了一个假如, 就是咱们的 CA 曾经被人收购, 给 www.apple.com 创立 cert.

正文完
 0