Endpoint: Tips and Tricks

Send/Receive Normal TCP/UDP Traffic

This is easy:

// Choose one of these. It'll return once a connection is established.
Endpoint ep(TCP | CLIENT, "example.com:80");       // Active open
Endpoint ep(TCP | SERVER, ":80");                  // Passive open
Endpoint ep(UDP | CLIENT, "example.com:41170");    // Send
Endpoint ep(UDP | SERVER, ":41170");               // Receive

if (!ep)   // If couldn't open socket
   std::cout << "failed: " << std::endl; 

// Print out the local and remote address
std::cout << "New socket: " << ep << std::endl;

// Find out who we're connected to (note that this is shown above also)
std::cout << "Connected to: " << string(ep.m_remote) << std::endl;

// Write some data
ep.Write("hi");

Use IPv6

If your host supports it, IPv6 will be automatically enabled. DNS names will resolve to 128-bit IPv6 addresses. To specifically use IPv6:

EndpointAddrlist::g_default_family = AF_INET6;

Now all DNS names will resolve to IPv6 addresses. (See also: RES_USE_INET6)

To connect to an IPv6 host without DNS, simply write the address. Use square brackets around the IPv6 address if you're also specifying a port. For example, to connect to a local web server you're running on IPv6:

Endpoint ep(TCP | CLIENT, "[::1]:80");

If you have IPv6 support but don't want it to get in the way, use:

EndpointAddrlist::g_default_family = AF_INET;

Use Raw Sockets

Endpoint now supports raw sockets with IPv4 (IPv6 doesn't have raw sockets; you have to use datalink access for that, which Endpoint doesn't currently support). If you want to write your own IP header, use RAW.

A number of transport-layer protocols that sit on top of IPv4 are available to Endpoint. To write IGMP packets, for example, use RAW_ICMP. This will make the IP header for you, but you have to write the IGMP header.

RAW_UDP and RAW_ICMP automatically create the UDP or ICMP header for you. See the next topic for using ICMP.

Send ICMP Messages

Simply create a RAW_ICMP | CLIENT socket with your destined address, specifying a port number of type,code. For example, to send a "host unreachable" ICMP message to 10.3.2.1:

Endpoint ep(RAW_ICMP | CLIENT, "10.3.2.1:3,1");

ep.Write("...");

To send a "ping" (ICMP echo request), replace "3,1" with "8,0". See the official IANA ICMP parameters for more information.

ICMP can be used as a covert channel. See Project Loki: ICMP Tunnelling in Phrack 49, by Alhambra and daemon9 for an article about this steganographic process.