shadowsocks / shadowsocks/shadowsocks-rust

[Suggestion] Use hash based domain-address mapping in fake-dns.

Open
#1,906 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
10.9k
Forks
1.5k
Avg merge
4d 15h
Merged PRs (30d)
5

Description

As mentioned in the Kubernetes docs, not all DNS clients respect the TTL of the returned records. Some clients cache DNS answers longer than they should, others resolve the domain names only once and cache the returned address.

This behavior can be problematic when used with fake-dns since the current implementation does not use a stable address for each domain, indeed, the address is always allocated from the lowest available addresses, and domains often point to expired entries. This behavior posts a great security risk when for example clients connect to what they think was a.com but got directed to b.com.

To mitigate this problem, it's best to use a stable mechanism when mapping domains to IP addresses. Often the IP pool is pretty large compared to the possible domain names, so a hash based, 'find-next-available address starting from some hashed address' strategy could satisfy the need for a stable address. Often the hashed address will be used, only in the rare case of a collision will the domain be mapped to some other address, reducing the risk significantly.

The strategy can be written as follows:
ip_base = map_to_ip_net(hash(domain_name))
ip = ip_base; do if ip available then assign(ip) else ip = ip + 1 until ip = ip_base;
if ip = ip_base (pool depleted, report error)

It should be pretty easy to implement as I have done ip translations(nat) like this in C.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating fake-dns's current address allocation and domain-to-address mapping, then review how expired entries and the available IP pool are handled. Implement the proposed hash-based starting address with collision probing and pool-depletion reporting; done means domains receive stable addresses without redirecting cached clients to other domains.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.