Perl資料型別安全研究【翻譯】

wyzsk發表於2020-08-19
作者: 路人甲 · 2015/01/06 14:53

0x00 背景


enter image description here

前幾天有個人在某大會上講了一個在perl中存在了20年的問題。作為一個只會perl不會python的人,真的很心痛。看完影片後感覺被黑的吃不下東西。

這儼然就是一場對perl的吐槽批鬥大會,整個演講充滿了sucks、fuck等和諧詞彙,也能看出演講者是多麼的義憤填膺,場下一次次的鼓掌和附,嗯,讓我想起了郭德綱。

0x01 問題


enter image description here

言歸正傳,這個在perl中存在了20年的問題到底是啥呢?拋去perl的語法的槽點,真正的問題在data types上,對的,就是資料型別。

Perl對資料型別的處理真是有點匪夷所思了。

我們先了解一下perl中的變數有哪幾種。

perl中的變數

perl的資料型別分為三類:標量$,陣列@,雜湊%。

具體定義在這裡不多說,我們來看幾個例子:

enter image description here

不管是標量、陣列還是雜湊(字典),定義跟其他語言沒什麼區別。

enter image description here

我們來看看幾個特殊的情況,下面每個預期值為正常人類理解應該得到的結果。

#!perl
@array =(1, 2, 'a', 'b', 'c');
print $array[0];

預期值 1

enter image description here

實際值 1

#!perl
$scalar = (1, 2, 'a', 'b', 'c'); 
print $scalar;

預期值 1

enter image description here

實際值 c 我擦淚,為毛會是c!太不科學了,繼續往下看。

#!perl
@list = (1, 2, 'a', 'b', 'c'); 
print scalar @list;

預期值 1

enter image description here

實際值 5 呵呵,他把陣列的長度輸出了。

再看看這個雜湊的例子

#!perl
%hash = (1, 2, 'a', 'b', 'c'); 
print $hash{'a'};

預期值 木有

enter image description here

實際值 b 為毛把b給輸出了,誰能告訴我這頭草泥馬是怎麼處理的。

0x02 漏洞


這些問題會產生什麼漏洞呢?

一起看看在web中php跟perl處理的對比。

enter image description here

enter image description here

這麼看來是木有任何問題的,那麼使用復參的時候呢?

enter image description here

php很好的處理了傳入的資料,而perl的做法就是草泥馬在奔騰%>_<%他是直接可以傳入陣列的。

再深入一下,看看當陣列和雜湊結合的時候的情況。

#!perl
@list = ('f', 'lol', 'wat');
$hash = {'a' => 'b',
         'c' => 'd', 
         'e' => @list
};
print $hash;

預期值

#!perl
{
'a' => 'b',
    
'c' => 'd',
    
'e' => ['f','lol','wat'] 
} 

enter image description here

神馬情況,陣列中的“,”變成了“=>”又給賦值了?e=>f、lol=>wat,what the f*cuk!

enter image description here

這是多大的一個坑啊!看Bugzilla是怎麼掉進去的。

http://zone.wooyun.org/content/15628

關於資料型別的這些問題我不想再說了,有些噁心。

0x03 GPC的問題


enter image description here

enter image description here

屌屌的棒棒的,對吧,可是……

enter image description here

我了個*,一個都不給轉義了,就這麼罷工了,可以順順暢暢的注入了好麼。

enter image description here

我想靜靜。

0x04 來源


Pdf:

http://events.ccc.de/congress/2014/Fahrplan/system/attachments/2542/original/the-perl-jam-netanel-rubin-31c3.pdf

影片地址:

http://media.ccc.de/browse/congress/2014/31c3_-6243-en-saal_1-201412292200-the_perl_jam_exploiting_a_20_year-old_vulnerability-_netanel_rubin.html#video

本文章來源於烏雲知識庫,此映象為了方便大家學習研究,文章版權歸烏雲知識庫!

相關文章