0Day Forums
can I implement a kill switch into a .bat fork bomb? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: .bat & .wsf & .cmd (https://0day.red/Forum-bat-wsf-cmd)
+--- Thread: can I implement a kill switch into a .bat fork bomb? (/Thread-can-I-implement-a-kill-switch-into-a-bat-fork-bomb)



can I implement a kill switch into a .bat fork bomb? - fossilation165078 - 07-23-2023

I want to show a friend how big the impact of a fork bomb can be on performance, but without needing to restart the computer afterwards.

Assuming the following fork bomb:

%0|%0

Is there a way to add a kill switch to this which, with one button press, will stop all running copies of this file, stop any new from being created and hopefully save the machine? I'm not really familiar with the command prompt syntax, so I'm not sure.


RE: can I implement a kill switch into a .bat fork bomb? - avra872 - 07-23-2023

Two ideas:

a) limit the depth your "bomb" is going to fork:

@echo off
set args=%*
if "%args%" EQU "" (set args=0) else set /a args=%args%+1
if %args% LSS 8 start /min thisfile.bat

(this will produce 2^9 -1 command windows, but only your main window is open.)

b) kill the cmd.exe process in the main batch file

@echo off
SET args=%*
:repeat
start /min thisfile.bat.bat some_arg
if "%args%" NEQ "" goto repeat
pause
taskkill /im cmd.exe

pressing any key in the initial batch file will instamntly kill all cmd windows currently open.

These solutions were tested with some restrictions, so if they work in a "hot" forkbomb, please let me know.

hope this helps.

**EDIT:**

c)implement a time switch in the original bat:
(still stops even if you can't get past `pause`)

@echo off
set args=%*
:repeat
start /min thisfile.bat some_arg
if "%args%" NEQ "" goto repeat
timeout /T 10
taskkill /im cmd.exe

or, using the smaller "bomb":

@echo off
set args=%*
if "%args%" NEQ "" (%0 some_arg|%0 some_arg) else start /min thisfile.bat some_arg
timeout /T 10
taskkill /im cmd.exe



RE: can I implement a kill switch into a .bat fork bomb? - Sirkaunas7 - 07-23-2023

If you're out to just show your friend fork bombs why not go for a silent but deadly approach? The fork bomb is in vbs, the cleanup is in batch.
Do note, the vbs fork bomb does nothing turning your pc off/on wont fix, it just floods your session proccess's.

The fork bomb:

Do until true = false
CreateObject("Wscript.Shell").Run Wscript.ScriptName
Loop
[Source](

[To see links please register here]

)

Cleanup:


title=dontkillme
FOR /F "tokens=2 delims= " %%A IN ('TASKLIST /FI ^"WINDOWTITLE eq
dontkillme^" /NH') DO SET tid=%%A
echo %tid%
taskkill /F /IM cmd.exe /FI ^"PID ne %tid%^"

[Source](

[To see links please register here]

)



RE: can I implement a kill switch into a .bat fork bomb? - sheeters827465 - 07-23-2023

If it runs in an accessible directory, you could try

IF EXIST kill.txt (exit /b) ELSE (%0|%0)
and make a file called kill.txt in the directory to stop the bomb.