Computer Hope

Microsoft => Microsoft DOS => Topic started by: zask on February 20, 2016, 04:57:55 PM

Title: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 20, 2016, 04:57:55 PM
Okay i have a batch file that creates a vbs file named "obfuscator.vbs". "obfuscator.vbs" obfuscates other vbs files that you name in a directory that you name with help from the batch file. these names are stored in the variables %PATH% and %FILE%. all i need to do is just pass in the vbs filename "message.vbs" to the script "obfuscator.vbs" as an argument from command line. how do i do this? for example you select a directory that has the vbs file name "message.vbs". it's code displays this. note that all the code below contains 0 errors.

this is "message.vbs"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

msgbox "message", ,"title"

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

if i drag and drop the file "message.vbs" on the "obfucator.vbs" file that is generated by this batch file, the "message.vbs" file will become obfuscated.

this is the batch file that creates the file "obfuscator.vbs"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

@echo off
title Vbs Obfuscator
color 0a

set /p "PATH=Enter the path of the folder place the obfuscator : "
set /p "FILE=Enter the filename that you wish to obfuscate (.txt or .vbs) : "

echo Option Explicit >> "%PATH%\Obfuscator.vbs"
echo.  >> "%PATH%\Obfuscator.vbs"
echo Dim oEncoder >> "%PATH%\Obfuscator.vbs"
echo Set oEncoder = CreateObject("Scripting.Encoder") >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Dim oFso >> "%PATH%\Obfuscator.vbs"
echo Set oFso = CreateObject("Scripting.FileSystemObject") >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Dim oFiles >> "%PATH%\Obfuscator.vbs"
echo set oFiles = WScript.Arguments >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Randomize >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Call EnObfuscate(oFiles) >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private function EnObfuscate(oFiles) >> "%PATH%\Obfuscator.vbs"
echo   Dim sFileName, oFile, sBody, i >> "%PATH%\Obfuscator.vbs"
echo   Dim sFileOut, sOutput >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   For i = 0 to oFiles.Count - 1 >> "%PATH%\Obfuscator.vbs"
echo     sFileName = oFiles(i) >> "%PATH%\Obfuscator.vbs"
echo     set oFile = oFso.GetFile(sFileName) >> "%PATH%\Obfuscator.vbs"
echo     sBody = ReadFile(oFile) >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo     sOutput = Encode(Obfuscate(sBody)) >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo     sFileOut = Left(sFileName, Len(sFileName) - 3) ^& "vbe" >> "%PATH%\Obfuscator.vbs"
echo     WriteFile sFileOut, sOutput >> "%PATH%\Obfuscator.vbs"
echo   Next >> "%PATH%\Obfuscator.vbs"
echo End Function >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private Function ReadFile(oFile) >> "%PATH%\Obfuscator.vbs"
echo   Dim oStream >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   Const IOMODE_FOR_READING = 1 >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   Set oStream = oFile.OpenAsTextStream(IOMODE_FOR_READING) >> "%PATH%\Obfuscator.vbs"
echo   ReadFile = oStream.ReadAll >> "%PATH%\Obfuscator.vbs"
echo   oStream.Close >> "%PATH%\Obfuscator.vbs"
echo End Function >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private Sub WriteFile(sFileOut, sOutput) >> "%PATH%\Obfuscator.vbs"
echo   Dim oOutputFile >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   Set oOutputFile = oFso.CreateTextFile(sFileOut) >> "%PATH%\Obfuscator.vbs"
echo   oOutputFile.Write sOutput >> "%PATH%\Obfuscator.vbs"
echo   oOutputFile.Close >> "%PATH%\Obfuscator.vbs"
echo End Sub >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private Function Obfuscate(txt) >> "%PATH%\Obfuscator.vbs"
echo   Dim enc, i >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   enc = "" >> "%PATH%\Obfuscator.vbs"
echo   for i = 1 to len(txt) >> "%PATH%\Obfuscator.vbs"
echo     enc = enc ^& "chr( " ^& form( asc(mid(txt,i,1)) ) ^& " ) & " >> "%PATH%\Obfuscator.vbs"
echo   next >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo  Obfuscate = "Execute(" ^& enc ^& " vbcrlf " ^& " ) " >> "%PATH%\Obfuscator.vbs"
echo End Function >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private Function form(n) >> "%PATH%\Obfuscator.vbs"
echo  dim r, k, ret >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo  r = int(rnd * 10000) >> "%PATH%\Obfuscator.vbs"
echo   k = int(rnd * 3) >> "%PATH%\Obfuscator.vbs"
echo   if( k = 0) then ret = (r+n) ^& "-" ^& r >> "%PATH%\Obfuscator.vbs"
echo   if( k = 1) then ret = (n-r) ^& "+" ^& r >> "%PATH%\Obfuscator.vbs"
echo   if( k = 2) then ret = (n*r) ^& "/" ^& r >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   form = ret >> "%PATH%\Obfuscator.vbs"
echo End Function >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo Private Function Encode(txt) >> "%PATH%\Obfuscator.vbs"
echo   Const Extension = ".vbs" >> "%PATH%\Obfuscator.vbs"
echo   Const Flags = 0 >> "%PATH%\Obfuscator.vbs"
echo   Const Language = "" >> "%PATH%\Obfuscator.vbs"
echo. >> "%PATH%\Obfuscator.vbs"
echo   Encode = oEncoder.EncodeScriptFile(Extension, txt, Flags, Language) >> "%PATH%\Obfuscator.vbs"
echo End Function >> "%PATH%\Obfuscator.vbs"

echo File "Obfuscator.vbs" was placed in the folder "%PATH%".
pause

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

i basically want to obfuscate the "message.vbs" file without having to put anymore effort other than adding the file path and file name. either way how can i do this? i ether need the batch code to do this or the vbscript code to do this.

this is an example of what im not trying to do
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

objShell.Run "message.vbs"

' Using Set is mandatory
Set objShell = Nothing

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX

Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 20, 2016, 05:03:19 PM
sorry didn't mean to double post that, fixed it
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 20, 2016, 06:51:49 PM
the argument is named oFiles
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 21, 2016, 02:18:09 PM
hmm... maybe it would be more helpful to post the vbs code that "obfuscator.bat" creates?

Option Explicit
 
Dim oEncoder
Set oEncoder = CreateObject("Scripting.Encoder")
 
Dim oFso
Set oFso = CreateObject("Scripting.FileSystemObject")
 
Dim oFiles
set oFiles = WScript.Arguments
 
Randomize
 
Call EnObfuscate(oFiles)
 
Private function EnObfuscate(oFiles)
  Dim sFileName, oFile, sBody, i
  Dim sFileOut, sOutput
 
  For i = 0 to oFiles.Count - 1
    sFileName = oFiles(i)
    set oFile = oFso.GetFile(sFileName)
    sBody = ReadFile(oFile)
 
    sOutput = Encode(Obfuscate(sBody))
 
    sFileOut = Left(sFileName, Len(sFileName) - 3) & "vbe"
    WriteFile sFileOut, sOutput
  Next
End Function
 
Private Function ReadFile(oFile)
  Dim oStream
 
  Const IOMODE_FOR_READING = 1
 
  Set oStream = oFile.OpenAsTextStream(IOMODE_FOR_READING)
  ReadFile = oStream.ReadAll
  oStream.Close
End Function
 
Private Sub WriteFile(sFileOut, sOutput)
  Dim oOutputFile
 
  Set oOutputFile = oFso.CreateTextFile(sFileOut)
  oOutputFile.Write sOutput
  oOutputFile.Close
End Sub
 
Private Function Obfuscate(txt)
  Dim enc, i
 
  enc = ""
  for i = 1 to len(txt)
    enc = enc & "chr( " & form( asc(mid(txt,i,1)) ) & " ) & "
  next
 
 Obfuscate = "Execute(" & enc & " vbcrlf " & " ) "
End Function
 
Private Function form(n)
 dim r, k, ret
 
 r = int(rnd * 10000)
  k = int(rnd * 3)
  if( k = 0) then ret = (r+n) & "-" & r
  if( k = 1) then ret = (n-r) & "+" & r
  if( k = 2) then ret = (n*r) & "/" & r
 
  form = ret
End Function
 
Private Function Encode(txt)
  Const Extension = ".vbs"
  Const Flags = 0
  Const Language = ""
 
  Encode = oEncoder.EncodeScriptFile(Extension, txt, Flags, Language)
End Function
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: patio on February 21, 2016, 02:43:53 PM
I like these Topics where you just answer yourself...
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 21, 2016, 03:18:22 PM
that doesn't awnser my question, "obfuscator.bat" creates obfuscator.vbs. obfuscator.vbs obfuscates other vbs files. how do i all i need to do is pass in the vbs filename "message.vbs" to the script "obfuscator.vbs" as an argument from command line. this is what im asking for. calling the file wont allow the argument oFiles to obfuscate the program. i need to basically pass the file "message.vbs" through "obfuscator.vbs".
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: BC_Programmer on February 21, 2016, 05:11:05 PM
If you want to pass arguments to a VBScript program, you include the arguments at the end of the call that runs the script.
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: zask on February 21, 2016, 06:21:39 PM
sorry still dont get what you mean can i have a simple example?
Title: Re: Drag a vbs file from one directory and drop in on top another vbs file with .bat
Post by: Geek-9pm on February 21, 2016, 07:18:09 PM
The general rule for a command line thing is like this:

my_script ar1 ar2 ar3

In this example, my_script is some suitable script or program and the items that follow are the parameters, or values the program needs to have.

If my_script is a BAT file, it can be called from a bat file:

call my_script %1 %2 %3

This is documented somewhere.