📜 ⬆️ ⬇️

Through a filtering proxy using a script in the name of the moon

This article is only a study on the topic and should not be used as an instruction for action.

Blocking continues, and I still don’t welcome the return of unencrypted HTTP traffic to overseas proxies , Tor , anonymizers, and the inclusion of saving traffic in the browser. As long as there is an opportunity, I will try to go straight to the sites. At the same time, the speed of communication with the site will not depend on the workload of the third-party service.

I installed the RequestPolicy plugin on Firefox and found it on the site’s HTTP headers.
X-Squid-Error:"403 Access Denied" 

This means that the connection to the site goes through a transparent proxy.
')
In this article I will try to go through a local proxy written in Lua ( Wiki )

Downloading LuaSocket 2.0.2 I wrote a small local proxy script.

 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() 

Save the script as “proxy.lua” in the unpacked folder with LuaSocket 2.0.2.

Create a simple "proxy.bat" file to run "proxy.lua", which we will save there.
 %~d0 cd %~p0 lua5.1 proxy.lua pause 


Now edit the “proxy.pac” from the previous article . (Addresses changed)
 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"; } 


We launch the proxy by double clicking on “proxy.bat”. Restart the browser and open rutracker.og.

The script was written quickly and repaired with crutches. This is not a full proxy.
If anyone comes up with a solution easier, I will be very happy.

Additionally:
In case of possible domain separation, add a line to the hosts file (Addresses are changed):
 #198.51.100.0 rutracker.og 

And if the domain is divided, you can uncomment the line by deleting the "#" and return access to the server.
 198.51.100.0 rutracker.og 


So for example, you can return access to the server rutor.og (address changed) by taking its ip from the registry or other sources.

Information used:
Lua 5.1 Reference Manual
LuaSocket: TCP / IP support
We fool the DPI with two scripts
Proxy Auto Configuration (PAC)
hosts - Wikipedia

Source: https://habr.com/ru/post/276623/


All Articles