HOWTO: Using hashcat on Windows through an SSH session

hashcat runs on multiple operating systems. Linux and UNIX provide an easy way to connect to a remote workstation over SSH, but doing so used to be awkward on Windows.

Try the built-in OpenSSH first. Windows has shipped an OpenSSH client and server for years, and between that and Windows Terminal a plain ssh session usually runs hashcat fine, keystrokes included. The winpty route below is worth the trouble only when you are stuck in Cygwin or MSYS2 and the interactive keys do not reach hashcat.

Tools such as Bash on Windows and the PowerShell team's OpenSSH implementation address this need, but they can have significant drawbacks, including rendering and TTY communication problems.

Cygwin and MSYS/MSYS2 can also have TTY-related problems. They rely on mintty, which does not provide unbuffered input. As a result, the 's', 'b', 'q', 'p' keystrokes used by hashcat are buffered when pressed and do not function as intended.

To use hashcat through an SSH session on Windows in these environments, one option is winpty.

The following instructions are taken directly from the winpty README and cover both Cygwin and MSYS/MSYS2.

Disclaimer

THIS GUIDE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. WE WILL NOT ACCEPT ANY LIABILITY FOR ANY SECURITY RISKS YOU INTRODUCE TO YOUR ENVIRONMENT UPON FOLLOWING THIS GUIDE.

At a minimum, you should ensure that all commands are executed in a trusted, and preferably isolated, environment.

Prerequisites

You need the following to build winpty:

  • A Cygwin, MSYS or MSYS2 installation
  • GNU make
  • A MinGW g++ toolchain capable of compiling C++11 code to build winpty.dll and winpty-agent.exe
  • A g++ toolchain targeting Cygwin or MSYS to build winpty.exe

Cygwin packages

The default g++ compiler for Cygwin targets Cygwin itself, but Cygwin also packages MinGW-w64 compilers. As of this writing, the necessary packages are:

  • Either mingw64-i686-gcc-g++ or mingw64-x86_64-gcc-g++. Select the appropriate compiler for your CPU architecture (x86 or x64).
  • gcc-g++
  • make

At the time this tutorial was written, winpty over an SSH session using MSYS or MSYS2 had not been tested. It should work similarly to the Cygwin case.

MSYS packages

For the original MSYS, use the mingw-get tool (MinGW Installation Manager), and select at least these components:

  • mingw-developer-toolkit
  • mingw32-base
  • mingw32-gcc-g++
  • msys-base
  • msys-system-builder

When running ./configure, make sure that mingw32-g++ is in your PATH. It will be in the C:\MinGW\bin directory.

MSYS2 packages

For MSYS2, use pacman and install at least these packages:

  • msys/gcc
  • mingw32/mingw-w64-i686-gcc or mingw64/mingw-w64-x86_64-gcc. Select the appropriate compiler for your CPU architecture (x86 or x64).
  • make

MSYS2 provides three start menu shortcuts for starting MSYS2:

  • MinGW-w64 Win32 Shell
  • MinGW-w64 Win64 Shell
  • MSYS2 Shell

To build winpty, use either the MinGW-w64 Win32 or MinGW-w64 Win64 shortcut, depending on which matches your MSYS2 installation architecture.

These shortcuts add the g++ compiler to your PATH. The 32-bit shortcut uses the mingw32/mingw-w64-i686-gcc package. The 64-bit shortcut uses mingw64/mingw-w64-x86_64-gcc.

Alternatively, install the mingw-w64-cross-gcc and mingw-w64-cross-crt-git packages instead of mingw32/mingw-w64-i686-gcc or mingw64/mingw-w64-x86_64-gcc.

These packages install cross-compilers into /opt/bin, and then any of the three shortcuts will work.

Build winpty

In the project directory, run:

$ ./configure
$ make
$ make install

By default, winpty is installed in /usr/local. Pass PREFIX=<path> to make install to change this location.

Use winpty with hashcat

To run a Windows console program in mintty or Cygwin/MSYS/MSYS2 sshd, prepend winpty to the command line:

$ winpty hashcat.exe -m 0 ....

This should resolve the input-buffering problems.

Because winpty does not support chroot'ed environments, all file paths (such as output files or wordlists) must be relative to the current directory or absolute within the Windows filesystem (i.e. '/opt/data/wordlists/MyWordlist' must be replaced by 'DRIVELETTER:/INSTALLATION_PATH/opt/data/wordlists/MyWordlist').

Example:

If you connect to the remote Windows workstation “TimmyStation” as “sshd”, with Cygwin/MSYS/MSYS2 installed in C:\INSTALL_PATH and hashcat in C:\INSTALL_PATH\opt\data\hashcat-3.20, a successful command line might look like this:

sshd@TimmyStation /opt/data/hashcat-3.20
$ winpty hashcat.exe -m 0 -o C:/INSTALL_PATH/opt/data/hashcat_outputhashes C:/INSTALL_PATH/opt/data/RawMD5_test.dump -a 0 C:/INSTALL_PATH/opt/data/wordlists/MyWordlist -r rules/best66.rule
Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain