forked from seveas/hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_passwords
executable file
·89 lines (78 loc) · 2.61 KB
/
reset_passwords
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
#!/bin/bash
#
# Find linux installs and reset passwords
# (c) 2008 Dennis Kaarsemaker
#
# Instructions:
# To recover/reset passwords of an installed linux system, it's easiest to boot
# from a live CD and run this script. To do so, follow this list:
# - Boot from live cd
# - Download this file to the desktop
# - Run this command: bash ~/Desktop/reset_passwords
# - Follow the instructions presented by the script
#
# For each user account it finds, it will prompt you to ask whether you want to
# change the password.
# Bugs:
# - Doesn't work if /usr is on a separate filesystem
# - Doesn't work for non-lsb distros
# Warning, disclaimer
if [ "$1" != "--nowarn" ]; then
echo -e "\033[1;31mThis tool will let you reset the passwords of any accounts\033[0m"
echo -e "\033[1;31mit finds on installed linux systems. Use with care!\033[0m"
echo -n "Press enter to continue, or CTRL-C to abort "
read discard
fi
if [ $UID -ne 0 ]; then
echo -e "\033[0;37mYou are $USER, not root. Attempting to run sudo\033[0m"
exec sudo bash "$0" --nowarn
fi
# Warn if things are mounted on /mnt
mount | grep -q '/mnt' && {
echo "A partition has been mounted under /mnt, aborting"
echo "To unmount these partitions, run the following commands:"
awk '/mnt/{ print "sudo umount " $2}' < /proc/mounts
exit;
}
# Find partitions
partitions=$(fdisk -l | sed -n -e 's@^\(/dev/[[:alnum:]]\+\).*@\1@p')
# Iterate over partitions
for part in $partitions; do
echo -e "\033[0;37mTrying partition $part\033[0m"
# Mount
mount $part /mnt >/dev/null 2>&1 || {
echo -e "\033[0;37mCouldn't mount $part\033[0m"
continue
}
# Detect linux
if [ ! -e /mnt/etc/shadow ] || [ ! -e /mnt/usr/bin/lsb_release ]; then
echo "$part doesn't seem to be a linux rootpartition"
umount /mnt
continue
fi
echo -e "\033[4;30mFound the following distribution on $part\033[0m:"
chroot /mnt /usr/bin/lsb_release -i -r -c -d
echo -ne "\033[4;30mReset passwords in this system\033[0m? [y/n] "
read cont
case $cont in
[yY])
;;
*)
echo -e "\033[0;37mSkipping $part\033[0m"
umount /mnt
continue
esac
# Detect users with usable passwords
users=$(chroot /mnt /usr/bin/passwd -S -a | sed -n -e 's/\([^[:space:]]\+\) P.*/\1/p')
# Iterate over them
for user in $users; do
echo -ne "Reset the password for \033[4;30m$user\033[0m? [y/n] "
read input
case $input in
[yY])
chroot /mnt /usr/bin/passwd $user
;;
esac
done
umount /mnt
done