Cyber Services / All lessons / CEH — Ethical Hacking / Web Scanning using Nmap Scripting Engine (NSE)

Web Scanning using Nmap Scripting Engine (NSE)

Module 15 of 130 · 9 min read · Free to read

MODULES ↓ Command blocks have a COPY button
Mastering NSE for Comprehensive Security Assessments
Advanced NSE Vulnerability Detection Network Enumeration Practical Activities

Overview

While basic NSE usage is powerful, mastering advanced techniques unlocks Nmap's full potential for security assessments. This guide explores sophisticated NSE scenarios, script customization, and practical applications for penetration testing and security auditing.

Advanced NSE Capabilities

Beyond simple discovery, NSE can perform targeted vulnerability scanning, exploit detection, advanced service enumeration, and even post-exploitation activities. Understanding these advanced capabilities transforms Nmap from a reconnaissance tool into a comprehensive security assessment platform.

Vulnerability Detection

Identify specific CVEs and security weaknesses across services

Service Enumeration

Extract detailed information from databases, web apps, and network services

Custom Scripting

Customize scripts with arguments for specific assessment scenarios

Network Discovery

Automate complex network mapping and host discovery tasks

Responsible Usage Notice

Advanced NSE techniques should only be used in authorized security assessments. Unauthorized scanning and testing is illegal and unethical. Always obtain proper permissions and follow responsible disclosure practices.

Targeted Vulnerability Assessment with NSE

Web Application Vulnerability Scanning

NSE includes comprehensive scripts for detecting common web vulnerabilities across various platforms and frameworks.

# Run all HTTP vulnerability detection scripts
nmap -p 80,443 --script http-vuln-* target_domain

Executes all available HTTP vulnerability scripts against web services on standard ports.

# Check for specific Apache Struts vulnerability
nmap -p 443 --script http-vuln-cve2017-5638 target_ip

Specifically checks for Apache Struts CVE-2017-5638 remote code execution vulnerability.

# WordPress vulnerability assessment
nmap -p 80,443 --script http-wordpress-* target_domain

Runs WordPress-specific vulnerability and enumeration scripts.

Database Security Assessment

Database servers often contain critical data and require thorough security checks using specialized NSE scripts.

# MySQL security audit and vulnerability check
nmap -p 3306 --script mysql-audit,mysql-vuln-cve2012-2122 target_ip

Performs MySQL security audit and checks for authentication bypass vulnerability (CVE-2012-2122).

# PostgreSQL brute-force and enumeration
nmap -p 5432 --script pgsql-brute,pgsql-enum-databases target_ip

Attempts to brute-force PostgreSQL credentials and enumerate available databases.

# MongoDB security assessment
nmap -p 27017 --script mongodb-* target_ip

Runs all MongoDB-related scripts for comprehensive database assessment.

Activity 1: Web Application Vulnerability Assessment
Objective: Perform comprehensive vulnerability assessment of a web application
  1. Identify all open web ports (80, 443, 8080, 8443) on the target
  2. Run HTTP vulnerability scripts: nmap -p 80,443 --script http-vuln-* target
  3. Execute WordPress-specific checks if applicable
  4. Test for specific CVEs based on detected technologies
  5. Document all findings with severity ratings
# Complete web application assessment command
nmap -p 80,443,8080,8443 --script "http-vuln-* or http-wordpress-*" -sV target_domain -oA web_vuln_scan

Advanced Service Enumeration Techniques

Comprehensive SMB Enumeration

SMB/CIFS services often reveal extensive network information, user accounts, and shared resources that are valuable for security assessments.

# Complete SMB enumeration
nmap -p 445 --script smb-os-discovery,smb-enum-shares,smb-enum-users,smb-enum-groups target_ip

Discovers OS information, shared resources, user accounts, and groups via SMB.

# Check for EternalBlue vulnerability
nmap -p 139,445 --script smb-vuln-ms17-010 --script-args unsafe=1 target_ip

Checks for EternalBlue vulnerability (CVE-2017-0144) with unsafe arguments for more aggressive testing.

# SMB security modes and settings
nmap -p 445 --script smb-security-mode,smb-server-stats target_ip

Retrieves SMB security settings and server statistics.

Advanced SNMP Information Gathering

SNMP services can reveal extensive network and system information when properly enumerated.

# SNMP community string brute-forcing
nmap -sU -p 161 --script snmp-brute target_ip

Attempts to brute-force SNMP community strings using common defaults.

# Comprehensive SNMP enumeration
nmap -sU -p 161 --script snmp-sysdescr,snmp-interfaces,snmp-processes,snmp-netstat target_ip

Extracts system description, network interfaces, running processes, and network statistics via SNMP.

# SNMP with specific community string
nmap -sU -p 161 --script snmp-info --script-args snmpcommunity=public target_ip

Uses a specific community string for SNMP information gathering.

Activity 2: Windows Network Enumeration
Objective: Perform comprehensive enumeration of Windows network services
  1. Scan for SMB services on ports 139 and 445
  2. Enumerate shares, users, and groups
  3. Check for common SMB vulnerabilities
  4. Attempt to identify the Windows version and domain information
  5. Document accessible resources and potential attack vectors
# Complete Windows network enumeration
nmap -p 139,445 --script "smb-* and not (smb-brute or smb-flood)" -sV target_ip -oA windows_enum

Custom Script Arguments for Advanced Scenarios

HTTP Script Customization

HTTP scripts can be extensively customized for specific testing scenarios and environments.

# Custom HTTP enumeration with specific paths
nmap -p 80 --script http-enum --script-args http-enum.displayall=true,http-enum.basepath=/webapp/ target_ip

Enables display of all results and sets a custom base path for web application enumeration.

# Custom User-Agent for HTTP requests
nmap -p 443 --script http-headers --script-args http.useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" target_ip

Sets a custom User-Agent string to mimic specific browser traffic.

# HTTP methods testing with custom paths
nmap -p 80 --script http-methods --script-args http-methods.url-path=/api/v1/ target_ip

Tests HTTP methods on a specific API endpoint path.

Brute-Force Script Configuration

Brute-force scripts can be configured with custom wordlists, timing parameters, and authentication mechanisms.

# SSH brute-force with custom wordlists
nmap -p 22 --script ssh-brute --script-args userdb=users.txt,passdb=passwords.txt,brute.retries=1 target_ip

Uses custom user and password lists for SSH brute-forcing with limited retries.

# FTP brute-force with timing control
nmap -p 21 --script ftp-brute --script-args brute.delay=2,brute.retries=1,brute.threads=3 target_ip

Configures delay between attempts, retries count, and thread count for FTP brute-forcing.

# MySQL brute-force with specific databases
nmap -p 3306 --script mysql-brute --script-args mysql-brute.dbs=admin,root,test target_ip

Targets specific database names during MySQL brute-force attempts.

Activity 3: Custom Script Configuration
Objective: Configure and customize NSE scripts for specific assessment scenarios
  1. Create custom user and password wordlists for brute-force testing
  2. Configure HTTP scripts to target specific application paths
  3. Set custom timing parameters to avoid detection
  4. Use script arguments to focus on specific services or vulnerabilities
  5. Test different script combinations for optimal results
# Example of customized scanning command
nmap -p 22,80,443 --script "ssh-brute or http-enum" --script-args userdb=custom_users.txt,passdb=custom_pass.txt,http-enum.basepath=/admin/ target_ip

Network Discovery and Mapping with NSE

Advanced Host Discovery

Beyond standard ping scans, NSE can perform sophisticated host discovery using various network protocols and techniques.

# Network target sniffing
nmap -sn --script targets-sniffer --script-args targets-sniffer.timeout=30 network_range

Sniffs the network for targets using ARP and other discovery methods with a 30-second timeout.

# DHCP server discovery
nmap -sn --script broadcast-dhcp-discover network_range

Discovers DHCP servers and requests IP configuration information from the network.

# Multicast DNS discovery
nmap -sn --script broadcast-mdns-service-discovery network_range

Discovers services and devices using multicast DNS (mDNS) protocol.

Service-Specific Discovery

Target discovery for specific services can reveal specialized devices and applications on the network.

# SNMP-enabled host discovery
nmap -sU -p 161 --script snmp-brute --script-args snmp-brute.communitiesdb=common-snmp-community-strings.txt network_range

Discovers SNMP-enabled hosts using common community strings across a network range.

# Windows/SMB host discovery
nmap -p 445 --script smb-discovery network_range

Discovers Windows/SMB hosts on the network by scanning for port 445.

# Database server discovery
nmap -p 1433,1521,3306,5432,27017 --script "oracle-tns-version or mysql-info or pgsql-banner or mongodb-info" network_range

Discovers and identifies various database servers on common database ports.

Practical Activities & Hands-On Tasks

Activity 4: Comprehensive Network Assessment
Objective: Perform a complete network security assessment using advanced NSE techniques
  1. Discover all live hosts on the target network
  2. Identify all open ports and services
  3. Perform service version detection
  4. Run vulnerability scripts against discovered services
  5. Enumerate user accounts and shares where possible
  6. Generate comprehensive reports in multiple formats
# Complete network assessment command
nmap -sS -sU -p- --script "default or safe or discovery or vuln" -sV -T4 -oA comprehensive_scan network_range
Activity 5: Web Application Security Assessment
Objective: Conduct thorough web application security testing using NSE
  1. Identify all web services and applications
  2. Test for common web vulnerabilities (XSS, SQLi, etc.)
  3. Enumerate web application structure and technologies
  4. Check for specific CMS vulnerabilities
  5. Test authentication mechanisms
  6. Document findings with proof of concept
# Web application security assessment
nmap -p 80,443,8080,8443 --script "http-* and not (http-brute or http-slowloris)" -sV --script-args http.useragent="Custom Security Scanner" target_domain
Activity 6: Database Security Audit
Objective: Perform security assessment of database servers
  1. Discover database servers on the network
  2. Identify database types and versions
  3. Test for weak authentication
  4. Check for known vulnerabilities
  5. Enumerate database structures and users
  6. Document security findings and recommendations
# Database security audit command
nmap -p 1433,1521,3306,5432,27017 --script "db-* or *-brute or *-info or *-vuln*" -sV network_range

Real-World Assessment Scenarios

Scenario 1: External Web Application Assessment

Comprehensive external web application security testing for internet-facing systems.

# External web application assessment
nmap -p 80,443,8080,8443 --script "http-* and not (http-brute or http-slowloris)" -sV target_domain

Runs all HTTP-related scripts except brute-force and DoS-related ones against common web ports.

Key Objectives:

  • Identify web application technologies and frameworks
  • Detect common web vulnerabilities (XSS, SQL injection, etc.)
  • Enumerate application structure and endpoints
  • Check for security misconfigurations
  • Identify information disclosure issues

Scenario 2: Internal Network Penetration Test

Comprehensive internal network security assessment for organizational networks.

# Internal network penetration test
nmap -sS -sU -p- --script "discovery,vuln,safe" -T4 -oA internal_network_scan network_range

Performs comprehensive TCP and UDP scan with discovery, vulnerability, and safe scripts.

Key Objectives:

  • Map the entire network topology
  • Identify all active hosts and services
  • Detect vulnerable services and configurations
  • Enumerate user accounts and shared resources
  • Identify potential lateral movement paths

Scenario 3: Targeted Service Assessment

Focus on specific services with detailed enumeration and vulnerability assessment.

# Targeted service assessment
nmap -p 22,21,23,25,53,80,110,143,443,993,995,1433,3306,3389,5432 --script "default or (discovery and safe)" -sV target_ip

Targets common service ports with default and discovery scripts for focused assessment.

Key Objectives:

  • Assess security of critical network services
  • Identify service-specific vulnerabilities
  • Check for weak authentication mechanisms
  • Verify service hardening and configuration
  • Document service exposure and risks
Advanced Security Considerations

Advanced NSE scripts can be intrusive and may impact target systems. Always ensure proper authorization before using vulnerability, exploit, or brute-force scripts. Some scripts may trigger security alerts in monitored environments. Consider the following:

  • Test scripts in isolated environments first
  • Use timing controls to minimize impact
  • Monitor target system responses during testing
  • Have rollback plans for critical systems
  • Document all activities for reporting and accountability

Conclusion

The Nmap Scripting Engine provides extensive capabilities for advanced security assessments when used appropriately. By mastering script selection, argument customization, and combining NSE with other Nmap features, security professionals can perform comprehensive network reconnaissance, vulnerability assessment, and service enumeration.

Key Takeaways
  • NSE transforms Nmap from a simple scanner to a comprehensive security assessment platform
  • Advanced script arguments enable customization for specific environments
  • Vulnerability detection scripts can identify specific CVEs and security issues
  • Service enumeration provides deep insights into network configurations
  • Proper output formatting enables effective reporting and documentation
  • Always operate within authorized scopes and follow ethical guidelines
Final Ethical Reminder

Advanced NSE techniques are powerful tools that must be used responsibly. Always ensure you have explicit, written permission before scanning any systems. Unauthorized scanning is not only unethical but also illegal in many jurisdictions. Use these skills to improve security, not compromise it. Document your findings responsibly and follow proper disclosure procedures.

Modules (130) ← CEH — Ethical Hacking