Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Thursday, September 16, 2010

UDOM : Transcript Code

Here is the source for what we did yesterday. You will also find the database dump. 

Please post any question here so that we can all share.

Sunday, August 22, 2010

MySQL Injection for Beginners - Part 1/2

SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on your database.
SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks.

Example
The situation is that we have to validate users by their username , and you have PHP code to handle the login as shown below, we will look at difference input and the resulting queries.
$username = $_POST['username']
$query = "SELECT * FROM users WHERE username = '$username'" ;
Normal Users: Username: eferuzi This will result to the $query of 
SELECT * FROM users WHERE username = 'eferuzi' AND password='mypassword'
Injection Users: Username: ' or 1  This will result to the $query of 
SELECT * FROM users WHERE username = '' or 1=1
The injection attack has actually made our query behave differently than we intended. By using a single quote (') they have ended the string part of our MySQL query,  and OR clause of 1 will always be true and so every single entry in the "users" table would be selected by this statement!
The above example displayed a situation where an attacker could possibly get access to a lot of information they shouldn't have, the attacks can be a lot worse. For example an attacker could empty out a table by executing a DROP statement.


Injection Users: Username: '; DROP TABLE users;  This will result to the $query of 
SELECT * FROM users WHERE username = ''; DROP TABLE users;
The effect of last example can be only be imagined.



Next: MySQL Injection for Beginners Part 2/2- Preventing SQL injection





Wednesday, August 18, 2010

MariaDB - an alternative to MySQL

After Oracle bought Sun, I started wondering what would happen to our dear RDBMS called MySQL. So I started digging around and reading blogs about other developers that had the same concern as mine. And lo and behold I came across MariaDB.


MariaDB is a backward compatible, drop-in replacement of the MySQL® Database Server. It includes all major open source storage engines.
So what is really different about MariaDB? I needed to convince myself that I should change from MySQL to MariaDB. So I started reading about its features and I must say I like what I have read. So here are a few things I have found out:-
  •  More Storage Engine
    • Aria
    • XtraDB (drop-in replacement for InnoDB)
    • PBXT
    • FederatedX (drop-in replacement for Federated)
    • OQGRAPH
    • SphinxSE
  • Speed improvements
  • Better Testing
  • Fewer warnings and bugs
The idea is to make MariaDB a full drop in replacement for MySQL, which means:
  • From the user standpoint, things should be the as before, except that there are some new commands and things should be faster and more reliable.
  • Only that package name is different; All filenames, binaries, paths, ports, sockets etc should be the same.
  • Client libraries are binary compatible.
  • Data and table definition files (.frm) files are binary compatible.
  • Command should work the same.

Try it and give me some feed back.





Sunday, November 22, 2009

kiGM : A Terminology Tool




To explain kiGM one has to start with GlossMaster. GlossMaster is the fabulous multi-lingual terminology tool developed for ANLoc, the African Network for Localization. kiGM is a very lightweght version GlossMaster with an aim of allowing user with low or no internet connection to work and sycn data with GlossMaster periodically.GlossMaster. kiGM has a verys small subset of the functionality that Glossmaster.

Please come in and help.


Monday, October 5, 2009

Backup with mysqldump with PHP

Have you ever wanted to create a script a script that will create a mysqldump of a database using PHP? Here is a good starting point. More can be done to extend this to make it more useful, things like emailing the dump, restoring the database on fly and so much more.

There is a minor difference between the script for a server running on MS Windows as compate to the Linux/UNIX

MS Windows: XAMMP or WAMP

/* variable declaration */
$db_user = "yourUsername";
$db_password = "yourPassword";
$db_database = "yourDatabaseName";
$db_server = "yourHostName"; //default: localhost
$backup_path = "C:\\path\\to\\backup\\folder\\";
//e.g $backup_path = "C:\\backups\\sqldumps\\";
$path_to_mysqldump = "C:\\path\\to\\mysql\\bin\\";
//e.g $path_to_mysqldump = "C:\\xampp\\mysql\\bin\\";
$filename = "backup".date("YmdHis").".sql"; //filename with a timestamp

/*construction the command to be run */
$command= "$path_to_mysqldump\\mysqldump.exe --add-drop-table --add-drop-database -h $db_server -u $db_user --password=$db_password $db_database > $filename ";

/* excution of the command */
exec($command, $dump, $status);

/*checking the status of the command after runing */
if($status!=0){
echo "The execution was not successful. An empty file has been created";
}else{
echo "The execution was successful. Backup files is " . $backup_path.$filename ;
}

Linux/UNIX
* variable declaration */
$db_user = "yourUsername";
$db_password = "yourPassword";
$db_database = "yourDatabaseName";
$db_server = "yourHostName"; //default: localhost
$backup_path = "/path/to/backup/folder/"; //you must have permission to write in this folder
//e.g $backup_path = "/servers/backups/sqldumps/";
$filename = $backup_path."backup".date("YmdHis").".sql"; //filename with a timestamp

/*construction the command to be run */
$command= "mysqldump.exe --add-drop-table --add-drop-database -h $db_server -u $db_user --password=$db_password $db_database > $filename ";

/* excution of the command */
exec($command, $dump, $status);

/*checking the status of the command after runing */
if($status!=0){
echo "The execution was not successful. An empty file has been created";
}else{
echo "The execution was successful. Backup files is " . $backup_path.$filename ;
}

Differences highlighted:
  • in windows it, unless you have added the mysql bin to the path, you must specify the full path to the mysqldump.exe, as in Linux it accessible with out the full path
  • also the \\ used in the path, as in Linux we use /
  • in Linux remember you mush have write asses to the folder you are

Afrigator