From 4fc8a67ca9b8346fd6bdf0fa926073217fcd543b Mon Sep 17 00:00:00 2001 From: centaur Date: Thu, 10 Dec 2015 18:48:56 +0100 Subject: [PATCH] Instalation simplified with setup and install pages. --- ajax.php | 4 +- assets/scripts.js | 28 ++++++++++- assets/style.css | 4 +- config.php | 25 ++++++++++ db-structure.sql | 5 +- export.php | 2 +- filter.php | 2 +- import.php | 2 +- includes/error.php | 18 +++++-- includes/functions.php | 4 +- includes/html/db-create-user-help.html | 44 +++++++++++++++++ includes/html/db-tuning.html | 34 +++++++++++++ includes/html/delete-files-help.html | 4 ++ includes/html/import-help.html | 35 +++++++++++++ includes/install.php | 60 +++++++++++++++++++++++ includes/list.php | 1 - includes/setup.php | 58 ++++++++++++++++++++++ index.php | 5 +- lib/class.db.php | 8 ++- lib/exceptions/class.common.exception.php | 3 +- lib/exceptions/class.db.exception.php | 15 ++++-- lib/mysql/class.mysql.php | 7 ++- 22 files changed, 340 insertions(+), 28 deletions(-) create mode 100755 config.php create mode 100644 includes/html/db-create-user-help.html create mode 100644 includes/html/db-tuning.html create mode 100644 includes/html/delete-files-help.html create mode 100644 includes/html/import-help.html create mode 100644 includes/install.php create mode 100644 includes/setup.php diff --git a/ajax.php b/ajax.php index 39ebb61..4cd65d9 100755 --- a/ajax.php +++ b/ajax.php @@ -1,5 +1,5 @@ - 0): $q = "SELECT ip as ipaddress, port_id, service, protocol, banner, title FROM data WHERE ip =".(int) $ip." ORDER BY scanned_ts DESC"; diff --git a/assets/scripts.js b/assets/scripts.js index a48e2fa..af70ec0 100755 --- a/assets/scripts.js +++ b/assets/scripts.js @@ -1,5 +1,4 @@ var delayTimer; - $('#myModal').on('show', function () { $(this).find('.modal-body').css({width:'auto', height:'auto', @@ -164,4 +163,31 @@ function searchData(data, throbber) }; $.ajax(ajax_options); return false; +} + +function showImportHelp() +{ + jQuery('#myModalLabel').text('How to scan and import data?'); + var ajax_options = { + beforeSend:function () { + + }, + complete:function () { + + }, + error:function (XMLHttpRequest, textStatus, errorThrown) { + alert('There was an error during request. Please try again!'); + }, + success:function (response, textStatus) { + $('#myModal').modal('show'); + jQuery('.modal-body').html(response); + }, + timeout:'100000', + type:'get', + dataType:'html', + data:'', + url:'/includes/html/import-help.html' + }; + $.ajax(ajax_options); + return false; } \ No newline at end of file diff --git a/assets/style.css b/assets/style.css index 60140d1..b60b655 100755 --- a/assets/style.css +++ b/assets/style.css @@ -131,4 +131,6 @@ img#ajax-loader-pagination { margin:10px 15px 0 0; display:none;} .container.errorPage { min-height:540px; } .container.errorPage p { font-size: inherit !important;} -.container.errorPage .jumbotron { margin-top:5%; } \ No newline at end of file +.container.errorPage .jumbotron { margin-top:0 !important; padding-top:10px !important;} +.container.errorPage .jumbotron h1 { margin:0 !important;} +pre.shell { background:black; color:white; } \ No newline at end of file diff --git a/config.php b/config.php new file mode 100755 index 0000000..6467254 --- /dev/null +++ b/config.php @@ -0,0 +1,25 @@ +Oops!

An error has occured.

-

Check read me file for help.

- + getMessage(), $matches)): + include DOC_ROOT.'includes/html/db-create-user-help.html'; + include DOC_ROOT.'includes/html/db-structure-help.html'; + include DOC_ROOT.'includes/html/db-tuning.html'; + include DOC_ROOT.'includes/html/delete-files-help.html'; + elseif (preg_match('/^Database (.*) not found/', $this->getMessage(), $matches)): + include DOC_ROOT.'includes/html/db-database-help.html'; + include DOC_ROOT.'includes/html/db-structure-help.html'; + include DOC_ROOT.'includes/html/db-tuning.html'; + include DOC_ROOT.'includes/html/delete-files-help.html'; + endif; + ?> + diff --git a/includes/functions.php b/includes/functions.php index 0d7caa0..5da6ba8 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -22,8 +22,8 @@ function browse($filter, $export = false) list($start_ip, $end_ip) = getStartAndEndIps($filter['ip']); $q .= " AND (ip >= $start_ip AND ip <= $end_ip)"; endif; - if (isset($filter['port']) && (int)$filter['port'] > 0 && (int)$filter['port'] <= 65535): - $q .= " AND port_id = " . (int)$filter['port']; + if (isset($filter['port']) && (int) $filter['port'] > 0 && (int) $filter['port'] <= 65535): + $q .= " AND port_id = " . (int) $filter['port']; endif; if (!empty($filter['protocol'])): $q .= " AND protocol = '" . DB::escape($filter['protocol']) . "'"; diff --git a/includes/html/db-create-user-help.html b/includes/html/db-create-user-help.html new file mode 100644 index 0000000..8ce1fef --- /dev/null +++ b/includes/html/db-create-user-help.html @@ -0,0 +1,44 @@ +

Step by step instructions:

+

Open and enter host, username, password and database name.

+

Open terminal and go to the document root of application by typing:

+
+root@kali:~# cd 
+
+

Edit config.php and update the file with mysql host, user, password and database information. Type:

+
+root@kali:# nano includes/config.php
+
+

and change the following values to suit your MySql server:

+
+define('DB_HOST',       '');
+define('DB_USERNAME',	'');
+define('DB_PASSWORD', 	'');
+define('DB_DATABASE', 	'');
+
+

Next step is to open terminal and login to MySql as root by executing following command:

+
+root@kali:# mysql -u root -p
+Enter password:
+Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+mysql>
+
+

If you didn't create database before, create it now by executing following command:

+
+mysql> create database ;
+Query OK, 1 row affected (0.01 sec)
+
+

Now create new user:

+
+mysql> CREATE USER ''@'' IDENTIFIED BY '';
+Query OK, 0 rows affected (0.00 sec)
+
+

Give the newly created user privileges for database :

+
+mysql> GRANT ALL PRIVILEGES ON .* TO ''@'';
+Query OK, 0 rows affected (0.01 sec)
+
+

Finally quit MySql:

+
+mysql> exit
+Bye
+
\ No newline at end of file diff --git a/includes/html/db-tuning.html b/includes/html/db-tuning.html new file mode 100644 index 0000000..e40eab5 --- /dev/null +++ b/includes/html/db-tuning.html @@ -0,0 +1,34 @@ +
+

MySql fine tunning

+

Masscan WEB UI use Full Text Search. The minimum length of words to be indexed is defined by the variable ft_min_word_len.

+

Variable must be set at server startup time. A server restart is required for the change to take effect and variable cannot be modified while the server is running.

+

Default value for ft_min_word_len is 4 and you probably need smaller value, 2 or even 1.

+
+

To change this variable, open MySql configuration file named my.cnf and change the value to the smaller one.

+

On Linux my.cnf is usually located in /etc/my.cnf, so to edit file type in terminal as root:

+
+root@kali:~# nano /etc/my.cnf
+
+

Find [mysqld] section in my.cnf and add/change variable=value pair to look something like this:

+
+[mysqld]
+ft_min_word_len=2
+
+

Restart MySql server by executing following command:

+
+root@kali:~# service mysql restart
+
+
+

If your database is not empty, you should rebuild your FULLTEXT indexes for the change to take effect.

+

For rebuilding FULLTEXT indexes, open terminal, log in into MySql as root, select appropriate database and execute REPAIR TABLE command.

+

That should be looking similar to this:

+
+root@kali:~# mysql -u root -p
+Enter password:
+Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+mysql>use ;
+Database changed
+mysql>REPAIR TABLE data QUICK;
+
+

Doing that you are done with fine tuning of MySql.

+
\ No newline at end of file diff --git a/includes/html/delete-files-help.html b/includes/html/delete-files-help.html new file mode 100644 index 0000000..867767d --- /dev/null +++ b/includes/html/delete-files-help.html @@ -0,0 +1,4 @@ +

Lastly, not required, but recommended is to delete files which are not used after install is completed.

+
+root@kali:# rm db-structure.sql index.html README.md
+
\ No newline at end of file diff --git a/includes/html/import-help.html b/includes/html/import-help.html new file mode 100644 index 0000000..4b544e8 --- /dev/null +++ b/includes/html/import-help.html @@ -0,0 +1,35 @@ +

Now you can use masscan to scan your targets, while specifying an XML output. More information about banner grabbing with masscan can be found at https://github.com/robertdavidgraham/masscan#banner-checking.

+
+masscan 10.0.0.0/8 -p80,21,53 --banners --source-ip 10.0.0.2 --max-rate 1000000 -oX scan-01.xml
+
+

Now let's import some scan results. In this example we imported the results of two class A scans:

+
+root@kali:/var/www/html# ls -l scan*
+-rw-r--r-- 1 root root 212929324 Dec  1 13:23 scan-01.xml
+-rw-r--r-- 1 root root 700816226 Dec  1 13:55 scan-02.xml
+root@kali:/var/www/html# php import.php scan-01.xml
+
+Do you want to clear the database before importing (yes/no)?: yes
+
+Clearing the db
+Reading file
+Parsing file
+Processing data (This may take some time depending on file size)
+
+Summary:
+Total records:738279
+Inserted records:738279
+Took about:3 minutes,18 seconds
+root@kali:/var/www/html# php import.php scan-02.xml
+
+Do you want to clear the database before importing (yes/no)?: no
+Reading file
+Parsing file
+Processing data (This may take some time depending on file size)
+
+Summary:
+Total records:2411974
+Inserted records:2411974
+Took about:9 minutes,41 seconds
+root@kali:/var/www/html#
+
\ No newline at end of file diff --git a/includes/install.php b/includes/install.php new file mode 100644 index 0000000..901be66 --- /dev/null +++ b/includes/install.php @@ -0,0 +1,60 @@ + +
+
+
+
+

Installing db tables

+

Installer will try to automatically execute required db queries for creating necessary tables.

+ +

Installation failed, queries not executed.

+

To manually install required tables, open terminal and go to the document root by executing following command:

+
+root@kali:~# cd 
+                            
+

To execute necessary queries, execute following command:

+
+root@kali:# mysql -u  -p  < db-structure.sql
+
+

You will be asked for MySql password. Enter password and if all went well, refresh the page by clicking here.

+ +

Installation completed, queries executed successfully.

+ + +

MASSCAN Web UI is ready for use. Refresh this page by pressing F5 or clicking here to start.

+ +

Installer can not find file db-structure.sql in and can not create necessary db tables.

+

Check our Github page for latest source and help.

+ +

File db-structure.sql in is not readable and installer can not execute required queries.

+

Make it readable and refresh page by clicking here to try again.

+ +
+
+
+
+ - 0):?>
diff --git a/includes/setup.php b/includes/setup.php new file mode 100644 index 0000000..bb67215 --- /dev/null +++ b/includes/setup.php @@ -0,0 +1,58 @@ + +
+
+
+
+

Setup MASSCAN WEB UI

+

It's easy and fast. Just follow instructions and setup will be done in a few minutes.

+

Open terminal and go to the document root of application by typing:

+
+root@kali:~# cd 
+
+

Edit config.php and update the file with MySql host, user, password and database information. Type:

+
+root@kali:# nano config.php
+
+

and change the default values if necessary:

+
+define('DB_HOST',       '');
+define('DB_USERNAME',	'');
+define('DB_PASSWORD', 	'');
+define('DB_DATABASE', 	'');
+
+

If you change default database params in config.php before you continue with setup, in order for the changes to take effect refresh this page (press F5 or click here) and you will have updated all commands later in this page.

+

Next step is to login to MySql as root by executing following command:

+
+root@kali:# mysql -u root -p
+Enter password:
+Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+mysql>
+
+

Create the database by executing following command:

+
+mysql> create database ;
+Query OK, 1 row affected (0.01 sec)
+
+

Now create new user:

+
+mysql> CREATE USER ''@'' IDENTIFIED BY '';
+Query OK, 0 rows affected (0.00 sec)
+
+

Give the newly created user privileges for database :

+
+mysql> GRANT ALL PRIVILEGES ON .* TO ''@'';
+Query OK, 0 rows affected (0.01 sec)
+
+

Finally quit MySql by typing:

+
+mysql> exit
+Bye
+
+

and you are done.

+

When you finished with all the above, you can continue with installation by pressing F5 or clicking here.

+ +
+
+
+
+ + +

How to import data? Click here for more info.

+
diff --git a/lib/class.db.php b/lib/class.db.php index 921e612..96d446d 100755 --- a/lib/class.db.php +++ b/lib/class.db.php @@ -113,12 +113,16 @@ public static function execute($q) * @return bool true on success otherwise false * */ - public static function query($q) + public static function query($q, $throwException = true) { try { return self::getInstance()->_Driver->query($q); } catch (DBException $e) { - $e->handleError(); + if ($throwException): + $e->handleError(); + else: + return false; + endif; } } diff --git a/lib/exceptions/class.common.exception.php b/lib/exceptions/class.common.exception.php index ad52f75..369ddb6 100755 --- a/lib/exceptions/class.common.exception.php +++ b/lib/exceptions/class.common.exception.php @@ -21,5 +21,4 @@ public function flowError() { } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/lib/exceptions/class.db.exception.php b/lib/exceptions/class.db.exception.php index c367e7c..a1a204d 100755 --- a/lib/exceptions/class.db.exception.php +++ b/lib/exceptions/class.db.exception.php @@ -3,8 +3,17 @@ class DBException extends Exception { public function handleError() { - include DOC_ROOT.'includes//error.php'; + if (substr(php_sapi_name(), 0, 3) == 'cli'): + echo $this->getMessage(); + die; + endif; + if (preg_match('/^Table (.*) doesn\'t exist/', $this->getMessage())): + include DOC_ROOT.'includes/install.php'; + elseif(preg_match('/^(.*)Access denied for user (.*)/s', $this->getMessage())): + include DOC_ROOT.'includes/setup.php'; + else: + include DOC_ROOT.'includes/error.php'; + endif; die; } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/lib/mysql/class.mysql.php b/lib/mysql/class.mysql.php index edf5b18..0b1ba22 100755 --- a/lib/mysql/class.mysql.php +++ b/lib/mysql/class.mysql.php @@ -15,7 +15,7 @@ public function __construct() try { $this->_con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); if (!$this->_con) { - throw new DBException('Problem with connection to the mysql server.
Error message: '.mysqli_connect_error()); + throw new DBException("Problem with connection to the mysql server.
Error message: ".mysqli_connect_error().""); } if (!mysqli_select_db($this->_con, DB_DATABASE)) { throw new DBException('Database '.DB_DATABASE.' not found!!'); @@ -34,12 +34,12 @@ private function executeQuery($q) if (empty($q)) { throw new DBException('Empty query submitted!'); } - if (DB_DEBUG): + if (defined('DB_DEBUG') && DB_DEBUG): $start = microtime(true); endif; $this->_res_resource = mysqli_query($this->_con, $q); - if (DB_DEBUG): + if (defined('DB_DEBUG') && DB_DEBUG): $end = microtime(true); $this->_executedQueries[] = array( 'q' => $q, 'time' => $end-$start); @@ -57,7 +57,6 @@ private function executeQuery($q) else{ $this->_affected_rows = @mysqli_affected_rows($this->_con); } - return true; }