Permalink
Browse files

Automagically figure out source/ns MAC and IP addresses

Change spood:start/1 to take a proplist. If the keys are not provided,
lookup the values from the interfaces.
  • Loading branch information...
msantos committed Jun 26, 2010
1 parent 5477f76 commit 97a8a18eb83ebeb63c5a5dd43e7c226052da0e32
Showing with 35 additions and 20 deletions.
  1. +2 −5 src/snuff.erl
  2. +21 −13 src/spood.erl
  3. +12 −2 src/spoof.erl
View
@@ -30,17 +30,14 @@
%% POSSIBILITY OF SUCH DAMAGE.
-module(snuff).
--export([service/1]).
+-export([service/2]).
-include("epcap_net.hrl").
-service(Dev) ->
+service(Dev, NS) ->
{ok, Socket} = packet:socket(),
ok = packet:promiscuous(Socket, packet:ifindex(Socket, Dev)),
- {ok, PL} = inet_parse:resolv(
- proplists:get_value(resolv_conf, inet_db:get_rc(), "/etc/resolv.conf")),
- NS = proplists:get_value(nameserver, PL),
error_logger:info_report({ns,NS}),
loop(Socket, NS).
View
@@ -30,22 +30,30 @@
%% POSSIBILITY OF SUCH DAMAGE.
-module(spood).
--export([start/0,start/3]).
-
--define(DNS_PORT, 53).
+-export([start/0,start/1]).
start() ->
- start("ath0",
- % Client
- {{16#00,16#15,16#af,16#59,16#08,16#26}, discover},
-
- % Nameserver
- {{16#00,16#16,16#b6,16#b5,16#3e,16#c6}, {192,168,213,1}}
- ).
-start(Dev, Client, Nameserver) ->
- spoof:start_link(Dev, Client, Nameserver),
+ start([]).
+start(Options) ->
+ Dev = proplists:get_value(dev, Options, "ath0"),
+
+ Smac = proplists:get_value(srcmac, Options),
+ Dmac = proplists:get_value(dstmac, Options),
+
+ Saddr = proplists:get_value(saddr, Options, discover),
+ Daddr = nameserver(proplists:get_value(nameserver, Options)),
+
+ spoof:start_link(Dev, {Smac,Saddr}, {Dmac, Daddr}),
dns:start_link(),
- spawn(snuff, service, [Dev]).
+ spawn(snuff, service, [Dev, Daddr]).
+
+
+nameserver(undefined) ->
+ {ok, PL} = inet_parse:resolv(
+ proplists:get_value(resolv_conf, inet_db:get_rc(), "/etc/resolv.conf")),
+ proplists:get_value(nameserver, PL);
+nameserver(NS) ->
+ NS.
View
@@ -63,6 +63,16 @@ init([Dev, {ClientMAC, Strategy}, {NSMAC, NSIP}]) ->
{ok, Socket} = packet:socket(),
Ifindex = packet:ifindex(Socket, Dev),
+ SrcMAC = case ClientMAC of
+ undefined -> packet:macaddress(Socket, Dev);
+ M1 -> M1
+ end,
+
+ DstMAC = case NSMAC of
+ undefined -> packet:arplookup(Socket, Dev, NSIP);
+ M2 -> M2
+ end,
+
Source = case Strategy of
discover ->
{SA1,SA2,SA3,SA4} = packet:ipv4address(Socket, Dev),
@@ -75,10 +85,10 @@ init([Dev, {ClientMAC, Strategy}, {NSMAC, NSIP}]) ->
{ok, #state{
s = Socket,
i = Ifindex,
- shost = ClientMAC,
+ shost = SrcMAC,
saddr = Source,
- dhost = NSMAC,
+ dhost = DstMAC,
daddr = NSIP
}}.

0 comments on commit 97a8a18

Please sign in to comment.