Hi all,
I would like to write a C# application (IRC client) that is using TOR. I read a lot, but I still don't know how can I run TOR proxy in transparent way (from my c# code).
I see that Tor Stem (https://stem.torproject.org/) can be used by Python code or there are packages for Linux, but not C# (.NET).
How can I run Tor proxy from C# ? Is there a library (dll) that I can run ? (without need to have open Tor Bundle browser).
Thanks for help
On 2014-12-15 16:51, Hollow Quincy wrote:
Hi all,
I would like to write a C# application (IRC client) that is using TOR. I read a lot, but I still don't know how can I run TOR proxy in transparent way (from my c# code).
I see that Tor Stem (https://stem.torproject.org/) can be used by Python code or there are packages for Linux, but not C# (.NET).
How can I run Tor proxy from C# ? Is there a library (dll) that I can run ? (without need to have open Tor Bundle browser).
Let your application start a 'private' Tor node and connect your program using SOCKS to it.
Greets, Jeroen
1) connect TOR through socks port(localhost:9050 default) from your c# application (TCP/IP) 2) Negotiate with TOR SOCKS( read https://www.ietf.org/rfc/rfc1928.txt carefully). Here is a simple c code .hope this will help.. ############################################################ //Create socket for client. sockfd = socket(PF_INET, SOCK_STREAM, 0); if (sockfd == -1) { perror("Socket create failed.\n") ; return -1 ; }
//Name the socket as agreed with server. address.sin_family = AF_INET; address.sin_addr.s_addr = inet_addr("127.0.0.1"); address.sin_port = htons(9050); len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len); //#######################################STEP1 DONE####################### char buf[1024]; send(sockfd,"\x05\x01\x00",3,0); // \x05= SOCKS5, \x01=NEXT BYTE LENGTH,\x00= NO AUTHENTICATION
int bytes_recv = recv(sockfd, buf,sizeof(buf),0); if ((buf[0] != 5) || buf[1] == 0xFF) { return 1; } //####################################NEGOTIATION 1 DONE############### \05=SOCKS5,01=CONNECT,00=reserved,03=DOMAIN, \ \x77\x77\x77\x2e\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d = www.google.com \ \x00\x50 == port(80)
send(sockfd,"\x05\x01\x00\x03\x0e\x77\x77\x77\x2e\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x00\x50",21,0); bytes_recv = recv(sockfd, buf,sizeof(buf),0); //####################################NEGOTIATION 2 DONE ################ char request[1024] = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
send(sockfd,request,sizeof(request),0);
int bytes_recieved =0; bytes_recieved = recv(sockfd, buf, 1024, 0); buf[bytes_recieved] = '\0'; cout<<buf<<endl; ############################### SENDING HTTP GET AND GETTING HEADER AS ANSWER #####
On Mon, Dec 15, 2014 at 4:51 PM, Hollow Quincy hollow.quincy@gmail.com wrote:
Hi all,
I would like to write a C# application (IRC client) that is using TOR. I read a lot, but I still don't know how can I run TOR proxy in transparent way (from my c# code).
I see that Tor Stem (https://stem.torproject.org/) can be used by Python code or there are packages for Linux, but not C# (.NET).
How can I run Tor proxy from C# ? Is there a library (dll) that I can run ? (without need to have open Tor Bundle browser).
Thanks for help _______________________________________________ tor-dev mailing list tor-dev@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
Hi,
I don't know if it's possible to use Tor as a library, but there are a few Java apps that communicate over Tor by launching a Tor process and using it as a SOCKS proxy. Does that sound like what you're aiming to do?
Here's a quick rundown of what you need to do:
1. Compile tor.exe from source, or copy it from the latest Tor Browser Bundle (your app won't need to execute the Tor Browser).
2. Launch tor.exe from within your app, using command-line arguments to pass the location of the config file and the PID of the controlling process (i.e. your app). The complete command will look something like this:
/path/to/tor.exe -f /path/to/config __OwningControllerProcess <pid>
3. Control tor.exe via the local control port using the Tor control protocol. There's a Java library that implements this protocol, but I don't know of a C# library, so you may need to write your own using the Java library as guidance. You can set the control port in the config file so it doesn't conflict with the Tor Browser.
You should use the AUTHENTICATE command to prevent other apps from accessing the control port, and the TAKEOWNERSHIP command to ensure tor.exe exits when your app exits.
https://gitweb.torproject.org/torspec.git/plain/control-spec.txt https://github.com/guardianproject/jtorctl
4. Communicate over Tor by connecting to the local SOCKS port. You can set this port in the config file so it doesn't conflict with the Tor Browser.
Here's some Java source code that may be useful for guidance: https://code.briarproject.org/akwizgran/briar/blob/master/briar-android/src/... https://github.com/Psiphon-Labs/ploggy/blob/master/AndroidApp/src/ca/psiphon... https://github.com/thaliproject/Tor_Onion_Proxy_Library
All of the above are based on Orbot by the Guardian Project: https://gitweb.torproject.org/orbot.git
Cheers, Michael
On 15/12/14 15:51, Hollow Quincy wrote:
Hi all,
I would like to write a C# application (IRC client) that is using TOR. I read a lot, but I still don't know how can I run TOR proxy in transparent way (from my c# code).
I see that Tor Stem (https://stem.torproject.org/) can be used by Python code or there are packages for Linux, but not C# (.NET).
How can I run Tor proxy from C# ? Is there a library (dll) that I can run ? (without need to have open Tor Bundle browser).
Thanks for help _______________________________________________ tor-dev mailing list tor-dev@lists.torproject.org https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev