简体   繁体   English

使用netcat构建的代理不允许http基本身份验证

[英]Proxy built with netcat not allowing http basic authentication

I made a simple proxy server using nc , here's the one-liner: 我使用nc制作了一个简单的代理服务器,这是一种代码:

mkfifo queueueue
nc -l 8080 <queueueue | nc http://$JENKINS_HOSTNAME 80 >queueueue

It listens on port 8080 and then forwards the data to a connection to our Jenkins server. 它侦听端口8080,然后将数据转发到与我们的Jenkins服务器的连接。 Jenkins is behind a VPN, and the machine I am running this proxy on has VPN access. 詹金斯(Jenkins)在VPN后面,并且我在其上运行此代理的计算机具有VPN访问权限。

On my other machine (no VPN access), I would like to curl the Jenkins server, here's the command to initiate the request through the proxy: 在我的另一台机器(无VPN访问)上,我想curl Jenkins服务器,这是通过代理启动请求的命令:

http_proxy=10.1.10.10:8080 curl --user $JENKINS_USERNAME:$JENKINS_PASSWORD http://$JENKINS_HOSTNAME/api/json

Both the client and the proxy machine are on the same network, I can ping and ssh between them, also, I know that the client is connecting to the proxy server, I think the failure is arising when the client is trying to authenticate, here's the output when I try to curl: 客户端和代理计算机都在同一网络上,我可以在它们之间ping和ssh,而且,我知道客户端正在连接到代理服务器,我认为当客户端尝试进行身份验证时会出现故障,这是当我尝试卷曲时的输出:

$ http_proxy=10.1.10.10:8080 curl --user $JENKINS_USERNAME:$JENKINS_PASSWORD http://$JENKINS_HOSTNAME/api/json
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="<some other url>">here</a>.</p>
<hr>
<address>Apache Server at $JENKINS_HOSTNAME Port 80</address>
</body></html>

How can I curl through a proxy like this with HTTP Basic Authentication? 如何使用HTTP Basic Authentication遍历像这样的代理?

I would use ssh for this instead of netcat. 我会为此使用ssh而不是netcat。

Just to get some confusion out of the way, I will be referring to the node with VPN access as the "server", and the node without VPN access as the "client". 只是为了消除混乱,我将具有VPN访问权限的节点称为“服务器”,将没有VPN访问权限的节点称为“客户端”。

On the server side you should only need to install and have an ssh server running (in my test I have OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011). 在服务器端,您只需要安装并运行ssh服务器(在我的测试中,我有OpenSSH_5.9p1,OpenSSL 0.9.8r 2011年2月8日)。

On the client side you will need to do the following: 在客户端,您需要执行以下操作:

1) in your /etc/hosts file add in the address that your target URL resolves as on the server. 1)在/ etc / hosts文件中,添加目标URL解析为服务器上的地址。 I wasn't able to get curl to run DNS lookups through the proxy, which is why this is necessary. 我无法通过代理来运行DNS查找,因此这是必要的。

2) setup ssh keys between the server and the client. 2)在服务器和客户端之间设置ssh密钥。 while this is not necessary, it makes life easier. 尽管这不是必需的,但它使生活更轻松。

3) run the following ssh command to have ssh act as a SOCKS proxy: 3)运行以下ssh命令以使ssh充当SOCKS代理:

user@host$ ssh -vND 9999 <server>

-v is there so you can see what is going on with ssh, -N tells ssh to not execute a remote command - this is useful for just simple port forwarding -D this option is what actually forwards your local requests to the server -v在那里,您可以看到ssh发生了什么,-N告诉ssh不执行远程命令-这仅对简单的端口转发很有用-D此选项实际上将本地请求转发到服务器

4) now you should be able to run the curl command you have above, but add in 4)现在,您应该能够运行上面的curl命令,但要添加

---socks5 localhost:9999

Your full command will look like this: 您的完整命令将如下所示:

curl --user $USER:$PASSWORD --socks5 localhost:9999 http://$JENKINS/api/json

If I can figure out how to forward the DNS requests from curl through ssh I'll update the ticket. 如果我能弄清楚如何通过ssh从curl转发DNS请求,我将更新票证。

edit: formatting, awful grammar. 编辑:格式化,糟糕的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM