Table of Contents
解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译)
Home Database Mysql Tutorial 解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库

解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库

Jun 07, 2016 pm 03:20 PM
co sqlserver use

解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译) http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/ 有时候你必须先作恶,后行善。情况就是 当你想磨练你的数据库修复技能 我现在添加了一个Corruptor 类到Orca

解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译)

http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/

有时候你必须先作恶,后行善。情况就是 当你想磨练你的数据库修复技能

我现在添加了一个Corruptor 类到OrcaMDF里面 去测试新的RawDatabase 的功能。Corruptor 就跟他的名字一样--他会故意损坏数据库文件


Corruptor 本身是比较简单的。Corruptor 会随机选择一些页面并且简单的使用0来完全复写页面。
根据页面的类型,这可能会造成致命伤害

我不想多说什么了,不过万一。。。请不要在你的生产库上运行。这会损坏你的数据。

 

例子
有两个 Corruptor.CorruptFile重载方法,他们都返回integers 的枚举值 -- 一系列的pageid 列表并且被复写0的

下面的代码会损坏5%的页面在AdventureWorks2008R2LT.mdf 文件里面,然后他会输出每个被损坏了的页面ID 。
你可以定义损坏页面的百分比 只需要改变第二个参数

<span>var</span> corruptedPageIDs = Corruptor.CorruptFile(<span>@"</span><span>C:\AdventureWorks2008R2LT.mdf</span><span>"</span>, <span>0.05</span><span>);
Console.WriteLine(</span><span>string</span>.Join(<span>"</span><span>, </span><span>"</span>, corruptedPageIDs));
Copy after login

<span>606</span>, <span>516</span>, <span>603</span>, <span>521</span>, <span>613</span>, <span>621</span>, <span>118</span>, <span>47</span>, <span>173</span>, <span>579</span><span>,
</span><span>323</span>, <span>217</span>, <span>358</span>, <span>515</span>, <span>615</span>, <span>271</span>, <span>176</span>, <span>596</span>, <span>417</span>, <span>379</span><span>,
</span><span>269</span>, <span>409</span>, <span>558</span>, <span>103</span>, <span>8</span>, <span>636</span>, <span>200</span>, <span>361</span>, <span>60</span>, <span>486</span><span>,
</span><span>366</span>, <span>99</span>, <span>87</span>
Copy after login

为了使损坏更厉害,你也可以使用第二个重载方法,他允许你定义一个确切的损坏页面的数目,在一个确定的pageid范围内。
下面的代码会确切的损坏pageid在0到49这个范围内的10个页面,因此会损坏大部分的元数据,大家知道系统表的数据基本都存储在数据库最靠前的页面上

<span>var</span> corruptedPageIDs = Corruptor.CorruptFile(<span>@"</span><span>C:\AdventureWorks2008R2LT.mdf</span><span>"</span>, <span>10</span>, <span>0</span>, <span>49</span><span>);
Console.WriteLine(</span><span>string</span>.Join(<span>"</span><span>, </span><span>"</span>, corruptedPageIDs));
Copy after login

<span>16</span>, <span>4</span>, <span>0</span>, <span>32</span>, <span>15</span>, <span>14</span>, <span>30</span>, <span>2</span>, <span>49</span>, <span>9</span>
Copy after login

 

在上面的情况我非常不幸的看到 下面这些页面都被填充了0 包括:

file header page,page 2 is the first GAM page,page 9 is the boot page ,page 16 allocation unit metadata。

这样的损坏程度,即使使用DBCC CHECKDB也没办法修复,留下给你的选择只有从备份中还原

 

或者,你可以尝试一下使用OrcaMDF RawDatabase去恢复尽可能多的数据,先到这里了,我以后还会继续介绍。

 

<span>DBCC</span> TRACEON(<span>3604</span>,<span>-</span><span>1</span><span>)
</span><span>GO</span>

<span>DBCC</span> PAGE(<span>[</span><span>sss</span><span>]</span>,<span>1</span>,<span>16</span>,<span>3</span><span>)
</span><span>GO</span>

<span>DBCC</span> 执行完毕。如果 <span>DBCC</span><span> 输出了错误信息,请与系统管理员联系。

PAGE: (</span><span>1</span>:<span>16</span><span>)


BUFFER:


BUF </span><span>@0x0000000080FDEB80</span><span>

bpage </span><span>=</span> <span>0x0000000080A74000</span> bhash <span>=</span> <span>0x0000000000000000</span> bpageno <span>=</span> (<span>1</span>:<span>16</span><span>)
bdbid </span><span>=</span> <span>8</span> breferences <span>=</span> <span>0</span> bcputicks <span>=</span> <span>0</span><span>
bsampleCount </span><span>=</span> <span>0</span> bUse1 <span>=</span> <span>19980</span> bstat <span>=</span> <span>0xc00009</span><span>
blog </span><span>=</span> <span>0x32159</span> bnext <span>=</span> <span>0x0000000000000000</span><span>

PAGE HEADER:


Page </span><span>@0x0000000080A74000</span><span>

m_pageId </span><span>=</span> (<span>1</span>:<span>16</span>) m_headerVersion <span>=</span> <span>1</span> m_type <span>=</span> <span>1</span><span>
m_typeFlagBits </span><span>=</span> <span>0x4</span> m_level <span>=</span> <span>0</span> m_flagBits <span>=</span> <span>0x200</span><span>
m_objId (AllocUnitId.idObj) </span><span>=</span> <span>7</span> m_indexId (AllocUnitId.idInd) <span>=</span> <span>0</span> Metadata: AllocUnitId <span>=</span> <span>458752</span><span>
Metadata: PartitionId </span><span>=</span> <span>458752</span> Metadata: IndexId <span>=</span> <span>1</span> Metadata: ObjectId <span>=</span> <span>7</span><span>
m_prevPage </span><span>=</span> (<span>0</span>:<span>0</span>) m_nextPage <span>=</span> (<span>1</span>:<span>130</span>) pminlen <span>=</span> <span>73</span><span>
m_slotCnt </span><span>=</span> <span>49</span> m_freeCnt <span>=</span> <span>4225</span> m_freeData <span>=</span> <span>4331</span><span>
m_reservedCnt </span><span>=</span> <span>0</span> m_lsn <span>=</span> (<span>1037</span>:<span>459</span>:<span>3</span>) m_xactReserved <span>=</span> <span>0</span><span>
m_xdesId </span><span>=</span> (<span>0</span>:<span>455</span>) m_ghostRecCnt <span>=</span> <span>0</span> m_tornBits <span>=</span> <span>-</span><span>563242027</span><span>

Allocation Status

GAM (</span><span>1</span>:<span>2</span>) <span>=</span> ALLOCATED SGAM (<span>1</span>:<span>3</span>) <span>=</span> <span>NOT</span><span> ALLOCATED 
PFS (</span><span>1</span>:<span>1</span>) <span>=</span> <span>0x60</span> MIXED_EXT ALLOCATED 0_PCT_FULL DIFF (<span>1</span>:<span>6</span>) <span>=</span><span> CHANGED
ML (</span><span>1</span>:<span>7</span>) <span>=</span> <span>NOT</span><span> MIN_LOGGED

Slot </span><span>0</span> Offset <span>0x60</span> Length <span>77</span><span>

Record Type </span><span>=</span> PRIMARY_RECORD Record Attributes <span>=</span> NULL_BITMAP Record Size <span>=</span> <span>77</span><span>

Memory </span><span>Dump</span> <span>@0x000000000DC7A060</span>

<span>0000000000000000</span>: <span>10004900</span> <span>00000300</span> <span>00000000</span> <span>01000003</span><span> †..I............. 
</span><span>0000000000000010</span>: <span>00000000</span> <span>00000000</span> 0001001f <span>00000001</span><span> †................ 
</span><span>0000000000000020</span>: <span>00570000</span> <span>00010056</span> <span>00000001</span><span> 000b0000 †.W.....V........ 
</span><span>0000000000000030</span>: <span>00000000</span> <span>00090000</span> <span>00000000</span> <span>00110000</span><span> †.....    .......... 
</span><span>0000000000000040</span>: <span>00000000</span> <span>00010000</span> 000c0000 <span>00</span><span>††††††††.............

Slot </span><span>0</span> <span>Column</span> <span>1</span> Offset <span>0x4</span> Length <span>8</span> Length (physical) <span>8</span><span>

auid </span><span>=</span> <span>196608</span><span>

Slot </span><span>0</span> <span>Column</span> <span>2</span> Offset <span>0xc</span> Length <span>1</span> Length (physical) <span>1</span><span>

type </span><span>=</span> <span>1</span><span>

Slot </span><span>0</span> <span>Column</span> <span>3</span> Offset <span>0xd</span> Length <span>8</span> Length (physical) <span>8</span><span>

ownerid </span><span>=</span> <span>196608</span><span>

Slot </span><span>0</span> <span>Column</span> <span>4</span> Offset <span>0x15</span> Length <span>4</span> Length (physical) <span>4</span><span>

status </span><span>=</span> <span>0</span><span>

Slot </span><span>0</span> <span>Column</span> <span>5</span> Offset <span>0x19</span> Length <span>2</span> Length (physical) <span>2</span><span>

fgid </span><span>=</span> <span>1</span><span>

pgfirst </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>6</span> Offset <span>0x1b</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgfirst </span><span>=</span> <span>0x1f0000000100</span><span>

pgroot </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>7</span> Offset <span>0x21</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgroot </span><span>=</span> <span>0x570000000100</span><span>

pgfirstiam </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>8</span> Offset <span>0x27</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgfirstiam </span><span>=</span> <span>0x560000000100</span><span>

Slot </span><span>0</span> <span>Column</span> <span>9</span> Offset <span>0x2d</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcused </span><span>=</span> <span>11</span><span>

Slot </span><span>0</span> <span>Column</span> <span>10</span> Offset <span>0x35</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcdata </span><span>=</span> <span>9</span><span>

Slot </span><span>0</span> <span>Column</span> <span>11</span> Offset <span>0x3d</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcreserved </span><span>=</span> <span>17</span><span>

Slot </span><span>0</span> <span>Column</span> <span>12</span> Offset <span>0x45</span> Length <span>4</span> Length (physical) <span>4</span><span>

dbfragid </span><span>=</span> <span>1</span><span>

Slot </span><span>0</span> Offset <span>0x0</span> Length <span>0</span> Length (physical) <span>0</span><span>

KeyHashValue </span><span>=</span> (016862d84319)
Copy after login

 

SELECT COUNT(*) FROM sys.[allocation_units]
--131
SELECT * FROM sys.[allocation_units]
SELECT * FROM sys.[system_internals_allocation_units]

 

存储在数据库1:16页面上(是[sys.system_internals_allocation_units]系统表)《深入解析sql2008》

 

第十七篇完

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that the object named already exists in the sqlserver database How to solve the problem that the object named already exists in the sqlserver database Apr 05, 2024 pm 09:42 PM

For objects with the same name that already exist in the SQL Server database, the following steps need to be taken: Confirm the object type (table, view, stored procedure). IF NOT EXISTS can be used to skip creation if the object is empty. If the object has data, use a different name or modify the structure. Use DROP to delete existing objects (use caution, backup recommended). Check for schema changes to make sure there are no references to deleted or renamed objects.

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

How to check sqlserver port number How to check sqlserver port number Apr 05, 2024 pm 09:57 PM

To view the SQL Server port number: Open SSMS and connect to the server. Find the server name in Object Explorer, right-click it and select Properties. In the Connection tab, view the TCP Port field.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

Where is the sqlserver database? Where is the sqlserver database? Apr 05, 2024 pm 08:21 PM

SQL Server database files are usually stored in the following default location: Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data The database file location can be customized by modifying the database file path setting.

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

See all articles