Home > Articles > Data > SQL Server

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Activity Reconstruction

The incident timeline developed thus far in your investigation will allow you to limit the scope of the activity reconstruction. Table 11.1 summarizes the incident timeline you have created.

Table 11.1. Incident Timeline

Time

Event

Source

2008-08-31 15:27:09.50

Brute-force attack initiated

192.168.1.20

2008-08-31 15:31:35.24

Attacker gained unauthorized access to the PROD-SQL05 server using the MSmith login account

MSmith login

2008-08-31 15:32:41.367

Temporary object #09DE7BCC was created within Tempdb database

MSmith login

2008-08-31 15:36:34.42

Attacker reconnects to PROD-SQL05

MSmith login

2008-08-31 15:38:15.31

Attacker reconnects to PROD-SQL05

MSmith login

2008-08-31 15:41:55.060

IllB3back table was created within Master database

MSmith login

2008-08-31 15:43:23.74

Attacker reconnects to PROD-SQL05

MSmith login

2008-08-31 15:46:03.340

EASYACCESS login created

MSmith login

A key method of identifying past activity is reviewing command execution. Thus the next step in your investigation focuses on identifying the commands executed by the attacker on the SQL Server during his or her period of unauthorized access. The first artifact you analyze is server state information in an effort to determine details about the intruder's actions.

Server State

The server state artifact captures the current state of active connections and processes on a server. It includes a wealth of information, ranging from active user connections to database processes executing in the background to the last command executed by each connected user. Within WFT, you select the Active Connections | Connections and Sessions links to view active sessions on the victim system at the time of automated artifact collection. After reviewing the data on these pages, you conclude that the attacker has disconnected from the system: The MSmith login account does not appear in the list of actively connected users.

The next artifact you analyze is the plan cache, which may have cached the attacker's previously executed database statements.

Plan Cache

Reviewing the plan cache enables you to pinpoint anomalous entries that may be associated with the attacker. Although plan cache entries cannot be associated with a specific user, the process of associating plan cache entries to other database activity can map actions to a specific SQL Server login or database user. As your next move, you run the following syntax within the INV_308_Scenario database to return a list of plan cache entries that were cached during the scope of the incident:

SELECT * from plch_data order by convert(datetime, creation_time) desc

A snippet of the results returned appears in Figure 11.9.

Figure 11.9

Figure 11.9 A snippet of the plan cache entries cached during the scope of the incident

Your first search of the plan cache was done in an effort to identify which statement forced the creation of the #09DE7BCC temporary table within the Tempdb database. Because the creation of this object has already been mapped back to the MSmith login, you can place the attacker at a specific cache entry. This information serves as a starting point for identifying past activity as well as future activity not yet discovered.

As shown earlier in Table 11.1, the #09DE7BCC table was created at 2008-08-31 15:32:41.367. Using this time to the second, you perform a search of the plan cache entries in the hopes of finding a cached statement that was the source of the temporary table creation:

SELECT * FROM PLCH_Data WHERE CAST ([Creation_time] AS DATETIME) >= cast ('2008-08-31
15:32:41.000' AS DATETIME) AND CAST ([Creation_time] AS DATETIME) <= CAST ('2008-08-31
15:32:41.999' AS DATETIME) or CAST ([Last_execution_time] AS DATETIME) >= cast ('2008-
08-31 15:32:41.000' AS DATETIME) AND CAST ([Last_execution_time] AS DATETIME) <= CAST
('2008-08-31 15:32:41.999' AS DATETIME) order by last_execution_time desc

Figure 11.10 shows a snippet of the results produced by this query.

Figure 11.10

Figure 11.10 Plan cache entries created or executed at 2008-08-31 15:32:41

At first glance, you notice that the sys.sp_helpdb procedure was created multiple times—when a stored procedure is cached, its definition is displayed within the plan cache after execution. In close proximity to the sp_helpdb execution are four statements that update the temporary table #spdbdesc. The naming convention of this table seems to be related to sp_helpdb, so you select the object definition of sp_helpdb for further analysis. You gather the definition for sp_helpdb from server SP2, which runs SQL Server 2005. This version of SQL Server was the same major and minor release used on the victim, based on the server information obtained from the DB Configuration | SQL Server Info link within WFT.

On the trusted instance, you execute the following syntax:

SELECT OBJECT_DEFINITION (OBJECT_ID ('sys.sp_helpdb'))

Within the returned definition, you identify the statement that creates the #spdbdesc table. You note the following snippet of code, which shows the syntax within the sp_helpdb procedure that creates the temporary table logged under the transaction executed by the MSmith account:

create table #spdbdesc  (   dbname sysname,   owner sysname null,   created
nvarchar(11),   dbid smallint,   dbdesc nvarchar(600) null,   dbsize  nvarchar(13)
null,   cmptlevel tinyint  )      /*  **  If no database name given, get 'em all.  */

Although plan cache entries cannot be directly mapped back to a user or SID as operations within the transaction log can be, you map the executed statement within the plan cache to the resulting table creation data logged within the transaction log; this mapping again leads back to the MSmith SID. This discovery proves that the MSmith account executed the sp_helpdb procedure once the user gained access to the database server. Because sp_helpdb provides information about the databases on a SQL Server instance, you suspect that the attacker executed this procedure to learn the structure of the database server to which he or she just gained access. With an idea of the attacker's objective, you execute the following query, which allows you to view all plan cache entries in descending order by last_execution_time:

select * from plch_data order by convert(datetime, last_execution_time )desc

Once this query is executed, database reconnaissance-related entries are noted in the plan cache. These entries are highlighted in Figure 11.11.

Figure 11.11

Figure 11.11 Database reconnaissance-related plan cache entries

The transaction execution history suggests that database reconnaissance activity has, indeed, taken place. Database reconnaissance typically involves the execution of vague statements that return a manageable amount of data and allow the user to sort out the information he or she needs. Attackers are typically unfamiliar with the structure of a database, but they must be careful when attempting to learn it because that effort may attract attention or simply take time away from their primary objective.

Within the results captured in Figure 11.11. some fields have been reordered due to formatting limitations. By beginning at row 30 and working backward, you identify the following actions believed to be executed by the unauthorized user:

  • Row 30: Queried the sys.syslogins view within the Master database to get an understanding of the accounts on the SQL Server instance. Execution of this statement within the Master database was identified by the dbid value of 1, which maps to the Master database (as seen by executing the DB Objects & Users | Database link within WFT).
  • Rows 29–16: Executed sp_helpdb to learn about the databases on the SQL Server instance (which you proved earlier). Because sp_helpdb is a system object that can be executed, it is launched from the Resource database (database ID 32767).
  • Row 13: Switched database context to the OnlineSales database after the user received the results from sp_helpdb as identified by the dbid value of 5 in the next database reconnaissance-related query.
  • Row 13: Queried the sys.sysusers view to learn about the database users within the OnlineSales database.
  • Row 11: Queried sysobjects with a where type = 'U' clause, which returns a listing of all tables within the database.
  • Row 10: Executed a select statement against the orderhistory table, which would have been listed within the previous sysobjects results.
  • Rows 9–5: Executed multiple queries against multiple views in search of password or encryption key–related information, perhaps in an attempt to decrypt the data within the orderhistory table believed to be encrypted by the attacker.
  • Row 4: After the reconnaissance, executed the sp_password procedure, as identified by its definition being recorded as a statement.

Even your artifact collection actions are logged within the plan cache. Row 2 from the results captured in Figure 11.11 shows the execution of the IR scripts used during incident response and, therefore, can be ignored.

Other entries within the plan cache involve updates to the Orders table. However, all entries affecting the Orders table within the transaction log were executed by the OSApp login, which is also interactively logged into the system. (This fact can be verified by reviewing the information within Active Connections | Connections and Sessions links.)

You now conclude that the SELECT INTO statement executed by the unauthorized user is not resident in the cache, either because the database engine did not cache it or because it was evicted prior to its preservation.

This step completes your plan cache analysis. Your final artifact to analyze is the active VLFs obtained from the OnlineSales and Master databases of the victim system.

Active VLFs

To begin analysis of active VLF data, you execute the following syntax within the database to return a summary of all transactions performed by SID 0x501AEC871FD432488B4 A487B06C61505, which belongs to the MSmith login:

SELECT DISTINCT [TRANSACTION NAME], [BEGIN TIME], [current lsn] FROM AVLF_TLOG where
[TRANSACTION ID] IN (SELECT distinct [TRANSACTION ID] FROM AVLF_TLOG WHERE [TRANSACTION
SID] = '0x501AEC871FD432488B4A487B06C61505') and [transaction name] <> 'NULL' order by
[current lsn]

When this syntax is run, you receive the results captured in Figure 11.12.

Figure 11.12

Figure 11.12 Summary of all transactions performed by the suspect SID

You immediately discount the two CREATE STATISTICS transactions, which occurred prior to the unauthorized user gaining access to the database server. Instead, you focus on the entries highlighted in Figure 11.12. To obtain more details about these transactions, you execute the following slightly modified query, which returns 269 rows:

SELECT [database], [transaction ID], [transaction name], [operation], [allocunitname],
[begin time], [end time], spid, [transaction sid] FROM AVLF_TLOG where [TRANSACTION ID]
IN (SELECT DISTINCT [TRANSACTION ID] FROM AVLF_TLOG WHERE [TRANSACTION SID] =
'0x501AEC871FD432488B4A487B06C61505')

(Note: The preceding query and its results will be referred to several times throughout the rest of this chapter as "the detailed transaction summary results.")

To see the logical progression of the attacker's actions on the database, you step through the detailed transaction summary results in sequence by transaction ID, beginning with transaction 2723.

You first analyze transaction ID 2723, a SELECT INTO statement located within row 21 of the detailed transaction summary results. Figure 11.13 contains a snippet of this transaction.

Figure 11.13

Figure 11.13 Snippet of transaction ID 2723

Unfortunately, the SELECT INTO statement did not record the affected table within the Master database in the AllocUnitName field. Nevertheless, you examine the date and time when the transaction was committed. Matching this information to an object within the Master database will allow you to identify the created table. Transaction 2723 began on 2008/08/31 15:41:55:060. You develop the following syntax to compare the time the transaction was initiated against the object creation times within the DOBJ_Data table, which contains all objects and their associated creation and last update times on the victim server:

SELECT * from dobj_data where convert(datetime, create_date) = convert(datetime, '2008-08-31 15:41:55:060')

When this query is run, it returns the IllB3back table. This result reaffirms your earlier investigation finding. A snippet of the results appears in Figure 11.14. Because the original plan cache entry could not be recovered during your investigation, the other table involved in the SELECT INTO statement cannot be identified.

Figure 11.14

Figure 11.14 Database objects created at 2008/08/31 15:41:55:060

The second statement executed by the unauthorized user is transaction ID 2724, which is located on row 100 of the previous detailed transaction summary results. A snippet of transaction ID 2724 within these results is shown in Figure 11.15.

Figure 11.15

Figure 11.15 Snippet of transaction ID 2724

Stepping through the various operations within this transaction, you focus on row 240. It reveals that the transaction was aborted at 2008/08/31 15:43:16:570, as shown in Figure 11.16. This operation would have reverted the copying of data from the source table to the destination IllB3Back table.

Figure 11.16

Figure 11.16 An aborted transaction

Transaction ID 2725 was executed by the database engine in response to the SELECT INTO statement executed via transaction 2724. Transaction 2724 began allocating data pages for the IllB3back table before it was aborted. Figure 11.17 shows the IllB3back table referenced under the allocation unit field of transaction 2725.

Figure 11.17

Figure 11.17 The IllB3back table referenced under the allocation unit field of transaction 2725

As seen in Figure 11.18, transaction ID 2726 related to the alteration of a login. This transaction shows that a login was modified, but that the operations were immediately aborted. This behavior is usually associated with a validation check performed on the server, which was not meant to proceed with the login alteration.

Figure 11.18

Figure 11.18 Snippet of an aborted alter login operation

In the next part of your investigation, you develop the following syntax to query the plan cache and identify cached statements that were created or used at the same time of the transaction to the second:

SELECT * FROM PLCH_Data WHERE CAST ([Creation_time] AS DATETIME) >= cast ('2008-08-31
15:45:15.000' AS DATETIME) AND CAST ([Creation_time] AS DATETIME) <= CAST ('2008-08-31
15:45:15.999' AS DATETIME) or CAST ([Last_execution_time] AS DATETIME) >= cast ('2008-
08-31 15:45:15.000' AS DATETIME) AND CAST ([Last_execution_time] AS DATETIME) <= CAST
('2008-08-31 15:45:15.999' AS DATETIME) order by last_execution_time desc

When this code is executed, the results (captured in Figure 11.19) reveal that the cache plan entry for sp_password was created at the same time to the second as the ALTER LOGIN operation within the transaction log.

Figure 11.19

Figure 11.19 Plan cache entries created or last executed at Database objects created at 2008-08-31 15:45:15

The creation time shown in Figure 11.19 is the date and time the entry was cached, and the last_execution_time is the last time the plan entry was used by a database user. Reviewing your log summary, you note that two additional ALTER LOGIN operations were executed under transactions 2727 and 2728; these operations are found in rows 244 and 247 within the detailed transaction summary results (see Figure 11.20).

Figure 11.20

Figure 11.20 Two additional ALTER LOGIN operations executed under transactions 2727 and 2728

In Figure 11.20, the ALTER LOGIN operation was executed under transaction ID 2727 (row 253) but immediately failed after initiation. This mirrors transaction 2726's result, which indicates another password reset-related failure. Transaction 2728, however, executed successfully, as evidenced by the LOP_COMMIT_XACT operation logged at 2008/08/31 15:45:43:797.

You develop the following syntax to compare transaction 2726's commit time with logins created or updated, to the second, during the successful account update performed by transaction 2728:

SELECT * FROM LOGN_SQL WHERE CAST ([UPDATEDATE] AS DATETIME) >= cast ('2008/08/31
15:45:43:000' AS DATETIME) AND CAST ([UPDATEDATE] AS DATETIME) < CAST ('2008/08/31
15:45:43:999' AS DATETIME)

When this syntax is run, it produces the results shown in Figure 11.21. It appears that the MSmith account was updated in accordance to the transaction log entry to the second. This finding also allows you to reconfirm Mike's statement from earlier during the investigation—namely, that he could not gain access to his account earlier in the day.

Figure 11.21

Figure 11.21 Logins updated at 2008/08/31 15:45:43

Transaction 2729 (row 254) is a CREATE statement that was analyzed earlier in your investigation. It led to your discovery that the MSmith account created the EASYACESS account within the database server.

No other notable findings were identified in the analysis of the other artifacts collected from the victim system.

  • + Share This
  • 🔖 Save To Your Account