\  Registry and File security no LabInfo

\ INCLUDE NTNetLib
Anew Labinfo

\ Registries ****************************************************

Registry remoto

: RegMachine ( computerNumber -- )
   HKEY_LOCAL_MACHINE Connect: remoto

   z" Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" NewKey: remoto
   z" Software\Microsoft\Windows NT\CurrentVersion\Winlogin"       NewKey: remoto
   z" Software\Microsoft\Windows\CurrentVersion\Internet Settings\Url History"  NewKey: remoto

   z" Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"  z" NoNetHood"                      1  SetDWORD: remoto  \ I-57
   z" Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"  z" NoSaveSettings"                 1  SetDWORD: remoto  \ I-85, I-108
   z" System\CurrentControlSet\Services\Browser"                    z" Start"                          2  SetDWORD: remoto  \ I-4
   z" System\CurrentControlSet\Control\NetworkProvider"             z" RestoreConnection"              0  SetDWORD: remoto  \ I-58
   z" System\CurrentControlSet\Services\LanManServer\Parameters"    z" Autodisconnect"        0xFFFFFFFF  SetDWORD: remoto  \ I-286
   z" System\CurrentControlSet\Services\Tcpip\Parameters"           z" PPTPTcpMaxDataRetransmissions" 30  SetDWORD: remoto  \ I-312
   z" System\CurrentControlSet\Services\Tcpip\Parameters"           z" ForwardBufferMemory"    256 100 *  SetDWORD: remoto  \ I-317
   z" System\CurrentControlSet\Services\Tcpip\Parameters"           z" KeepAliveTime"        3 3600000 *  SetDWORD: remoto  \ I-322  3 horas
   z" System\CurrentControlSet\Services\Tcpip\Parameters"           z" KeepAliveInterval"         600000  SetDWORD: remoto  \ I-322  10 minutos
   z" Software\Microsoft\Windows NT\CurrentVersion\Winlogon"        z" DeleteRoamingCache"             1  SetDWORD: remoto  \ I-80
   z" Software\Microsoft\Windows NT\CurrentVersion\Winlogin"        z" DeleteRoamingCache"             1  SetDWORD: remoto  \ I-80
   z" Software\Microsoft\Internet Explorer\Main"                    z" Cache_Directory"      z" C:\temp"  SetSZ: remoto
   z" Software\Microsoft\Internet Explorer\Main"                    z" History_Directory"    z" C:\temp"  SetSZ: remoto
   z" Software\Microsoft\Windows\CurrentVersion\Internet Settings\Url History" z" Directory" z" C:\temp"  SetSZ: remoto

(( TCP/IP filtering
   z" System\CurrentControlSet\Services\Tcpip\Parameters"           z" EnableSecurityFilters"          1  SetDWORD: remoto  \ I-328  on
   z" System\CurrentControlSet\Services\IBMFE1\Parameters\Tcpip"    z" RawIpAllowedProtocols"          0  SetDWORD: remoto  \ I-329   ?
   z" System\CurrentControlSet\Services\IBMFE1\Parameters\Tcpip"    z" TcpAllowedPorts"              550  SetDWORD: remoto  \ I-330   ?
   z" System\CurrentControlSet\Services\IBMFE1\Parameters\Tcpip"    z" UdpAllowedPorts"                0  SetDWORD: remoto  \ I-331   ?
))

   Disconnect: remoto
;

: RegTodos
   48 32 DO  I .  I RegMachine  LOOP
;

\ Test application for directory browsing class +++++++++++++++++++

DirBrowse List

: .FileName  ( -- )
   CR Show: List
   Dir?: List  IF ."  is directory"
                  ProcessDirectory: List
                  ."    directory done"
               THEN
;

: dirtree
  ['] .FileName FileProcess: List
  ProcessFiles: List
;

\ Home$ *********************************************************************

Process Privileges

StudentDirBrowse Home
FileSecurity StudentFile

\ Report total size of multimedia files  ++++++++++++++++++++++

create aluno MAXSTRING allot       \ guarda matricula do aluno
: to_aluno  ( zstr -- )
   aluno over asciiz->asc-len 1+ nip cmove ;

Create MultiMedia ," .JPG.jpg.MP3.mp3.MPG.mpgMPEGmpeg.AVI.avi.MOV.mov"
Create Install ," .ZIP.zip.EXE.exe.ARJ.arj"

variable PictureSize
variable TotalPictureSize
variable SoftSize
variable TotalSoftSize

: .Size  1024 / 8 U.R ;

: .Sizes
    PictureSize @ SoftSize @ + 1000000 >
    IF   CR aluno asciiz->asc-len TYPE
         PictureSize @ dup .Size  TotalPictureSize +!
         SoftSize @ dup .Size     TotalSoftSize +!
         start/stop
    THEN ;

: ano? ( zstr -- )  \ conta de aluno do ano ?
   @  Name: Home  @  0xffffff and  = ;

: SumSizes
   Root?: Home IF   PictureSize off
                    SoftSize off
                    StudentDir?: Home IF
                                          z" g97" ano? IF
                                                  Name: Home  to_aluno
                                                  ProcessDirectory: Home
                                                  .Sizes
                                               THEN
                                      THEN
               ELSE
                    Dir?: Home IF   ProcessDirectory: Home
                               ELSE Multimedia Extension?: Home
                                    IF  Size: Home  PictureSize +!  THEN
                                    Install Extension?: Home
                                    IF  Size: Home  SoftSize +!  THEN
                               THEN
               THEN
;

: ReportSize
   TotalPictureSize off
   TotalSoftSize off
   ['] SumSizes FileProcess: Home
   CR ." Matricula   Pics   Softs"
   ProcessFiles: Home
   CR ." Total   " TotalPictureSize @ .Size
                   TotalSoftSize @ .Size
;

\ Browse through home diretory and set ownership and access rights ++++++++++

: SetHomeDir ( AccessorName -- )
    Change: StudentFile
    Name: Home  Set: StudentFile
    ProcessDirectory: Home
;

: SetHomeFile ( -- )
   Root?: Home IF
                  StudentDir?: Home             IF
                                                    CR Show: Home
                                                    Name: Home  SetHomeDir
                                                THEN
               ELSE
                  Name: Home  Set: StudentFile
                  Dir?: Home IF  ProcessDirectory: Home  THEN
              THEN
;

: PrepareProcessHome
   All: Privileges
   z" Administradores" owner: StudentFile
   ['] SetHomeFile FileProcess: Home
;

: ProcessHome      \ home$ must be mounted on current disk
   PrepareProcessHome
   ProcessFiles: Home
;

\ Browse through home diretory and verify ownership ++++++++++

variable CheckHomeFile>

: CheckHomeFile ( -- )
   Root?: Home IF
                  StudentDir?: Home IF
                                        Name: Home  Change: StudentFile
                                        ProcessDirectory: Home
                                    THEN
               ELSE
                  Name: Home  OwnerOk?: StudentFile
                  IF    Dir?: Home IF  ProcessDirectory: Home  THEN
                  ELSE  CR Cd: Home TYPE  ASCII \ EMIT  Show: Home
                        Name: Home  Set: StudentFile
                        Dir?: Home IF
                                        ['] SetHomeFile FileProcess: Home
                                        ProcessDirectory: Home
                                        CheckHomeFile> @ FileProcess: Home
                                   THEN
                  THEN
              THEN
;

: CheckHome
   All: Privileges
   z" Administradores" owner: StudentFile
   ['] CheckHomeFile CheckHomeFile>  !
   CheckHomeFile> @ FileProcess: Home
   ProcessFiles: Home
;

\ Client PC discs  *********************************************************

RemoteDirBrowse discoC
FileSecurity sysFile

CREATE AvoidList
 ," C$"
     ," ffastun.ffa"
     ," ffastun.ffl"
     ," ffastun.ffo"
     ," ffastun0.ffx"
     ," pagefile.sys"
     ," RECYCLER"
     ," TEMP"
     ," "
 ," C$\Arquivos de Programas\Microsoft Office\Office"
     ," Normal.dot"
     ," "
 ," C$\Arquivos de programas\Microsoft Office\Office"
     ," Normal.dot"
     ," "
 ," C$\Arquivos de Programas\PLUS!\Microsoft Internet"
     ," cookies.txt"
     ," "
 ," C$\WINNT"
     ," ?"
     ," Active Setup Log.BAK"
     ," extend.dat"
     ," COOKIES"
     ," drwtsn32.log"
     ," MSIMGSIZ.DAT"
     ," KeyHook.dll"
     ," user.dmp"
     ," hh.dat"
     ," PIF"
     ," "
 ," C$\WINNT\Desktop"
     ," ??????????"
     ," "
 ," C$\WINNT\Java"
     ," Classes"          \ talvez tirar da lista também
     ," "
 ," C$\WINNT\system32"
     ," ??????????"
     ," calc.GID"
     ," drwtsn32.GID"
     ," FFASTLOG.TXT"
     ," MSForms.TWD"
     ," QBASIC.INI"
     ," winfile.GID"
     ," temppf.sys"
     ," "
 ," C$\WINNT40"
     ," ?"
     ," Active Setup Log.BAK"
     ," extend.dat"
     ," COOKIES"
     ," drwtsn32.log"
     ," MSIMGSIZ.DAT"
     ," KeyHook.dll"
     ," user.dmp"
     ," hh.dat"
     ," PIF"
     ," "
 ," C$\WINNT40\Desktop"
     ," ??????????"
     ," "
 ," C$\WINNT40\Java"
     ," Classes"          \ talvez tirar da lista também
     ," "
 ," C$\WINNT40\system32"
     ," ??????????"
     ," calc.GID"
     ," drwtsn32.GID"
     ," FFASTLOG.TXT"
     ," MSForms.TWD"
     ," QBASIC.INI"
     ," temppf.sys"
     ," winfile.GID"
     ," "
 ," C$\WINNT40\SYSTEM32"
     ," ??????????"
     ," calc.GID"
     ," drwtsn32.GID"
     ," FFASTLOG.TXT"
     ," MSForms.TWD"
     ," QBASIC.INI"
     ," temppf.sys"
     ," winfile.GID"
     ," "
 ," "


\ Look for files not owned by administrator ++++++++++++++++++++++++++

: ReportIntruder ( -- )
   Name: discoC  OwnerOk?: sysFile
   IF    \ if good file owner keep on searching
         Dir?: discoC IF  ProcessDirectory: discoC  THEN
   ELSE  \ if wrong file owner mark for deletion
         Dir?: discoC  IF    CR ." RD /S /Q "
                       ELSE  CR ." DEL /F /Q /A "  THEN
         ASCII " EMIT
            Cd: discoC  12 /String TYPE  ASCII \ EMIT
            Show: discoC
         ASCII " EMIT
   THEN
;

: ReportIntruders
   132 8000 SetMaxColRow cls \ increase the console buffer size
   z" Administradores" owner: sysFile
   ['] ReportIntruder FileProcess: discoC
   AvoidList avoid: discoC

   22 1 DO
     I SetC$: discoC
     CR ." NET USE X: " ShowC$: discoC
\     CR ." FOR /D %%f in (X:\WINNT\Profiles\g9*) do rd /s /q %%f "
\     CR ." FOR /D %%f in (X:\WINNT40\Profiles\g9*) do rd /s /q %%f "
     CR ." X:"
     ProcessFiles: discoC
     CR ." C:"
     CR ." NET USE X: /delete" CR
   LOOP
;

: ReportOnLine
   45 32 DO
     I SeeC$: discoC
   LOOP
;


\ Browse through discs and set ownership and access rights +++++++++

: SetClientFile ( -- )
   Name: discoC  Set: sysFile
   Dir?: discoC  IF  ProcessDirectory: discoC  THEN
;

: ProcessClients
   All: Privileges
   z" Administradores" Owner: sysFile
   z" Usuários"  Read: sysFile
   ['] SetClientFile FileProcess: discoC
   AvoidList avoid: discoC

   22 12 DO
     I SetC$: discoC
     ProcessFiles: discoC
   LOOP
;

: ProcessSomeFilesInClients
   All: Privileges
   z" Administradores" Owner: sysFile
   z" Usuários" Read: sysFile
   ['] SetClientFile FileProcess: discoC
   AvoidList avoid: discoC

   49 48 DO
     I SetC$: discoC
     z" WINNT\Profiles\All Users\Menu iniciar\Programas\X-Win32"
         REL>ABS Call SetCurrentDirectory win-abort" Down directory failed."
     ProcessFiles: discoC
   LOOP
;


