Last active
July 20, 2021 20:33
-
-
Save Alexander-Mages/3a83d74442c180c603bf2183f0a78104 to your computer and use it in GitHub Desktop.
sctp transport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import socks | |
import threading | |
#threading but with better performance, allows multiple cores to be used | |
from multiprocessing import Process | |
#will need to eventually implement both socks versions | |
print("launching socks proxy to communicate with the tor browser...") | |
sockssock = socks.socksocket() | |
socksversion = "SOCKS5" # this will need to be defined somewhere else | |
if socksversion == "SOCKS5": | |
sockssock.set_proxy(socks.SOCKS5, "127.0.0.1") | |
elif socksversion == "SOCKS4": | |
sockssock.set_proxy(socks.SOCKS4, "127.0.0.1") #subsequent argument is port if desired | |
elif socksversion == "HTTP": | |
sockssock.set_proxy(socks.HTTP, "127.0.0.1") | |
else: | |
print("error") | |
#add an exception here, might want to look into custom errors | |
sockssock.bind(("127.0.0.1", 9050)) #whatever port tor uses for socks | |
sockssock.listen(25) | |
print("launching upstream->downstream sctp socket on port 6000...") | |
sctpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SCTP) | |
sctpsock.bind(("0.0.0.0", 6000)) | |
sctpsock.listen(25) | |
#initialize pool | |
#controls threads running with concurrency | |
#source is socks/tor browser, destination is tor bridge | |
def proxyDownstream(source, dest): | |
while True: | |
#this buffer size is arbitrary and holds no reasoning, probably want to change if helps performance | |
print("first") | |
data = source.recv(4096) | |
if data == '': | |
break | |
dest.sendall(data) | |
#source is sctp traffic from bridge, destination is socks/tor browser | |
def proxyUpstream(source, dest): | |
print("second works") | |
while True: | |
data = source.recv(4096) | |
if data == '': | |
break | |
dest.sendall(data) | |
#spawn concurrent threads | |
print("1") | |
sctpsocket, address = sctpsock.accept() | |
print("sctp connection accepted from bridge at", address) | |
sockssocket, address = sockssock.accept() | |
print("socks connection accepted from tor browser at", address) | |
#CHANGE NAME OF SOCKSSOCKET, IT IS WAY TOO SIMIMLAR TO SOCKSOCKET | |
#no idea whether to use multiprocessing, threading, concurrency, or asyncrynosity | |
downstreamTransport = Process(target=proxyDownstream(source=sockssocket, dest=sctpsocket)) | |
upstreamTransport = Process(target=proxyUpstream(source=sctpsocket, dest=sockssocket)) | |
downstreamTransport.start() | |
upstreamTransport.start() | |
upstreamTransport.join() | |
downstreamTransport.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment