Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with password in Batch  (Read 9801 times)

0 Members and 1 Guest are viewing this topic.

doubleriospy09

    Topic Starter


    Rookie
    • Yes
    • Computers: The Future of Mankind
  • Certifications: List
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Help with password in Batch
« on: August 20, 2009, 11:40:09 AM »
Ok. I work with computers for a living and basically taught myself everything about them. I recently discovered how much fun it was to program and a co-worker recommended that I start out with batch. I got the basics down, but I can't figure out how to mask input. I am working on a program to launch Firefox after a password prompt. here is what I have so far:
Code: [Select]
@title Firefox Launcher
@color 2f
@echo off
goto passverify
:error
REM tricks unauthorised user into thinking computer is deleting contents in Windows
cls
echo System Error 5 has occured
echo.
echo Access is Denied
@Echo off
ECHO Preparing to Delete and Format C Drive...
Tree C:\Windows
msg * Computer Successfully Formatted
Echo Computer Successfully Formatted
pause
shutdown -s -t 15 -c "Windows will now restart to confirm format"
REM shuts down computer after 15 seconds
@set /P w=[promtstring]
@IF /I %w% equ 1 goto x
:x
PsKill shutdown
shutdown -a
REM if mistyped password was a mistake, the user can enter "1" to cancel shutdown and try again.
:passverify
REM prompts for password
cls
set /p pass=Type password to unlock:
if %pass%==Wizkid goto 1
goto error
:1
REM if password matches, will start Firfox
cd C:\Program Files\Mozilla Firefox\
start firefox.exe
@cls
end

Is there a way I can mask a password without a scripted HTA file?
The simplest solution is usually the correct one

smeezekitty

  • Guest
Re: Help with password in Batch
« Reply #1 on: August 20, 2009, 03:24:22 PM »
quite an odd batch file
i think password masking is fairly useless

BatchFileBasics



    Hopeful

    Thanked: 18
    Re: Help with password in Batch
    « Reply #2 on: August 20, 2009, 08:40:46 PM »
    try this, i found it in the forums.

    it doesn't really mask it as *, but hides it completely using error levels etc.
    When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

    hibyy



      Rookie

      • Experience: Familiar
      • OS: Windows 8
      Re: Help with password in Batch
      « Reply #3 on: August 24, 2009, 02:45:07 PM »
      try this, i found it in the forums.

      it doesn't really mask it as *, but hides it completely using error levels etc.
      The way the person suggests  in the forum is okay but it can still be read becuase he just reputs each letter into ASCII instead of text...

      if you want it so the person can't read your script for the password maybe you should try compiling it to a .exe

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Help with password in Batch
      « Reply #4 on: August 24, 2009, 05:20:25 PM »
      heh, System Error 5 is actually Access Denied...  ;D



      The way the person suggests  in the forum is okay but it can still be read becuase he just reputs each letter into ASCII instead of text...

      if you want it so the person can't read your script for the password maybe you should try compiling it to a .exe

      That won't work either, necessarily, since no batch "compiler" actually compiles the batch file.

      I was trying to dereference Null Pointers before it was cool.

      BatchFileBasics



        Hopeful

        Thanked: 18
        Re: Help with password in Batch
        « Reply #5 on: August 24, 2009, 06:01:09 PM »
        zomg?
        When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        I was trying to dereference Null Pointers before it was cool.

        BatchFileBasics



          Hopeful

          Thanked: 18
          Re: Help with password in Batch
          « Reply #7 on: August 24, 2009, 06:23:46 PM »
           :P i mean what do you mean
          Quote
          no batch "compiler" actually compiles the batch file
          When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Help with password in Batch
          « Reply #8 on: August 24, 2009, 06:27:43 PM »
          It always executes the batch through CMD; that is, ALL batch compilers at some point write out the batch file and execute it. Some of them try to encrypt it, so it doesn't appear when you view the EXE, but POOF! run the program and the decrypted batch code appears both in memory (as seen through Process Explorer) as well as on disk (viewable through Process Monitor or File Monitor, almost always in either the temp folder or the current directory).
          I was trying to dereference Null Pointers before it was cool.

          BatchFileBasics



            Hopeful

            Thanked: 18
            Re: Help with password in Batch
            « Reply #9 on: August 24, 2009, 06:32:43 PM »
            ohh, wow i did not know its that easily....viewable  :o
            When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Help with password in Batch
            « Reply #10 on: August 24, 2009, 07:45:48 PM »
            remember tan_za? out of spite they posted a "complicated" batch file for somebody, and wouldn't post the actual code. So I dug out process explorer, ran the batch and grabbed it from memory (comments and all, mostly self-conceited, if I remember) and posted for the original poster :)
            I was trying to dereference Null Pointers before it was cool.

            BatchFileBasics



              Hopeful

              Thanked: 18
              Re: Help with password in Batch
              « Reply #11 on: August 24, 2009, 07:52:54 PM »
              ahh yes
              The attackment should do what you want, it will count files and folders in the directiory that the program is placed in. It is not as easy as you would think so I dout it to be in any book because this is really complicated batch stuff that what you are asking gets into.

              Hope you like, but since the code is quite difficult the app is and exe,
              Tan_Za

              back when i wasn't so active in the forums, good times  ::)
              When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: Help with password in Batch
              « Reply #12 on: August 24, 2009, 07:54:59 PM »
              lol, yeah, and then it was what- 15-20 lines?
              I was trying to dereference Null Pointers before it was cool.

              BatchFileBasics



                Hopeful

                Thanked: 18
                Re: Help with password in Batch
                « Reply #13 on: August 24, 2009, 08:00:53 PM »
                haha yes, his "difficult" "complicated' batch was
                Code: [Select]
                FOR /f "tokens=*" %%G IN ('dir /b') DO (call :s_do_sums "%%G")and
                Code: [Select]
                echo %count%:%1
                set /a count+=1
                i mean don't get me wrong. its confusing when your starting, but it took me a good hour 1/2 to understand the concept of the for /f loops.

                but i think the only user allowed to say their code is "intermediete" is devcom  ;D
                When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                smeezekitty

                • Guest
                Re: Help with password in Batch
                « Reply #14 on: August 24, 2009, 08:07:43 PM »
                remember tan_za? out of spite they posted a "complicated" batch file for somebody, and wouldn't post the actual code. So I dug out process explorer, ran the batch and grabbed it from memory (comments and all, mostly self-conceited, if I remember) and posted for the original poster :)
                go BC_programmer

                doubleriospy09

                  Topic Starter


                  Rookie
                  • Yes
                  • Computers: The Future of Mankind
                • Certifications: List
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: Help with password in Batch
                « Reply #15 on: August 24, 2009, 08:45:03 PM »
                try this, i found it in the forums.

                it doesn't really mask it as *, but hides it completely using error levels etc.

                Ok. so i tried that, modified my code nd I got something saying that AUTOEXEC.NT is not suitable for running both MS-DOS and Windows applications. Would this have something to do with the ".com" portion of it? as i know those are compiled batch files, and I did work with some on my old tandy
                The simplest solution is usually the correct one

                BatchFileBasics



                  Hopeful

                  Thanked: 18
                  Re: Help with password in Batch
                  « Reply #16 on: August 24, 2009, 08:58:38 PM »
                  this could most likely because by autoexec.nt is either corrupt...or missing all together.

                  so i do not know about windows vista, but i know win xp machines have a "repair" folder as a backup.

                  so navigate to the folder c:\windows\repair\
                  copy autoexec.nt
                  then navigate to c:\windows\system32\
                  paste autoexec.nt inside
                  re-run batch script
                  When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                  Helpmeh



                    Guru

                  • Roar.
                  • Thanked: 123
                    • Yes
                    • Yes
                  • Computer: Specs
                  • Experience: Familiar
                  • OS: Windows 8
                  Re: Help with password in Batch
                  « Reply #17 on: August 24, 2009, 09:13:36 PM »
                  go BC_programmer
                  Every once and a while, BC does something that the world benefits from. This is one of those moments. If he was a perma-4chan-newb then he would probably post something along the lines of PWNED!!!1!!!shift!!!!one!!! Instead of gracing us with tar's "protected" script.
                  Where's MagicSpeed?
                  Quote from: 'matt'
                  He's playing a game called IRL. Great graphics, *censored* gameplay.

                  doubleriospy09

                    Topic Starter


                    Rookie
                    • Yes
                    • Computers: The Future of Mankind
                  • Certifications: List
                  • Computer: Specs
                  • Experience: Experienced
                  • OS: Windows 7
                  Re: Help with password in Batch
                  « Reply #18 on: August 28, 2009, 12:13:31 AM »
                  this could most likely because by autoexec.nt is either corrupt...or missing all together.

                  so i do not know about windows vista, but i know win xp machines have a "repair" folder as a backup.

                  so navigate to the folder c:\windows\repair\
                  copy autoexec.nt
                  then navigate to c:\windows\system32\
                  paste autoexec.nt inside
                  re-run batch script
                  OK. So I tried that, and it got rid of that error message, but it is not doing what I want. When I run the script, it stops responding. Any ideas? btw: thanks for the help thus far!
                  The simplest solution is usually the correct one

                  BatchFileBasics



                    Hopeful

                    Thanked: 18
                    Re: Help with password in Batch
                    « Reply #19 on: August 28, 2009, 12:35:54 AM »
                    when you say not responding, do you mean the command window shows the
                    c:\windows\system32\ (not responding)

                    or the script just does nothing?
                    When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                    doubleriospy09

                      Topic Starter


                      Rookie
                      • Yes
                      • Computers: The Future of Mankind
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Experienced
                    • OS: Windows 7
                    Re: Help with password in Batch
                    « Reply #20 on: August 28, 2009, 11:58:26 AM »
                    when you say not responding, do you mean the command window shows the
                    c:\windows\system32\ (not responding)

                    or the script just does nothing?
                    When I say it stops responding, I mean the script hangs (does nothing) and I need to hit ctrl+alt+del. When I do that, it comes up as "Not Responding" and I need to end it.
                    The simplest solution is usually the correct one

                    BatchFileBasics



                      Hopeful

                      Thanked: 18
                      Re: Help with password in Batch
                      « Reply #21 on: August 28, 2009, 12:09:47 PM »
                      this is strange, have you tried both of the codes?

                      especially this one:
                      Code: [Select]
                      @echo off
                      echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>hide.com

                      :retry
                      set /p userid=Enter UserId:
                      set /p password=Enter password: <nul
                      for /f "tokens=*" %%i in ('hide.com') do set password=%%i
                      if /i %password%==password goto next
                      cls
                      echo Try again. You are not logged in!
                      goto retry

                      :next
                      echo.
                      echo You are logged in!
                      del hide.com
                      When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                      doubleriospy09

                        Topic Starter


                        Rookie
                        • Yes
                        • Computers: The Future of Mankind
                      • Certifications: List
                      • Computer: Specs
                      • Experience: Experienced
                      • OS: Windows 7
                      Re: Help with password in Batch
                      « Reply #22 on: August 28, 2009, 04:32:31 PM »
                      this is strange, have you tried both of the codes?

                      especially this one:
                      Code: [Select]
                      @echo off
                      echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>hide.com

                      :retry
                      set /p userid=Enter UserId:
                      set /p password=Enter password: <nul
                      for /f "tokens=*" %%i in ('hide.com') do set password=%%i
                      if /i %password%==password goto next
                      cls
                      echo Try again. You are not logged in!
                      goto retry

                      :next
                      echo.
                      echo You are logged in!
                      del hide.com
                      Ok. The 1st code did not work, but I tried this one, and it did work. Thanks! I did modify it to work with my needs though. I have attached my code.
                      Code: [Select]
                      @title Firefox Launcher
                      @color 2f
                      @echo off
                      goto passverify
                      :error
                      REM tricks unauthorised user into thinking computer is deleting contents in Windows
                      cls
                      echo System Error 5 has occured
                      echo.
                      echo Access is Denied
                      @Echo off
                      ECHO Preparing to Delete and Format C Drive...
                      Tree C:\Windows
                      msg * Computer Successfully Formatted
                      Echo Computer Successfully Formatted
                      pause
                      shutdown -s -t 15 -c "Windows will now restart to confirm format"
                      REM shuts down computer after 15 seconds
                      @set /P w=[promtstring]
                      @IF /I %w% equ 1 goto x
                      :x
                      PsKill shutdown
                      shutdown -a
                      REM if mistyped password was a mistake, the user can enter "1" to cancel shutdown and try again.
                      :passverify
                      REM prompts for password
                      @echo off
                      echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>hide.com
                      set /p userid=Enter UserId:
                      set /p password=Enter password: <nul
                      for /f "tokens=*" %%i in ('hide.com') do set password=%%i
                      if /i %password%==Wizkid goto next
                      cls
                      goto error

                      :next
                      echo.
                      echo You are logged in!
                      del hide.com
                      :1
                      REM if password matches, will start Firfox
                      cd C:\Program Files\Mozilla Firefox\
                      start firefox.exe
                      @cls
                      end
                      The simplest solution is usually the correct one

                      BatchFileBasics



                        Hopeful

                        Thanked: 18
                        Re: Help with password in Batch
                        « Reply #23 on: August 28, 2009, 04:36:19 PM »
                        im glad I helped  :)

                        and welcome to the forums!
                        When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

                        doubleriospy09

                          Topic Starter


                          Rookie
                          • Yes
                          • Computers: The Future of Mankind
                        • Certifications: List
                        • Computer: Specs
                        • Experience: Experienced
                        • OS: Windows 7
                        Re: Help with password in Batch
                        « Reply #24 on: August 30, 2009, 08:30:03 PM »
                        haha thanks
                        The simplest solution is usually the correct one

                        doubleriospy09

                          Topic Starter


                          Rookie
                          • Yes
                          • Computers: The Future of Mankind
                        • Certifications: List
                        • Computer: Specs
                        • Experience: Experienced
                        • OS: Windows 7
                        Re: Help with password in Batch
                        « Reply #25 on: September 03, 2009, 10:26:08 PM »
                        ok. so i decided to expand on that script, and got kinda excited. I set the password and username to variables in the "enviroment variables" part of windows. (I figure it is a little more secure). Anyway, script works fine, but I have one small problem. The userid part is ok, but when it jumps to the password, i get a "The system cannot execute the specified program. goto was unexpected at this time. press any key..." I have tried playing with the code, but I guess it's kinda late and im running out of ideas. Any ideas? lol
                        Code: [Select]

                        @title Firefox Launcher by Matt Rania
                        @color 2f
                        @echo off
                        goto passverify
                        :error
                        REM tricks unauthorised user into thinking computer is deleting contents in Windows
                        cls
                        echo System Error 5 has occured
                        echo.
                        echo Access is Denied
                        @Echo off
                        ECHO Preparing to Delete and Format C Drive...
                        Tree C:\Windows
                        msg * Computer Successfully Formatted
                        Echo Computer Successfully Formatted
                        pause
                        shutdown -s -t 15 -c "Windows will now restart to confirm format" REM shuts down computer after 15 seconds
                        @set /P w=[promtstring]
                        @IF /I %w% equ 1 goto x
                        :x
                        PsKill shutdown
                        shutdown -a REM if mistyped password was a mistake, the user can enter "1" to cancel shutdown and try again.
                        :passverify
                        REM prompts for password
                        cls
                        @echo off
                        echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>hide.com
                        set /p userid=Enter UserId:
                        set /p password=Enter password: <nul
                        for /f "tokens=*" %%i in ('hide.com') do set password=%%i
                        if /i %password%==%realpass% goto z
                        :z
                        for /f "tokens=*" %%i in ('hide.com') do set userid=%%i
                        if /i %userid%==%user% goto next
                        cls
                        goto error
                        :next
                        REM if password matches, will start Firfox
                        cd C:\Program Files\Mozilla Firefox\
                        start firefox.exe
                        @cls
                        del hide.com
                        exit
                        The simplest solution is usually the correct one

                        Salmon Trout

                        • Guest
                        Re: Help with password in Batch
                        « Reply #26 on: September 05, 2009, 01:03:42 AM »
                        Sounds like one of your IF tests is trying to compare a string value with a null (an empty, zero-length string). (e.g. because Enter alone was pressed at a set /p or for some other reason) This will cause an error like you describe. The goto in the error message is the clue. To avoid this, enclose both sides in quotes, periods, curly or square brackets (or some other character pairs which are nonspecial in batch scripts) like this

                        Code: [Select]
                        if /i "%value1%"=="%value2%" goto label
                        if /i {%value1%}=={%value2%} goto label
                        if /i .%value1%.==.%value2%. goto label
                        if /i [%value1%]==[%value2%] goto label

                        That way when the variables are expanded at runtime a variable holding a null string becomes "" or {} or .. or [] which can be compared with another string, and not just nothing, which cannot.

                        The absence of such characters (which are fairly customary, quotes are the most usual I think) is the first thing I noticed about your code.


                        Helpmeh



                          Guru

                        • Roar.
                        • Thanked: 123
                          • Yes
                          • Yes
                        • Computer: Specs
                        • Experience: Familiar
                        • OS: Windows 8
                        Re: Help with password in Batch
                        « Reply #27 on: September 05, 2009, 06:13:19 AM »
                        My piece of advice, always use quotes (or brackets, etc.) when comparing user input.
                        Where's MagicSpeed?
                        Quote from: 'matt'
                        He's playing a game called IRL. Great graphics, *censored* gameplay.