forked from Orange-Cyberdefense/fenrir-ocd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FenrirTail.py
executable file
·88 lines (70 loc) · 2.96 KB
/
FenrirTail.py
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
# coding=utf-8
######################################################################
##|# ------ FenrirTail : Fenrir logging and output class ----- #|###
##|# - It is responsible for printing error/debug/info - #|###
##|# - messages to the user - #|###
######################################################################
from scapy.all import *
from sys import stdout
###########################################################################
### ---------------- Main component of FenrirTail ---------------- ####
###########################################################################
class FenrirTail :
def __init__(self, debugLevel=1) :
self.debug = debugLevel
self.threshold = 100
def packetCounter(self, pkt, pktNumber, PKTthread_number):
stdout.write("\r\033[1m\033[32m[RAWR]\033[0m Processing packet number\033[1m \033[31m" + str(
pktNumber))
stdout.flush()
# Verbosity : 0 = no msg, 1 = normal, 2 = information (light), 3 = this damn tool won't stop printing stuff
## Notify : main function for standard output ##
def notify(self, msg, verbosityLevel, bold=0) :
if self.debug >= verbosityLevel :
if bold == 1:
msg = '\033[1m' + msg + '\033[0m'
else:
msg = '[-- ' + msg
print msg
## notifyGood : green color ##
def notifyGood(self, msg, verbosityLevel, bold=0) :
if self.debug >= verbosityLevel :
msg = '\033[32m[*] ' + msg + '\033[0m'
self.notify(msg, verbosityLevel, bold)
## notifyWarn : yellow color ##
def notifyWarn(self, msg, verbosityLevel, bold=0) :
if self.debug >= verbosityLevel :
msg = '\033[33m[*] ' + msg + '\033[0m'
self.notify(msg, verbosityLevel, bold)
## notifyBad : red color ##
def notifyBad(self, msg, verbosityLevel, bold=0) :
if self.debug >= verbosityLevel :
msg = '\033[31m[*] ' + msg + '\033[0m'
self.notify(msg, verbosityLevel, bold)
## mangleException : responsible for writing mangle exceptions logs to file ##
def mangleException(self, pkt, reason=''):
self.notifyBad('\nFENRIR PANIC : Process failed during MANGLING', 1, 1)
if reason != '':
self.notifyBad('Reason : ' + reason, 1)
self.notify('Packet was logged to errorLogFile : FENRIR.err', 1)
logfd = open('FENRIR.err', 'a')
logfd.write(
'---DUMP BEGINS--------------------------------------------------------------------------------------\n')
logfd.write(
'[*] Packet header SRC : ' + pkt[IP].src + ' (' + pkt[Ether].src + ') DST : ' + pkt[IP].dst + ' (' + pkt[
Ether].dst + ')\n')
logfd.write('Packet dump :\n')
logfd.write(str(ls(pkt)) + '\n')
logfd.write(
'---DUMP ENDS----------------------------------------------------------------------------------------\n')
logfd.close()
## fenrirPanic : unrecoverable exception handling ##
def fenrirPanic(self, msg, bold=1, exitOnFailure=1) :
if bold == 1 :
msg = '\033[1m' + 'FENRIR PANIC : ' + msg + '\033[0m'
else :
msg = 'FENRIR PANIC : ' + msg
if exitOnFailure == 1 :
exit(msg)
else :
print msg