diff --git a/src/runtests/__init__.py b/src/runtests/__init__.py index c9a6e3dc..10694b70 100644 --- a/src/runtests/__init__.py +++ b/src/runtests/__init__.py @@ -16,6 +16,7 @@ from .clearnettor import test_clearnet_tor_request from .housekeeping import test_inserted_housekeeping from .lanservertest import test_lan_server from .sneakernettest import test_sneakernet_import +from .dnsrebindingtest import test_dns_rebinding """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,7 +42,8 @@ RUN_TESTS = [uicheck.check_ui, test_clearnet_tor_request, test_inserted_housekeeping, test_lan_server, - sneakernettest.test_sneakernet_import + sneakernettest.test_sneakernet_import, + test_dns_rebinding ] SUCCESS_FILE = os.path.dirname(os.path.realpath(__file__)) + '/../../tests/runtime-result.txt' diff --git a/src/runtests/dnsrebindingtest.py b/src/runtests/dnsrebindingtest.py new file mode 100644 index 00000000..8a430674 --- /dev/null +++ b/src/runtests/dnsrebindingtest.py @@ -0,0 +1,46 @@ +"""Onionr - Private P2P Communication. + +Test apis for dns rebinding +""" +import config +import requests +from filepaths import private_API_host_file, public_API_host_file +import logger +""" + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + + +def test_dns_rebinding(test_manager): + f = '' + with open(private_API_host_file, 'r') as f: + host = f.read() + private_api_port = config.get('client.client.port') + + if requests.get(f'http://{host}:{private_api_port}/ping', headers={'host': 'example.com'}) == 'pong!': + raise ValueError('DNS rebinding failed') + logger.info('It is normal to see 403 errors right now', terminal=True) + + if config.get('general.security_level', 0) > 0 or not config.get('transports.tor', True): + return + public_api_port = config.get('client.public.port') + f = '' + with open(public_API_host_file, 'r') as f: + host = f.read() + + if requests.get(f'http://{host}:{public_api_port}/ping', headers={'host': 'example.com'}) == 'pong!': + raise ValueError('DNS rebinding failed') + logger.info('It is normal to see 403 errors right now', terminal=True) + + diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt index 8dc1d799..652cfcbb 100644 --- a/tests/runtime-result.txt +++ b/tests/runtime-result.txt @@ -1 +1 @@ -1585902463 \ No newline at end of file +1585974430 \ No newline at end of file