|NO.Z.00024|——————————|^^ 部署 ^^|——|Linux&VSFTP服务.V06|——|VSFTP部署|加密验证|openssl+vsftpd|

一、openssl+vsftpd加密验证方式
### --- openssl+vsftpd加密验证方式
### --- 在明文传输时抓取数据包查看账户名及密码
~~~     拓展:使用tcpdump工具进行指定端口抓包,抓取ftp登录中的数据包

tcpdump -i eth0 -nn -X -vv tcp port 21 and  ip host 来源ip
-i                                                          // interface:指定tcpdump需要监听的接口
-n                                                          // 对地址以数字方式显示,否则显示为主机名
-nn                                                         // 除了-n的作用外,还把端口显示为数值,否则显示端口服务名
-X                                                          // 输出包的头部文件,会以16进制的ASCII两种方式同时输出。
-xx                                                         // 产生更详细的输出
and                                                         // 连接的形式
来源IP                                                      // 客户端的地址
port21                                                      // 服务器的端口
### --- 查看服务是否正常启动

[root@server21 ~]# netstat -antp
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      1671/vsftpd 
~~~     客户端没有加密是所抓取到的账户密码信息;ftp默认以明文的方式进行传输。
~~~     用windows的客户端工具连接服务器
~~~     主机:20.20.20.21  用户名:ftp 密码:空格,端口21      连接:会有提示:该服务器不支持FTP over TLS,如果继续,您的密码和文件将会通过互联网明文传输。

[root@server21 ~]# tcpdump -i eth1 -nn -X -vv tcp port 21 and  ip host 20.20.20.240             //本地客户端地址
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
10:55:24.560937 IP (tos 0x0, ttl 64, id 2552, offset 0, flags [DF], proto TCP (6), length 78)
    20.20.20.21.21 > 20.20.20.240.58560: Flags [P.], cksum 0x516d (incorrect -> 0xffd4), seq 21:59, ack 11, win 115, length 38
    0x0000:  4500 004e 09f8 4000 4006 df85 1414 1415  E..N..@.@.......
    0x0010:  1414 14f0 0015 e4c0 9edb 1d23 d122 871f  ...........#."..
    0x0020:  5018 0073 516d 0000 3533 3020 506c 6561  P..sQm..530.Plea  // 抓取的登录信息
    0x0030:  7365 206c 6f67 696e 2077 6974 6820 5553  se.login.with.US
    0x0040:  4552 2061 6e64 2050 4153 532e 0d0a       ER.and.PASS...                
10:55:27.143705 IP (tos 0x0, ttl 128, id 50613, offset 0, flags [DF], proto TCP (6), length 50)
    20.20.20.240.58560 > 20.20.20.21.21: Flags [P.], cksum 0x189a (correct), seq 21:31, ack 97, win 4105, length 10
    0x0000:  4500 0032 c5b5 4000 8006 e3e3 1414 14f0  E..2..@.........
    0x0010:  1414 1415 e4c0 0015 d122 8729 9edb 1d6f  .........".)...o
    0x0020:  5018 1009 189a 0000 5553 4552 2066 7470  P.......USER.ftp  // use表示客户端登录的账户名是ftp
10:55:27.146204 IP (tos 0x0, ttl 128, id 50614, offset 0, flags [DF], proto TCP (6), length 48)
    20.20.20.240.58560 > 20.20.20.21.21: Flags [P.], cksum 0x8437 (correct), seq 31:39, ack 131, win 4105, length 8
    0x0000:  4500 0030 c5b6 4000 8006 e3e4 1414 14f0  E..0..@.........
    0x0010:  1414 1415 e4c0 0015 d122 8733 9edb 1d91  .........".3....
    0x0020:  5018 1009 8437 0000 5041 5353 2020 0d0a  P....7..PASS....  // PASS,因为我设置的密码是空格,所以会这样显示,常规会把你键入的密码完整的显示在上面   
二、openssl+vsftpd加密验证方式部署
### --- 准备环境:

centos6.x——serve21:20.20.20.21      VSFTP server
centos6.x——serve22:20.20.20.22      VSFTP CA
centos6.x——serve23:20.20.20.23      VSFTP Client
### --- 查看是否安装了openssl

[root@server21 ~]# rpm -q openssl
openssl-1.0.1e-48.el6.x86_64
### --- 查看vsftpd是否支持openssl

[root@server21 ~]# which vsftpd
/usr/sbin/vsftpd
[root@server21 ~]# ldd /usr/sbin/vsftpd |grep libssl            // 验证vsftpd执行时是否调用libbssl
    libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f92fc52f000)// 表示vsftpd程序支持ssl
### --- 生成加密信息的秘钥和证书文件位置

[root@server21 ~]# cd /etc/ssl/certs/
[root@server21 certs]# openssl genrsa -out vsftpd.key 1024      // 建立服务器私钥,生成RSA秘钥
Generating RSA private key, 1024 bit long modulus
.............++++++
............++++++
e is 65537 (0x10001)
[root@server21 certs]# ls vsftpd.key 
vsftpd.key
~~~     通过vsftpd.key文件生成证书文件,需要以此输入国家,地区,城市,组织,组织单位,Email等信息,最重要的是有一个common name可以写你的名字或者域名,如果为了https申请,这个必须和域名吻合,否则会引发浏览器警报,生成的csr文件交给CA签名后形成服务端自己的证书

[root@server21 certs]# openssl req  -new -key vsftpd.key -out vsftpd.csr
Country Name (2 letter code) [XX]:CN                            // 国家
State or Province Name (full name) []:BJ                        // 地区
Locality Name (eg, city) [Default City]:BJ                      // 城市
Organization Name (eg, company) [Default Company Ltd]:atyanqi   // 组织和组织单位,写错了退格键是删不了的,需要Ctrl+退格键删
Organizational Unit Name (eg, section) []:yjs                   // 部门
Common Name (eg, your name or your server's hostname) []:www.atyanqi.com // 主机名
Email Address []:yanqi_vip@yeah.net                             // Email,可以不写
A challenge password []:                                        // 设置一个密码,不设置可以直接跳过;不对证书加密,若是设置加密,一旦调用,必须使用证书解密。
An optional company name []:    
~~~     通过证书文件办法签字后的证书。
~~~     使用CA服务器签发证书,设置证书的有效期等信息
~~~     注意1:生成秘钥和证书文件后,将本目录/etc/ssl/certs/的权限修改为500.
~~~     注意2:在实验环境中可以用命令生成测试,在生产环境中必须要在hosts证书厂商注册(否则浏览器不识别)

[root@server21 certs]# openssl x509 -req -days 365 -sha256 -in vsftpd.csr -signkey vsftpd.key -out vsftpd.crt       // openssl x509:颁发固定格式 -req -days 365:证书的时效为一年-sha256:机密类型及长度 -in vsftpd.csr:指使用的证书 -signkey vsftpd.key:使用的哪一个秘钥文件 -out vsftpd.crt:产生签字后的证书
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=atyanqi/OU=yjs/CN=www.atyanqi.com
Getting Private key
[root@server21 certs]# ls -l vsftpd.*
-rw-r--r-- 1 root root 830 Feb  4 11:29 vsftpd.crt              // 签字证书文件
-rw-r--r-- 1 root root 643 Feb  4 11:22 vsftpd.csr              // 证书文件
-rw-r--r-- 1 root root 887 Feb  4 11:15 vsftpd.key              // 秘钥文件
[root@server21 certs]# chmod 500 .                              // 当前目录必须设置为500权限
[root@server21 certs]# ls -ld           
dr-x------. 2 root root 4096 Feb  4 11:29 .                     // 500只能进入目录,及读取权限,不能新建文件及删除文件,没有w目录,就不可以创建及删除
### --- 修改注配置文件/etc/vsftpd/vsftpd.conf
~~~     注:秘钥文件要在配置文件中单独声明(写入配置文件时,在文末添加,注释要单独一行,
~~~     否则会报警)注意结尾不要有空格

[root@server21 ~]# vim /etc/vsftpd/vsftpd.conf
ssl_enable=YES
#启用ssl认证
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
#开启tlsv1.sslv2.sslv3都支持
allow_anon_ssl=YES
#允许匿名用户{虚拟用户}
force_anon_logins_ssl=YES                                       // 强制要求匿名及虚拟用户登录时必须使用ssl
force_anon_data_ssl=YES                                         // 匿名登录和传输时强制使用ssl
#匿名登录和传输时强制使用ssl
force_local_logins_ssl=YES
force_local_data_ssl=YES
#本地登录和传输时强制使用ssl
rsa_cert_file=/etc/ssl/certs/vsftpd.crt
#rsa格式的证书
rsa_private_key_file=/etc/ssl/certs/vsftpd.key
#rsa格式的秘钥 
### --- 重启服务:

[root@server21 vsftpd]# service vsftpd restart
### --- 测试(使用第三方客户端连接)

[root@server21 ~]# !tcpdump                                     // 执行上一次的抓包命令规则
[root@server21 ~]#  tcpdump -i eth1 -nn -X -vv tcp port 21 and  ip host 20.20.20.240 
 
~~~     FileZilla-FTP(第三方客户端工具)
~~~     文件——>我的站点——>新站点——>协议:FTP-文件传输协议——>主机:20.20.20.21端口:21——>加密:要求显示的FTP over TLS——>登录方式:正常——>用户名:ftp,密码:空格——>连接
~~~     会弹出一个认证信息:证书为未知,说明加密生成OK
~~~     user/PASSWD相关字段的信息不会再出现,而CN字段会出现,说明登录开始是以加密的方式连接交互。
~~~     连接测试时选择:
~~~     服务器类型:
~~~     服务器类型:显示TLS/SSL
~~~     登录类型:一般或匿名

[root@server21 ~]#  tcpdump -i eth1 -nn -X -vv tcp port 21 and  ip host 20.20.20.240        //获取抓包信息
12:46:11.854539 IP (tos 0x0, ttl 64, id 49644, offset 0, flags [DF], proto TCP (6), length 921)
    20.20.20.21.21 > 20.20.20.240.59631: Flags [P.], cksum 0x54b8 (incorrect -> 0xacde), seq 52:933, ack 380, win 123, length 881
    0x0120:  310b 3009 0603 5504 0613 0243 4e31 0b30  1.0...U....CN1.0
三、以加密的形式登录


 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(293)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示