File: Crack

package info (click to toggle)
crack 5.0a-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,016 kB
  • sloc: ansic: 7,444; perl: 1,375; sh: 1,062; makefile: 218
file content (441 lines) | stat: -rwxr-xr-x 8,267 bytes parent folder | download | duplicates (4)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/bin/sh
###
# This program was written by and is copyright Alec Muffett 1991,
# 1992, 1993, 1994, 1995, and 1996, and is provided as part of the
# Crack v5.0 Password Cracking package.
#
# The copyright holder disclaims all responsibility or liability with
# respect to its usage or its effect upon hardware or computer
# systems, and maintains copyright as set out in the "LICENCE"
# document which accompanies distributions of Crack v5.0 and upwards.
###
# User-configurable junk for Crack
###

# nice, generic path (RedHat Linux, Solaris1, Solaris2)
CRACK_PATH=/usr/local/bin:/usr/ccs/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/ucb:/usr/etc:$PATH

###
# security
###

umask 077
export CRACK_PATH                       # So it can be picked up later
PATH=$CRACK_PATH                        # For temporary use...
export PATH

###
# Defaults
###

usage="Usage: Crack [options] [bindir] [[-fmt format] files]..."

version="5.0a"                          # version string
deffmt=trad                             # for default trad2spf
dodie=""                                # for verbose usage/die
debug="false"                           # ...guess...
node=`uname -n`                         # more portable then `hostname`

###
# home base
###

CRACK_HOME=`echo $0 | sed -e 's/Crack$//'`

if [ "$CRACK_HOME" = "" ]
then
	CRACK_HOME=.
fi

if cd $CRACK_HOME
then
	CRACK_HOME=`pwd`
else
	echo "Fatal Error: $CRACK_HOME: cannot chdir" 1>&2
	exit 1
fi

export CRACK_HOME

###
# sanity check
###

if [ ! -f "$CRACK_HOME/Crack" ]
then
	echo "Fatal Error: $CRACK_HOME: something weird going down" 1>&2
	exit 1
fi

###
# Hierarchy
###

for dir in run run/bin
do
	test -d $dir || mkdir $dir || exit 1
done

###
# Flagwaving
###

echo "Crack $version: The Password Cracker."
echo "(c) Alec Muffett, 1991, 1992, 1993, 1994, 1995, 1996"
echo "System:" `uname -a 2>/dev/null`
echo "Home: $CRACK_HOME"
echo "Invoked: $0 $*"

###
# Parse Arguments
###

argbackup1="$*"

while [ "x$1" != "x" ]
do
	case $1 in
		-fmt)
			$debug && echo "beginning of filespecs detected"
			break
			;;

		-recover)
			echo "Option: $1 enabled"
			recover=true
			shift
			;;

		-keep)
			echo "Option: $1 enabled"
			keep=true
			shift
			;;

		-debug)
			echo "Option: $1 enabled"
			debug=true
			set -x
			shift
			;;

		-network)
			echo "Option: $1 enabled"
			networkflag=$1
			shift
			;;

		-remote)
			echo "Option: $1 enabled"
			remoteflag=$1
			shift
			;;

		-makeonly)
			echo "Option: $1 enabled"
			makeonlyflag=$1
			shift
			;;

		-makedict*)
			echo "Option: $1 enabled"
			makedictflag="-makedict"
			shift
			;;

		-fgnd)
			echo "Option: $1 enabled"
			fgndflag=$1
			shift
			;;

		-mail)                                  # pass to cracker
			echo "Option: $1 enabled"
			mailflag=$1
			shift
			;;

		-nice)                                  # pass to cracker
			echo "Option: $1 enabled"
			if [ "$2" = "" ]
			then
				echo "Crack: -nice needs an argument" 1>&2
				exit 1
			fi
			niceflag="$1 $2"
			shift 2
			;;

		-from)                                  # pass to cracker
			echo "Option: $1 enabled"
			if [ "$2" = "" ]
			then
				echo "Crack: -from needs an argument" 1>&2
				exit 1
			fi
			fromflag="$1 $2"
			shift 2
			;;

		-kill)                                  # pass to cracker
			echo "Option: $1 enabled"
			if [ "$2" = "" ]
			then
				echo "Crack: -kill needs an argument" 1>&2
				exit 1
			fi
			killflag="$2"
			shift 2
			;;

		-*)
			echo "Crack: unrecognised argument $1" 1>&2
			dodie=yes
			shift
			;;

		*)
			$debug && echo "End of options detected."
			break
			;;
	esac
done

if [ "x$dodie" != "x" ]
then
	echo $usage 1>&2
	exit 1
fi

###
# Sanity test bindir - written in gruntscript for clarity.
###

bdname=`scripts/binstamp 2>/dev/null`

if [ "x$bdname" = "x" ]
then
	echo "Crack: error: cannot continue as binstamp returned empty string" 1>&2
	exit 0
fi

echo "Stamp: $bdname"
echo ""


if [ "x$1" != "x" ]
then
	if [ "$1" = "-fmt" ]            # use generic name
	then
		bindir=run/bin/$bdname
	elif [ -d run/bin/$1 ]          # have been here before
	then
		bindir=run/bin/$1
		shift
	elif [ ! -f $1 ]                # use specified name
	then
		bindir=run/bin/$1
		shift
	else                            # use generic name
		bindir=run/bin/$bdname
	fi
else                                    # supporting "-makeonly"
	if [ "$makeonlyflag" != "" ]
	then
		bindir=run/bin/$bdname

	elif [ "$makedictflag" != "" ]
	then
		bindir=run/bin/$bdname

	elif [ "$remoteflag" != "" ]
	then
		bindir=run/bin/$bdname
	else
		echo $usage 1>&2
		exit 1
	fi
fi

###
# Reset PATH in advance
###

PATH=$CRACK_HOME/scripts:$CRACK_HOME/$bindir:$PATH
export PATH 


###
# Make the dictionary passes
###

dp=run/dict
dplf=$dp/.dictmade

if [ ! -f $dplf ]
then
	test -d $dp && rm -rf $dp

	echo "Crack: making dictionary groups, please be patient..."
	mkdictgrps $dp || exit 1

	echo "Crack: Created new dictionaries..."
	date > $dplf
else
	echo "Crack: The dictionaries seem up to date..."
fi

###
# Make Dict Only ?
###

if [ "x$makedictflag" != "x" ]
then
	echo "Crack: makedict done"
	exit 0
fi

###
# We're on a roll...
###

# F-files are feedback
crackin=run/I$node.$$           # I-files are input to the cracker
crackfb=run/D.boot.$$           # D-files are data from the cracker/fb
crackout=run/D$node.$$
crackerr=run/E$node.$$          # E-files are errors from the cracker

if [ "x$killflag" = "x" ]
then
	crackkf=run/K$node.$$   # K-files are kill file for 'plaster'
else
	crackkf=$killflag
fi

if [ "x$mailflag" != "x" ]
then
	crackmf=run/M$node.$$   # M-files are for mail commands
fi


###
# SPF
###

# The SPF scripts are frontend processors for creating "Single
# Password Format" files which Crack can work on, from any of a
# variety of possible inputs.

# if your target system uses a non-traditional passwd-file format (eg:
# /etc/master.passwd in FreeBSD) then you can use/write a spf script
# (eg: freebsd2spf) to convert the data, and invoke it thusly:

# Crack -fmt freebsd /etc/master.passwd

# If your system has shadow passwords but the core of the password
# data is held in a "traditional" format and uses the standard
# crypt(), function it is recommended that you coerce your data into a
# BSD format file to feed into Crack, by using one of the supplied
# "shadmrg" scripts, or by your own means.

# if your target system is running a non-traditional crypt()
# algorithm, you will have to modify the ELCID code, too.

if [ "x$remoteflag" = "x" ]
then
	echo "Crack: Sorting out and merging feedback, please be patient..."
	fbmerge

	echo "Crack: Merging password files..."
	argbackup2="$*"

	(
		cat run/F-merged        # first the feedback

		while [ "x$1" != "x" ]
		do
			if [ "$1" = "-fmt" ]
			then
				shift || exit 1
				deffmt=$1

			elif [ "$deffmt" = "spf" ]
			then
				cat $1 1>&3 # skip the sort
			else
				${deffmt}2spf $1
			fi

			shift
		done |
		crack-sort -t: -k 1
	) 3>&1 |
	fbfilt $crackfb $crackmf > $crackin # remove feedback-guessable users

	if [ "x$crackmf" != "x" ]
	then
		if [ -s $crackmf ]
		then
			echo "Crack: mailing nastygrams..."
			sh -x $crackmf
		fi
		rm -f $crackmf
	fi

	if [ "x$recover" = "x" ]
	then
	    echo "Crack: Creating gecos-derived dictionaries"
	    mkgecosd $dp $crackin
	else
	    echo "Crack: -recover: using existing gecos-derived dictionaries"
	fi
else
	echo "Crack: reading data from stdin..."
	cat > $crackin # has already been thru fbfilt on master
	ls -l $crackin
fi

###
# Launch it...
###

flags="$fromflag $niceflag $mailflag"

if [ "x$networkflag" != "x" ]
then
	if [ "x$remoteflag" != "x" ]
	then
		echo "Error: cannot -network AND -remote" 1>&2
		exit 1
	elif [ "x$fgndflag" != "x" ]
	then
		echo "Error: cannot -network AND -foreground" 1>&2
		exit 1
	fi

	echo "Crack: launching: netcrack $flags"
	netcrack $flags <$crackin

elif [ "x$fgndflag" != "x" ]
then
	echo "Crack: exec: cracker -kill $crackkf $flags"
	exec cracker $flags <$crackin
else
	echo "Crack: launching: cracker -kill $crackkf $flags"
	exec 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&-
	nohup cracker -kill $crackkf $flags <$crackin >$crackout 2>$crackerr &
fi

if [ "x$keep" = "x" ]
then
	sleep 3
	rm $crackin             # Aye, some things never change...
fi

###
# Exit
###

echo "Done"

exit 0