Simple hashcat wrapper in C#
#1
Hi all,
I am trying to create a simple wrapper around oclHashcat-lite that can get the status from the command so that I can used it programatically. Unfortunately so far I've been unable to send any key in an automatic manner to the hashcat process. Could you please help a little?
here is the simple wrapper class:
Code:
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace testhc
{
    class MainClass
    {
        private static StringBuilder hcOutput = null;
        private static int numOutputLines = 0;

        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern bool AttachConsole (int pid);

        public static void Main (string[] args)
        {
            Console.WriteLine ("Creating HashCat process...");
            Process process = new System.Diagnostics.Process ();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.FileName = "D:/tmp/oclHashcat-lite-0.09/cudaHashcat-lite32.exe";
            process.StartInfo.WorkingDirectory = "D:/tmp/oclHashcat-lite-0.09";
            process.StartInfo.Arguments = "9b957cc6ab97cbf88c4f6f0f146adafe";
            process.StartInfo.CreateNoWindow = true;
            hcOutput = new StringBuilder ("");
            process.OutputDataReceived += new DataReceivedEventHandler (HCOutputHandler);
            process.Start ();
            StreamWriter hcStreamWriter = process.StandardInput;
            process.BeginOutputReadLine ();
            Console.WriteLine ("Process running");
            hcStreamWriter.AutoFlush = true;
            while (true) {
                Thread.Sleep (10000);
                hcStreamWriter.WriteLine ('s');
                hcStreamWriter.Flush ();
                Console.WriteLine (hcOutput);
            }
        }

        private static void HCOutputHandler (object sendingProcess,
            DataReceivedEventArgs outLine)
        {
            // Collect the hashcat command output.
            if (!String.IsNullOrEmpty (outLine.Data)) {
                numOutputLines++;

                // Add the text to the collected output.
                hcOutput.Append (Environment.NewLine +
                    "[" + numOutputLines.ToString () + "] - " + outLine.Data);
            }
        }
    }
}

Thanks in advance.


Messages In This Thread
Simple hashcat wrapper in C# - by djbobyd - 03-13-2012, 12:56 AM
RE: Simple hashcat wrapper in C# - by atom - 03-13-2012, 11:16 AM
RE: Simple hashcat wrapper in C# - by djbobyd - 03-13-2012, 11:53 AM