Skip to content

neuralgorithm/Nana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nana is a layer-7 proxy daemon.

Nana runs on a certain port specified in the source code, accepts
connections to the port, reads the header and determines the protocol,
and proxies the connections to the appropriate host and port also
specified in the source code.

An example use is to run nana on port 80 of a host to proxy HTTP and
VNC connections to the port to port 8088 and 5901 of the same host,
respectively. For this purpose, the source code should be as follows:

| // The nana daemon runs on port 80
| #define LOCAL_PORT 80
|
| // First target is apache running on localhost:8088
| #define TARGET1_REGEX "HTTP"
| #define TARGET1_HOST "localhost"
| #define TARGET1_PORT 8088
| #define TARGET1_SERVER_FIRST 0 // In HTTP, client talks first.
|
| // Second target is vncserver running on localhost:5901
| #define TARGET2_REGEX "RFB"
| #define TARGET2_HOST "localhost"
| #define TARGET2_PORT 5901
| #define TARGET2_SERVER_FIRST 1 // In VNC, server talks first.

You can increase the number of targets as many as you want. You should
copy and paste the following code in do_accept() while replacing {X}
with the target number:

|  regcomp(&pat, TARGET{X}_REGEX, REG_EXTENDED);
|  if (0 == regexec(&pat, buf, 1, &match, 0)){
|    hp = gethostbyname(TARGET{X}_HOST);
|    memcpy(&target.sin_addr, hp->h_addr, hp->h_length);
|    target.sin_port = htons(TARGET{X}_PORT);
|    read_from_server_first = TARGET{X}_SERVER_FIRST;
|    protocol_matched = 1;
|  }
|  regfree(&pat);

Nana expects that the client starts to negotiate so as to know the protocol
that the client wants to speak. HTTP is ok, because in HTTP a client speaks
first. In other protocols such as VNC, a server is assumed to speak first.
In such a case, the client program has to be modified so as not to wait
the first message from the server. Also, nana has to know if the target
protocol is one of such protocols by setting TARGET{X}_SERVER_FIRST
variable to 1.

nana.c is built with libdaemon [libdaemon]. Install libdaemon first.

nana.c is written based on the source code of redir-2.2.1 [redir].

nana.c is licensed under GPL.

Folder vnc_javasrc contains the source code of TightVNC [tightvnc]
Java Viewer 1.3.10 with a modification to RfbProto.java for L7-proxy.

Please let me know if you have questions or comments.

YAMAZAKI, Tadashi (neuralgorithm)
http://neuralgorithm.org/

Refs:
[libdaemon] http://0pointer.de/lennart/projects/libdaemon/
[redir] http://packages.debian.org/squeeze/redir
[tightvnc] http://www.tightvnc.com/

About

Layer-7 proxy daemon

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published