473,588 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keylogger in Python

Jay
ok, i thought for 2 seconds i might have created a Keylogger in python
but i still have one major think stopping me... PYTHON. when i run the
program i have python create a file named keylog2.log and it then logs
all keys pressed/typed in the python IDE into that file. All i want to
know now is how do i hide or background python so that it will log all
the keys pressed outside of Python.

feel free to play around with my program... but please post ur findings
on my post...
############### ############### ############### ########
class keylogger:
pass

keylogging = keylogger()
keylog = open("keylog2.l og", "w")
text = raw_input()

keylog.write(te xt)
keylog.close
keylog = open("keylog2.l og", "r")
keylog.read

Jul 30 '05 #1
12 6810
"Jay" <ja*****@gawab. com> writes:
ok, i thought for 2 seconds i might have created a Keylogger in python
but i still have one major think stopping me... PYTHON. when i run the
program i have python create a file named keylog2.log and it then logs
all keys pressed/typed in the python IDE into that file. All i want to
know now is how do i hide or background python so that it will log all
the keys pressed outside of Python.


You are completely confused and keyloggers don't work anything like that.
Why do you want to log keystrokes anyway?
Jul 30 '05 #2
On 30 Jul 2005 01:11:32 -0700, "Jay" <ja*****@gawab. com> declaimed the
following in comp.lang.pytho n:
ok, i thought for 2 seconds i might have created a Keylogger in python
No, all you've done is create a /user mode/ application that
reads ITS system input stream (and not even character by character --
raw_input doesn't return until a <cr> has been entered, at which point
you get all characters up to that point).
but i still have one major think stopping me... PYTHON. when i run the
program i have python create a file named keylog2.log and it then logs
all keys pressed/typed in the python IDE into that file. All i want to
know now is how do i hide or background python so that it will log all
the keys pressed outside of Python.

A keylogger, at the lowest level, injects itself between the
keyboard driver and the OS dispatcher (for windowing systems, in
particular). It has to be transparent -- your program is consuming the
characters meaning they are not available anywhere else; a key logger
has to "copy" the keys (probably raw key-codes and not characters) from
the input stream without blocking them from reaching the normal
application that want them. That's why, for example, Windows (NT) uses
the <ctrl><alt><del > to get a log-in prompt. That key combination is
handled at the very lowest level of the keyboard driver, and NEVER
passes out to where a user program can intercept it -- meaning one can
not write a "login capture" program to fake a Windows login screen.

Doing key logging is highly OS dependent. Under AmigaOS, one
would inject a key handler at high-priority into the OS input stream
chain (a linked list of priority ordered programs that want to see
input). The logger would receive, on its input port, an OS packet with
the timestamp and key codes, could log it, and then return it to the OS
to be passed to the next program in the chain (some programs consume the
stream and don't pass it on). It was also easy to inject fake events --
a program could inject, for example, disk-change events that other
programs would respond to.

On Windows... I don't know for sure... Chapter 27 of
"Programmin g Applications for Microsoft Windows 4th Ed." might be of use
(may also be a more up-to-date version available too). It shows some
system call of AttachThreadInp ut() being used to link a program's input
stream (queue in the book's terminology) to another program so both
receive the same data (I think). You're logger would have to hook into
the process start-up system so that it could link to every process that
might be reading keys.

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Jul 30 '05 #3
Jay
yo, thanks for the great input. And the only reason i want to create a
python based keylogger is because there is none. Just a fun project...
But im gonna do some more research on the keyboard drivers and stuff
like that and to learn how to attach my python porgrams into the
sub-processes so that it would instead log every char instead of just
char in the IDE.
thx

Jul 31 '05 #4
Jay wrote:
yo, thanks for the great input. And the only reason i want to create a
python based keylogger is because there is none. Just a fun project...
But im gonna do some more research on the keyboard drivers and stuff
like that and to learn how to attach my python porgrams into the
sub-processes so that it would instead log every char instead of just
char in the IDE.


I think this is going to be much harder than you think, and I imagine
this will only end in frustration for you. You will not be able to do it
well with just Python. I would recommend a different fun project.
--
Michael Hoffman
Jul 31 '05 #5
Michael Hoffman wrote:
I think this is going to be much harder than you think, and I imagine
this will only end in frustration for you. You will not be able to do it
well with just Python. I would recommend a different fun project.

Actually, it's pretty easy, using the pyHook and Python win32 modules.
I use code like this to detect when the user is away from the keyboard.

import pyHook
import time
import pythoncom

def OnKeyboardEvent (event):
print event.Ascii

hm = pyHook.HookMana ger()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard ()

while True:
pythoncom.PumpM essages()
Sw.

Jul 31 '05 #6
si**********@gm ail.com wrote:
Actually, it's pretty easy, using the pyHook and Python win32 modules.


Well, I'll be.
--
Michael Hoffman
Jul 31 '05 #7
[Michael Hoffman]
Jay wrote:
yo, thanks for the great input. And the only reason i want to
create a python based keylogger is because there is none. Just a
fun project... But im gonna do some more research on the keyboard
drivers and stuff like that and to learn how to attach my python
porgrams into the sub-processes so that it would instead log every
char instead of just char in the IDE.

I think this is going to be much harder than you think, and I imagine
this will only end in frustration for you. You will not be able to do
it well with just Python. I would recommend a different fun project.


I'm just stumbling on that message, and did not follow the whole thread,
sorry if I repeat things already discussed. My point is that Python is
able to do surprising things, given the `fcntl' and `ioctl' modules.

Surely on Linux, logging keys under X-Windows or under virtual terminals
are quite different matters. Let me share a related experience for
virtual terminals. I once had to rush the port on Linux a few QNX
applications, written in C, which were using the QNX term library
for input and display. In console mode, the QNX keyboard is richer
than the Linux one. As users wanted to retain the _exact_ keyboard
functionality, I saw no choice but reading raw scan codes on the Linux
side. So, I wrote a term library emulator as a thin C layer, which was
itself using a Python module (Python was to be transparently embedded by
the emulated library) for doing the bulk of keyboard processing.

It was something pretty heretic to do, I know. But Python was more than
fast enough for handling the low-level keyboard reading, for applications
otherwise all written in C. But it allowed the port to be done quickly.

While debugging such a thing, you often loose the keyboard and with it,
the capability of switching terminals, so you have to devise some extra
machinery for restoring the keyboard into a usable state.

--
François Pinard http://pinard.progiciels-bpi.ca
Jul 31 '05 #8
François Pinard wrote:
Surely on Linux, logging keys under X-Windows or under virtual terminals
are quite different matters. Let me share a related experience for
virtual terminals. I once had to rush the port on Linux a few QNX
applications, written in C, which were using the QNX term library
for input and display. In console mode, the QNX keyboard is richer
than the Linux one. As users wanted to retain the _exact_ keyboard
functionality, I saw no choice but reading raw scan codes on the Linux
side. So, I wrote a term library emulator as a thin C layer, which was
itself using a Python module (Python was to be transparently embedded by
the emulated library) for doing the bulk of keyboard processing.


You think this is a suitable beginner project?

And for that matter, it doesn't sound like you were doing keylogging, as
it is usually understood to mean globally logging keypresses, no matter
the application being presented to the user.
--
Michael Hoffman
Jul 31 '05 #9
[Michael Hoffman]
You think this is a suitable beginner project?
One surely learns a lot! :-)
And for that matter, it doesn't sound like you were doing keylogging, as
it is usually understood to mean globally logging keypresses, no matter
the application being presented to the user.


One possible avenue to keylogging might be to start a shell, over the
keyboard processing layer, presuming the shell do only simple things
over its standard input.

But most likely, the shell is playing termios trickery and such things.
So one might have to use pty's to get a working solution. Agreed, this
is not all evident, and probably too much of a challenge for a beginner.

--
François Pinard http://pinard.progiciels-bpi.ca
Jul 31 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4521
by: Kevin | last post by:
i'd like to create a KeyLogger that saves to a file, the keystrokes and the program/window changes, that a user does. i wanted to know if there's a better way to do this than using a timer and the GetAsyncKeyState API, i dont think the timer is efficient. Like is there something that u can do, like each time a Keyboard event happens. if not, what is the best way. THANKS
2
8689
by: Du Dang | last post by:
i wanna use keys combo to show and hide my app could someone show me how to capture global key strokes ??? essentially it behave like a keylogger program, but it not :-) thanks
11
13597
by: CodeLeon | last post by:
Hi. I would like to create a keylogger, are there any good tutorials? Also, more importantly, how do i hide this process from the task manager? NO, i am not a virus writer, so PLEASE no messages asking me my intentions or ridiculing me for wanting to do this as other legitimate entities have been doing this for years. Than You!
2
8043
by: JC | last post by:
I'm looking for help creating a keylogger program.It doesn't have to be hidden because I want to allow people access to what they have written. Can anyone help me with this or send me tutorials or code on how to create a keylogger. Thanks *** Sent via Developersdex http://www.developersdex.com ***
10
4123
by: Apolakkiatis | last post by:
Does anyone have a tutorial they could give me or post on how to make a keylogger to monitor my computer because my brother also uses it.... i dont want just the code for one, i want to understand how the VB code for it works also so i can get a feel for it... Thanx
3
2068
by: NickNeedsHelp | last post by:
Hey, my name's Nick, and I seriously need some help. One of my friends has been dating his girlfriend for coming up 2 years now, and recently there's been way too many rumours around school she's being unfaithful. A few days ago, he came to me asking for my help for some way of tracking what she types on her PC (I'm his best friend, he knows I'm computer savvy, but I'm nowhere near code-savvy :\), and I've agreed to help him. I have no...
4
1786
by: pavanip | last post by:
Hi friends, I am developing one application like Anti spyware.how to get those spyware dlls present in our registry or our system.And what is adware,Trojans, Malware, Keylogger.how to find those data programmatically.please anyone provide me source code for that.I am not getting any idea for how to get those data from the registry. Thanks in advance Pavani
0
7862
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5729
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
1459
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.