2016-10-15 75 views
2

我想找出一个目标支持的协议,但问题是他们是相当多的网站不支持特定的版本,但是当我执行握手它是成功的becz目标超过我给和支持 版本进行握手的版本[事情发生在只有1个网站]在OpenSSL握手后查找SSL版本

例如:我通过一个版本:TLSVersion.TLS_1_2但使用TLSv1_0 becz它不支持TLSVersion.TLS_1_2进行握手

由于上述问题,我想检查握手版本,我不想使用scapy.ssl_tls

version = [SSL.SSLv23_METHOD, 
      SSL.TLSv1_METHOD, 
      SSL.TLSv1_1_METHOD, 
      SSL.TLSv1_2_METHOD] 
context = OpenSSL.SSL.Context(version) 
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
soc.settimeout(CONNECTION_TIMEOUT) 
connection = OpenSSL.SSL.Connection(context,soc) 
connection.connect((host,port)) 
connection.do_handshake() 
#wants to check version here 

回答

1

i want to check the version on handshake

的相关功能检查版本在pyOpenSSL剩余会话的客户端和服务器使用的是get_protocol_version_nameget_protocol_version

connection.do_handshake() 
#wants to check version here 
print(connection.get_protocol_version_name()) 

注意,这些功能仅因为pyOpenSSL 0.16.0

请不要在创建上下文时指定TLS方法列表,但only a single method本质上指定客户端支持的最小TLS版本。因此

context = OpenSSL.SSL.Context(SSL.TLSv1_METHOD) 

允许客户端使用TLS 1.0和更好。如果您使用SSL.TLSv1_2_METHOD,则客户端将被限制为TLS 1.2或更高版本,因此无法与仅支持TLS 1.0的服务器建立SSL连接。

+0

我没有这个功能在我的版本。 --python-openssl已经是最新版本了(0.15.1-2build1) –

+1

@hassan_anwer:引用自己:*“这些函数只有在pyOpenSSL 0.16.0之后才可用”*。而且由于[当前版本是0.16.2](https://pypi.python.org/pypi/pyOpenSSL/16.2.0),您的版本0.15.1显然不是最新版本。它可能是您的系统附带的最新版本,但这是另一回事。 –

+0

@hassan_anwer:如果你的系统没有提供所需的pyOpenSSL版本,而且你不知道如何安装它,你可以安装[anaconda python](https://www.continuum.io/downloads),它包括pyOpenSSL 0.16 。这可以与你现有的python分开安装。 –

1

Find SSL Version after Handshake in OpenSSL...

如果我解析你想要什么正确......你想要的协议版本类似印刷的openssl s_client

$ openssl version 
OpenSSL 1.1.0b 26 Sep 2016 

$ openssl s_client -connect www.google.com:443 -servername www.google.com 
CONNECTED(00000005) 
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA 
verify error:num=20:unable to get local issuer certificate 
Server did acknowledge servername extension. 
--- 
... 
--- 
New, TLSv1.2, Cipher is ECDHE-RSA-CHACHA20-POLY1305 
Server public key is 2048 bit 
Secure Renegotiation IS supported 
No ALPN negotiated 
SSL-Session: 
    Protocol : TLSv1.2 
... 

的第一条消息“新,TLSv1.2工作”告诉你密码。也就是当ECDHE-RSA-CHACHA20-POLY1305第一次到达TLS时。在ECDHE-RSA-CHACHA20-POLY1305的情况下,密码套件首次出现在TLS 1.2中。

s_client的源代码位于<openssl src>/apps/s_client.c。负责在OpenSSL的1.0.2中的代码是围绕线2210:

/* line 2210 */ 
c = SSL_get_current_cipher(s); 
BIO_printf(bio, "%s, Cipher is %s\n", 
      SSL_CIPHER_get_version(c), SSL_CIPHER_get_name(c)); 
... 

所述第二消息“协议:TLSv1.2工作”的告诉您密钥交换和随后的密码选择和批量传送过程中使用的协议的版本。

该负责OpenSSL中1.0.2代码是围绕线105 <openssl src>/ssl/ssl_txt.c

/* line 105 */ 
int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) 
{ 
    unsigned int i; 
    const char *s; 

    if (x == NULL) 
     goto err; 
    if (BIO_puts(bp, "SSL-Session:\n") <= 0) 
     goto err; 
    if (x->ssl_version == SSL2_VERSION) 
     s = "SSLv2"; 
    else if (x->ssl_version == SSL3_VERSION) 
     s = "SSLv3"; 
    else if (x->ssl_version == TLS1_2_VERSION) 
     s = "TLSv1.2"; 
    else if (x->ssl_version == TLS1_1_VERSION) 
     s = "TLSv1.1"; 
    else if (x->ssl_version == TLS1_VERSION) 
     s = "TLSv1"; 
    else if (x->ssl_version == DTLS1_VERSION) 
     s = "DTLSv1"; 
    else if (x->ssl_version == DTLS1_2_VERSION) 
     s = "DTLSv1.2"; 
    else if (x->ssl_version == DTLS1_BAD_VER) 
     s = "DTLSv1-bad"; 
    else 
     s = "unknown"; 
    if (BIO_printf(bp, " Protocol : %s\n", s) <= 0) 
     goto err; 

    ... 
} 

I want to find out the protocols supported by a target but the problem is that their are quite a number websites which are not supporting a particular version but when i performed handshake ...

这是一个不同的问题。您应该查看sslscan的源代码SSLScan - Fast SSL Scanner以了解它的工作原理。 Sourceforge似乎被放弃了。它缺乏SNI和其他新功能,如安全协商和ALPN。

你可以试试这个sslscan from GitHub:rbsec/sslscan。 GitHub一个被积极维护,似乎更新。


example : i passed a version :TLSVersion.TLS_1_2 but the handshake is performed using TLSv1_0 becz it is not supporting TLSVersion.TLS_1_2

这不会发生。 TLS仅指定一个协议版本。这个想法是你的尝试TLS 1.2。如果失败了,那么你会回到TLS 1.1。如果失败了,那么你会回到TLS 1.0。 Ad infinitum

尝试后备方法是RFC 7504, TLS Fallback Signaling Cipher Suite Value (SCSV) for Preventing Protocol Downgrade Attacks的原因。这是来自浏览者群体的可怕的乐队助手。例如参见Last Call: (TLS Fallback Signaling Cipher Suite Value (SCSV) for Preventing Protocol Downgrade Attacks) to Proposed Standard

TLS确实接受了一系列协议版本像很多人认为。我们试图改变它几次。例如参见A new TLS version negotiation mechanism