Created
April 15, 2014 21:56
-
-
Save stolen/10780653 to your computer and use it in GitHub Desktop.
escript demonstrating bad negotiation in OTP SSL server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
% This escript sends malformed SSLv3 client_hello to specified server | |
% and prints negotiated version and cipher suite | |
% | |
% Usage example: ./badhello.escript localhost 9998 | |
-module(badhello). | |
-include_lib("ssl/src/ssl_handshake.hrl"). | |
client_hello() -> | |
<<22, 3,0, 49:16, % handshake, SSL 3.0, length | |
1, 45:24, % client_hello, length | |
3,0, % SSL 3.0 | |
16#deadbeef:256, % 32 'random' bytes = 256 bits | |
0, % no session ID | |
6:16, 0,255, 0,61, 0,57, | |
% three cipher suites -- null, one with sha256 hash and one with sha hash | |
1, 0 % no compression | |
>>. | |
main([Host, PortStr]) -> | |
run(Host, list_to_integer(PortStr)). | |
run(Host, Port) -> | |
{ok, S} = gen_tcp:connect(Host, Port, [binary, {active, false}]), | |
ok = gen_tcp:send(S, client_hello()), | |
{ok, <<22, RecMajor:8, RecMinor:8, _RecLen:16, 2, HelloLen:24>>} = gen_tcp:recv(S, 9, 10000), | |
{ok, <<HelloBin:HelloLen/binary>>} = gen_tcp:recv(S, HelloLen, 5000), | |
#server_hello{} = ServerHello = tls_handshake:decode_handshake({RecMajor, RecMinor}, 2, HelloBin), | |
#server_hello{ | |
server_version = ServerVer, | |
cipher_suite = CipherSuite } = ServerHello, | |
io:format("Received server_hello of version ~w with cipher suite ~w~n", [ServerVer, ssl:suite_definition(CipherSuite)]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment