【信息收集】https证书查询 与 查询结果前端格式化输出的python实现(十三)

一、https运作流程

一个https协议实际是由两次http协议传输完成,分为八步

第一个HTTP请求:
1.客户端发出https请求,连接443端口
2.服务器准备好自己的私钥公钥证书
3.服务器将自己的公钥证书发给客户端
4.客户端验证证书是否来自服务器,并产生随机的会话密钥,然后使用服务器的公钥加密

第二个HTTP请求:
5.客户端会话密钥的密文发给服务器
6.服务器使用自己的私钥解密,得到会话密钥,并使用会话密钥对需要传输的数据加密
7.服务器将数据的密文发给客户端
8.客户端使用会话密钥解密,得到数据

HTTPS在传输的过程中会涉及到三个密钥:

S or C 产生的秘钥类型 产生意义
服务器 公钥和私钥 非对称加密
客户端 会话密钥 对称加密

在这里插入图片描述

二、https证书查询的 python-django 代码实现

后端views.py:

def https(request):
    domain = request.POST['url']

    try:
        # https://crt.sh/?q=baidu.com
        results = requests.get('https://crt.sh/?q=' + domain, headers=get_ua(),verify=False)
        print(results.text)
        soup = BeautifulSoup(results.content, 'html.parser')

        wsd = soup.get_text()
        comp = re.compile(
            r'a:link, a:visited {.*? }|a:hover {.*?}|white-space: .*?;|font-family:.*?;|function\s+s|window.location.href\s+=\s+".*?"|return\s+false;| var _sedoq\s+=\s+_sedoq|_sedoq.partnerid\s+=\s+''316085'';| _sedoq.locale\s+=\s+''zh-cn'';|var\s+s\s+=\s+document.createElement|s.type\s+=\s+''text/javascript'';|s.async\s+=\s+true;|s.src\s+=\s+''.*?'';|var\s+f\s+=\s+document.getElementsByTagName|f.parentNode.insertBefore|/.*?/|pre\s+{|word-wrap:\s+break-word;|}|\s*\(str1\){|\s+\+\s+str1;|\s+\|\s+\|\|\s+{;|\s+\|\|\s+{;|_sedoq.partnerid|\s+=|''316085''|\s+'';|\s+enter\s+your\s+partner\s+id|_sedoq.locale\s+=\s+|zh-cn|language\s+locale|\(function\(\)\s+{|\[0\];|s.type|text/javascript|script|s,\s+f|document.getElementById\(.*?\)|.style.marginLeft|=window|\|\||\s+{|;|en-us,|en-uk,|de-de,|es-er-fr,|pt-br,|\s+.innerWidth2|es-|er-|fr|.innerWidth2|er|-,')
        tih = re.sub(comp, '', wsd)
        tih_list = tih.split('\n')
        tih_list = tih_list[46:-12]
        # print(tih_list)

        res1_list = []
        number = 0
        for i in tih_list:
            if i != "":
                res1_list.append(i)

        step = 7
        res2_list = [res1_list[i:i + step] for i in range(0, len(res1_list), step)]
        for i in res2_list:
            number +=1
        number_list = list(range(1, number + 1))

        dict_res = dict(zip(number_list, res2_list))
        print('dict:-----', dict_res)
		return render(request, 'detection/https.html', {
    
    'status': "yes", 'url': domain, 'res_list': dict_res})

    except Exception as e:
        print(e)
        return render(request, 'detection/https.html', {
    
    'status': "no", 'url': domain})

后端返回结果:
在这里插入图片描述
前端template.html代码:

<table class="table">
                    <tr>
                        <th>序号</th>
                        <th>证书编号</th>
                        <th>记入时间</th>
                        <th>创建时间</th>
                        <th>最后修改时间</th>
                        <th>通用名称</th>
                        <th>匹配身份</th>
                        <th>发行名称</th>
                    </tr>
                    {% for key,value in res_list.items %}
                        <tr>
                            <td>{
   
   { key }}</td>
                            <td>{
   
   { value.0 }}</td>
                            <td>{
   
   { value.1 }}</td>
                            <td>{
   
   { value.2 }}</td>
                            <td>{
   
   { value.3 }}</td>
                            <td>{
   
   { value.4 }}</td>
                            <td>{
   
   { value.5 }}</td>
                            <td>{
   
   { value.6 }}</td>
                        </tr>
                    {% endfor %}

</table>

前端展示:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_45859826/article/details/124258783