generated from 8dcc/cheat-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.sh
executable file
·65 lines (57 loc) · 2.56 KB
/
inject.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
#!/bin/bash
pid=$(pidof "devildaggers")
libpath=$(realpath "libdd-re.so")
if [ "$pid" == "" ]; then
echo "inject.sh: process not running."
exit 1
fi
# Used to echo the command. For debugging.
#set -x
if [ "$1" == "unload" ]; then
sudo gdb -n -q -batch \
-ex "attach $pid" \
-ex "set \$dlopen = (void* (*)(char*, int))dlopen" \
-ex "set \$dlclose = (int (*)(void*))dlclose" \
-ex "set \$dlerror = (char* (*)(void))dlerror" \
\
-ex "set \$self = \$dlopen(\"$libpath\", 6)" \
-ex "call \$dlclose(\$self)" \
-ex "call \$dlclose(\$self)" \
\
-ex "call \$dlerror()" \
-ex "detach" \
-ex "quit"
exit 0
fi
if grep -q "$libpath" "/proc/$pid/maps"; then
echo -e "dd-re already loaded. Reloading...\n";
# 0x2 -> RTLD_NOW
# 0x6 -> RTLD_LAZY | RTLD_NOLOAD
# For more info on the 3 mid lines, see self_unload() in main.c
sudo gdb -n -q -batch \
-ex "attach $pid" \
-ex "set \$dlopen = (void* (*)(char*, int))dlopen" \
-ex "set \$dlclose = (int (*)(void*))dlclose" \
-ex "set \$dlerror = (char* (*)(void))dlerror" \
\
-ex "set \$self = \$dlopen(\"$libpath\", 6)" \
-ex "call \$dlclose(\$self)" \
-ex "call \$dlclose(\$self)" \
\
-ex "call \$dlopen(\"$libpath\", 2)" \
-ex "call \$dlerror()" \
-ex "detach" \
-ex "quit"
else
sudo gdb -n -q -batch \
-ex "attach $pid" \
-ex "set \$dlopen = (void* (*)(char*, int))dlopen" \
-ex "set \$dlclose = (int (*)(void*))dlclose" \
-ex "set \$dlerror = (char* (*)(void))dlerror" \
-ex "call \$dlopen(\"$libpath\", 2)" \
-ex "call \$dlerror()" \
-ex "detach" \
-ex "quit"
fi
set +x
echo -e "\nDone."