Metadata-Version: 2.5
Name: lupaxa-zone-transfer
Version: 0.1.5
Summary: Test whether a domain's nameservers allow DNS zone transfer (AXFR).
Project-URL: Homepage, https://github.com/lupaxa-security-toolbox/zone-transfer
Project-URL: Repository, https://github.com/lupaxa-security-toolbox/zone-transfer
Project-URL: Issues, https://github.com/lupaxa-security-toolbox/zone-transfer/issues
Author: The Lupaxa Project
License: MIT License
        
        Copyright (c) The Lupaxa Project
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENCE
Keywords: axfr,cli,dns,security,zone-transfer
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: System :: Networking
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Requires-Dist: colored>=2.2
Requires-Dist: dnspython>=2.6
Requires-Dist: prettytable>=3.10
Provides-Extra: dev
Requires-Dist: bump-my-version>=1.2.0; extra == 'dev'
Requires-Dist: hatch>=1.12.0; extra == 'dev'
Requires-Dist: mypy>=1.12.0; extra == 'dev'
Requires-Dist: pip-audit>=2.7.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-cov>=5.0; extra == 'test'
Requires-Dist: pytest>=8.0; extra == 'test'
Description-Content-Type: text/markdown

<p align="center">
  <a href="https://github.com/lupaxa-security-toolbox">
    <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/security-toolbox/readme-logo.png" alt="Security Toolbox" />
  </a>
</p>

<h1 align="center">Zone Transfer</h1>

Test whether a domain's nameservers allow DNS zone transfer (AXFR),
and show the zone contents when they do.

> **Warning:** **Authorised use only.** This tool contacts nameservers and can expose
> a full zone. Use it only on systems you are allowed to test.

## Install

Requires Python 3.10+. Runtime dependencies (`dnspython`, `prettytable`,
and `colored`) install with the package.

```bash
pip install lupaxa-zone-transfer
zone-transfer --help
```

You can also run `python -m lupaxa.zone_transfer`.

## CLI

```bash
zone-transfer example.com
zone-transfer example.com example.org
zone-transfer example.com --nameserver ns1.example.net --nameserver 203.0.113.10
zone-transfer example.com --format json
zone-transfer example.com --fail-open
zone-transfer example.com --timeout 10 --no-color
python -m lupaxa.zone_transfer --version
```

Each domain is inspected independently. The tool discovers `NS` records
(or uses `--nameserver` for every domain and skips discovery), sorts
hosts by name with IPv4 before IPv6, and tries AXFR on every address.
On a TTY a spinner on stderr shows the current lookup or transfer.
`--fail-open` exits `2` if any server allowed AXFR.

| Flag                 | Default       | Description                                     |
| :------------------- | :------------ | :---------------------------------------------- |
| `--nameserver`, `-n` | discover `NS` | Nameserver host or IP (repeatable)              |
| `--format`, `-f`     | `table`       | Output format: `table` or `json`                |
| `--fail-open`        | off           | Exit `2` if any endpoint allowed AXFR           |
| `--timeout`          | `10`          | DNS and AXFR timeout in seconds (must be `> 0`) |
| `--no-color`         | off           | Disable colour in table output                  |
| `--version`          | —             | Print the package version and exit              |

Table output is titled with the domain. Rows are nameserver, address,
family, status, and reason. For each `allowed` attempt a second table
lists name, type, TTL, and rdata. On a colour terminal, `allowed` is
red, `refused` is green, and `error` is grey. Pass `--no-color` or set
`NO_COLOR` for plain text.

JSON is a list of `{domain, error, attempts}` objects. Each attempt has
`nameserver`, `address`, `family`, `status`, `reason`, and `records`.
Record objects use `type` (not `rtype`). `error` is a string, never
`null`. `records` is always a list.

```json
[
  {
    "domain": "example.com",
    "error": "",
    "attempts": [
      {
        "nameserver": "ns1.example.net",
        "address": "203.0.113.10",
        "family": "IPv4",
        "status": "allowed",
        "reason": "",
        "records": [
          {"name": "@", "type": "SOA", "ttl": 3600, "rdata": "ns1.example.net. hostmaster. 1 1 1 1 1"}
        ]
      }
    ]
  }
]
```

### Attempt Status

| Status    | Meaning                                               |
| :-------- | :---------------------------------------------------- |
| `allowed` | AXFR succeeded; `records` holds the zone              |
| `refused` | Server answered not permitted (`REFUSED` / `FORMERR`) |
| `error`   | Timeout, connect failure, or no addresses             |

### Exit Codes

| Code | When                                                              |
| :--- | :---------------------------------------------------------------- |
| `0`  | Every domain was tested; refused and per-endpoint errors are OK   |
| `2`  | Invalid input, `NS` discovery failure, or `--fail-open` + allowed |

A domain-level `NS` discovery failure sets `error` and exits `2`. A
refused transfer is a normal result and exits `0` unless `--fail-open`
saw an `allowed` attempt.

## Library

```python
from lupaxa.zone_transfer import inspect_domain, inspect_many

report = inspect_domain("example.com")
pinned = inspect_domain("example.com", nameservers=["203.0.113.10"])
reports = inspect_many(["example.com", "example.org"], timeout=10.0)

for attempt in report.attempts:
    print(attempt.endpoint.address, attempt.status)
    for record in attempt.records:
        print(record.name, record.rtype, record.rdata)
```

`inspect_domain` does not raise when AXFR is refused or one address
fails. Those become attempt rows. Empty domains, an empty nameserver
list, or an empty `inspect_many` list raise `InvalidTargetError`.
`NameserverLookupError` is raised by `lookup_nameservers`;
`inspect_domain` catches it into `DomainReport.error`.
`ZoneTransferError` is the base class.

Pass `on_progress` to receive `Progress` events (`domain`, `phase`,
`message`, `current`, `total`). Phases are `lookup` (NS discovery),
`resolve` (A/AAAA expansion), and `try` (one AXFR). The library does
not print; the CLI uses that hook for the spinner.

## Development

```bash
make init
make python-install-dev
make python-check
```

<a href="https://github.com/the-lupaxa-project">
    <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
</a>
