Tested on Ubuntu 16.04 Docker container. The Dockerfile is a single line FROM ubuntu:16.04
.
NOTE: stopping services didn't work for me for some reason. That's why there is pidof <service name> | xargs kill
after each failed service <service name> stop
to kill it.
- How to request new TOR identity in terminal
- How to anonymize the programs from your terminal with torify
- How To: Using Tor From The Command Line
- How to change Tor identity in Python?
- Control Port telnet AUTHENTICATE without any password
- Tor IP changing and web scraping
root@75f6721089f2:/# apt update
root@75f6721089f2:/# apt install tor
root@75f6721089f2:/# service tor status
* tor is not running
root@75f6721089f2:/# service tor start
* Starting tor daemon... [ OK ]
root@75f6721089f2:/# service tor status
* tor is running
It's not possible to connect as ControlPort
is not set yet.
root@75f6721089f2:/# apt install netcat
root@75f6721089f2:/# echo -e 'AUTHENTICATE' | nc 127.0.0.1 9051
(UNKNOWN) [127.0.0.1] 9051 (?) : Connection refused
root@75f6721089f2:/# service tor stop
* Stopping tor daemon... [fail]
root@75f6721089f2:/# pidof tor | xargs kill
root@75f6721089f2:/# service tor status
* tor is not running
root@75f6721089f2:/# echo "ControlPort 9051" >> /etc/tor/torrc
root@75f6721089f2:/# service tor start
* Starting tor daemon... [ OK ]
It's possible to connect but Authentication fails.
root@75f6721089f2:/# echo -e 'AUTHENTICATE' | nc 127.0.0.1 9051
515 Authentication failed: Wrong length on authentication cookie.
root@75f6721089f2:/# service tor stop
* Stopping tor daemon... [fail]
root@75f6721089f2:/# pidof tor | xargs kill
root@75f6721089f2:/# echo "CookieAuthentication 0" >> /etc/tor/torrc
root@75f6721089f2:/# service tor start
* Starting tor daemon...
Jan 20 11:34:30.911 [warn] ControlPort is open, but no authentication method has been configured.
This means that any program on your computer can reconfigure your Tor.
That's bad!
You should upgrade your Tor controller as soon as possible.
[ OK ]
Authentication passes.
# NOTE Use Ctrl+C to exit.
root@75f6721089f2:/# echo -e 'AUTHENTICATE' | nc 127.0.0.1 9051
250 OK
root@75f6721089f2:/# apt install curl
root@75f6721089f2:/# curl http://icanhazip.com/
89.196.159.79
root@75f6721089f2:/# torify curl http://icanhazip.com/
185.220.101.17
root@75f6721089f2:/# echo -e 'AUTHENTICATE\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051
250 OK
250 OK
250 closing connection
root@75f6721089f2:/# torify curl http://icanhazip.com/
185.220.101.6
root@75f6721089f2:/# apt install python3
root@75f6721089f2:/# apt install python3-pip
root@75f6721089f2:/# pip3 install stem
root@75f6721089f2:/# python3
>>> from stem import Signal
>>> from stem.control import Controller
>>>
>>> with Controller.from_port(port=9051) as controller:
... controller.authenticate()
... controller.signal(Signal.NEWNYM)
...
>>>
root@75f6721089f2:/# torify curl http://icanhazip.com/
185.107.81.233
If you know where the cookie file is, like let's say /run/tor/control.authcookie, then you can run this command:
echo -e 'AUTHENTICATE '`hexdump -ve '1/1 "%.2x"' /run/tor/control.authcookie`'\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051