Home page logo
/
Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News

Library comm

Common communication functions for network discovery tasks like banner grabbing and data exchange.

The functions in this module return values appropriate for use with exception handling via nmap.new_try.

These functions may be passed a table of options, but it's not required. The keys for the options table are "bytes", "lines", "proto", and "timeout". "bytes" sets a minimum number of bytes to read. "lines" does the same for lines. "proto" sets the protocol to communicate with, defaulting to "tcp" if not provided. "timeout" sets the socket timeout (see the socket function set_timeout for details).

If both "bytes" and "lines" are provided, "lines" takes precedence. If neither are given, the functions read as many bytes as possible.

Author:
Kris Katterjohn 04/2008

Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html

Source: http://nmap.org/svn/nselib/comm.lua

Functions

bestoption (port)

This function returns best protocol order for trying to open a conenction based on port and service information

exchange (host, port, data, opts)

This function connects to the specified port number on the specified host, sends data, then waits for and returns the response, if any.

get_banner (host, port, opts)

This function simply connects to the specified port number on the specified host and returns any data received.

is_ssl (port_number)

This function just checks if the provided port number is on a list of ports that usually provide services with ssl

opencon (ip, port, protocol, data, opts)

This function opens a connection, sends the first data payload and check if a response is correctly received (what means that the protocol used is fine)

tryssl (host, port, data, opts)

This function tries to open a connection based on the best option about which is the correct protocol



Functions

bestoption (port)

This function returns best protocol order for trying to open a conenction based on port and service information

The first value is the best option, the second is the worst

Parameters

  • port: The port table

Return values:

  1. Best option ("tcp" or "ssl")
  2. Worst option ("tcp" or "ssl")
exchange (host, port, data, opts)

This function connects to the specified port number on the specified host, sends data, then waits for and returns the response, if any.

The first return value is true to signal success or false to signal failure. On success the second return value is the response from the remote host. On failure the second return value is an error message.

Parameters

  • host: The host to connect to.
  • port: The port on the host.
  • data: The data to send initially.
  • opts: The options. See the module description.

Return values:

  1. Status (true or false).
  2. Data (if status is true) or error string (if status is false).
get_banner (host, port, opts)

This function simply connects to the specified port number on the specified host and returns any data received.

The first return value is true to signal success or false to signal failure. On success the second return value is the response from the remote host. On failure the second return value is an error message.

Parameters

  • host: The host to connect to.
  • port: The port on the host.
  • opts: The options. See the module description.

Return values:

  1. Status (true or false).
  2. Data (if status is true) or error string (if status is false).
is_ssl (port_number)

This function just checks if the provided port number is on a list of ports that usually provide services with ssl

Parameters

  • port_number: The number of the port to check

Return value:

bool True if port is usually ssl, otherwise false
opencon (ip, port, protocol, data, opts)

This function opens a connection, sends the first data payload and check if a response is correctly received (what means that the protocol used is fine)

Possible options: timeout: generic timeout value connect_timeout: especific timeout for connection request_timeout: especific timeout for requests recv_before: receive data before sending first payload

Default timeout is set to 8000.

Parameters

  • ip: The destination host IP
  • port: The destination host port
  • protocol: The protocol for the connection
  • data: The first data payload of the connection
  • opts:

Return values:

  1. sd The socket descriptor, nil if no connection is estabilished
  2. response The response received for the payload
  3. early_resp If opt recv_before is true, returns the value of the first receive (before sending data)
tryssl (host, port, data, opts)

This function tries to open a connection based on the best option about which is the correct protocol

If the best option fails, the function tries the other option

This function allows writing nse scripts in a way that the API will take care of ssl issues, making failure detection transparent to the programmer

Parameters

  • host: The host table
  • port: The port table
  • data: The first data payload of the connection
  • opts: Options, such as timeout

Return values:

  1. sd The socket descriptor
  2. response The response received for the payload
  3. correctOpt Correct option for connection guess
  4. earlyResp If opt recv_before is true, returns the value of the first receive (before sending data)

Nmap Site Navigation

Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]