This repository has been archived by the owner on May 27, 2021. It is now read-only.
/
functions
executable file
·204 lines (172 loc) · 5.43 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
#!/bin/bash
###################################################################
# Prey Windows Specific Functions - by Tomas Pollak (bootlog.org)
# URL: http://preyproject.com
# License: GPLv3
####################################################################
# in windows, prey always runs as the local user
run_as_current_user(){
$1
}
get_pid(){
processes | grep "$1" | sed 's/[a-z\. ]*\([0-9]*\).*/\1/'
}
############################################
# verification stuff
############################################
verify_installation(){
# check prey service on
log " -- Checking if Prey system service is running..."
local cron_running=`is_process_running "cronsvc"`
if [ -n "$cron_running" ]; then
echo " -- Cron system service up and running. Good."
else
echo " !! Cron system service not found! Please make sure no antivirus is blocking Cron Service (cronsvc) from running. Optionally reinstall. :)"
fi
# check net framework
log ' -- Checking for installed .NET Framework...'
if [ "`is_net_framework_installed`" == 1 ]; 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_bigger_than $result $version` == 1 ]]; then
echo 1
break
fi
done
return 0
}
############################################
# core network functions
############################################
get_gateway_ip() {
if [ -z "$gateway_ip" ]; then
gateway_ip=`ipconfig | grep Gateway | sed 's/^.*: //g' | grep -v '^$' | head -1`
fi
}
get_internal_ip() {
if [ -z "$internal_ip" ]; then
internal_ip=`ipconfig | grep "Address" | grep -v "local" | sed 's/^.*: //g' | grep -v '^$' | head -1`
fi
}
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
}
############################################
# module functions
############################################
get_delay_for(){
local delay_var=$(($1*1))
if [ "$delay_var" == "$1" ]; then # integer, minute
echo $(($1*60*1000))
else
case "$1" in
"hourly")
echo 3600000 # 60 * 60 * 1000
;;
"daily")
echo 86400000 # 24 * 60 * 60 * 1000
;;
"weekly")
echo 604800000 # 7 * 24 * 60 * 60 * 1000
;;
# "monthly")
# echo 18144000000 # 30 * 7 * 24 * 60 * 60 * 1000
# ;;
esac
fi
}
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 "$new_delay" //f > /dev/null
}
############################################
# module functions
############################################
is_module_active(){
cat "$base_path/modules/$1/active" 2> /dev/null
}
############################################
# 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
}
pre_update_hook(){
# stop the cron windows 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 $?
}
# lets restart prey so it refreshes with the new status
post_update_hook(){
reset_permissions
log ' -- Reloading Prey...'
net start "Cron Service for Prey"
}
############################################
# Device creation parameters
############################################
get_pc_info(){
pc_name=`hostname`
if [ -n "$winxp" ]; then
pc_os_version="xp"
else
local pc_os_number=`echo 'os get caption' | wmic 2> /dev/null | grep -i 'microsoft'`
if [[ -n `echo "$pc_os_number" | grep -i 'vista'` ]]; then
pc_os_version="vista"
else
pc_os_version="7"
fi
fi
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="Portable"
else
pc_type="Desktop"
fi
}