Debian Codegraph @

scripts/airgraph-ng/airgraphviz/lib_Airgraphviz.py

raw
1 __author__ = 'Ben "TheX1le" Smith'
2 __email__ = '[email protected]'
3 __website__= 'http://trac.aircrack-ng.org/browser/trunk/scripts/airgraph-ng/'
4 __date__ = '03/02/09'
5 __version__ = ''
6 __file__ = 'lib_Airgraphviz.py'
7 __data__ = 'This library supports airgraph-ng'
8
9 """
10 ########################################
11 #
12 # Airgraph-ng.py --- Generate Graphs from airodump CSV Files
13 #
14 # Copyright (C) 2009 Ben Smith <thex1le[a.t]gmail.com>
15 #
16 # This program is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License version 2 as
18 # published by the Free Software Foundation; version 2.
19 #
20 # This program is distributed in the hope that it will be useful, but
21 # WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 # General Public License for more details.
24 #
25 #########################################
26 """
27
28 """ Airgraph-ng Support Library """
29
30 def apColor(Label,APcolorList): #OLDNAME AP_Label_Color
31 """
32 Inputs a list containing AP information and the AP color information
33 Returns a graph object that holds AP information (colors and details)
34 TODO: Get sample data for each line?
35 """
36 APcolor = APcolorList[0]
37 fontColor = APcolorList[1]
38
39 graph = ['\t','"',Label[0],'"',
40 '[label="',Label[0],
41 '\\nEssid: ',Label[1].rstrip('\x00'), #NULL ESSID is equal to binary space, must remove
42 '\\nChannel: ',Label[2],
43 '\\nEncryption: ',Label[3],
44 '\\nNumber of Clients: ','%s' %(Label[4]), #Check to see if this method is actually needed
45 '"',' style=filled',
46 ' fillcolor="',APcolor,
47 '"',' fontcolor="',fontColor,
48 '"',' fontsize=7','];\n']
49 return graph
50
51 def clientColor(mac,color,label=""): #OLDNAME Client_Label_Color
52 """
53 Creates a label for the client information passed in (mac, color)
54 Returns a graph object
55 TODO: Pass a label in that may hold additional client data that could in turn be written on the client.
56 """
57 if label == "":
58 label = mac
59 graph = ['\t','"',mac,'"',' [label="',label,'"',' color="',color,'"',' fontsize=7','];\n']
60 return graph
61
62 def encryptionColor(enc): #OLDNAME Return_Enc_type
63 """
64 Take in the encryption used by the AP and return the proper color scheme based on that value.
65 Returns a list containing the AP fill color and AP font color
66 """
67 fontColor = "black" #Default Font Color to be used
68
69 if enc == "OPN":
70 color = "firebrick2"
71 elif enc == "WEP":
72 color = "gold2"
73 elif enc in ["WPA","WPA2WPA","WPA2","WPAOPN"]:
74 color = "green3"
75 else: #No AP should ever get to this point as they will either be encrypted or open
76 color = "black"
77 fontColor = "white"
78
79 APcolorList = (color,fontColor) #OLDNAME colorLS
80 return APcolorList
81
82
83 def graphvizLinker(objA,sep,objB): #OLDNAME graphviz_link
84 """
85 Return a graph object that links 2 objects together. Both objects are passed in with a separator
86 """
87 graph =['\t','"',objA,'"',sep,'"',objB,'"',';\n']
88 return graph
89
90 def dotClose(input,footer): #OLDNAME dot_close
91 """
92 Close the graphiz config file
93 Return final output to be written
94 """
95 input.extend(footer)
96 input.append("}")
97 output = ''.join(input)
98 return output
99
100 def dotWrite(data): #OLDNAME dot_write
101 """
102 Write all the information obtained to a configuration file
103 """
104 try:
105 subprocess.Popen(["rm","-rf","airGconfig.dot"]) #Delete the file if it already exists
106 except Exception:
107 pass
108 with open('airGconfig.dot','a') as fid:
109 fid.writelines(data)
110
111 def subGraph(items,graphName,graphType,tracked,parse): #OLDNAME subgraph
112 """
113 Create a subgraph based on the incoming values
114 TODO: Figure out what this does and clean it up
115 """
116 subgraph = ['\tsubgraph cluster_',graphType,'{\n\tlabel="',graphName,'" ;\n']
117
118 if parse == "y":
119 for line in items:
120 clientMAC = line[0]
121 probe_req = ', '.join(line[6:])
122 for bssid in tracked:
123 if clientMAC not in tracked[bssid]:#check to make sure were not creating a node for a client that has an association already
124 subgraph.extend(['\tnode [label="',clientMAC,' \\nProbe Requests: ',probe_req,'" ] "',clientMAC,'";\n'])
125 subgraph.extend(['\t}\n'])
126 elif parse == "n":
127 subgraph.extend(items)
128 subgraph.extend(['\t}\n'])
129 return subgraph
130
131
132 ###############################################
133 # Filter Class #
134 ###############################################
135 #def filter_enc(input,enc):
136 # AP = info[1]
137 # for key in AP:
138 # bssid = AP[key]
139 # if bssid[5] != enc:
140 # del AP[bssid]
141 # return_list = [info[0],AP]
142 # return return_list
143
144
145
146
147 #encryption type
148 #number of clients
149 #OUI
150 #channel
151 #beacon rate?
152 #essid
153 #speed
154 #time
155 #probe requests
156 #whore mode... search for ANY one wanting to connect