At times I have wanted to demo the development version of a server that is running on my FreeBSD virtual machine. This is not a problem if the person I want to show it to is withing walking distance. The net being what it is, sometimes the other party is halfway around the world.
I figured tor would be a neat way to demo a server running on my laptop. This post covers serving content via tor on a FreeBSD machine. This does not cover securing a hidden service because it is non-trivial and that is not my use case.
First, install security/tor. Consider enabling TOR2WEB if your service does not really need to be hidden.
Serve content to a port on localhost. For example, add the following to server.sh for a simple date server that serves content to port 8080. This is not a robust server, but it is good enough for configuration testing.
If using the above, make the server script executable and run it.
The following commands can be used to test the above server.
Enable tor in /etc/rc.conf
Get the hostname for your hidden service with the following command. Do not share the private_key, found in the same directory.
The following command can be used to test the above nc server by supplying the tor proxy with -x and proxy protocol with -X. The -w 1 specifies a timeout. This is necessary because the nc server does not close the connection. The -v flag gives verbose output.
Test your hidden service with curl by supplying the tor proxy with the -x option.
You alo can test your hidden service with Tor2web. For example, if your hidden service has a hostname of ABCDEFGHIJKLMNOP.onion, go to https://ABCDEFGHIJKLMNOP.onion.to to view it in a web browser. The nc server listed above might be a little flakey because it expects the client to close the connection.. You may need to restart the script if the server stops responding.
Test the hidden service with Tor2web from the command line with the following command. Note that Tor2web blocks the curl user agent, so the user agent is set to test instead.
To disable tor when you no longer need to use it, stop it with the service command.
Then disable it in /etc/rc.conf.
- Tor Project
- Tor, Tor2web
- Tor, Configuring Hidden Services for Tor
- Tor, Edit torrc
- Tor, HTTP connection closed on: Excess found in a non pipelined read
- Tor, StackOverflow, curl an .onion url over an http proxy does not return expected source
- Tor, Using nc and ncat with tor without torify/torsocks
- FreeBSD, Man nc
- FreeBSD, Man curl
- FreeBSD Forums, nc Server Not Disconnecting
- Bash, How to assign a heredoc value to a variable in Bash?
- Bash, The while loop
- Bash, Length of string in bash
- Bash, Command Substitution
- UNIX, Simple command line http server
- UNIX, One command line web server on port 80 using nc (netcat)
- UNIX, Faking Services using Netcat (For Testing Nagios)
- Wikipedia, Netcat: Setting up a one-shot webserver on port 8080 to present the content of a file