This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
/
setup.py
152 lines (111 loc) · 4.37 KB
/
setup.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
143
144
145
146
147
148
149
150
151
152
import argparse
import os
import stat
import pip
from sys import platform
from shutil import copy2, rmtree
from distutils.dir_util import copy_tree
__author__ = "Ghost"
__email__ = "[email protected]"
__license__ = "GPL"
__version__ = "2.0"
# installation directory PATHs
FILE_PATH_LINUX = "/usr/share/sqliv"
EXEC_PATH_LINUX = "/usr/bin/sqliv"
FILE_PATH_MAC = "/usr/local/bin"
EXEC_PATH_MAC = "/usr/local/bin"
def metadata():
print "SQLiv (2.0) by {}".format(__author__)
print "Massive SQL injection vulnerability scanner"
def dependencies(option):
"""install script dependencies with pip"""
try:
with open("requirements.txt", "r") as requirements:
dependencies = requirements.read().splitlines()
except IOError:
print "requirements.txt not found, please redownload or do pull request again"
exit(1)
for lib in dependencies:
pip.main([option, lib])
def install(file_path, exec_path):
"""full installation of SQLiv to the system"""
os.mkdir(file_path)
copy2("sqliv.py", file_path)
copy2("requirements.txt", file_path)
copy2("LICENSE", file_path)
copy2("README.md", file_path)
os.mkdir(file_path + "/src")
copy_tree("src", file_path + "/src")
os.mkdir(file_path + "/lib")
copy_tree("lib", file_path + "/lib")
# python dependencies with pip
dependencies("install")
# add executable
with open(exec_path, 'w') as installer:
installer.write('#!/bin/bash\n')
installer.write('\n')
installer.write('python2 {}/sqliv.py "$@"\n'.format(file_path))
# S_IRWXU = rwx for owner
# S_IRGRP | S_IXGRP = rx for group
# S_IROTH | S_IXOTH = rx for other
os.chmod(exec_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
def uninstall(file_path, exec_path):
"""uninstall sqliv from the system"""
if os.path.exists(file_path):
rmtree(file_path)
print "Removed " + file_path
if os.path.isfile(exec_path):
os.remove(exec_path)
print "Removed " + exec_path
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--install", help="install sqliv in the system", action='store_true')
parser.add_argument("-r", "--reinstall", help="remove old files and reinstall to the system", action="store_true")
parser.add_argument("-u", "--uninstall", help="uninstall sqliv from the system", action="store_true")
args = parser.parse_args()
if platform == "linux" or platform == "linux2":
# Linux require root
if os.getuid() != 0:
print "linux system requires root access for the installation"
exit(1)
FILE_PATH = FILE_PATH_LINUX
EXEC_PATH = EXEC_PATH_LINUX
elif platform == "darwin":
FILE_PATH = FILE_PATH_MAC
EXEC_PATH = EXEC_PATH_MAC
else:
print "Windows platform is not supported for installation"
exit(1)
if args.install and not (args.reinstall or args.uninstall):
#full installation to the system
if os.path.exists(FILE_PATH):
print "sqliv is already installed under " + FILE_PATH
exit(1)
if os.path.isfile(EXEC_PATH):
print "executable file exists under " + EXEC_PATH
exit(1)
install(FILE_PATH, EXEC_PATH)
print "Installation finished"
print "Files are installed under " + FILE_PATH
print "Run: sqliv --help"
elif args.uninstall and not (args.install or args.reinstall):
# uninstall from the system
uninstall(FILE_PATH, EXEC_PATH)
option = raw_input("Do you want to uninstall python dependencies? [Y/N]: ").upper()
while option != "Y" and option != "N":
option = raw_input("Do you want to uninstall python dependencies? [Y/N]: ").upper()
if option == "Y":
dependencies("uninstall")
print "Python dependencies removed"
print "Uninstallation finished"
elif args.reinstall and not (args.install or args.uninstall):
# reinstall to the system
uninstall(FILE_PATH, EXEC_PATH)
print "Removed previous installed files"
install(FILE_PATH, EXEC_PATH)
print "Reinstallation finished"
print "Files are installed under " + FILE_PATH
print "Run: sqliv --help"
else:
metadata(); print ""
parser.print_help()