LoginSignup
0
1

More than 1 year has passed since last update.

Webサーバでソースポート(送信元ポート番号)を取得する

Last updated at Posted at 2021-09-13

背景

昨今のアドレス共有技術(DS-Lite/MAP-Eなど)に関わる問題として「IP アドレスだけではユーザが特定できなくなること」が指摘されており、通信先のサーバなどでアクセスしてきた送信元ポート番号、正確なタイムスタンプを取ることをRFC6302では推奨しています
もちろん、記録されたログが保全(改ざんされていないなど)されることも重要ですね

で、本題

どうやるか?
(アドレス共有技術の適用はIPv6とセットにされることが多いので、サーバのIPv6化すればいいのですが、ここではおいておいて)

apache httpdの場合

こんなconfigを設定可能です
%{remote}p の部分ですね

httpd.conf
LogFormat "[%h]:%{remote}p %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "[%h]:%{remote}p %l %u %t \"%r\" %>s %b" common

出力

[xxx.xxx.xxx.xxx]:47716 - - [08/May/2013:10:26:10 +0900] "GET / HTTP/1.1" 200 4658 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)"

AWS ELBの場合

X-Forwarded-Portを使えればいいのですが、これはサーバ側(送信先ポート番号)です
なので、ALB/ELBでアクセスログを取得するしかありません。

方法は、ALB/ELBの属性の編集から、アクセスログを有効化します。指定のS3バケットに保存されます。
Screen Shot 2021-09-13 at 22.01.20.png
Screen Shot 2021-09-13 at 22.01.41.png

このログのclient:portに保存されます

AWSLogs/xxxxxxxxxxxx/elasticloadbalancing/ap-northeast-1/2021/MM/DD/xxxxxxxxxxxx_elasticloadbalancing_ap-northeast-1_app.ELB01.xxxxxxxxxxxxxxxx_2021MMDDT0000Z_xx.xxx.xx.xx_xxxxxxxx.log.gz

http 2021-MM-DDTHH:MM:SS.nnnnnnZ app/ELB01/xxxxxxxxxxxx xx.xx.xx.xx:1614 172.xx.xx.xx:80 0.002 0.003 0.000 200 200 433 4288 "GET http://xxxxxxxxxxxxxxxx:80/hogehoge.txt HTTP/1.1" "Mozilla/5.0 (Linux; Android 7.0;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible)" - - arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:targetgroup/TG01/xxxxxxxxxxxx "Root=1-xxxxxxxxxxxx "-" "-" 2 2021-MM-DDTHH:MM:SS.nnnnnnZ "forward" "-" "-" "172.xx.xx.xx:80" "200" "-" "-"

詳細は公式ドキュメント AWS Application Load Balancer のアクセスログ  をご確認ください

0
1
0

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
0
1