簡體   English   中英

無法在while讀取循環內運行交互式hashcat

[英]Can't run interactive hashcat inside a while read loop

我試圖在循環中多次在bash腳本中運行hashcat。 我遇到的問題是,由於hashcat是交互式的,因此腳本會多次執行它。 我想運行第一個hashcat命令,並且只有在該命令完成后,才應運行第二個。

腳本示例:

while read dict
do
    hashcat -m 0 -a 0 hashfile.hash $dict
done < dictionary_paths

另外,嵌套的while循環又如何呢?

例如:

while read rule_right
do
    while read rule_left
    do
        hashcat -m 0 -a 1 hashfile.hash dict.lst dict.lst --rule-right=$rule_right --rule-left=$rule_left
    done < $rule_left_file
done < $rule_right_file

此處的直接答案是使用標准輸入以外的文件描述符:

while IFS= read -r dict <&3; do
    hashcat -m 0 -a 0 hashfile.hash "$dict" # assuming dict is just one argument
done 3< dictionary_paths

3<表示我們在FD 3上打開dictionary_paths ,然后read ... <&3在讀取操作本身期間將FD 3重定向到stdin。 因此,FD 0 – stdin –在腳本操作期間仍指向其原始源(例如終端)。


對於嵌套循環,請在每個級別使用不同的FD:

while IFS= read -r rule_right <&3; do
    while IFS= read -r rule_left <&4; do
        hashcat -m 0 -a 1 hashfile.hash dict.lst dict.lst \
                --rule-right="$rule_right" --rule-left="$rule_left"
    done 4<"$rule_left_file"
done 3<"$rule_right_file"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM