Bounty 初體驗 - 資安

Table of Contents

※ 引述《CMJ0121 (不要偷 Q)》之銘言:
> 在待業的過程中 繼續找零用錢
因為之前有回報過 Synology 邀請我參加 7.0 beta 的測試 時間軸如下

2020-12-10 -> 收到邀請
2020-12-29 發送第二次回報 <-
2021-01-29 -> 終於確認受理範圍與獎金 (預計 2/29 發金)
同時宣告不能在 2021-03-29 前公布細節
2021-02-29 (沒收到 $$)
2021-03-03 還沒收到 $$ 寄信詢問 <-
2021-03-04 -> 表示會計問題 延遲發放
2021-03-15 寄信詢問發放時間 <-
2021-03-17 -> 宣稱 3/31 會發放獎金
2021-03-31 -> 表示發生意外、會額外寄送禮物表示歉意
2021-04-27 -> 已收到禮物
2021-05-03 -> 已收到獎金 <- 現在 (結案)


這次找到比較有趣的漏洞 是屬於 misconfiguration[0] 的類型

透過審慎 review 數千行 nginx 後 發現一個設定錯誤 在 nginx 設定檔中有很多重複出現下面的設定

location ~ ^/volume(?:X|USB|SATA|Gluster)?\d+/ {
internal;
root /;
open_file_cache off;
include conf.d/x-accel.*.conf;
}

在 nginx 官方文件描述[1] 設定 internal 的 location

只能被內部存取 (internal requests) 如果需要外部存取則需要透過

- error_page / index / random_index / try_files 做重導向
- 來自 upstream 且有 X-Accel-Redirect 這個額外 header 的重導向
- 透過 rewrite 的指定路徑





很明顯的 在這個 location 下可以存取的檔案都屬於高價值 (bounty 應該也比較高)

按照上面的可存取方式 最後發現幾個沒有正確的設定 像是

location ~ ^/oo/t/ {
rewrite /oo/t/([0-9a-zA-Z_.]+)$ /webman/3rdparty/Spreadsheet/index.html last;
rewrite /oo/t/(.*) /$1 last;
include scgi_params;
scgi_pass synoscgi;
}

透過 nginx 存取 /oo/t/ 開頭的路徑時 會做 redirect 判斷

- 符合 /oo/t/`數字、字母、底線、. 的組合` -> /webman/3rdparty/Spreadsheet/index.html
- 其他狀況 -> 其他狀況

表示如果存取 /oo/t/abcde 就會連到 /webman/3rdparty/Spreadsheet/index.html

但是連到 /oo/t/ab/cde 就會連到 /ab/cde

結合最開始的找到有趣的 inernal location 規則

就可以用 /oo/t/volumnX/Y/Z 存取 /volumnX/Y/Z 下的檔案了


## How to fix ##
其實解決方式也很簡單 Synology 的開發者其實也知道

就是在有機會做 redirect 的 location 下額外下 root 就可以 像是下面這個規則就不存在這個漏洞

location ~ ^/mo/sharing/(.+)\.cgi {
root /usr/syno/synoman; # <-- 關鍵的一行
rewrite /mo/sharing/(.+) /$1 break;
include scgi_params;
scgi_read_timeout 3600s;
scgi_pass synoscgi;
}


## 警語 ##
打 bounty 賺零用錢是不錯 如果想要當正職可能需要思考一下

尤其當公司方因為若干原因還不給你錢的時候 ...


[0]: https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration
[1]: http://nginx.org/en/docs/http/ngx_http_core_module.html#internal

--

All Comments

Gilbert avatarGilbert2021-04-05
推推
Isla avatarIsla2021-04-09
現在處理 bounty 真的有點慢 XDrz
Gary avatarGary2021-04-13
To: 樓上。沒辦法 你也知道現在已經變成怎樣了 XD
Joseph avatarJoseph2021-04-18
這樣大的公司沒提早給就算了,還拖那麼久
Irma avatarIrma2021-04-22
Elma avatarElma2021-04-26
推推
Kumar avatarKumar2021-05-01
更新一下進度
Dorothy avatarDorothy2021-05-05
獎金還沒給...
James avatarJames2021-05-09
最後更新:已收到獎金。歷時 N 天 :)