1010from grpcClient import *
1111
1212
13+ #
14+ # Constant
15+ #
16+ BeaconNodeItemType = "Beacon"
17+ ListenerNodeItemType = "Listener"
18+
19+ PrimaryListenerImage = "images/firewall.svg"
20+ WindowsSessionImage = "images/pc.svg"
21+ LinuxSessionImage = "images/linux.svg"
22+
23+
24+ #
25+ # Graph Tab Implementation
26+ #
1327# needed to send the message of mouseMoveEvent because QGraphicsPixmapItem doesn't herit from QObject
1428class Signaller (QObject ):
1529 signal = pyqtSignal ()
@@ -22,17 +36,23 @@ class NodeItem(QGraphicsPixmapItem):
2236 # Signal to notify position changes
2337 signaller = Signaller ()
2438
25- def __init__ (self , type , hash , parent = None ):
26- if type == "Listener" :
27- self .type = "Listener"
28- pixmap = QPixmap ("firewall.png" ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
39+ def __init__ (self , type , hash , os = "" , privilege = "" , parent = None ):
40+ if type == ListenerNodeItemType :
41+ self .type = ListenerNodeItemType
42+ pixmap = QPixmap (PrimaryListenerImage ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
2943 self .beaconHash = ""
3044 self .connectedListenerHash = ""
3145 self .listenerHash = []
3246 self .listenerHash .append (hash )
33- elif type == "Beacon" :
34- self .type = "Beacon"
35- pixmap = QPixmap ("pc.png" ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
47+ elif type == BeaconNodeItemType :
48+ self .type = BeaconNodeItemType
49+ # print("NodeItem beaconHash", hash, "os", os, "privilege", privilege)
50+ if "linux" in os .lower ():
51+ pixmap = QPixmap (LinuxSessionImage ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
52+ elif "windows" in os .lower ():
53+ pixmap = QPixmap (WindowsSessionImage ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
54+ else :
55+ pixmap = QPixmap (LinuxSessionImage ).scaled (64 , 64 , Qt .KeepAspectRatio , Qt .SmoothTransformation )
3656 self .beaconHash = hash
3757 self .connectedListenerHash = ""
3858 self .listenerHash = []
@@ -68,14 +88,16 @@ def __init__(self, listener, beacon, pen=None):
6888 self .listener = listener
6989 self .beacon = beacon
7090
71- self .pen = pen or QPen (QColor ("black " ), 2 )
91+ self .pen = pen or QPen (QColor ("white " ), 3 )
7292 self .setPen (self .pen )
7393 self .update_line ()
7494
7595 def print (self ):
7696 print ("Connector" , "beaconHash" , self .beacon .beaconHash , "connectedListenerHash" , self .beacon .connectedListenerHash , "listenerHash" , self .listener .listenerHash )
7797
7898 def update_line (self ):
99+ # print("listener", self.listener.pos())
100+ # print("beacon", self.beacon.pos())
79101 center1 = self .listener .pos () + self .listener .boundingRect ().center ()
80102 center2 = self .beacon .pos () + self .beacon .boundingRect ().center ()
81103 self .setLine (QLineF (center1 , center2 ))
@@ -145,7 +167,7 @@ def updateGraph(self):
145167 for session in sessions :
146168 if session .beaconHash == nodeItem .beaconHash :
147169 runing = True
148- if not runing and self .listNodeItem [ix ].type == "Beacon" :
170+ if not runing and self .listNodeItem [ix ].type == BeaconNodeItemType :
149171 for ix2 , connector in enumerate (self .listConnector ):
150172 if connector .beacon .beaconHash == nodeItem .beaconHash :
151173 print ("[-] delete connector" )
@@ -162,7 +184,7 @@ def updateGraph(self):
162184 if session .beaconHash == nodeItem .beaconHash :
163185 inStore = True
164186 if not inStore :
165- item = NodeItem ("Beacon" , session .beaconHash )
187+ item = NodeItem (BeaconNodeItemType , session .beaconHash , session . os , session . privilege )
166188 item .connectedListenerHash = session .listenerHash
167189 item .signaller .signal .connect (self .updateConnectors )
168190 self .scene .addItem (item )
@@ -185,7 +207,7 @@ def updateGraph(self):
185207 runing = True
186208 if not runing :
187209 # primary listener
188- if self .listNodeItem [ix ].type == "Listener" :
210+ if self .listNodeItem [ix ].type == ListenerNodeItemType :
189211 for ix2 , connector in enumerate (self .listConnector ):
190212 if self .listNodeItem [ix2 ].listenerHash in connector .listener .listenerHash :
191213 print ("[-] delete connector" )
@@ -196,7 +218,7 @@ def updateGraph(self):
196218 del self .listNodeItem [ix ]
197219
198220 # beacon listener
199- elif self .listNodeItem [ix ].type == "Beacon" :
221+ elif self .listNodeItem [ix ].type == BeaconNodeItemType :
200222 if listener .listenerHash in self .listNodeItem [ix ].listenerHash :
201223 for ix2 , connector in enumerate (self .listConnector ):
202224 if self .listNodeItem [ix2 ].listenerHash in connector .listener .listenerHash :
@@ -214,7 +236,7 @@ def updateGraph(self):
214236 inStore = True
215237 if not inStore :
216238 if not listener .beaconHash :
217- item = NodeItem ("Listener" , listener .listenerHash )
239+ item = NodeItem (ListenerNodeItemType , listener .listenerHash )
218240 item .signaller .signal .connect (self .updateConnectors )
219241 self .scene .addItem (item )
220242 self .listNodeItem .append (item )
@@ -229,7 +251,7 @@ def updateGraph(self):
229251 # Update connectors
230252 #
231253 for nodeItem in self .listNodeItem :
232- if nodeItem .type == "Beacon" :
254+ if nodeItem .type == BeaconNodeItemType :
233255 inStore = False
234256 beaconHash = nodeItem .beaconHash
235257 listenerHash = nodeItem .connectedListenerHash
@@ -241,6 +263,7 @@ def updateGraph(self):
241263 if listener .isResponsableForListener (listenerHash )== True :
242264 connector = Connector (listener , nodeItem )
243265 self .scene .addItem (connector )
266+ connector .setZValue (- 1 )
244267 self .listConnector .append (connector )
245268 print ("[+] add connector listener:" , listenerHash , "beacon" , beaconHash )
246269
0 commit comments