Protecting BAT scripts

Discussion in 'Scripting' started by nima1024, Jan 25, 2014.

  1. nima1024

    nima1024 MDL Member

    Sep 18, 2010
    240
    42
    10
    Hello all,
    I actually wrote a BAT script and I want to protect it and does not allow it to be modified or it's source being seen by other.
    I converted to EXE with many programs and tested it, everything was OK but the problem is when you run an EXE file which is converted from BAT file, it's complete source will be saved to User Temp folders. Although you can set it to remove after application closed, but while it's running, it's source can be reached easily.

    Is there anyway to make it protected or encrypted or any other way for running a BAT file without any readable Temp file?

    Thanks,
     
  2. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    This is a problem I spotted more than once and researched at least for several days...
    I haven't found any workaround that more or less doesn't need 3rd party tools or in the end will become pretty messy (several wrappers, problems with working directory)
     
  3. Chrystopher

    Chrystopher MDL Member

    Oct 23, 2013
    188
    65
    10
    Try this

    P.S. Take a look at MSMG Toolkit, it was created with batch code, but when we try to view the code by putting it in notepad, the code is encrypted
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    #4 KNARZ, Jan 26, 2014
    Last edited: Jan 26, 2014
    I had several problems with Advanced BAT to EXE Converter and more complex batches.
     
  5. nima1024

    nima1024 MDL Member

    Sep 18, 2010
    240
    42
    10
    Me, too.
    Compiled EXE does not run properly in my case, it opens and suddenly closes and can not use it. :(
    Other applications work fine, but it's source can easily be reached in temp folder.

    Any more ideas? :(
     
  6. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    #6 KNARZ, Jan 26, 2014
    Last edited: Jan 26, 2014
    As I said I searched very very long on this topic but haven't found anything that satisfied my needs.
    Working with call, pipes <> and so on are always ending up in a mess.

    I haven't worked with recent http://www.abyssmedia.com/quickbfc/
    but this application made at least less errors as all others I tested - but I don't remember if this also writes the source to temp.

    This programm works best for cmd 2 exe and is freeware, but it also exports the source to temp and the parsing of the working directory is not function correctly.
    http://www.f2ko.de/programs.php?lang=de&pid=b2e

    I know the idea is just to crypt the CMD but it seems you need a wrapper at all.
     
  7. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    #7 KNARZ, Jan 26, 2014
    Last edited: Jan 26, 2014
    I remember that i found 2 command line tools that should work for the purpose but one of them was paid and didn't fit the requirements (deployment for several machines) as this needed license for every pc.

    The other one had pretty much complicated syntax and I wasn't able to get it running.

    Unfortunatly I forget both names... - I only remember that one of them had a very very simple website (white background, black text, no images).

    Both do basic encryption and work with a password. The resulting file than is your encrypted batch.
     
  8. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #8 Mr Jinje, Jan 26, 2014
    Last edited: Jan 26, 2014
    Why not design your own exe wrapper, but instead of %temp%, only decrypt it to a file.io.memorystream.

     
  9. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    lack of programming skills.
     
  10. nima1024

    nima1024 MDL Member

    Sep 18, 2010
    240
    42
    10
    Would you help me more about this? :)

    @KNARZ:
    Thanks for all info you gave. :)
     
  11. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #11 Dos_Probie, Feb 16, 2014
    Last edited by a moderator: Apr 20, 2017
    ALL of the bat to exe programs use about the same compression with pkzip and upx to convert over to a .exe file, only problem is you get all kind of FP malware-virus alarms going off!
    See my simplebatch and then .exe below that I just converted with Advanced Bat to Exe to a .exe then ran a scan with virus total with 7 of 49 virus hits!
    DP:fear2:

    Code:
    @echo off
    title DEMO BATCH FILE by: ~DosProbie
    echo Hello MDL Forum! This is a basic batch file for demonstration..
    timeout /t 5 >nul
    SimpleBatch.cmd code above to .exe ==>http://www.datafilehost.com/d/27806628
    https://www.virustotal.com/en/file/...0ec27e9b4ae3ee3e57dc007d/analysis/1392575846/
     
  12. woot332

    woot332 MDL Senior Member

    Feb 18, 2011
    390
    815
    10
    #12 woot332, Mar 13, 2014
    Last edited by a moderator: Apr 20, 2017
    try this lazy solution:p
    http://www.sendspace.com/file/cl6is5
     
  13. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    #13 Dos_Probie, Mar 13, 2014
    Last edited: Mar 13, 2014
  14. woot332

    woot332 MDL Senior Member

    Feb 18, 2011
    390
    815
    10
    nsis, now take look at test.bat with notepad after cmd has opened with winrar sfx leaves the bat file exposed after extraction.
    nsis sfx should not:p.
     
  15. woot332

    woot332 MDL Senior Member

    Feb 18, 2011
    390
    815
    10
    #15 woot332, Mar 13, 2014
    Last edited by a moderator: Apr 20, 2017
    Here you go have fun as you can see once .bat file is loaded in memory we simply overwrite test.bat with useless bits.

    Code:
    batch.nsi: 
    
    ; The name of the installer
    Name "test"
    
    SetCompressor "/SOLID" "lzma" 
    
    SilentInstall "silent"
    
    SubCaption 2 " "
    
    ; The file to write
    OutFile "batch.exe"
    
    ; The default installation directory
    InstallDir $TEMP
    
    ; Request application privileges for Windows Vista
    RequestExecutionLevel admin
    
    XPStyle on
    
    Dirtext "extacting files...."
    
    ;--------------------------------
    
    ; Pages
    
    Page directory
    Page instfiles
    
    ;--------------------------------
    
    ; The stuff to install
    Section "" ;No components page, name is not important
    
      SetOutPath $TEMP
      File "test.bat"
      ExecShell "open" "$TEMP\test.bat" "SW_SHOWNORMAL"
      FindWindow $1 "ConsoleWindowClass"
      IntCmp $1 0 fail ok ok
      fail:
      Goto -2
      ok:
      sleep "2000"
      ClearErrors
      FileOpen $0 "$TEMP\test.bat" w
      IfErrors done
      FileWrite $0 "F<=?@<?@B>D<??>@B>DCDF?=<F@EBFAC@>>ACAD=B=?@F@@AECC>EAACDFF=D?@?>EF=EB>@=ADDA@C?@FDCC<?FE=@<<F<C@>FDBEC<CE<ECEAA@<AACC<A<@=ECDE><AF?@D=E?A"
      FileClose $0
      done:
    
    SectionEnd ; end the section