Skip to content

Commit

Permalink
ioc2rpz is a place where threat intelligence meets DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
Homas committed Mar 12, 2019
1 parent 2849c3f commit 1f40fd9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ioc2rpz change log
[CB] - Changed Behaviour

## 2019-03-10 v0.9.3.0
## 2019-03-11 v0.9.3.1
- REST API
- added rebar3 to manage dependencies

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- [ ] MGMT via REST API
- [ ] Statistics per source, RPZ, performance
- [ ] Bug RPZ stats after reload config
- [ ] Bug in cowboy. Can not send 501 in "catch all"

## Configuration
- [.] Validate: Configuration file name pass as a variable to the container
Expand Down
2 changes: 1 addition & 1 deletion include/ioc2rpz.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
%%%%%%
%%%%%% Do not modify any settings below the line
%%%%%%
-define(ioc2rpz_ver, "0.9.3.0-2019030401").
-define(ioc2rpz_ver, "0.9.3.1-2019031101").

-define(ZNameZip,16#c00c:16). %Zone name/original fqdn from a request is always at byte 10 in the response
-define(MaxZipPSize,16#3FFF:16). %Max packet size to zip DNS labels
Expand Down
24 changes: 22 additions & 2 deletions src/ioc2rpz_rest.erl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ srv_mgmt(Req, State, Format) when State#state.op == stats_serv -> % Statistics -
Srv_IOCs = lists:sum(([ element(25,X) || [X] <- ets:match(cfg_table,{[rpz,'_'],'_','$2'}), element(25,X) /= undefined])),
RPZ_stat = [ {element(4,X),element(25,X)} || [X] <- ets:match(cfg_table,{[rpz,'_'],'_','$2'}), element(25,X) /= undefined],
Sources_stat = [ {element(2,X),element(6,X)} || [X] <- ets:match(cfg_table,{[source,'_'],'$2'}),element(6,X) /= undefined],
Body=io_lib:format("Peer: ~s:~p\nSrv IOCs: ~p\nRPZ:\n ~p\nSources:\n ~p\n",[ioc2rpz:ip_to_str(IP),Port,Srv_IOCs,RPZ_stat,Sources_stat]),
%Body0=Body++io_lib:format("\n\nReq:\n~p\n\nState:\n~p\n\n",[Req,State]),
Body=case Format of
txt -> io_lib:format("Srv total RPZ IOCs: ~p\nRPZ:\n ~p\nSources:\n ~p\n",[Srv_IOCs,RPZ_stat,Sources_stat]);
json -> io_lib:format("{\"srv_total_rules\":~p,\"rpz\":~s,\"sources\":~s}\n",[Srv_IOCs,list_tuples_to_json(RPZ_stat),list_tuples_to_json(Sources_stat)])
end,
{Body, Req, State};

srv_mgmt(Req, State, Format) when State#state.op == catch_all -> % Catch all unsupported requests from authenticated users
Expand All @@ -151,3 +153,21 @@ srv_mgmt(Req, State, Format) when State#state.op == catch_all -> % Catch all uns

rest_terminate(Req, State) ->
ok.

list_tuples_to_json(Array) ->
io_lib:format("[~s]",[list_tuples_to_json([],Array)]).

list_tuples_to_json([],[E|Rest]) ->
list_tuples_to_json(tuple_to_json(E),Rest);

list_tuples_to_json(Resp,[E|Rest]) ->
list_tuples_to_json(tuple_to_json(E)++","++Resp,Rest);

list_tuples_to_json(Resp,[]) ->
Resp.

tuple_to_json({Name,Value}) when is_integer(Value)->
io_lib:format("{\"~s\":~b}",[Name,Value]);

tuple_to_json({Name,Value}) ->
io_lib:format("{\"~s\":\"~b\"}",[Name,Value]).

0 comments on commit 1f40fd9

Please sign in to comment.