Giter Site home page Giter Site logo

hm4c's Introduction

hm4c

Solution to midnightsun 2018 qualifier ctf crypto challenge 'hm4c'

The h4mc.py service essentially accepts a message and returns

sha256((key ⊕ message) + message)

Where ⊕ is bitwise XOR and + is bitwise addition

Suppose key = 01100001 and our message = 00000000, then

 key                      = 01100001
 message                  = 00000000
 key ⊕ message            = 01100001
(key ⊕ message) + message = 01100001

That is (key ⊕ message) + message = key

So immediately we can get sha256(key). However, this is not particularly useful on it's own, as it would be computationally intractible to find the 'preimage' of the hash.

However suppose Suppose key = 01100001 and our message = 00000001. Notice how message matches key on the 0th bit. Then

 key                      = 01100001
 message                  = 00000001
 key ⊕ message            = 01100000
(key ⊕ message) + message = 01100001

So because the 0th bit message matched the 0th bit of key, (key ⊕ message) + message = key again.

We now have the kernel of an algorithm for inferring key by testing the ith bit of key. If the sha256 of our test of the ith bit is equal to sha256(key), we can infer that the ith bit of key is set. Otherwise the ith bit of key is not set.

The exploiable flaw in the toy implementation of an 'HMAC' is that the + should be concatenation, not bitwise addition.

hm4c_solution.py connects to a hm4c.py service, either locally or remotely, and tests each bit until the entire key has been inferred.

hm4c's People

Contributors

newjam avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.