staging.inyokaproject.org

Keine Ausgabe des grep Ergebnisses in shell while Schleife

Status: Ungelöst | Ubuntu-Version: Kubuntu 20.04 (Focal Fossa)
Antworten |

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13242

Falls hier noch jemand Spaß an Geschwindigkeitsvergleichen hat, kann er diese Ruby-Version nehmen

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/ruby

require 'digest'

passwords = {}

File.foreach(ARGV.shift) do |line|
  if %r{^\S+\s+(\S+)\s*$} =~ line
    hash = Digest::SHA1.hexdigest($1)
    hash.upcase!
    passwords[hash.freeze] = $1
  end
end

pwned = ARGV.shift

block = proc do |io|
  io.each_line do |line|
    line.chomp!

    # if %r{^(\h+):\d+$} =~ line
    #   hash = $1
    if %r{^\h+} =~ line
      hash = $&
      pw = passwords[hash] and puts "Found '#{pw}' with hash #{hash}!"
    end
  end
end

mime = IO.popen(%w{file --brief --mime-type} << pwned) {|io| io.readline.chomp}

case mime
when 'application/x-7z-compressed'
  IO.popen(%w{7z x -so} << pwned, &block)
when 'text/plain'
  File.open(pwned, &block)
else
  fail "ERROR: no idea what to do with MIME type #{mime} of #{pwned}"
end

Parameter

  1. Name der Datei mit Passwörtern, die zu prüfen sind.

  2. Name der pwned-Liste als .7z-Datei oder ausgepackt.

Antworten |