よーでんのブログ

One for All,All for わんわんお!

WSL2のcurlをburpに経由させたい!

WSL2のcurlをburpに経由させる

  • ip制限の都合でburpのupstream proxy serversでproxyの設定をしている
  • curlをしたいが、proxyに通せないのでipが変わってしまう

ということに困ったので、書く。

summary

以下で自分のグローバルipが見れる。

$ curl http://httpbin.org/ip
{
  "origin": "xx.xx.xx.xx"
}

-xでプロキシを指定できるという記事を見つけたため、試してみる。

$ curl http://httpbin.org/ip -x http://localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

localhost:8080にburp proxyがあるはずなのに、うまくいかない
WSLあるある(?)のlocalhost問題だ。

solve

proxyのoptionsタブからipを指定する。

f:id:y0d3n:20210614192425p:plain
bind to address

ipはたぶん127.0.0.1以外だったらどれでもよさそう。ここでは192.168.33.1を選択した。
このプロキシのipを指定して、再度curlしてみる。

$ curl http://httpbin.org/ip -x http://192.168.33.1:8080

burpに経由され、burpで編集できる状態になる。

f:id:y0d3n:20210614192730p:plain
intercept

結果、proxyのipになっているのが確認できる。

$ curl http://httpbin.org/ip -x http://192.168.33.1:8080
{
  "origin": "yy.yy.y.yy"
}

HTTPSに対応したい

この状況だと、証明書関連の影響でHTTPScurlできない。
(-kでできるようになるけど)

$ curl https://httpbin.org/ip -x http://192.168.33.1:8080
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

burpの証明書をcurlによしなにしてあげる必要がある。
cacert.derをダウンロードし、pemに変換。

$ openssl x509 -inform der -in cacert.der -out burp.pem

lsとかすると、burp.pemが作成されてるはず。
それを指定してcurlしてみる。

$ curl https://httpbin.org/ip -x http://192.168.33.1:8080 --cacert burp.pem
{
  "origin": "yy.yy.yy.yy"
}

無事HTTPSでもcurlできた。

オプションの省略

何回もcurlする場合、いちいち-xとかついてるのは不格好なので、設定ファイルに書き込んじゃう。

$ cat .curlrc
proxy = "http://192.168.33.1:8080"
cacert = "/home/y0d3n/burp.pem"

.culcrcに2行書けばただcurlをするだけでburpを通して通信できる。

$ curl https://httpbin.org/ip
{
  "origin": "yy.yy.yy.yy"
}