-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.lua
389 lines (334 loc) · 10 KB
/
test.lua
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
local av = {}
-- https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/OS.lua
-- Neļaut OCAV ielādēties vēlreiz
if computer["\xFFOCAV_LOADED\xFF"] and computer["\xFFOCAV_LOADED\xFF"] == true then return {load = function() return false end} end
av.load = function(consent,fs,efi,inet)
local fsf = {} for a,b in pairs(fs) do fsf[a] = b end
local eff = {} for a,b in pairs(efi) do eff[a] = b end
inet = nil --if inet ~= nil then local inf = {} for a,b in pairs(inet) do inf[a] = b end end
local ocav_getver = function() return "1" end
local oldpull = computer.pullEvent
local oldpush = computer.pushEvent
local x = function()
local newpull = function(...)
local a, b = pcall(function()
x()
if _G.OCAV_GetVersion ~= ocav_getver then computer.pushEvent("ocav","functionOverwrite","getVersion") _G.OCAV_GetVersion = ocav_getver end
return oldpull(...)
end)
if a ~= nil then return b else return {"ocav", "error", b} end
end
x = function()
if computer.pullEvent ~= newpull then computer.pushEvent("ocav","functionOverwrite","pullEvent") computer.pullEvent = newpull end
if computer.pushEvent ~= oldpush then computer.pushEvent("ocav","functionOverwrite","pushEvent") computer.pullEvent = oldpush end
end
computer["\xFFOCAV_LOADED\xFF"] = true
-- Noņem OCAV no package.loaded
package.loaded["antivirus"] = nil
local systemFiles = {
"/.OCAV";
"/OS.lua";
"/Libraries";
"/Users";
"/MineOS";
"/Icons";
"/Extensions";
"/Localizations";
"/Mounts/" .. tostring(fsf.address);
}
local exclusions = {
"/Applications";
"/Versions.cfg";
}
-- Ielikt exclusions tabulā visas mapes mapē /Users
for i = 1, #fsf.list("/Users/") do
table.insert(exclusions, "/Users/" .. fsf.list("/Users/")[i])
end
-- Padarīt tā, ka fs.list "/" atgriež visu izņemot ".OCAV"
fs.list = function(path)
local list = fsf.list(path)
for i,v in ipairs(list) do
if v == ".OCAV" then
table.remove(list,i)
break
end
end
if path == "/" then
list[#list+1] == ".OCAV_Temp"
end
return list
end
fs.open = function(path,mode)
local mustAskForConsent = false
-- Ja path sākas ar jebko no systemFiles, bet ne no exclusions, tad mustAskForConsent = true
for i,v in pairs(systemFiles) do
if string.sub(path,1,#v) == v then
mustAskForConsent = true
break
end
end
for i,v in pairs(exclusions) do
if string.sub(path,1,#v) == v then
mustAskForConsent = false
break
end
end
local allowed = true
if path == "" or "/" then mustAskForConsent = true end
if mustAskForConsent == true then
-- nejautāt priekš atļaujas, ja mode ir r vai rb
local allowed = false
if mode == "r" then
allowed = true
else
allowed = false
allowed = consent("Program wants to open file "..path.." for writing. Allow?")
end
end
if allowed == true then
return fsf.open(path,mode)
else
return nil
end
end
-- Tā pat ar fs.makeDirectory
fs.makeDirectory = function(path)
local mustAskForConsent = false
-- Ja path sākas ar jebko no systemFiles, bet ne no exclusions, tad mustAskForConsent = true
for i,v in pairs(systemFiles) do
if string.sub(path,1,#v) == v then
mustAskForConsent = true
break
end
end
if path == "/" or "" then mustAskForConsent = true end
for i,v in pairs(exclusions) do
if string.sub(path,1,#v) == v then
mustAskForConsent = false
break
end
end
local allowed = true
if mustAskForConsent == true then
-- nejautāt priekš atļaujas, ja mode ir r vai rb
local allowed = false
-- pārbaudīt, vai mape jau eksistē izmantojot fsf.isDirectory(path)
if fsf.isDirectory(path) == true then
allowed = true
else
allowed = false
allowed = consent("Program wants to create folder "..path..". Allow?")
end
end
if allowed == true then
return fsf.makeDirectory(path)
else
return nil
end
end
-- un fs.remove
fs.remove = function(file)
local mustAskForConsent = false
-- Ja path sākas ar jebko no systemFiles, bet ne no exclusions, tad mustAskForConsent = true
for i,v in pairs(systemFiles) do
if string.sub(file,1,#v) == v then
mustAskForConsent = true
break
end
end
for i,v in pairs(exclusions) do
if string.sub(file,1,#v) == v then
mustAskForConsent = false
break
end
end
local allowed = true
if path == "" or "/" then mustAskForConsent = true end
if mustAskForConsent == true then
-- nejautāt priekš atļaujas, ja mode ir r vai rb
local allowed = false
allowed = consent("Program wants to delete file "..file..". Allow?")
end
if allowed == true then
return fsf.remove(file)
else
return nil
end
end
-- un fs.rename
fs.rename = function(oldName,newName)
local mustAskForConsent = false
-- Ja path sākas ar jebko no systemFiles, bet ne no exclusions, tad mustAskForConsent = true
for i,v in pairs(systemFiles) do
if string.sub(oldName,1,#v) == v then
mustAskForConsent = true
break
end
end
if path == "/" or "" then mustAskForConsent = true end
for i,v in pairs(exclusions) do
if string.sub(oldName,1,#v) == v then
mustAskForConsent = false
break
end
end
local allowed = true
if mustAskForConsent == true then
-- nejautāt priekš atļaujas, ja mode ir r vai rb
local allowed = false
allowed = consent("Program is trying to rename file "..oldName.." to "..newName..". Allow?")
end
if allowed == true then
return fsf.rename(oldName,newName)
else
return nil
end
end
-- Aizsargāt EEPROM
efi.set = function(value)
-- Jautāt, priekš atļaujas
local allowed = consent("Program is trying to write to EEPROM. Allow?")
if allowed == true then
return eff.set(value)
else
return nil
end
end
-- tā pat ar efi.setLabel
efi.setLabel = function(value)
-- Jautāt, priekš atļaujas
local allowed = consent("Program wants to change EEPROM name. Allow?")
if allowed == true then
return eff.setLabel(value)
else
return nil
end
end
-- un efi.makeReadonly
efi.makeReadonly = function(checksum)
-- Jautāt, priekš atļaujas
local allowed = consent("Program is trying to make EEPROM readonly. Allow?")
if allowed == true then
return eff.makeReadonly(checksum)
else
return nil
end
end
-- Aizsargāt datoru no OCHammer 2 un citu vīrusu lejupielādes
local blockedRootURLs = {
{"https://raw.githubusercontent.com/ocboy3/OC/main/OCHammer.app","OCHammer"};
{"https://raw.githubusercontent.com/ocboy3/OC/main/OCHammer2.app","OCHammer 2"};
{"https://raw.githubusercontent.com/KKosty4ka/Solaris", "Solaris virus"};
{"https://raw.githubusercontent.com/KKosty4ka/ScamDisk", "ScamDisk"};
{"https://raw.githubusercontent.com/Jack5079/opencomputers/master/SysFucked%20Slient.app", "SysFucked Silent"};
{"https://raw.githubusercontent.com/Jack5079/opencomputers/master/SysFucked.app", "SysFucked"};
{"https://raw.githubusercontent.com/Jack5079/opencomputers/","program(s) from a malicious repo that got flagged by OCAV"};
}
local fakeTCPObject = {
read = function(n)
return "Blocked by OCAV"
end;
close = function()
return
end;
write = function(s)
return
end;
finishConnect = function()
error("Blocked by OCAV")
end;
id = function()
return -1
end;
}
local fakeHTTPObject = {
read = function(n)
return "Blocked by OCAV"
end;
close = function()
return
end;
response = function()
return 404
end;
finishConnect = function()
error("Blocked by OCAV")
end;
}
local lastVirusDownloadTime = -9999
local virusDownloadTime = 5
if inet ~= nil then
local function isDownloadAllowed()
-- atgriezt true, ja starpība lastVirusDownloadTime un os.time() ir mazāka vai vienāda par 5 sekundēm
return (os.time() - lastVirusDownloadTime) >= virusDownloadTime
end
inet.connect = function(adress, port)
-- pārbaudīt, vai adress nav bloķēts/a
local blocked = false
local virus = ""
for i,v in pairs(blockedRootURLs) do
if string.sub(adress,1,#v[1]) == v[1] then
virus = v[2]
blocked = true
break
end
end
-- ja adress ir bloķēta, tad jautāt lietotājam, vai atļaut lejupielādi
if blocked == true then
if isDownloadAllowed() == true then
-- atļaut lejupielādi
return inf.connect(adress, port)
else
-- jautāt lietotājam, vai atļaut lejupielādi
local allowed = consent("Program wants to download "..virus..". Allow?")
if allowed == true then
-- atļaut lejupielādi
lastVirusDownloadTime = os.time()
return inf.connect(adress, port)
else
-- neatļaut lejupielādi
error("Blocked by OCAV")
end
end
else
-- adress nav bloķēta
return inf.connect(adress, port)
end
end
inet.request = function(url, postdata, headers)
-- pārbaudīt, vai url nav bloķēta/a
local blocked = false
local virus = ""
for i,v in pairs(blockedRootURLs) do
if string.sub(url,1,#v[1]) == v[1] then
virus = v[2]
blocked = true
break
end
end
-- ja url ir bloķēta, tad jautāt lietotājam, vai atļaut lejupielādi
if blocked == true then
if isDownloadAllowed() == true then
-- atļaut lejupielādi
return inf.request(url, postdata, headers)
else
-- jautāt lietotājam, vai atļaut lejupielādi
local allowed = consent("Program is trying to download "..virus..". Allow?")
if allowed == true then
-- atļaut lejupielādi
lastVirusDownloadTime = os.time()
return inf.request(url, postdata, headers)
else
-- neatļaut lejupielādi
error("Blocked by OCAV")
end
end
else
-- adress nav bloķēta
return inf.request(url, postdata, headers)
end
end
end
return true
end
return av