SSL connection fails with wget, curl, but succeed with firefox and lynx

霸气de小男生 提交于 2019-12-24 04:41:12

问题


I'm having trouble accessing this website by automated script: https://mydtac.dtac.co.th/EserviceLogin/Login?page=N&lang=en

If i view from a browser (chrome, firefox, even lynx is working), it's all ok. I if try to load it from PHP (fsockopen), wget, or curl, it's complaining:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac in

Also the openssl check fails:

openssl s_client -connect mydtac.dtac.co.th:443 3074164412:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:787:

I've tried on different systems (debian), both stable and testing release, and the problem is present everywhere with wget.

I've done a TCP dump on the connection, and it seems the way is different how the working and the failing methods are trying to initialize the ssl connection:

Failing request and response:

T 192.168.1.42:60748 -> 202.91.21.208:443 [AP] ....,...(..j...3O.....N[U.iv.).5'...P..2.......0.,.(.$.........k.j.9.8.....2...*.&.......=.5.../.+.'.#.........g.@.3.2.....E.D.1.-.).%...... .<./...A...............................................m...........4.2...................................................#..... ............ .........................
# T 202.91.21.208:443 -> 192.168.1.42:60748 [AP] ......(

Working request and response:

T 192.168.1.42:60751 -> 202.91.21.208:443 [AP] .................2...axg....;..|vYV....oS#..WD=u.zp..R./w...................3.2.E.9.8...../.A.5...........B.........mydtac.dtac.co.th...... ..................#..3t...........
# T 202.91.21.208:443 -> 192.168.1.42:60751 [AP] ....:...6..T ..(..ok.q
..A....F?....k.>V....U..T.......^x.c...................0...0...............a..L.Gd....0....H........0f1.0...U....US1 .0...U....DigiCert Inc1.0...U....www.digicert.com1%0#..U....DigiCert High Assurance CA-30...120912000000Z..150917120000Z0..1.0...U....TH1.0. ..U....Bangkok1.0...U....Pathumwan1(0&..U....DTAC Internet Service Co., Ltd.1#0!..U....Enterprise Service Support1.0...U.....dtac.co.th0.." 0...*.H.............0.........sa.9.w..3.@I.K.....|...F...LgP.{J....b+.....:....".._.b.{c.....h...n.2.J...h..|lJ.=..^..i@6..^.Fgg.!s....U|..' ...w@.RU.>.... 3=cc.W......0U.......Jvlr....J.hb...p.+...d.}..A.. .;R..U.HN.\.#r%.%..F..X..;..Y&.......y....IUy>.....NU.-..$..i..I.P....... ...\c........N0..J0...U.#..0...P.s..)...... ..y.H..0...U.......-f.....U.Y.9;.....T0#..U....0...*.dtac.co.th..dtac.co.th0...U...........0...U .%..0...+.........+.......0a..U...Z0X0*.(.&.$http://crl3.digicert.com/ca3-g22.crl0*.(.&.$http://crl4.digicert.com/ca3-g22.crl0.....U. ....0. ..0......H...l..0...0:..+.........http://www.digicert.com/ssl-cps-repository.htm0..d..+.......0..V...R.A.n.y. .u.s.e. .o.f. .t.h.i.s. .C.e. r.t.i.f.i.c.a.t.e. .c.o.n.s.t.i.t.u.t.e.s. .a.c.c.e.p.t.a.n.c.e. .o.f. .t.h.e. .D.i.g.i.C.e.r.t. .C.P./.C.P.S. .a.n.d. .t.h.e. .R.e.l.y.i.n. g. .P.a.r.t.y. .A.g.r.e.e.m.e.n.t. .w.h.i.c.h. .l.i.m.i.t. .l.i.a.b.i.l.i.t.y. .a.n.d. .a.r.e. .i.n.c.o.r.p.o.r.a.t.e.d. .h.e.r.e.i.n. .b.y. .r.e.f.e.r.e.n.c.e..0{..+........o0m0$..+.....0

I'm trying to find a workaround this for 2 days but got stuck here. Any suggestions would be highly appreciated.

I know this is something which the webmaster should investigate, but that's not an option, as 99% of the people does not have any problem accessing these pages, they will do nothing for sure ...

|improve this question

回答1:


openssl s_client -connect mydtac.dtac.co.th:443 3074164412:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:787:

You need to use SSLv3 or TLS 1.0. You can't send a ClientHello with TLS 1.1 or 1.2.

First, TLS 1.0 (don't worry about the self-signed certificate warning - I'm not using the CAfile option):

$ /usr/local/ssl/darwin/bin/openssl s_client -tls1 -connect mydtac.dtac.co.th:443
CONNECTED(00000003)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert High Assurance EV Root CA
verify error:num=19:self signed certificate in certificate chain
verify return:0
---
Certificate chain
 0 s:/C=TH/ST=Bangkok/L=Pathumwan/O=DTAC Internet Service Co., Ltd./OU=Enterprise Service Support/CN=*.dtac.co.th
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3
 1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
 2 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
   i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
...

Next, TLS 1.2:

$ /usr/local/ssl/darwin/bin/openssl s_client -tls1_2 -connect mydtac.dtac.co.th:443
CONNECTED(00000003)
140735152734684:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:337:
...

Related, that server is down level and poorly configured. You should avoid it if possible:

$ openssl s_client -ssl3 -connect mydtac.dtac.co.th:443
CONNECTED(00000003)
...
New, TLSv1/SSLv3, Cipher is RC4-MD5
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : SSLv3
    Cipher    : RC4-MD5
    Session-ID: 1C04C221FDD0501832FFD8904790A34

Judging from the SSL scan, I'd speculate its an older IIS server:

$ sslscan --no-failed mydtac.dtac.co.th
                   _
           ___ ___| |___  ___ __ _ _ __
          / __/ __| / __|/ __/ _` | '_ \
          \__ \__ \ \__ \ (_| (_| | | | |
          |___/___/_|___/\___\__,_|_| |_|

                  Version 1.8.2
             http://www.titania.co.uk
        Copyright Ian Ventura-Whiting 2009

Testing SSL server mydtac.dtac.co.th on port 443

  Supported Server Cipher(s):
    Accepted  SSLv3  128 bits  ADH-RC4-MD5
    Accepted  SSLv3  128 bits  RC4-SHA
    Accepted  SSLv3  128 bits  RC4-MD5
    Accepted  SSLv3  40 bits   EXP-ADH-RC4-MD5
    Accepted  SSLv3  40 bits   EXP-RC4-MD5
    Accepted  TLSv1  256 bits  AES256-SHA
    Accepted  TLSv1  128 bits  AES128-SHA
    Accepted  TLSv1  128 bits  ADH-RC4-MD5
    Accepted  TLSv1  128 bits  RC4-SHA
    Accepted  TLSv1  128 bits  RC4-MD5
    Accepted  TLSv1  112 bits  EDH-RSA-DES-CBC3-SHA
    Accepted  TLSv1  112 bits  ADH-DES-CBC3-SHA
    Accepted  TLSv1  112 bits  DES-CBC3-SHA
    Accepted  TLSv1  56 bits   EDH-RSA-DES-CBC-SHA
    Accepted  TLSv1  56 bits   ADH-DES-CBC-SHA
    Accepted  TLSv1  56 bits   DES-CBC-SHA
    Accepted  TLSv1  40 bits   EXP-EDH-RSA-DES-CBC-SHA
    Accepted  TLSv1  40 bits   EXP-ADH-DES-CBC-SHA
    Accepted  TLSv1  40 bits   EXP-DES-CBC-SHA
    Accepted  TLSv1  40 bits   EXP-ADH-RC4-MD5
    Accepted  TLSv1  40 bits   EXP-RC4-MD5

  Prefered Server Cipher(s):
    SSLv3  128 bits  RC4-MD5
    TLSv1  128 bits  RC4-MD5


来源:https://stackoverflow.com/questions/25986195/ssl-connection-fails-with-wget-curl-but-succeed-with-firefox-and-lynx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!