Skip to content

Instantly share code, notes, and snippets.

View stolen's full-sized avatar

Danil Zagoskin stolen

  • Erlyvideo
  • Moscow, Russia
View GitHub Profile
@stolen
stolen / badhello.escript
Created April 15, 2014 21:56
escript demonstrating bad negotiation in OTP SSL server
#!/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() ->
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%% vim: sw=2 ts=2
% This escript sends garbage SSLv3 record between client_hello and any other record
% to specified server causing acceptor to crash with function_clause
%
% Usage example: ./badhandshake.escript localhost 9998
-module(badhandshake).
-include_lib("ssl/src/ssl_handshake.hrl").
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%% vim: sw=2 ts=2
% This escript sends valid TLSv1.2 client_hello to specified server
% crashing the OTP 17.0 acceptor due to bad hashsign default value
%
% Usage example: ./tlsv12_no_hs.escript localhost 9998
-module(tlsv12_no_hs).
-include_lib("ssl/src/ssl_handshake.hrl").
@stolen
stolen / .gitignore
Created February 13, 2012 16:10
Erlang module alias generator
ebin/*.beam
@stolen
stolen / leb128.erl
Created July 20, 2012 22:07
LEB128 erlang implementation
-module(leb128).
-export([encode/2, decode/2]).
encode(Value, signed) ->
encode_ranged(Value, 0, 16#40);
encode(Value, unsigned) when Value >= 0 ->
encode_ranged(Value, 0, 16#80).
@stolen
stolen / gs_up.erl
Created September 27, 2012 09:33
gen_server with self-upgrading state prototype
-module(gs_up).
-export([init/1, handle_call/3, terminate/2]).
-record(state, {
own_fields,
field1,
field2,
field3
}).
@stolen
stolen / bubble.erl
Last active December 14, 2015 03:28
Recursive bubble sort in Erlang (just for fun)
-module(bubble).
-export([sort/1, sort/2]).
sort(List) ->
sort(fun erlang:'=<'/2, List, []).
sort(Compare, List) ->
sort(Compare, List, []).
-module(cue_parse).
-export([parse_md/1]).
parse_md(<<CatNumber:128/binary, LeadInNum:64/integer, IsCD:1, 0:2071, TrackNum:8, Rest/binary>>) ->
Metadate = #{cat_number => CatNumber, lead_in => LeadInNum, is_cd => (IsCD == 1), tracks => TrackNum},
{ok, Metadate, Rest};
parse_md(<<_/binary>>) ->
{error, not_enough_data}.
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%%! -pa ranch/ebin -sname ranch_race +P 1000000 +A 200 +K true -env ERL_MAX_PORTS 1000000
%% This script is tested only in Linux environment.
%% I could not make it work with Mac OS (it limits connection rate).
%%
%% Warning: you are likely going to hit max open files limit.
%% Before running this script you should raise max fds by executing:
%% sudo -E -- bash -c "ulimit -n 1000000; sudo -E -u $USER bash --login"
-module(bininspector).
% For inspecting binary usage by all accessible ETS tables, run
% [{T, (catch ets:foldl(fun bininspector:collect/2, {0, 0}, T))} || T <- ets:all()].
-export([collect/2]).
collect(B, {S, R}) when is_bitstring(B) ->
{S + byte_size(B), R + binary:referenced_byte_size(B)};
collect(T, Acc) when is_tuple(T) ->