作者:
winsyk
·
2014/12/31 18:49
0x00 背景
本文是為了揭示那些被忽視的開發安全問題,主要針對基礎設施部署環境基礎解決方案包括(內部、外部、雲環境)。
0x01 攻擊面
github
版本控制工具:
持續整合工具:
aws config files:
客戶端配置工具:
elasticsearch:
記憶體資料庫:
版本控制工具:
github資訊洩漏:
github支援較為較為強大的搜尋語法,透過這些搜尋語法,透過github可以搜尋到一些常規方法無法搜尋的內容,如搜尋內部專案、密碼,ssh私鑰等。 Conviso Research and Development Team編寫了個較為詳細的github語法搜尋文章,可以透過http://blog.conviso.com.br/2013/06/github-hacking-for-fun-and-sensitive.html 查閱。 如搜尋mysqldump 備份的sql檔案,可使用extension:mysqldump sql來搜尋。

另外還可以透過github來查詢程式碼安全問題,如輸入規則:extension:php mysql_query $_GET,可以搜尋到大量包含mysql_query $_GET的請求,可以有針對性的進行程式碼審計。

git 娛樂:
github 是否能讓我們冒充其他使用者呢?讓我們試下成為linus,透過郵件組收集下大神的郵箱資訊。

透過github 可以搜尋到linus的commit記錄。

結果linus大神的commit記錄出現在了我們的repo源。

該問題後的總結,審計誰可以訪問到你的repos,啟用github雙因素認證。
git配置不當:
如果.git資料夾可以被外網,攻擊者可以透過.git下載所有的程式碼,當前前提是目錄可被遍歷,如果能遍歷可以簡單的獲取到原始碼。

接著執行。

透過在google中輸入查詢語句,*".git" intitle:"Index of”,可以找到幾條記錄。

透過Google找到了一臺配置錯誤的機器,看我們可以訪問到.git目錄

上邊這些程式碼,都可以被我們下載到。如果目錄沒有開放遍歷,可以檢測.git/config

使用dvcs-pillage or dvs-ripper 下載原始碼,dvcs-pillage 也支援HG和GZR檔案格式。 .git 洩漏你可以獲取哪些東西呢,包括配置檔案,原始碼,開發者姓名、公鑰、郵箱地址等,repo記錄,漏洞漏洞刪除的修復記錄、密碼、私鑰等資訊,wordpress配置檔案,站點資料庫備份在.git,會話金鑰等。
svn配置不當:
在svn1.6之前的版本,透過訪問.entries,可以下載到svn裡的程式碼,比如案例: WooYun: 樂視某分站原始碼洩漏
在metasploit裡有利用程式,對應的利用模組是:
auxiliary/scanner/http/svn_scanner。
在svn1.7之後的版本,透過訪問.svn/wc.db,對應的metasploit模組也是有利用程式的,對應的modules是:
auxiliary/scanner/http/svn_wcdb_scanner。
gitlist:
透過google 搜尋關鍵字,powered by gitlist,可以看到可以搜尋到的記錄數為: 897,000 條結果。

在gitlist 4.0及之前版本存在遠端程式碼執行漏洞,漏洞CVE版本號為CVE-2014-4511,該漏洞利用方式為:””whoami
,透過執行該命令可以導致gitlist出現知名錯誤。

在2014年6月29號的時候, 該文章對這個遠端程式碼執行漏洞進行了詳細講解並且給出了漏洞利用程式碼。
部落格地址:http://hatriot.github.io/blog/2014/06/29/gitlist-rce/ 透過該利用程式可以將php木馬寫入到gitlist目錄中,從而獲取許可權伺服器

利用程式碼:

利用方式:

持續整合工具:
hudson是jenkins的前身,是基於Java開發的一種持續整合工具,用於監控程式重複的工作,Jenkins是一個開源軟體專案,旨在提供一個開放易用的軟體平臺,使持續整合變成可能。
透過Google Hacking方法,講hundon輸入到shodan中進行搜尋,可以發現大量使用hundon的伺服器如,hundson搜尋結果。

jenkins搜尋結果。

在Jenkins如果缺少認證,可以訪問/view/ALL/newJob來新建一個build然後執行惡意程式碼如下圖:


另外也可以使用metasploit來進行滲透測試。


透過metasploit來進行利用,可以獲取目標伺服器許可權。

參考:https://www.pentestgeek.com/2014/06/13/hacking-jenkins-servers-with-no-password/ 把邪惡的東西放在/vagrant/.git/hooks/post-commit並等待使用者提交一些程式碼,從使用者掛載/vagrant目錄開始,鉤子就一直在執行,即使使用者銷燬了VM。
kickstart files:
在kickstart中有3種辦法重置使用者密碼,1、安裝過程中 2、在kickstart檔案加密的雜湊" rootpw --iscrypted" 3、在kickstart檔案明文" rootpw --plaintext"
舉個例子


aws config files:
AWS 命令列介面 (CLI) 是用於管理 AWS 服務的統一工具。只透過一個工具進行下載和配置,您可以使用命令列控制多個 AWS 服務並利用指令碼來自動執行這些服務。
aws使用aws商店以明文儲存hiddle申請,這是典型的特權訪問。


客戶端配置工具:
Chef是由Ruby與Erlang寫成的配置管理軟體,它以一種純Ruby的領域專用語言(DSL)儲存系統配置“食譜(recipes)”或“做飯書(cookbooks)”。
Chef由Opscode公司開發,並在Apache協議版本2.0下開源釋出。Chef可在主從式架構之下執行,亦可在名為“chef-solo”的整合配置之下執行。
透過shodanhq來搜尋下“chef server" 可以找到較多執行該服務的伺服器。

透過檢視chef上可以看到登入的帳號密碼,即可完成登入,可以看到較多敏感資訊!所以一定要記得修改預設密碼。

knife 是一個chef命令列實用工具,可以加密及儲存資料包憑證,使用方法例如:


chef/knife 加密資料包:


Vagrant:
你知道如何修改你的ssh keys嗎?Vagrant有預設證照,並且sudo不需要密碼,可以使用metasploit來掃描預設key,如圖:



elasticsearch:
elasticSearch是一個基於Lucene構建的開源,分散式,RESTful搜尋引擎。設計用於雲端計算中,能夠達到實時搜尋,穩定,可靠,快速,安裝使用方便。
elasticsearch 本身沒有訪問控制,任何透過http api搜尋es中儲存的結果,可以用put請求來update儲存結果。elasticsearch早與1.2.0版本中存在遠端程式碼執行漏洞,cve版本號為:CVE-2014-3120
elasticsearch啟動預設埠為9200,可以看到叢集版本資訊如圖:

使用metasploit溢位存在漏洞的叢集,成功獲取許可權。

記憶體資料庫:
redis是一個key-value儲存系統。和Memcached類似,它支援儲存的value型別相對更多,包括string(字串)、list(連結串列)、set(集合)、zset(sorted set --有序集合)和hash(雜湊型別)
redis沒有加密方式,監聽6379 tcp埠,預設redis如果沒有指向監聽內網地址,而對外開放,外網攻擊者可以直接訪問該資料庫。
透過shodan來搜尋redis:6379 關鍵字,可以獲取大量redis資訊:

隨機找一條,可以正常登入,redis-cli 可以指向需要連線的redis ip地址。

memcache:
memcache 是一種分散式快取伺服器,和通常使用的非分散式的ecache不同,memcache需要獨立的伺服器支撐,客戶端透過配置IP地址和埠號(預設11211)與之連線並使用API進行資料的快取操作。
memcached未作IP限制導致快取資料可被攻擊者控制,可被攻擊者控制,透過連線上後可獲取敏感資訊,如圖:

0x03 結語
透過這些案例,讓我們知道,其實安全問題不止來源於web問題,安全問題更來自於運維安全,運維和運維安全的好弱是衡量一個公司安全的基礎!
本文章來源於烏雲知識庫,此映象為了方便大家學習研究,文章版權歸烏雲知識庫!