hashcat Forum

Full Version: Simple hashcat wrapper in C#
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
This is the wrong approach. If you want to keep track of the progress you better parse the restore file. See here for structure: http://hashcat.net/wiki/oclhashcat_lite#...store-file
Hi atom,
Thanks for your reply. I am also not a big fan of parsing stdout, but the fact is that stdout gives you much more information than the restore file does. We make heavy use of the temperature , and speed measures provided in stdout.

I am aware that they can be taken from another application, but it is better, in my opinion, to take the output from one place only instead of executing several external commands to gather all needed information.

I will try several different approaches to write to console program and hope that any of them will work.

If you or anyone else here knows the right way to send command to the console please share it, despite this being the wrong way to read information from hashcat Smile