· 8 years ago · Jun 19, 2018, 11:00 AM
1#Setting up LAMP stack in server(D9b)
2
3#=>=>1.Installing MariaDB(MySQL)
4apt install mariadb-client mariadb-server
5
6#Log in as your root user and set up a regular user and a database.
7mysql -u root -p
8 passwd
9
10#Creating a database
11CREATE DATABASE newdb;
12
13#creates a regular user that can sign in locally and set that user's password.
14#It is an absolutely terrible idea to use the root user for anything other than managing MariaDB as a whole.
15CREATE USER 'username'@'localhost' IDENTIFIED BY 'userpassword';
16
17#In order for that user to be able to use the database that you just created, you need to grant them privileges on it.
18GRANT ALL PRIVILEGES ON newdb.* to 'username'@'localhost';
19
20#Once that's done, flush all privileges from the console and exit.
21FLUSH PRIVILEGES;
22quit
23
24#=>=>2.Installing PHP
25apt install php7.0 php7.0-mysql
26
27#=>=>3.Installing Apache
28apt install apache2 libapache2-mod-php7.0
29
30#=>=>4.Testing Your Server
31#Open up your browser and type in localhost in your address bar. If you aren't doing this locally, type your domain name or IP. You should see a long table containing information about your PHP install.
32By default, Apache will server the contents of /var/www/html and will look first for a file called index.php or index.html. Create that file, and place the following line of code in it.
33 <?php phpinfo(); ?>
34
35#To setup PHPmyAdmin in linux server(D9b)
36apt install phpmyadmin
37
38# To access PHPmyAdmin site
39localhost/phpmyadmin
40http://10.0.0.235/phpmyadmin/
41phpmyadmin
42passwd
43
44
45#How To Create a SSL Certificate on Apache for Debian 8
46
47#https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-debian-8
48
49#To install openssl
50apt-get upgrade openssl
51
52#To check for modules which are enabled.
53apache2ctl -M
54
55#To enable openssl in Apache2
56a2enmod ssl
57apache2ctl -M | grep ssl
58 ssl_module (shared)
59
60#The default Apache website comes with a useful template for enabling SSL, so we will activate the default website now.
61a2ensite default-ssl
62
63#Restart Apache to put these changes into effect.
64systemctl reload apache2
65
66apt-get install net-tools
67netstat -antulp
68
69#Create a Self-Signed SSL Certificate
70#First, let's create a new directory where we can store the private key and certificate.
71
72mkdir /etc/apache2/ssl
73
74openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
75Generating a 2048 bit RSA private key
76....+++
77...........................................................................................................+++
78writing new private key to '/etc/apache2/ssl/apache.key'
79-----
80You are about to be asked to enter information that will be incorporated
81into your certificate request.
82What you are about to enter is what is called a Distinguished Name or a DN.
83There are quite a few fields but you can leave some blank
84For some fields there will be a default value,
85If you enter '.', the field will be left blank.
86-----
87Country Name (2 letter code) [AU]:IN
88State or Province Name (full name) [Some-State]:TAMIL NADU
89Locality Name (eg, city) []:CHENNAI
90Organization Name (eg, company) [Internet Widgits Pty Ltd]:LABInc
91Organizational Unit Name (eg, section) []:PROXMOX_VM
92Common Name (e.g. server FQDN or YOUR name) []:debian9b.lab.com
93Email Address []:SomeEmailID@gmail.com
94
95#Set the file permissions to protect your private key and certificate.
96chmod 600 /etc/apache2/ssl/*
97
98#Configure Apache to Use SSL
99
100nano /etc/apache2/sites-enabled/default-ssl.conf
101<IfModule mod_ssl.c>
102 <VirtualHost _default_:443>
103 ServerAdmin webmaster@localhost
104 ServerName example.com:443
105 DocumentRoot /var/www/html
106
107 . . .
108 SSLEngine on
109
110 . . .
111
112 SSLCertificateFile /etc/apache2/ssl/apache.crt
113 SSLCertificateKeyFile /etc/apache2/ssl/apache.key
114systemctl reload apache2
115
116openssl s_client -connect debian9b.lab.com:443
117
118
119# http://manintheit.org/security/ssl-client-certificate-authentication-with-apache/
120
121#Creating CA Certificate
122mkdir /etc/ssl/mycaANDcerts
123
124#We use this certificate for only signing certificates that we use for the clients and our web servers. It should be kept very secure. If it is disclosed other certificates signed with this certificate will be disclosed as well.
125openssl genrsa -des3 -out ca.key 4096
126#Enter pass phrase for ca.key: passwd
127#Verifying - Enter pass phrase for ca.key: passwd
128# This will give us an encrypted ca.key which is protected.
129# To get unencrypted key use this next command however it is not needed.
130openssl rsa -in ca.key -out ca_decrypted.key
131Enter pass phrase 'for' ca.key:
132writing RSA key
133
134#Creating crt file
135openssl req -new -x509 -days 365 -key ca.key -out ca.crt
136#Enter pass phrase for ca.key: passwd
137#You are about to be asked to enter information that will be incorporated
138#into your certificate request.
139#What you are about to enter is what is called a Distinguished Name or a DN.
140#There are quite a few fields but you can leave some blank
141#For some fields there will be a default value,
142#If you enter '.', the field will be left blank.
143-----
144Country Name (2 letter code) [AU]:IN
145State or Province Name (full name) [Some-State]:TAMIL NADU
146Locality Name (eg, city) []:CHENNAI
147Organization Name (eg, company) [Internet Widgits Pty Ltd]:LABInc
148Organizational Unit Name (eg, section) []:PROXMOX_VM
149Common Name (e.g. server FQDN or YOUR name) []:ca.lab.com
150Email Address []:SomeEmailID@gmail.com
151
152# Use the following command to inspect what is inside the ca.crt file.
153openssl x509 -in ca.crt -text -noout
154
155#Creating a Key and CSR for the Client
156#Creating a client certificate is the same as creating Server certificate.
157openssl req -newkey rsa:2048 -nodes -keyout client.key -out client.csr
158
159Generating a 2048 bit RSA private key
160....................................+++
161...............................................+++
162writing new private key to 'client.key'
163-----
164#You are about to be asked to enter information that will be incorporated
165#into your certificate request.
166#What you are about to enter is what is called a Distinguished Name or a DN.
167#There are quite a few fields but you can leave some blank
168#For some fields there will be a default value,
169#If you enter '.', the field will be left blank.
170-----
171Country Name (2 letter code) [AU]:IN
172State or Province Name (full name) [Some-State]:TAMIL NADU
173Locality Name (eg, city) []:CHENNAI
174Organization Name (eg, company) [Internet Widgits Pty Ltd]:LABInc
175Organizational Unit Name (eg, section) []:PROXMOX_VM
176Common Name (e.g. server FQDN or YOUR name) []:debian9a.lab.com
177Email Address []:SomeEmailID@gmail.com
178Please enter the following 'extra' attributes
179to be sent with your certificate request
180A challenge password []:
181An optional company name []:
182
183# To see what is in the client.csr file use this command don't use the X509 like we did for ca.crt
184openssl req -in client.csr -noout -text
185
186#Signing the client certificate with previously created CA.
187
188#Not: Do not forget to change serial each time you sign new certificate, otherwise may get serial conflict error in the web browsers.
189openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 02 -out client.crt
190Signature ok
191subject=/C=TR/L=Default City/O=Client Certificate/CN=Client Certificate
192Getting CA Private Key
193#Enter pass phrase for ca.key
194
195#To Check what is inside the crt file which got generated just now we can take a look at debian9a.crt.
196openssl x509 -in debian9a.crt --noout -text
197
198#Creating a Key and CSR for the Server(Apache Virtual Host ankara.example.com)
199openssl req -newkey rsa:2048 -nodes -keyout debian9b.key -out debian9b.csr
200
201#Signing Server Certificate with previously created CA.
202#Do not forget to change serial number. As it may conflict with existing one.
203openssl x509 -req -days 365 -in debian9b.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out debian9b.crt
204
205#Apache Configuration for the Authentication with Client Certificate
206
207#This sample configuration shows how to force server to request client certificate.
208<Directory /srv/ankara/www>
209 Require all granted
210</Directory>
211
212
213<VirtualHost *:443>
214 SSLEngine On
215 SSLCertificateFile /etc/httpd/conf.d/certs/ankara.crt
216 SSLCertificateKeyFile /etc/httpd/conf.d/certs/ankara.key
217 ServerName ankara.example.com
218 DocumentRoot /srv/ankara/www
219 SSLVerifyClient require
220 SSLVerifyDepth 5
221 SSLCACertificateFile "/etc/httpd/conf.d/certs/ca.crt"
222</VirtualHost>
223
224#The depth actually is the maximum number of intermediate certificate issuers, i.e. the number of CA certificates which are max allowed to be followed while verifying the client certificate. A depth of 0 means that self-signed client certificates are accepted only, the default depth of 1 means the client certificate can be self-signed or has to be signed by a CA which is directly known to the server (i.e. the CA’s certificate is under SSLCACertificatePath), etc.
225#Reference: https://httpd.apache.org/docs/2.4/mod/mod_ssl.html
226
227#Experimenting with Curl
228
229# Without specifying the client certificate
230curl https://ankara.example.com -v
231* Rebuilt URL to: https://ankara.example.com/
232* Trying 192.168.122.30...
233* Connected to ankara.example.com (192.168.122.30) port 443 (#0)
234* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
235* found 597 certificates in /etc/ssl/certs
236* ALPN, offering http/1.1
237* gnutls_handshake() failed: Handshake failed
238* Closing connection 0
239curl: (35) gnutls_handshake() failed: Handshake failed
240
241# With client certificate
242gokay@ankara:~/certs$ curl https://ankara.example.com --key client.key --cert client.crt --cacert ca.crt -v
243* Rebuilt URL to: https://ankara.example.com/
244* Trying 192.168.122.30...
245* Connected to ankara.example.com (192.168.122.30) port 443 (#0)
246* found 1 certificates in ca.crt
247* found 597 certificates in /etc/ssl/certs
248* ALPN, offering http/1.1
249* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
250* server certificate verification OK
251* server certificate status verification SKIPPED
252* common name: ankara.example.com (matched)
253* server certificate expiration date OK
254* server certificate activation date OK
255* certificate public key: RSA
256* certificate version: #1
257* subject: C=TR,L=Default City,O=Ankara LTD,CN=ankara.example.com
258* start date: Sun, 24 Dec 2017 10:00:20 GMT
259* expire date: Mon, 24 Dec 2018 10:00:20 GMT
260* issuer: C=TR,L=Default City,O=BlueTech CA,OU=CA,CN=BlueTech CA
261* compression: NULL
262* ALPN, server did not agree to a protocol
263> GET / HTTP/1.1
264> Host: ankara.example.com
265> User-Agent: curl/7.47.0
266> Accept: */*
267>
268< HTTP/1.1 200 OK
269< Date: Sun, 24 Dec 2017 10:21:15 GMT
270< Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
271< Last-Modified: Sun, 24 Dec 2017 10:19:51 GMT
272< ETag: "3b-5611363e4a8e0"
273< Accept-Ranges: bytes
274< Content-Length: 59
275< Content-Type: text/html; charset=UTF-8
276<
277<h1>My Secure Page Ankara</h1>
278<h2>ankara.example.com</h2>
279* Connection #0 to host ankara.example.com left intact
280
281openssl req -newkey rsa:2048 -nodes -keyout isoc.key -out isoc.csr
282Generating a 2048 bit RSA private key
283..............................................+++
284....................................................................................................................................................+++
285writing new private key to 'isoc.key'
286-----
287You are about to be asked to enter information that will be incorporated
288into your certificate request.
289What you are about to enter is what is called a Distinguished Name or a DN.
290There are quite a few fields but you can leave some blank
291For some fields there will be a default value,
292If you enter '.', the field will be left blank.
293-----
294Country Name (2 letter code) [AU]:IN
295State or Province Name (full name) [Some-State]:TAMIL NADU
296Locality Name (eg, city) []:CHENNAI
297Organization Name (eg, company) [Internet Widgits Pty Ltd]:LABInc
298Organizational Unit Name (eg, section) []:PROMOX_VM
299Common Name (e.g. server FQDN or YOUR name) []:isoc-ThinkCentre-M92P.lab.com
300Email Address []:SomeEmailID@gmail.com
301
302Please enter the following 'extra' attributes
303to be sent with your certificate request
304A challenge password []:
305An optional company name []:
306
307
308#Converting certificate and to pkcs12 format
309#If you want to import a certificate to a web browser, you have to convert your existing certificate other than PEM format. For the Mozilla Firefox, you need to convert it to pkcs12 format.
310openssl pkcs12 -export -out isoc.pfx -inkey isoc.key -in isoc.crt -certfile ca.crt
311
312#Only thing we need to do it import ankara.pfx to our browser.
313
314
315https://stackoverflow.com/questions/16200501/http-to-https-apache-redirection
316# Change the file 000-default.conf to redirect port to https
317
318vim /etc/apache2/sites-enabled/000-default.conf
319
320NameVirtualHost *:80
321<VirtualHost *:80>
322 ServerName debian9b.lab.com
323 DocumentRoot /var/www/html
324 Redirect permanent / https://debian9b.lab.com/
325</VirtualHost>
326
327
328
32905/06/2018
330
331#Coding first.php (need to be updated)(st,et,ip,loc,date,submit)
332
333<html>
334<body>
335 <title> Pcap Pulling Automation </title>
336 <h1> Pcap Request <h1>
337
338<form method="post" action="">
339 Start time: <input type="text" name="st"><br>
340 End time: <input type="text" name="et"><br>
341 IP Address: <input type="text" name="ip" value = "Eg:10.0.0.125"><br>
342 Location: <select name="loc">
343 <option>9a</option>
344 <option>9b</option>
345 <option>9c</option>
346 <option>9d</option>
347 <option>9e</option>
348 </select><br>
349 date:<input type="date" id="datepicker" name='from' size='9' value="" /><br>
350 <input type="submit" name="sub" value="Submit">
351</form>
352<?php
353
354?>
355</html>
356</body>
357
358#Creating and Manage Databases in MySQL and MariaDB
359CREATE DATABASE pcapinfo;
360
361Query OK, 1 row affected (0.00 sec)
362
363#Viewing Databases
364SHOW DATABASES;
365
366+--------------------+
367| Database |
368+--------------------+
369| information_schema |
370| mysql |
371| new |
372| newdb |
373| pcapinfo |
374| performance_schema |
375| phpmyadmin |
376| testing1 |
377+--------------------+
3788 rows in set (0.00 sec)
379
380#Find out which database is currently selected
381SELECT database();
382
383+------------+
384| database() |
385+------------+
386| NULL |
387+------------+
3881 row in set (0.01 sec)
389
390#Changing Databases
391USE new_database;
392
393Database changed
394
395#We can see that the database has been selected by re-issuing the command we ran previously:
396
397SELECT database();
398
399+--------------+
400| database() |
401+--------------+
402| new_database |
403+--------------+
4041 row in set (0.00 sec)
405
406#Delete a Database
407
408DROP DATABASE new_database;
409
410Query OK, 0 rows affected (0.00 sec)
411
412#Creating a table
413
414CREATE TABLE IF NOT EXISTS info (
415 st int(5) NOT NULL,
416 et int(5) NOT NULL,
417 ip int(5) NOT NULL,
418 loc varchar(20) DEFAULT NULL
419 );
420
421Query OK, 0 rows affected (0.03 sec)
422
423#Defining Columns
424show columns in info;
425
426+-------+-------------+------+-----+---------+-------+
427| Field | Type | Null | Key | Default | Extra |
428+-------+-------------+------+-----+---------+-------+
429| st | int(5) | NO | | NULL | |
430| et | int(5) | NO | | NULL | |
431| ip | int(5) | NO | | NULL | |
432| loc | varchar(20) | NO | | NULL | |
433+-------+-------------+------+-----+---------+-------+
4344 rows in set (0.00 sec)
435
436
437#Inserting Data
438syntax:
439
440INSERT INTO table_name (field1, field2, ...) VALUES (value1, value2, ...);
441
442INSERT INTO info (st, et, ip, loc)
443VALUES
444(11, 12, 15, "del");
445
446
447#To see the information, query the table. The asterisk (*) is a special wildcard character that matches everything.
448 SELECT * FROM info;
449
450+----+----+----+---------+
451| st | et | ip | loc |
452+----+----+----+---------+
453| 11 | 12 | 10 | chennai |
454| 11 | 12 | 15 | del |
455+----+----+----+---------+
4562 rows in set (0.00 sec)
457
458#Deleting a table
459
460DROP TABLE table_name;
461
462
46307/06/2018
464
465#Creating second.php to display the data which is been inputed
466
467<html>
468<body>
469
470The date you have entered is: <?php echo $_POST["datevar"]; ?><br>
471The Start Time is: <?php echo $_POST["st"]; ?><br>
472The End Time is: <?php echo $_POST["et"]; ?><br>
473The IP is: <?php echo $_POST["ip"]; ?><br>
474The Location is: <?php echo $_POST["loc"]; ?>
475
476</body>
477</html>
478
479#Creating test.php to testing connect to db
480
481 <?php
482$servername = "localhost";
483$username = "username";
484$password = "userpassword";
485$DBname = "pcapinfo";
486
487// Create connection
488$conn = mysqli_connect($servername, $username, $password, $DBname);
489
490// Check connection
491if (!$conn) {
492 die("Connection failed: " . mysqli_connect_error());
493}
494else{
495 echo "Connected successfully <br>";
496}
497$sql = "INSERT INTO info (st,et,ip,loc) VALUES ('6:30', '7:30', '10.22.22.22', 'FROMWebPAGE');";
498
499//$sql = "SHOW DATABASES;";
500
501/*if ($conn->mysqli_query($sql) === TRUE) {
502 echo "New record created successfully";
503}
504else {
505 echo "Error: " . $sql . "<br>" . $conn->error;
506}*/
507
508
509if ($result = $mysqli->query($sql)) {
510 printf("Select returned %d rows.\n", $result->num_rows);
511 $result->close();
512}
513
514$conn->close();
515
516?>
517
518#Creating /var/www/html/new/1a.php/ improved connection file
519
520<?php
521$link = mysqli_connect("localhost", "newusername", "userpassword", "database1");
522
523if (!$link) {
524 echo "Error: Unable to connect to MySQL." . PHP_EOL;
525 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
526 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
527 exit;
528}
529
530echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
531echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
532
533echo "NIB 1 <br>";
534
535
536/* return name of current default database */
537if ($result = $link->query("SELECT DATABASE()")) {
538 $row = $result->fetch_row();
539 printf("Default database is %s.\n", $row[0]);
540 $result->close();
541}
542
543echo "<br> NIB 2 <br>";
544
545/* change db to world db */
546$link->select_db("pcapinfo");
547
548/* return name of current default database */
549if ($result = $link->query("SELECT DATABASE()")) {
550 $row = $result->fetch_row();
551 printf("The Changed database is %s.\n", $row[0]);
552 $result->close();
553}
554
555echo "<br> NIB 3 <br>";
556
557/* Select queries return a resultset */
558if ($result = $link->query("SELECT * FROM info")) {
559 printf("Select returned %d rows.\n", $result->num_rows);
560 /* free result set */
561 $result->close();
562}
563
564/* Select queries return a resultset */
565if ($result = $link->query("INSERT INTO info (st,et,ip,loc) VALUES ('6:30', '7:30', '10.22.22.22', 'NIB');")) {
566 /*printf("Select returned %d rows.\n", $result->num_rows);
567 free result set */
568 $result->close();
569}
570mysqli_close($link);
571?>
572
573
574
57511/06/2018
576
577# To Modify table
578MariaDB [pcapinfo]> ALTER TABLE info MODIFY et VARCHAR(30);
579Query OK, 9 rows affected (0.35 sec)
580Records: 9 Duplicates: 0 Warnings: 0
581
582MariaDB [pcapinfo]> SHOW FIELDS FROM info;
583+-------+-------------+------+-----+---------+-------+
584| Field | Type | Null | Key | Default | Extra |
585+-------+-------------+------+-----+---------+-------+
586| st | int(5) | NO | | NULL | |
587| et | varchar(30) | YES | | NULL | |
588| ip | int(5) | NO | | NULL | |
589| loc | varchar(20) | NO | | NULL | |
590+-------+-------------+------+-----+---------+-------+
5914 rows in set (0.00 sec)
592
593MariaDB [pcapinfo]> ALTER TABLE info MODIFY st VARCHAR(30);
594Query OK, 9 rows affected (0.40 sec)
595Records: 9 Duplicates: 0 Warnings: 0
596
597MariaDB [pcapinfo]> ALTER TABLE info MODIFY ip VARCHAR(30);
598Query OK, 9 rows affected (0.25 sec)
599Records: 9 Duplicates: 0 Warnings: 0
600
601MariaDB [pcapinfo]> SHOW FIELDS FROM info;
602+-------+-------------+------+-----+---------+-------+
603| Field | Type | Null | Key | Default | Extra |
604+-------+-------------+------+-----+---------+-------+
605| st | varchar(30) | YES | | NULL | |
606| et | varchar(30) | YES | | NULL | |
607| ip | varchar(30) | YES | | NULL | |
608| loc | varchar(20) | NO | | NULL | |
609+-------+-------------+------+-----+---------+-------+
6104 rows in set (0.00 sec)
611
612ALTER TABLE info ADD COLUMN pcaphash VARCHAR(100) AFTER loc;
613
614
615
616#Second.php (display info, calculate the hash with date-st,et,ip,loc, Establishing a connection, inserting values in the DB)
617<html>
618<body>
619
620<?php
621$datevari=$_POST["datevar"];
622$stime=$_POST["st"];
623//Here I am trying to concate Date and time
624$stime="$datevari" . " $stime";
625$etime=$_POST["et"];
626$etime="$datevari" . " $etime";
627$ipaddr=$_POST["ip"];
628$location=$_POST["loc"];
629
630$pcaphash="$stime" . "$etime" . "$ipaddr" . "$location";
631
632
633echo "The date you have entered is " . $datevari . "<br>";
634echo "The start time is" . $stime . "<br>";
635echo "The end time is" . $etime . "<br>";
636echo "The IP address is" . $ipaddr . "<br>";
637echo "The location is" . $location . "<br>";
638echo "The pcaphash string value is <b>" . $pcaphash . "</b> <br>";
639
640//echo hash('md5', $pcaphash) . "<br>";
641$pcaphash=hash('md5', $pcaphash);
642echo "The pcaphash value is <b>" . $pcaphash . "</b> <br>";
643
644
645echo "<br><br><br>";
646
647
648$link = mysqli_connect("localhost", "newusername", "userpassword", "database1");
649
650if (!$link) {
651 echo "Error: Unable to connect to MySQL." . PHP_EOL;
652 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
653 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
654 exit;
655}
656
657echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
658
659echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
660
661
662/* return name of current default database */
663if ($result = $link->query("SELECT DATABASE()")) {
664 $row = $result->fetch_row();
665 printf("Default database is %s.\n", $row[0]);
666 $result->close();
667}
668
669/* change db to world db */
670$link->select_db("pcapinfo");
671
672/* return name of current default database */
673if ($result = $link->query("SELECT DATABASE()")) {
674 $row = $result->fetch_row();
675 printf("The Changed database is %s.\n", $row[0]);
676 $result->close();
677}
678
679/* Select queries return a resultset */
680if ($result = $link->query("SELECT * FROM info")) {
681 printf("Select returned %d rows.\n", $result->num_rows);
682 /* free result set */
683 $result->close();
684}
685
686//echo "INSERT INTO info VALUES ( \"$stime\", \"$etime\" , \"$ipaddr\", \"$location\");";
687
688$link->query("INSERT INTO info VALUES ( \"$stime\", \"$etime\" , \"$ipaddr\", \"$location\", \"$pcaphash\");");
689
690
691
692/*This will retrieve values from the DB
693
694
695 //$query = "SELECT * from info;";
696
697 echo "======================<br>";
698 //echo "My query is " . $query . "<br>";
699
700 if ($result = $link->query("SELECT * from info")) {
701
702 /* Get field information for all columns */
703 $finfo = $result->fetch_fields()
704
705 echo "My finfo variable is " . $finfo . "<br>";
706 echo "My first index is " . finfo[0] . "<br>"; */
707
708/*
709 //Creates a loop to loop through results
710 while(){
711 //$row['index'] the index here is a field name
712 //echo "<tr><td>" . $row['st'] . "</td><td>" . $row['et'] . "</td><td>" . $row['ip'] . "</td><td>" . $row['loc'] . "</td><td>" . $row['pcaphash'] . "</td></tr>";
713 echo $row["st"];
714 echo $finfo->st;
715 }
716*/
717
718/*
719 foreach ($finfo as $val) {
720 //echo "My val variable is " . $val . "<br>";
721 printf("st: %s", $val->st);
722 printf("et: %s", $val->et);
723 printf("ip: %s", $val->ip);
724 printf("loc: %s", $val->loc);
725 printf("pcaphash: %s", $val->pcaphash);
726 echo "<br>";
727 }
728
729*/
730 $result->free();
731 }
732
733$link->close();
734?>
735</body>
736</html>
737
738
739
740#Tableview.php
741
742<?php
743// Establishing a connection to DB
744$link = mysqli_connect("localhost", "newusername", "userpassword", "pcapinfo");
745
746if (!$link) {
747 echo "Error: Unable to connect to MySQL." . PHP_EOL;
748 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
749 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
750 exit;
751}
752echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
753echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
754
755$sql = 'SELECT * FROM info';
756// mysqli_query(connection,query,resultmode); //performs a query against the database.
757$query = mysqli_query($link, $sql);
758// Creating a table
759echo "<table border=1>";
760echo"<tr>
761<td>Start Time</td>
762<td>End Time</td>
763<td>IP Address</td>
764<td>Location</td>
765<td>Hash Value</td>
766</tr>";
767// mysqli_fetch_array(result,resulttype); //fetches a result row as an associative array, a numeric array, or both.
768while ($row = mysqli_fetch_array($query))
769{
770echo '<tr>
771<td>'.$row['st'].'</td>
772<td>'.$row['et'].'</td>
773<td>'.$row['ip'].'</td>
774<td>'.$row['loc'].'</td>
775<td>'.$row['pcaphash'].'</td>
776</tr>';
777}
778echo "</table>";
779?>
780
781
78212/06/2018
783
784#Adding Downloadable pcap path to the DB
785# Eg: https://debian9b.lab.com/uploads/23b58def11b45727d3351702515f86af.pcap
786#Modified new/second.php line 34 to
787
788$pcaphash="https://debian9b.lab.com/uploads/" . hash('md5', $pcaphash) . ".pcap";
789
790
791
7922018-06-20 0:01 2018-06-20 4:00 10.6.6.6 9a e680710435adc644fc85605ae7177123
7932018-06-20 0:01 2018-06-20 4:00 10.6.6.6 9a e680710435adc644fc85605ae7177123
7942018-06-15 0:10 2018-06-15 7:30 10.0.0.125 9c https://debian9b.lab.com/uploads/c51f81560db969b09fc56f99a08d2ad1.pcap
795
796
797#setting the link to download pcap in tableview.php
798#Print last 50 Entries
799
800<?php
801
802$link = mysqli_connect("localhost", "newusername", "userpassword", "pcapinfo");
803
804if (!$link) {
805 echo "Error: Unable to connect to MySQL." . PHP_EOL;
806 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
807 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
808 exit;
809}
810echo "Success: A proper connection to MySQL was made! The database1 database is great." . PHP_EOL;
811echo "Host information: " . mysqli_get_host_info($link) . "<br>" . PHP_EOL;
812
813echo "NIB 1 <br>";
814$sql = 'SELECT * FROM INFO ORDER BY ID DESC LIMIT 50;';
815echo "sql ok ";
816// mysqli_query(connection,query,resultmode); //performs a query against the database.
817$query = mysqli_query($link, $sql);
818echo "query ok";
819echo "after query";
820echo "<table border=1>";
821echo"<tr>
822<td>Start Time</td>
823<td>End Time</td>
824<td>IP Address</td>
825<td> Location </td>
826<td>Pcap file</td>
827</tr>";
828// mysqli_fetch_array(result,resulttype); //fetches a result row as an associative array, a numeric array, or both.
829while ($row = mysqli_fetch_array($query))
830{
831echo '<tr>
832<td>'.$row['ST'].'</td>
833<td>'.$row['ET'].'</td>
834<td>'.$row['IP'].'</td>
835<td>'.$row['LOC'].'</td>
836<td>'.$row['PCAPHASH'].'</td>
837</tr>';
838
839}
840echo "</table>";
841?>
842
843
844
845#Adding ID to Table (Not needed)
846
847ALTER TABLE info ADD COLUMN ID int NOT NULL PRIMARY KEY FIRST;
848
849
850ALTER TABLE info ADD COLUMN pcaphash VARCHAR(100) AFTER loc;
851
852
853#To add a new column to an existing table, you use the ALTER TABLE ADD COLUMN statement as follows:
854ALTER TABLE table
855ADD [COLUMN] column_name column_definition [FIRST|AFTER existing_column];
856
857Ex:
858ALTER TABLE vendors
859ADD COLUMN phone VARCHAR(15) AFTER name;
860
861#Creating a new table INFO and column ID with auto increment
862
863CREATE TABLE INFO (ID INT NOT NULL AUTO_INCREMENT,ST VARCHAR(30),ET VARCHAR(30),IP VARCHAR(30),LOC VARCHAR(30),PCAPHASH VARCHAR(100),PRIMARY KEY (ID));
864
865
866#working in progress saving data to file.txt
867
86813/06/2018
869
870#To set permission
871
872root@Debian9b:/tmp# ls -ltrh
873total 8.0K
874drwx------ 3 root root 4.0K Jun 1 14:02 systemd-private-05728b53d5b64c4f9c6751171a636c69-apache2.service-BQF1Nn
875-rw-r--r-- 1 www-data www-data 33 Jun 13 10:14 mydata.txt
876root@Debian9b:/tmp# ls -ltrhd /var/www/html/new/tesing/
877drwxr-xr-x 2 root root 4.0K Jun 13 10:14 /var/www/html/new/tesing/
878root@Debian9b:/tmp# chmod 770 /var/www/html/new/tesing/
879root@Debian9b:/tmp# chgrp www-data /var/www/html/new/tesing/
880root@Debian9b:/tmp# ls -ltrhd /var/www/html/new/tesing/
881drwxrwx--- 2 root www-data 4.0K Jun 13 10:14 /var/www/html/new/tesing/
882root@Debian9b:/tmp# chmod 770 /var/www/html/new/tesing/
883
884
885#To create and write the data into .txt file (line 40 /var/www/html/new/second.php)
886#https://stackoverflow.com/questions/14998961/php-write-file-from-input-to-txt
887
888// Writing data into .txt file
889$data = "$stime" . ', ' . "$etime" . ', ' . "$ipaddr" . ', ' . "$location" . ', ' . "$pcaphash" . "\n" ;
890 //file_put_contents opens, writes and closes files for you
891$ret = file_put_contents('/var/www/html/pcapdata.txt', $data, FILE_APPEND | LOCK_EX);
892
893
894#Existing file is overwritten, unless the FILE_APPEND flag is set.
895// Writing to text file
896$data = "$stime" . ', ' . "$etime" . ', ' . "$ipaddr" . ', ' . "$location" . ', ' . "$pcaphash" . "\n" ;
897 //file_put_contents opens, writes and closes files for you
898$ret = file_put_contents('/var/www/html/pcapdata.txt', $data, LOCK_EX);