利用 Cloudflare Workers 繞過 Cloudflare 自家的阻擋機制

Hacker News 首頁上看到「How to bypass Cloudflare bot protection (jychp.medium.com)」這則,裡面的文章是「How to bypass CloudFlare bot protection ?」這篇,利用 Cloudflare Workers 繞過 Cloudflare 自家的 CAPTCHA 機制。

這個漏洞有先被送給 Cloudflare,但被認為不是問題,所以作者就決定公開:

Several months ago I submitted what appeared to be a security flaw to CloudFalre’s bugbounty program. According to them, this is not a problem, it’s up to you to make up your own mind.

技術上就是透過 Cloudflare Workers 當作 proxy server,只是看起來 Cloudflare 對自家 IP 有特別處理,在設定妥當後,用 Cloudflare Workers 的 IP address 去連 Cloudflare 的站台,幾乎不會觸發 Cloudflare 的阻擋機制。

不過 free tier 還是有限制,主要就是數量:

The first 100,000 requests each day are free and paid plans start at just $5/10 million requests, making Workers as much as ten-times less expensive than other serverless platforms.

作者也有提到這點:

So let’s enjoy the 100 000 request/day for your free Cloudflare account and go scrape the world !

但這是個有趣的方法,加上信用卡盜刷之類的方式,這整包看起來就很有威力...

Cloudflare 改用自己的 CAPTCHA 服務 hCaptcha

CloudflareGooglereCAPTCHA 改用自家的 hCaptcha:「Moving from reCAPTCHA to hCaptcha」。

看起來其實就是錢的問題,reCAPTCHA 要收費了,而以 Cloudflare 的量會太貴:

Earlier this year, Google informed us that they were going to begin charging for reCAPTCHA. That is entirely within their right. Cloudflare, given our volume, no doubt imposed significant costs on the reCAPTCHA service, even for Google.

另外 hCaptcha 有提供免費版本給一般網站用,剛出來這幾天等白老鼠寫心得後,再決定要不要跳進去測試...

用 PoW 當作防機器人的方式

看到「wehatecaptchas」這個服務試著用 PoW (Proof of work) 擋機器人...

這個方式不需要像 GooglereCAPTCHA 那樣蒐集大量行為 (對隱私不利),也不需要解一堆奇怪的圖片問題。

CAPTCHA 最常用的領域,也就是擋 spam 這件事情來說,PoW 這樣的單一方式應該是不夠,但可以當作綜合方法裡面的一種...

破 reCAPTCHA 的 Buster

在「用 Google 的 Speech Recognition API 破 Google 的 reCAPTCHA」與「reCAPTCHA 與語音辨識:以子之矛,攻子之盾」都提過用語音辨識功能破 reCAPTCHA,現在又有一套了,而且直接在各瀏覽器的 extension 平台上架:「Buster: Captcha Solver for Humans」。

說明可以看到一樣是透過聲音的部份辨識:

Buster is a browser extension which helps you to solve difficult captchas by completing reCAPTCHA audio challenges using speech recognition. Challenges are solved by clicking on the extension button at the bottom of the reCAPTCHA widget.

除了安裝很簡單以外,設定也弄得很簡單,這個套件支援多種不同語音辨識 API,包括 GoogleMicrosoft 以及 IBM 的服務,只要在套件的設定頁輸入 API key 就可以了...

另外剛好也跟 reCAPTCHA 有關,在 Hacker News 上的「Google's Captcha in Firefox vs. in Chrome (grumpy.website)」看到 Google Chrome 與 Mozilla Firefox 在跑 reCAPTCHA 的不同之處 (Chrome 的流程順很多,Firefox 卡很多),不過我覺得證據還有點弱,需要再看其他的測試...

另外裡面有提到一些奇怪的東西,像是 W3C 的替代方案 (這個組織提的東西...):「Inaccessibility of CAPTCHA」,找時間來研究一下...

reCAPTCHA 與語音辨識:以子之矛,攻子之盾

GooglereCAPTCHA 大概是目前最常用的反制機器人工具了,但因為 accessibility 的原因 (而且應該是有法令要求),還是需要提供盲人可以存取的方式,也就是以語音判斷是否是機器人。

unCaptcha2 就是用這塊,加上 Google 自家的語音辨識 API (也支援其他家 API) 可以直接打穿:

現有的程式碼已經先被 Google 反制,但目的是展示出這樣的概念。

砍站的技巧?

Hacker News 上看到的文章,講如何用 JavaScript 砍站:「I Don’t Need No Stinking API – Web Scraping in 2016 and Beyond」。

引起注意的是「Beating CAPTCHA」這邊,直接拿 Antigate 的服務 (付費服務) 來打穿 CAPTCHA,看了一下價錢:

Cheapest price on the market - starting from 0.7USD per 1000 images, depending on the daily volume

唔,這服務這好像頗不賴... 記錄起來用 :o

利用 CloudFlare 的 reCAPTCHA 反向找出真正的 Tor 使用者

Cryptome 這邊看到可能可以被拿來用的技巧:「Cloudflare reCAPTCHA De-anonymizes Tor Users」。

Tor 使用者連到 CloudFlare 上時,常常會出現 reCAPTCHA 的提示,要求你驗證,而這個驗證過程的 traffic pattern 太龐大而且很明顯,當情治單位同時可以監控 CloudFlare 的上游 (像是「Airtel is sniffing and censoring CloudFlare’s traffic in India and CloudFlare doesn’t even know it.」這篇提到的問題) 或是監控 Tor 的 exit node 的上游,再加上同時監測使用者可能的 ISP,就可以對照湊出使用者:

Each click on one of the images in the puzzle generates a total of about 50 packets between Tor user's computer and the Cloudflare's server (about half are requests and half are real-time responses from the server.) All this happens in less than a second, so eventual jitter introduced in onion mixing is immaterial. The packet group has predictable sizes and patterns, so all the adversary has to do is note the easily detectable signature of the "image click" event, and correlate it with the same on the Cloudflare side. Again, no decryption required.

短短的一秒鐘內會產生 50 個封包,而且 pattern 很清楚...

用 Tesseract OCR 解 CAPTCHA

在「python 乌云账号暴力猜解工具」這邊看到 Tesseract OCR 這個 command line 工具,比想像中的簡單很多...

Tesseract OCR 最新版是 2012 年出的,所以也不需要另外用 ppa 安裝,在 Ubuntu 下可以直接用 apt-get 安裝到 3.02 版:

# apt-get install tesseract-ocr

隨便抓張 CAPTCHA 後直接跑就可以了,像是這張:

跑出來的結果:

$ tesseract a.gif a
Tesseract Open Source OCR Engine v3.02 with Leptonica
$ cat a.txt
8308

預設的輸出檔名會加上 .txt 是比較討厭的地方,不然就可以用 /dev/stdout 當作輸出檔名處理掉...

關於重設密碼的步驟

這應該有很標準的程序,不過好像還是有很多站沒這樣做...

必要的步驟包括:

  • 如果使用者只記得 username,輸入後告知使用者「已經發送確認信至 username 當初所註冊的信箱」。
  • 如果使用者只記得 e-mail,輸入後告知使用者「已經發送確認信至該 e-mail」,如果該 e-mail 沒有被註冊也不要有不同的訊息,因為如果可以判斷 e-mail 有沒有不同的訊息,可以利用這個功能大致判斷某個人有沒有註冊這個服務。
  • 基本上都要加上 CAPTCHA 以及對 IP rate limit 避免有人利用這個行為惡搞。

要注意的是要透過「確認信」的步驟再改密碼,而不能在要求重設密碼時就馬上把密碼改掉,不然就可以惡搞使用者。