-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkuang
executable file
·204 lines (167 loc) · 5.83 KB
/
kuang
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
:
# /* Copyright 1985 Robert W. Baldwin */
# /* Copyright 1986 Robert W. Baldwin */
#
# Jan 1990, Ported to bourne shell from Csh. Dan Farmer
#
# Took out some comments, combined four of Bob's shell
# scripts into one (the target script remains separate for
# easy editing of targets.) More or less a straight line
# for line translation; a rewrite that goes for speed will
# come later. Maybe just rewrite it in C. Yeah, that's it....
###############################################
# Kuang: Rule based computer security checker.
###############################################
# commands used....
SH=/bin/sh
MV=/bin/mv
TEST=/bin/test
ECHO=/bin/echo
AWK=/bin/awk
RM=/bin/rm
# Initialization.
$SH ./init_kuang
# Main loop
#
$ECHO Starting main loop #>/dev/tty
while $TEST -f uids.n -o -f gids.n -o -f files.n
do
if $TEST -f uids.n ; then
$MV uids.n uids.x
# Process a list of uids from stdin.
# Usage: douids username comments
$ECHO Called douids #>/dev/tty
i=1
while $TEST "1"
do
nextuid=`$AWK '{if (NR=="'$i'") print $0}' uids.x`
i=`expr $i + 1`
if $TEST -z "$nextuid" ; then
break;
fi
user=`$ECHO $nextuid | $AWK '{print $1}'`
$ECHO " " User $user #>/dev/tty
# Rules mapping uids to files.
#
next=`$ECHO $nextuid | $AWK '{for (i=2;i<=NF;i++) printf("%s ", $i)}'`
./addto files /etc/passwd replace grant $user $next
./addto files /usr/lib/aliases replace trojan $user $next
# hsh = home sweet home = home directory of $user
hsh=`./tilde $user`
if $TEST -f $hsh/.rhosts ; then
./addto files $hsh/.rhosts write grant $user $next
fi
if $TEST -f $hsh/.login ; then
./addto files $hsh/.login replace trojan $user $next
fi
if $TEST -f $hsh/.cshrc ; then
./addto files $hsh/.cshrc replace trojan $user $next
fi
if $TEST -f $hsh/.profile ; then
./addto files $hsh/.profile replace trojan $user $next
fi
if $TEST "$user" = "root" ; then
if $TEST -f /usr/lib/crontab ; then
./addto files /usr/lib/crontab replace create supershell $next
else
./addto files /usr/spool/cron/crontabs replace create supershell $next
fi
./addto files /etc/rc replace trojan $user $next
./addto files /etc/rc.local replace trojan $user $next
fi
if $TEST "$user" != "root" ; then
./addto files /etc/hosts.equiv replace allow rlogin $next
fi
if $TEST "$user" != "root" -a -f /etc/hosts.equiv -a -s /etc/hosts.equiv
then
./addto files /etc/hosts replace fake HostAddress $next
fi
done
fi
if $TEST -f gids.n ; then
$MV gids.n gids.x
$ECHO Called dogids #>/dev/tty
i=1
while $TEST "1"
do
nextgid=`$AWK '{if (NR=="'$i'") print $0}' gids.x`
i=`expr $i + 1`
if $TEST -z "$nextgid" ; then
break;
fi
group=`$ECHO $nextgid | $AWK '{print $1}'`
$ECHO " " Group $group #>/dev/tty
# Rules mapping gids to uids.
#
next=`$ECHO $nextgid | $AWK '{for (i=2;i<=NF;i++) printf("%s ", $i)}'`
use=`./members $group`
for user in $use
do
./addto uids $user grant $group $next
done
# Rules mapping gids to files.
#
./addto files /etc/group replace grant $group $next
done
fi
if $TEST -f files.n ; then
$MV files.n files.x
# A list of file names is read from successive lines of stdin.
# Each file is examined for ways to access it.
# The input format is:
# <filename> <whitespace> <mode> <comments>
# The <mode> is either "write" or "replace".
#
$ECHO Called dofiles. #>/dev/tty
i=1
while $TEST "1"
do
nextfile=`$AWK '{if (NR=='"$i"') print $0}' files.x`
i=`expr $i + 1`
if $TEST -z "$nextfile" ; then
break;
fi
file=`$ECHO $nextfile | $AWK '{print $1}'`
mode=`$ECHO $nextfile | $AWK '{print $2}'`
$ECHO " File $file, mode $mode" #>/dev/tty
# Rules converting filename goals into UserName or GroupName goals.
#
next=`$ECHO $nextfile | $AWK '{for (i=3;i<=NF;i++) printf("%s ", $i)}'`
writers=`./filewriters $file`
numwriters=`$ECHO $writers | $AWK '{print NF}'`
if $TEST "$numwriters" = "3" ; then
owner=`$ECHO $writers | $AWK '{print $1}'`
group=`$ECHO $writers | $AWK '{print $2}'`
other=`$ECHO $writers | $AWK '{print $3}'`
$ECHO " Writers are $owner $group $other" #>/dev/tty
./addto uids $owner $mode $file $next
if $TEST "$group" != "NONE" ; then
./addto gids $group $mode $file $next
fi
if $TEST "$other" != "NONE" ; then
./addto uids $other $mode $file $next
fi
else
$ECHO " $file does not exist" #>/dev/tty
continue
fi
# Rules converting filename goals into other filename goals.
#
if $TEST "$mode" != "replace" ; then
continue
fi
parent=`$ECHO $file | $AWK -F/ '{if (NF == 2) {
printf("/%s", $1)}
else if (NF>2) {for (i=2;i<NF;i++) printf("/%s", $i)}
else printf("")'}`
basename=`$ECHO $file | $AWK -F/ '{print $NF}'`
$ECHO -n " " Parent directory is $parent #>/dev/tty
$ECHO ", " basename is $basename #>/dev/tty
if $TEST -n "$parent" ; then
./addto files $parent write replace $basename $next
fi
done
fi
done
# destroy the evidence.... Need "Success" file for report, though.
$RM files.? gids.? uids.?