AutoHotkey Community

It is currently May 27th, 2012, 12:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: December 6th, 2008, 8:42 am 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
SwissKey v.02

This application will lock your pc from the applications tray icon.
Right click the icon, and click on lock.

Image

How it works:
The program blanks the users screen to a black box and prompts the user to enter a SwissKey (USB Drive). Doing so unlocks the station again to be used normally.
The application blocks the windows key and task manager so the user is unable to unlock the workstation or run any applications via #R .

Note:
In order to generate your SwissKey, you must have the designated drive unplugged. Then you can click generate SwissKey to make one. You MUST generate a key before you lock your station.
Panic Key is:!+g which can be changed at your discretion.

Authentication:
The application generates a keycode and stores the ciphered code onto your usb drive. The uncoded copy sits in a database on your hard drive.

To-Do
-More work on the storing of the keys.
-User Login Authentication Via SwissKey

Credits:
Parts of the code come from:
http://www.autohotkey.com/forum/topic9003.html

The rest is from yours truly ;)
Changelog V0.1 - V0.2
-added in cipher and database comparison feature
-added screensaver
-ability to create a SwissKey
-froze mouse movement on pc lock.

Code:
OnMessage(0x219, "notify_change")
DriveGet , dlist, list, REMOVABLE
start=1
salt=o,r,e,s,h,c,i,t,1,t,1,6,y,1,9,k,b,y,z,y,a,z,7,f,v,9,m,8,7,i,8,e,o,h,b,t,p,7,e,5,u,g,r,i,2,s,w,h,c,s,O,8,d,n,6,f,f,j,1,e,m,g,f
string=
count=0
num=0
foundpos=0
generate=0
enable=0
;menu , tray , nostandard
menu , tray , add , Lock , Enable
menu , tray , add , Reload Script , Reloaded
menu , tray , add , Generate SwissKey , generate
menu , tray , add
menu , tray , add , Quit , Quit
hotkey , #r, Off
hotkey , LWin, Off
hotkey , RWin, Off
hotkey , !Tab , Off
^!+g::gosub toggle
#r::
!Tab::
^+Escape::
^Escape::
RWIN::
LWIN::
return

Enable:
if enable = 1
gosub toggle
else
{
gui , 8:+Lastfound +Disabled -caption +toolwindow +alwaysontop
gui , 8:color, black
gui , 8:show, w%A_ScreenWidth% h%A_ScreenHeight% x0 y0 NoActivate, ...
gui , 9:+Lastfound +Disabled -caption +toolwindow +alwaysontop
Gui , 9:Font, S8 CDefault Bold, Verdana
Gui , 9:Add, GroupBox, x6 y7 w330 h130 , Station has been locked
Gui , 9:Font, S12 CDefault Bold, Verdana
Gui , 9:Add, Text, x16 y37 w310 h80 vtext1, Please insert the appropriate SwissKey in order to operate this station.
Gui , 9:Show, h144 w342 ,
enable=1
gosub toggle
}
return

exitapp:
Quit:
exitapp

Reloaded:
Reload

Toggle:
{
  if (start == 0)
    {
      gui , 8:hide
     gui , 9:hide
      hotkey , #r, Off
     hotkey , !Tab , Off
      hotkey , LWin, Off
      hotkey , RWin, Off
     SetTimer , CloseTaskmgr, off
     SetTimer , Idle, off
     blockinput , MouseMoveOff
      start=1
      return
    }
  if (start == 1)
    {
      gui , 8:show
     gui , 9:show
      hotkey , #r, On
     hotkey , !Tab , On
      hotkey , LWin, On
      hotkey , RWin, On
     blockinput , MouseMove
     SetTimer , CloseTaskmgr, 25
     SetTimer , Idle, 2000
      start=0
      return
    }
}

notify_change(wParam, lParam, msg, hwnd)
{ ; give the OS two seconds to do whatever (shuffle drivers or whatnot)
   SetTimer, CheckUSBDrives, -2000
}

Idle:
settimer , Idle, off
random , Nx , 0 , (a_screenwidth-342)
random , Ny , 0 , (a_screenheight-144)
gui , 9:show , x%Nx% y%Ny%
settimer , Idle , 2000
return
 


reset:
Gui , 9:Font, s12 cBlack Bold, Verdana
GuiControl , 9:Font, text1
guicontrol , 9:text , text1 , Please insert the appropriate SwissKey in order to operate this station.
settimer , reset , off
return


CloseTaskmgr:
SetTimer , CloseTaskmgr, off
if (start == 0)
{
IfWinExist , Task Manager
WinClose
IfWinExist , Windows Task Manager
WinClose
}
SetTimer , CloseTaskmgr, on
return

generate:
generate=1
random ,serial1,1,7
random ,serial2 ,10000,29999
random ,serial2a,100000,999999
serial2=%serial2%%serial2a%
random ,serial3,0,23
random ,serial4,1,60
loop
{
  if (count == 4)
  {
    ;ifexist , %A_WinDir%\temp.db
   fileappend , %serial%`n , %A_WinDir%\temp.db
   break   
  }
  else
  {
    random ,number,1,4
   if not foundpos:=RegExMatch(string,number)
      {
     count:=count+1
     string:=string . number
     newpart:=regexreplace(number,number,serial%number%)
     code=%code%%newpart%
     serial:=code
     serial=%serial%
     }
  }
}
count=0
generate=1
msgbox , 1 , Generate SwissKey , Please insert a thumbdrive to create a swisskey and press'OK'.
ifmsgbox Ok
return
else
{
  fileread , datas ,%A_WinDir%\temp.db
  StringReplace, datas, datas, %serial%,, All
  StringReplace, datas, datas, `r`n,, All
  filedelete , %A_WinDir%\temp.db
  fileappend , %datas% , %A_windir%\temp.db
  datas=
  string=
  serial=
  code=
  generate=0
  return
}
return

generate2:
;generate different salt numbers
loop
{
  if (count == 4)
    break
  else
  {
    if (count == 0)
   {
      random ,int1,1,63
     count=1
   }
   if (count == 1)
   {
      random ,int2,1,63
     if (int2 != int1)
       count=2
   }
   if (count == 2)
   {
      random ,int3,1,63
     if (int3 != int1) and if (int3 != int2)
       count=3
   }
   if (count == 3)
   {
      random ,int4,1,63
     if (int4 != int1) and if (int4 != int2) and if (int4 != int3)
       break
   }
  }
}
count=0
loop , parse, salt, `,
{
  if (A_index == int1) or if (A_index == int2) or if (A_index == int3) or if (A_index == int4)
  {
    if (count == 2)
      A_salt=%A_salt%,%A_Loopfield%
    else
    {
      A_salt=%A_salt%%A_Loopfield%
    }
    count:=count+1
  }
}
stringsplit , super, A_salt, `,
SetFormat , integer, h
serial += 0
SetFormat , integer, d
stringtrimleft ,serial,serial,2
serial=%super1%%serial%%super2%
return

decode:
stringtrimleft , code , code, 2
stringtrimright , code , code, 2
code=0x%code%
SetFormat , integer, d
code += 0
code:=code
return

CheckUSBDrives:
DriveGet, nlist, list, REMOVABLE
Loop Parse, nlist
   IfNotInString, dlist, %a_LoopField%
   {
    if generate = 1
   {
     gosub generate2
     ifexist , %a_loopfield%:\unlock.dat
       filedelete , %a_loopfield%:\unlock.dat
     fileappend , %serial% , %a_LoopField%:\unlock.dat
   }
   else
     {
     if start = 0
       {
          guicontrol , 9:text , text1 , Device detected at %a_loopfield%:\`n\
        ifexist %a_loopfield%:\unlock.dat
        {
           fileread, code , %a_loopfield%:\unlock.dat
         gosub decode
         fileread , o_serial , %A_WinDir%\temp.db
         foundpos := Regexmatch(o_serial,code)
         if foundpos > 0
         {
         StringReplace, o_serial, o_serial, %code%,, All
         StringReplace, o_serial, o_serial, `r`n,, All
         filedelete , %A_WinDir%\temp.db
         fileappend , %o_serial% , %A_windir%\temp.db
         }
        }
        if foundpos > 0
        {
          Gui , 9:Font, s12 cGreen Bold, Verdana
         GuiControl , 9:Font, text1
         guicontrol , 9:text , text1 , SwissKey Accepted..
         sleep 2000
         gosub toggle
        }
         else
        {
          Gui , 9:Font, s12 cRed Bold, Verdana
         GuiControl , 9:Font, text1
         guicontrol , 9:text , text1 , ERROR:Please insert a SwissKey.
        }
       }
      }
   if generate = 0
     settimer ,reset, 2000
   else
     Msgbox `t`tSwissKey Created!`nYou may now use the SwissKey to unlock your machine once.
   }
generate=0
foundpos=0
dlist := nlist
return


Last edited by Gosugenji on December 7th, 2008, 6:36 pm, edited 7 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 10:26 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
A few ideas off the top of my head:

1. Remember multi-monitor environments
2. For situations when no screensaver is active, the notification box should move to random positions on screen at regular time intervals
3. To minimize the chances of a workaround, disable all keys but ENTER; should be enough to dismiss the screensaver when there's no mouse connected
4. Since there are scripts that monitor mouse "parking" in screen corners and could possibly launch applications, better restrict mouse range to a small square in the center of the screen
5. The total_keys variable should be directly dependant on the number of built-in serials; add a loop, parse the serials and dump the result to total_keys - it would eliminate inconsistencies
6. Showing the serial of the plugged-in device might not be wise - someone knowledgeable enough could get the idea to crack this script and fit his own serial in
7. Further improvement for better protection could be regularly writing a string (containing date/time hash or whatever) to the USB device and reading it when inserted to unlock; this way we could monitor the access

Good luck! ;)

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 11:55 am 
Offline

Joined: August 20th, 2008, 4:25 pm
Posts: 256
http://www.autohotkey.com/forum/viewtopic.php?t=34877

_________________
-Chavez.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 12:18 pm 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
The scope of this project is to create an alternative to the windows xp login screen, where one could just plug in their usb drive and login to their own desktop.

The serial to unlock will be ciphered and stored in a file on the pc. The cipher command will be in an include portion in a future version as to prevent serial injections as you mentioned earlier.

Im thinking of just disabling the mouse all together when the screen is locked.

As to workarounds, wouldn't the box being +alwaysontop override any new program they may happen to open?

Edit: Almost done with a HUGE update (150+ lines more), coming soon!


Last edited by Gosugenji on December 7th, 2008, 7:21 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 5:22 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Some applications can change the Z-order and might pop up on top of other assumingly on-top applications (like this one).

And it's always good to have choices so even if such scripts already exist, there's always something to learn.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 8:35 am 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
Updated to V.02


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 10:49 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
1. Registry entries might be a better alternative to the commonly-named temp.db file in A_WinDir (which might already exist and pertain to another application).
2. A_ScreenWidth and A_ScreenHeight do not take into account multi-monitor environments; the Help file recommends SysGet,VirtualWidth, 78 and SysGet, VirtualHeight, 79 instead.
3. Choosing Create SwissKey pops up a message box asking for a thumb drive. After one is inserted and SwissKey is created, there's a second messagebox stating 'SwissKey created', however the first messagebox is still displayed.

[EDIT] Here's a screenshot of a Win98SE machine working in dual-monitor, supposedly locked. You may notice that the taskbar became visible after CTRL+ESC (it's usually autohidden) and also is on top of the blank login screen, while the secondary display is fully visible and functional. Since applications (such as SlimBrowser in the screenshot) may have capability to launch external applications (command prompt, etc), this is a critical flaw in SwissKey. Or maybe Win9x is too smart. ;)

Image

[EDIT 2] Forgot to mention the mouse was also functional during the supposedly locked stage.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Last edited by Drugwash on December 7th, 2008, 12:49 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 12:08 pm 
Offline

Joined: July 17th, 2008, 9:46 am
Posts: 225
Taskmanager can be used to exit autohotkey.exe and continue!
Greets,
DHMH


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 2:29 pm 
Offline

Joined: November 29th, 2008, 12:35 am
Posts: 111
Location: United Kingdom
DHMH wrote:
Taskmanager can be used to exit autohotkey.exe and continue!
Greets,
DHMH


surely you can get around this by locking as many keys as you can and auto-moving the mouse to the top right corner of the screen evry .3 seconds? ;p

_________________
Adam
http://moourl.com/8w0tx
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 4:52 pm 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
Chavez wrote:
http://www.autohotkey.com/forum/viewtopic.php?t=34877


In the link, many more good ideas are waiting...
I gave info on how to make it a service that is kept alive even if you end task, (because your exe will be started by another exe that checks), will work in Safe Mode Networking and Safe Mode. http://www.autohotkey.com/forum/viewtop ... 370#235370 And how to disable task manager.. http://www.autohotkey.com/forum/viewtop ... 416#233416

Together, you can make something even cooler! 8)

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 6:34 pm 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
Your ideas are great, however what if a low level limited user account wants the access this script provides? you cant really modify registries then.. plus if this script needs to be deployed to 500 workstations, whats the odds of 3/4 of them being limited user accounts. It would be hell to track which worked and not worked. Im making this as account friendly as possible..

As for the task manager opening, this is tested on Windows XP and it doesnt open with the mouse being locked in one spot.

Custom User logins coming soon via SwissKey..

Screensaver mode edited so its always on top, no matter what..

adding multi monitor support when test in a 2 monitor enviroment. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 10:41 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
I can test dual monitor at any time since that's my daily environment. The two SysGet commands will get the size of the whole virtual desktop in any environment.

If you want to make this script user account-based, then maybe it's best to save separate key files in %APPDATA%\SwissKey or somewhere along that line. This would ensure access for each user. May work in Win9x too.

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 7th, 2008, 11:24 pm 
Offline

Joined: November 29th, 2008, 12:35 am
Posts: 111
Location: United Kingdom
dont wana be ants at the picnic but the second time i tryed it I had to hold the power button down because it wouldnt recognize the code, after i restarted i checked the code in my memory stick and it was the new code not the first one i used

_________________
Adam
http://moourl.com/8w0tx
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2008, 8:19 am 
Offline

Joined: May 7th, 2008, 5:37 pm
Posts: 87
Location: In your Internets
use the panic shortcut, you shouldnt have to restart.

Control + alt + shift + G would bring u back to the desktop.

The code is a one shot code by the way, you always have to generate a new one before you lock it again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2008, 9:00 am 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Shouldn't this operation be completely transparent to the user? I mean, clicking 'Lock' should automatically check the previous code against the one on the thumb drive and if it matches, automatically generate and save the new one.

One more thing: what if the machine has more than one thumb drive connected? How does the user select which one to use as a SwissKey for the first time?

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Google Feedfetcher, SKAN and 6 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group