python - Python 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 读取这种字符串?
解决方案
argparse
您的问题与Python无关。
$6
等是对 Unix/Linux 中 [不存在的] 环境变量的引用。它们的值为''
(空字符串)。将整个散列括在单引号中,以保护数据不被 shell 解释:'$6$krVh8s..$ttQmt30au3s9wHywp/...'
.
推荐阅读
- python - 为 Keras 制作自定义损失函数
- sas - PROC PRINT 和 PROC MEANS
- ms-access - 当有多个最大值时,选择最大值在 VBA 中返回什么?
- c - 读取变量时出错,无法访问内存
- node.js - 我是否需要打开或关闭文件才能通过 Node.js 读取文件?
- nuget - 在 C:\Users\username\.nuget\packages\ 中找不到该包。运行 NuGet 包还原以下载包
- c# - query.wait 没有完成
- mysql - 更新依赖于另一个表中 ENUM 列值的表中的值
- javascript - 流符号不可谷歌搜索,我在文档中的任何地方都看不到它(小于,然后是冒号 - “<:”)
- r - 在降价中包含行 r 代码,其中名称使用重音符号