Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

#!/usr/bin/env python 

# -*- coding: utf-8 -*- 

""" gui.py 

 

The GUI for antikythera 

 

""" 

import sys 

import logging 

import multiprocessing as mp 

 

# Fix kivy's logging 

import antikythera.kivylogs 

from kivy.logger import Logger 

 

from kivy.app import App 

from kivy.lang import Builder 

from kivy.factory import Factory 

from kivy.uix.button import Button 

from kivy.uix.label import Label 

from kivy.animation import Animation 

from kivy.clock import Clock, mainthread 

from kivy.uix.gridlayout import GridLayout 

from kivy.uix.floatlayout import FloatLayout 

from kivy.properties import NumericProperty, ReferenceListProperty 

from kivy.graphics import * 

from multiprocessing import Queue 

from time import sleep 

 

from kivy.uix.settings import SettingsWithSidebar 

from kivy.config import Config 

 

from antikythera import __version__ 

from antikythera.antikythera import __projectname__, __author__, __copyright__, __license__ 

from antikythera.antikythera import Anti, create_parser 

 

_logger = logging.getLogger(__name__) 

 

# Loads main from design file 

Builder.load_file("mainscreen.kv") 

 

# Color pallete (RGBA) 

color_highlight = [0xAD/255, 0xD8/255, 0xE6/255, 0.5] # Blue highlight 

 

class DefconLevel(GridLayout): 

pass 

 

class Metric(GridLayout): 

pass 

 

class Scanner(GridLayout): 

def __init__(self, *args, **kwargs): 

super(Scanner, self).__init__(*args, **kwargs) 

 

self.defconLevel = 5 

self.numPackets = 0 

self.numSuspectPackets = 0 

 

''' 

self.canvas.add(Color(rgba=self.color)) 

self.canvas.add(Rectangle(pos=self.pos, size=self.size)) 

''' 

 

# Called whenever itself or children are updated 

def do_layout(self, *args): 

self.metric.packet_display.text = self.metric.packet_display.default_text + str(self.numPackets) 

self.metric.suspect_packet_display.text = self.metric.suspect_packet_display.default_text + str(self.numSuspectPackets) 

 

super(Scanner, self).do_layout(*args) 

for child in self.children: 

if not isinstance(child, DefconLevel): 

continue 

 

# Creates new canvas 

child.canvas.before.clear() 

child.canvas.after.clear() 

 

# Calculates values for border (Optional) 

border = 0 

insideSize = [child.size[0] - border, child.size[1] - border] 

insidePos = [child.pos[0] + (child.size[0] - insideSize[0]) / 2, child.pos[1] + (child.size[1] - insideSize[1]) / 2] 

 

with child.canvas.before: 

# Defcon color 

Color(rgba=child.color) 

Rectangle(pos=insidePos, size=insideSize) 

 

if (child.level == self.defconLevel): 

# Highlights 

Color(rgba=color_highlight) 

Rectangle(pos=child.pos, size=child.size) 

 

 

#child.canvas.add(rgba=child.color) 

#child.canvas.add(Rectangle(pos=child.pos, size=child.size)) 

 

# Creates new label 

''' 

child.children.clear() 

 

with Label() as label: 

label.text = child.text 

''' 

 

child.label.text = child.text 

child.label.color = [0, 0, 0, 1] 

 

if (child.level == self.defconLevel): 

# Changes text color 

#child.label.color = [1, 1, 1, 1] 

 

iconSize = [child.height, child.height] 

iconPos = [child.pos[0] + (child.size[0] - child.height), child.pos[1]] 

 

with child.canvas.after: 

# Meme icon 

Color(rgba=[1, 1, 1, 1]) 

Rectangle(source=child.icon, pos=iconPos, size=iconSize) 

pass 

 

def update_defcon(self, level): 

""" 

Updates threat level in GUI. 

int : level - Defcon level (1-5) 

""" 

if (level is None): 

return 

 

self.defconLevel = level 

self.do_layout() # Re-draws GUI 

 

def update_packet_count(self, count): 

self.numPackets = count 

self.do_layout() # Re-draws GUI 

 

def update_suspect_packet_count(self, count): 

self.numSuspectPackets = count 

self.do_layout() # Re-draws GUI 

 

 

class RootWidget(GridLayout): 

""" 

 

""" 

def start_detector(self): 

""" 

 

""" 

_logger.info("GUI: Starting detector") 

self.detecting() 

 

 

def detecting(self, *args): 

""" 

 

""" 

# TODO: Add stop scan functionality 

self.title.button_scan.text = "Stop Scan" 

self.title.button_scan.disabled = True 

 

''' 

# Remove start button and add status 

self.remove_widget(self.detect_button) 

self.status.text = ('Looking for a stingray...') 

''' 

 

xMax = self.scanner.anim_box.width * 0.8 

xMin = xMax * 0.3 

 

# Spinny Widget 

action_bar = Factory.AnimWidget() 

self.scanner.anim_box.add_widget(action_bar) 

animation = Animation(opacity=0.3, width=xMin, duration=0.6) 

animation += Animation(opacity=1, width= xMax, duration=0.8) 

animation.repeat = True 

animation.start(action_bar) 

 

 

''' 

# Scanning Label 

label = Label() 

self.scanner.anim_box.add_widget(action_bar) 

 

with label: 

font_size = 30 

text = "Scanning" 

color = [1, 1, 1, 1] 

halign = "center" 

''' 

 

 

def update_defcon(self, level): 

self.scanner.update_defcon(level) 

 

def update_packet_count(self, count): 

self.scanner.update_packet_count(count) 

 

def update_suspect_packet_count(self, count): 

self.scanner.update_suspect_packet_count(count) 

 

def update_status(self, new_text): 

self.status.text = new_text 

 

 

class MetricDisplay(App): 

""" 

 

""" 

 

def __init__(self, *args, **kwargs): 

self.title = __projectname__ 

super(MetricDisplay, self).__init__(*args, **kwargs) 

self.IMSI_detector = None 

self.timesUpdated = 0 

 

def on_start(self): 

# Set even that's called every 1/2 second 

event = Clock.schedule_interval(self.update_from_shared_memory, 1/2) 

""" 

 

""" 

parser = create_parser() 

args = parser.parse_args(sys.argv[1:]) 

 

if args.loglevel: 

Logger.setLevel(level=args.loglevel) 

else: 

#loglevel = LOG_LEVELS.get(Config.get(['kivy', 'log_level'])) 

Logger.setLevel(level=logging.WARNING) 

 

self.IMSI_detector = Anti(args.threads, args.headless, interface=args.interface, capturefile=args.pcap, max_qsize=args.qsize) 

 

def update_from_shared_memory(self, *args): 

''' 

Reads values in shared memory and updates GUI display 

''' 

 

shared = self.IMSI_detector.sharedMemory 

 

for key in shared: 

if (key == 'numPackets'): 

self.root.update_packet_count(shared[key].value) 

elif (key == 'numSuspectPackets'): 

self.root.update_suspect_packet_count(shared[key].value) 

elif (key == 'defconLevel'): 

self.root.update_defcon(shared[key].value) 

 

return 

 

def build(self): 

""" 

 

""" 

self.settings_cls = SettingsWithSidebar 

return RootWidget() 

 

def start(self): 

self.IMSI_detector.start() 

self.root.start_detector() 

 

 

def on_stop(self): 

""" 

 

""" 

if self.IMSI_detector.is_alive(): 

_logger.info("GUI: Sending shutdown signal to Anti") 

self.IMSI_detector.shutdown() 

_logger.info("GUI: Joining Anti process {}".format(self.IMSI_detector.pid)) 

self.IMSI_detector.join() 

_logger.info("GUI: Shutdown successfully".format(self.IMSI_detector.pid)) 

 

def open_config(self): 

""" 

Button - Open configuration settings 

""" 

 

pass 

 

def build_settings(self, settings): 

json = ''' 

[ 

{ 

"type": "options", 

"title": "Capture Interface", 

"desc": "Determines network interface for packet capture", 

"section": "Finding Mr. Ray", 

"key": "text", 

"options": ["Pcap File", "Network"] 

} 

] 

''' 

settings.add_json_panel('Finding Mr. Ray', self.config, data=json) 

 

def build_config(self, config): 

""" 

Set the default values for the configs sections. 

""" 

Config.kivy = "Something" 

config.setdefaults('Finding Mr. Ray', {'text': 'Pcap File'}) 

 

def on_config_change(self, config, section, key, value): 

if config is self.config: 

token = (section, key, value) 

if token == ("Finding Mr. Ray", "text", "Pcap File"): 

# Do the Pcap File things 

print('Capture interface changed to', value) 

 

elif token == ("Finding Mr. Ray", "text", "Network"): 

# Do the network capture things 

print('Capture interface changed to', value) 

 

def run(): 

""" 

 

""" 

_logger.info("GUI: Starting GUI App") 

MetricDisplay().run() 

return 

try: 

MetricDisplay().run() 

except Exception as e: 

_logger.info("GUI: Exception was thrown\n" + str(e)) 

 

 

if __name__ == "__main__": 

run()