欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > TLS实验报告

TLS实验报告

2024/10/23 10:03:10 来源:https://blog.csdn.net/XLYcmy/article/details/143140481  浏览:    关键词:TLS实验报告
  1. Task 1: TLS Client

3.1 Task 1.a: TLS handshake

修改一下配置文件handshake.py内容:

然后输入指令:./handshake.py www.baidu.com

和百度进行握手。

执行得到如下图结果:

针对实验手册中提出的问题,我们回答如下:

What is the cipher used between the client and the server?

Please print out the server certifificate in the program.

Explain the purpose of /etc/ssl/certs.

Use Wireshark to capture the network traffifics during the execution of the program, and explain your observation. In particular, explain which step triggers the TCP handshake, and which step triggers the TLS handshake. Explain the relationship between the TLS handshake and the TCP handshake.

  1. Cipher used: ('ECDHE-RSA-AES128-GCM-SHA256', 'TLSv1.2', 128)

(2)Server certificate:

{'OCSP': ('http://ocsp.globalsign.com/gsrsaovsslca2018',),

 'caIssuers': ('http://secure.globalsign.com/cacert/gsrsaovsslca2018.crt',),

 'crlDistributionPoints': ('http://crl.globalsign.com/gsrsaovsslca2018.crl',),

 'issuer': ((('countryName', 'BE'),),

            (('organizationName', 'GlobalSign nv-sa'),),

            (('commonName', 'GlobalSign RSA OV SSL CA 2018'),)),

 'notAfter': 'Aug  6 05:16:01 2023 GMT',

 'notBefore': 'Jul  5 05:16:02 2022 GMT',

 'serialNumber': '4417CE86EF82EC6921CC6F68',

 'subject': ((('countryName', 'CN'),),

             (('stateOrProvinceName', 'beijing'),),

             (('localityName', 'beijing'),),

             (('organizationalUnitName', 'service operation department'),),

             (('organizationName',

               'Beijing Baidu Netcom Science Technology Co., Ltd'),),

             (('commonName', 'baidu.com'),)),

 'subjectAltName': (('DNS', 'baidu.com'),

                    ('DNS', 'baifubao.com'),

                    ('DNS', 'www.baidu.cn'),

                    ('DNS', 'www.baidu.com.cn'),

                    ('DNS', 'mct.y.nuomi.com'),

                    ('DNS', 'apollo.auto'),

                    ('DNS', 'dwz.cn'),

                    ('DNS', '*.baidu.com'),

                    ('DNS', '*.baifubao.com'),

                    ('DNS', '*.baidustatic.com'),

                    ('DNS', '*.bdstatic.com'),

                    ('DNS', '*.bdimg.com'),

                    ('DNS', '*.hao123.com'),

                    ('DNS', '*.nuomi.com'),

                    ('DNS', '*.chuanke.com'),

                    ('DNS', '*.trustgo.com'),

                    ('DNS', '*.bce.baidu.com'),

                    ('DNS', '*.eyun.baidu.com'),

                    ('DNS', '*.map.baidu.com'),

                    ('DNS', '*.mbd.baidu.com'),

                    ('DNS', '*.fanyi.baidu.com'),

                    ('DNS', '*.baidubce.com'),

                    ('DNS', '*.mipcdn.com'),

                    ('DNS', '*.news.baidu.com'),

                    ('DNS', '*.baidupcs.com'),

                    ('DNS', '*.aipage.com'),

                    ('DNS', '*.aipage.cn'),

                    ('DNS', '*.bcehost.com'),

                    ('DNS', '*.safe.baidu.com'),

                    ('DNS', '*.im.baidu.com'),

                    ('DNS', '*.baiducontent.com'),

                    ('DNS', '*.dlnel.com'),

                    ('DNS', '*.dlnel.org'),

                    ('DNS', '*.dueros.baidu.com'),

                    ('DNS', '*.su.baidu.com'),

                    ('DNS', '*.91.com'),

                    ('DNS', '*.hao123.baidu.com'),

                    ('DNS', '*.apollo.auto'),

                    ('DNS', '*.xueshu.baidu.com'),

                    ('DNS', '*.bj.baidubce.com'),

                    ('DNS', '*.gz.baidubce.com'),

                    ('DNS', '*.smartapps.cn'),

                    ('DNS', '*.bdtjrcv.com'),

                    ('DNS', '*.hao222.com'),

                    ('DNS', '*.haokan.com'),

                    ('DNS', '*.pae.baidu.com'),

                    ('DNS', '*.vd.bdstatic.com'),

                    ('DNS', '*.cloud.baidu.com'),

                    ('DNS', 'click.hm.baidu.com'),

                    ('DNS', 'log.hm.baidu.com'),

                    ('DNS', 'cm.pos.baidu.com'),

                    ('DNS', 'wn.pos.baidu.com'),

                    ('DNS', 'update.pan.baidu.com')),

 'version': 3}

[{'issuer': ((('organizationalUnitName', 'GlobalSign Root CA - R3'),),

             (('organizationName', 'GlobalSign'),),

             (('commonName', 'GlobalSign'),)),

  'notAfter': 'Mar 18 10:00:00 2029 GMT',

  'notBefore': 'Mar 18 10:00:00 2009 GMT',

  'serialNumber': '04000000000121585308A2',

  'subject': ((('organizationalUnitName', 'GlobalSign Root CA - R3'),),

              (('organizationName', 'GlobalSign'),),

              (('commonName', 'GlobalSign'),)),

  'version': 3}]

(3)/etc/ssl/certs目录放置的是所有的系统CA证书,就类似于上个实验中浏览器中的CA证书一样。

(4)Wireshark截图如下:

TLS握手是在建立了TCP连接之上了。从上图中可以看到,在程序运行之后先建立了TCP连接,从15-17这三个包是用于建立TCP连接的,而这时候还没有TLS连接。

按一下任意键之后开始建立TLS连接。从第18个包开始建立TLS连接,到第32个包结束。

综上综述,通过执行以上操作,我们完成了TLS handshake任务

3.2 Task 1.b: CA’s Certifificate

这个实验我们建立自己的CA证书文件夹,来代替上面的/etc/ssl/certs文件夹。将handshake.py中的

  1. cadir修改一下,如下所示:

由之前的图可知:

CA证书是:GlobalSign_Root_CA.pem

然后在/etc/ssl/certs目录中找到对应的CA文件:

把GlobalSign_Root_CA.pem文件拷贝到clien-certs目录下:

后使用如下命令获取一个hash值,并创建一个名为该hash值的软链接。

openssl x509 -in GlobalSign_Root_CA.pem -noout -subject_hash

执行得到如下图结果:

最后再回到volumes目录中执行handshake.py www.baidu.com即可看到结果:

然后在对另外两个不同的

网址执行上述指令,不再赘述过程,直接上图:

第一个:www.seu.edu.cn

第二个网站

:www.nju.edu.cn(进行操作时发现二者是相同的根CA,前面的就不再赘述,直接开始后面的)

综上所述,通过执行以上操作,我们完成了CA’s Certificate任务。

Task 1C: Expirement with the hostname check

在宿主机/docker 1.1.1.1上执行以下命令:

在VM主机上执行dig命令获取www.baidu.com的IP地址,如下所示:

修改一下/etc/hosts内容,

将handshake.py中的context.check_hostname选项分别设置为False和True,然后运行handshake.py www.namedn2022.com命令,然后查看结果:

False(不进行主机校验):

运行结果,可以正常访问。

设置为True(进行主机检验):

执行得到如下图结果:

无法正常访问。

针对实验手册中提出的问题,我们回答如下:

针对两次结果的不同,我们得出结论:

如果不进行主机名检验,那么攻击者可以通过用其他网站的合法证书来冒充自己伪造网站的合法证书,发回给用户进行验证,由于没有主机名校验,用户无法察觉,达到欺骗用户的目的。

综上综述,通过执行以上操作,我们完成了Expirement with the hostname check任务

Task 1D: Sending and getting Data

修改一下配置文件handshake.py内容:

执行handshake.py www.baidu.com得到如下图结果:

从这里往后是多出来的内容:

在经过老师的点拨后,

得知在代码段Get后加入具体的URL即可,正确读出二进制图片信息:

综上所述,通过执行以上操作,我们完成了Sending and getting Data任务

2.Task2: TLS Server

Task2a: Implement a simple TLS server

  1. 首先我们的域名是www.name2022.com(就是之前在PKI里的那个网址),这个域名对应的服务会在Server容器也就是地址10.9.0.43中开启,所以需要将DNS记录添加到hosts文件中。
  2. 按照PKI实验的步骤创建CA证书即ca.crt和ca.key,然后为自己的域名创建对应的server.key和server.crt。
  3. 我是直接使用PKI实验中的ca.crt和ca.key;以及server.key和server.crt。所以所以使用指令cp即可。    将server.key和server.crt复制到server-certs文件夹中。Server.py中的server.key和server.crt位置和名称也要修改和自己生成的证书的名称和位置相同:注意:Server.py默认端口是4433,需要改成443。
  4. 3.在server容器启动服务,并且运行server.py文件:

  5. 输入密码:dees

    4.将ca.crt放入client-certs中,并使用openssl命令获取hash之后在client-certs中建立软链接。

    然后运行handshake.py文件,这里的handshake.py文件是:./client-certs。在Server容器中也有输出:

  6. 然后将handshake.py中的certs目录修改为/etc/ssl/certs,再次运行测试:
  7.  

  8. 执行得到如下图结果:
  9. 这里成功建立了TCP连接,但是无法建立TLS连接。

    针对实验手册中提出的问题,我们回答如下:

    using the /etc/ssl/certs folder时:

    只能成功建立TCP连接,但是无法建立TLS连接。

    the ./client-certs folder

    成功建立TLS连接。

    原因是我们把证书放在了./client-certs 文件夹下。

    综上综述,通过执行以上操作,我们完成了Implement a simple TLS server任务

    Task2b: Testing the server program using browsers

    在宿主机/docker 1.1.1.1上执行以下命令:

    在浏览器访问HTTPS需要将自己的CA证书加入浏览器的证书列表中,这在PKI实验中做过,所以这里不需要重复了。

    在浏览器访问我的域名:www.name2022.com,结果如下:

  10. 综上综述,通过执行以上操作,我们完成了Testing the server program using browsers任务

    Task 2c: Certificate with multiple names

    该实验是在2b的基础上使多URL映射到同一个站点,这个其实在PKI实验中已经做过,但是当时使用的是命令行的方式添加参数生成CSR,这里是使用配置文件的方式生成CSR文件,除此之外没有其他区别:

  11. 修改一下配置文件内容:
  12. [ req ]  

    prompt = no  

    distinguished_name = req_distinguished_name  

    req_extensions = req_ext  

      

    [ req_distinguished_name ]  

    C = US  

    ST = New York  

    L = Syracuse  

    O = XYZ LTD.  

    CN = www.name2022.com  

      

    [ req_ext ]  

    subjectAltName = @alt_names  

      

    [alt_names]  

    DNS.1 = www.name2022.com  

    DNS.2 = www.name2022A.com  

    DNS.3 = www.name2022B.com  

    2.以配置文件的形式使用openssl req命令生成CSR文件

    openssl req -newkey rsa:2048 -config ./server_openssl.cnf -batch \
    -sha256 -keyout server.key -out server.csr

    3.之后使用openssl ca命令为证书签名:

    openssl ca -md sha256 -days 3650 -config ./myopenssl.cnf -batch \
    -in server.csr -out server.crt \
    -cert ca.crt -keyfile ca.key

  13. 使用新生成的证书开启server服务。
  14. 访问别名:5.要在浏览器访问成功,需要把别名也加入/etc/hosts中,6.浏览器访问别名:

综上综述,通过执行以上操作,我们完成了Certificate with multiple name任务

Task3: A Simple HTTPS Proxy

本实验使用proxy作为中间代理,既做Server又做Client,于真实的Server和Client进行交互。

  1. 首先选择一个网站:www.taobao.com

2.使用CA对该网站签发证书(先CSR 然后是 CRT证书)。然后把证书taobao.key和taobao.crt放在下面的proxy.py同目录下,以便proxy.py使用。

注意,这里我直接使用的是之前签发过的淘宝网站证书,所以把文件复制到相应地方即可。

3.自己构建一个新文件,命名为proxy.py,编写程序为

import threading

import ssl

import socket

cadir = " ./client-certs"

def process_request(ssock_for_browser):

    hostname = "www.taobao.com"

    #Make a connection to the real server

    sock_for_server=socket.create_connection((hostname,443))

    #set up the TLS context

    context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

    context.load_verify_locations(capath=cadir)

    context.check_hostname = True

    print("sock_for_server")

    ssock_for_server = context.wrap_socket(sock_for_server,server_hostname=hostname,do_handshake_on_connect=False)

    ssock_for_server.do_handshake()

    request = ssock_for_browser.recv(2048)

    if request:

        #Forward request to server

        ssock_for_server.sendall(request)

    #Get response from server,and forward it to browser

    response = ssock_for_server.recv(2048)

    while response:

        ssock_for_browser.sendall(response)#Forward to browser

        response = ssock_for_server.recv(2048)

    ssock_for_browser.shutdown(socket.SHUT_RDWR)

    ssock_for_browser.close()

4.在VM虚拟机中修改/etc/hosts,将www.taobao.com的地址映射到10.9.0.143。

5.在Proxy容器中修改/etc/resolv.文件,将nameserver修改为8.8.8.8:

6.在Proxy容器启动proxy.py之前在VM虚拟机的浏览器访问www.taobao.com,执行得到如下图结果:

7.然后在Proxy容器中启动proxy.py:输入指令

:python3 proxy.py:

8.在宿主机容器的火狐浏览器中输入:https://www.taobao.com

查看proxy中是否有输出,有输出就表示经过了proxy程序。

可以看出是没有问题的。

9.延伸(密码抓取)

这时候可以自己抓包对输入密码的包进行过滤,然后找到包含密码的包。之后在网上查找如何对加密的数据进行解密(已经有私钥了)。这样就可以做到使用proxy程序抓取密码的目的:

综上所述,通过执行以上操作,我们完成了A Simple HTTPS Proxy任务,

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com