Lab1: Basic server-side template injection

https://portswigger.net/web-security/server-side-template-injection/exploiting/lab-server-side-template-injection-basic

進入以上網頁後按access the lab進入以下畫面,按下view details後會發現下圖的2跑出來。

把把burp給intercept on後再重複一次剛剛的操作,可以發現上圖2的文字其實是發送了一個get請求,message的後面會接東西。我們按右鍵把這一些東西送進repeater來試試看message能不能塞入一些別的東西:

參考以下網頁:

SSTI (Server Side Template Injection) - HackTricks

根據題目提示,看上圖的ERB的東西,並把上圖紅底線的東西塞到message後面如下圖左上角的底線:

可以發現網頁會把它解析成49,如上圖右下角底線。可以再依照上上張圖下方的一些指令試試看:

<%= system("whoami") %>

回到proxy,實際送刪除的指令:

一直按forward,沒得按後再重新整理網頁,即可解題。

Lab2: Basic server-side template injection (code context)

https://portswigger.net/web-security/server-side-template-injection/exploiting/lab-server-side-template-injection-basic-code-context

進入以上網頁後按access the lab進入以下畫面:

按上圖view post進入下圖網頁,並按下圖紅圈登入。

可以發現文章底下有評論。容易有SSTI的部分是使用者名稱跟評論。

登入:

按底下Preferred name選單選別的,記得在那之前burp需要intercept on:

可以發現下圖紅圈處,這是可以SSTI的洞:

依題目提示找Torando:

試著改一改如下圖紅圈,按forward送出:

可以發現的確名稱變64:

所以可以開始送指令:

}}{%25+import+os+%25}{{os.system('whoami')

}}{%25+import+os+%25}{{os.system('rm%20/home/carlos/morale.txt')

一直forward到結束,再去重新整理有評論的那個頁面,即可成功執行刪除動作。

Lab3: Server-side template injection using documentation

https://portswigger.net/web-security/server-side-template-injection/exploiting/lab-server-side-template-injection-using-documentation

進入以上網頁後按access the lab進入以下畫面:

點上圖右上角紅圈登入:

登入後點下圖右上角紅圈回到首頁:

回到首頁後,隨便點進去一個,比如說下圖紅圈:

進去後發現這是可以編輯的:

點上圖紅圈後會出現編輯器如下圖,其中可能有SSTI弱點如下圖底線:

參考以下網頁:

https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#smarty-php

測試7*7是不是真的會算出來

看上圖下方底線,的確是會。那麼回到

https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#smarty-php

去找找有一樣式子的不同語言範例,比如下圖:

試試上圖紅線,貼上如下圖:

從上圖看可以發現出現錯誤,但上圖的下面紅圈顯示了它是FreeMaker,所以再從

https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#smarty-php

找一下,如下圖:

照抄上圖紅底線貼上,如下圖:

看上圖反藍處,可知linux指令id有確實執行。

試試ls -al,來看看指令裡空白有沒有問題。看來也是ok,而且也看到了morale.txt如上圖下面紅圈。

Lab4: Server-side template injection in an unknown language with a documented exploit

https://portswigger.net/web-security/server-side-template-injection/exploiting/lab-server-side-template-injection-in-an-unknown-language-with-a-documented-exploit

點上圖的access the lab後進入如下畫面:

可以發現點了上圖的紅圈處,會出現箭頭指向的文字。試著把burp打開且intercept on,再按一次上圖紅圈處,攔截到的request如下:

上圖左邊紅線處就是SSTI的注入點。改成{{7*7}}後報錯,從右半邊的報錯訊息,可以看到右邊底線處顯示是handlebars,於是去下列網址找找有關handlebars的SSTI資訊:

https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#handlebars-nodejs

可以發現上圖紅圈處就是payload。也可以試試看自己產生payload,把上圖紅圈處那一大段複製(會執行whoami)到下圖的上面大框框,再選擇encoded成url,即可生成一樣的payload。

把這一長串貼到message後面如下圖(先在repeater試試),可以發現會正常response,且下圖右半邊紅圈代表指令有執行。

確定可行後,把那一大段之中的whoami改成題目要的rm morale.txt,用同樣方式encode生成payload。

這一次來正式的,所以是切到proxy,把payload貼到message後面:

按forward一直按直到沒得按,再重新整理頁面,即可解題。

參考:

https://blog.csdn.net/m0_53008479/article/details/127799085

Lab 5: Server-side template injection with information disclosure via user-supplied objects

https://portswigger.net/web-security/server-side-template-injection/exploiting/lab-server-side-template-injection-with-information-disclosure-via-user-supplied-objects

按上圖access the lab進入下圖頁面:

點上圖紅圈進行登入:

用題目提示的帳密登入後,按下圖紅圈回到列表:

回到列表如下圖,按下圖紅圈:

按完後進入下圖頁面,再按下圖紅圈:

可以發現下圖template編輯器,有很明顯的SSTI注入處如下圖反藍:

payload參考:

https://github.com/Lifars/davdts

用了其中的{% debug %}的確可以爆出一些東西不會報錯。

根據下面網頁:

https://www.k0rz3n.com/2018/11/12/%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%B8%A6%E4%BD%A0%E7%90%86%E8%A7%A3%E6%BC%8F%E6%B4%9E%E4%B9%8BSSTI%E6%BC%8F%E6%B4%9E/#1-Django

(一篇文章带你理解漏洞之SSTI漏洞)

可以發現別人爆出key是用下圖所提payload:

不過這一題沒這麼複雜,只要setting.SECRET_KEY即可,答案如下圖反藍處:


#SSTI: ERB #SSTI: 藏的深 #SSTI: import其他函式庫、多行變一行payload #SSTI: 報錯以找出使用template #SSTI: handlebars找key







Related Posts

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 9

AWS Solutions Architect - Associate (SAA) 學習計畫與備考心得: Module 9

PHP、MySQL 語法基礎

PHP、MySQL 語法基礎

Bicycle Kinematic Model 筆記

Bicycle Kinematic Model 筆記


Comments