-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexfil.sh
executable file
·331 lines (286 loc) · 7.6 KB
/
exfil.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env bash
#
# Steal everything
#
# Andrew Martin, 2021-09-02 07:00:39
#
## Usage: %SCRIPT_NAME% [options] filename
##
## Options:
## -d, --description [string] Description
##
## --config=file Configuration file to override flags, formatted as options without prefixed hyphens
## --debug Enable debug mode
## -v, --version Print version
## -h, --help Display this message
##
# exit on error or pipe failure
set -eo pipefail
# propagate ERR traps to subshells
set -o errtrace
# error on unset variable
if test "${BASH}" = "" || "${BASH}" -uc 'a=();true "${a[@]}"' 2>/dev/null; then
set -o nounset
fi
# error on clobber
set -o noclobber
# disable passglob
shopt -s nullglob globstar
_error_handler() {
local ERR=$?
set +o xtrace
echo "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}: '${BASH_COMMAND}' exited with status ${ERR} in ${FUNCNAME[1]}()"
if [ ${#FUNCNAME[@]} -gt 2 ]; then
echo "Call tree:"
for ((i = 1; i < ${#FUNCNAME[@]} - 1; i++)); do
echo " $i: ${BASH_SOURCE[$i + 1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)"
done
fi
exit "${ERR}"
}
trap _error_handler ERR
# resolved directory and self
declare -r DIR=$(cd "$(dirname "${0}")" && pwd)
declare -r THIS_SCRIPT="${DIR}/$(basename "${0}")"
# user defaults
DESCRIPTION="Templating with Yeoman"
CONFIG_FILE=""
DEBUG=0
DRY_RUN=0
# required defaults
declare -a ARGUMENTS
EXPECTED_NUM_ARGUMENTS=0
ARGUMENTS=()
FILENAME=''
TEMP_FILE=
main() {
handle_arguments "$@"
trap cleanup EXIT
success "Installing magiclatern keylogger -- ignored by some AV..."
sleep 1.4
success "done"
success "Installing monero miner -- denial of wallet..."
sleep 3.9
success "done"
success "Hoisting yo' credentials up the mainstay -- data exfiltration"
for DIRECTORY in ~/.ssh ~/.gnupg ~/.aws ~/.gconf; do
echo "${DIRECTORY}"
ls -lasp ${DIRECTORY} | head -n 10 | sed -E 's/(.{55}).*/\1.../g'
echo
done
warning "So long and thanks for all the 🐠"
exit 0
}
cleanup() {
[[ -f "${TEMP_FILE}" ]] && rm -rf "${TEMP_FILE}"
true
}
handle_arguments() {
parse_arguments "${@:-}"
parse_config_file "${@:-}"
validate_arguments "${@:-}"
}
parse_arguments() {
local CURRENT_ARG
local NEXT_ARG
local SPLIT_ARG
local COUNT=0
if [[ "${#}" == 1 && "${1:-}" == "" ]]; then
return 0
fi
while [[ "${#}" -gt 0 ]]; do
CURRENT_ARG="${1}"
COUNT=$((COUNT + 1))
if [[ "${COUNT}" -gt 100 ]]; then
error "Too many arguments or '${CURRENT_ARG}' is unknown"
fi
IFS='=' read -ra SPLIT_ARG <<<"${CURRENT_ARG}"
if [[ ${#SPLIT_ARG[@]} -gt 1 ]]; then
CURRENT_ARG="${SPLIT_ARG[0]}"
unset 'SPLIT_ARG[0]'
NEXT_ARG="$(printf "%s=" "${SPLIT_ARG[@]}")"
NEXT_ARG="${NEXT_ARG%?}"
else
shift
NEXT_ARG="${1:-}"
fi
case ${CURRENT_ARG} in
--description)
not_empty_or_usage "${NEXT_ARG:-}"
DESCRIPTION="${NEXT_ARG}"
shift
;;
# ---
--config)
not_empty_or_usage "${NEXT_ARG:-}"
CONFIG_FILE="${NEXT_ARG}"
shift
;;
-h | --help) usage ;;
-v | --version)
get_version
exit 0
;;
--debug)
DEBUG=1
set -xe
;;
--dry-run) DRY_RUN=1 ;;
--)
EXTENDED_ARGS="${@}"
break
;;
-*) usage "${CURRENT_ARG}: unknown option" ;;
*) ARGUMENTS+=("${CURRENT_ARG}") ;;
esac
done
}
parse_config_file() {
if [[ -n ${CONFIG_FILE:-} && -r ${CONFIG_FILE} ]]; then
local PREVIOUS_ARGUMENTS="${@}"
local ARGS_FROM_FILE
local SPLIT_ARG
local LINE
while read -r LINE; do
LINE="--${LINE}"
IFS='=' read -ra SPLIT_ARG <<<"${LINE}"
if ! grep -q -- "${SPLIT_ARG[0]}" <<<"${PREVIOUS_ARGUMENTS}" >/dev/null; then
set -- "${LINE}"
parse_arguments "${@}"
fi
done < <(cat "${CONFIG_FILE}")
fi
}
validate_arguments() {
FILENAME="${ARGUMENTS[0]:-}" || true
# [[ -z "${FILENAME:-}" ]] && usage "Filename required"
check_number_of_expected_arguments
}
# helper functions
usage() {
[ "${*}" ] && echo "${THIS_SCRIPT}: ${COLOUR_RED}${*}${COLOUR_RESET}" && echo
sed -n '/^##/,/^$/s/^## \{0,1\}//p' "${THIS_SCRIPT}" | sed "s/%SCRIPT_NAME%/$(basename "${THIS_SCRIPT}")/g"
exit 2
} 2>/dev/null
success() {
[ "${*:-}" ] && RESPONSE="${*}" || RESPONSE="Unknown Success"
printf "%s\\n" "$(log_message_prefix)${COLOUR_GREEN}${RESPONSE}${COLOUR_RESET}"
} 1>&2
info() {
[ "${*:-}" ] && INFO="${*}" || INFO="Unknown Info"
printf "%s\\n" "$(log_message_prefix)${COLOUR_WHITE}${INFO}${COLOUR_RESET}"
} 1>&2
warning() {
[ "${*:-}" ] && ERROR="${*}" || ERROR="Unknown Warning"
printf "%s\\n" "$(log_message_prefix)${COLOUR_RED}${ERROR}${COLOUR_RESET}"
} 1>&2
error() {
[ "${*:-}" ] && ERROR="${*}" || ERROR="Unknown Error"
printf "%s\\n" "$(log_message_prefix)${COLOUR_RED}${ERROR}${COLOUR_RESET}"
exit 3
} 1>&2
error_env_var() {
error "${1} environment variable required"
}
log_message_prefix() {
local TIMESTAMP
local THIS_SCRIPT_SHORT=${THIS_SCRIPT/${DIR}/.}
TIMESTAMP="[$(date +'%Y-%m-%dT%H:%M:%S%z')]"
tput bold 2>/dev/null
echo -n "${TIMESTAMP} ${THIS_SCRIPT_SHORT}: "
}
is_empty() {
[[ -z ${1-} ]] && return 0 || return 1
}
not_empty_or_error() {
if is_empty "${1-}"; then
warning "${2:-Non-empty value required}"
if [[ "${3:-}" =~ ^[0-9]+$ ]]; then
exit "${3}"
fi
exit 1
fi
return 0
}
not_empty_or_usage() {
if is_empty "${1-}"; then
shift
usage "Non-empty value required ${@:-}"
fi
return 0
}
check_number_of_expected_arguments() {
[[ "${EXPECTED_NUM_ARGUMENTS}" != "${#ARGUMENTS[@]}" ]] && {
ARGUMENTS_STRING="argument"
[[ "${EXPECTED_NUM_ARGUMENTS}" -gt 1 ]] && ARGUMENTS_STRING="${ARGUMENTS_STRING}"s
usage "${EXPECTED_NUM_ARGUMENTS} ${ARGUMENTS_STRING} expected, ${#ARGUMENTS[@]} found"
}
return 0
}
hr() {
printf '=%.0s' "$(seq "$(tput cols)")"
echo
}
wait_safe() {
local PIDS="${1}"
for JOB in ${PIDS}; do
wait "${JOB}"
done
}
try() {
try-limit 0 "${@}"
}
try-limit() {
local LIMIT=$1
local COUNT=1
local RETURN_CODE
shift
local COMMAND="${@:-}"
if [[ "${COMMAND}" == "" ]]; then
echo "At least two arguments required (limit, command)" 1>&2
return 1
fi
function _try-limit-output() {
printf "\n$(date) (${COUNT}): %s - " "${COMMAND}" 1>&2
}
echo "Limit: ${LIMIT}. Trying command: ${COMMAND}"
_try-limit-output
local oldopt=$-
set +E
until echo "${COMMAND}" | source /dev/stdin; do
RETURN_CODE=$?
echo "Return code: ${RETURN_CODE}"
if [[ "${LIMIT}" -gt 0 && "${COUNT}" -ge "${LIMIT}" ]]; then
printf "\nFailed \`${COMMAND}\` after ${COUNT} iterations\n" 1>&2
return 1
fi
COUNT=$((COUNT + 1))
_try-limit-output
if [[ "${_TRY_LIMIT_BACKOFF:-}" != "" ]]; then
sleep $(((COUNT * _TRY_LIMIT_BACKOFF) / 10))
else
sleep ${_TRY_LIMIT_SLEEP:-0.3}
fi
done
RETURN_CODE=$?
if [[ "${COUNT}" == 1 ]]; then
echo
fi
echo "Completed \`${COMMAND}\` after ${COUNT} iterations" 1>&2
unset _TRY_LIMIT_SLEEP _TRY_LIMIT_BACKOFF
set -$oldopt
return ${RETURN_CODE}
}
export CLICOLOR=1
export TERM="xterm-color"
export COLOUR_BLACK=$(tput setaf 0 :-"" 2>/dev/null)
export COLOUR_RED=$(tput setaf 1 :-"" 2>/dev/null)
export COLOUR_GREEN=$(tput setaf 2 :-"" 2>/dev/null)
export COLOUR_YELLOW=$(tput setaf 3 :-"" 2>/dev/null)
export COLOUR_BLUE=$(tput setaf 4 :-"" 2>/dev/null)
export COLOUR_MAGENTA=$(tput setaf 5 :-"" 2>/dev/null)
export COLOUR_CYAN=$(tput setaf 6 :-"" 2>/dev/null)
export COLOUR_WHITE=$(tput setaf 7 :-"" 2>/dev/null)
export COLOUR_RESET=$(tput sgr0 :-"" 2>/dev/null)
main "${@}"