|
|
Home » Developing U++ » UppHub » NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++
NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++ [message #48812] |
Sun, 24 September 2017 19:54 |
Oblivion
Messages: 1091 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
Netproxy is here with it's new design.
NetProxy package for Ultimate++
--------------------------------
This delegate class, formerly known as NetworkProxy, encapsulates two widely used network
proxy protocols: Http tunneling and SOCKS.
Features and Highlights
-----------------------
- Uses HTTP_CONNECT method for http tunneling.
- Encapsulates SOCKS proxy protocol version 4/4a, and version 5, as defined in RFC 1928 and RFC 1929.
- In SOCKS mode, NetProxy can work with both IPv4 and IPv6 address families.
- In SOCKS mode, NetProxy allows BIND requests.
- In SOCKS mode, NetProxy allows remote name lookups (DNS).
- Supports both synchronous and asynchronous operation modes.
- Allows SSL connections to the target machine (not to proxy itself) in both Http and SOCKS modes.
- Package comes with full public API document for Topic++, and has a typical BSD license.
Known Issues
-----------------------
- In SOCKS mode, NetProxy currently does not allow UDP association.
History
-----------------------
- 2017-09-23: Initial release of version 2.0:
A change in naming: NetworkProxy is from now on called NetProxy.
This change is in parallel with the change in class design.
There is now a single class that can make both HTTP_CONNECT and SOCKS requests.
Handling of socks BIND requests is simplified.
Internal cleanup redesigne allowed some performance gain around %4.
New design brings a single class with both HTTP_CONNECT tunneling, and SOCKS protocol support, a simpler interface. Also better optimization.
Since NetProxy is a "delegate" class, which takes a socket as it's client and upon finishing its job hands it over back to the user, it is in most cases trivial to add proxy support to existing classes and apps.
All you need to do is pass a socket handle and the host information (address, port) using an Event/Gate, or Function (before actual connection).
For example below addition can do the trick (it can work as a completely optional plugin):
class NetworkFoo {
public:
Gate<TcpSocket&> WhenProxy; // Or WhenConnect
};
//...
NetworkFoo nwf;
nwf.WhenProxy = [=, proxy_host, proxy_port, target_host, target_port](TcpSocket& sock) {
NetProxy proxy(sock, proxy_host, proxy_port);
proxy.Timeout(10000)
.Auth("user", "password")
.Socks5();
return proxy.Connect(target_host, target_port);
};
Bug reports, criticism, reviews are appreciated.
Best regards,
Oblivion
-
Attachment: NetProxy.zip
(Size: 12.48KB, Downloaded 258 times)
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sun, 24 September 2017 20:11] Report message to a moderator
|
|
|
Re: NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++ [message #54197 is a reply to message #48812] |
Sat, 06 June 2020 23:04 |
Oblivion
Messages: 1091 Registered: August 2007
|
Senior Contributor |
|
|
Hi,
NetProxy package has received a small update. (Minor bug fixes.)
Also, I've added two simple Socks5 connection examples to upp-components/Examples directory:
SocksProxyExample - Demonstrates a simple SOCKS5 connection, using NetProxy package.
SocksProxyExampleNB - Demonstrates a simple, non-blocking SOCKS5 connection, using NetProxy package.
SocksProxyExample:
#include <Core/Core.h>
#include <NetProxy/NetProxy.h>
using namespace Upp;
// This example demonstrates the basic usage of NetProxy class with socks5 tunnels.
// Default proxy server: Turk Telekom, a well-known ISP in Turkey. No auth required...
// Target server: test.rebex.net -> A well-known FTP/SFTP test server.
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
NetProxy::Trace();
const char *proxy_server = "88.249.26.113";
const int proxy_port = 1080;
TcpSocket sock;
NetProxy socksproxy(sock, proxy_server, proxy_port);
if(socksproxy.Timeout(10000).Socks5().Connect("test.rebex.net", 21)) {
RLOG("-------------");
RLOG(sock.GetLine()); // Get the first line of FTP server HELO...
RLOG("-------------");
return;
}
RLOG(socksproxy.GetErrorDesc());
}
If you have any questions, let me know.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 06 June 2020 23:07] Report message to a moderator
|
|
|
Re: NetProxy package. (HTTP/SOCKS4/4a/5 with BIND support) encapsulation for U++ [message #54208 is a reply to message #48812] |
Wed, 10 June 2020 13:11 |
Oblivion
Messages: 1091 Registered: August 2007
|
Senior Contributor |
|
|
Hi
I've added a Socks5-proxied SSH connection example to upp-components repo.
Example uses the Upp's Core/SSH package and also demonstrates the usage of WhenProxy event of SshSession class.
Here is the code:
#include <Core/Core.h>
#include <Core/SSH/SSH.h>
#include <NetProxy/NetProxy.h>
using namespace Upp;
// This example demonstrates a basic SSH2 connection over a Socks5 proxy.
// WARNING: The sole purpose of this example is to demonstrate the usage of
// NetProxy package with the SSH package. The example uses an anon.
// proxy server (with no authentication) to access a public SFTP
// server.
//
// NEVER USE A PUBLIC PROXY SERVER FOR YOUR SSH CONNECTIONS. IN FACT,
// IT IS HIGHLY RECOMMENDED TO COMPLETELY AVOID USING PROXY SERVERS FOR
// SENSITIVE/ENCRYPTED DATA TRANSFERS.
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Ssh::Trace();
NetProxy::Trace();
const char *proxy_server = "88.249.26.113"; // Anonymous socks proxy server of a well-known ISP in Turkey (Turk Telekom).
const int proxy_port = 1080;
const char *ssh_server = "test.rebex.net"; // A well-known and popular SSH test server.
const int ssh_port = 22;
SshSession session;
session.WhenProxy = [&]() -> bool
{
NetProxy socksproxy(session.GetSocket(), proxy_server, proxy_port);
return socksproxy.Timeout(10000).Socks5().Connect(ssh_server, ssh_port);
};
if(session.Timeout(30000).Connect(ssh_server, ssh_port, "demo", "password")) {
SFtp sftp(session);
String s = sftp.LoadFile("./readme.txt");
if(!sftp.IsError()) {
RLOG("---------------------------");
RLOG(s);
RLOG("----------------------------");
}
return;
}
RLOG(session.GetErrorDesc());
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 10 June 2020 13:23] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Thu Mar 28 22:42:19 CET 2024
Total time taken to generate the page: 0.02038 seconds
|
|
|