Python argparse减少了一半参数

时间:2018-11-03 04:20:36

标签: python python-3.x command-line-arguments argparse

我试图输入sha512哈希作为参数,但argparse却无缘无故地将其切掉了一半。当我输入Unix哈希(MiqkFWCm1fNJI)时,它可以按预期工作。我试图搜索类似的内容,但未找到任何内容。 我的命令行参数代码如下:

def check_args():
    parse = argparse.ArgumentParser()
    parse.add_argument('-p', '--password', type=str, action='store', help='enter your hashed password: -p your_hash')
    parse.add_argument('-w', '--wordlist', help='add your wordlist: -w wordlist')
    parse.add_argument('-f', '--file', help='file with hashes: -f your_hashes')

    args_list = parse.parse_args()

    return args_list

使用代码的一部分:

    c_arg = check_args()

    psw = c_arg.password
    wordlist = c_arg.wordlist
    file = c_arg.file
    print(psw)

所以当我运行脚本时

python crack.py -p $6$krVh8s..$ttQmt30au3s9wHywp/KGdFKGe1WoEK4xpFJupMA.I06/tdv1//4x7e1gSU2e2Qu/1kQ0rfqXRxghfBX0Io1BJ.

我得到以下输出:

../KGdFKGe1WoEK4xpFJupMA.I06/tdv1//4x7e1gSU2e2Qu/1kQ0rfqXRxghfBX0Io1BJ.

应为:

 $6$krVh8s..$ttQmt30au3s9wHywp/KGdFKGe1WoEK4xpFJupMA.I06/tdv1//4x7e1gSU2e2Qu/1kQ0rfqXRxghfBX0Io1BJ.

如果我使用相同的参数运行相同的脚本,它将按预期工作:

python crack.py -p MiqkFWCm1fNJI

输出:

MiqkFWCm1fNJI

这可能有什么问题,如何使argparse读取这种字符串?

1 个答案:

答案 0 :(得分:1)

您的问题与argparse或Python无关。

$6等是Unix / Linux中对[不存在]环境变量的引用。它们的值为''(空字符串)。将整个哈希用单引号引起来,以防止数据被外壳'$6$krVh8s..$ttQmt30au3s9wHywp/...'解释。