Saturday, January 10, 2015

MySQL injection in details

SQL injection is a code injection technique, used to attack data-driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker).[1] SQL injection must exploit a security vulnerability in an application's software, for example, when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and unexpectedly executed. SQL injection is mostly known as an attack vectorfor websites but can be used to attack any type of SQL database.

From Wiki - http://en.wikipedia.org/wiki/SQL_injection

Versionselect versionnumber, version_timestamp from sysibm.sysversions;
Commentsselect blah from foo; — comment like this
Current Userselect user from sysibm.sysdummy1;
select session_user from sysibm.sysdummy1;
select system_user from sysibm.sysdummy1;
List UsersN/A (I think DB2 uses OS-level user accounts for authentication.)Database authorities (like roles, I think) can be listed like this:
select grantee from syscat.dbauth;
List Password HashesN/A (I think DB2 uses OS-level user accounts for authentication.)
List Privilegesselect * from syscat.tabauth; — privs on tables
select * from syscat.dbauth where grantee = current user;
select * from syscat.tabauth where grantee = current user;
select * from SYSIBM.SYSUSERAUTH – List db2 system privilegies
List DBA Accountsselect name from SYSIBM.SYSUSERAUTH where SYSADMAUTH = ‘Y’ or SYSADMAUTH = ‘G’
Current Databaseselect current server from sysibm.sysdummy1;
List DatabasesSELECT schemaname FROM syscat.schemata;
List Columnsselect name, tbname, coltype from sysibm.syscolumns;
List Tablesselect name from sysibm.systables;
Find Tables From Column Nameselect tbname from sysibm.syscolumns where name=’username’
Select Nth Rowselect name from (SELECT name FROM sysibm.systables order by
name fetch first N+M-1 rows only) sq order by name desc fetch first N rows only;
Select Nth CharSELECT SUBSTR(‘abc’,2,1) FROM sysibm.sysdummy1;  — returns b
Bitwise ANDThis page seems to indicate that DB2 has no support for bitwise operators!
ASCII Value -> Charselect chr(65) from sysibm.sysdummy1; — returns ‘A’
Char -> ASCII Valueselect ascii(‘A’) from sysibm.sysdummy1; — returns 65
CastingSELECT cast(’123′ as integer) FROM sysibm.sysdummy1;
SELECT cast(1 as char) FROM sysibm.sysdummy1;
String ConcatenationSELECT ‘a’ concat ‘b’ concat ‘c’ FROM sysibm.sysdummy1; — returns ‘abc’
select ‘a’ || ‘b’ from sysibm.sysdummy1; — returns ‘ab’

No comments:

Post a Comment