יום ראשון, 6 במרץ 2011

Keylogger for a special project using microsoft powershell

In one project we have to take input of 4 sattelite dishes and decide if the signal is lost. the outcome must be some kind of graph that could show when, where and what device has lost connection, this will help us to learn when a signal was lost and perhaps also in what conditions.
first thing we've done is open a USB keyboard we had and get it's USB controller.

we have 4 input devices so we've decided to use the keyboard numbers 1-4 , each signal will be connected to a certain keyboard input and then we could log it's status once each 100ms.

after searching over the net finding nothing but spam, Mr. Braitmaiere, A family member that has a large mind, has developed this code for us to use in Microsoft PowerShell:



/// Start Code:
$signature = @'
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern short GetKeyState(int virtualKeyCode);
'@
$getKeyState = Add-Type –memberDefinition $signature -name “Win32GetKeyState” -namespace Win32Functions –passThru
$charCheck = @([char]'1', [char]'2', [char]'3', [char]'4')
while ($true)
{
Start-Sleep -Milliseconds 100
$logged = ""
foreach ($char in $charCheck)
{
$vkey = [int]$char
$result = $getKeyState::GetKeyState($vkey)
$result = 0x8000 -band $result
if ($result -ne 0)
{
$logged += " 1 "
}
else
{
$logged += " 0 "
}
}
$now = Get-Date;
$logLine = "signals $logged @ " + $now.ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss:fff")
$fileName = $now.ToUniversalTime().ToString("yyyy-MM-dd") + ".log"
Out-File -FilePath $fileName -Append -InputObject "$logLine"
}
/// end code



This code works quite well, it and writes out the desired sensor a,b,c,d and time each 100ms into a log file.
(post will be updated with follow ups of the project)
הוסף רשומת תגובה