14
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

短縮URLの危険性を検証してみる

Last updated at Posted at 2017-10-11

はじめに

短縮URL便利だなーと使っていたところ適当に入力した短縮URLに個人情報が書いてあったのでちょっと怖くなった…ということがあったので今回はその危険性は検証してみたいと思います!

どう危険なのか

もうお分かりかとは思いますが、例えばスプレッドシートをリンクを知っている全員に公開とした場合見られちゃう。
個人情報が書いてあろうものならもう悲惨ですよね。。。

とりあえず検証

Google URL Shortener(goo.glで始まるアレ)のURLが存在するかひたすらリクエストを送って検証。
今回はみんな大好きRubyでやってみます。

# 文字列を生成するためのリスト
list = [*'a'..'z', *'A'..'Z', *'0'..'9']
# リストからランダムで文字を取得
short_uri = "https://goo.gl/"+ 6.times.map { list.sample }.join
# =>"https://goo.gl/123ABc"

まず、前提条件としてGoogle URL Shortenerは英数字(0-9, a-z, A-Z)が6文字らしい。
なので(0-9, a-z, A-Z)も文字列のリストを作り、その中からランダムで6文字取得しURLを生成する。

次はURLの存在を確認してみる!

require 'net/http'

Net::HTTP.get_response(URI.parse("確認するURL"))
# =><Net::HTTPMovedPermanently 301 Moved Permanently readbody=true>

Net::HTTP.get_response()で指定したURLのレスポンスを取得。
Google URL ShortenerはURLが存在する場合Net::HTTPMovedPermanentlyが返ってくるらしい。

完成コード!!

URLShortening_isDanger.rb
require 'net/http'

def generate_uri
  list = [*'a'..'z', *'A'..'Z', *'0'..'9']
  short_uri = "https://goo.gl/"+ 6.times.map { list.sample }.join
end

def request_uri(uri)
  response = Net::HTTP.get_response(URI.parse(uri))

  case response
  when Net::HTTPMovedPermanently
    puts uri
  end
end


50.times {
  request_uri(generate_uri)
}

URLShortening_isDanger.rb我ながらに良いネーミングセンスだと思う。

今回は50回適当なURLを叩いて見ました。

結果として、やってみると結構URLがでるでる。
簡単に見つけられちゃうから怖いですね。。。

まとめ

短縮URLはかなり便利だけど使い方はちゃんと考えた方が良さそう。(誰に見られても大丈夫なものだけに使おう)
今回の件以外にも悪質なサイトに飛ばされるなどいろんな問題があるみたい。

最後に

今回のソースコードはGitHubにあるのでよければissueなりコメントなりください!
https://github.com/h-akaishi/URLShortening

14
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?