PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries (SQL इंजेक्शन (SQLi): डेटाबेस हमला, रोकथाम और तैयार स्टेटमेंट्स) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: SQL Injection (SQLi) occurs when untrusted user input is concatenated into database queries without separation, letting attackers bypass authentication, extract tables, or execute administrative commands—completely prevented by parameterized queries.
अध्याय सार: SQL इंजेक्शन (SQLi) तब होता है जब अनफिल्टर्ड यूज़र इनपुट को सीधे SQL क्वेरी स्ट्रिंग में जोड़ा जाता है, जिससे हमलावर लॉगिन बायपास, डेटा चोरी या डेटाबेस में बदलाव कर सकता है; इसकी अचूक रोकथाम पैरामीटराइज्ड क्वेरी (Prepared Statements) से होती है।
SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries: Detailed Notes & Architecture (SQL इंजेक्शन (SQLi): डेटाबेस हमला, रोकथाम और तैयार स्टेटमेंट्स)
1. Root Cause: String Concatenation & Code-Data Confusion (मूल कारण: स्ट्रिंग संयोजन से कोड व डेटा का मिश्रण)
[EN] SQL Injection arises whenever an application builds dynamic SQL statements by concatenating raw strings—such as "SELECT * FROM users WHERE name='" + input + "'"—instead of passing bound parameters. Because the database parser receives a single merged string, metacharacters like single quotes ('), SQL comments (-- , #, /* */), semicolons (;), or Boolean operators (OR/AND) break out of the string literal context and mutate query syntax.
[HI] SQL इंजेक्शन तब पैदा होता है जब प्रोग्राम डेटाबेस क्वेरी को स्ट्रिंग जोड़कर ('+' या f-string से) बनाता है। डेटाबेस इंजन को यूज़र डेटा और SQL कमांड एक ही स्ट्रिंग में मिलते हैं, इसलिए सिंगल कोट ('), कमेंट (--, #) और OR जैसे कीवर्ड्स क्वेरी की संरचना को ही बदल देते हैं।
2. SQLi Taxonomy: In-Band, Blind & Out-of-Band (OOB) (SQLi के प्रकार: इन-बैंड, ब्लाइंड और आउट-ऑफ-बैंड)
[EN] In-Band SQLi retrieves data directly in the same HTTP response via Error-Based techniques (forcing DB errors that leak table names) or UNION-Based queries ('UNION SELECT username, password FROM users' after matching column counts using 'ORDER BY N'). When error messages and data output are suppressed, attackers perform Blind SQLi: Boolean-Based Blind asks true/false questions watching subtle page differences, while Time-Based Blind triggers delays like 'SLEEP(5)' or 'WAITFOR DELAY'. Out-of-Band SQLi exfiltrates results asynchronously over DNS or HTTP requests.
[HI] इन-बैंड SQLi में डेटा सीधे वेब पेज पर दिखता है—या तो Error संदेशों से या 'UNION SELECT' के माध्यम से (जहाँ 'ORDER BY' से कॉलम की संख्या मिलाई जाती है)। जब आउटपुट न दिखे तो Blind SQLi होता है: Boolean Blind में सही/गलत पेज व्यवहार देखा जाता है और Time-Based में 'SLEEP(5)' से देरी मापी जाती है। OOB में डेटा DNS/HTTP अनुरोध से बाहर भेजा जाता है।
3. Authentication Bypass & Second-Order SQL Injection (ऑथेंटिकेशन बायपास व सेकंड-ऑर्डर SQL इंजेक्शन)
[EN] A classic login bypass injects "admin' -- " or "' OR 1=1 -- " into a username field, turning the query condition universally true and commenting out the password check. In Second-Order SQLi, a malicious payload is safely stored in the database on an initial request (for example, a username containing quotes saved via a prepared statement), and triggers later when another legacy module reads that stored value and concatenates it unsafely into an administrative query.
[HI] लॉगिन फॉर्म में "admin' -- " या "' OR 1=1 -- " डालने से WHERE शर्त हमेशा सत्य हो जाती है और आगे का पासवर्ड चेक कमेंट होकर अनदेखा हो जाता है। वहीं Second-Order SQLi में पेलोड पहली बार डेटाबेस में सेव हो जाता है और बाद में किसी अन्य असुरक्षित मॉड्यूल द्वारा उस मान को बिना पैरामीटराइजेशन के क्वेरी में जोड़ने पर सक्रिय होता है।
4. Prepared Statements (Parameterized Queries) & Hardening (तैयार स्टेटमेंट्स (Prepared Statements) और सुरक्षा नियम)
[EN] The primary defense against SQLi is Parameterized Queries (Prepared Statements), where the SQL command template with placeholders ('?' or '%s' or ':id') is compiled into an Execution Plan by the DB engine FIRST, and user values are bound strictly as typed scalar parameters afterward—so injected quotes remain literal text. Supporting layers include ORM query builders (without raw SQL interpolation), Principle of Least Privilege DB accounts, disabling stacked queries/xp_cmdshell, and Web Application Firewalls (WAF).
[HI] SQLi का सबसे विश्वसनीय समाधान Prepared Statements (Parameterized Queries) हैं: इनमें SQL संरचना प्लेसहोल्डर ('?' या '%s') के साथ पहले ही कंपाइल हो जाती है और यूज़र इनपुट बाद में शुद्ध डेटा मान के रूप में जुड़ता है। इसके साथ DB यूज़र को न्यूनतम अधिकार (Least Privilege), और इनपुट टाइप वैलिडेशन लागू किया जाता है।
Syntax, Formula & Technical Example (SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries)
# VULNERABLE: String concatenation lets input alter SQL syntax
# Input: ' OR '1'='1' --
query = f"SELECT id FROM users WHERE user='{username}' AND pass='{password}'"
# SAFE: Parameterized Query / Prepared Statement (Python DB-API / PDO style)
cursor.execute(
"SELECT id, role FROM users WHERE user = %s AND pass_hash = %s",
(username, password_hash)
)
# UNION probe rule: column count & compatible data types must match original SELECT
# Probe: ' ORDER BY 3-- | Exploit: ' UNION SELECT 1, table_name, NULL FROM information_schema.tables--
SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries Quick Reference & Comparison Table
| SQLi Category / Defense | Core Technique / Syntax | Technical & Exam Behavior |
|---|---|---|
| UNION-Based In-Band SQLi | ' UNION SELECT col1, col2 FROM users-- | Requires exact column count & compatible types |
| Boolean-Based Blind SQLi | ' AND SUBSTRING(version(),1,1)='8'-- | Infers characters bit-by-bit via true/false page changes |
| Time-Based Blind SQLi | '; SELECT SLEEP(5)-- / WAITFOR DELAY | Infers truth when server response pauses N seconds |
| Parameterized Prepared Statement | cursor.execute('... WHERE id=?', (val,)) | Pre-compiles SQL AST; binds input strictly as literal data |
SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries Top 20 Bilingual MCQs with Answers
Q1. What is the single most effective coding defense that structurally eliminates SQL Injection?
(SQL इंजेक्शन को जड़ से समाप्त करने का सबसे प्रभावी कोडिंग उपाय कौन सा है?)
(A) Hiding error messages via CSS display:none
(B) Client-side JavaScript form validation before POST
(C) Parameterized Queries (Prepared Statements) with bound placeholders
(D) Removing the word 'SELECT' using case-sensitive string replace
Correct Answer: (C)
[EN] Prepared statements separate SQL syntax compilation from parameter binding, ensuring injected quotes can never become executable SQL commands.
[HI] Prepared Statements SQL कोड की संरचना को डेटा मानों से पूरी तरह अलग रखते हैं, जिससे इनपुट कभी कमांड नहीं बन पाता।
Q2. What happens when an attacker enters "admin' -- " into a vulnerable concatenated SQL login query?
(जब हमलावर किसी असुरक्षित SQL लॉगिन क्वेरी में "admin' -- " दर्ज करता है, तो क्या होता है?)
(A) The web browser clears all local cookies
(B) The single quote closes the username string and '-- ' comments out the remaining password verification clause
(C) The SQL engine automatically encrypts the password column
(D) The database creates a new administrator user named '--'
Correct Answer: (B)
[EN] In SQL, '-- ' (note trailing space in MySQL) comments out the rest of the statement, bypassing the AND password='...' check.
[HI] सिंगल कोट नाम को बंद कर देता है और '-- ' आगे के पासवर्ड जांच वाले हिस्से को कमेंट बनाकर निष्क्रिय कर देता है।
Q3. What strict prerequisite must hold for a 'UNION SELECT' SQL injection payload to succeed?
('UNION SELECT' SQL इंजेक्शन पेलोड के सफल होने के लिए कौन सी अनिवार्य शर्त पूरी होनी चाहिए?)
(A) Both tables must contain at least 1,000 rows
(B) Both SELECT queries must return the exact same number of columns with compatible data types
(C) The attacker must possess the database administrator's OS SSH key
(D) The query must always use HTTPS port 443
Correct Answer: (B)
[EN] SQL UNION fails with a syntax error unless column counts match; attackers find the count sequentially via 'ORDER BY 1--', 'ORDER BY 2--', etc.
[HI] SQL में UNION चलाने के लिए दोनों SELECT क्वेरी में कॉलमों की संख्या बिल्कुल समान और डेटा प्रकार संगत होने चाहिए।
Q4. Why do attackers inject payloads like "' ORDER BY 5-- " prior to running a UNION attack?
(हमलावर UNION हमला चलाने से पहले "' ORDER BY 5-- " जैसे पेलोड क्यों डालते हैं?)
(A) To restart the database server cleanly
(B) To sort stolen passwords alphabetically before download
(C) To upgrade a normal database user to DBA role
(D) To enumerate the exact number of columns returned by the original vulnerable SELECT query
Correct Answer: (D)
[EN] When 'ORDER BY N' succeeds and 'ORDER BY N+1' throws an 'Unknown column' error, the original query has exactly N columns.
[HI] जब 'ORDER BY N' सफल हो और 'ORDER BY N+1' एरर दे, तो पता चलता है कि मूल क्वेरी में ठीक N कॉलम हैं।
Q5. Which SQL function is typically used in MySQL for a 'Time-Based Blind SQL Injection' test?
(MySQL में 'Time-Based Blind SQL Injection' जांचने के लिए सामान्यतः किस फ़ंक्शन का उपयोग किया जाता है?)
(A) PAUSE_DB(5)
(B) pg_sleep(5)
(C) SLEEP(5)
(D) WAITFOR DELAY '0:0:5'
Correct Answer: (C)
[EN] MySQL uses SLEEP(n), Microsoft SQL Server uses WAITFOR DELAY '0:0:n', and PostgreSQL uses pg_sleep(n) to measure response latency.
[HI] MySQL में SLEEP(n), MS SQL Server में WAITFOR DELAY तथा PostgreSQL में pg_sleep(n) उपयोग होता है।
Q6. What defines 'Second-Order SQL Injection'?
('Second-Order SQL Injection' की सही परिभाषा क्या है?)
(A) Exploiting a backup replica database rather than the primary node
(B) Injecting SQL into two separate database tables inside one HTTP header
(C) Running an automated tool after manual injection fails
(D) A payload safely stored in the database on request 1 executes as SQL when later retrieved and concatenated unsafely in request 2
Correct Answer: (D)
[EN] Even if input is escaped on INSERT, a downstream report or profile-edit query that reads DB fields without parameterization becomes vulnerable.
[HI] इसमें पेलोड पहले अनुरोध में सुरक्षित रूप से DB में सेव होता है, लेकिन दूसरे अनुरोध में बिना पैरामीटराइजेशन के दोबारा उपयोग होने पर हमला करता है।
Q7. Why is relying purely on blacklisting keywords like 'UNION' or 'SELECT' an inadequate SQLi defense?
(केवल 'UNION' या 'SELECT' जैसे शब्दों की ब्लैकलिस्टिंग करना SQLi से बचाव का अधूरा तरीका क्यों है?)
(A) Attackers bypass naive filters using mixed case ('UnIoN'), inline comments ('SEL/**/ECT'), URL/hex encoding, or alternate logic
(B) Blacklisting breaks TCP 3-way handshakes on port 3306
(C) Parameterized queries automatically disable all blacklists
(D) Databases ignore blacklisted keywords automatically during compilation
Correct Answer: (A)
[EN] Signature blacklists are trivially evaded using case variation, SQL inline comments, or numeric/boolean injections that need no quotes.
[HI] हमलावर केस बदलकर ('UnIoN'), कमेंट बीच में डालकर ('SEL/**/ECT') या कोडिंग बदलकर कीवर्ड फ़िल्टर को आसानी से चकमा दे देते हैं।
Q8. In MySQL/PostgreSQL/Oracle, which system metadata view do SQLi attackers query to enumerate table and column names?
(MySQL/PostgreSQL डेटाबेस में टेबल और कॉलम के नाम निकालने के लिए SQLi हमलावर सामान्यतः किस सिस्टम स्कीमा से क्वेरी करते हैं?)
(A) ETC.PASSWD_DB
(B) SYS.BOOT_CONFIG
(C) MYSQL.TEMP_CACHE
(D) INFORMATION_SCHEMA (e.g., information_schema.tables)
Correct Answer: (D)
[EN] Standard ANSI SQL exposes metadata about all databases, tables, and columns inside the INFORMATION_SCHEMA catalog.
[HI] मानक SQL डेटाबेस में सभी टेबलों और कॉलमों की सूची INFORMATION_SCHEMA (जैसे information_schema.tables) में संग्रहीत होती है।
Q9. What dangerous feature in Microsoft SQL Server allows an attacker exploiting SQLi as 'sa' to execute OS shell commands?
(Microsoft SQL Server में कौन सा खतरनाक फीचर 'sa' अधिकारों वाले SQLi हमलावर को सीधे ऑपरेटिंग सिस्टम कमांड चलाने दे सकता है?)
(A) pg_read_file
(B) xp_cmdshell
(C) LOAD DATA INFILE
(D) SHOW VARIABLES
Correct Answer: (B)
[EN] When enabled, the extended stored procedure 'xp_cmdshell' spawns a Windows command shell directly from T-SQL.
[HI] MS SQL Server में सक्षम होने पर 'xp_cmdshell' स्टोर्ड प्रोसीजर सीधे SQL क्वेरी से Windows कमांड शेल चला सकता है।
Q10. Why can an integer parameter query like "SELECT * FROM items WHERE id = " + id remain vulnerable even if single quotes are escaped?
(यदि कोई कोड सिंगल कोट (') को फ़िल्टर कर भी दे, तब भी "SELECT * FROM items WHERE id = " + id जैसी न्यूमेरिक क्वेरी असुरक्षित क्यों रहती है?)
(A) Integer columns automatically execute JavaScript inside SQL
(B) Numeric SQL parameters are not wrapped in quotes, so payloads like '1 OR 1=1' or '1 UNION SELECT...' need no quote characters at all
(C) MySQL treats integers larger than 100 as admin privileges
(D) Escaping quotes converts integers into floating-point overflows
Correct Answer: (B)
[EN] Because numbers aren't delimited by quotes, quote-escaping functions like addslashes() do nothing to stop numeric SQLi.
[HI] संख्यात्मक मान के बाहर सिंगल कोट नहीं होता, इसलिए बिना कोट लगाए ही '1 OR 1=1' या '1 UNION SELECT...' चल जाता है।
Q11. How does 'Out-of-Band (OOB) SQL Injection' exfiltrate data when HTTP pages show zero errors, content changes, or timing differences?
(जब वेब पेज पर कोई एरर, बदलाव या देरी न दिखे, तब 'Out-of-Band (OOB) SQLi' डेटा कैसे बाहर निकालता है?)
(A) By sending ARP broadcast packets over the internet
(B) By forcing the database server to trigger outbound DNS lookups or HTTP requests containing stolen data in the subdomain/URL
(C) By writing passwords into the user's browser localStorage directly
(D) By printing stolen tables onto the data center monitor locally
Correct Answer: (B)
[EN] Functions like Oracle UTL_HTTP or MSSQL xp_dirtree force the DB server to make DNS requests to an attacker-controlled domain carrying leaked records.
[HI] OOB SQLi डेटाबेस सर्वर को मजबूर करता है कि वह चुराए गए डेटा को सबडोमेन में जोड़कर हमलावर के सर्वर पर DNS या HTTP अनुरोध भेजे।
Q12. Why might a SQL Stored Procedure STILL be vulnerable to SQL Injection?
(कोई SQL Stored Procedure (स्टोर्ड प्रोसीजर) कब अभी भी SQL इंजेक्शन के प्रति संवेदनशील हो सकता है?)
(A) When the stored procedure internally builds and runs dynamic SQL strings using EXEC() or PREPARE/EXECUTE with concatenated inputs
(B) Whenever the database runs on Linux instead of Windows
(C) Stored procedures are inherently immune in every situation
(D) Whenever the stored procedure uses a SELECT statement instead of UPDATE
Correct Answer: (A)
[EN] Stored procedures are only safe if they use static parameterized statements; concatenating inputs inside EXEC(@sql) reintroduces SQLi.
[HI] यदि स्टोर्ड प्रोसीजर के भीतर इनपुट को जोड़कर डायनामिक SQL (जैसे EXEC(@sql)) चलाया जा रहा हो, तो उसमें भी SQLi हो सकता है।
Q13. Which well-known open-source automated penetration testing tool specializes in detecting and exploiting SQL Injection flaws?
(SQL इंजेक्शन कमजोरियों को खोजने और जांचने के लिए कौन सा ओपन-सोर्स पेनिट्रेशन टेस्टिंग टूल सबसे प्रसिद्ध है?)
(A) sqlmap
(B) John the Ripper
(C) Aircrack-ng
(D) Wireshark
Correct Answer: (A)
[EN] sqlmap automates fingerprinting DBMS versions and exploiting error-based, UNION, blind, and time-based SQL injection vectors.
[HI] sqlmap डेटाबेस के प्रकार की पहचान करने तथा सभी प्रकार के SQL इंजेक्शन परीक्षण को स्वचालित करने का मानक टूल है।
Q14. How does the 'Principle of Least Privilege' reduce SQL Injection damage even if a coding flaw exists?
(कोड में बग होने के बावजूद 'Principle of Least Privilege' (न्यूनतम विशेषाधिकार सिद्धांत) SQLi के नुकसान को कैसे कम करता है?)
(A) It hides the website from Google search engines
(B) Running the web app with a restricted DB user prevents DROP TABLE, reading unrelated schemas, or OS file/command execution
(C) It turns every SQL injection payload into a 404 HTML page
(D) It automatically rewrites PHP queries into Rust before execution
Correct Answer: (B)
[EN] An application querying only a product catalog should never connect as 'root'/'sa' or hold DROP/FILE/SYSTEM privileges.
[HI] यदि वेब ऐप को केवल आवश्यक टेबल पढ़ने का सीमित DB अधिकार मिले, तो हमलावर अन्य डेटाबेस डिलीट नहीं कर सकता और न ही OS कमांड चला सकता है।
Q15. Why is '-- ' (with a trailing space) preferred over '--' alone when commenting out queries in MySQL?
(MySQL में क्वेरी का शेष भाग कमेंट करने के लिए अकेले '--' के बजाय '-- ' (अंत में स्पेस सहित) क्यों आवश्यक होता है?)
(A) The trailing space turns SELECT into INSERT
(B) MySQL requires at least one whitespace or control character immediately after '--' to treat it as a SQL comment
(C) The space encrypts the remainder of the SQL statement
(D) Without the space MySQL executes the query twice
Correct Answer: (B)
[EN] Unlike PostgreSQL/MSSQL where '--' needs no space, MySQL syntax strictly mandates whitespace after '--' (or uses '#' instead).
[HI] MySQL सिंटैक्स में '--' को कमेंट मानने के लिए उसके तुरंत बाद कम से कम एक स्पेस (या विकल्प में '#') होना अनिवार्य है।
Q16. Which statement about SQL Injection and Parameterized Queries is FALSE?
(SQL इंजेक्शन और पैरामीटराइज्ड क्वेरी के संबंध में निम्नलिखित में से कौन सा कथन असत्य (FALSE) है?)
(A) Prepared statements compile the SQL structure separately from bound parameter values
(B) Client-side HTML5 input patterns and JavaScript checks completely prevent SQL Injection against the backend API
(C) Blind SQLi infers data via boolean response differences or deliberate time delays
(D) Table names and SQL keywords like ORDER BY ASC/DESC cannot be parameterized directly and need strict allowlisting
Correct Answer: (B)
[EN] Attackers bypass browser JavaScript entirely using curl, Burp Suite, or Python scripts—security validation and parameterization MUST happen server-side.
[HI] हमलावर ब्राउज़र की JavaScript जांच को curl या प्रॉक्सी (Burp Suite) से आसानी से बायपास कर देते हैं, इसलिए सुरक्षा हमेशा सर्वर-साइड पर होनी चाहिए।
Q17. Within SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries, which sqli category / defense directly maps to: "' UNION SELECT col1, col2 FROM users--"?
(SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries में कौन सा SQLi Category / Defense सीधे "' UNION SELECT col1, col2 FROM users--" से संबंधित है?)
(A) Time-Based Blind SQLi
(B) Parameterized Prepared Statement
(C) Boolean-Based Blind SQLi
(D) UNION-Based In-Band SQLi
Correct Answer: (D)
[EN] In SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries, 'UNION-Based In-Band SQLi' handles '' UNION SELECT col1, col2 FROM users--' (Requires exact column count & compatible types).
[HI] SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries में 'UNION-Based In-Band SQLi' का कार्य/विवरण '' UNION SELECT col1, col2 FROM users--' (Requires exact column count & compatible types) है।
Q18. Which option accurately describes 'Boolean-Based Blind SQLi' in SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries?
(SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries के संदर्भ में 'Boolean-Based Blind SQLi' की सही विशेषता कौन सी है?)
(A) '; SELECT SLEEP(5)-- / WAITFOR DELAY
(B) cursor.execute('... WHERE id=?', (val,))
(C) ' UNION SELECT col1, col2 FROM users--
(D) ' AND SUBSTRING(version(),1,1)='8'--
Correct Answer: (D)
[EN] 'Boolean-Based Blind SQLi' provides '' AND SUBSTRING(version(),1,1)='8'--' — key point: Infers characters bit-by-bit via true/false page changes.
[HI] 'Boolean-Based Blind SQLi' का मुख्य विवरण '' AND SUBSTRING(version(),1,1)='8'--' है (Infers characters bit-by-bit via true/false page changes)।
Q19. In SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries, identify the correct parameter for the specification: "'; SELECT SLEEP(5)-- / WAITFOR DELAY".
(SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries में "'; SELECT SLEEP(5)-- / WAITFOR DELAY" विवरण किस विकल्प के लिए सही है?)
(A) Boolean-Based Blind SQLi
(B) Time-Based Blind SQLi
(C) Parameterized Prepared Statement
(D) UNION-Based In-Band SQLi
Correct Answer: (B)
[EN] 'Time-Based Blind SQLi' corresponds to ''; SELECT SLEEP(5)-- / WAITFOR DELAY' (Infers truth when server response pauses N seconds).
[HI] 'Time-Based Blind SQLi' का संबंध ''; SELECT SLEEP(5)-- / WAITFOR DELAY' (Infers truth when server response pauses N seconds) से है।
Q20. Considering SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries, what key behavior defines 'Parameterized Prepared Statement'?
(SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries में 'Parameterized Prepared Statement' की मुख्य भूमिका या मान क्या है?)
(A) ' UNION SELECT col1, col2 FROM users--
(B) cursor.execute('... WHERE id=?', (val,))
(C) ' AND SUBSTRING(version(),1,1)='8'--
(D) '; SELECT SLEEP(5)-- / WAITFOR DELAY
Correct Answer: (B)
[EN] 'Parameterized Prepared Statement' represents 'cursor.execute('... WHERE id=?', (val,))' (Pre-compiles SQL AST; binds input strictly as literal data).
[HI] 'Parameterized Prepared Statement' का अर्थ/मान 'cursor.execute('... WHERE id=?', (val,))' है (Pre-compiles SQL AST; binds input strictly as literal data)।
SQL Injection (SQLi): Vulnerability, Exploitation and Parameterized Queries — Exam FAQs
Q1: Can parameterized placeholders ('?' or '%s') be used for dynamic table names or ASC/DESC sort order?
क्या टेबल का नाम या ORDER BY (ASC/DESC) चुनने के लिए भी पैरामीटर प्लेसहोल्डर ('?') उपयोग हो सकते हैं?
[EN] No. Placeholders only bind literal data values (like strings or numbers), not SQL identifiers or keywords. For dynamic sorting or column names, validate input against a strict server-side allowlist dictionary.
[HI] नहीं। प्लेसहोल्डर केवल डेटा मानों के लिए होते हैं। टेबल/कॉलम नाम या ASC/DESC को डायनामिक चुनने के लिए सर्वर पर सख्त व्हाइटलिस्ट (Allowlist) जांच आवश्यक है।
Q2: Why do prepared statements defeat even encoded or multi-byte SQL injection payloads?
पैरामीटराइज्ड क्वेरी एन्कोडेड या मल्टी-बाइट SQLi पेलोड को भी क्यों विफल कर देती हैं?
[EN] Because the SQL AST (parse tree) is finalized by the database engine before parameter values are supplied; bound parameter bytes are never fed into the SQL parser.
[HI] क्योंकि डेटाबेस इंजन पहले ही SQL पार्स ट्री बना लेता है और बाद में भेजे गए पैरामीटर बाइट्स को कभी भी SQL कोड के रूप में पार्स ही नहीं किया जाता।
Q3: Does using an ORM (like Django ORM, Hibernate, or SQLAlchemy) guarantee immunity from SQLi?
क्या ORM (जैसे Django ORM या Hibernate) का उपयोग करने से SQLi से 100% सुरक्षा मिल जाती है?
[EN] Only when using its native parameterized query APIs. Calling raw query escapes (like .raw(), nativeQuery, or text() with string formatting) reintroduces SQL injection immediately.
[HI] केवल तभी जब उसके मानक पैरामीटराइज्ड मेथड उपयोग किए जाएं; यदि ORM के अंदर भी स्ट्रिंग जोड़कर रॉ SQL क्वेरी लिखी जाए तो SQLi फिर से उत्पन्न हो जाता है।
Post a Comment
Post a Comment