summaryrefslogtreecommitdiffstats
path: root/tests
AgeCommit message (Collapse)Author
2021-07-12Remove ttl hack & require -r option.Scott Kuhl
Previously, it was possible to run sshuttle locally without using ssh and connecting to a remote server. In this configuration, traffic was redirected to the sshuttle server running on the localhost. However, the firewall needed to distinguish between traffic leaving the sshuttle server and traffic that originated from the machine that still needed to be routed through the sshuttle server. The TTL of the packets leaving the sshuttle server were manipulated to indicate to the firewall what should happen. The TTL was adjusted for all packets leaving the sshuttle server (even if it wasn't necessary because the server and client were running on different machines). Changing the TTL caused trouble and some machines, and the --ttl option was added as a workaround to change how the TTL was set for traffic leaving sshuttle. All of this added complexity to the code for a feature (running the server on localhost) that is likely only used for testing and rarely used by others. This commit updates the associated documentation, but doesn't fully fix the ipfw method since I am unable to test that. This change will also make sshuttle fail to work if -r is used to specify a localhost. Pull request #610 partially addresses that issue. For example, see: #240, #490, #660, #606.
2021-05-30Merge branch 'master' into nat-ipv6Scott Kuhl
2021-05-29Add IPv6 support to nat (iptables) method.Scott Kuhl
Adding IPv6 support to the nat method is straightforward after the previous work to add IPv6 support for nft.
2021-05-27Fix --tmark optionScott Kuhl
Even when --tmark was used, the iptables code always used '1' for the mark. This patch corrects the problem. Previously, it wasn't clear if the tmark should be supplied in hexadecimal or as an integer. This makes it use hexadecimal, checks that the input is hexadecimal, and updates the associated documentation. This patch also makes --ttl information get passed to the firewall in a way that matches how other information gets passed. The ttl and tmark information are passed next to each other in many places and this patch also makes the order consistent.
2021-03-05firewall: Allow overriding the TTLVictor Kareh
In instances where a cluster pod in a local VM needs to access a server that is sshuttle'd from the host, since the packets arriving at the host already made a hop, their TTL is 63 and so get ignored by sshuttle. Allowing an override of the firewall TTL rule allows the packets to go through.
2021-02-16Allow comments in configuration fileKees Hink
2021-01-17feat: remove mock from test dependencies.masahitojp
Because mock can be replace by unittest.mock
2021-01-04tproxy: Skip firewall chains if packets have local destination. (#578)Scott Kuhl
If you use the tproxy method with a large subnet (such as 0/0), then (1) you may not receive UDP packets that sshuttle/tproxy can handle and (2) you are unable to connect to your machine using an IP that your computer recognizes as its own. To resolve those issues, any traffic to an IP that the host knows is local, does not go through the sshuttle chains.
2021-01-01Refactor debug, log and Fatal messages.Scott Kuhl
This commit rewrites the log() function so that it will append a newline at the end of the message if none is present. It doesn't make sense to print a log message without a newline since the next log message (which will write a prefix) expects to be starting at the beginning of a line. Although it isn't strictly necessary, this commit also removes any newlines at the ends of messages. If I missed any, including the newline at the end of the message will continue to work as it did before. Previously, some calls were missing the newline at the end even though including it was necessary for subsequent messages to appear correctly. This code also cleans up some redundant prefixes. The log() method will prepend the prefix and the different processes should set their prefix as soon as they start. Multiline messages are still supported (although the prefix for the additional lines was changed to match the length of the prefix used for the first line).
2020-12-28Refactor automatic method selection.Scott Kuhl
Add an "is_supported()" function to the different methods so that each method can include whatever logic they wish to indicate if they are supported on a particular machine. Previously, methods/__init__.py contained all of the logic for selecting individual methods. Now, it iterates through a list of possible options and stops on the first method that it finds that is_supported(). Currently, the decision is made based on the presence of programs in the PATH. In the future, things such as the platform sshuttle is running on could be considered.
2020-11-04Merge pull request #552 from skuhl/systemd-resolvedBrian May
Intercept DNS requests sent by systemd-resolved.
2020-11-03Make server and client handle resolv.conf differently.Scott Kuhl
The server should just read from resolv.conf to find DNS servers to use. This restores this behavior after the previous commit changed it. The client now reads both /etc/resolv.conf and /run/systemd/resolve/resolv.conf. The latter is required to more reliably intercept regular DNS requests that systemd-resolved makes.
2020-10-26Merge branch 'master' into which-fix to resolve merge conflict.Scott Kuhl
2020-10-23Improve consistency of PATH, environments, and which()Scott Kuhl
This patch attempts to fix (or aid in debugging) issue #350. sshuttle didn't explicitly search /sbin and /usr/sbin and they may be missing in the user's PATH. If PATH is missing, these folders wouldn't be searched either. There was also a program_exists function which is redundant to which(). This consolidates everything into the helpers.py file. This patch introduces get_path() to return PATH + some extra hardcoded paths. A new get_env() function can be called to create a consistent environment when calling external programs. The new which() wrapper function also ensures we use the same set of paths. If -vv is supplied, messages clearly indicate the programs we are looking for, if they are found, and where we looked if we failed to find them. I haven't tested the changes to ipfw or pf.
2020-10-21IPv6 support in nft method.Scott Kuhl
This works for me but needs testing by others. Remember to specify a ::0/0 subnet or similar to route IPv6 through sshuttle. I'm adding this to nft before nat since it is not sshuttle's default method on Linux. Documentation updates may be required too. This patch uses the ipaddress module, but that appears to be included since Python 3.3.
2020-10-21Make nat and nft rules consistent; improve rule ordering.Scott Kuhl
First, check if TTL indicates we should ignore packet (instead of checking in multiple rules later). Also, nft method didn't do this at all. Now, nft matches the behavior of nat. Second, forward DNS traffic (we may need to intercept traffic to localhost if a DNS server is running on localhost). Third, ignore any local traffic packets. (Previously, we ignored local traffic except DNS and then had the DNS rules). The nft method didn't do this previously at all. It now matches the behavior of nat. Lastly, list the subnets to redirect and/or exclude. This step is left unchanged. Excluding the local port that we are listening on is redundant with the third step, but should cause no harm. In summary, this ordering simplifies the rules in nat and eliminates differences that previously existed between nat and nft.
2020-10-20Merge pull request #541 from skuhl/use-all-ipsBrian May
When subnets and excludes are specified with hostnames, use all IPs.
2020-10-19Only write /etc/hosts when necessary.Scott Kuhl
Without this patch, sshuttle 'restores' /etc/hosts even if it didn't make any modifications to it. This can be confirmed by running without --auto-hosts and confirming that the modification time of /etc/hosts is unchanged while sshuttle is running, but is updated when sshuttle exits (and a debug2() message is printed indicating the file is written). I'm not aware of the previous behavior causing problems. However, writing an important file unnecessarily as root should be avoided.
2020-10-17Remove localhost test since it can resolve to either IPv4, IPv6, or both in ↵Scott Kuhl
any particular order
2020-10-17fix flake8 issues in updated testsScott Kuhl
2020-10-17Make tests for parse_subnetport() expect lists & update expected error ↵Scott Kuhl
messages in tests
2020-08-13Fix parse_hostport to always return string for hosttest_parse_hostportBrian May
This fixes #488 and provides an alternative solution for #489.
2020-06-03reduceJoshua Li
2020-06-03remove version_info based branchingJoshua Li
2019-10-13Add tproxy udp port mark filter that was missed in #144, fixes #367.Norman Rasmussen
2019-09-22Fix capturing of local DNS serversNick Sokolov
Regression was introduced in #337 that is skipping all local traffic, including DNS. This change makes UDP port 53 (DNS) LOCAL traffic to be treated as special case. Fixes #357
2019-09-22The size of pf_rule grew in OpenBSD 6.4Anthony Cornehl
2019-06-08Fix tests for existing PR-312 (#337)Daniel Jeffery
* use addrtype match to return the LOCAL trafik * Add assertion for the new LOCAL firewall rule added in PR 312. * Fix linter complaints
2019-02-11Fix/pep8 (#277)Bastian Venthur
* re-organized imports according to pep8 * fixed all remaining pep8 issues * moved common config into setup.cfg, additionally test `tests` * removed --select=X -- the errors selected where by default not in flake8's --ignore list so effectively had no effect * update .travis.yml to reflect changes in tox.ini * make travis just use tox in order to avoid code duplaction * replace py.test with pytest * fixed .travis.yml * try different pypy toxenv * hopefully fixed testenv for pypy * added pypy basepython, removed unused python2.6 * install dev package before testing (fixes missing coverage) * fixed empty exception pass blocks with noqa * Added dummy log message on empty try-except-pass blocks to make dodacy happy :( * Replaced Exception with BaseException
2018-11-03Changes pf exclusion rules precedenceJoão Vieira
Before this change, in pf, exclusions used a pass out quick which gave them higher precedence than any other rule independent of subnet width. As reported in #265 this causes exclusion from one instance of sshuttle to also take effect on other instances because quick aborts the evaluation of rules across all anchors. This commit changes the precedence of rules so quick can now be dropped. The new order is defined by the following rule, from subnet_weight: "We need to go from smaller, more specific, port ranges, to larger, less-specific, port ranges. At each level, we order by subnet width, from most-specific subnets (largest swidth) to least-specific. On ties, excludes come first."
2018-10-23Fixes support for OpenBSD (6.1+) (#282)João Vieira
* Fixes support for OpenBSD (6.1+) As reported in #219, new versions of OpenBSD ship with a different pfioc_rule struct. This commit adjusts the offset to match the new struct. * Fixes tests for OpenBSD 6.1+
2018-10-17updated pathBastian Venthur
2018-10-17Moved sshuttle/tests into tests to.Bastian Venthur
Having the tests in a `tests` directory in root is the most common approach. Also moved pytest's conftest.py into `tests` making the fixture available for client and server tests.