3 ms·
The .js script isn't injecting code into another program in order to deletee itself; it is deleeting itself directly. It can do that because, I'm guessing, the
by kazinator 3y ago
The .js script isn't injecting code into another program in order to deletee itself; it is deleeting itself directly.
It can do that because, I'm guessing, the file isn't open; the run-time isn't executing instructions from that file. The file was read, the content compiled into memory, and closed.
The script is deleting its source code, not itself. What actually deletes the script itself is the garbage collector in the run-time. Once the fso.Deletefile call and the for loop are executed, they are no longer reachable and so they are garbage. If there is a way for the "var fso" and "var path" variables to go out of scope, they become garbage also.
A binary executable is mapped into memory while the process is running it. In Windows, an open file cannot be deleted.
But, even on Windows, a prog.exe could delete the prog.c source code it was compiled from, right? Same thing, sort of.
- masfuerte 3y agoBeing pedantic, you can delete open files on Windows if you open them with FILE_SHARE_DELETE.
- sim7c00 3y agoThe script doesn't inject. But a lot of malware downloads a script and runs it, so you'd hit another rule.
- kazinator 3y agoThe way I understand it, the uninstaller program that wants to delete itself doesn't have to download the script from anywhere; it generates the script out to a file.
- sim7c00 3y agothis is true, a good heuristic would see the difference perhaps. but malicious scripts can also be generated rather than downloaded (or more commonly decrypted from some seemonly random data) so it can be hard to tell, especially given threat actors having access to security products easily while the opposite is not always true.
- dmazzoni 3y agoIs the behavior that a running .js script is fully loaded into memory and the file doesn't need to exist documented, supported behavior? What if, hypothetically, the system was suspended in the middle of script execution, and the resume function was designed to reload the script from disk? It just feels like a different hack to me. Also - trying 20 times and pausing 500 ms seems wasteful. What are the chances that it's going to succeed a subsequent try if it fails the first try? Why not catch the error message and only retry for errors that have a plausible chance of succeeding if you retry?
- omnicognate 3y ago> Is the behavior that a running .js script is fully loaded into memory and the file doesn't need to exist documented, supported behavior? If Raymond Chen says to rely on it then yes.
- sim7c00 3y agoeven though i admot this guy is genious level, its not really good to rely on one persons judgement for anything. thats a bad practice in general. zerotrust and all :)
- chrchang523 3y agoAgree, I'm shocked at how ugly the recommended alternative is. This does not make MS look good.
- Arainach 3y agoThere are plenty of other solutions; that was merely one straightforward option that could be shown in a few lines of code and which doesn't require *injecting code into a binary you don't own*.
- chrchang523 3y agoSure, but there isn't even an offhand remark about how hacky this kind of polling is. It's presented as if it's a completely normal way to do things in reliable software.