<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Php on ashitaka blog</title>
    <link>https://8fd9c3c3.blog-1xe.pages.dev/tags/php/</link>
    <description>Recent content in Php on ashitaka blog</description>
    <generator>Hugo</generator>
    <language>ja-jp</language>
    <lastBuildDate>Fri, 17 May 2019 04:44:56 +0900</lastBuildDate>
    <atom:link href="https://8fd9c3c3.blog-1xe.pages.dev/tags/php/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>第4回CTF勉強会 | ksnctf</title>
      <link>https://8fd9c3c3.blog-1xe.pages.dev/2019/05/17/ctf-4/</link>
      <pubDate>Fri, 17 May 2019 04:44:56 +0900</pubDate>
      <guid>https://8fd9c3c3.blog-1xe.pages.dev/2019/05/17/ctf-4/</guid>
      <description>&lt;p&gt;今日は4人しかこなかった&amp;hellip; 火曜の8:45からってのがきつすぎるんかな&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;31-kangacha&#34;&gt;31 Kangacha&lt;/h2&gt;
&lt;p&gt;PHPで書かれた簡単なwebアプリケーションの問題. Gachaというボタンを押せば日本の戦艦の名前がランダムでリストに追加されていく. ソースコードも与えられているので読んでいく.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
if (isset($_POST[&amp;#39;submit&amp;#39;]))
{
    //  Gacha
    if ($_POST[&amp;#39;submit&amp;#39;] === &amp;#39;Gacha&amp;#39;)
    {
        //  Yamato is ultra rare
        $ship[] = mt_rand(0, count($shipname)-2);
        $s = implode(&amp;#39;,&amp;#39;, $ship);
        $sign = hash(&amp;#39;sha512&amp;#39;, $salt.$s);
        setcookie(&amp;#39;ship&amp;#39;, $s);
        setcookie(&amp;#39;signature&amp;#39;, $sign);
    }
    //  Clear
    if ($_POST[&amp;#39;submit&amp;#39;] === &amp;#39;Clear&amp;#39;)
    {
        setcookie(&amp;#39;ship&amp;#39;, &amp;#39;&amp;#39;, 0);
        setcookie(&amp;#39;signature&amp;#39;, &amp;#39;&amp;#39;, 0);
    }
    header(&amp;#34;Location: {$_SERVER[&amp;#39;REQUEST_URI&amp;#39;]}&amp;#34;);
    exit();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;このソースから, &lt;code&gt;$_COOKIE[&#39;ship&#39;]&lt;/code&gt;に戦艦の番号の配列が, &lt;code&gt;$_COOKIE[&#39;signature&#39;]&lt;/code&gt;にあらかじめ決められた&lt;code&gt;$salt&lt;/code&gt;と戦艦番号のハッシュ値が格納される.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
//  Check signature and read
if (isset($_COOKIE[&amp;#39;ship&amp;#39;]) and
    isset($_COOKIE[&amp;#39;signature&amp;#39;]) and
    hash(&amp;#39;sha512&amp;#39;, $salt.$_COOKIE[&amp;#39;ship&amp;#39;]) === $_COOKIE[&amp;#39;signature&amp;#39;])
    $ship = explode(&amp;#39;,&amp;#39;, $_COOKIE[&amp;#39;ship&amp;#39;]);
else
    $ship = array();
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ここで&lt;code&gt;$_COOKIE[&#39;signature&#39;]&lt;/code&gt;のバリデーションを確認され, 不正であれば配列の中身が空になってしまう.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
