Skip to content

Instantly share code, notes, and snippets.

@timmyRS
Last active October 30, 2017 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmyRS/292e9db72117f858cba85fa3be06deda to your computer and use it in GitHub Desktop.
Save timmyRS/292e9db72117f858cba85fa3be06deda to your computer and use it in GitHub Desktop.
The 1-Route Protocol: Reach the unreachable.

The 1-Route Protocol

by Tim Speckhals

Purpose

The Purpose of the 1-Route Protocol is to allow unreachable locations to be reached anyways using a proxy server.

Use Cases

  • Your server is being null-routed and you want your files to be accessable whilst you move them to a new location
  • Your ISP doesn't allow incoming connections but you want to expose a local service to the public

Existing Implementations

Name Author Language(s) Info
1-Route Implementation timmyRS Java Proxy and Target in one.

The Packet Format

The 1-Route Protocol is a big endian protocol. The default port is 197.

Type Content
unsigned short The length of the Packet.
byte The ID of the Packet.
byte array The Data of the Packet.

The Packets

0x00 Auth (Target to Proxy)

Type Content
byte Protocol Version of the target. The newest is 1.
unsigned short The length of the following string. 0 (no password) may be accepted by the proxy, but an IP Filter is recommended in that case.
string The UTF-8 bytes of the password.
byte The kind of connection this is. See below.
unsigned short Only sent if the connection is a Proxy Connection. This specifies the port this connection is for.

Connection Types

Byte Name
0x00 Control Connection
0x01 Proxy Connection

0x01 Ports to Open (Target to Proxy)

This can be sent at any point by the target to tell the proxy to start accepting connections to certain ports.

Type Content
byte The length of the following array
unsigned short Array of ports the proxy shall open and proxy to the target

When the packet has been processed, even when no ports were specified, the proxy will send 0x01 Unaccepted Ports to notify of any ports that could not be opened.

0x02 Ports to Close (Target to Proxy)

This can be sent at any point by the target to tell the proxy to stop accepting connection to certain ports without closing the control connection.

Type Content
byte The length of the following array
unsigned short Array of ports the target will no longer accept and can therefore be closed
boolean If true, connections on the port must also be closed.

0x00 Auth Response (Proxy to Target)

Type Content
boolean Whether the authentication was successful
byte If the previous is false, this specifies the reason for it. See below.
unsigned short If the previous is 0x00, this specifies the length of the
string UTF-8 bytes of the reason why the authentication failed

If the authentication was unsucessful, the connection should be closed by the proxy.

If the authentication was for a Proxy Connection, it should be ensured that the entire packet has been read, as the following data will be the raw bytes sent by the client.

Authentication Failure Reasons

Byte Name
0x01 IP-Address or Range not allowed
0x02 Protocol Version not supported
0x03 Incorrect Password
0x00 Other

0x01 Unaccepted Ports (Proxy to Target)

Type Content
byte The length of the following array
unsigned short Array of ports which could not be opened

Sent after the target sent 0x01 Ports to Open to notify of any ports that could not be opened.

0x02 Connect (Proxy to Target)

Type Content
unsigned short The port which the client has connected to and the local connection would be opened to

It is recommened to check if the port had been sent in Ports to Open to prevent unwanted connections which seemingly come from localhost.

An Example

Client            # Reverse Proxy         # <-----------------> # Target
                  #                       #                     #
                  #                       # <- Auth ----------- #
                  #                       # -- Auth Response -> #
                  # Opens the given ports # <- Ports to Open -- #
Connects to Proxy #                       # -------- Connect -> #
                  #                       #                     # Opens a new connection to the proxy
                  #                       # <-- Auth ---------- #
                  #                       # -- Auth Response -> # Opens a local connection to the given port
                  # Starts proxying       #                     #
                  -------------- Bytes of any other Protocol -> # Proxies the bytes to the local connection
                  #                       #                     #

Handling

  • When a local connection of the target is closed, the connection to the proxy should be closed.
  • When a proxy connection to the proxy is closed, the proxy should disconnect the client associated with it.
  • When the control connection of a target is closed, the proxy should close the ports opened by the target and disconnect all clients connected to the target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment