This commit is contained in:
emdee@spm.plastiras.org 2024-02-21 08:03:10 +00:00
parent abfc9d28e5
commit 9c6594c301
15 changed files with 77 additions and 35 deletions

View File

@ -15,23 +15,23 @@ lint::
install:: install::
${PIP_EXE_MSYS} --python ${PYTHON_EXE_MSYS} install \ ${PIP_EXE_MSYS} --python ${PYTHON_EXE_MSYS} install \
--no-deps \
--target ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/ \ --target ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/ \
--upgrade . --upgrade .
sed -i -e "1s@/usr/bin/python${PYTHON_MINOR}@${PYTHON_EXE_MSYS}@" \
${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/bin/*
rsync:: rsync::
bash .rsync.sh bash .rsync.sh
install::
${PYTHON_EXE_MSYS} -m pip --timeout=30 --disable-pip-version-check --proxy http://127.0.0.1:9128 install --only-binary :none: --progress-bar=off --target /usr/local/lib/python3.11/site-packages --upgrade .
# execute these tests as: make test PASS=password # execute these tests as: make test PASS=password
test:: test::
echo src/${MOD}/check_digests.py echo src/${MOD}/check_digests.py
TOR_CONTROLLER_PASSWORD=${PASS} src/${MOD}/check_digests.py TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/check_digests.py
echo src/${MOD}/interpreter.py echo src/${MOD}/interpreter.py
TOR_CONTROLLER_PASSWORD=${PASS} src/${MOD}/interpreter.py TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/interpreter.py
echo src/${MOD}/connection_resolution.py echo src/${MOD}/connection_resolution.py
sudo env TOR_CONTROLLER_PASSWORD=${PASS} src/${MOD}/connection_resolution.py sudo env TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/connection_resolution.py
# broken because this site fails: http://128.31.0.39:9131/tor/status-vote # broken because this site fails: http://128.31.0.39:9131/tor/status-vote
# ${PYTHON_EXE_MSYS} src/${MOD}/compare_flags.py # ${PYTHON_EXE_MSYS} src/${MOD}/compare_flags.py
# cant use from make: waits for the cmdline to to terminate # cant use from make: waits for the cmdline to to terminate
@ -45,7 +45,7 @@ test::
echo src/${MOD}/outdated_relays.py NOT WORKING? echo src/${MOD}/outdated_relays.py NOT WORKING?
TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/outdated_relays.py TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/outdated_relays.py
echo src/${MOD}/relay_connections.py echo src/${MOD}/relay_connections.py
TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/relay_connections.py sudo env TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/relay_connections.py
echo src/${MOD}/tor_bootstrap_check.py echo src/${MOD}/tor_bootstrap_check.py
TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/tor_bootstrap_check.py TOR_CONTROLLER_PASSWORD=${PASS} ${PYTHON_EXE_MSYS} src/${MOD}/tor_bootstrap_check.py

View File

@ -17,7 +17,6 @@ classifiers = [
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: CPython",
] ]
#
dynamic = ["version", "readme", ] # cannot be dynamic ['license'] dynamic = ["version", "readme", ] # cannot be dynamic ['license']
[project.scripts] [project.scripts]

View File

@ -20,7 +20,7 @@ classifiers =
zip_safe = false zip_safe = false
python_requires = ~=3.6 python_requires = ~=3.6
include_package_data = include_package_data =
"*" = ["*.txt"] "*" = ["*.txt", "*.bash" ]
install_requires = install_requires =
stem stem
ruamel.yaml ruamel.yaml

View File

@ -21,6 +21,8 @@ import stem
from stem_examples.tor_controller import set_socks_proxy from stem_examples.tor_controller import set_socks_proxy
LOG = logging.getLogger() LOG = logging.getLogger()
sKNOWN_ONION = 'facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd' # facebook
iTIMEOUT = 120
@contextlib.contextmanager @contextlib.contextmanager
def ignoreStdout() -> None: def ignoreStdout() -> None:
@ -108,13 +110,13 @@ if __name__ == '__main__':
lArgs = sys.argv[1:] lArgs = sys.argv[1:]
LOG.info(f"Getting some {len(lArgs)}") LOG.info(f"Getting some {len(lArgs)}")
else: else:
sKNOWN_ONION = 'facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd' # facebook LOG.info(f"Getting some FPs from the IPs to a sKNOWN_ONION TIMEOUT={iTIMEOUT}")
LOG.info("Getting some FPs from a sKNOWN_ONION")
from stem_examples.introduction_points import lMain as lIPMain from stem_examples.introduction_points import lMain as lIPMain
with ignoreStdout(): with ignoreStdout():
lArgs = lIPMain([sKNOWN_ONION]) lArgs = lIPMain([sKNOWN_ONION], timeout=iTIMEOUT)
LOG.info(f"Got {len(lArgs)} FPs from a sKNOWN_ONION") LOG.info(f"Got {len(lArgs)} FPs from a sKNOWN_ONION")
if not lArgs:
sys.exit(1)
i = iMain(lArgs) i = iMain(lArgs)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
i = 0 i = 0

0
src/stem_examples/connection_resolution.py Normal file → Executable file
View File

2
src/stem_examples/interpreter.py Normal file → Executable file
View File

@ -25,7 +25,7 @@ LOG = logging.getLogger()
def iMain(lArgs=None): def iMain(lArgs=None):
if not lArgs: if not lArgs:
lArgs = ['GETINFO' 'version'] lArgs = ['GETINFO' 'version']
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
if os.path.exists('/run/tor/control'): if os.path.exists('/run/tor/control'):
controller = get_controller(password=password, unix='/run/tor/control') controller = get_controller(password=password, unix='/run/tor/control')
else: else:

View File

@ -22,52 +22,93 @@ import sys
import os import os
import getpass import getpass
import logging import logging
import binascii
import stem
from stem.control import Controller from stem.control import Controller
from stem import Timeout
from stem.client.datatype import LinkByFingerprint
from stem.descriptor.hidden_service import HiddenServiceDescriptorV3
from stem_examples.tor_controller import get_controller from stem_examples.tor_controller import get_controller
from stem.descriptor.hidden_service import HiddenServiceDescriptorV3
LOG = logging.getLogger() LOG = logging.getLogger()
TIMEOUT = 60
lKNOWN_ONIONS = [ lKNOWN_ONIONS = [
'facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd', # facebook 'facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd', # facebook
'duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad', # ddg 'duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad', # ddg
'zkaan2xfbuxia2wpf7ofnkbz6r5zdbbvxbunvp5g2iebopbfc4iqmbad', # keys.openpgp.org
'libera75jm6of4wxpxt4aynol3xjmbtxgfyjpu34ss4d7r7q2v5zrpyd',
'oftcnet6xg6roj6d7id4y4cu6dchysacqj2ldgea73qzdagufflqxrid',
] ]
def bin_to_hex(raw_id:int, length: int|None = None) -> str:
if length is None: length = len(raw_id)
res = ''.join('{:02x}'.format(raw_id[i]) for i in range(length))
return res.upper()
def iMain(lArgs=None): def iMain(lArgs=None):
lRetval = lMain(lArgs) lRetval = lMain(lArgs)
if lRetval is None: if lRetval is None:
return -1 return -1
return 0 return 0
def lMain(lArgs=None, timeout=None): def lMain(lArgs=None, timeout=TIMEOUT) -> list:
lRetval = [] lRetval = []
if not lArgs: if not lArgs:
lArgs = lKNOWN_ONIONS lArgs = lKNOWN_ONIONS
try: try:
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
if os.path.exists('/run/tor/control'): if os.path.exists('/run/tor/control'):
controller = get_controller(password=password, unix='/run/tor/control') controller = get_controller(password=password, unix='/run/tor/control')
else: else:
controller = get_controller(password=password, port=9051) controller = get_controller(password=password, port=9051)
for elt in lArgs: for elt in lArgs:
LOG.info(f"onion: {elt}")
try:
desc = controller.get_hidden_service_descriptor(elt, desc = controller.get_hidden_service_descriptor(elt,
await_result=True, await_result=True,
timeout=timeout) timeout=timeout)
LOG.info(f"{desc} get_hidden_service_descriptor\n") except Exception as e:
LOG.warn (f"{elt} EXCEPTION {e}")
continue
if desc.descriptor_id is None or desc.version is None:
# reparse as HSv3
inner_layer = HiddenServiceDescriptorV3.from_str(str(desc)).decrypt(elt)
if hasattr(inner_layer, 'introduction_points'):
LOG.info (f"{elt} reparsed desc.decrypt len={len(desc.introduction_points())}")
l = inner_layer.introduction_points
else:
LOG.warn (f"{elt} reparsed desc.decrypt={dir(inner_layer)}")
sys.exit(1)
#LOG.info(f"version: {desc.version}\n")
#LOG.info(f"lifetime: {desc.lifetime}\n")
else:
LOG.info(f"published: {desc.published}\n")
l = desc.introduction_points() l = desc.introduction_points()
if not l: if not l:
LOG.warn(f"{elt} NO introduction points {l}\n") LOG.warn(f"{elt} NO introduction points {l}\n")
continue continue
LOG.info(f"{elt} introduction points are...\n")
lp = []
for introduction_point in l: for introduction_point in l:
lRetval += [introduction_point] for linkspecifier in introduction_point.link_specifiers:
LOG.info(' %s:%s => %s' % (introduction_point.address, # if isinstance(linkspecifier, LinkByFingerprint):
# LOG.log(40, f"Getting fingerprint for {linkspecifier}")
if hasattr(linkspecifier, 'fingerprint') and \
len(linkspecifier.value) == 20:
lp += [bin_to_hex(linkspecifier.value)]
elif hasattr(introduction_point, 'address'):
LOG.info('IP: %s:%s => %s' % (introduction_point.address,
introduction_point.port, introduction_point.port,
introduction_point.identifier)) introduction_point.identifier))
else:
pass # LOG.warn(f"{elt} introduction_point type={type(linkspecifier)}")
LOG.info(f"{elt} {len(lp)} introduction points {lp}")
except Exception as e: except Exception as e:
LOG.exception(f"Exception: {e}") LOG.exception(f"Exception: {e}")
finally: finally:
@ -83,7 +124,7 @@ if __name__ == '__main__':
vsetup_logging(LOG, log_level) vsetup_logging(LOG, log_level)
try: try:
l = lMain(sys.argv[1:]) l = lMain(sys.argv[1:])
if l: print(l) if l: print('IPs: ', l)
i = 0 i = 0
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
LOG.exception(f"Exception {e}") LOG.exception(f"Exception {e}")

View File

@ -15,7 +15,7 @@ def iMain():
else: else:
controller = get_controller(port=9051) controller = get_controller(port=9051)
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
try: try:
controller.authenticate(password) controller.authenticate(password)

View File

@ -29,7 +29,7 @@ LOG = logging.getLogger()
def sMapaddressResolv(target, iPort=9051): def sMapaddressResolv(target, iPort=9051):
try: try:
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
if os.path.exists('/run/tor/control'): if os.path.exists('/run/tor/control'):
controller = get_controller(password=password, unix='/run/tor/control') controller = get_controller(password=password, unix='/run/tor/control')
else: else:

View File

@ -35,7 +35,7 @@ def iMain(lArgs=None):
with_contact += 1 with_contact += 1
LOG.info("%i outdated relays found, %i had contact information" % (count, with_contact)) LOG.info("%i outdated relays found, %i had contact information" % (count, with_contact))
# http://vt5hknv6sblkgf22.onion/tutorials/examples/outdated_relays.htmlhttp://vt5hknv6sblkgf22.onion/tutorials/examples/outdated_relays.html # http://vt5hknv6sblkgf22.onion/tutorials/examples/outdated_relays.html
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -52,7 +52,7 @@ def iMain(lArgs=None):
parser.add_argument("--resolver", help="default: autodetected") parser.add_argument("--resolver", help="default: autodetected")
args = parser.parse_args(lArgs) args = parser.parse_args(lArgs)
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
control_port = int(args.ctrlport) if args.ctrlport else 'default' control_port = int(args.ctrlport) if args.ctrlport else 'default'
if False and os.path.exists('/run/tor/control'): if False and os.path.exists('/run/tor/control'):
controller = get_controller(password=password, unix='/run/tor/control') controller = get_controller(password=password, unix='/run/tor/control')

0
src/stem_examples/stem_utils.py Normal file → Executable file
View File

View File

@ -21,7 +21,7 @@ from stem_examples.tor_controller import get_controller
LOG = logging.getLogger() LOG = logging.getLogger()
def iMain(lArgs=None): def iMain(lArgs=None):
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
if os.path.exists('/run/tor/control'): if os.path.exists('/run/tor/control'):
controller = get_controller(password=password, unix='/run/tor/control') controller = get_controller(password=password, unix='/run/tor/control')
else: else:

View File

@ -39,7 +39,7 @@ def get_controller(password=None, address='127.0.0.1', port=9051, unix='/run/tor
if password is None: if password is None:
# print("DBUG: trying TOR_CONTROLLER_PASSWORD") # print("DBUG: trying TOR_CONTROLLER_PASSWORD")
password = os.environ.get('TOR_CONTROLLER_PASSWORD') password = os.environ.get('TOR_CONTROLLER_PASSWORD', '')
else: else:
# print(f"DBUG: using a password {len(password)}") # print(f"DBUG: using a password {len(password)}")
pass pass

0
src/stem_examples/torcontactinfo.py Normal file → Executable file
View File