月の名前のスクリプトを使用したフィルタリングプロキシ経由

この記事はこのトピックに関する一連の研究であり、行動の指示として使用すべきではありません。



ロックは継続しますが 、暗号化されていないHTTPトラフィックを海外のプロキシTorアノニマイザーに転送したり、ブラウザにトラフィックを保存したりすることまだ歓迎しません。 機会があれば、直接サイトにアクセスしてみます。 同時に、サイトとの通信速度はサードパーティのサービスの負荷に依存しません。



FirefoxにRequestPolicyプラグインをインストールし、サイトのHTTPヘッダーで見つけました。

X-Squid-Error:"403 Access Denied"
      
      





これは、サイトへの接続が透過プロキシを経由することを意味します。



この記事では、Lua( Wiki )で書かれたローカルプロキシを使用してみます。



LuaSocket 2.0.2をダウンロードした 、小さなローカルプロキシスクリプトを作成しました。



 require "socket" local cors = {} function main() local proxy_bind = socket.tcp() proxy_bind:setoption("reuseaddr", true) --    proxy_bind:bind("localhost", 8080) --       proxy_bind:listen(100) -- 100    proxy_bind:settimeout(0) -- 0s           . repeat --      local client, accept_err = proxy_bind:accept() if (client) then local new_cor = coroutine.create(new_client) local ok, err = coroutine.resume(new_cor, client) if (ok) then table.insert(cors, new_cor) end end local new_list = {} for id, cor in ipairs(cors) do local ok, err = coroutine.resume(cor) if (ok) then table.insert(new_list, cor) end end cors = new_list socket.sleep(0.001) --      until accept_err and (accept_err ~= "timeout") end
      
      





 --           function new_client(client) client:settimeout(0) local headers, err = get_data(client:receive("*a")) local host, port = get_host_port(headers) headers = headers:gsub("( HTTP/1.1)\13(\10Host: )", "%1%2") local server = socket.connect(host, port) print("NC", host, port) if (server) then if (not send_connect(server, string.format("%s:%s", socket.dns.toip(host), port))) then server:close() server = socket.connect(host, port) end if (server) then headers = headers:gsub("\10Connection%: keep%-alive\13\10", "\10Connection: close\13\10") server:send(headers) cycle_data(server, client, host) end end print("CLOSED", host, port) server:close() client:close() end
      
      





 function get_data(data, err, part, marker) data = (data or part) return data, err end
      
      





 function get_host_port(headers) if headers and (#headers > 0) then if not (headers:find(" HTTP/1.1\13\10Host: ", 1, true)) then return end local _, _, host, port = headers:find(" HTTP/1.1\13\10Host: ([a-z0-9%.%-]+):?([0-9]*)\13\10") if (#port > 0) then port = tonumber(port) else port = 80 end return host, port end end
      
      





 --   CONNECT      TCP  local connect = "CONNECT %s HTTP/1.1\13\10Host: %s\13\10\13\10" function send_connect(server, address) server:send(string.format(connect, address, address)) server:settimeout(0.1) local headers, err = get_data(server:receive("*a")) while ((not headers) or (#headers <= 12)) and not (err and (err ~= "timeout")) do coroutine.yield() --      local data, err = get_data(server:receive("*a")) if (data and #data > 0) then headers = (headers or "") .. data end end return headers:find("^HTTP/1.[01] 200") end
      
      





 --      function cycle_data(server, client, host, port) local _in_, out = server, client repeat _in_:settimeout(0) out:settimeout(1) local data, receive_err = get_data(_in_:receive("*a")) if data and (#data > 0) then data = data:gsub("\13\10Connection%: keep%-alive\13\10", "\13\10Connection: close\13\10") local index, send_err = send_data(out, data) end coroutine.yield() --      until (receive_err and (receive_err ~= "timeout")) or (send_err and (send_err ~= "timeout")) end
      
      





 function send_data(out, data) local index = 0 repeat index = index +1 index, err = get_index(out:send(data, index)) until index >= #data or (err and (err ~= "timeout")) return index, err end function get_index(index, err, partial_index) return (index or partial_index), err end main()
      
      





LuaSocket 2.0.2を使用して、解凍したフォルダーに「proxy.lua」としてスクリプトを保存します。



単純な「proxy.bat」ファイルを作成して「proxy.lua」を実行し、そこに保存します。

 %~d0 cd %~p0 lua5.1 proxy.lua pause
      
      







最後の記事の「proxy.pac」を編集します 。 (住所が変更されました)

 function FindProxyForURL(url, host) { if (shExpMatch(url, "http://*") && shExpMatch(host, "rutracker.og")) { return "PROXY localhost:8080; PROXY rutracker.og; DIRECT"; } /*  HTTPS   HTTP   CONNECT   */ if (shExpMatch(url, "https://*") && shExpMatch(host, "rutracker.og")) { return "PROXY rutracker.og; DIRECT"; } return "DIRECT"; }
      
      







「proxy.bat」をダブルクリックしてプロキシを起動します。 ブラウザを再起動し、rutracker.ogを開きます。



スクリプトは迅速に記述され、松葉杖で修復されました。 これは完全なプロキシではありません。

誰かがより簡単な解決策を思い付くなら、私はとても幸せです。



オプション:

ドメインのパーティション分割が可能な場合は、 hostsファイルに行を追加ます(アドレスが変更されました)。

 #198.51.100.0 rutracker.og
      
      





ドメインを分割する場合は、「#」を削除して行のコメントを解除し、サーバーへのアクセスを返すことができます。

 198.51.100.0 rutracker.og
      
      







そのため、たとえば、 レジストリまたはその他のソースからIPを取得することにより、rutor.ogサーバー(アドレスが変更された)へのアクセスを返すことができます。



使用される情報:

Lua 5.1リファレンスマニュアル

LuaSocket:TCP / IPサポート

2つのスクリプトでDPIをだます

プロキシ自動構成(PAC)

ホスト-ウィキペディア



All Articles