-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (67 loc) · 3.15 KB
/
Makefile
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
#
# SUIDWGEN - set uid wrapper generator
# Copyright (C) 2018 Mario Aichinger <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
SCRIPT:=/dev/null
INTERPRETER:=/bin/false
USER=root
CHECK_SCRIPT_NOT_WRITABLE:=1
CHECK_SCRIPT_NOT_READABLE:=1
CHECK_SCRIPT_ONLY_USR_EXEC:=1
CHECK_SAME_OWN:=1
CHECK_SAME_GRP:=1
CHECK_NOT_ROOT_U:=0
CHECK_NOT_ROOT_G:=0
MAX_ARGS:=-1
UNSET_ENV:=1
DEBUG:=0
CHECK_MAX_ARGS:=0
CHECK_HASH:=1
NEW_SCRIPT:=$(SCRIPT)-$(USER)
SCRIPT_WRAPPER:=$(SCRIPT)-$(USER)-wrapper
SCRIPT_WRAPPER_C:=$(SCRIPT_WRAPPER).c
clean:
sudo rm $(SCRIPT_WRAPPER_C) || true
sudo rm $(SCRIPT_WRAPPER) || true
sudo rm $(NEW_SCRIPT) || true
wrapper: clean
sudo cp -r $(SCRIPT) $(NEW_SCRIPT)
touch $(SCRIPT_WRAPPER_C)
echo -n > $(SCRIPT_WRAPPER_C)
echo "" >> $(SCRIPT_WRAPPER_C)
echo "#define SCRIPT \""$(NEW_SCRIPT)"\"" >> $(SCRIPT_WRAPPER_C)
echo "#define INTERPRETER \""$(INTERPRETER)"\"" >> $(SCRIPT_WRAPPER_C)
if [[ $(CHECK_SCRIPT_NOT_WRITABLE) = 1 ]]; then echo "#define CHECK_SCRIPT_NOT_WRITABLE 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_SCRIPT_NOT_READABLE) = 1 ]]; then echo "#define CHECK_SCRIPT_NOT_READABLE 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_SCRIPT_ONLY_USR_EXEC) = 1 ]]; then echo "#define CHECK_SCRIPT_ONLY_USR_EXEC 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_SAME_OWN) = 1 ]]; then echo "#define CHECK_SAME_OWN 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_SAME_GRP) = 1 ]]; then echo "#define CHECK_SAME_GRP 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_NOT_ROOT_U) = 1 ]]; then echo "#define CHECK_NOT_ROOT_U 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_NOT_ROOT_G) = 1 ]]; then echo "#define CHECK_NOT_ROOT_G 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_HASH) = 1 ]]; then echo "#define CHECK_SCRIPT_SUM \""$$(sha1sum $(SCRIPT) | cut -d ' ' -f 1)"\"" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(CHECK_MAX_ARGS) = 1 ]]; then echo "#define MAX_ARGS" $(MAX_ARGS) >> $(SCRIPT_WRAPPER_C); fi
if [[ $(UNSET_ENV) = 1 ]]; then echo "#define UNSET_ENV 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ $(DEBUG) = 1 ]]; then echo "#define DEBUG 1" >> $(SCRIPT_WRAPPER_C); fi
if [[ 1 = 1 ]]; then echo "#define ENABLE_HELP 1" >> $(SCRIPT_WRAPPER_C); fi
cat suidwgen.c >> $(SCRIPT_WRAPPER_C)
if [[ $(CHECK_HASH) = 1 ]]; then LIB="-lssl -lcrypto" ; else LIB="";fi; gcc $$(echo $$LIB) -o $(SCRIPT_WRAPPER) $(SCRIPT_WRAPPER_C)
secure:
sudo chmod 700 $(NEW_SCRIPT);
sudo chmod 711 $(SCRIPT_WRAPPER);
sudo chown $(USER):$(USER) $(NEW_SCRIPT);
sudo chown $(USER):$(USER) $(SCRIPT_WRAPPER);
sudo chmod a+s $(SCRIPT_WRAPPER);
all: clean wrapper secure