安云网 - AnYun.ORG | 专注于网络信息收集、网络数据分享、网络安全研究、网络各种猎奇八卦。
当前位置: 安云网 > 技术关注 > 编程茶楼 > Python > python对SSL(V1,V2,V3)的支持-https

python对SSL(V1,V2,V3)的支持-https

时间:2016-11-21来源:安云网 作者:anyun点击:
通过 curl -1(2,3) url 检测对应哪个ssl版本 V1 #customHTTPSopener,bannersoracle10gserversupportsSSLv3onlyimporthttplib,ssl,urllib2,socketclassHTTPSConnectionV3(httplib.HTTPSConnection):def__init__(self,*args,**kwargs):httplib.HTTPSConnection.__init__(self,*args,**kwa

通过 curl -1(2,3) url  检测对应哪个ssl版本

//内容来自AnYun.ORG


//安云网咨询系统

V1  //内容来自AnYun.ORG

#custom HTTPS opener, banner's oracle 10g server supports SSLv3 only
import httplib, ssl, urllib2, socket
class HTTPSConnectionV3(httplib.HTTPSConnection):
    def __init__(self,*args,**kwargs):
        httplib.HTTPSConnection.__init__(self,*args,**kwargs)
         
    def connect(self):
        sock= socket.create_connection((self.host,self.port),self.timeout)
        if self._tunnel_host:
            self.sock= sock
            self._tunnel()
        try:
            self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1)
        except ssl.SSLError, e:
            print("Trying SSLv3.")
            self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1)
             
class HTTPSHandlerV3(urllib2.HTTPSHandler):
    def https_open(self, req):
        return self.do_open(HTTPSConnectionV3, req)
# install opener
urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3()))
 
if __name__== "__main__":
    r= urllib2.urlopen("https://www.t00ls.net")
    print(r.read()) //内容来自安云网 


//copyright AnYun.ORG


//内容来自安云网

V3 //ANYUN.ORG

#custom HTTPS opener, banner's oracle 10g server supports SSLv3 only
import httplib, ssl, urllib2, socket
class HTTPSConnectionV3(httplib.HTTPSConnection):
    def __init__(self,*args,**kwargs):
        httplib.HTTPSConnection.__init__(self,*args,**kwargs)
         
    def connect(self):
        sock= socket.create_connection((self.host,self.port),self.timeout)
        if self._tunnel_host:
            self.sock= sock
            self._tunnel()
        try:
            self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_SSLv3)
        except ssl.SSLError, e:
            print("Trying SSLv3.")
            self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_SSLv23)
             
class HTTPSHandlerV3(urllib2.HTTPSHandler):
    def https_open(self, req):
        return self.do_open(HTTPSConnectionV3, req)
# install opener
urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3()))
 
if __name__== "__main__":
    r= urllib2.urlopen("https://baidu.com")
    print(r.read()) //ANYUN.ORG 


//安云网,anyun.org

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
相关内容
推荐内容