ctfnote
  • /home/ret2basic.eth
  • Game Hacking
    • āœ…C++
    • Ghidra
    • Cheat Engine
    • Proxy
    • DLL injection
    • Keygen
    • Aimbot
  • Web3 Security Research
    • šŸ‘‘Web3 Security Research Trivia
    • āœ…Solidity
      • āœ…Mastering Ethereum
      • āœ…Storage
      • āœ…Memory
      • āœ…Calldata
      • āœ…ABI
    • āœ…Foundry
      • āœ…Introduction
      • āœ…How to Write Basic Tests
      • āœ…Set Soliditiy Compiler Version
      • āœ…Remappings
      • āœ…Auto Format Code
      • āœ…Console Log
      • āœ…Authentication
      • āœ…Error
      • āœ…Event
      • āœ…Time
      • āœ…Send ETH
      • āœ…Signature
      • āœ…Fork
      • āœ…Mint 1 Million DAI on Mainnet Fork
      • āœ…FFI
      • āœ…Fuzz
      • āœ…Invariant Testing - Part 1
      • Invariant Testing - Part 2
      • Invariant Testing - Part 3
      • Differential Test
    • āœ…Secureum
      • āœ…Epoch 0
        • āœ…Slot 1: Ethereum 101
          • āœ…Notes
          • āœ…Ethereum Whitepaper
          • āœ…Extra Study: What happens when you send 1 DAI
          • āœ…Quiz
        • āœ…Slot 2: Solidity 101
          • āœ…Notes
          • āœ…OpenZeppelin ERC20
          • āœ…OpenZeppelin ERC721
          • āœ…OpenZeppelin Ownable
          • āœ…OpenZeppelin Pausable
          • āœ…OpenZeppelin ReentrancyGuard
          • āœ…Quiz
        • āœ…Slot 3: Solidity 201
          • āœ…Notes
          • āœ…OpenZeppelin SafeERC20
          • āœ…OpenZeppelin ERC-777
          • āœ…OpenZeppelin ERC-1155
          • āœ…OpenZeppelin ERC-3156
          • āœ…OpenZeppelin - Proxy Upgrade Pattern
          • āœ…Quiz
        • āœ…Slot 4: Pitfalls and Best Practices 101
          • āœ…Notes
          • āœ…Intro to Security First Development
          • āœ…Quiz
        • āœ…Slot 5: Pitfalls and Best Practices 201
          • āœ…Notes
          • So you want to use a price oracle
          • The Dangers of Surprising Code
          • āœ…Quiz
        • āœ…Slot 6: Auditing Techniques & Tools 101
          • āœ…Notes
          • āœ…Quiz
        • āœ…Slot 7: Audit Findings 101
          • Notes
          • āœ…Fei Protocol - ConsenSys
          • āœ…Uniswap V3 - Trail of Bits
          • āœ…Chainlink - Sigma Prime
          • āœ…Opyn Gamma - OpenZeppelin
          • āœ…Quiz
        • āœ…Slot 8: Audit Findings 201
          • Notes
          • 1inch Liquidity - Consensus
          • Original Dollar - Trail of Bits
          • Synthetix EtherCollateral - Sigma Prime
          • Holdefi - OpenZeppelin
          • Quiz
      • āœ…Epoch āˆž
        • āœ…RACE #4 - ERC20 Implementation
        • āœ…RACE #5 - ERC1155 Implementation
        • āœ…RACE #6 - ERC721 Application
        • āœ…RACE #7 - Bored Ape
        • āœ…RACE #8 - ERC721 Roles
        • āœ…RACE #9 - Proxy
        • āœ…RACE #10 - Test Cases
        • āœ…RACE #11 - Staking
        • āœ…RACE #12 - ERC20 Permit
        • āœ…RACE #13 - ERC20 with Callback
        • āœ…RACE #14 - Lending
        • āœ…RACE #15 - DEX
        • āœ…RACE #16 - Flash Loan
        • āœ…RACE #17
    • DeFi
      • Glossary
        • TWAP vs. VWAP
        • Tranches
      • DeFi MOOC
        • Lecture 2: Introduction to Blockchain Technologies
        • Lecture 5: DEX
        • Lecture 6: Decentralized Lending
        • Lecture 10: Privacy on the Blockchain
        • Lecture 12: Practical Smart Contract Security
        • Lecture 13: DeFi Security
      • Uniswap V2
      • Compound V3
        • āœ…Whitepaper
        • āœ…Interacting with Compound
          • āœ…Supply and Redeem
          • āœ…Borrow and Repay
          • āœ…Liquidation
          • āœ…Long and Short
        • āœ…Interest Model
        • CToken
      • Aave
      • Chainlink
        • āœ…Getting Started
        • āœ…Data Feeds
        • āœ…VRF
      • Optimism
        • Bedrock
      • LayerZero
      • Opensea
        • Seaport
    • EVM
      • āœ…Andreas Antonopoulos - The Ethereum Virtual Machine
      • āœ…Program The Blockchain - Smart Contract Storage
      • āœ…EVM Codes - EVM Playground for Opcodes
      • āœ…Fvictorio - EVM Puzzles
      • āœ…Daltyboy11 - More EVM Puzzles
      • āœ…EVM Through Huff
      • Noxx - EVM Deep Dives
      • āœ…Jordan McKinney - EVM Explained
      • Openzepplin - Deconstructing a Solidity Contract
      • Jeancvllr - EVM Assembly
      • Peter Robinson - Solidity to Bytecode, Memory & Storage
      • Marek Kirejczyk - Ethereum Under The Hood
      • āœ…Official Solidity Docs
      • Dissecting EVM using go-ethereum Eth client implementation - deliriusz.eth
    • Vulnerabilities
      • Rounding Issues
        • Kyberswap
      • Bridges
      • Governance / Voting Escrows
      • Bizzare Bug Classes
        • TIME - ERC2771Context + Multicall calldata manipulation
    • Fancy Topics
      • Vulnerabilities SoK
        • āœ…Demystifying Exploitable Bugs in Smart Contracts
        • Blockchain Hacking Techniques 2022 Top 10 - Todo
      • yAcademy
        • Proxies
          • yAcademy - Proxy Basics
          • yAcademy - Proxies Deep Dive
          • yAcademy - Security Guide to Proxy Vulns
        • defi-fork-bugs
      • Spearbit
        • āœ…Community Workshop: Riley Holterhus
        • Economic Security with fmrmf
        • Numerical Analysis for DeFi Audits: A TWAMM Case Study by Kurt Barry
  • Red Teaming
    • āœ…Enumeration
      • Service Enumeration
        • SMTP (Port 25)
        • Samba (Port 139, 445)
        • SNMP (Port 161,162,10161,10162)
        • rsync (Port 873)
        • NFS (Port 2049)
        • Apache JServ Protocol (Port 8081)
        • NetBIOS
      • Nmap
      • Gobuster / Feroxbuster / FUFF / Wfuzz
      • Drupal
    • āœ…Exploitation
      • Public Exploits
      • PHP Webshells
      • Reverse Shell
      • TTY
      • File Transfer
      • Metasploit
      • Password Spray
    • āœ…Buffer Overflow
      • Step 0: Spiking (Optional)
      • Step 1: Fuzzing
      • Step 2: Finding the Offset
      • Step 3: Overwriting the EIP
      • Step 4: Finding Bad Characters
      • Step 5: Finding the Right Module
      • Step 6: Generating Shellcode and Gaining Root
    • āœ…Privilege Escalation
      • Linux Privilege Escalation
        • Linux Permissions
        • Manual Enumeration
        • Automated Tools
        • Kernel Exploits
        • Passwords and File Permissions
        • SSH Keys
        • Sudo
        • SUID
        • Capabilities
        • Cron Jobs
        • NFS Root Squashing
        • Docker
        • GNU C Library
        • Exim
        • Linux Privilege Escalation Course Capstone
      • Windows Privilege Escalation
        • Manual Enumeration
        • Automated Tools
        • Kernel Exploits
        • Passwords and Port Forwarding
        • WSL
        • Token Impersonation and Potato Attacks
        • Meterpreter getsystem
        • Runas
        • UAC Bypass
        • Registry
        • Executable Files
        • Startup Applications
        • DLL Hijacking
        • Service Permissions (Paths)
        • CVE-2019-1388
        • HiveNightmare
        • Bypass Space Filter
    • āœ…Post Exploitation
      • Linux Post Exploitation
        • Add a User
        • SSH Key
      • Windows Post Exploitation
        • windows-resources
        • Add a User
        • RDP
    • āœ…Pivoting
      • Windows: Chisel
      • Linux: sshuttle
    • Active Directory (AD)
      • Initial Compromise
        • HTA Phishing
        • VBA Macro Phishing
        • LLMNR Poisoning
        • SMB Relay
        • GPP / cPassword
      • Domain Enumeration
        • Manual Enumeration
        • PowerView
        • BloodHound
      • Lateral Movement
        • PsExec
        • WMI
        • Runas
        • Pass the Hash
        • Overpass the Hash
        • Pass the Ticket
      • Kerberos
        • Kerberoast
        • AS-REP Roast
      • MS SQL Server
    • Command & Control (C2)
      • Cobalt Strike
        • Bypassing Defences
          • Artifact Kit
          • Resource Kit
          • AMSI Bypass
          • PowerPick
        • Extending Cobalt Strike
          • Elevate Kit
          • Malleable C2 Profile
      • Metasploit
        • Payloads
        • Post Exploitation
        • Automation
      • C2 Development
    • Malware Development
      • "Hot Dropper"
      • PE Format
        • Overview
      • Process Injection
      • Reflective DLL
      • x86 <=> x64
      • Hooking
      • VeraCry
      • Offensive C#
      • AV Evasion
        • AV Evasion with C# and PowerShell
        • AMSI Bypass
  • Cryptography
    • Hash Functions
    • MAC
    • AES
      • Byte at a Time
      • CBC CCA
      • CBC Bit Flipping
      • CBC Padding Oracle
    • Diffie-Hellman
    • RSA
      • Prime Factors
      • Multiple Ciphertexts
      • Low Public Exponent
      • Low Private Exponent
    • ECC
    • Digital Signature
    • JWT
    • PRNG
    • SSL/TLS
    • Research
      • āœ…Lattice-based Cryptography (Lattice)
      • Elliptic Curve Cryptography (ECC)
      • Oblivious Transfer (OT)
      • Secure Multi-party Computation (MPC)
      • Learning with Error (LWE)
      • Fully Homomorphic Encryption (FHE)
      • Zero Knowledge Proof (ZKP)
      • Oblivious RAM (ORAM)
  • Computer Science
    • Linux
      • Setup
      • curl
      • Hard Link vs. Symlink
      • Man Page
      • /dev/null
    • Python
      • New Features
      • Operators, Expressions, and Data Manipulation
      • Program Structure and Control Flow
      • Objects, Types, and Protocols
      • Functions 101
      • Generators
      • Classes and Object-Oriented Programming
      • Memory Management
      • Concurrency and Parallelism
        • Multithreading and Thread Safety
        • Asynchronization
        • Multiprocessing
        • Global Interpreter Lock (GIL)
      • Built-in Functions and Standard Library
        • import collections
        • import itertools
        • import sys
        • import re
        • import pickle
        • import json
      • Third-party Library
        • from pwn import *
        • import requests
        • from bs4 import BeautifulSoup
        • from scapy.all import *
        • py2exe
    • HTML, CSS, JavaScript, and React
      • HTML
      • CSS
      • JavaScript
        • var vs. let
        • Objects
        • Arrays
        • Functions
        • Modules
        • Asynchronous JavaScript
      • React
    • Data Structures and Algorithms
      • Binary Search
    • The Linux Programming Interface
      • Processes
        • Memory Allocation
        • The Process API
        • Process Creation
        • Process Termination
        • Monitoring Child Processes
        • Program Execution
      • Signals
      • Threads
        • Thread Synchronization
        • Thread Safety and Pre-Thread Storage
      • IPC
        • Pipes and FIFOs
        • Memory Mappings
        • Virtual Memory Operations
      • Sockets
    • Computer Systems
      • Hexadecimal
      • Signedness
      • Registers
      • Instructions
      • Syscall
      • Process Memory
      • Stack Frame
      • Preemptive Multitasking
      • IPC
      • Threads
    • Databases
      • MySQL
        • Basic Syntax
        • Data Types
        • Modifying Tables
        • Duplicating and Deleting
        • SELECT
        • Transaction
      • GraphQL
    • Distributed Systems
      • Introduction
        • What is a Distributed System?
        • Design Goals
        • Scaling Techniques
        • Types of Distributed Systems
      • Architecture
        • System Architectures
        • Example Architectures
      • Communication
        • Foundations
        • Remote Procedure Call
        • Message-oriented Communication
      • Coordination
        • Clock Synchronization
        • Logical Clock
      • Consistency and Replication
        • Introduction
        • Data-centric Consistency
        • Client-centric Consistency
    • Static Analysis
      • Intermediate Representation
      • Data Flow Analysis
      • Interprocedural Analysis
      • Pointer Analysis
      • Static Analysis for Security
      • Datalog-Based Program Analysis
      • Soundness and Soundiness
      • CFL-Reachability and IFDS
  • Web
    • āœ…Prerequisites
      • OWASP Top 10
        • 1. Broken Access Control
        • 2. Cryptographic Failures
        • 3. Injection
        • 4. Insecure Design
        • 5. Security Misconfiguration
        • 6. Vulnerable and Outdated Components
        • 7. Identification and Authentication Failures
        • 8. Software and Data Integrity Failures
        • 9. Security Logging and Monitoring Failures
        • 10. SSRF
      • HTTP
        • HTTP Status Codes
        • HTTP Headers
      • Burp Suite
        • Burp Intruder
        • Burp Extender
        • Burp Collaborator
      • Information Gathering
        • DNS
        • Git
        • Editor
        • Server
      • Bug Bounty Report Writing
    • File Upload
      • Webshell
      • IIS, Nginx, and Apache Vulnerabilities
      • .htaccess (Apache) / web.config (IIS)
      • Alternate Data Stream
      • Code Review: bWAPP Unrestricted File Upload
    • SQL Injection (SQLi)
      • Cheat Sheet
      • UNION Attacks
      • Examining the Database
      • Blind SQL Injection
      • WAF Bypass
      • Out-Of-Band (OOB)
      • Webshell and UDF
      • sqlmap
        • Code Review: Initialization
        • Code Review: tamper
    • Cross-Site Scripting (XSS)
      • Cheat Sheet
      • Reflected XSS
      • Stored XSS
      • DOM-Based XSS
      • XSS Contexts
      • CSP
    • CSRF and SSRF
      • Client-Side Request Forgery (CSRF)
        • XSS vs. CSRF
        • CSRF Tokens and SameSite Cookies
      • Server-Side Request Forgery (SSRF)
        • Attacks
        • Bypassing Restrictions
        • SSRF + Redis
    • XML External Entities (XXE)
    • Insecure Deserialization
      • Python Deserialization
      • PHP Deserialization
      • Java Deserialization
        • Shiro
        • FastJSON
        • WebLogic
    • HTTP Request Smuggling
    • OS Command Injection
      • Whitespace Bypass
      • Blacklist Bypass
      • Blind OS Command Injection
      • Lab 1: HITCON 2015 BabyFirst
      • Lab 2: HITCON 2017 BabyFirst Revenge
      • Lab 3: HITCON 2017 BabyFirst Revenge v2
    • āœ…Directory Traversal
    • HTTP Parameter Pollution
    • Server-Side Template Injection (SSTI)
    • LDAP Injection
    • Redis
      • Authentication
      • RCE
      • Mitigations
  • Pwn
    • Linux Exploitation
      • Protections
      • Shellcoding
        • Calling Convention
        • Null-free
        • Reverse Shell
        • ORW
      • ROP
        • Stack Alignment
        • ret2text
        • ret2syscall
        • ret2libc
        • ret2csu
        • BROP
        • SROP
        • Stack Pivot
      • ptmalloc
        • chunks
        • malloc() and free()
        • bins
        • tcache
      • UAF
      • Race Conditions
        • TOCTTOU
        • Dirty Cow
        • Meltdown
        • Spectre
      • Kernel
      • Appendix: Tools
        • socat
        • LibcSearcher-ng
        • OneGadget
    • Windows Exploitation
      • Classic
      • SEH
      • Egghunting
      • Unicode
      • Shellcoding
      • ROP
      • Appendix: Tools
        • ImmunityDbg
        • Mona.py
    • Fuzzing
      • AFL++
        • Quickstart
        • Instrumentation
        • ASAN
        • Code Coverage
        • Dictionary
        • Parallelization
        • Partial Instrumentation
        • QEMU Mode
        • afl-libprotobuf-mutator
      • WinAFL
      • Fuzzilli
  • Reverse
    • Bytecode
      • Python Bytecode
    • šŸ‘‘Z3 solver
    • angr
      • angr Template
Powered by GitBook
On this page

Was this helpful?

Last updated 3 years ago

Was this helpful?

Hash Function

A hash function is any function that can be used to map data of arbitrary size to fixed-size values, called digest. In cryptography, we are interested in cryptographic hash function.

Cryptographic hash function has the following three properties:

  • Preimage resistance: No one should be able to reverse the hash function in order to recover the input given an output.

  • Second preimage resistance: Given an input and the digest it hashes to, no one should be able to find a different input that hashes to the same digest.

  • Collision resistance: No one should be able to produce two different inputs that hash to the same output.

Birthday Paradox

In probability theory, the birthday problem asks for the probability that, in a set of randomly chosen people, at least two will share a birthday. The birthday paradox is that, counterintuitively, the probability of a shared birthday exceeds 50% in a group of only 23 people.

A birthday attack is a type of cryptographic attack that exploits the mathematics behind the birthday problem in probability theory. This attack can be used to abuse communication between two or more parties. The attack depends on the higher likelihood of collisions found between random attack attempts and a fixed degree of permutations (pigeonholes). With a birthday attack, it is possible to find a collision of a hash function in , with being the classical preimage resistance security.

If our hash function generates random outputs of 256 bits, the space of all outputs is of size . This means that collisions can be found with good probability after generating digests (due to the birthday bound). This is the number we’re aiming for, and this is why hash functions at a minimum must provide 256-bit outputs.

Hash Functions in the Real World

Commitment

Suppose that Alice knows some secret, call it , and this secret can be revealed after a certain date . She wants to show Bob that she actually knows the secret but she can't reveal the content of for now. In this case, a commitment scheme does the following things:

  • Alice computes , such as SHA256(M), and send to Bob.

  • After date , Alice sends Bob the secret .

  • Bob computes and compares the result with .

Commitments in cryptography generally try to achieve two properties:

  • Hiding: A commitment must hide the underlying value.

Hash function provides hiding and binding if used as a commitment scheme, because:

  • Preimage resistence is equivalent to hinding.

  • Collision resistence is equivalent to binding.

Subresource integrity

CDN serves JavaScripts files but the integrity must be verified, otherwise malicious JavaScript files may be injected to clients. To counter this, web pages can use a feature called subresource integrity that allows the inclusion of a digest in the import tag:

Once the JavaScript file is retrieved, the browser hashes it (using SHA-256) and verifies that it corresponds to the digest that was hardcoded in the page.

Hashing Passwords

Most websites require username and password as authentication method. If a website stores user passwords in plaintext in the database, those passwords may be leaked through web attacks such as SQL injection. Therefore, websites should only store the hash of user passwords. But other problems exist with this solution.

  • Problem 1: If an attacker retrieves hashed passwords, a brute force attack or an exhaustive search (trying all possible passwords) can be undertaken. This would test each attempt against the whole database. Ideally, we would want an attacker to only be able to attack one hashed password at a time.

  • Problem 2: Hash functions are supposed to be as fast. Attackers can leverage this to brute force (many, many passwords per second). Ideally, we would have a mechanism to slow down such attacks.

The solutions are:

  • Solution 1: Append salts to user passwords before hashing. Salts are random values that are public and different for each user. Even weak passwords will become stronger because of the existence of satls.

  • Solution 2: Use password hashes, which are designed to be slow. The current state-of-the-art choice for this is Argon2.

Caveat: MD5 and SHA-1 are Deprecated

MD5 and SHA-1 were shown to be broken in 2004 and 2016, respectively, when collisions were published by different research teams.

Lab

Reference

Binding: A commitment must hide a single value. In other words, if you commit to a value , you shouldn't be able to later successfully reveal a different value .

nnn
2n=2n/2\sqrt{2^n} = 2^{n/2}2n​=2n/2
2n2^n2n
22562^{256}2256
21282^{128}2128
SSS
DDD
SSS
SSS
H=Hash(S)H = Hash(S)H=Hash(S)
HHH
DDD
SSS
Hash(S)Hash(S)Hash(S)
HHH
xxx
yyy
<script src="https://code.jquery.com/jquery-2.1.4.min.js" integrity="sha256-8WqyJLuWKRBVhxXIL1jBDD7SDxU936oZkCnxQbWwJVw="></script>
  1. Cryptography

Hash Functions

PreviousAMSI BypassNextMAC
  • Hash Function
  • Birthday Paradox
  • Hash Functions in the Real World
  • Commitment
  • Subresource integrity
  • Hashing Passwords
  • Caveat: MD5 and SHA-1 are Deprecated
  • Lab
  • Reference
Real-World CryptographyManning Publications
Real-World Cryptography
Logo
CryptoHack – Hash Functions challengesCryptoHack
Hash Functions - CryptoHack
Logo