“第 10 行:敏锐:找不到命令”是什么意思?我的 if 语句的意思是什么?

发布于 2025-01-11 13:19:00 字数 1101 浏览 0 评论 0原文

这是我的脚本:

#!/bin/bash

#read password.lst, hash each word, store in variable and check it against our hash

target_hash="14a4b8e7ae966e72a3a2c51633bfabc6"
password_lst=/usr/share/metasploit-framework/data/wordlists/password.lst

while IFS= read -r password
  do
    hashed_password=printf $password | /usr/bin/md5sum | cut -d  " " -f 1

    if [ $hashed_password == $target_hash ]
                then 
                        printf "==========================\n"
                        printf "Found Password: $password\n"
                        printf "==========================\n"
                        break
                else 
                        printf "Password: $password\n"
                        printf "Target hash: $target_hash\n"
                        printf "Current Hash: $hashed_password\n"
        fi

done < "$password_lst"

目的是对文件 password.lst 中的每个单词进行哈希处理,对照 target_hash 检查它,如果正确,则输出正确的密码,直到循环到达那里,输出它当前正在处理的哈希值。

我在第 10 行和第 12 行不断收到错误。有谁知道可能出了什么问题以及如何修复它?

Here's my script:

#!/bin/bash

#read password.lst, hash each word, store in variable and check it against our hash

target_hash="14a4b8e7ae966e72a3a2c51633bfabc6"
password_lst=/usr/share/metasploit-framework/data/wordlists/password.lst

while IFS= read -r password
  do
    hashed_password=printf $password | /usr/bin/md5sum | cut -d  " " -f 1

    if [ $hashed_password == $target_hash ]
                then 
                        printf "==========================\n"
                        printf "Found Password: $password\n"
                        printf "==========================\n"
                        break
                else 
                        printf "Password: $password\n"
                        printf "Target hash: $target_hash\n"
                        printf "Current Hash: $hashed_password\n"
        fi

done < "$password_lst"

The purpose is to hash each word in the file password.lst, check it against the target_hash and if it's correct, output the correct password and until the loop gets there, output what hash it's currently working on.

I keep getting errors in lines 10 and 12. Does anyone know what could be wrong and how I can fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不…忘初心 2025-01-18 13:19:00

我认为这行代码并不像您想象的那样工作:

hashed_password=printf $password | /usr/bin/md5sum | cut -d  " " -f 1

shell 将此视为:

  • 将环境变量 hashed_pa​​ssword 设置为 printf,然后运行 ​​$password< /code> (即展开变量并将值作为命令运行)并设置该环境变量
  • 将上一步的结果通过管道传输到 /usr/bin/md5sum
  • 将上一步的结果通过管道传输进入 cut ....

我认为您想要的是评估整个事情并将结果分配给hashed_pa​​sword?如果是这样,您需要使用这种形式:

var=$(evaluate this thing and assign it to the var)

所以:

hashed_password=$(printf $password | /usr/bin/md5sum | cut -d  " " -f 1)

I think this line doesn't work the way you might think:

hashed_password=printf $password | /usr/bin/md5sum | cut -d  " " -f 1

The shell sees this as:

  • Set the env var hashed_password to printf and then run $password (that is, expand the variable and run the value as a command) with that env vars set
  • Pipe the results of the previous step into /usr/bin/md5sum
  • Pipe the results of the previous step into cut ....

What I think you want is to evaluate the whole thing and assign the result into hashed_pasword? If so, you need to use this form:

var=$(evaluate this thing and assign it to the var)

So:

hashed_password=$(printf $password | /usr/bin/md5sum | cut -d  " " -f 1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文