Skip to content

bad-antics/nullsec-binarydiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NullSec BinaryDiff

Binary Comparison Tool

A comprehensive binary diff and analysis tool written in Swift, demonstrating protocol-oriented programming for security-focused binary comparison.

Swift Security Version License

🎯 Overview

NullSec BinaryDiff compares binary files to identify changes in sections, functions, imports, and exports. It highlights security-sensitive modifications and calculates similarity scores for patch analysis and malware research.

✨ Features

  • Section Comparison - Detect changes in .text, .data, .bss sections
  • Function Diffing - Track function additions, removals, modifications
  • Import/Export Analysis - Monitor library dependencies
  • Security Highlighting - Flag changes to sensitive functions
  • Similarity Scoring - Calculate binary similarity percentage
  • Complexity Tracking - Monitor cyclomatic complexity changes

πŸ” Analysis Types

Type Description Severity
.text Modified Code section changed High
Security Func Changed auth/crypto function modified High
Section Added New section in binary Low
Function Removed Function deleted Medium
Import Added New library dependency Info

πŸ“¦ Installation

# Clone the repository
git clone https://github.com/bad-antics/nullsec-binarydiff
cd nullsec-binarydiff

# Compile with swiftc
swiftc -O binarydiff.swift -o binarydiff

# Or run directly
swift binarydiff.swift

πŸš€ Usage

# Compare two binaries
./binarydiff app_v1 app_v2

# Function-level diff only
./binarydiff -f old.so new.so

# Section-level diff only
./binarydiff -s binary1 binary2

# JSON output
./binarydiff -j old new

# Run demo mode
./binarydiff

πŸ’» Example Output

╔══════════════════════════════════════════════════════════════════╗
β•‘            NullSec BinaryDiff - Binary Comparison Tool           β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

[Demo Mode]

Comparing sample binaries...

  Section Differences:

  [~] .text
    Type:   MODIFIED
    Reason: Section content changed

  [~] .data
    Type:   MODIFIED
    Reason: Section content changed

  [+] .plt
    Type:   ADDED
    Reason: New section added

  Function Differences:

  [HIGH] ~ auth_user πŸ”’
    β€’ Size: 200 β†’ 350
    β€’ Complexity: 8 β†’ 12

  [MEDIUM] ~ main
    β€’ Size: 500 β†’ 600
    β€’ Complexity: 15 β†’ 18

  [HIGH] - unsafe_strcpy πŸ”’
    β€’ Function removed

  [INFO] + new_feature
    β€’ New function

  Import Changes:
    [-] libssl.so.1.1
    [+] libssl.so.3
    [+] libpthread.so.0

═══════════════════════════════════════════

  Summary:
    Old Binary:  /usr/bin/app_v1.0
    New Binary:  /usr/bin/app_v2.0
    Similarity:  20.0%

  Changes:
    Sections:    4
    Functions:   5
    Imports:     3
    Exports:     1

  Security-Sensitive Changes: 2

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Binary Parser                              β”‚
β”‚           ELF | Mach-O | PE Format Support                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Binary Info Extraction                          β”‚
β”‚    Sections | Functions | Imports | Exports | Hashes        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β–Ό               β–Ό               β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚ Section  β”‚   β”‚ Function β”‚   β”‚  Symbol  β”‚
     β”‚ Compare  β”‚   β”‚ Compare  β”‚   β”‚ Compare  β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚               β”‚               β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β–Ό
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚ DiffAnalysis β”‚
                   β”‚   Result     β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ¦… Swift Features Demonstrated

  • Enums with Associated Values - DiffType, Severity
  • Structs - Value types for Section, FunctionEntry, BinaryInfo
  • Computed Properties - Severity.color
  • Protocol Extensions - CaseIterable
  • Optionals - Safe handling of missing data
  • Higher-Order Functions - filter, map, contains
  • Set Operations - subtracting for diff calculation
  • String Interpolation - Clean output formatting

πŸ”§ Data Structures

struct BinaryInfo {
    let path: String
    let size: UInt64
    let hash: String
    let sections: [Section]
    let functions: [FunctionEntry]
    let imports: [String]
    let exports: [String]
}

struct FunctionDiff {
    let diffType: DiffType
    let oldFunc: FunctionEntry?
    let newFunc: FunctionEntry?
    let severity: Severity
    let changes: [String]
}

πŸ” Security-Sensitive Functions

The tool flags changes to these function patterns:

  • Memory: strcpy, memcpy, malloc, free
  • System: system, exec, popen, fork
  • Network: connect, bind, recv, send
  • Crypto: crypt, encrypt, decrypt
  • Auth: auth, login, verify, validate

πŸ›‘οΈ Security Use Cases

  • Patch Analysis - Understand security patch changes
  • Malware Research - Compare malware variants
  • Supply Chain - Verify binary integrity
  • Forensics - Identify unauthorized modifications
  • Vulnerability Research - Track function changes

⚠️ Legal Disclaimer

This tool is intended for:

  • βœ… Authorized security research
  • βœ… Malware analysis (authorized samples)
  • βœ… Patch verification
  • βœ… Educational purposes

Only analyze binaries you're authorized to examine.

πŸ”— Links

πŸ“„ License

MIT License - See LICENSE file for details.

🏷️ Version History

  • v1.0.0 - Initial release with binary comparison and security analysis

Part of the NullSec Security Toolkit

About

Swift binary comparison tool with section/function diffing and security analysis

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages