Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 36 ยท Evasion, Timing and Ethics

Legal and Ethical Scanning

Learn when scanning is allowed, how to get written authorisation, define scope and rules of engagement, avoid harm, and build a scope checker in Python.

Nmap is a legitimate, widely used professional tool. Network administrators, security teams, researchers and students all use it. But a scan is not a harmless act in every context. It sends traffic to computers that belong to someone, it can trigger alarms and, with some options, it can disturb fragile services. The law and good practice both turn on one question: do you have permission?

This lesson is general education, not legal advice. Laws differ by country and change over time. When in doubt, ask the system's owner and, for formal work, a lawyer.

Only scan networks and devices that you own, or that the owner has authorised you in writing to test. "It is only a scan" and "I did not break in" are not defences. Home routers, school networks, workplace networks and cloud accounts all count as someone else's property unless you are the owner or have written permission.

Why permission matters

  • Computer misuse laws. Many countries (for example the Computer Fraud and Abuse Act in the United States and the Computer Misuse Act in the United Kingdom, plus laws in the EU and elsewhere) criminalise unauthorised access or attempts. Courts treat scanning differently; some see plain port scans as low risk, others treat them as preparation for an offence. Do not rely on that uncertainty.
  • Contracts and terms of service. Cloud providers and hosting companies often forbid unannounced scanning of their infrastructure, or require you to follow a policy, even for your own virtual machines. Read the provider's penetration-testing policy first.
  • Practical harm. Some devices (old printers, medical equipment, industrial controllers) can fail when probed. Your scan may cause real outages.
  • Employment. Scanning your employer's network without approval can end a career even if no law is broken.

Authorisation in practice

For professional work, get these in writing before the first packet:

  1. A signed authorisation. Who is allowing the test, on behalf of which organisation, and with what authority to approve it. Verify that the signer actually controls the targets (a company may not own the data centre network or the third-party service involved).
  2. Scope. Exactly which addresses, ranges, domains and cloud accounts are included, and which are excluded (third-party hosted systems, production databases, safety-critical devices).
  3. Rules of engagement. Allowed techniques (discovery only? version detection? vulnerability scripts?), forbidden ones (denial of service, brute force on production), test window, maximum scan rate, and contact persons.
  4. Emergency contacts. A phone number to call at once if a service breaks, and the person who can stop the test.
  5. Data handling. Where results are stored, who may read them, and how long they are kept. Scan results are sensitive: they list weaknesses.

A short written scope for a small business might look like this:

TEXT
Target ranges:        192.0.2.0/25 (office network)
Excluded:             192.0.2.10, 192.0.2.11 (production printers, do not scan)
Allowed:              host discovery, port scan (top 1000), -sV, safe/default NSE scripts
Not allowed:          brute, dos, exploit, fuzzer categories
Rate limit:           --max-rate 200
Window:               Saturday 22:00-24:00 UTC
Contact during test:  IT manager (phone number in the contract)

A scope checker in Python

Before launching a scan from a script, check every target against the written scope. This catches typing errors, such as a missing digit that points your scan at a different organisation's addresses. Python's ipaddress module does the work.

Python Check targets against the authorised scope

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that a /24 is refused even though it contains in-scope addresses, because it also reaches outside the scope. The safest design is to refuse unless the whole range is provably allowed.

Ethics beyond the law

Being legal is the minimum. A good practitioner also:

  • Minimises impact: uses gentle timing, avoids intrusive categories, and avoids scanning at peak hours.
  • Respects privacy: does not collect more than needed, and protects results.
  • Discloses responsibly: if you find an issue on a system you were allowed to test, report it to the owner privately and give time to fix it. If you stumble on a weakness elsewhere, report it through the organisation's security contact (security.txt) or a national CERT rather than exploiting or publishing it.
  • Stays within scope, even when something interesting appears just outside. Stop and ask.
  • Stays honest: the report states what was and was not tested, with the real limitations.

Safe places to practise

You do not need anyone else's network to learn:

  • Your own computer via 127.0.0.1 (nmap -sT 127.0.0.1 shows the services you run yourself).
  • A home lab: virtual machines on a private virtual network (VirtualBox, VMware, Hyper-V, or containers) that you control.
  • Deliberately vulnerable practice targets that you run yourself, such as the intentionally weak machines published for training, kept on an isolated network.
  • Official test hosts that explicitly allow scanning. The Nmap project provides scanme.nmap.org for light, polite testing, within its stated limits. Check the current terms on the project's site before use, and do not hammer it.
  • Documentation address ranges (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) are reserved for examples and are not routed on the internet, so they do not belong to anyone's machines.

Treat any host outside this list as off limits until you have written permission.

Python Checklist before a scan

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Where this leaves your Nmap use

Everything in this course assumes the checklist above. Use scans to know and protect your own systems. When your work grows beyond your own lab, put the authorisation in writing first, scan gently, and keep records. The project lessons in Projects and Practice build on this: they work on sample data and loopback only.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the most important condition for scanning a network?

    Permission from the owner is the dividing line between professional testing and potentially illegal activity.
  2. 2. Which item belongs in a written scope?

    A good scope states what is included and excluded, how you will test, when, and whom to call if something goes wrong.
  3. 3. Which addresses are safe to use for documentation examples?

    These three ranges are reserved for documentation and are not used by real internet hosts.
  4. 4. In the scope checker, why is a /24 refused although it contains authorised addresses?

    A range is allowed only if all of it is inside the scope. Partial overlap means some targets are not authorised.
  5. 5. What should you do if you find a weakness on a system outside your scope?

    Staying within scope and reporting responsibly is both legal practice and good ethics.

Summary

  • Get written authorisation, scope, rules of engagement and emergency contacts before scanning.
  • Check each target against the scope in code, and refuse anything not fully inside it.
  • Minimise harm, protect results and disclose findings responsibly.
  • Practise on 127.0.0.1, your own lab and documentation ranges.

Next: Output Formats