将数据包包装在连接请求中,直到到达最后一个代理 [英] Wrap packets in connect requests until reach the last proxy

查看:78
本文介绍了将数据包包装在连接请求中,直到到达最后一个代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是问自己代理链如何构建这样的代理链:

I always asked myself how proxychains can build a chain of proxies like this:

我的电脑 -> 代理 1 -> 代理 2 -> 代理 3 -> 代理 4 -> 代理 5 -> 站点

my pc -> proxy1 -> proxy2 -> proxy3 -> proxy4 -> proxy5 -> site

这个程序如何使所有这些链都链接起来,请求通过所有这些代理发送到站点,而答案通过所有这些代理发送到我的电脑?是否可以使用套接字库创建代理链:

How can this program make possible that all this chain is linked and the request goes to the site through all these proxies and that the answer goes to my pc through all these proxies? Is this possibile to make a chain of proxies using socket library:

mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

或其他类似的图书馆?

我想知道它是如何工作的,因为我知道 proxychains 是用 C 编写的,而且由于我只懂 Python,我无法分析源代码.

I'd like to know how it works, cause I know proxychains is written in C and since I only know Python, I can't analyse the source.

推荐答案

proxychains 背后的主要思想是代理允许你建立一条通向另一个系统的隧道.例如,如果您想通过 HTTP 代理 A 和 SOCKS4 代理 B 访问系统 T,请执行以下操作:

The main idea behind proxychains is that proxies allow you to build a tunnel to another system. For example if you want to reach system T via HTTP proxy A and SOCKS4 proxy B you do the following:

  • 创建到代理 A 的 TCP 连接(即套接字).
  • 执行 HTTP CONNECT 请求以建立到代理 B 的隧道 - 请参阅RFC 2817 有关 CONNECT 的详细信息.建立此隧道后,您的套接字仍连接到代理 A,但代理 A 会将您的所有数据发送到代理 B,反之亦然.
  • 在套接字上发送 SOCKS4 标头以通过代理 B 建立另一个隧道.此 SOCKS4 标头将通过套接字从您的系统发送到代理 A,然后代理 A 将其转发到代理 B.然后 B 将连接到最终目标 T 基于此标头中的信息,然后将它接收到的任何数据(通过从程序中获取的代理 A)转发到 T,反之亦然.有关 SOCKS 协议的更多信息,请参阅维基百科.
  • Create a TCP connection (i.e. a socket) to proxy A.
  • Do a HTTP CONNECT request to establish a tunnel to proxy B - see RFC 2817 for details about CONNECT. After this tunnel is established your socket is still connected to proxy A but proxy A will sent all your data to proxy B and vice versa.
  • Send the SOCKS4 header on the socket to establish another tunnel via proxy B. This SOCKS4 header will be sent from your system via the socket to proxy A which will then forward it to proxy B. B will then make a connection to the final target T based on the information in this header and then forward any data it receives (via proxy A which got it from your program) to T and vice versa. For more information on the SOCKS protocol see Wikipedia.

从那时起,您从套接字发送到代理 A 的任何数据都将转发到代理 B,然后转发到目标 T.类似的 T 会将其响应发送回 B,后者将其发送回 A,后者将其发送到您的申请.

From then on any data you send from your socket to proxy A will be forwarded to proxy B and then forwarded to target T. Similar T will sent its response back to B which will sent it back to A which will sent it to your application.

是否可以使用套接字库创建代理链:

Is this possibile to make a chain of proxies using socket library:

    mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   

或其他类似的图书馆?

从上面的描述中可以看出,这些步骤是必需的

As you can see from the description above the steps are needed

  • 创建套接字
  • 将套接字连接到代理 A
  • 通过 A 创建到代理 B 的隧道 - 使用 HTTP 或 SOCKS 协议
  • 类似通过 [A,B] 创建隧道到代理 C
  • 类似创建一个通过 [A,B,C] 到 D 的隧道
  • ... 直到您的最后一个代理被指示建立通向最终目标的隧道 T

只要您对 HTTP 和 SOCKS 协议有适当的了解,就可以在 Python 中轻松实现.或者您可以简单地将您的 python 程序包装到类似于任何其他程序的代理链中.这将神奇地连接到连接并为您构建隧道.

This can be easily implemented in Python as long you have the appropriate knowledge of the HTTP and SOCKS protocols. Or you could simply wrap your python program into proxychains similar to any other program. This will magically hook into the connect and build the tunnels for you.

这篇关于将数据包包装在连接请求中,直到到达最后一个代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆