This code is a fakeroute
program written by Julian Assange in 1996. Found it in a pile of old emails I had, so here it is. Wanted to perserve it for history I guess.
UPDATE: Rotorouter was part of FreeBSD and has been lost really to time.
Now for the ChatGPT breakdown... It aims to simulate traceroute responses by sending ICMP packets with spoofed information to mimic the appearance of a network route. Below is a detailed breakdown and explanation of the code:
-
Configuration File:
- The configuration file (default named "hops") contains tuples specifying the destination IP, hop count, fake router IP, and latency in milliseconds.
-
Libraries and Definitions:
- The code includes necessary libraries for network programming and packet capturing such as
pcap.h
,netinet/in.h
,netinet/ip.h
, and others. - Definitions for boolean values and endian bug handling are also included.
- The code includes necessary libraries for network programming and packet capturing such as
-
Global Variables:
- Various global variables are declared for pcap handling, raw socket, and configuration parameters such as timeout and verbosity.
-
struct hop
:- This structure represents a hop with attributes like destination IP, hop IP, latency, and TTL.
-
struct udp_state
:- This structure keeps track of UDP state information including source and destination IPs, source port, and the time of the last packet.
-
pexit
andeexit
:- Utility functions to handle errors and exit the program with a message.
-
xmalloc
:- A wrapper around
malloc
to allocate memory and handle allocation failure.
- A wrapper around
-
fast_icmp_cksum
:- Computes the checksum for ICMP packets.
-
lookup_printer
:- Looks up and returns the appropriate printer function based on the data link type.
-
open_pcap
:- Opens a pcap session for packet capturing with the specified device, promiscuous mode, filter, and timeout.
-
ether_if_print
andppp_if_print
:- These functions process packets captured on Ethernet and PPP interfaces, respectively, and pass them to the
analyze_udp
function.
- These functions process packets captured on Ethernet and PPP interfaces, respectively, and pass them to the
-
find_hop
:- Finds and returns the hop information for a given destination IP and TTL.
-
icmp_reply
:- Crafts and sends an ICMP reply based on the captured packet and hop information.
-
analyze_udp
:- Analyzes UDP packets to determine if they match any configured hops, then generates and sends ICMP replies if necessary.
-
open_raw
:- Opens a raw socket for sending custom ICMP packets.
-
populate_hops
:- Reads the configuration file and populates the list of hops with destination IPs, hop IPs, TTLs, and latencies.
-
usage
:- Displays usage information and exits the program.
- The
main
function processes command-line arguments to set various parameters such as interface, promiscuous mode, hops file, usec, max TTL, timeout, and verbosity. - It calls
populate_hops
to load the hop configuration,open_pcap
to start packet capturing, andlookup_printer
to get the appropriate printer function. - Finally, it enters a packet capturing loop (
pcap_loop
) to continuously process packets.
To run the program, you might use a command like:
fakeroute -i eth0 -h my_hops_file -u 100 -t 5 -n 300 -v
-i eth0
: Use theeth0
network interface.-h my_hops_file
: Usemy_hops_file
for hop configuration.-u 100
: Set the timeout for pcap reads to 100 microseconds.-t 5
: Set the maximum TTL to 5.-n 300
: Set the timeout for UDP state entries to 300 seconds.-v
: Increase verbosity.
The fakeroute
program is a sophisticated tool for simulating network routes and responses, useful for testing and security research. It involves capturing UDP packets, identifying specific routes based on predefined configurations, and sending crafted ICMP replies to mimic a real traceroute.