Module: PWN::Plugins::CredentialAttack
- Defined in:
- lib/pwn/plugins/credential_attack.rb
Overview
hydra/john/hashcat wrappers and ~/.pwn/wordlists convention.
Constant Summary collapse
- WORDLISTS =
File.join(Dir.home, '.pwn', 'wordlists')
Class Method Summary collapse
- .authors ⇒ Object
- .fetch_seclists(opts = {}) ⇒ Object
- .hashcat(opts = {}) ⇒ Object
- .help ⇒ Object
- .hydra(opts = {}) ⇒ Object
- .identify_hash(opts = {}) ⇒ Object
- .john(opts = {}) ⇒ Object
- .medusa(opts = {}) ⇒ Object
- .required_bins ⇒ Object
- .wordlist_dir(opts = {}) ⇒ Object
Class Method Details
.authors ⇒ Object
92 93 94 |
# File 'lib/pwn/plugins/credential_attack.rb', line 92 public_class_method def self. "AUTHOR(S):\n 0day Inc. <[email protected]>\n" end |
.fetch_seclists(opts = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/pwn/plugins/credential_attack.rb', line 82 public_class_method def self.fetch_seclists(opts = {}) dest = (opts[:dest] || File.join(WORDLISTS, 'SecLists')).to_s return dest if Dir.exist?(dest) FileUtils.mkdir_p(File.dirname(dest)) url = opts[:url] || 'https://github.com/danielmiessler/SecLists.git' stdout, stderr, status = Open3.capture3('git', 'clone', '--depth', '1', url, dest) { dest: dest, stdout: stdout, stderr: stderr, exit: status.exitstatus } end |
.hashcat(opts = {}) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/pwn/plugins/credential_attack.rb', line 44 public_class_method def self.hashcat(opts = {}) PWN::Plugins::PreflightChecker.require_bin!(name: 'hashcat') hashfile = opts[:hashfile] || opts[:file] mode = (opts[:mode] || 0).to_i wordlist = opts[:wordlist] || File.join(WORDLISTS, 'rockyou.txt') stdout, stderr, status = Open3.capture3('hashcat', '-m', mode.to_s, hashfile.to_s, wordlist) { stdout: stdout, stderr: stderr, exit: status.exitstatus } end |
.help ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/pwn/plugins/credential_attack.rb', line 96 public_class_method def self.help puts "USAGE: # List host binaries this module expects to be installed. #{self}.required_bins # Run wordlist dir and return its result #{self}.wordlist_dir( ensure: 'optional - ensure value consumed by #wordlist_dir' ) # Run hydra and return its result #{self}.hydra( target: 'optional - hostname, IP, or CIDR to scan', service: 'optional - service value consumed by #hydra', user: 'optional - user value consumed by #hydra (defaults to opts[:login])', login: 'optional - login value consumed by #hydra', wordlist: 'optional - wordlist value consumed by #hydra', extra: 'optional - Array extra value consumed by #hydra', tasks: 'optional - tasks value consumed by #hydra' ) # Run john and return its result #{self}.john( hashfile: 'required - hashfile value consumed by #john (defaults to opts[:file])', file: 'required - filesystem path' ) # Run hashcat and return its result #{self}.hashcat( hashfile: 'optional - hashfile value consumed by #hashcat (defaults to opts[:file])', file: 'optional - filesystem path', mode: 'optional - mode value consumed by #hashcat', wordlist: 'optional - wordlist value consumed by #hashcat' ) # Run medusa against a host (lockout-aware: keep -t low). #{self}.medusa( target: 'required - hostname or IP', user: 'optional - username (defaults to root)', wordlist: 'optional - password list path', module: 'optional - medusa module name (defaults to ssh)' ) # Guess a hash type from a sample (hashid if present, else length heuristics). #{self}.identify_hash( hash: 'required - hash string to identify', sample: 'optional - alias for hash' ) # Clone SecLists into ~/.pwn/wordlists/SecLists when missing. #{self}.fetch_seclists( dest: 'optional - destination directory', url: 'optional - git URL (defaults to danielmiessler/SecLists)' ) # Print the AUTHOR(S) string for this module. #{self}.authors " constants.sort end |
.hydra(opts = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pwn/plugins/credential_attack.rb', line 21 public_class_method def self.hydra(opts = {}) PWN::Plugins::PreflightChecker.require_bin!(name: 'hydra') target = opts[:target].to_s service = (opts[:service] || 'ssh').to_s user = opts[:user] || opts[:login] wordlist = opts[:wordlist] || File.join(WORDLISTS, 'rockyou.txt') extra = Array(opts[:extra]) cmd = ['hydra', '-l', user.to_s, '-P', wordlist, '-t', (opts[:tasks] || 4).to_s] cmd += extra cmd += [target, service] stdout, stderr, status = Open3.capture3(*cmd) { stdout: stdout, stderr: stderr, exit: status.exitstatus } end |
.identify_hash(opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pwn/plugins/credential_attack.rb', line 63 public_class_method def self.identify_hash(opts = {}) sample = (opts[:hash] || opts[:sample]).to_s raise 'ERROR: hash is required' if sample.empty? if PWN::Plugins::PreflightChecker.bin?(name: 'hashid') stdout, = Open3.capture3('hashid', sample) return { hash: sample, tool: 'hashid', stdout: stdout } end kind = case sample when /\A\$2[aby]\$/ then 'bcrypt' when /\A[a-f0-9]{32}\z/i then 'md5' when /\A[a-f0-9]{40}\z/i then 'sha1' when /\A[a-f0-9]{64}\z/i then 'sha256' else 'unknown' end { hash: sample, kind: kind } end |
.john(opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/pwn/plugins/credential_attack.rb', line 35 public_class_method def self.john(opts = {}) PWN::Plugins::PreflightChecker.require_bin!(name: 'john') hashfile = opts[:hashfile] || opts[:file] raise 'ERROR: hashfile is required' if hashfile.to_s.empty? stdout, stderr, status = Open3.capture3('john', hashfile.to_s) { stdout: stdout, stderr: stderr, exit: status.exitstatus } end |
.medusa(opts = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/pwn/plugins/credential_attack.rb', line 53 public_class_method def self.medusa(opts = {}) PWN::Plugins::PreflightChecker.require_bin!(name: 'medusa') target = opts[:target].to_s raise 'ERROR: target is required' if target.empty? cmd = ['medusa', '-h', target, '-u', (opts[:user] || 'root').to_s, '-P', (opts[:wordlist] || File.join(WORDLISTS, 'rockyou.txt')).to_s, '-M', (opts[:module] || 'ssh').to_s] stdout, stderr, status = Open3.capture3(*cmd) { stdout: stdout, stderr: stderr, exit: status.exitstatus } end |
.required_bins ⇒ Object
12 13 14 |
# File 'lib/pwn/plugins/credential_attack.rb', line 12 public_class_method def self.required_bins %w[hydra john hashcat medusa] end |
.wordlist_dir(opts = {}) ⇒ Object
16 17 18 19 |
# File 'lib/pwn/plugins/credential_attack.rb', line 16 public_class_method def self.wordlist_dir(opts = {}) FileUtils.mkdir_p(WORDLISTS) if opts[:ensure] != false WORDLISTS end |