Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash GIT_ASKPASS包含超过个echo_Bash_Git_Credentials - Fatal编程技术网

Bash GIT_ASKPASS包含超过个echo

Bash GIT_ASKPASS包含超过个echo,bash,git,credentials,Bash,Git,Credentials,我正在GIT_ASKPASS上玩不同的变体,我想制作一个POC,可以从外部“存储”中提取密码。为了证明这一点,我认为只要调用API并从响应返回密码就很简单了。问题是,git挂起了我提供的脚本,我不知道为什么 一些信息: 脚本是chmod+x-ed $(…)中的命令工作正常 我在这里看到了回应,但它告诉我的是,我们正在做同样的事情 我的git是git版本2.26.2 以下是脚本: #!/usr/bin/env bash password="$(http https://postman-ech

我正在GIT_ASKPASS上玩不同的变体,我想制作一个POC,可以从外部“存储”中提取密码。为了证明这一点,我认为只要调用API并从响应返回密码就很简单了。问题是,
git
挂起了我提供的脚本,我不知道为什么

一些信息:

  • 脚本是
    chmod+x
    -ed
  • $(…)
    中的命令工作正常
  • 我在这里看到了回应,但它告诉我的是,我们正在做同样的事情
  • 我的git是
    git版本2.26.2
以下是脚本:

#!/usr/bin/env bash

password="$(http https://postman-echo.com/get password=="trust-me" | jq '.args | .password' | tr -d '"')"
exec echo "${password}"
下面是日志:

GIT_TRACE=1 GIT_ASKPASS=./git_ask_pass_url git clone "https://askpass-git-2@github.com/kornicameister/askpass-git-test.git" /tmp/ddddd
23:43:22.266086 git.c:439               trace: built-in: git clone https://da-user@github.com/kornicameister/askpass-git-test.git /tmp/ddddd
Cloning into '/tmp/ddddd'...
23:43:22.270259 run-command.c:663       trace: run_command: git-remote-https origin https://askpass-git-2@github.com/kornicameister/askpass-git-test.git
23:43:23.054837 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 get'
23:43:23.057470 git.c:703               trace: exec: git-credential-cache --timeout=28800 get
23:43:23.057506 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 get
23:43:23.059112 run-command.c:663       trace: run_command: ./git_ask_pass_url 'Password for '\''https://askpass-git-2@github.com'\'': '

更新:

好的,我将脚本更改为:

#!/usr/bin/env bash

test "${GIT_TRACE}" -eq 1 && set -x
curl "https://postman-echo.com/get?password=${GIT_PASSWORD}" | jq -r '.args | .password'
通过这种设置,我们有:

GIT_PASSWORD="foo-course" GIT_TRACE=1 GIT_ASKPASS=./git_ask_pass_url git clone "https://foo-1@github.com/kornicameister/foo-test.git" /tmp/b              20:57:03
20:57:04.473789 git.c:439               trace: built-in: git clone https://foo-1@github.com/kornicameister/foo-test.git /tmp/b
Cloning into '/tmp/b'...
20:57:04.478021 run-command.c:663       trace: run_command: git-remote-https origin https://foo-1@github.com/kornicameister/foo-test.git
20:57:05.258448 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 get'
20:57:05.262080 git.c:703               trace: exec: git-credential-cache --timeout=28800 get
20:57:05.262126 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 get
20:57:05.264706 run-command.c:663       trace: run_command: ./git_ask_pass_url 'Password for '\''https://foo-1@github.com'\'': '
++ curl 'https://postman-echo.com/get?password=foo-course'
++ jq -r '.args | .password'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   238  100   238    0     0    409      0 --:--:-- --:--:-- --:--:--   409
+ password=foo-course
+ exec echo foo-course
20:57:06.387701 run-command.c:663       trace: run_command: 'git credential-cache --timeout=28800 store'
20:57:06.391164 git.c:703               trace: exec: git-credential-cache --timeout=28800 store
20:57:06.391214 run-command.c:663       trace: run_command: git-credential-cache --timeout=28800 store
20:57:07.176076 run-command.c:663       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 24977 on kornicameister' --check-self-contained-and-connected
20:57:07.177517 git.c:439               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 24977 on kornicameister' --check-self-contained-and-connected
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 2), reused 10 (delta 2), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (2/2), done.
20:57:07.202708 run-command.c:663       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
20:57:07.204214 git.c:439               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
20:57:07.206501 run-command.c:663       trace: run_command: /tmp/b/.git/hooks/post-checkout 0000000000000000000000000000000000000000 581d755bfb10e1beee93fc190cd99428f9f1595c 1

所以听起来好像问题出在使用
http
而不是普通的
curl

好的,你可以使用上面更新中发布的
curl
,但我必须给http一些荣誉。如果您希望在
GIT_ASKPASS
中使用它,这样做非常重要:

http -I "https://postman-echo.com/get" password=="${GIT_PASSWORD}" | jq -r '.args | .password'
注意
-I
标志。它阻止从标准输入读取数据
GIT_ASKPASS
实际上在stdin上接收到一些字符串,因此它在最初的尝试中被卡住了


所以,是的,我想一个结论是,有时候最简单的工具可以工作,而更高级的工具会导致意外问题。

这不是你的问题,但是使用
jq-r
,这样你就不需要
tr
。这也将修复其他错误(任何需要转义序列编码为JSON的密码在当前代码中转换后都会出错)…至于跟踪直接问题,我强烈建议更改脚本的第二行,添加如下内容:
exec 2>~/logfile;PS4=“${BASH_SOURCE##*/}:$LINENO+”;设置-x
,然后通读
~/logfile
的内容。顺便问一下,愚蠢的问题,但是这个
http
命令是什么?如果它是点文件中定义的shell函数或别名,则非交互shell通常无法访问它。@CharlesDuffy
http
对应于
httpie
,它也非常有用,有很多很好的功能,可以简化通过commad线路对http请求的操作。我注意到,
set-x
跟踪来确定git\u ask\u pass\u url
中发生的事情仍然没有包括在问题中。是的,应该在这里。但是,
-b
是多余的,因为对于,默认情况下只打印响应主体。thx@JakubRoztocil。我想我们可以称之为“最好安全,然后道歉”:)我从上面的答案中删除了
-b
。这更冗长,但多余。