偽造基於ASSM表空間的資料塊

sundog315發表於2010-06-25
從底向上第一篇--瞭解DML操作
從底向上第二篇--瞭解行遷移
從底向上第三篇--瞭解index的compress
從底向上第四篇--瞭解行連結
從底向上第五篇--瞭解表的壓縮屬性
從底向上第六篇--compress for oltp真正壓縮的閾值觸發條件
從底向上第七篇--超255列表的儲存
從底向上第八篇--偽造基於ASSM表空間的資料塊

突發奇想,既然Oracle資料塊的格式我們基本都能瞭解,那麼,偽造一個資料塊也應該是可行的,做個實驗,測試一下

SQL> conn test/test
已連線。
SQL> create table t as select * from dba_objects where rownum=1;

表已建立。

SQL> select count(*) from t;

COUNT(*)
----------
1

SQL> alter system checkpoint;

系統已更改。

SQL> select header_file,header_block from dba_segments where segment_name='T';

HEADER_FILE HEADER_BLOCK
----------- ------------
4 130

SQL> alter system dump datafile 4 block min 128 block max 131;

系統已更改。
[@more@]Dump of First Level Bitmap Block
--------------------------------
nbits : 4 nranges: 1 parent dba: 0x01000081 poffset: 0
unformatted: 4 total: 8 first useful block: 3
owning instance : 1
instance ownership changed at
Last successful Search
Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295
First free datablock : 4
Bitmap block lock opcode 0
Locker xid: : 0x0000.000.00000000
Inc #: 0 Objd: 68305
HWM Flag: HWM Set
Highwater:: 0x01000084 ext#: 0 blk#: 4 ext size: 8
#blocks in seg. hdr's freelists: 0
#blocks below: 4
mapblk 0x00000000 offset: 0
--------------------------------------------------------
DBA Ranges :
--------------------------------------------------------
0x01000080 Length: 8 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:FULL
4:unformatted 5:unformatted 6:unformatted 7:unformatted
--------------------------------------------------------

Extent Control Header
-----------------------------------------------------------------
Extent Header:: spare1: 0 spare2: 0 #extents: 1 #blocks: 8
last map 0x00000000 #maps: 0 offset: 2716
Highwater:: 0x01000084 ext#: 0 blk#: 4 ext size: 8
#blocks in seg. hdr's freelists: 0
#blocks below: 4
mapblk 0x00000000 offset: 0
Unlocked
--------------------------------------------------------
Low HighWater Mark :
Highwater:: 0x01000084 ext#: 0 blk#: 4 ext size: 8
#blocks in seg. hdr's freelists: 0
#blocks below: 4
mapblk 0x00000000 offset: 0
Level 1 BMB for High HWM block: 0x01000080
Level 1 BMB for Low HWM block: 0x01000080
--------------------------------------------------------
Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0
L2 Array start offset: 0x00001434
First Level 3 BMB: 0x00000000
L2 Hint for inserts: 0x01000081
Last Level 1 BMB: 0x01000080
Last Level II BMB: 0x01000081
Last Level III BMB: 0x00000000
Map Header:: next 0x00000000 #extents: 1 obj#: 68305 flag: 0x10000000
Inc # 0
Extent Map
-----------------------------------------------------------------
0x01000080 length: 8

Auxillary Map
--------------------------------------------------------
Extent 0 : L1 dba: 0x01000080 Data dba: 0x01000083
--------------------------------------------------------

Second Level Bitmap block DBAs
--------------------------------------------------------
DBA 1: 0x01000081

Block 128 First Level Bitmap,可以看到,現在只格式化了0-3的塊,我準備構造一個新塊,放入塊6中
用dd來實現:

C:UsersAdministrator>dd if=C:oracleappAdministratororadataTESTUSERS01.DB
F of=aaa.block bs=8192 count=1 skip=131
1+0 records in
1+0 records out

C:UsersAdministrator>dd of=C:oracleappAdministratororadataTESTUSERS01.DB
F if=aaa.block bs=8192 count=1 seek=134 conv=notrunc
1+0 records in
1+0 records out

這樣,構造了一個與131完全相同的新塊,並放入134中。

然後,用BBED修改塊128如下內容:
unformatted、Highwater、blk#、#blocks below,以及將6:unformatted修改為format狀態。

修改完畢的塊128:


Dump of First Level Bitmap Block
--------------------------------
nbits : 4 nranges: 1 parent dba: 0x01000081 poffset: 0
unformatted: 3 total: 8 first useful block: 3
owning instance : 1
instance ownership changed at
Last successful Search
Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295
First free datablock : 4
Bitmap block lock opcode 0
Locker xid: : 0x0000.000.00000000
Inc #: 0 Objd: 68305
HWM Flag: HWM Set
Highwater:: 0x01000087 ext#: 0 blk#: 7 ext size: 8
#blocks in seg. hdr's freelists: 0
#blocks below: 7
mapblk 0x00000000 offset: 0
--------------------------------------------------------
DBA Ranges :
--------------------------------------------------------
0x01000080 Length: 8 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:FULL
4:unformatted 5:unformatted 6:75-100% free 7:unformatted
--------------------------------------------------------


同樣的,用BBED修改塊130(Extent Control Header)的Highwater相關內容。

由於我們是將塊131複製到134中,還需要修改134的DBA值。由01000083修改為01000086


Dump of memory from 0x0E2E8200 to 0x0E2EA200
E2E8200 0000A206 01000086 007A91B0 04020000 [..........z.....]
E2E8210 0000CC7F 00000001 00010AD1 007A91AE [..............z.]
E2E8220 00000000 00320003 01000080 0000FFFF [......2.........]
E2E8230 00000000 00000000 00000000 00008000 [................]
E2E8240 007A91AE 00000000 00000000 00000000 [..z.............]
E2E8250 00000000 00000000 00000000 00000000 [................]
Repeat 1 times
E2E8270 00000000 00000000 00000000 00010100 [................]
E2E8280 0014FFFF 1F1F1F33 00001F1F 1F330001 [....3.........3.]
E2E8290 00000000 00000000 00000000 00000000 [................]
Repeat 496 times
E2EA1A0 00000000 00000000 00000000 2C000000 [...............,]
E2EA1B0 53030E00 49055359 244C4F43 15C102FF [...SYS.ICOL$....]
E2EA1C0 0503C102 4C424154 6E780745 3A0D1905 [....TABLE.xn...:]
E2EA1D0 6E78071C 3A0D1905 3032131C 302D3031 [..xn...:..2010-0]
E2EA1E0 35322D35 3A32313A 323A3735 41560537 [5-25:12:57:27.VA]
E2EA1F0 0144494C 014E014E 02C1024E 91B00602 [LID.N.N.N.......]

至此,修改完畢。我們來看看效果:

SQL> alter system flush buffer_cache;

系統已更改。
SQL> alter session set events '10202 trace name context forever';

會話已更改。

SQL> select count(*) from t;

COUNT(*)
----------
2

成功了。

SQL> alter session set events '10202 trace name context off';

會話已更改。

Consistent read complete...
Block header dump: 0x01000083
Object id on Block? Y
seg/obj: 0x10ad1 csc: 0x00.7a91ae itc: 3 flg: E typ: 1 - DATA
brn: 0 bdba: 0x1000080 ver: 0x01 opc: 0
inc: 0 exflg: 0

Itl Xid Uba Flag Lck Scn/Fsc
0x01 0xffff.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.007a91ae
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
Consistent read complete...
Block header dump: 0x01000086
Object id on Block? Y
seg/obj: 0x10ad1 csc: 0x00.7a9138 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x1000080 ver: 0x01 opc: 0
inc: 0 exflg: 0

Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x000d.01c.000002c2 0x03422891.03b0.1e --U- 1 fsc 0x0000.007a913a
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000


模擬測試完成,我們直接從底層偽造了一個合法的資料塊。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19423/viewspace-1034642/,如需轉載,請註明出處,否則將追究法律責任。

相關文章