-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathexecution_penquin_test.sh
More file actions
executable file
·201 lines (177 loc) · 8.38 KB
/
execution_penquin_test.sh
File metadata and controls
executable file
·201 lines (177 loc) · 8.38 KB
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
#!/bin/bash
# ---------------------------------------------------------------------------
# execution_penquin_test - Bash shell script to test the execution of the Penquin emulation software used for ATT&CK Evaluations Turla Round.
#NOTE: Assumed execution from the Resources folder with sudo permissions
# Copyright 2023 MITRE Engenuity. Approved for public release. Document number CT0005.
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
# This project makes use of ATT&CK®
# ATT&CK Terms of Use - https://attack.mitre.org/resources/terms-of-use/
# ---------------------------------------------------------------------------
PROGNAME=${0##*/}
VERSION="1.0"
TESTNUMBER=0
# PRETTIFY
# success/fail colors
GREEN='\033[1;32m'
PINK='\033[1;31m'
# other
CYAN='\033[1;36m'
PURPLE='\033[1;35m'
NC='\033[0m' # No Color
# This script requires root. If not root or executing as sudo, it will exit.
if [ "$EUID" -ne 0 ]
then printf "\n${PINK}Please level up as root or use sudo\n\nTerminating...\n\n\n"
exit
fi
printf "
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::___::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::-' \`-::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::-' \`::::::::::::::::
:::::::::::::::::::::::::::::::::::::::- ' ${PINK}_o)${NC} \`:::::::::::::::
:::::::::::::::::::::::::::::::::::-' | ${PINK}//\ ${NC} :::::::::::::::
::::::::::::::::::::::::::::::::- . ${PINK}V_/_${NC} ,::::::::::::::
::::::::::::::::::::::::::::-' . ,::::::::::::::::
:::::::::::::::::::::::::-' `-`.___.-::::::::::::::::::
:::::::::::::::::::::-' _,,-::::::::::::::::::::::::::
::::::::::::::::::-' _,--:::::::::::::::::::::::::::::::
::::::::::::::-' _.--:::::::::::::::::::::::#####::::::::
:::::::::::-' _.--::::::::::::::::::::::::::::#####:::::###
::::::::' ## ###.-:::::::###::::::::::::::::::::::#####:::::###
::::-' _##_.::###:::::::::###::::::::::::::#####:##########:::##
:' .:###:::#####::::::::###::::::::::::::#####:##########:::##
...--:::###::#######:::::::###:::::######:::#####:##########:::##
_ .--::##::::###:#########::::::###:::::######:::#####:###############
'#########::::###:##########:::#######:::######:::#####:###############
'#########:::################:#########::######:::#####################
##########:::##########################::##############################
##########:::##########################################################
##########:::##########################################################
#######################################################################
#######################################################################
#######################################################################
#######################################################################
------------------------------------------------
Gotham: https://asciiart.website/index.php?art=comics/batman
Paranoid Penguin: https://jr.co.il/humor/ascii-art-penguin.txt
------------------------------------------------
\n
"
# HELPER FUNCTIONS
#######################################
# check_file_exists
# Helper fuction that uses Linux test function to print if a file exists or does not exists
# ERROR: print statement for failed test
#######################################
function check_file_exists () {
if test -x "$1"; then
printf "${CYAN}$1 exists & has executable permissions${NC}\n"
elif test -a "$FILE"; then
printf "${CYAN}$1 exists but does not have executable permissions${NC}\n"
else
printf "${PINK}$1 does not exist${NC}\n"
fi
}
# same fucntion as above but flipped for removal of files
function check_file_rm () {
if test -f "$1"; then
printf "${PINK}$1 exists${NC}\n"
else
printf "${GREEN}✔ $1 does not exist${NC}\n"
fi
}
#######################################
# check_exit_code
# Helper fuction that evaluates the exit code of the last run command
# ERROR: print statement for failed test
#######################################
function execute () {
# read the command from an arguement
$1
if [ $? -eq 0 ]; then
printf "${GREEN}✔ Success:${NC} $1\n"
else [ $? -eq 0 ]
printf "${PINK}ERROR: $1${NC}\n"
fi
}
printf "${CYAN}=========================================================\n"
printf "${CYAN}Beginning Tests${NC}\n"
printf "${CYAN}=========================================================\n"
# =========================================================================
# Setups and Tear Downs
# =========================================================================
printf "${NC}Setting up installation....\n${NC}\n"
# Move penquin to /root folder
execute "cp ./hsperfdata /root/hsperfdata"
sleep 1
# unzip penquin
sh -c 'cd /root/ && unzip -o hsperfdata'
if [ $? -eq 0 ]; then
printf "${GREEN}✔ Success:${NC} $0\n"
else [ $? -eq 0 ]
printf "${PINK}ERROR: $0${NC}\n"
fi
#verity executable file permissions
((TESTNUMBER++))
FILE=/root/hsperfdata
if test -x "$FILE"; then
printf "${GREEN}Test $TESTNUMBER Success!${CYAN} $FILE exists & has executable permissions${NC}\n"
elif test -a "$FILE"; then
printf "${PINK}Test $TESTNUMBER Fail: $FILE exists but does not have executable permissions${NC}\n"
else
printf "${PINK}Test $TESTNUMBER Fail: $FILE does not exist${NC}\n"
fi
sleep .5
# Execute Penquin in a separate process so that it doesn't affact the current script test
printf "${Purple}Executing...(for 8 seconds)...\n"
execute `sh -c 'cd /root/ && ./hsperfdata'`
# =========================================================================
# Tests
# =========================================================================
printf "=========================================================\n"
printf "[${CYAN}Test 1${NC}]: Installation Check\n"
printf "=========================================================\n"
# Penquin installer checked during installation
printf "${NC}Testing dropped files....\n${NC}"
# cron executable (BPF listener)
check_file_exists /usr/bin/cron
# cron service file
check_file_exists /etc/systemd/system/cron.service
printf "=========================================================\n"
printf "[${CYAN}Test 2${NC}]: Execution Checks\n"
printf "=========================================================\n"
printf "${NC}Checking cron service status...${NC}\n"
# Check cron status
((TESTNUMBER++))
SERVICE="cron"
if (systemctl is-active --quiet $SERVICE); then
printf "${GREEN}Test $TESTNUMBER Success!${CYAN} $SERVICE is running${NC}\n"
else
printf "${PINK}Test $TESTNUMBER Fail: $SERVICE is dead${NC}\n"
fi
# Check for process group id specific to where we expect our malicious cron to run
printf "checking for running cron process from ${PURPLE}usr/bin${NC} rather than ${PURPLE}usr/sbin${NC}...\n"
processID=0
processID=$(ps axo pgid,command | grep -i '/usr/bin/cron -f' | grep -v grep | awk '{print $1;exit;}')
((TESTNUMBER++))
if [ $processID -ne 0 ];then
printf "${GREEN}Test $TESTNUMBER Success! Cron is running under PGID: ${CYAN}$processID${NC}\n"
else
printf "${PINK}Test $TESTNUMBER Fail: No PGID returned${NC}\n"
fi
printf "checking raw socket connection...\n"
# Check secure for active raw sockets with cron running
((TESTNUMBER++))
if ss -l -a -n -p | awk '/p_raw/ && /cron/' &> /dev/null;then
printf "${GREEN}Test $TESTNUMBER Success! A raw socket is running with cron active${NC}\n"
else
printf "${PINK}Test $TESTNUMBER Fail: No sockets are open that are both cron & raw sockets${NC}\n"
fi
# =========================================================================
# End of all tests
# =========================================================================
printf "=========================================================\n"
printf "[${CYAN}All Tests Complete${NC}]\n"
printf "=========================================================\n"