Usefull Batch Files
#1
As the title says. I'll start.

This Batch File blocks in/out connections of a software to the softwares home servers.

This batch file will place itself into the softwares install directory once ran. When Y or N commands have been completed. It'll add Windows FireWall rules and then delete itself from the softwares installation directory.

This is in no way my creation. It's been taken from multiple sources, refined, checked. Then checked again. The recursive or "drill down" ability is solely down to one person (And won't be added if this thread doesn't find legs).

Anyway. Here's the content of the file. Obviously you need to replace the Software install path goes between the exclamation marks needs to be replaced with the actual softwares installation path. E.g.:

C:\Program Files\ESET\ESET Endpoint Antivirus

This install path will be placed three times and within the "", exclamation marks.

Code:
@ echo off
@copy %0 "Software install path goes between the exclamation marks"
@setlocal enableextensions
@cd "Software install path goes between the exclamation marks"
color 06
title LowOrbit - FatElvis UA-07 FireWall LazyBoy
echo.
echo.           ============================================================
echo.
echo.           =========         Windows Firewall LazyBoy         =========
echo.
echo.           ========= Your 1 Stop Application FireWall Blocker =========
echo.
echo.           =========      A LowOrbit - FatElvis Release       =========
echo.
echo.           ====  File Refined For Recursiveness And Other Shit By  ====
echo.
echo.           ======================    UA-07    =========================
echo.
echo.           ============================================================
echo.
echo.
echo.
echo.
Echo Current location: %cd%
echo.
echo.
echo.
CHOICE /C YN /M "Do you want to search for executables in the current location?"
IF Errorlevel 2 goto END
IF Errorlevel 1 goto Yes




::--------------------CHECK and searching files-----------------
:Yes
set location=%cd%
cls
echo.
Echo. Searching for .exe files in %location%
echo.
set /a count=0
echo.___________________________________________
echo.Found:
echo.
FOR  %%i in (*.exe) do (echo. %%i & set /a count+=1)
echo.___________________________________________
echo.
title LowOrbit - FatElvis - UA-07 FireWall LazyBoy %count% Files found
echo.          Number of files found with the .exe extention: %count%
echo.
echo.
set add2=

CHOICE /C YN /M        "Do you want to add additional information?"
IF Errorlevel 2 goto block
IF Errorlevel 1 goto ADD

::-----------------ADD additional info---------------
:ADD
Set /p add=Please type the additonal information for the name:
Set add2=%add%

::-----------------Add files to firewall--------------
:block
cls
title LowOrbit / Fat_Elvis / UA-07 FireWall LazyBoy - Blocking Rules
set /a countt=0
echo.
echo.___________________________________________
echo. Inbound Rules
echo.___________________________________________
FOR /r %%B in (*.exe) do (set /a countt+=1 & echo.%countt%. %%~nxB blocking... & netsh advfirewall firewall add rule name="%add2%%%~nxB" dir=in action=block program="%%~dpfnxB")
echo.___________________________________________
echo. OutBound rules
set /a coun=0
echo.___________________________________________
FOR /r %%B in (*.exe) do (set /a coun+=1 & echo.%coun%. %%~nxB blocking... & netsh advfirewall firewall add rule name="%add2%%%~nxB" dir=out action=block program="%%~dpfnxB")
echo.___________________________________________
Echo. Added files to Windows FireWall
echo.
title LowOrbit / Fat_Elvis / UA-07 FireWall LazyBoy locked
Pause

::------------------------END---------------------

:END
cls
ECHO.
Echo. Thanks for using LowOrbit / Fat_Elvis / UA-07 FireWall LazyBoy
Echo.

CHOICE /C YN /T 10 /D n /M "Do you want to open Windows FireWall? (10 seconds)"
IF Errorlevel 2 goto EXIT
IF Errorlevel 1 goto OPEN

::------------------Open Firewall---------------
:OPEN
start "C:\Windows\System32" rundll32.exe shell32.dll,Control_RunDLL firewall.cpl
Goto EXIT


:EXIT

start /b "" cmd /c del "Software install path goes between the exclamation marks\BlockInFireWall.bat"&exit /b

Save as FireWallLazyBoy.bat

Feel free to edit/MOD this in any way you want as like i said, it's not my work. Just our modifying.

Direct download of the file:

https://www.mirrorcreator.com/files/GYMA....bat_links


NOW POST YOUR USEFUL BATCH FILES AND SHARE
Reply
#2
I got one which Compresses stuff!s

Code:
@echo off
Title WonDERkIDO
echo  Repacking
echo
echo
echo
echo
echo
pause
@echo Working Arc+Precomp+Srep+Arc again
arc a -lc8 -ep1 -ed -p512 -hp -r -w.\ Data\Data.cab -msrep+delta+lzma:a1:mfbt4:d858m:fb273:mc888888:lc8 "Directory"
pause

You Need Arc + Srep files
Reply
#3
Enable or Disable your Network Adapters.

Disable Network Adapters:

Save this in Notepad as DisableAdapters.bat:

Code:
netsh interface set interface "Local Area Connection" DISABLE
netsh interface set interface "Wireless Network Connection" DISABLE

Enable Network Adapters:

Save this in Notepad as EnableAdapters.bat:

Code:
netsh interface set interface "Local Area Connection" ENABLE
netsh interface set interface "Wireless Network Connection" ENABLE
Reply
#4
Ahh bat files, one piece of obsolete'ish tech that I absolutely love to challenge myself with.

My rules are usually pretty simple, the bat file needs to be able to be ran on a vanilla install of Windows (~ XP'ish or later). I assume an internet connection is available.

Here are some functions I wrote/gathered and use quite often to download dependencies, unzip files, check if current cmd.exe is running under elevated UAC context, prompt for UAC elevation if needed, etc:

Code:
:: downloadFile
:: -arg1 url
:: -arg2 file path
:: -arg3 [optional] job name for bitsadmin
:downloadFile
setlocal EnableDelayedExpansion
 set "url=%~1"
 set "saveTo=%~2"
 set "jobName=%~3"
 if [%jobName%]==[] (set "jobName=DL")
 
 call :isCommandAvailable wgetFound wget.exe
 call :isCommandAvailable psFound powershell.exe
 call :isCommandAvailable bitsFound bitsadmin.exe
 
 if [%wgetFound%]==[0] (
 if [%bitsFound%]==[0] (
 if [%psFound%]==[0] (
   call :echoError "Wget.exe or BitsAdmin.exe is required to support downloading"
   call :halt  
   goto :eof
 )
 )
 )
 
 if /i [%_defaultDownloader%]==[WGET] (
   if [%wgetFound%]==[1] ( goto :downloadWithWget ) else ( goto :downloadWithBitsAdmin )
 ) else if /i [%_defaultDownloader%]==[PS] (
   if [%psFound%]==[1] ( goto :downloadWithPowershell ) else ( goto :downloadWithBitsAdmin )
 ) else (
   if [%bitsFound%]==[1] ( goto :downloadWithBitsAdmin ) else ( goto :downloadWithWget )
 )

 :downloadWithWget
   wget.exe !url!
   goto :return
   
 :downloadWithPowershell
   powershell -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('!url!', '!saveTo!'))"
   goto :return

 :downloadWithBitsAdmin
   bitsadmin.exe /transfer %jobName% /download /priority high !url! !saveTo!
   goto :return

 :return
endlocal
goto :eof

:: unzipFile: Unzip specified file into the specified output folder
:: -arg1 file path to zip
:: -arg2 folder path to output
:: https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx
:unzipFile
setlocal
 set zipFilePath=%~1
 set destPath=%~2
 
 if not exist %zipFilePath% goto :eof
 if not exist %destPath% mkdir %destPath%
 
 echo Dim strCurPath                                                                            > "%TEMP%\tmpUnzip.vbs"
 echo strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")         >> "%TEMP%\tmpUnzip.vbs"
 echo Set ArgObj = WScript.Arguments                                                           >> "%TEMP%\tmpUnzip.vbs"
 echo If (Wscript.Arguments.Count ^> 0) Then arg1 = ArgObj(0) Else arg1 = "" End if            >> "%TEMP%\tmpUnzip.vbs"
 echo If (Wscript.Arguments.Count ^> 1) Then arg2 = ArgObj(1) Else arg2 = "" End if            >> "%TEMP%\tmpUnzip.vbs"
 echo If arg1 = "" Then strFileZip = "example.zip" Else strFileZip = arg1 End if               >> "%TEMP%\tmpUnzip.vbs"
 echo If arg2 = "" Then strFolderOut = strCurPath ^& "\" Else strFolderOut = arg2 ^&"\" End if >> "%TEMP%\tmpUnzip.vbs"
 echo Set objShell = CreateObject("Shell.Application")                                         >> "%TEMP%\tmpUnzip.vbs"
 echo Set objSource = objShell.NameSpace(strFileZip).Items()                                   >> "%TEMP%\tmpUnzip.vbs"
 echo Set objTarget = objShell.NameSpace(strFolderOut)                                         >> "%TEMP%\tmpUnzip.vbs"
 echo intOptions = 20                                                                          >> "%TEMP%\tmpUnzip.vbs"
 echo WScript.Echo ("Extracting file: " ^& strFileZip)                                         >> "%TEMP%\tmpUnzip.vbs"
 echo objTarget.CopyHere objSource, intOptions                                                 >> "%TEMP%\tmpUnzip.vbs"
 echo WScript.Echo ("Extracted.")                                                              >> "%TEMP%\tmpUnzip.vbs"
 cscript "%TEMP%\tmpUnzip.vbs" %zipFilePath% %destPath%
endlocal
goto :eof
 
:: isCommandAvailable: Check if a console command is valid [ 1 = available, 0 = not available ]
:: -arg1 returnValue
:: -arg2 command to try
:isCommandAvailable
setlocal
 where %~2 >nul 2>&1
 if [%ERRORLEVEL%]==[0] ( set "result=1" ) else ( set "result=0" )
endlocal & set "%~1=%result%"
goto :eof

:: isComputerAvailable: Ping a computer on the LAN and determine if its online [ 1 = online, 0 = offline ]
:: -arg1 returnValue
:: -arg2 computer to attempt ping
:isComputerAvailable
setlocal
 ping -n 1 -w 200 %~2 | find "TTL=" >nul 2>&1
 if [%ERRORLEVEL%]==[0] ( set "result=1" ) else ( set "result=0" )
endlocal & set "%~1=%result%"
goto :eof

:: isRunningAsAdmin: Check if current bat file is running as admin [ 1 = running as admin, 0 = not running as admin ]
:isRunningAsAdmin
setlocal
 net file >nul 2>&1
 if [%ERRORLEVEL%]==[0] ( set "result=1" ) else ( set "result=0" )
endlocal & set "%~1=%result%"
goto :eof  

:: Escalate current bat file to have admin privileges
:runAsAdmin
setlocal
 call :isRunningAsAdmin result
 if [%result%]==[1] (goto :eof)
 if [%1]==[escalate] (shift & goto :install)
 setlocal DisableDelayedExpansion
 set "batchPath=%~0"
 setlocal EnableDelayedExpansion
 echo Set UAC = CreateObject^("Shell.Application"^)                     > "%temp%\tmpUacEscalate.vbs"
 echo UAC.ShellExecute "!batchPath!", "/relaunch", "", "runas", 1        >> "%temp%\tmpUacEscalate.vbs"
 "%temp%\tmpUacEscalate.vbs"
endlocal & exit /b
goto :eof
I will use a function like this at first to check each dependency then host a zip file with all deps to download and prepare if needed (this particular one is used to prepare a remote file installer/self-updater for remote deployment via psexec and full ANSI colorization via ansicon [with fallback to no color]):
Code:
:checkRequirements
setlocal
 set "checkedAlready=%~2"
 set PATH=%PATH%;C:\program files\7-zip

 call :echoInfo "Checking loader dependencies..."
 echo.
 
 set "reqFiledMissing=0"
 
 call :isCommandAvailable result psexec.exe
 if [%result%]==[1] (
   call :echoInfo "[DEP] PsExec.exe: FOUND"
 ) else (
   call :echoWarning "[DEP] PsExec.exe: NOT FOUND"
   set "reqFiledMissing=1"
 )
 
 call :isCommandAvailable result wget.exe
 if [%result%]==[1] (
   call :echoInfo "[DEP] Wget.exe: FOUND"
 ) else (
   call :echoWarning "[DEP] Wget.exe: NOT FOUND"
   set "reqFiledMissing=1"
 )
 
 call :isCommandAvailable result 7z.exe
 if [%result%]==[1] (
   call :echoInfo "[DEP] 7z.exe: FOUND"
 ) else (
   call :echoWarning "[DEP] 7z.exe: NOT FOUND"
   set "reqFiledMissing=1"
 )
 
 call :isCommandAvailable result ansicon.exe
 if [%result%]==[1] (
   call :echoInfo "[DEP] AnsiCon.exe: FOUND"
 ) else (
   call :echoWarning "[DEP] AnsiCon.exe: NOT FOUND"
   set "reqFiledMissing=1"
 )
 echo.

 if [%reqFiledMissing%]==[1] (
   if [%checkedAlready%]==[1] (
     set "isSuccess=0"
   ) else (  
     call :echoInfo "WARNING: Support files missing. Attempting to download/install..."
     echo.
     if exist %TEMP%\tmpSupportFiles.zip (
       rmdir /q /s %TEMP%\tmpSupportFiles
     )
     call :downloadFile %supportFileSource% %TEMP%\tmpSupportFiles.zip
     call :unzipFile %TEMP%\tmpSupportFiles.zip %TEMP%\tmpSupportDir
     
     call :echoInfo "Download complete. Rechecking..."
     echo.

     call :checkRequirements result 1
     set "isSuccess=%result%"
   )
 ) else (
   call :echoInfo "Done."
   echo.

   rem // IS UAC ESCALATION REQUIRED?
   if [%requireUacOnReceiver%]==[1] (
     call :isRunningAsAdmin result
     if not [%result%]==[1] (
       call :echoWarning "UAC escalation needed. Relaunching..."
       goto :relaunch
     )
   )

   setlocal EnableDelayedExpansion
   if [!ANSICON!]==[] (
     goto :relaunch
   )
   endlocal

   set "isSuccess=1"
 )
 echo %isSuccess%
endlocal & set "%~1=%isSuccess%"
goto :eof

Some more useful commands:

Using psexec to remotely open up ports on a firewall (MS-SQL server in this case) [note psexec.exe is a great tool to use on domains and stuff to remotely execute commands, but is not a built-in command, get from sysinternals]:

Code:
psexec \\machinename -h -u machinename\someuser -p somepw "c:\windows\system32\netsh.exe" advfirewall firewall add rule name=SQL1433 dir=in action=allow enable=yes protocol=TCP profile=domain localport=1433 remoteport=1433

Command to disable firewall completely:

Code:
netsh advfirewall set allprofiles state off

Silently install VNC Server, combine with psexec or whatever:

Code:
msiexec /i C:\temp\tightvnc.msi /quiet /norestart /ADDLOCAL="Server,Viewer" VIEWER_ASSOCIATE_VNC_EXTENSION=1 SERVER_REGISTER_AS_SERVICE=1 SERVER_ADD_FIREWALL_EXCEPTION=1 VIEWER_ADD_FIREWALL_EXCEPTION=1 SERVER_ALLOW_SAS=1 SET_USEVNCAUTHENTICATION=1 VALUE_OF_USEVNCAUTHENTICATION=1 SET_PASSWORD=1 VALUE_OF_PASSWORD=MyPasswordToReplace SET_USECONTROLAUTHENTICATION=1 VALUE_OF_USECONTROLAUTHENTICATION=1 SET_CONTROLPASSWORD=1 VALUE_OF_CONTROLPASSWORD=MyOtherPasswordToReplace

Enable RDP/TermServ via command line:

Code:
reg add "hklm\system\currentcontrolset\control\terminal server" /v "AllowTSConnections" /t REG_DWORD /d 0x1 /f
reg add "hklm\system\currentcontrolset\control\terminal server" /v "fDenyTSConnections" /t REG_DWORD /d 0x0 /f
sc config TermService start= auto
net start TermService

Get mac addresses and copy to clipboard

Code:
getmac /v | clip

(pipe any stdout to clip to have it available in clipboard)

Get info on all currently logged in users:

Code:
Quser

Get full details on current user

Code:
whoami /all
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A multithreaded audio batch encoder Fant0men 0 5,042 Jul 05, 2023, 22:08 pm
Last Post: Fant0men
  Regarding to Purpose for .class files in Java ankitdixit 1 10,655 Mar 10, 2022, 14:26 pm
Last Post: RobertX
  What's a good way to host files on a home website NeonPinkQuartz 3 23,033 Jun 17, 2020, 18:22 pm
Last Post: Moe
  Batch Script to Convert File Extensions LowOrbit 9 27,356 Apr 16, 2015, 03:43 am
Last Post: bob5695



Users browsing this thread: 1 Guest(s)