This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
functions
executable file
·247 lines (203 loc) · 6.71 KB
/
functions
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
#!/bin/bash
###################################################################
# Prey Windows Specific Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################
run_as_current_user(){
if [ "$(whoami)" == "SYSTEM" ]; then
userrun $1
else # username exists
eval $1
fi
}
############################################
# verification stuff
############################################
verify_installation(){
# check prey service on
log " -- Checking if Prey's cron service is running..."
if [ -n `is_process_running "cronsvc.exe"` ]; then
log " -- Cron service up and running. Good."
elif [ -n `is_process_running "cron.exe"` ]; then
log " -- Cron.exe up. You're OK, but you should switch to System mode, otherwise auto-updating won't work!"
else
log " !! Cron service not found! Please make sure no antivirus is blocking cron.exe from running. Optionally reinstall. :)"
fi
# check net framework
log ' -- Checking for installed .NET Framework...'
if [ -n "`is_net_framework_installed`" ]; then
log " -- Required .NET version $required_net_version or newer is installed. All good."
else
log " !! .NET framework version $required_net_version or newer not installed!"
fi
}
# returns 1 if it is
is_net_framework_installed() {
local version=`echo $required_net_version | sed 's/\..\./\./'`
local results=`reg query "HKLM\Software\Microsoft\NET Framework Setup\NDP" | sed -e '1,2d' -e 's/[^0-9.]//g' | grep -v "^$"`
for result in `echo -e "$results"`; do
if [[ "$result" == "$version" || `is_greater_than $result $version` == 1 ]]; then
echo 1
break
fi
done
}
############################################
# core network functions
############################################
# used only in network module. system module gets the MAC from wmic
get_mac_address() {
ifconfig //all | grep MAC | sed 's/^.*: //g'
}
# gets all ip addresses or the one from NIC matching a specific MAC
get_ip_address() {
if [ -n "$1" ]; then
ifconfig //all | grep "$1" -A1 | grep "IP" | sed "s/.*:\([0-9\.]*\) .*/\1/"
else # get all ip addresses
ifconfig //all | grep "IP" | sed "s/.*:\([0-9\.]*\) .*/\1/g"
fi
}
# gets all netmasks or the one matching a specific MAC
get_netmask(){
if [ -n "$1" ]; then
ifconfig //all | grep "$1" -A2 | grep "Mask" | sed "s/.*:\([0-9\.]*\) .*/\1/"
else # get all netmasks
ifconfig //all | grep "Mask" | sed "s/.*:\([0-9\.]*\) .*/\1/g"
fi
}
# gets all netmasks or the one matching a specific MAC
get_gateway_ip() {
if [ -n "$1" ]; then
ifconfig //all | grep "$1" -A3 | grep "Gateway" | sed "s/.*:\([0-9\.]*\) .*/\1/"
else # get all netmasks
ifconfig //all | grep "Gateway" | sed "s/.*:\([0-9\.]*\) .*/\1/g"
fi
}
get_system_proxy(){
# remove everything before the http:
proxycfg | grep "Proxy Server" | sed "s/.*http/http/g"
}
get_wifi_info() {
if [ -n "$winxp" ]; then
wifi_info=`autowcxp.exe -list`
else
if [ "`is_net_framework_installed`" == 1 ]; then
wifi_info=`autowc.exe -list`
else
log " !! .NET framework version $required_net_version or newer not installed!"
fi
fi
}
try_to_connect() {
if [ "`is_net_framework_installed`" == 1 ]; then
autowc.exe -connect 2> /dev/null
else
log " !! .NET framework version $required_net_version or newer not installed!"
fi
}
on_demand_stdin(){
local sleep_interval=2
local last_msg=""
while sleep $sleep_interval; do
[ ! -e "$on_demand_pipefile" ] && break
local new_msg=`tail -1 "$on_demand_pipefile"`
[ "$new_msg" != "$last_msg" ] && echo "$new_msg"
last_msg="$new_msg"
done
}
############################################
# module functions
############################################
# transforms integer into miliseconds, assuming integer is a minute
get_delay_for(){
echo $(($1*60*1000))
}
get_random_minute_delay(){
get_delay_for 60
}
# returns 1 if delay is set to regular one-hour interval
one_hour_interval(){
[ "$current_delay" == "$(get_delay_for 60)" ] && echo 1
}
get_current_delay(){
reg query "$prey_reg_key" //v "Delay" | grep Delay | sed "s/[^0-9]*//"
}
update_execution_delay(){
reg add "$prey_reg_key" //v "Delay" //d "$1" //f > /dev/null
}
############################################
# module functions
############################################
is_module_active(){
cat "$base_path/modules/$1/active" 2> /dev/null
}
############################################
# dummy trigger enabling functions
# not needed as the trigger is bundled with Prey's CronService
############################################
# echoes 1 if it is
is_trigger_loaded(){
echo 1
}
reload_trigger(){
return 0
}
unload_trigger(){
return 0
}
############################################
# updater-specific functions
############################################
reset_permissions(){
log ' -- Resetting permissions...'
if [ -n "$winxp" ]; then
local command="echo y| cacls.exe"
local readonly="//t //c //p Everyone:r //g Administrators:f"
local fullaccess="//t //c //p Everyone:f"
else
local command='Icacls.exe'
local readonly="//T //C //grant Everyone:R"
local fullaccess="//T //C //grant Everyone:F"
fi
# perhaps we should iterate over the diff file and only apply this on the
# modified files, but seems like overkill to me -- Tomas
eval $command \"$base_path/*\" "$readonly" &> /dev/null
eval $command \"$base_path/prey.log\" "$fullaccess" &> /dev/null
# eval $command \"$platform_path\tmp\" "$fullaccess" &> /dev/null
}
# this runs in the context of the new process, already daemonized
pre_update_hook(){
# stop the cron service
TASKKILL //F //IM cronsvc.exe //T &> /dev/null
# we also need to make sure the configurator is not running, so we can
# also update it in case its necessary
local configurator_running=`is_process_running 'prey-config.exe'`
if [ -n "$configurator_running" ]; then
log ' -- Forcing shutdown of Prey Configurator... Sorry!'
TASKKILL //F //IM prey-config.exe //T &> /dev/null
fi
return 0
}
# lets restart prey so it refreshes with the new status
post_update_hook(){
reset_permissions
log ' -- Restarting Prey Cron Service...'
net start CronService
}
############################################
# Device creation parameters
############################################
get_current_hostname(){
reg query "HKLM\System\CurrentControlSet\Control\ComputerName\ComputerName" | grep ComputerName | tail -1 | awk '{print $3}'
}
get_pc_info(){
pc_name=$(get_current_hostname)
local chassis_type=`echo 'systemenclosure get ChassisTypes' | wmic 2> /dev/null | grep '{' | sed 's/[^0-9]//g'`
if [[ $chassis_type == "8" || $chassis_type == "9" || $chassis_type == "10" || $chassis_type == "11" || $chassis_type == "14" ]]; then
pc_type="Laptop"
else
pc_type="Desktop"
fi
rm -f "$base_path/TempWmicBatchFile.bat" 2> /dev/null
}