HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
      • Create new note
      • Create a note from template
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ## Nookcrypt ### Challenge Summary > Tom Nook is testing a new encryption scheme for nookphones, but it seems to be a bit faulty... can you break it? The challenge description tells us that we're doing something ECC related, and that we've got to exploit a fault attack somewhere. We're presented with a service with the following functionality ![](https://i.imgur.com/fdgngxS.png) 1. Gives us an encrypted version of the flag, and the string 'hello world'. If we run it enough, we observe that we occasionally get different results, clueing us into this having an error. 2. We enter a message 'x' and get Enc('x'). This is confirmed to be non-faulty via challenge hints ### Solution #### Recovering the curve Since encryption returns two large numbers, we assume that these are elliptic curve points. Since (2) is non-faulty, we expect these to be on the curve, and so we use them to recover the curve. We further assume that the elliptic curve is of large characteristic, and not on an extension field. This means that the curve is the set of all points ${x, y}$ s.t. $y^2 \equiv x^3 + ax + b\pmod p$, for fixed parameters $[a, b, p]$. Given many elliptic curve points $(x_i, y_i)$ we want to recover the base field $F_p$ and parameters of the elliptic curve. The idea for doing this is to first recover $p$ by making many expressions that we can evaluate which are $0 \pmod p$, and then taking the GCD of them. Afterwards, recovering the elliptic curve $a, b$ is easy. Recall that Therefore if subtract two such equations for $(x_i, y_i)$ and $(x_{i+1}, y_{i+1})$ and re-arrange, we get $$y_{i}^2 - y_{i+1}^2 - (x_i^3 - x_{i+1}^3) = a(x_i - x_{i + 1}) \pmod p$$ For brevity, let $c_i := y_{i}^2 - y_{i+1}^2 - (x_i^3 - x_{i+1}^3)$ We can rewrite this as $a \equiv c_i(x_i - x_{i+1})^{-1} \pmod p$ However we can make a similar such expression for $a$, for every pair of points $(x_i, x_{i+1})$. Setting two such expressions equal to one another, we get $$c_{i+1}(x_{i+1} - x_{i+2})^{-1} \equiv c_i(x_i - x_{i+1})^{-1} \pmod p$$ We can't actually evaluate this due to the modular inverse, so we multiply both sides by the inverses. Finally, we rearrange to get something $0 \pmod p$: $$c_{i+1}(x_i - x_{i+1}) - c_i(x_{i+1} - x_{i+2}) \equiv 0 \pmod p$$ We can evaluate the left hand side over the integers, since we know all the constituent terms. Therefore we take the GCD of many such expressions to recover $p$. To recover $a$ use the expression for $a$ derived before, and finally to recover $b$ use the elliptic curve equation. Doing this we've recovered the elliptic curve. #### Recovering the encryption function Since this is sourceless, we guess that we don't actually have an encryption function, and instead $Enc(x) = xG$, G being the elliptic curve generator. To test this, we send $Enc(1)$ to the server and set $G$ to this value, and choose $x$ at random, and get $Enc(x)$ and just check if $xG = Enc(x)$. It turns out that this is true. ![](https://i.imgur.com/wzu67B7.jpg) #### Sicing the flag Finally time to get the flag. Our goal is essentially to recover the discrete logarithm of $Enc(Flag)$, leveraging the fact we have faulty computations of $Enc(Flag)$. They clarified that the error model is an odd one, where the prime $p$ of the elliptic curve is corrupted to $p'$ throughout the entire encryption, and corrupted in the same way for Enc(flag) and Enc("hello world"). So what does it mean if the prime $p$ is corrupted to $p'$ and we actually do computations on the Elliptic curve $y^2 \equiv x^3 + ax + b \pmod{p'}$? First, with overwhelming probability our generator $G$ is not actually on this elliptic curve. However, for any EC point $Z$, and numbers $a, p'$, there exists a $b'$ such that $Z$ is on the elliptic curve with parameters $[a, b', p']$. Exercise: Convince yourself of this =). Recall that on a short weierstrass curve, the addition and point doubling laws don't depend on $b$. Therefore it is perfectly fine to consider our $G$ as being on the curve $y^2 \equiv x^3 + ax + b' \pmod{p'}$. With overwhelming probability, this curve is weak, so we can do small subgroup attacks to recover the discrete log modulo distinct small primes. (This high level attack idea is basically the same as [invalid curve attacks](https://web-in-security.blogspot.com/2015/09/practical-invalid-curve-attacks.html), sans the different prime $p'$.) We then repeat for different corruptions to recover the flag modulo many small primes, and finally just CRT to recover the flag. Moreover, we find that sometimes $p'$ is not actually a prime, but instead has factors $cd$. In these cases, you really have two elliptic curves with the same $a,b$ parameters, just one mod $c$ and one mod $d$. This makes breaking such curves even easier. ##### Recovering the faulty $b', p'$ parameters All thats left is to describe how we get the new curve parameters $b'$ and $p'$. Notice that we know 3 points on this new curve, Enc(Flag), Enc("hello\ world"), and $G$. Let these be represented as $(x_0, y_0), (x_1, y_1), (x_2, y_2)$. The core idea is the same as how we recovered the elliptic curve prime, get two equations that are 0 mod p'. To do this, we take the curve equation for each point, subtract two such equations to remove the dependence on $b'$, and re-arrange terms. This gives us: $$y_i^2 - y_{i + 1}^2 - (x_i^3 - x_{i+1}^3) - a(x_i - x_{i + 1}) \equiv 0 \pmod{p'}$$ We take the GCD of two such equations, and then use the defining elliptic curve equation to recover $b'$. Thus using the idea of the prior section we sice the flag `uiuctf{th4t_5ur3_w4s_f4ulty_huh?}`

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully