Exploiting A Tricky SQL Injection With sqlmap


[출처] http://pentestmonkey.net/blog/exploiting-a-tricky-sql-injection-with-sqlmap



Like many pentesters, I’m a fan of sqlmap.  It’s often the first and last tool I reach for when exploiting boolean or time-based SQL injection vulnerabilities.

I wanted to briefly document a slightly tricky SQL injection issue I encountered recently and a few of the sqlmap features that impressed me most.

I initially noticed that the following URLs returned the same page:

http://host/script?id=10
http://host/script?id=11-1 # same as id=10
http://host/script?id=(select 10) # same as id=10

Which looks pretty standard. The were a few problems with this injection, though. Firstly “and” and “or” didn’t work for some reason I never figured out:

 http://host/script?id=10 and 1=1 # failed

Secondly, I could’t terminate the query

http://host/script?id=10-- # failed
http://host/script?id=10;-- # failed
http://host/script?id=10);-- # failed
http://host/script?id=10)subquery;-- # failed

I spent a long time trying to terminate the query in burp intruder with a custom dictionary of possible strings. To no avail. I therefore could not make this into a UNION injection.

To exploit it as a boolean injection, I rewrote the URL slightly to help sqlmap – which was struggling because “and” and “or” didn’t work as they normally would:

 http://host/script?id=11-(case when 1=1 then 1 else 0 end)

It was then possible to put ” and 1=2″ etc. after the “1=1″ to give two different pages for the true or false response:

http://host/script?id=11 # the "when" clause is false
http://host/script?id=10 # the "when" clause is true

Apparently if you increase the “–level” parameter, sqlmap will try clever stuff like this for you.  I bares illustrating how to do it manually, though.

Telling sqlmap Where To Inject

By default sqlmap will figure out for itself where the injection point it. If you want to guide it, simply add a * to the URL like this:

sqlmap -u http://host/script?id=11-(case when 1=1* then 1)

BTW I’m using SVN version.  Apparently this feature was present in v0.9, but wasn’t documented.  Use the docs from the SVN  read about this feature.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

It’s a brilliant feature. I probably wouldn’t have bothered with sqlmap if it didn’t have this feature.

Error Correction

For some reason, the server gave me inconsistent responses (load balancing / general brokenness?). This resulted in about 25% of the chars retrieve by sqlmap being incorrect – not the fault of the tool, but the fault of the server.

This is a problem not faced by sqlmap users when using time-based (“waitfor delay”) injection because sqlmap has a cool feature: error correction.  After each character it extracts, it checks using a true/false query that the character is correct.

It wasn’t too hard to activate the error-correction feature for boolean injections too – in fact I changed a single line of code.

Sweet.  Error-free data from the database.

I’ve mailed Bernardo, sqlmap’s author and hopefully we’ll see this as an optional feature in a future release.  It does mean about 1/8th more queries will be required, but that’s a small price to pay when the server’s giving you bad data.

Tamper Scripts

To further complicate the injection, some characters needed URL encoding – e.g. > to %3E.  My instinct was to use “–tamper=between” which converts “> 5″ to “not between 0 and 5″.  However, this made the query too long (a further trickyness of this particular injection).

It was fairly easy to create a custom tamper script based on one of the 20 plus examples that ship with sqlmap:

cd sqlmap/tamper
cp between.py ptm.py
vi ptm.py
../sqlmap.py --tamper=ptm ...

Update: In retrospect –tamper=charencode may have worked.

Support

I found Bernardo very helpful and welcoming of feedback*.  He and Miroslav Stampar have done a great job on this tool.  And it just keeps improving.

*Though, always RTFM (v0.9 SVN version) before contacting him :-)

Tags: ,

Posted in Blog






본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 침투테스트(취약점검점검, 모의해킹) 문의 / 답변 졸리운_곰 2017.12.10 28360
29 [정보보안 기사 - 국가기술자격] [Kali Linux] Dos(Denial of Service) 공격 및 방어 file 졸리운_곰 2023.07.30 168
28 2018년도 국가공인 산업보안관리사(공인 제2016-5호, 산업통상자원부 장관) 자격검정시험 연간일정 안내 졸리운_곰 2018.01.17 164
27 정보보안기사 1차 필기 1차 시험, 2차 시험 기출문제 file 졸리운_곰 2017.09.23 250
26 2017년 9회 정보보안기사 실기 가답안 졸리운_곰 2017.09.23 346
25 시스템 취약점 점검도구 선정 지침 file 졸리운_곰 2017.09.10 181
24 정보보안기사 요약 정리.pdf file 졸리운_곰 2017.08.25 394
23 정보보안 기사_산업기사 정보보안 관리 및 법규 요약.pdf file 졸리운_곰 2017.08.25 300
22 정보보안기사 실기 기출문제 1,2,3,4 회 file 졸리운_곰 2016.10.23 1058
21 정보보안기사 요약 자료 pdf file 졸리운_곰 2016.10.23 5606
20 제8회 정보보안기사필기결과 secret 졸리운_곰 2016.10.15 0
19 정보보안 국가기술자격검정 최종합격 현황 중요 file 졸리운_곰 2016.08.31 335
18 정보보안기사 실기 준비요령 file 졸리운_곰 2015.05.23 1229
17 제5회 정보보안기사 1차 필기 결과 file 졸리운_곰 2015.04.17 644
16 위험분석 방법론 졸리운_곰 2015.01.17 489
15 Cisco 장비에서 ACL 설정을 해보자! file 졸리운_곰 2014.11.17 639
14 CCNA/CCNP 자료 졸리운_곰 2014.11.17 578
13 [알아봅시다] OTP one time password 란? file 졸리운_곰 2014.11.17 616
12 * PKI 조사 file 졸리운_곰 2014.11.17 274
11 * SET 결제시스템 조사 file 졸리운_곰 2014.11.17 517
10 정보보안기사 실기 기출 [1회/2회/3회] file 졸리운_곰 2014.10.28 8602
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED