Monthly Archives: January 2019

Object.defineProperty

Object.defineProperty(obj, prop, descriptor) descriptor分成data descriptor和access descriptor,兩者不能混用。 If a descriptor has neither of value, writable, get and set keys, it is treated as a data descriptor. If a descriptor has both value or writable and get or set keys, an exception … Continue reading

Posted in nodejs | Leave a comment

mongodb connect slow

在實際mongoose連線時,發現使用mongodb://localhost/db連線常常要好幾十秒才會建起來,而mongodb://127.0.0.1/db就馬上可以連上,追蹤了底層發現原因主要是mongodb-core 3.x他預設是使用tcp family 6的參數建連線,如果在系統內沒有正確設定localhost對應的ipv6 dns lookup (/etc/hosts ::1 或是 external dns的ipv6 dnslookup)就會等到查詢timeout,這時候mongodb nodejs driver才改用family 4的參數連線 node_modules/mongodb-core/lib/connection/connection.js 而127.0.0.1連線時,也是會帶family 6去連,但是在nodejs net.createConnection會進行dns.lookup 而 dns.lookup會再檢查一次字串是否為ip以及解出對應的family https://github.com/nodejs/node/blob/master/lib/dns.js 這類的問題比較麻煩的是在不同的機器上不一定能reproduce,有可能ipv6 localhost設定正確或是對外查詢dns可以正常查到,所以在追問題的時候仍需從經過的source code著手

Posted in nodejs | Leave a comment

openssl heartbleed

有用到openssl 需要注意他的漏洞更新,這邊提到的是大約2014年中的一個重大漏洞,屬於implementation flaw,同年的還有ShellShock和POODLE。作為許多軟體的底層元件,在當時影響的層面相當廣泛(參考: https://en.wikipedia.org/wiki/Heartbleed) https://blog.cloudflare.com/answering-the-critical-question-can-you-get-private-ssl-keys-using-heartbleed/這篇主要描述了openssl heartbleed bug(CVE-2014-0160),主要是利用heartbeat會response echo傳來的訊息,而在程式中沒有做message size boundary check 而依賴在protocol中由client提供的16bits length (存在payload變數), hbtype為message type,因為是16bits 所以最多可以echo 64kb的資料,因此可以從response拿到一些存在heap記憶體的資料,透過大量的request一直malloc free,其中可能可以拿到之前request帶的敏感資訊而進一步攻擊 有問題的點在上面的memcpy 將p1的內容複製到bp,共payload個bytes,而payload又是直接讀取content轉出來 n2a(p, payload) 那一行 測試可參考https://github.com/mpgn/heartbleed-PoCopenssl影響的版本為1.0.1~1.01f,實際拿apache + openssl 1.0.1c來測試就會發現能夠dump server side的記憶體內容

Posted in General | Leave a comment