-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcyberus.py
114 lines (90 loc) · 2.95 KB
/
cyberus.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
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
from generic_model import *
from generic_spam_text import *
from generic_spam_url import *
from banners import *
import re
import os
def main():
cyberus_obj = cyberus()
while True:
if not cyberus_obj.get_input(singleline=False):
break
cyberus_obj.process()
cyberus_obj.print()
input("Press any key to continue...")
class cyberus:
def __init__(self) -> None:
self.spam_text_instance = spam_text()
self.spam_url_instance = spam_url()
self._cleanup_()
def _cleanup_(self):
self.input_text = ""
# No result can be 0% risky, some risk always involved.
# and not result can be 100%, some possibility of safety
# is always exist, thus add padding to those values.
self.results = [True, False]
# Clean output screen
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
def get_input(self, singleline=False):
if singleline:
return self._singleline_prompt_()
return self._multiline_prompt_()
def _singleline_prompt_(self):
print(PROMPT_BANNER_SINGLE_LINE)
self.input_text = input(">> ")
# More check on first line
if self.input_text.lower().strip() == "exit":
return False
# Indicating that got some useful
return True
def _multiline_prompt_(self):
# Starting with fresh
self._cleanup_()
# Prompt banner
print(INTRO_BANNER)
print(PROMPT_BANNER)
self.input_text = input()
# More check on first line
if self.input_text.lower().strip() == "exit":
return False
# Take multiple lines
while True:
try:
line = input()
except EOFError:
return True
self.input_text += f"\n{line}"
def _judge_text_(self):
res = self.spam_text_instance.judge_all(self.input_text)
self.results.extend(res)
def _judge_url_(self):
res = []
urls = re.findall(r"(?:https|http|ftp)\S*", self.input_text)
for url in urls:
for ins_res in self.spam_url_instance.judge_all(url):
res.append(ins_res)
self.results.extend(res)
def process(self):
self._judge_text_()
self._judge_url_()
def get_results(self):
return self.results
def get_score(self):
score = self.results.count(True)/len(self.results)*100
return round(score, 2)
def print(self):
score = self.get_score()
if score >= 50:
print(INDICATOR_HIGH)
elif score > 20:
print(INDICATOR_MEDIUM)
else:
print(INDICATOR_LOW)
result_string = f"{score:.2f}% ({self.results.count(True)} out of {len(self.results)})."
print(" > Cyberus Risc Score: " + result_string)
print(INDICATOR_END)
if __name__ == "__main__":
main()