Unix System Administration

Slides:



Advertisements
Similar presentations
Module XIV SQL Injection
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Keys, Referential Integrity and PHP One to Many on the Web.
Objectives Connect to MySQL from PHP
ADVM420- Class #4 Web Design with PHP and MySQL Adding and Listing from a MySQL Database.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
PHP-MySQL By Jonathan Foss. PHP and MySQL Server Web Browser Apache PHP file PHP MySQL Client Recall the PHP architecture PHP can communicate with a MySQL.
Check That Input Preventing SQL Injection Attacks By Andrew Morton For CS 410.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
MIS Week 11 Site:
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
Session 5: Working with MySQL iNET Academy Open Source Web Development.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
INTERNET APPLICATION DEVELOPMENT For More visit:
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
(CPSC620) Sanjay Tibile Vinay Deore. Agenda  Database and SQL  What is SQL Injection?  Types  Example of attack  Prevention  References.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Nic Shulver, Retrieving Stored Data Introduction This set of slides shows: The information source database structure The data.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
PHP MySQL. SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
PHP Part 2.
Lecture 10 – MYSQL and PHP (Part 2)
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
1 IT420: Database Management and Organization Database Security 5 April 2006 Adina Crăiniceanu
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Sumanth M Ganesh B CPSC 620.  SQL Injection attacks allow a malicious individual to execute arbitrary SQL code on your server  The attack could involve.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Enterprise PHP – Reading Data from a DB Reading Data from a relational database in PHP Nic Shulver, FCES, Staffordshire University Using the SQLi interface.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Slide Set #24: Database security SY306 Web and Databases for Cyber Operations.
SQL INJECTION Diwakar Kumar Dinkar M.Tech, CS&E Roll Diwakar Kumar Dinkar M.Tech, CS&E Roll
CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.
Web Systems & Technologies
Database System Implementation CSE 507
Databases.
Introduction to Dynamic Web Programming
WEB APPLICATION TESTING
CS320 Web and Internet Programming SQL and MySQL
Unix System Administration
Open Source Server Side Scripting Permissions & Users
Unix System Administration
Web Design and Development
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Introduction to Web programming
MySQL tutorial.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
Tutorial 6 PHP & MySQL Li Xu
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Introduction to Web programming
Presentation transcript:

Unix System Administration Chris Schenk Lecture 19 – Tuesday Mar 18 CSCI 4113, Spring 2008

SQL Meta Queries Stuff for creating DBs/tables, altering tables Create a database; CREATE DATABASE <db>; Create a table CREATE TABLE <table>; Alter an existing table ALTER TABLE <table> ADD <column> <type>; Drop a table or database DROP TABLE <table>; DROP DATABASE <db>;

Creating Users Easiest way to create users is to first create a database and add users to it CREATE DATABASE mydb; Users added with the 'GRANT' command GRANT ALL PRIVILEGES ON <db>.<tables> TO '<user>'@'<host>'; GRANT ALL PRIVILEGES ON mydb.* to 'chris'@'localhost' Host is where the user can connect FROM!

Sample Database CREATE DATABASE login_monitor; USE login_monitor; Tell MySQL that we're modifying this database Create a table for tracking user logins CREATE TABLE logins ( id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(20), ip VARCHAR(15), time TIMESTAMP DEFAULT 0); Insert some data into it: INSERT INTO logins (username, ip, time) VALUES ('chris', '128.138.242.249', NOW());

Viewing Sample Data Select the information out of the 'logins' table mysql> SELECT * FROM logins; +----+----------+-----------------+---------------------+ | id | username | ip | time | +----+----------+-----------------+---------------------+ | 1 | chris | 128.138.242.249 | 2008-03-12 22:36:09 | +----+----------+-----------------+---------------------+ 1 row in set (0.00 sec) Select a specific column mysql> SELECT username FROM logins; +----------+ | username | +----------+ | chris | +----------+ 1 row in set (0.00 sec)

Selecting Specific Data Let's add one more row: INSERT INTO logins (username, ip, time) VALUES ('root', '128.138.242.249', NOW()); Select only root: mysql> SELECT * FROM logins WHERE username='root'; +----+----------+-----------------+---------------------+ | id | username | ip | time | +----+----------+-----------------+---------------------+ | 2 | root | 128.138.242.249 | 2008-03-12 22:41:44 | +----+----------+-----------------+---------------------+ 1 row in set (0.00 sec) Select IP 128.138.242.249: mysql> SELECT * FROM logins WHERE ip='128.138.242.249'; +----+----------+-----------------+---------------------+ | id | username | ip | time | +----+----------+-----------------+---------------------+ | 1 | chris | 128.138.242.249 | 2008-03-12 22:36:09 | | 2 | root | 128.138.242.249 | 2008-03-12 22:41:44 | +----+----------+-----------------+---------------------+ 2 rows in set (0.00 sec)

PHP + MySQL Don't know how to connect to MySQL in PHP? Google it! Except there's lots of bad code out there like I said Pretty easy to connect, query, and close $resource = mysql_connect($host, $user, $pass); mysql_select_db($db); $results = mysql_query(“select * from logins”); while($row = mysql_fetch_assoc($results)) { print “User: “.$row['username']; print “, IP: “.$row['ip'].”\n”; } mysql_close(); All of this requires packages php5-cli and php5-mysql Web version simply uses HTML to format

Selecting Data from User Input Let's say we want to let users login to a page Simple username/password combo We have a 'users' table with following columns: Username, password, emailaddress Ignore the fact that the password is plain- text To perform a login, we simply create a query: $query = “SELECT * FROM users WHERE username='$username' AND password='$password'”; We run the query with mysql_query($query);

SQL Injection Part of the SANS Top 20 Vulnerabilities list http://www.sans.org/top20/#s1 SQL Injection attack by white-hat hackers http://www.unixwiz.net/techtips/sql- injection.html SQL Injection cheat-sheet http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/ Thousands of web servers are vulnerable Poorly written applications will allow access to data within the database because of lack of input sanitization on web pages

Preventing SQL Injection Very, very simple ways to mitigate injection Do any of the following: Check input fields for valid input Characters and length (maybe with regex) Use prepared statements Inputs cannot modify the query itself Use stored procedures Even better than prepared statements, eliminates writing actual SQL queries! Notify admins on query syntax errors Error reporting on the application itself

PHP Prepared Statements We have to convert our mysql code to mysqli Newer, better library in php5 Object oriented, must keep track of our connection within a variable ($conn in the example) Three extra function calls required $stmt = mysqli_prepare($conn, $query); mysqli_stmt_bind_param($stmt, ...)' mysqli_stmt_execute($stmt); Prepared statements effectively prevent your code from being susceptible to SQL injection