[comp.lang.pascal] password program

caster@jove.cs.pdx.edu (Brad J. Caster) (05/30/91)

Well, if a password program is executed from config.sys, then
Ctrl-Break & Ctrl-C cannot break out of it.  So it was futile
to write a complicated program for that purpose.

There may be something of use here anyway.  The following is
the Turbo Pascal (v5.0) source code I ended up with.  It's a
memory resident password program.  It is armed when you first
run it.

BTW, does anyone know how to keep someone from just booting up
from a floppy?

Use:
	Run program with password as argument.
	With no argument, the default password is 'hello'.

	It starts out in Locked mode.

	To alternate between Locked and Unlocked modes,
	press both shift keys simultaneously, then type in
	password.

	The beep lets you know if you type it in correctly.

	You can "Lock" your computer any time you want, but
	no guarantees are made as to whether it will "Unlock"
	safely when you want.

	Be sure to save your data first.  It will Lock permanently
	if someone tries typing on it.

	It can be run from config.sys, but beware that your
	password will be changed to upper-case by DOS.
	(ie. INSTALL=PASSWORD.EXE knockknock)

Following the source code, is the UUencoded executable.
------- Cut Here -------
{$M 1024,0,0}
program Password;
        uses crt,dos;
var
   PW : string;
   C,P,L : byte;
   K : char;
   Pntr : pointer;
   Locked,InUse,Stop : boolean;
   Regs : registers;


procedure Bleep;
begin
     sound(128);
     delay(128);
     sound(512);
     delay(128);
     nosound;
end;

procedure Bleep2;
begin
     sound(512);
     delay(128);
     sound(128);
     delay(128);
     nosound;
end;

procedure GetKey;
interrupt;
begin
     Intr($64,Regs);
     if not InUse then
     begin
          InUse := true;
          if Locked then
          begin
               C := C + 1;
               if C > 20 then
               repeat
                     Bleep;
               until false;
          end;
          if (Mem[$0040:$0017] and $03 = $03) then
          begin
               P := 1;
               Stop := false;
               repeat
                     Regs.AH := $00;
                     intr($16,Regs);
                     K := chr(Regs.AL);
                     if K = PW[P] then
                        P := P + 1
                     else
                         Stop := true;
               until Stop or (P > L);
               if not Stop then
                    if Locked then
                    begin
                         Bleep2;
                         Locked := false;
                    end
                    else
                    begin
                         Bleep;
                         C := 0;
                         Locked := true;
                    end;
          end;
     end;
     InUse := false;
end;


begin
     InUse := true;
     getintvec($64,Pntr);
     writeln;
     if Pntr = nil then
     begin
          C := 0;
          Locked := true;
          if ParamCount > 0 then
             PW := ParamStr(1)
          else
              PW := 'hello';
          L := length(PW);
          writeln('Armed and Dangerous');
          Bleep;
          getintvec($09,Pntr);
          setintvec($64,Pntr);
          setintvec($09,@GetKey);
          keep(0);
     end
     else
         writeln('Password Cannot be Loaded');
     InUse := false;
end.
------- Cut Here -------
begin 644 password.exe
M35J  0H *@ - '@ > !C 0 $  "$ 0  '     @    1    &@   ",    L
M    ,0   #\   !(    40   %H   !C    :    'H   ")    X0   (<!
M  ", 0  I0$  *\!  "T 0  SP$  .(!  #P 0  !0(  !T"   B @  )P( 
M #<"  !' @  4 (  %<"  !? @  <P(  '@"  !] @  C (  !< -0 J #4 
M,@$U  $ EP#= )< 6@>7                 %6)Y3' FD0"EP"X@ !0FL8"
M-0"X@ !0FIX"-0"X  )0FL8"-0"X@ !0FIX"-0":\P(U (GL7<-5B>4QP)I$
M I< N  "4)K& C4 N(  4)J> C4 N(  4)K& C4 N(  4)J> C4 FO,"-0")
M[%W#4%-14E97'@95B>6X)P&.V+!D4+]* 1Y7F@L *0" /D<! '0#Z:H Q@9'
M 0& /D8! '05H#X!,.1 HCX!@#X^ 11V!>A,_^O[N$  4+\7  <FB@4D SP#
M=7C&!C\! <8&2 $ Q@9+ 0"P%E"_2@$>5YH+ "D H$H!HD$!H#\!,.2+^(J%
M/@ Z!D$!=0N@/P$PY$"B/P'K!<8&2 $!@#Y( 0!U": _ 3H&0 %VMX ^2 $ 
M=1Z /D8! '0*Z S_Q@9& 0#K#>C+_L8&/@$ Q@9& 0'&!D<! (GL70<?7UY:
M65M8SP5H96QL;Q-!<FUE9"!A;F0@1&%N9V5R;W5S&5!A<W-W;W)D($-A;FYO
M="!B92!,;V%D962:  "7 )H  #4 58GE@>P  <8&1P$!L&10OT(!'E>:;  I
M +]R AY7FK 'EP":#@*7 *%" 0L&1 %T ^FA ,8&/@$ Q@9& 0&:N@B7  G 
M?A^-O@#_%E>X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NB _U\')HE=".L&B]PVQ'\$)H-]&@!U
M \H$ (,^-@  =?8&5R;_71@+P'3LHS8 Z^=5B^P>Q'X,!E?HXO[%=@BY  !U
M%>C[_CP-= X\&G0*0T%&B 0[3@9UZROQB Q?!R:)70@?7<H& %6+[![$?@P&
M5^CJ_G4EQ78(BTX&_*PRY"O(?@RP(.CY_N+YBD3_,N2+R.,'_*SHZ?[B^5\'
M)HE="!]=R@8 58OLBU8&"])T!>A) .LPM##-(3P#N   <B6.!C( )HX&+  S
M__PF.@5T![G___*NZ_2#QP.+][D  ?*ND?;0'@8?Q'X(_*J1\Z0?7<H" #/2
MZ ( D\N.!C( OX  )HH-,NU',]OC"2: /2!W T?B]XOWXPDF@#T@=@-'XO>+
MQRO&= 1#2G7>PP                                              
J                                                   "    
 
end
------- Cut Here -------

caster@jove.cs.pdx.edu (Brad J. Caster) (05/30/91)

Checksum for uuencoded portion:

16-bit Checksum    Blocks
----------------   ------
         63043         7

s2525090@techst02.technion.ac.il (Eran Davidov) (05/30/91)

there is a way to block someone from booting from a floppy, which I learned
while playing around with HARDWARE security cards.
they change the boot sectore (or partition) so that any dos not autorized
by them cannot read the hard disk. when a user boots with a password (which
is supplied to the ROM security program) the program puts in memory a filter
that will change the boot sector to what it should be if anyone tries to read it, and that will write the altered sector, if anyone tries to write.
that way if you reset the computer, you have to supply the password again.
I dont know wether this is applicable to a software security routine, since
the code in config.sys is read from the directory, thus there cannot be a filter
,but maybe if a pingpong like (the virus) boot sector method is used, it might
work.