cvs: pear /Net_Nmap Nmap.php package.xml /Net_Nmap/examples example1.php /Net_Nmap/tests NetNmapScanTest.php test_config.php
[email protected] ("Luca Corbo") Mon, 12 May 2008 13:18:34 -0000
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvslucor1210598314@cvsserver> |
lucor Mon May 12 13:18:34 2008 UTC
Modified files:
/pear/Net_Nmap/tests NetNmapScanTest.php test_config.php
/pear/Net_Nmap Nmap.php package.xml
/pear/Net_Nmap/examples example1.php
Log:
- Changed. By default nmap scan is performed without any parameters.
- Added. The enableOptions() method to Nmap class to set Nmap parameters.
- Changed. The Os detection flag was removed as option in the constructor.
- Updated. Tests and examples.
lucor-20080512131834.txt
(text/plain, 12.2 KB)
http://cvs.php.net/viewvc.cgi/pear/Net_Nmap/tests/NetNmapScanTest.php?r1=1.1.1.1&r2=1.2&diff_format=u
Index: pear/Net_Nmap/tests/NetNmapScanTest.php
diff -u pear/Net_Nmap/tests/NetNmapScanTest.php:1.1.1.1 pear/Net_Nmap/tests/NetNmapScanTest.php:1.2
--- pear/Net_Nmap/tests/NetNmapScanTest.php:1.1.1.1 Wed Apr 16 09:08:30 2008
+++ pear/Net_Nmap/tests/NetNmapScanTest.php Mon May 12 13:18:34 2008
@@ -52,6 +52,8 @@
public function testNmapBinaryInPath()
{
$nmap = new Net_Nmap();
+ $nmap->enableOptions($GLOBALS['nmap_options']);
+ print_r($GLOBALS['nmap_options']);
$res = $nmap->scan($this->_target);
$this->assertEquals(true, $res);
}
http://cvs.php.net/viewvc.cgi/pear/Net_Nmap/tests/test_config.php?r1=1.1.1.1&r2=1.2&diff_format=u
Index: pear/Net_Nmap/tests/test_config.php
diff -u pear/Net_Nmap/tests/test_config.php:1.1.1.1 pear/Net_Nmap/tests/test_config.php:1.2
--- pear/Net_Nmap/tests/test_config.php:1.1.1.1 Wed Apr 16 09:08:30 2008
+++ pear/Net_Nmap/tests/test_config.php Mon May 12 13:18:34 2008
@@ -31,4 +31,9 @@
//define('NMAP_BINARY', 'C:\Programmi\Nmap\nmap.EXE');
define('OUTPUT_FILE', '/tmp/testNmapSaveOutputFile1.xml');
define('NMAP_BINARY', '/usr/local/bin/nmap');
+$nmap_options = array('os_detection' => true,
+ 'service_info' => true,
+ 'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',
+ //'all_options' => true
+ );
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/pear/Net_Nmap/Nmap.php?r1=1.1.1.1&r2=1.2&diff_format=u
Index: pear/Net_Nmap/Nmap.php
diff -u pear/Net_Nmap/Nmap.php:1.1.1.1 pear/Net_Nmap/Nmap.php:1.2
--- pear/Net_Nmap/Nmap.php:1.1.1.1 Wed Apr 16 09:08:30 2008
+++ pear/Net_Nmap/Nmap.php Mon May 12 13:18:34 2008
@@ -49,7 +49,7 @@
* Location of the nmap binary
*
* @var string $nmap_path
- * @see Net_Namp::__construct()
+ * @see Net_Nmap::__construct()
* @access private
*/
private $_nmap_binary;
@@ -58,19 +58,10 @@
* Absolute path to store the Nmap XML output file.
*
* @var string
- * @see Net_Namp::__construct()
+ * @see Net_Nmap::__construct()
* @access private
*/
private $_output_file = null;
-
- /**
- * Force the OS detection
- *
- * @var boolean
- * @see Net_Namp::__construct()
- * @access private
- */
- private $_os_detection = false;
/**
* Delete Nmap output file after parsing
@@ -89,6 +80,15 @@
private $_failed_to_resolve = array();
/**
+ * Nmap option arguments
+ *
+ * @var array
+ * @link http://nmap.org/book/man-briefoptions.html
+ * @access private
+ */
+ private $_nmap_options = array();
+
+ /**
* Creates a new Nmap object
*
* Available options are:
@@ -98,9 +98,6 @@
*
* - string output_file: Path to store the Nmap XML output file.
* If not specified, a temporary file is created.
- *
- * - boolean os_detection: Force the OS detection, requires root privileges.
- * If not specified, defaults to false.
*
* @param array $options optional. An array of options used to create the
* Nmap object. All options must be optional and are
@@ -119,10 +116,6 @@
if (array_key_exists('output_file', $options)) {
$this->_output_file = (string)$options['output_file'];
}
-
- if (array_key_exists('os_detection', $options)) {
- $this->_os_detection = (boolean)$options['os_detection'];
- }
}
/**
@@ -135,7 +128,6 @@
*/
private function _createCommandLine($targets)
{
- $default_option = ' -A ';
if ($this->_output_file === null) {
$this->_output_file = tempnam(System::tmpdir(), __CLASS__);
@@ -144,10 +136,7 @@
}
$cmd = escapeshellarg($this->_nmap_binary);
- $cmd .= $default_option;
- if ($this->_os_detection) {
- $cmd .= ' -O ';
- }
+ $cmd .= ' ' . implode(' ', $this->_nmap_options);
$cmd .= ' -oX ' . escapeshellarg($this->_output_file) . ' ';
foreach ($targets as $target) {
$cmd .= escapeshellarg($target) . ' ';
@@ -229,5 +218,54 @@
{
return $this->_failed_to_resolve;
}
+
+ /**
+ * Enable Nmap options
+ * Available nmap options are:
+ *
+ * - boolean os_detection: Enable the OS detection (-O).
+ * - boolean service_info: Probe open ports to determine
+ * service/version info (-sV)
+ * - string port_ranges : Port ranges, only scan
+ * specified ports (-p <port ranges>)
+ * Ex: 22; 1-65535; U:53,111,137,T:21-25,80,139,8080
+ * - boolean all_options : Enables OS detection and Version detection,
+ * Script scanning and Traceroute (-A)
+ *
+ * @param array $nmap_options Nmap options to enable
+ *
+ * @return void
+ * @link http://nmap.org/book/man-briefoptions.html
+ * @throws Net_Nmap_Exception If the option argument is not valid.
+ * @access public
+ */
+ public function enableOptions($nmap_options)
+ {
+ $enable_os_detection = array_key_exists('os_detection', $nmap_options);
+ $enable_service_info = array_key_exists('service_info', $nmap_options);
+ $enable_port_ranges = array_key_exists('port_ranges', $nmap_options);
+ $enable_all_options = array_key_exists('all_options', $nmap_options);
+
+ if ($enable_os_detection && $nmap_options['os_detection']) {
+ $this->_nmap_options[] = '-O';
+ }
+ if ($enable_service_info && $nmap_options['service_info']) {
+ $this->_nmap_options[] = '-sV';
+ }
+ if ($enable_port_ranges) {
+ $port_ranges = $nmap_options['port_ranges'];
+ $allowed_format = '([U,T]\:)*[0-9]+(-[0-9]+)*';
+
+ $regexp = '/^' . $allowed_format . '(,' . $allowed_format . ')*$/';
+ if (preg_match($regexp, $port_ranges)) {
+ $this->_nmap_options[] = '-p ' . $port_ranges;
+ } else {
+ throw new Net_Nmap_Exception('Port ranges: not valid format.');
+ }
+ }
+ if ($enable_all_options && $nmap_options['all_options']) {
+ $this->_nmap_options[] = '-A';
+ }
+ }
}
-?>
+?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/pear/Net_Nmap/package.xml?r1=1.1.1.1&r2=1.2&diff_format=u
Index: pear/Net_Nmap/package.xml
diff -u pear/Net_Nmap/package.xml:1.1.1.1 pear/Net_Nmap/package.xml:1.2
--- pear/Net_Nmap/package.xml:1.1.1.1 Wed Apr 16 09:08:29 2008
+++ pear/Net_Nmap/package.xml Mon May 12 13:18:34 2008
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.6.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.7.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>Net_Nmap</name>
<channel>pear.php.net</channel>
<summary>A simple wrapper class for the Nmap utility</summary>
@@ -17,23 +17,26 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
- <date>2008-04-15</date>
- <time>20:53:18</time>
+ <date>2008-05-12</date>
+ <time>15:06:50</time>
<version>
- <release>0.9.9</release>
- <api>0.9.9</api>
+ <release>1.0.0beta1</release>
+ <api>1.0.0beta1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
- <notes>Initial release</notes>
+ <notes>- Changed. By default nmap scan is performed without any parameters.
+- Added. The enableOptions() method to Nmap class to set Nmap parameters.
+- Changed. The Os detection flag was removed as option in the constructor.
+- Updated. Tests and examples.</notes>
<contents>
<dir baseinstalldir="Net" name="/">
<file baseinstalldir="Net" md5sum="b29c0845cfd8eb68f25dd58c624c161f" name="docs/LICENSE" role="data" />
<file baseinstalldir="Net" md5sum="c9f392b18fe4858ed94fdbe0b9e42ea4" name="docs/README" role="data" />
- <file baseinstalldir="Net" md5sum="11545ad1578b8353f8b703a163288b58" name="examples/example1.php" role="data" />
+ <file baseinstalldir="Net" md5sum="ef0012d21f92f805542a73e4bdadfdeb" name="examples/example1.php" role="data" />
<file baseinstalldir="Net" md5sum="c2777cd5fc39894621d0db683d9c51cd" name="examples/example2.php" role="data" />
<file baseinstalldir="Net" md5sum="18e069a87ebdd95a186af0b68293fba4" name="examples/example2.xml" role="data" />
<file baseinstalldir="Net" md5sum="b3183c33dc2c8e3e9dc88e24a63c9670" name="Nmap/Exception.php" role="php" />
@@ -42,9 +45,9 @@
<file baseinstalldir="Net" md5sum="397993dab656ce44e2dd772fa75f16b9" name="Nmap/Service.php" role="php" />
<file baseinstalldir="Net" md5sum="2009883fbca681f18650332f46f9d585" name="tests/NetNmapParseTest.php" role="test" />
<file baseinstalldir="Net" md5sum="18e069a87ebdd95a186af0b68293fba4" name="tests/NetNmapParseTest.xml" role="test" />
- <file baseinstalldir="Net" md5sum="8d38b007a35ff60ca932c2bc60c7a50d" name="tests/NetNmapScanTest.php" role="test" />
- <file baseinstalldir="Net" md5sum="647ed23e0128a1f6c0ac6966105594b9" name="tests/test_config.php" role="test" />
- <file baseinstalldir="Net" md5sum="0433385f7fef3a25bed9b25ea825a80c" name="Nmap.php" role="php" />
+ <file baseinstalldir="Net" md5sum="0b0b7cad6875a55140903794ef6bb72c" name="tests/NetNmapScanTest.php" role="test" />
+ <file baseinstalldir="Net" md5sum="0275854dd7278353fc56b5ab0aadcda7" name="tests/test_config.php" role="test" />
+ <file baseinstalldir="Net" md5sum="f54fab5638a9a305814fe7becadb7790" name="Nmap.php" role="php" />
</dir>
</contents>
<dependencies>
@@ -147,5 +150,21 @@
<license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
<notes>Initial release</notes>
</release>
+ <release>
+ <version>
+ <release>1.0.0beta1</release>
+ <api>1.0.0beta1</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <date>2008-05-12</date>
+ <license uri="http://www.gnu.org/licenses/lgpl.html">LGPL</license>
+ <notes>- Changed. By default nmap scan is performed without any parameters.
+- Added. The enableOptions() method to Nmap class to set Nmap parameters.
+- Changed. The Os detection flag was removed as option in the constructor.
+- Updated. Tests and examples.</notes>
+ </release>
</changelog>
</package>
http://cvs.php.net/viewvc.cgi/pear/Net_Nmap/examples/example1.php?r1=1.1.1.1&r2=1.2&diff_format=u
Index: pear/Net_Nmap/examples/example1.php
diff -u pear/Net_Nmap/examples/example1.php:1.1.1.1 pear/Net_Nmap/examples/example1.php:1.2
--- pear/Net_Nmap/examples/example1.php:1.1.1.1 Wed Apr 16 09:08:30 2008
+++ pear/Net_Nmap/examples/example1.php Mon May 12 13:18:34 2008
@@ -36,12 +36,20 @@
$target = array('127.0.0.1');
$options = array('output_file' => '/your/path/testNmap.xml',
- 'nmap_binary' => '/usr/local/bin/nmap',
- 'os_detection' => true);
+ 'nmap_binary' => '/usr/local/bin/nmap');
try {
$nmap = new Net_Nmap($options);
-
+
+ //Enable nmap options
+ $nmap_options = array('os_detection' => true,
+ 'service_info' => true,
+ 'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',
+ //'all_options' => true
+ );
+
+ $nmap->enableOptions($nmap_options);
+
//Scan target
$res = $nmap->scan($target);