Forms curl命令行POST密码

Forms curl命令行POST密码,forms,post,curl,passwords,Forms,Post,Curl,Passwords,我有下面的curl命令,它工作得非常好: curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \ --form 'username=xxx' --form 'password=yyy' 'http://example.com' 它登录到站点,发布一个带有可变名称用户名和密码的表单 问题是:我不想以明文形式传递密码 我还尝试将密码保存在工作目录(chmod 600 passwd)中名为passwd的文件中,并使用了以

我有下面的curl命令,它工作得非常好:

curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=yyy' 'http://example.com'
它登录到站点,发布一个带有可变名称用户名和密码的表单

问题是:我不想以明文形式传递密码

我还尝试将密码保存在工作目录(chmod 600 passwd)中名为passwd的文件中,并使用了以下curl命令(这就是为什么我使用--form而不是--data,在清除密码的情况下可以很好地工作),但是,它不起作用:

curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=<passwd' 'http://example.com'
curl--silent--location-cookie“$cookie”--cookiejar“$cookie”\

--form'username=xxx'--form'password=在环境变量中设置密码,例如
导出PASSWD=secret
并在
--form“password=${PASSWD}”
中使用它。在我看来,使用环境变量的答案是正确的。尽管我可能只是在bash中添加了这一点,但您可以使用
read
命令,这将提示输入密码,而不会使其在历史记录中可见

所以用法是这样的

$ read -s PASSWD  # -s is there so the characters you type don't show up
$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form "password=${PASSWD}" 'http://example.com'
更新:

在注释中找到的另一个解决方案是使用
curl
--数据urlencodename@filename
参数。 引用手册页:

name@filename 这将使curl从给定的文件(包括任何换行符)加载数据,URL对该数据进行编码并在POST中传递

最后的命令看起来像

$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--data 'username=xxx' --data-urlencode "password@passwd" 'http://example.com'

在命令行中传递机密是不安全的,因为它们在进程列表中可用

您应该使用
--data urlencodename@filename
方法

                 This will make curl load data from the given file
                 (including any newlines), URL-encode that data and
                 pass it on in the POST. 
-K,--config


另请参见

感谢您的快速回复。我忘了告诉大家我想在cron中调度curl命令,所以使用环境变量没有帮助,因为我不想在crontab文件中的cron命令前面放置
export PASSWD=secret
。为什么不这样做呢
PASSWD=$(使用密码的文件的cat路径);克朗--形成“密码= $PASWD”…<代码>(格式很糟糕,所有的东西都应该在一行中)@ STX73-你可以设置一个永久的环境变量,你不必每次都进行导出。它肯定是有效的,但是,我会考虑解决方案<代码>——表单“密码=奇怪的是它不能替换文件的内容。”也许可以试试这个
curl--data-urlencode“password@passwd“
          Specify a text file to read curl arguments from. The
          command line arguments found in the text file will be used
          as if they were provided on the command line.