openssl telnet openssh

Network Security Introduction
  Background:
    The early Internet - 1980s, we need to share data, transmission of data; data transmitted or shared by both the plaintext;
    With the development of the Internet, known as a safe country's strategic resources;
    we do such as programming, operation and maintenance - handicraft;
    security is a form of scientific research - secure algorithms are required to mathematical problems as a basis for the study;
    each country crazy to study their own encryption algorithm, and others to decipher the encryption algorithm; the United States - banned the export of longer than 256-bit encryption algorithm;

To ensure data security, we must meet at four points: 1, the data must be encrypted; 2, integrity check (hash, one-way encryption, fingerprint); 3, source authentication; 4, the certificate system (openssl is used PKI certificates to achieve this architecture, it contains a tricycle;)

1, data encrypted
  data must be encrypted
  a symmetric secret key encrypted
    with a secret key for encryption and decryption with a secret key;
    advantages: High efficiency
    disadvantages: keys maintenance is very difficult; Key Exchange is very difficult;
  2, asymmetric secret key encrypted
    secret key pair (public, private)
    a - B
    a a private key public key
    B may be encrypted with the data by using the public key a, and then transferred to a;
    advantages: easy maintenance keys; data safer;
    disadvantages: inefficient (very low), and symmetric encryption, the gap is about 1000 times;

  Two encryption forms
  1, stream encryption
    01010100100101011100100101001010
    the Cisco 0101
    01010101010101010101010101010101
    XOR ------------------------------------ -------
    00000 ... (the same is different from 0 to 1)

    Confidential
    00000 ...
    the Cisco 0101
    01010101010101010101010101010101
    XOR ---------------------------------------- ----
    01010100100101011100100101001010

    1101 0010
    1111 1111
    ----- -----
    0010 1101

  2, a block encryption
    0101 0100 1001 0101 1001 0100 1010 1100 is
    Vl value / | / | ... ... ... ...
    0000 | / |
  ---------------- ------------------------------------------------
    01,010,001

2、完整性校验 -- 指纹
  测试数据的完整性,保证数据没有被篡改;
  原理:获取B机器对数据的hash值,A机器对获取的数据再进行一次hash;拿A自己hash的结果,与获取到的B机器的hash结果进行比较;
  如果相同,则说明数据完整;否则,数据不可信任;

  hash特点:
    1、不可逆性 -- 单向加密
    2、雪崩效应 -- 修改一个字符,输出的结果完全不同

  MAC 信息认证代码
    随机生成密钥对 ,再将密钥对加上数据报文一起做HASH -- HMAC
    这种方式即完成了原认证同时也完成完整性校验;

3、源认证
  非对称秘钥的另外一个作用:
    数字签名 (数据加密(太慢,不使用)、秘钥交换)
    在做秘钥交换的时候,我们是用了 -- 公钥机密私钥解密
    数字签名 私钥加密 -- 公钥解密
      只有自己拥有自己的私钥,用自己的私钥对数据进行加密;
      对端,使用自己的公钥进行解密,如果能解密说明数据源是正确的;否则,不可信任;

*4、证书机制 -- PKI(Openssl)*
  我们通过PKI(公共秘钥基础设施)架构,来实现上面提到的三点认证机制;
  PKI包括:
    CA -- 证书服务器 CA服务器,用来做证书签发;
    RA -- 搭建CA的机构,注册证书的机构;
    CRL -- 整数吊销列表;

  PKI证书体系架构原理(见图)

  openssl
    openssl 管理工具
    两个加密程序调用接口--库文件

    了解------------------------------------------
    dh -- 非对称秘钥算法(工作:完成秘钥交换)
      A     -- B
      A -- >   x
          p^x%g = X
          p^x%g^y = p^xy%g 这个结果两个相同,就能获取一个相同的数;这个就是相同的结果
      B -->   y
          p^y%g = Y
          p^x%g^y = p^xy%g
---------------------------------------------

    常见文件:
      /etc/pki/tls
        扩展 -- 1995年 由网景公司开发 ssh 2.0
            1996年      ssh 3.0 //普遍使用
            1999年 网景公司已经快挂了,自然没有能力去维护ssh -- > 把ssh交给了一个公有组织维护 tls 协议 1.0
            2006年  开发了 tls 1.1
            2008年  开发了tls 1.2 //是当前互联网环境下普遍使用的ssh/tls协议
            2018年  开发了tls 1.3
      /etc/pki/tls/openssl.cnf -- 默认主配置文件
      /usr/bin/openssl -- 命令文件
      /etc/pki/CA -- 证书服务器的证书服务根目录
      /etc/pki/CA/certs -- 证书存放目录
      /etc/pki/CA/crl --
      /etc/pki/CA/private

      index.txt //证书索引信息文件
      serial //证书序列号
      cakey.pem //ca证书申请文件
      cacert.pem //ca根证书文件

      ssl、tls协议的连接过程;
      以https为例
        http -- > 80
       客户端 -- 服务器端
        tcp三次握手
       http请求 ->
         <- http的响应
        https --> 443
       客户端 -- 服务器端
        tcp三次握手
        ssl 握手

       ssl的握手过程:
        1、建立TCP会话的过程,ssl是需要借助tcp会话的 -- 三次握手的过程
        2、ssl的握手认证
          服务器端发送证书 给客户端
          客户端验证(检查发行者的名称,找到发行者公钥,进行解密,验证发行者)
          检查网站名称,和这个证书名称的名字是否一致,如果不是,则不行;
          检查整数的信息是否完整,通过单向加密,确认证书信息是否完整;
          最后检测这个证书是否已经被吊销;是否处于证书吊销列表中;
        3、客户端生成对称秘钥,并将秘钥交换给对端
          使用对端的公钥加密对称秘钥,发送给对端
          【一般情况下,服务器端是不需要验证客户端整数的】
        4、客户端请求对端url下的资源;
        5、服务器端对客户端请求的资源进行加密
          (保持连接和短连接) 短连接每次连接都会生成新的秘钥;

      实验:如何去使用 openssl 工具搭建 https 访问站点

      openssl的命令使用格式:
        openssl 子命令
        openssl help
        man 子命令 //查看到子命令的帮助信息

        https://www.cnblogs.com/BurnovBlog/p/10990052.html

      openssl
        enc
        version
        rsa
        dsa
        ---
        md5 sha
        ---
        aes
        des
        des3
        rc2-cfb
        rc-cbc

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

Telnet 【缺点:明文,不安全】
  C/S -- S listen:23 -- tcp

  在网络设备上:Telnet默认开开;
    line vty 0 4
      login local
    username passwd
    ---------------------
    line vty 0 4
      logging
      password xxx
    ---------------------
    line vty 0 4
      login authencation aaa
    test aaa 。。。
    用户名密码写在 aaa
    【可以给用户授权】

  服务器设备: -- 不会去建议用Telnet登录服务器(不能用root去登录Telnet)
    Telnet-server
    xinetd

    https://www.cnblogs.com/BurnovBlog/p/10988627.html

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

ssh
  ssh服务端的参数与优化
  C/S 和Telnet一样, -- openssl(软件程序)
    能够进行数据加密(你传输的密码是被加密的)

    ssh协议借助ssl/tls 协议来传输数据,加密数据;
    在传输数据之前,会见
  
  ssh的登录过程:
    1、建立ssl隧道
      传输公钥
      生成并传输随机秘钥信息
      才能建立隧道
      【之后的操作均在隧道中完成】
    2、服务器端返回 登录界面
    3、客户端输入密码 -- 这个密码才是用户密码(root)

  ssh的认证方式:
    1、passwd的密码认证方式
    2、证书认证机制 -- 免秘钥
      ssh-keygen -t rsa -P '' -f '~/.ssh/id_rsa'
      ssh-copy-id [email protected]
      自动将公钥传送到对端的 /root/.ssh 目录 authorized_keys
      到客户端登录服务器端
      ssh [email protected] 'ifconfig'

    scp 推、拉
    sftp

    脚本:通过expect来实现交互界面自动化执行;
      #!/usr/bin/expect
      spawn -- 开启新的expect会话 #!/bin/bash
      send -- 行为
      expect -- 匹配字符串
      interact -- timeout

      expect "*command*" send { "yes" }

      expect执行多个语句判断的时候,使用 exp_continue;

      对 192.168.1.1 - 192.168.1.100 做无密码登录;

        #!/bin/bash
        ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa' -- 做判断:[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa'

        expect << EOF
          spawn ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
          expect {
          "password" { send "123456\n" }
          }
          interact
        EOF

        ssh [email protected]

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

      #!/bin/bash
      #
      [ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -p '' &> /dev/null
      while read line;do
        ip=`echo $line | cut -d" " -f1`
          user_name=`echo $line | cut -d" " -f2`
        pass_word=`echo $line | cut -d" " -f3 `
      expect << EOF
        spawn ssh-copy-id -i /root/.ssh/idrsa.pub $user_name@$ip
        expect {
          "yes/no" { send "yes\n";exp_continue }
          "password" { send "$pass_word\n" }
          }
        expect eof
      EOF
      done < /root/host_ip.txt

      pscp.pssh -h /root/host_ip.txt /root/your_scripts.sh /root
      pssh -h /root/host_ip.txt -i bash /root/your_scripts.sh


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

  ssh 常用参数:
    port 22022
    AddressFamily any //ipv4或者ipv6
    Listenaddress 0.0.0.0 //所有地址,一般需要修改
    ::: //ipv6的所有地址
    Hostkey //主机密钥
    KeyRegenerationInterval 1h //对称密钥从新生成
    SyslogFacility AUTH //记录日志的方式
    */var/log/secure 下记录的登陆日志信息*
    LoginCraceTime 2m //登陆的宽限时长 2风中
    PermitRootLogin yes //是否容许管理员登陆
    StrictModes yes //是否使用严格检查模式
    MaxAuthTries 6 //最大的尝试次数
    MaxSessions 10 //最大的会话数
    RSAAuthentication yes //RSA认证
    PubkeyAuthentication yes
    PasswordAuthentication yes //是否基于口令认证
    ChallengeResponscAuthentication yes //挑战认证方式
    #Kerberos options //守护认证,第三方统一认证架构服务
    GSSAPI options
    X11 forwarding //开启图形的传输功能
    UseDNS no //关闭DNS的反向解析

Guess you like

Origin www.cnblogs.com/4443056bdH/p/11493889.html