2 #######################################################################
3 # prads to dotviz script - Version 1.0
4 # Copyright © 2015 Andrea Trentini (www.atrent.it)
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # or browse http://www.gnu.org/licenses/gpl.txt
20 #######################################################################
22 # this version connects the nodes, it just sorts services to
23 # group them on a per-node basis, something like this:
25 # (localhost)---(samenet1)---(samenet2)---...---(samenetM)
27 # (hop1router[dummy])---(hop1.1)---(hop1.2)---...---(hop1.N)
29 # (hop2router[dummy])---(hop2.1)---(hop2.2)---...---(hop2.O)
31 # (hop3router[dummy])---(hop3.1)---(hop3.2)---...---(hop3.P)
35 # (hopZrouter[dummy])---(hopZ.1)---(hopZ.2)---...---(hopZ.X)
37 # it generates a dot file, then use
39 # dot to convert to image
41 #######################################################################
43 # only if this gets very complicated
45 # it can be optimized... ;)
46 #######################################################################
48 #the general format for prads data is:
49 #asset,vlan,port,proto,service,[service-info],distance,discovered
51 ### inside [service info] there is again "," !!!
52 ### standby... temporarily solved by prads author
54 #1 asset = The ip address of the asset.
55 #2 vlan = The virtual lan tag of the asset.
56 #3 port = The port number of the detected service.
57 #4 proto = The protocol number of the matching fingerprint.
58 #5 service = The "Service" detected, like: TCP-SERVICE, UDP-SERVICE, SYN, SYNACK,MAC,.....
59 #6 service-info= The fingerprint that the match was done on, with info.
60 #7 distance = Distance based on guessed initial TTL (service = SYN/SYNACK)
61 #8 discovered = The timestamp when the data was collected
63 #######################################################################
68 echo Usage
: $0 '<logfile from prads>'
75 # convert file to substitute internal "," in "[]" field
79 LEFT
=$
(echo $LINE|cut
-f1 -d"[")
80 MIDDLE
=$
(echo $LINE|cut
-f2 -d"["|cut
-f1 -d"]"|
tr "," ";")
81 RIGHT
=$
(echo $LINE|cut
-f2 -d"]")
82 echo $LEFT"["$MIDDLE"]"$RIGHT
86 #sort -k7 -b -n -t"," $FILE
89 #NODES=$(cut -f1 -d"," $FILE|sort -n|uniq|grep 192.168) # 192.168 just to test it
90 NODES
=$
(grep -v -F "asset,vlan,port,proto,service,[service-info],distance,discovered" $FILE|cut
-f1 -d","|
sort -n|
uniq)
93 DISTANCES
=$
(grep -v -F "asset,vlan,port,proto,service,[service-info],distance,discovered" $FILE|cut
-f7 -d"," |
sort -n|
uniq)
94 #echo \#Distances: $DISTANCES
96 echo "digraph \"$FILE\" {"
97 #echo "node [shape=parallelogram]"
98 echo "graph [root=\"Distance_0\",ratio=\"1\",rankdir = \"LR\"];"
104 #echo $node \($(host $node)\);
105 echo \"Node_
$node\" # |tr "." "_"
107 #fields=$(grep $node $FILE|head -n 1|cut -f 2- -d"," | tr -d " "|tr "," "\n")
112 #echo $fields\"|tr -d "[]\n"
113 grep -F "$node," $FILE | cut
-f 2- -d"," |
tr -d " "|
tr "\n" "|"|
rev|cut
-c2-|
rev
115 echo -n shape
= record
118 ## grep $node $FILE|cut -f 2,3,4,5,6,8 -d","
119 # grep $node $FILE|cut -f 2- -d","
123 for dist
in $DISTANCES
125 #echo \# === distance $dist
129 echo Distance_
$prev " ->" Distance_
$dist\
;
132 for node
in $
(cut
-f1,7 -d"," $FILE|
sort|
uniq|
grep ",${dist}$"|cut
-f1 -d",") #repetitive, optimize?
134 echo -n Distance_
$dist " ->"
135 echo \"Node_
$node\"\
;