forked from natrix-fork/Florid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflorid.py
executable file
·142 lines (117 loc) · 4.71 KB
/
florid.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
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
from __future__ import absolute_import
from __future__ import print_function
import datetime
import json
import optparse
import pathlib
import re
import signal
import threading
import time
import requests
import core.initializer
from settings import ROOT_PATH
core.initializer.Initializer().init()
import lib.common
import lib.colorprint
import lib.processbar
import lib.urlentity
import core.importer
import core.producer
import core.consumer
import core.checker
florid_banner = {
'version': '3.2.4',
'update': '2017-9-25',
'logo':
r'''
_______ _____ ______ _____ ______
|______ | | | |_____/ | | \
| |_____ |_____| | \_ __|__ |_____/
'''
}
def florid_show_banner():
lib.colorprint.color().pink(florid_banner['logo'])
print('[Florid Version] ' + florid_banner['version'])
print('[Last Updated] ' + florid_banner['update'])
print('[*] ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
print('\nPress [Ctrl+C] to abort the scan')
print('\n')
def florid_get_parse():
parser = optparse.OptionParser()
parser.add_option('--url', action='store', help='Target URL')
parser.add_option('--modules', action='store', help='Modules to be included')
parser.add_option('--output', action='store', help='output file to save result in json format')
(options, args) = parser.parse_args()
if options.modules is None:
lib.colorprint.color().red('[!] Fatal Error: No modules specified. Use "-m" to do it.', end='\n')
lib.colorprint.color().red('[!] You can get help with "-h"', end='\n')
exit()
return options
def florid_init(options):
# TODO: this is a temporary solution to validate the target, redo to something better
try:
requests.get(options.url)
except (ConnectionError, Exception) as error:
print(error)
file_path = ROOT_PATH.joinpath(options.output)
# write empty list to handle error (quick temporary solution)
result = {
"Empty": "Nothing found by Florid",
"Error": error,
}
with open(file_path, "w") as jf:
json.dump(result, jf, indent=2)
exit(1)
lib.common.SOURCE_URL = lib.urlentity.URLEntity(options.url).get_url()
pattern = r'.*[/\\](.+)\.py$'
modules_path_phase_one: pathlib.Path = ROOT_PATH.joinpath("module/phase_one")
modules_path_phase_two: pathlib.Path = ROOT_PATH.joinpath("module/phase_two")
for __file_name in modules_path_phase_one.iterdir():
# for __file_name in glob.glob('module/phase_one/*.py'):
name_of_file: str = str(__file_name)
__file_name = name_of_file
if '__init__' not in __file_name and 'pyc' not in __file_name:
lib.common.MODULE_ONE_NAME_LIST.append(
re.findall(pattern, __file_name)[0][1])
if options.modules.lower() == 'all':
for __file_name in modules_path_phase_two.iterdir():
name_of_file: str = str(__file_name)
__file_name = name_of_file
if '__init__' not in __file_name and 'pyc' not in __file_name:
lib.common.MODULE_NAME_LIST.append(
re.findall(pattern, __file_name)[0][1])
else:
if options.modules != '':
for __file_name in options.modules.replace(' ', '').split(','):
lib.common.MODULE_NAME_LIST.append(__file_name)
def florid_organize():
core.importer.Importer().do_import()
tasks = list([])
# tasks.append(threading.Thread(target=lib.processbar.run, args=()))
tasks.append(threading.Thread(target=core.producer.Producer(lib.common.SOURCE_URL).run, args=(), daemon=True))
tasks.append(threading.Thread(target=core.consumer.Consumer().run, args=(), daemon=True))
tasks.append(threading.Thread(target=core.checker.ResultPrinter().run, args=(), daemon=True))
for __task in tasks:
# __task.setDaemon(True)
__task.start()
while not lib.common.FLAG['scan_done']:
alive = False
if lib.common.FLAG['stop_signal']:
for t in tasks:
alive = alive or t.is_alive()
if not alive:
break
lib.colorprint.color().green('\n-- FINISH --\n')
def florid_exit(signum, frame):
lib.common.FLAG['stop_signal'] = True
lib.colorprint.color().red('\n\n[!] User abort. Terminating the scan...')
if __name__ == '__main__':
time_start = time.time()
signal.signal(signal.SIGINT, florid_exit)
signal.signal(signal.SIGTERM, florid_exit)
# florid_show_banner()
florid_init(florid_get_parse())
florid_organize()
time_end = time.time()
print(f"{int((time_end - time_start) / 60)}:{int((time_end - time_start) % 60)} минут прошло")