SQL Injection

Many web developers are unaware of how SQL queries can be tampered with, and assume that an SQL query is a trusted command. It means that SQL queries are able to circumvent access controls, thereby bypassing standard authentication and authorization checks, and sometimes SQL queries even may allow access to host operating system level commands.

Direct SQL Command Injection is a technique where an attacker creates or alters existing SQL commands to expose hidden data, or to override valuable ones, or even to execute dangerous system level commands on the database host. This is accomplished by the application taking user input and combining it with static parameters to build a SQL query. The following examples are based on true stories, unfortunately.

Owing to the lack of input validation and connecting to the database on behalf of a superuser or the one who can create users, the attacker may create a superuser in your database.

Example 27-2. Splitting the result set into pages ... and making superusers (PostgreSQL)

<?php

$offset
= $argv[0]; // beware, no input validation!
$query  = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;";
$result = pg_query($conn, $query);

?>
Normal users click on the 'next', 'prev' links where the $offset is encoded into the URL. The script expects that the incoming $offset is a decimal number. However, what if someone tries to break in by appending a urlencode()'d form of the following to the URL

0;
insert into pg_shadow(usename,usesysid,usesuper,usecatupd,passwd)
    select 'crack', usesysid, 't','t','crack'
    from pg_shadow where usename='postgres';
--

If it happened, then the script would present a superuser access to him. Note that 0; is to supply a valid offset to the original query and to terminate it.

Note: It is common technique to force the SQL parser to ignore the rest of the query written by the developer with -- which is the comment sign in SQL.

A feasible way to gain passwords is to circumvent your search result pages. The only thing the attacker needs to do is to see if there are any submitted variables used in SQL statements which are not handled properly. These filters can be set commonly in a preceding form to customize WHERE, ORDER BY, LIMIT and OFFSET clauses in SELECT statements. If your database supports the UNION construct, the attacker may try to append an entire query to the original one to list passwords from an arbitrary table. Using encrypted password fields is strongly encouraged.

Example 27-3. Listing out articles ... and some passwords (any database server)

<?php

$query  
= "SELECT id, name, inserted, size FROM products
                  WHERE size = '$size'
                  ORDER BY $order LIMIT $limit, $offset;"
;
$result = odbc_exec($conn, $query);

?>
The static part of the query can be combined with another SELECT statement which reveals all passwords:

'
union select '1', concat(uname||'-'||passwd) as name, '1971-01-01', '0' from usertable;
--

If this query (playing with the ' and --) were assigned to one of the variables used in $query, the query beast awakened.

SQL UPDATE's are also susceptible to attack. These queries are also threatened by chopping and appending an entirely new query to it. But the attacker might fiddle with the SET clause. In this case some schema information must be possessed to manipulate the query successfully. This can be acquired by examining the form variable names, or just simply brute forcing. There are not so many naming conventions for fields storing passwords or usernames.

Example 27-4. From resetting a password ... to gaining more privileges (any database server)

<?php
$query
= "UPDATE usertable SET pwd='$pwd' WHERE uid='$uid';";
?>
But a malicious user sumbits the value ' or uid like'%admin%'; -- to $uid to change the admin's password, or simply sets $pwd to "hehehe', admin='yes', trusted=100 " (with a trailing space) to gain more privileges. Then, the query will be twisted:

<?php

// $uid == ' or uid like'%admin%'; --
$query = "UPDATE usertable SET pwd='...' WHERE uid='' or uid like '%admin%'; --";

// $pwd == "hehehe', admin='yes', trusted=100 "
$query = "UPDATE usertable SET pwd='hehehe', admin='yes', trusted=100 WHERE
...;"
;

?>

A frightening example how operating system level commands can be accessed on some database hosts.

Example 27-5. Attacking the database hosts operating system (MSSQL Server)

<?php

$query  
= "SELECT * FROM products WHERE id LIKE '%$prod%'";
$result = mssql_query($query);

?>
If attacker submits the value a%' exec master..xp_cmdshell 'net user test testpass /ADD' -- to $prod, then the $query will be:

<?php

$query  
= "SELECT * FROM products
                    WHERE id LIKE '%a%'
                    exec master..xp_cmdshell 'net user test testpass /ADD'--"
;
$result = mssql_query($query);

?>

MSSQL Server executes the SQL statements in the batch including a command to add a new user to the local accounts database. If this application were running as sa and the MSSQLSERVER service is running with sufficient privileges, the attacker would now have an account with which to access this machine.

Note: Some of the examples above is tied to a specific database server. This does not mean that a similar attack is impossible against other products. Your database server may be similarly vulnerable in another manner.

Avoiding techniques

You may plead that the attacker must possess a piece of information about the database schema in most examples. You are right, but you never know when and how it can be taken out, and if it happens, your database may be exposed. If you are using an open source, or publicly available database handling package, which may belong to a content management system or forum, the intruders easily produce a copy of a piece of your code. It may be also a security risk if it is a poorly designed one.

These attacks are mainly based on exploiting the code not being written with security in mind. Never trust any kind of input, especially that which comes from the client side, even though it comes from a select box, a hidden input field or a cookie. The first example shows that such a blameless query can cause disasters.

Besides these, you benefit from logging queries either within your script or by the database itself, if it supports logging. Obviously, the logging is unable to prevent any harmful attempt, but it can be helpful to trace back which application has been circumvented. The log is not useful by itself, but through the information it contains. More detail is generally better than less.




Broken Soft   Americana Host

PHP Manual PHP Documentation PHP Tutorials PHP Articles PHP Programming PHP Functions Arrays MySQL articles directory
php php manual manuals function php functions php online documentation php online manual Apache MySQL PostgreSQL Zend Technologies phpmyadmin Web Programming php tutorial php date php tutorials Programming php resources php lesson php resource php lessons free php lessons free php tutorials Linux php unix php free php hosting Web Programming using PHP/MySQL PHP Training Introduction to PHP Programming Course - html wysiwyg editor Phoenix PHP Developers ActionScript / PHP php hotscripts php web hot scripts MySQL com Dreamweaver MX Basic PHP Course PHP Programming Course php array php arrays php redirect php manual download php manual pdf php manual array Classes and Objects (PHP 4) Operators Expressions Constants Variables Database Security CGI binary php manual install Databases php Database phpbb php sql forumes php articles directory Broken Soft >> Best Free Arabic Ebooks - Free Ebooks Download- Free English Ebooks - Free Domain Names Ebooks - Free Web Hosting ebooks - Free Resellers Hosting Ebooks - Free Servers Hosting Ebooks- Free Google Adsense Ebooks - Free SEO Ebooks - Free Search Engines Ebooks - Free WebMasters Ebooks - Free Page Rank Ebooks - Free PR Ebooks - Free Web Design Ebooks - Free Web Development Ebooks - Free Flash Mx Ebooks - Free Adobe Photoshop Ebooks - Free Cinema4d(cinema4d ebooks) ebooks - Free 3dmax Ebooks - Free Autocad Ebooks - Free Switch Max Ebooks - Free Programming Ebooks - Free Microsoft Visual Basic Ebooks - Free Dream Waver Ebooks - Free Microsoft Front Page Ebooks - Free Microsoft Visual Basic.net (vb.net) Ebooks - Free Csharp Ebooks (Free c# Ebooks) - Free c Ebooks - Free C+(Cplus) Ebooks - Free C++ (C plus plus) Ebooks - Free Java Ebooks - Free Assembly Ebooks - Free Delphi Ebooks - Free Assemply Ebooks - Free Delphi Ebooks - Free Xml Ebooks - Free Web Programming Ebooks - Free PHP Ebooks - Free Java Script Ebooks - Free Javascripe Ebooks - Free HTML Ebooks - Free ASP Ebooks - Free Microsoft ASP.NET Ebooks - Free Perl Ebooks - Free CGi Ebooks - Free API Ebooks - Free Cpanel Ebooks - Free Digi Chat Ebooks - Free TCP/IP Ebooks - Free PDF Ebooks - Free EXE Ebooks - Free CHM Ebooks - Free BiBLE Ebooks - The Google Adsense Empire Handbook - Free Amazon Ebooks - Free Google SEO Ebooks - Free Mesothelioma Ebooks - Free Lawyers Ebooks - Free Cars Care Ebooks - Free Computers Ebooks - Free LabTops Ebooks - Free Microsoft Windows Ebooks - Free linux Ebooks - Free Unix Ebooks - Free Database Ebooks - Free Microsoft ACCESS Ebooks - Free microsoft SQL Server 2000 Ebooks - Free Oracle Ebooks - Free MySql Ebooks - Free Networks Ebooks - Free Mesothelioma Treatment Ebooks - All These Free Ebooks In Broken Soft For Free Ebooks Best Free Ebooks With Broket Free Ebooks Free Free Free Free Ebooks In Broken Soft Free Ebooks php,php manual,manuals,function,php functions,php online documentation,php online manual,Apache,MySQL,PostgreSQL,sql, Zend Technologies ,zend,phpmyadmin,Web Programming,php tutorial,php date,php tutorials,Programming,php resources,php lesson,php resource,php lessons, free php lessons,free php tutorials,Linux,php,unix,php,free php hosting,Web Programming using PHP/MySQL,PHP Training,Introduction to PHP,Programming Course,html,wysiwyg editor,Phoenix,PHP Developers,ActionScript / PHP,php hotscripts,php web hot scripts,MySQL com,Dreamweaver MX,Basic PHP Course,PHP Programming Course,php array,php arrays, php redirect,php manual download,php manual pdf,php manual array,Classes and Objects (PHP 4),Operators,Expressions,Constants,Variables,Database Security,CGI ,binary,php manual install,Databases,php Database,phpbb,php forumes,php articles directory

Qwesz Article Directory Qwesz Directory
شبكة هجوم و منتديات هجوم منتديات تحميل برامج و تحميل برامج جوال و برامج تعريف قطع الاجهزة و برامج ماسنجر و خطوط و ايضا منتديات لعب العاب و العاب فلاش و العاب بنات للبنات فقط و العاب باربي و العاب جوال و العاب مكياج ميك اب و تحميل صور و صور سيارات و افلام و اغانى و صيانة جوالات و بوكيت بي سي و ثيمات و بلوتوث و مسجات جوال و دردشة و شات - العاب دليل بروكين سوفت دروس الفوتوشوب ( دروس قلعة الفوتوشوب ) ( دروس فوتوشوب ) ( دروس فوتوشوب للمبتدئين ) ( دروس فوتوشوب للمتقدمين ) ( فلاتر فوتوشوب ) ( فرش الفوتوشوب ) ( تدرجات الفوتوشوب ) ( أشكال الفوتوشوب ) ( مواقع ومنتديات الفوتوشوب ) ( أيقونات و صور PNG ) ( دروس ايميج ريدى ) برامج فى برامج ( مواقع و منتديات البرامج ) ( البرامج الأساسية ) ( برامج النظام و الخدمات ) ( برامج مكافحة ملفات التجسس و برامج جدار ناري ) ( برامج منع النوافذ الإعلانية ) ( برامج الحماية و مكافحة الفايروسات ) ( برامج تعريفات الأجهزة ) ( برامج الماسنجر و المحادثة ) ( برامج الكمبيوتر ) ( برامج الانترنت ) ( برامج تسريع الانترنت ) ( برامج تحديث أنظمة ميكروسوفت ) ( برامج نوكيا الجيل الثاني و الثالث ) ( برامج الجوال والاتصالات ) ( برامج خدمية ومكتبية ) ( برامج تحميل الملفات ) ( برامج الفيديو ) ( برامج الصوتيات و المرئيات ) ( برامج الصوت ) ( برامج البانرات و الايقونات ) ( برامج التصميم و الصور ) ( برامج نسخ الاسطوانات ) ( برامج عربية و إسلامية ) ( برامج مدرسية ) ( برامج تصميم المواقع ) ( برامج أخرى ) ( البرامج التعليمية ) ( المتصفحات و برامج البحث ) ( برامج البريد الإلكتروني ) ( برامج مشاركة الملفات ) ( برامج الترجمة ) دروس التصميم والجرافيكس ( دروس الفلاش ) ( مواقع و منتديات تعليم الفلاش ) ( مواقع ومنتديات السينما فور دى Cinema 4D ) ( مواقع و منتديات تعليم الثرى دى ماكس 3D Max ) ( دروس السويش ماكس ) تطوير المواقع ( دروس تطوير المواقع ) ( برامج تطوير المواقع ) ( قوالب مواقع جاهزة Templates ) ( مواقع و منتديات تطوير المواقع ) ( دروس Cpanel ) ( شعارات جاهزة PSD ) تطوير المنتديات ( تطوير منتديات vBulletin ) ( ستايلات منتديات vBulletin ) ( هاكات منتديات vBulletin ) ( مواقع دعم منتديات vBulletin ) ( تطوير منتديات PHPBB ) ( ستايلات منتديات PHPBB ) ( هاكات منتديات PHPBB ) ( مواقع دعم منتديات PHPBB ) ( تطوير منتديات IPB ) ( ستايلات منتديات IPB ) ( هاكات منتديات IPB ) ( مواقع دعم منتديات IPB ) ( تطوير منتديات SMF ) ( ستايلات منتديات SMF ) ( هاكات منتديات SMF ) ( مواقع دعم منتديات SMF ) دروس البرمجه ( دروس فيجوال بيسك ) دروس اوفيس ( دروس اكسس ) ( دروس وورد ) ( دروس بوربوينت ) ( دروس اكسل ) ( دروس الفرونت بيج ) خطوط ( خطوط عربية ) ( خطوط انجليزية دروس الفوتوشوب ( دروس قلعة الفوتوشوب ) ( دروس فوتوشوب ) ( دروس فوتوشوب للمبتدئين ) ( دروس فوتوشوب للمتقدمين ) ( فلاتر فوتوشوب ) ( فرش الفوتوشوب ) ( تدرجات الفوتوشوب ) ( أشكال الفوتوشوب ) ( مواقع ومنتديات الفوتوشوب ) ( أيقونات و صور PNG ) ( دروس ايميج ريدى ) برامج فى برامج ( مواقع و منتديات البرامج ) ( البرامج الأساسية ) ( برامج النظام و الخدمات ) ( برامج مكافحة ملفات التجسس و برامج جدار ناري ) ( برامج منع النوافذ الإعلانية ) ( برامج الحماية و مكافحة الفايروسات ) ( برامج تعريفات الأجهزة ) ( برامج الماسنجر و المحادثة ) ( برامج الكمبيوتر ) ( برامج الانترنت ) ( برامج تسريع الانترنت ) ( برامج تحديث أنظمة ميكروسوفت ) ( برامج نوكيا الجيل الثاني و الثالث ) ( برامج الجوال والاتصالات ) ( برامج خدمية ومكتبية ) ( برامج تحميل الملفات ) ( برامج الفيديو ) ( برامج الصوتيات و المرئيات ) ( برامج الصوت ) ( برامج البانرات و الايقونات ) ( برامج التصميم و الصور ) ( برامج نسخ الاسطوانات ) ( برامج عربية و إسلامية ) ( برامج مدرسية ) ( برامج تصميم المواقع ) ( برامج أخرى ) ( البرامج التعليمية ) ( المتصفحات و برامج البحث ) ( برامج البريد الإلكتروني ) ( برامج مشاركة الملفات ) ( برامج الترجمة ) دروس التصميم والجرافيكس ( دروس الفلاش ) ( مواقع و منتديات تعليم الفلاش ) ( مواقع ومنتديات السينما فور دى Cinema 4D ) ( مواقع و منتديات تعليم الثرى دى ماكس 3D Max ) ( دروس السويش ماكس ) تطوير المواقع ( دروس تطوير المواقع ) ( برامج تطوير المواقع ) ( قوالب مواقع جاهزة Templates ) ( مواقع و منتديات تطوير المواقع ) ( دروس Cpanel ) ( شعارات جاهزة PSD ) تطوير المنتديات ( تطوير منتديات vBulletin ) ( ستايلات منتديات vBulletin ) ( هاكات منتديات vBulletin ) ( مواقع دعم منتديات vBulletin ) ( تطوير منتديات PHPBB ) ( ستايلات منتديات PHPBB ) ( هاكات منتديات PHPBB ) ( مواقع دعم منتديات PHPBB ) ( تطوير منتديات IPB ) ( ستايلات منتديات IPB ) ( هاكات منتديات IPB ) ( مواقع دعم منتديات IPB ) ( تطوير منتديات SMF ) ( ستايلات منتديات SMF ) ( هاكات منتديات SMF ) ( مواقع دعم منتديات SMF ) دروس البرمجه ( دروس فيجوال بيسك ) دروس اوفيس ( دروس اكسس ) ( دروس وورد ) ( دروس بوربوينت ) ( دروس اكسل ) ( دروس الفرونت بيج ) خطوط ( خطوط عربية ) ( خطوط انجليزية جوالات فى جوالات فى جوالات ( جوال فى جوال فى جوال ) ( جوالات نوكيا جوالات Nokia ) ( جوالات سونى اريكسون جوال Sony Ericsson ) ( جوالات Siemens جوال سيمنز ) ( جوالات Samsung جوال و جوالات سامسونج ) ( جوالات LG جوال و جوالات ال جى ) ( جوالات Symbian OS Series 60 ) ( جوالات Symbian OS Series 80 Communicators ) ( جوالات Symbian OS Series 90 Media Phones ) ( جوالات Symbian OS UIQ ) ( جوالات Pocket PC & Palm جوالات البالم والبوكيت بى سى ) ( الجوالات الأخرى جوالات اخرى ) العاب فى العاب فى العاب ( العاب فلاش فى العاب فلاش ) ( العاب جديدة فى العاب جديدة ) ( العاب بنات فى العاب بنات ) ( العاب باربي فى العاب باربى ) ( العاب تلبيس فى العاب تلبيس ) ( العاب اطفال فى العاب اطفال ) ( العاب سوبر ماريو فى العاب سوبر ماريو ) ( العاب طبخ فى العاب طبخ ) ( العاب تلوين فى العاب تلوين ) ( العاب سونيك فى العاب سونيك ) ( العاب اكشن قتالية فى العاب اكشن قتال ) ( العاب توم وجيري فى العاب توم وجيري ) ( العاب ميك اب فى العاب ميك اب Makeup ) ( العاب فلة و ترتيب ) ( العاب تسديد و نيشان رائعة ) ( العاب الذاكرة ) ( العاب الورق رائعة ) ( العاب السباقات رائعة ) ( العاب رياضية رائعة ) ( العاب الحركة و التشويق رائعة ) ( العاب تسديد و نيشان رائعة ) ( العاب بازل و متاهات رائعة ) ( العاب ذكاء صعبة ) ( العاب اخرى ) طب وصحة ( الصحه العامه ) ( صحة المرأة و الحامل ) ( سؤال و جواب في النسائية والتوليد ) ( جلدية و تناسلية ) ( باطنية كبد و جهاز هضمي ) ( كلى و مسالك بولية ) ( غدد و سكري ) ( القلب و امراض القلب و الجهاز الدوراني ) ( صحة الطفل و الرضيع ) ( فم اسنان و لثة ) ( عيون و جفون ) ( عظام مفاصل و عضلات ) ( مخ جهاز عصبي و نفسي ) ( الغذاء و الوزن ) ( صحة عامة و اسعافات اولية ) ( عقم و ذكورة ) ( انف اذن حنجرة و صدرية ) ( جراحة عامة و تجميل ) ( امراض الجهاز المناعي ) ( مجموعة "هل تعلم كيف" المصورة التعليمية ) ( الطب البديل ) ( ملفات طبية خاصة ) ( الحصن البدني النفسي الحصين ) ( موسوعة صحة الطفل ) ( اخبار طبية و علمية ) ( تشريح جسم الانسان ) ( البوم الصور الطبية ) كتب فى كتب ( مواقع كتب ومكتبات عربية ) ( كتب هاردوير ) ( كتب انظمة التشغيل ) ( كتب برامج خدمات النظام ) ( كتب برامج التعامل مع الملفات ) ( كتب برامج حماية ) ( كتب برامج ميكروسوفت أوفيس ) ( كتب برامج و طرق التعامل مع الاسطوانات ) ( كتب برامج الوسائط المتعددة ) ( كتب برامج الأعمال المكتبية ) ( كتب برامج التعريب والبرمجة ) ( كتب برامج الإنترنت والتصفح ) ( كتب برامج المحادثة والشات ) ( كتب برامج التصميم ) ( كتب الفوتوشوب ) ( كتب بناء المواقع و المنتديات ) ( كتب اخرى ) صور فى صور فى صور ( ابتسامات فى سمايلات فى ابتسامات ) ( صور اسلامية ) ( صور سيارات ) ( صور فوتوغرافية ) ( خلفيات سطح المكتب ) ( صور دول عربية وعالمية ) ( صور حروف وأرقام ) ( صور جوالات و صور موبايل ) ( صور طريفة ) ( صور خيول ) ( صور من الفضاء ) ( أيقونات و ازرار ) ( خلفيات و صور للمواقع ) ( مناظر و صور طبيعية ) ( صور للمنتديات ) ( صور متحركة ) ( صور اطفال ) افلام فى افلام فى افلام ( افلام وثائقية ) ( افلام مضحكة ) ( افلام نينجا ) اسلاميات ( اغانى اسلامية صيانة الكمبيوتر | تعلم الفرونت بيج | دروس الفوتوشوب | دروس الإستضافه | تعلم ويندوز إكس بى | Mesothelioma Lawyers Mesothelioma Attorneys | PHP MANUAL | FUNCTIONS | تعليم ويندوز إكس بى Microsoft Windows XP | دليل دروس الهادوير | دليل المواقع العربية | صوت الإسلام | Ebooks Home | دروس الفوتوشوب | Holy Book | صحيح البخارى | تطوير المواقع | Cpanel Tutorials | WHM Tutorials | Cpanel User Manual | WHM User Manual | برامج Downloads | راسلنا | منظم القوائم البريديه | موسوعة الأدعيه الصحيحه Islam | Webmasters Tools | Open Directory Project | القران الكريم | Domain Name Registration Glossary | Broken Soft Books | Contact US | دليل دروس الفوتوشوب دليل النينجا | Articles Directory | Mesothelioma Lawyers Articles | Hosting Articles Directory | Article Directory Submission Submit Your Articles | المرجع الإسلامى الشامل | Online Degree | Forex | Adobe PhotoshopTutorials | Forex Trading | Affordable Web Hosting Directory Mesothelioma Lawyers Directory | Conference Calling Services | Qwesz Article Directory - Submit Articles | Qwesz Article Directory - Submit Articles Free | web hosting article directory | Cheap WebHosting Directory | Broken Soft Books Article Directory | Photoshop Tutorials Directory| WebHosting Articles Directory | Mesothelioma Lawyers Article Directory | Microsoft Frontpage Article Directory | Computer Hardware Articles Directory | Americana Hosting Directory | Americana Hosting Article Directory | Articles Directories Directory | Directories Directory | Web Hosting Directory | Cheap Web Hosting Directory | Web Hosting Reviews Directory | Web Hosting Services Directory | Cheap Web Hosting Providers Directory Web Hosting Articles | americana hosting directory Miraco Soft Directory | Broken Soft Web Hosting Directory | Cheap Web Hosting Reviews Services Providers Directory WebMasters Directory Cheap Web Hosting Reviews Services Providers Directory Mesothelioma Lawyers Attorneys Articles Directory Broken Soft Articles Directory AmericanaHost Articles Directory Qwesz Articles Directory Submit Articles Alninga Search Articles Directory Cheap Hosting Articles Directory Articles Directory Algasos Directory Mesothelioma Lawyers Mesothelioma Attorneys Articles Directory Article Directory Directories Directories Directory Free WebMaster SEO Tools Directory WebMasters Directory SEO Chat Tools webmaster tools Article Directory Directories Directories Directory Free WebMaster SEO Tools Directory WebMasters Directory Directories Directory webmaster seo tools directory web hosting directory cheap hosting directory طريق الإسلام Islam Way Web Design Directory Web Hosting Ping Directory Web Hosting Directory webmasters directory Broken Soft Articles Directory Mesothelioma Killer Lawyers Articles Directory Alninga Search Articles Directory Americana Hosting Articles Directory Affordable Web Hosting mesothelioma attorneys articles directory