Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐️ nmap provider #4168

Merged
merged 3 commits into from
Dec 15, 2024
Merged

⭐️ nmap provider #4168

merged 3 commits into from
Dec 15, 2024

Conversation

chris-rock
Copy link
Member

@chris-rock chris-rock commented Jun 2, 2024

nmap provider

Nmap, short for Network Mapper, is a powerful and versatile open-source tool used for network discovery and security auditing. This tool is widely utilized by network administrators, security professionals, and penetration testers to map out network structures, discover hosts, identify services, and detect vulnerabilities.

The nmap provider maps primary objects and attributes that nmap uses to store and manage information about scanned targets, discovered hosts, and their associated ports and services.

Pre-requisites

This provider requires the nmap tool to be installed on your system. You can download and install nmap from the official website.

Get Started

cnquery shell nmap

Example

Scan active IP address in network

nmap.network("192.168.178.0/24").hosts { name ports { * }  }
nmap.network.hosts: [
  0: {
    ports: [
      0: {
        service: "http"
        version: ""
        method: "probed"
        state: "open"
        protocol: "tcp"
        port: 443
        product: "FRITZ!Box http config"
      }
      1: {
        service: "sip"
        version: ""
        method: "probed"
        state: "open"
        protocol: "tcp"
        port: 5060
        product: "AVM FRITZ!OS SIP"
      }
    ]
    name: "192.168.178.1"
  }
  1: {
    ports: [
      0: {
        service: "rtsp"
        version: "770.8.1"
        method: "probed"
        state: "open"
        protocol: "tcp"
        port: 5000
        product: "AirTunes rtspd"
      }
      1: {
        service: "rtsp"
        version: "770.8.1"
        method: "probed"
        state: "open"
        protocol: "tcp"
        port: 7000
        product: "AirTunes rtspd"
      }
    ]
    name: "192.168.178.25"
  }
]

Host scan with specific ip

nmap.network(target: "192.168.178.25").hosts { ports }
nmap.network.hosts: [
  0: {
    ports: [
      0: nmap.port port=5000 service="rtsp"
      1: nmap.port port=7000 service="rtsp"
    ]
  }
]

Advanced Usage

Discover all exposed hosts on a network.

cnquery shell nmap --networks "192.168.0.0/20" --discover hosts

Connect to a specific IP address and display all open ports.

cnquery shell nmap host 8.8.8.8

Verifying the Installation of nmap

To verify the installation of nmap, run the following command:

cnquery run nmap -c "nmap.version { * }"
nmap.version: {
  compiledWithout: []
  nsockEngines: [
    0: "kqueue"
    1: "poll"
    2: "select"
  ]
  version: "7.95"
  platform: "arm-apple-darwin23.4.0"
  compiledWith: [
    0: "liblua-5.4.6"
    1: "openssl-3.3.1"
    2: "libssh2-1.11.0"
    3: "libz-1.2.12"
    4: "libpcre2-10.44"
    5: "nmap-libpcap-1.10.4"
    6: "nmap-libdnet-1.12"
    7: "ipv6"
  ]
}

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 2, 2024

Test Results

3 171 tests  +2   3 169 ✅ +1   1m 42s ⏱️ +2s
  379 suites +6       2 💤 +1 
   29 files   +1       0 ❌ ±0 

Results for commit 52a21eb. ± Comparison against base commit a865b57.

♻️ This comment has been updated with latest results.

Makefile Outdated Show resolved Hide resolved
providers/defaults.go Outdated Show resolved Hide resolved
providers/nmap/README.md Outdated Show resolved Hide resolved
providers/nmap/README.md Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

@chris-rock chris-rock force-pushed the chris-rock/nmap branch 2 times, most recently from d4657a4 to 6b9b283 Compare October 4, 2024 12:09

This comment has been minimized.

@chris-rock
Copy link
Member Author

For discovery:

nmap -sT -T4 192.184.215.14

For service detection:

nmap -sT -T4 -sV 93.184.215.14

This comment has been minimized.

@atomic111
Copy link
Member

just to do a very fast ip discovery without scanning any port:

nmap -sn -n --min-parallelism 100 -T4 192.168.1.0/24

This comment has been minimized.

@atomic111
Copy link
Member

make a port scan just for the discovered hosts/ips

nmap -sT -sV  -n --min-parallelism 100 -T4 192.168.1.0/24

@chris-rock chris-rock marked this pull request as ready for review December 14, 2024 20:56
Copy link
Member

@atomic111 atomic111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris-rock awesome. thank you for the new nmap provider

@atomic111 atomic111 merged commit ebc4e69 into main Dec 15, 2024
16 checks passed
@atomic111 atomic111 deleted the chris-rock/nmap branch December 15, 2024 01:03
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants