first commit
This commit is contained in:
commit
0fb4e077c5
|
@ -0,0 +1,13 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
stem = "*"
|
||||
pyyaml = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.6"
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "f36534d2282b14e23b847a7f0153a306c5b79b516091b911a16c9001745e98ba"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.6"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97",
|
||||
"sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76",
|
||||
"sha256:4f4b913ca1a7319b33cfb1369e91e50354d6f07a135f3b901aca02aa95940bd2",
|
||||
"sha256:6034f55dab5fea9e53f436aa68fa3ace2634918e8b5994d82f3621c04ff5ed2e",
|
||||
"sha256:69f00dca373f240f842b2931fb2c7e14ddbacd1397d57157a9b005a6a9942648",
|
||||
"sha256:73f099454b799e05e5ab51423c7bcf361c58d3206fa7b0d555426b1f4d9a3eaf",
|
||||
"sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f",
|
||||
"sha256:7739fc0fa8205b3ee8808aea45e968bc90082c10aef6ea95e855e10abf4a37b2",
|
||||
"sha256:95f71d2af0ff4227885f7a6605c37fd53d3a106fcab511b8860ecca9fcf400ee",
|
||||
"sha256:ad9c67312c84def58f3c04504727ca879cb0013b2517c85a9a253f0cb6380c0a",
|
||||
"sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d",
|
||||
"sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c",
|
||||
"sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.3.1"
|
||||
},
|
||||
"stem": {
|
||||
"hashes": [
|
||||
"sha256:a0b48ea6224e95f22aa34c0bc3415f0eb4667ddeae3dfb5e32a6920c185568c2"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.8.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
# Configuration
|
||||
- Create a password hash for the control port
|
||||
|
||||
```
|
||||
❯ tor --hash-password reallygoodpassword
|
||||
16:E3080659B8209B3B60FFB5084A5B3BFC09E334182A07822BD5E93C95FC
|
||||
```
|
||||
|
||||
- Configure Tor daemon `/etc/tor/torrc`
|
||||
|
||||
```
|
||||
SocksPolicy accept 198.18.0.0/17
|
||||
SocksPolicy accept 127.0.0.0/8
|
||||
SocksPolicy reject *
|
||||
Log notice syslog
|
||||
RunAsDaemon 1
|
||||
DataDirectory /var/lib/tor
|
||||
ControlPort 9051
|
||||
HashedControlPassword 16:E3080659B8209B3B60FFB5084A5B3BFC09E334182A07822BD5E93C95FC
|
||||
HiddenServiceDir /var/lib/tor/hidden_service/
|
||||
HiddenServicePort 80 127.0.0.1:80
|
||||
```
|
||||
|
||||
- Restart Tor daemon `systemctl restart tor`
|
||||
|
||||
- Create a `~/.torctlrc` file
|
||||
|
||||
```
|
||||
config:
|
||||
host: 127.0.0.1
|
||||
password: reallygoodpassword
|
||||
port: 9051
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
- `pipenv shell`
|
||||
- `pipenv sync`
|
||||
|
||||
## Available commands
|
||||
|
||||
```
|
||||
❯ python -m torctl.torctl
|
||||
|
||||
valid commands are:
|
||||
add-event-listener add-status-listener attach-stream authenticate clear-cache close close-circuit close-stream connect connection-time create-ephemeral-hidden-service create-hidden-service drop-guards enable-feature extend-circuit from-port from-socket-file get-accounting-stats get-circuit get-circuits get-conf get-conf-map get-effective-rate get-exit-policy get-hidden-service-conf get-hidden-service-descriptor get-info get-latest-heartbeat get-listeners get-microdescriptor get-microdescriptors get-network-status get-network-statuses get-newnym-wait get-pid get-ports get-protocolinfo get-server-descriptor get-server-descriptors get-socket get-socks-listeners get-start-time get-streams get-uptime get-user get-version is-alive is-authenticated is-caching-enabled is-feature-enabled is-geoip-unavailable is-localhost is-newnym-available is-set is-user-traffic-allowed list-ephemeral-hidden-services load-conf map-address msg new-circuit reconnect remove-ephemeral-hidden-service remove-event-listener remove-hidden-service remove-status-listener repurpose-circuit reset-conf save-conf set-caching set-conf set-hidden-service-conf set-options signal
|
||||
```
|
||||
|
||||
### Creating a new circuit
|
||||
|
||||
```
|
||||
❯ python -m torctl.torctl new-circuit
|
||||
result: 33
|
||||
|
||||
```
|
|
@ -0,0 +1,62 @@
|
|||
import yaml as Y
|
||||
import os as O
|
||||
import sys as S
|
||||
import types as TYPES
|
||||
from stem.control import Controller as C
|
||||
|
||||
class tor_controller():
|
||||
|
||||
def __init__(self, args):
|
||||
self.is_func_or_meth = lambda f: (
|
||||
TYPES.FunctionType
|
||||
== type(f)
|
||||
or TYPES.BuiltinFunctionType
|
||||
== type(f)
|
||||
or TYPES.BuiltinMethodType
|
||||
== type(f)
|
||||
or TYPES.MethodType
|
||||
== type(f)
|
||||
or TYPES.LambdaType
|
||||
== type(f)
|
||||
) and True or False
|
||||
|
||||
if not O.path.exists("{}/.torctlrc".format(O.path.expanduser("~") ) ):
|
||||
self.create_config()
|
||||
|
||||
self.conf = Y.load(open("{}/.torctlrc".format(O.path.expanduser("~") ) ), Loader = Y.FullLoader).get('config')
|
||||
|
||||
self.controller = C.from_port(port = self.conf.get("port") )
|
||||
self.controller.authenticate(self.conf.get("password") )
|
||||
|
||||
try:
|
||||
meth_or_prop = getattr(self.controller, [ x for x in dir(self.controller)
|
||||
if not x.startswith("_") and x == args[1].replace("-", "_") ][0] )
|
||||
|
||||
if self.is_func_or_meth(meth_or_prop):
|
||||
print("result: {}".format(meth_or_prop() ) )
|
||||
else:
|
||||
print("{}".format(meth_or_prop))
|
||||
|
||||
except IndexError as e:
|
||||
self.usage(args)
|
||||
|
||||
def create_config(self):
|
||||
self.conf = {}
|
||||
self.conf["config"] = {}
|
||||
self.conf["config"]["host"] = "127.0.0.1"
|
||||
self.conf["config"]["port"] = 9051
|
||||
self.conf["config"]["password"] = "password"
|
||||
|
||||
Y.dump(self.conf, open("{}/.torctlrc".format(O.path.expanduser("~")), "w+") )
|
||||
|
||||
def usage(self, args):
|
||||
print("""
|
||||
valid commands are:
|
||||
{commands}
|
||||
""".format(commands = " ".join([x.replace("_", "-")
|
||||
for x in dir(self.controller)
|
||||
if not x.startswith("_")] ) ) )
|
||||
|
||||
if __name__ == "__main__":
|
||||
tor_controller(S.argv)
|
||||
|
Loading…
Reference in New Issue