Http tunneling to pass firewall in C# (TCP) - c#

My need is to communicate between 2 client behind NAT using http tunneling. Is it possible? What all setup is needed to achieve this (like http proxy server etc.)? Is there any library or sample code available for implementing http tunneling over TCP in C#?

It might be possible for you to use this library:
http://granados.sourceforge.net/
It supports port forwarding (tunneling in this case),
but I haven't tried it myself.
It's an SSH library... so if you can set up an SSH server on either end of the connection
you'll be able to establish an SSH connection and create a tunnel.

Related

Xsockets.NET over proxy server

I have written a winforms client, that connects to a Windows service establishing a connection with XSockets.Net. This is working fine for a direct connection to the internet.
But when there is a proxy server, it will fail.
As I checked the XSockets API I have not found any settings, that allows me to use a proxy server.
Also for the websockets protocol I have not found a sufficient answer.
Any ideas?
Use WSS:// for connection, that is the equivalent to HTTPS in WebSocket.
The WebSocket protocol handshake sends the HTTP headers "Upgrade:websocket" and "Connection:Upgrade", meaning that the proxy will probably remove the "Upgrade" header because is set as a "Connection" header. By using a secure protocol, the proxy won't be able of intercept the request and will just let it pass.
Cheers.

How to use an existing Putty-SSH-Connection with HttpClient

I have set up a SSH connection to a remote computer on a specific local port via Putty.
It works fine, as I can use it with Firefox, setting the SOCKS-Host on this port.
I want to use this connection with my program, where I use HttpClient to do the work (send data to DB).
Is there a way to access the port with HttpClient? Simply putting it into the address didn't work.
Tried to attend WebProxy("127.0.0.1", port) to the client, but it didn't work either.
Any suggestions?
You have set up a SOCKS proxy, not an HTTP proxy. I don't usually code C#, so I did a google search, but it is unclear to me whether WebProxy directly supports SOCKS proxies - to me it seems SOCKS support is lacking in .NET, unless you can find some freely available, third party classes.
You can look into using a SOCKS proxy with WebProxy - you can probably achieve the same thing using some wrapper class. Another option is set up Polipo or Privoxy, and then use your existing code changing only the port for your WebProxy call. They are both HTTP proxies that feature proxy chaining with existing SOCKS proxies - configure to use your SSH SOCKS proxy, and you're good to go...

WebSocket java plugin unable to connect

I am using this http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/#comment-689 plugin. I am experiencing a problem where when I create the websocket object and a regular tcp server written in c#. I confirm the the connection headers are recieved, however, the onopen or onmessage events in the javascript are not fired? Any suggestions? Thanks!
You mention using a regular tcp server. Are you aware that a websocket connection is slightly more complicated that a regular tcp connection? You have to complete a handshake then frame all subsequent messages. Your browser handles all this for you on the client; you have to provide equivalent code on the server.
RFC 6455 describes the protocol if you want to write your own server. Or you could use an existing C# server - using either the .NET v4.5 class or a third party server.

Stop a TCP stream when listening to all ports

I'm programming an application that listens to ports for specific packets using REGEX. I can see the original TCP Stream, but I'm wondering if this is possible to intercept and stop this stream without any packet forging library.
Example:
A user navigates on a page where there is the word P*RN or "J*st** Bi*ber", and automatically, he loses this specific connection.
If I cannot do it, maybe I'll replace some HTMLElements on the fly.
You can implement a proxy server, so that all traffic from your users to the internet (and back) will go through your proxy. You can implement the proxy using the .NET networking API (no packet forging). When you want to drop the connection, you can either close the TCP stream, or send back an error response.
This solution has some problems too:
you have to implement specific proxy for each protocol you want to filter (SMTP, IMAP, POP3)
you need to force your users to use your proxy server when connecting to internet (this could be configured at network level)
it will not work with SSL (HTTPS), since the traffic is encrypted
Edit
I don't think there is a way how to intercept TCP streams using .NET API. However you can forward TCP streams (accepting client connection and then forwarding all communication between the client and the server). Since you accepted the client TCP connection, you can also terminate it.

SSL without SslStream because I'd like to connect through a SOCKS5 Proxy

BACKGROUND INFORMATION: PROGRAM WRITTEN IN C#
I'm working on a program right now that connects through a SOCKS5 proxy (coded from scratch. works well enough.), but I'd also like to (through that proxy) communicate to a DESTINATION through SSL.
I've done some research, googled many a time, and have come to the conclusion that SslStream won't be ideal for my situation. I NEED to first authenticate with the SSL through the proxy, and THEN start sending encrypted packets, once I receive the key.
QUESTIONS:
How can I encrypt my packets with TLS in C#? For some reason I can't at all figure it out. I'm stuck! :(
What is the raw syntax required to even REQUEST said SSL certificate?
You might want to have a look at the TLS implementation in the open source Bouncy Castle cryptography library. If it won't work as-is, you can hack it into doing what you need. If you want to deep-dive the specification itself, you'll find it as IETF RFC 5246.
As you've probably discovered, though, doing any portion of the connection setup work yourself leaves you with no way to use the WebRequest family of classes to handle the HTTP portion of the protocol work. That leaves you with two options I can see: do the HTTP yourself as well (I found a trivial example HTTP client floating around the net), or change the current user proxy server settings
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="socks=socks.example.net:1080"
then send the request normally using the WebRequest classes.
I'd like to offer you SSLBlackbox package of our SecureBlackbox product. Among numerous other components it has a simple SSL client component that is socket-based, can connect via different proxies (SOCKS, HTTPS CONNECT) and supports all features of SSL/TLS up to TLS 1.2. If you need more control, you can use any custom socket, and not just built-in socket support. This lets you use the components for securing traffic that goes not via sockets at all (pigeon mail can be secured this way as well).
An HTTPS client is available and included into SSLBlackbox as well.

Categories

Resources