ssl.SSLError:[SSL:WRONG_VERSION_NUMBER]错误的版本号(_ssl.c:661)python2.7

时间:2017-12-05 21:38:09

标签: python bash sockets ssl protocols

我已经尝试了给我的各种数字和选项,甚至进入了bash的协议部分并查看了各种各样的网站,无论我的代码怎么做都无法摆脱那个错误(如上所述)在标题中),这是我的代码和完整的错误消息,希望有人可以指出我正确的方向,我真的很感激。 我试过的版本:

SSLv2,SSLv3,SSLv23[1],TLSv1,TLSv1_1,TLSv1_2 with all proper apache 
configurations, and encryption when making the SSL self-signed cert 

服务器版本:

cert is version 3
cert signature algorithm is PKCS #1 SHA-256 With RSA Encryption

我正在运行的kali linux版本:

4.14.0-kali1-amd64

错误讯息:

anon@kali:~/Desktop/python scripts$ python SSL\ client.py 
Traceback (most recent call last):
File "SSL client.py", line 21, in <module>
ssl_socket = context.wrap_socket(c, server_side=False, 
do_handshake_on_connect=True, suppress_ragged_eofs=True, 
server_hostname='vulnerable')
File "/usr/lib/python2.7/ssl.py", line 363, in wrap_socket
_context=self)
File "/usr/lib/python2.7/ssl.py", line 611, in __init__
self.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 840, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number 
(_ssl.c:661)

我的代码:

import socket
import requests
import ssl

t_host = "vulnerable"
t_port = 443


c = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
c.connect((t_host,t_port))
c.send(b"GET / HTTP/1.1\r\nHost: vulnerable\r\n\r\n")
getRequest = "GET /HTTP/1.1\r\nHost: vulnerable\r\n\r\n"
requests.packages.urllib3.disable_warnings()
r = requests.get('https://vulnerable/',verify=False)

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
context.load_verify_locations(cafile="/etc/ssl/certs/apache-selfsigned.crt")

ssl_socket = context.wrap_socket(c, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True, server_hostname='vulnerable')
ssl_socket.connect(('vulnerable', 443 ))
re = c.recv(4096)
ssl_socket.send(getRequest)
print ssl_socket.recv(1024)
print ssl_socket.recv(1024)
print (re.decode('UTF-8'))
print r.text

我正在寻找成功运行的结果:

HTTP/1.1 200 OK
Date: Wed, 30 Nov 2016 01:02:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Tue, 29 Nov 2016 11:13:07 GMT
ETag: "70-5426eac41e995"
Accept-Ranges: bytes
Content-Length: 112
Vary: Accept-Encoding
Content-Type: text/html

0 个答案:

没有答案