起因:這是很早的文章了,當初團隊師傅想看H片,奈何不想花錢購買,然後審計了H站自助提卡系統,並收穫了80G種子1
前言
並非有意願要審計該站,前面的走的黑盒沒有過於精彩部分就不在貼上了,對於此係統站你們懂的,多說無益,這套程式是開源的,像這種自助提卡系統相信大家已經不在陌生了,很多違法網站通過這種平臺方式提卡密的相當於購買邀請碼,原始碼是小夥伴提供的,採用的是php+mysql進行開發的24小時自動售卡平臺,廢話就不多說了。
相關環境
原始碼資訊:你猜啊
漏洞型別:Forwarded-For注入
搭建成功之後如下 :
看到如下頁面是不是有似曾相識的感受:

上圖是安裝過後的首頁,就是一個提卡網,繼續吧繼續!

這是首頁檔案,進去首先判斷了install目錄下的lock檔案是否不存在並且判斷是否有index.php檔案,如果滿足以上條件就跳轉到install目錄下的index.php,我們跟進install/index.php檔案:


這裡我們只看判斷是否安裝過程式,判斷是否存在lock檔案並且step不等於5的情況下就執行判斷語句中的程式碼,當然這裡如果header函式後沒有exit就會存在重灌漏洞。
我們接著看index.php,光是index.php檔案就用413行程式碼,程式碼都不規範,所以我們先看看其它檔案,看看api.php檔案:

這裡很明顯我們看到了SQL隱碼攻擊,首先判斷是否設定了$_POST[“dh”]再判斷$_POST[“dh”]不為空則將該引數拼接到SQL語句中,看到這裡就可以判斷出該程式存在聯合查詢注入,可是$config哪來的,這個檔案也沒包含其它的檔案啊!!!怎麼辦呢?那麼我們就來找找index檔案中是否包含了api.php,search一下

可以看到在294行這裡包含了api.php檔案,我們構造下放入sqlmap中玩一玩
Python sqlmap.py -u “http://localhost:8081/index.php” --batch --dbms=”mysql” --data=”dh=a”

這裡可以看到注入型別確實是聯合查詢,我們接著嘗試下這個提卡網是否存在SQL隱碼攻擊
Python sqlmap.py -u "http://xxxx.pw/index.php" --batch --dbms="mysql" --data="dh=a"

我們嘗試本地站點的時候毫無問題,可是為啥這個提卡網就存在問題了呢?很明顯這個網站可能是升級或者二開過的,我們接著看看其它點,進入./pay/pay.php檔案





程式碼過多就不一一貼圖出來了,主要構成漏洞的程式碼就在這其中,我們從38行開始看著走
這裡判斷$_GET[“type”]等於delete的時候則執行40-49行的程式碼,41將獲取到的ip拼接到sql語句中,我們看看ip函式:


這裡可以看到程式獲取ip可以從客戶端的頭引數中獲取,分別為HTTP_X_FORWARDED_FOR,HTTP_CLIENT_IP,這個函式真的僅僅是獲取外部傳遞的引數的,一點也沒有過濾,我們看到了這裡就可以嘿嘿嘿了,基本上這個網站拿下了,我們接著看看,回到41行,再看下邊的,我們不宜在這裡進行SQL隱碼攻擊,因為接著會將查詢到的值又進行下一個SQL語句的拼接,這樣返回值就不準確,用工具的過程就很難判斷了,我們跳出這裡的判斷,看看51-54行分別判斷了$_GET['type'],$_GET['money'],$_GET['title'],$_GET['pwd']這幾個引數存不存在,所以我們這裡可以這樣構造get引數:type=a&money=1&title=adssad&pwd=123
我們接著看下邊的,第58-65行,首先是判斷了type是否等於zfb,若不等於則退出當前程式並列印Tip:Type error!,所以我們還得接著改改get引數:
type=zfb&money=1&title=adssad&pwd=123
接下來,可以看到67行中再次將獲取到的ip拼接到了SQL語句中,我們這樣來,在67行的下邊列印出當前執行的SQL語句

好了,現在我們開啟burp進行抓包,然後偽造ip進行一系列的嘿嘿嘿了,因為./pay/index.php中包含了pay.php,所以我們對index.php進行注入就好
復現:
訪問http://localhost:8081/pay/index.php?type=zfb&money=1&title=adssad&pwd=123

可以看到這是一個很正常的頁面了,並且列印出了SQL語句,我們抓包


正常頁面:

錯誤頁面:

好的,現在看到了吧!我們放到SQLmap中跑一下看看,我們將這個資料包儲存到文字中,並且標註注入位置

Python sqlmap.py -r test.txt --batch --dbms="mysql"

我們對那個網站測試一番,訪問:http://xxxxx.pw/pay/index.php?type=zfb&money=1&title=adssad&pwd=123

可以看到缺少spid引數我們加上繼續訪問:
http://xxxxxx.pw/pay/index.php?type=zfb&money=1&title=adssad&pwd=123&spid=1

把該資料放到文字中,接著進行測試:

Python sqlmap.py -r test.txt --batch --dbms="mysql"

成功挖掘到了該網站的漏洞,繼續。。。。

Python sqlmap.py -r test.txt --batch -D yulinxscom --tables

Python sqlmap.py -r test.txt --batch -D yulinxscom -T admin --dump

成功拿到了管理賬號及密碼。。。。。接著來
預設後臺:http://xxxxx.pw/admin.php

由於之前進去過一次,讓他虧損了點錢,現在後臺的名字也改了 。
寫在結尾
跟此網站的搭建人聊了會,從去年11月份搭建平臺以來已獲利普通人一年的薪資。為了養家餬口,冒此風險也是不容易,切勿為了蠅頭小利以身試法,就這樣做個記錄,到此為止吧。
文中提及技術細節,僅作交流,請勿用於非法活動!!