Computer Hope

Software => Computer programming => Topic started by: doubleriospy09 on August 20, 2009, 11:40:09 AM

Title: Help with password in Batch
Post by: doubleriospy09 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?
Title: Re: Help with password in Batch
Post by: smeezekitty on August 20, 2009, 03:24:22 PM
quite an odd batch file
i think password masking is fairly useless
Title: Re: Help with password in Batch
Post by: BatchFileBasics on August 20, 2009, 08:40:46 PM
try this (http://www.computerhope.com/forum/index.php?topic=69496.0), i found it in the forums.

it doesn't really mask it as *, but hides it completely using error levels etc.
Title: Re: Help with password in Batch
Post by: hibyy on August 24, 2009, 02:45:07 PM
try this (http://www.computerhope.com/forum/index.php?topic=69496.0), 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
Title: Re: Help with password in Batch
Post by: BC_Programmer 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.

Title: Re: Help with password in Batch
Post by: BatchFileBasics on August 24, 2009, 06:01:09 PM
zomg?
Title: Re: Help with password in Batch
Post by: BC_Programmer on August 24, 2009, 06:01:52 PM
zomg?

 ???
Title: Re: Help with password in Batch
Post by: BatchFileBasics on August 24, 2009, 06:23:46 PM
 :P i mean what do you mean
Quote
no batch "compiler" actually compiles the batch file
Title: Re: Help with password in Batch
Post by: BC_Programmer 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).
Title: Re: Help with password in Batch
Post by: BatchFileBasics on August 24, 2009, 06:32:43 PM
ohh, wow i did not know its that easily....viewable  :o
Title: Re: Help with password in Batch
Post by: BC_Programmer 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 :)
Title: Re: Help with password in Batch
Post by: BatchFileBasics 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  ::)
Title: Re: Help with password in Batch
Post by: BC_Programmer on August 24, 2009, 07:54:59 PM
lol, yeah, and then it was what- 15-20 lines?
Title: Re: Help with password in Batch
Post by: BatchFileBasics 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
Title: Re: Help with password in Batch
Post by: smeezekitty 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
Title: Re: Help with password in Batch
Post by: doubleriospy09 on August 24, 2009, 08:45:03 PM
try this (http://www.computerhope.com/forum/index.php?topic=69496.0), 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
Title: Re: Help with password in Batch
Post by: BatchFileBasics 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
Title: Re: Help with password in Batch
Post by: Helpmeh 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.
Title: Re: Help with password in Batch
Post by: doubleriospy09 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!
Title: Re: Help with password in Batch
Post by: BatchFileBasics 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?
Title: Re: Help with password in Batch
Post by: doubleriospy09 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.
Title: Re: Help with password in Batch
Post by: BatchFileBasics 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
Title: Re: Help with password in Batch
Post by: doubleriospy09 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
Title: Re: Help with password in Batch
Post by: BatchFileBasics on August 28, 2009, 04:36:19 PM
im glad I helped  :)

and welcome to the forums!
Title: Re: Help with password in Batch
Post by: doubleriospy09 on August 30, 2009, 08:30:03 PM
haha thanks
Title: Re: Help with password in Batch
Post by: doubleriospy09 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
Title: Re: Help with password in Batch
Post by: Salmon Trout 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.

Title: Re: Help with password in Batch
Post by: Helpmeh on September 05, 2009, 06:13:19 AM
My piece of advice, always use quotes (or brackets, etc.) when comparing user input.