-
Notifications
You must be signed in to change notification settings - Fork 0
/
bincpy.sh
executable file
·63 lines (51 loc) · 1.47 KB
/
bincpy.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
#
# !!! Do not use this script on production !!!
#
BIN_LST="sh ssh bash rsync nc telnet cat ls pwd cp chmod chown mkdir mv rm mktemp sync tar less more ln kill find grep ps"
LIBS="$(find {/lib,/lib64,/usr/lib,/usr/lib64} -name libns[sl]\*)\n"
DIRS="/etc\n"
BINS=""
TARGET_DIR=$(echo "${1}"|sed 's/\/$//g')
OTHER_FILES="/etc/passwd
/etc/group
/etc/nsswitch.conf"
echo $TARGET_DIR
if [ ! "${TARGET_DIR}" ]; then
exit
fi
for i in ${BIN_LST}; do
BIN=$(which ${i} 2>/dev/null)
if [ "${BIN}" ]; then
LIBS="${LIBS}$(ldd ${BIN}|awk '$3 && $3 ~ "^/" {print $3}')\n" # objdump -p /path/to/program | grep NEEDED
LIBS="${LIBS}$(ldd ${BIN}|grep 'ld-linux.*\.so\.[0-9]\{0,1\}'|awk '$1 {print $1}')\n"
DIRS="${DIRS}$(dirname ${BIN})\n"
BINS="${BINS}${BIN}\n"
fi
done
LIBS=$(echo -e "${LIBS}"|sort|uniq|awk '$1 {print $1}')
BINS=$(echo -e "${BINS}"|sort|uniq|awk '$1 {print $1}')
for i in ${LIBS}; do
DIRS="${DIRS}$(dirname ${i})\n"
done
DIRS=$(echo -e "${DIRS}"|sort|uniq|awk '$1 {print $1}')
for i in ${DIRS}; do
i=$(echo "${i}"|sed 's/^\///g')
mkdir -p "${TARGET_DIR}/${i}"
done
for i in ${BINS}; do
SRC=${i}
i=$(echo "${i}"|sed 's/^\///g')
cp ${SRC} "${TARGET_DIR}/${i}"
done
for i in ${LIBS}; do
SRC=${i}
i=$(echo "${i}"|sed 's/^\///g')
cp ${SRC} "${TARGET_DIR}/${i}"
done
for i in ${OTHER_FILES}; do
SRC=${i}
i=$(echo "${i}"|sed 's/^\///g')
cp ${SRC} "${TARGET_DIR}/${i}"
done
#echo "$DIRS"
#echo "$SUFFICIENT"