1. Trang chủ
  2. » Công Nghệ Thông Tin

Hacking APIs early access

353 199 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Hacking APIs
Tác giả Corey J. Ball
Trường học No Starch Press
Thể loại early access
Năm xuất bản 2022
Định dạng
Số trang 353
Dung lượng 39,44 MB

Cấu trúc

  • Foreword

  • Acknowledgments

  • Introduction

  • Part I: The State of Web API Security

    • 0: Preparing for API Security Testing

      • Receiving Authorization

        • Threat Modeling an API Test

        • Which API Features You Should Test

          • API Authenticated Testing

          • Web Application Firewalls

          • Mobile Application Testing

          • Auditing API Documentation

          • Rate Limit Testing

        • Restrictions and Exclusions

          • Security Testing Cloud APIs

          • DoS Testing

        • Reporting and Remediation Testing

        • A Note on Bug Bounty Scope

        • Summary

    • 1: How Web Applications Work

      • Web App Basics

        • The URL

          • HTTP Requests

          • HTTP Responses

          • HTTP Status Codes

          • HTTP Methods

          • Stateful and Stateless HTTP

        • Web Server Databases

          • SQL

          • NoSQL

        • How APIs Fit into the Picture

        • Summary

    • 2: The Anatomy of Web APIs

      • How Web APIs Work

        • Standard Web API Types

          • RESTful APIs

          • GraphQL

        • REST API Specifications

        • API Data Interchange Formats

          • JSON

          • XML

          • YAML

        • API Authentication

          • Basic Authentication

          • API Keys

          • JSON Web Tokens

          • HMAC

          • OAuth 2.0

          • No Authentication

        • APIs in Action: Exploring Twitter’s API

        • Summary

    • 3: API Insecurities

      • Information Disclosure

        • Broken Object Level Authorization

        • Broken User Authentication

        • Excessive Data Exposure

        • Lack of Resources and Rate Limiting

        • Broken Function Level Authorization

        • Mass Assignment

        • Security Misconfigurations

        • Injections

        • Improper Assets Management

        • Business Logic Vulnerabilities

        • Summary

  • Part II: Lab Setup

    • 4: Setting Up an API Hacking System

      • Kali Linux

        • Analyzing Web Apps with DevTools

        • Capturing and Modifying Requests with Burp Suite

          • Setting Up FoxyProxy

          • Adding the Burp Suite Certificate

          • Navigating Burp Suite

          • Intercepting Traffic

          • Altering Requests with Intruder

        • Crafting API Requests in Postman, an API Browser

          • The Request Builder

          • Environments

          • Collections

          • The Collection Runner

          • Code Snippets

          • The Tests Panel

        • Configuring Postman to Work with Burp Suite

        • Supplemental Tools

          • Performing Reconnaissance with OWASP Amass

          • Discovering API Endpoints with Kiterunner

          • Scanning for Vulnerabilities with Nikto

          • Scanning for Vulnerabilities with OWASP ZAP

          • Fuzzing with Wfuzz

          • Discovering HTTP Parameters with Arjun

        • Summary

      • Lab #1: Enumerating the User Accounts in a REST API

    • 5: Setting Up Vulnerable API Targets

      • Creating a Linux Host

        • Installing Docker and Docker Compose

        • Installing Vulnerable Applications

          • The completely ridiculous API (crAPI)

          • OWASP DevSlop’s Pixi

          • OWASP Juice Shop

          • Damn Vulnerable GraphQL Application

        • Adding Other Vulnerable Apps

        • Hacking APIs on TryHackMe and HackTheBox

        • Summary

      • Lab #2: Finding Your Vulnerable APIs

  • Part III: Attacking APIs

    • 6: Discovering APIs

      • Passive Recon

        • The Passive Recon Process

          • Google Hacking

          • ProgrammableWeb’s API Search Directory

          • Shodan

          • OWASP Amass

          • Exposed Information on GitHub

        • Active Recon

          • The Active Recon Process

          • Baseline Scanning with Nmap

          • Finding Hidden Paths in Robots.txt

          • Finding Sensitive Information with Chrome DevTools

          • Validating APIs with Burp Suite

          • Crawling URIs with OWASP ZAP

          • Brute-Forcing URIs with Gobuster

          • Discovering API Content with Kiterunner

        • Summary

      • Lab #3: Performing Active Recon for a Black Box Test

    • 7: Endpoint Analysis

      • Finding Request Information

        • Finding Information in Documentation

          • Importing API Specifications

          • Reverse Engineering APIs

        • Adding API Authentication Requirements to Postman

        • Analyzing Functionality

          • Testing Intended Use

          • Performing Privileged Actions

          • Analyzing API Responses

        • Finding Information Disclosures

        • Finding Security Misconfigurations

          • Verbose Errors

          • Poor Transit Encryption

          • Problematic Configurations

        • Finding Excessive Data Exposures

        • Finding Business Logic Flaws

        • Summary

      • Lab #4: Building a crAPI Collection and Discovering Excessive Data Exposure

    • 8: Attacking API Authentication

      • Classic Authentication Attacks

        • Password Brute-Force Attacks

          • Password Reset and Multifactor Authentication Brute-Force Attacks

          • Password Spraying

          • Including Base64 Authentication in Brute-Force Attacks

        • Forging Tokens

          • Manual Load Analysis

          • Live Token Capture Analysis

          • Brute-Forcing Predictable Tokens

        • JSON Web Token Abuse

          • Recognizing and Analyzing JWTs

          • The None Attack

          • The Algorithm Switch Attack

          • The JWT Crack Attack

        • Summary

      • Lab #5: Cracking a crAPI JWT Signature

    • 9: API Fuzzing

      • Effective Fuzzing

        • Choosing Fuzzing Payloads

          • Detecting Anomalies

        • Fuzzing Wide and Deep

          • Fuzzing Wide with Postman

          • Fuzzing Deep with Burp Suite

          • Fuzzing Deep with Wfuzz

        • Fuzzing Wide for Improper Assets Management

        • Testing Request Methods with Wfuzz

        • Fuzzing “Deeper” to Bypass Input Sanitization

        • Fuzzing for Directory Traversal

        • Summary

      • Lab #6: Fuzzing for Improper Assets Management Vulnerabilities

    • 10: Exploiting API Authorization

      • Finding BOLAs

        • Locating Resource IDs

          • A-B Testing for BOLA

          • Side-Channel BOLA

        • Finding BFLAs

          • A-B-A Testing for BFLA

          • Testing for BFLA in Postman

        • Authorization Hacking Tips

          • Postman’s Collection Variables

          • Burp Suite Match and Replace

        • Summary

      • Lab #7: Finding Another User’s Vehicle Location

    • 11: Exploiting Mass Assignment

      • Finding Mass Assignment Targets

        • Account Registration

          • Unauthorized Access to Organizations

        • Finding Mass Assignment Variables

          • Finding Variables in Documentation

          • Fuzzing Unknown Variables

          • Blind Mass Assignment Attacks

        • Automating Mass Assignment Attacks with Arjun and Burp Suite Intruder

        • Combining BFLA and Mass Assignment

        • Summary

      • Lab #8: Changing the Price of Items in an Online Store

    • 12: API Injection

      • Discovering Injection Vulnerabilities

        • Cross-Site Scripting (XSS)

        • Cross-API Scripting (XAS)

        • SQL Injection

          • Manually Submitting Metacharacters

          • SQLmap

        • NoSQL Injection

        • Operating System Command Injection

        • Summary

      • Lab #9: Faking Coupons Using NoSQL Injection

  • Part IV: Real-World API Hacking

    • 13: Evasive Techniques and Rate Limit Testing

      • Evading API Security Controls

        • How Security Controls Work

          • API Security Control Detection

          • Using Burner Accounts

          • Evasive Techniques

          • Automating Evasion with Burp Suite

          • Automating Evasion with Wfuzz

        • Testing Rate Limits

          • A Note on Lax Rate Limits

          • Path Bypass

          • Origin Header Spoofing

          • Rotating IP Addresses in Burp Suite

        • Summary

    • 14: Attacking GraphQL

      • GraphQL Requests and IDEs

        • Active Reconnaissance

          • Scanning

          • Viewing DVGA in a Browser

          • Using DevTools

        • Reverse Engineering the GraphQL API

          • Directory Brute-Forcing for the GraphQL Endpoint

          • Cookie Tampering to Enable the GraphiQL IDE

          • Reverse Engineering the GraphQL Requests

          • Reverse Engineering a GraphQL Collection Using Introspection

        • GraphQL API Analysis

          • Crafting Requests Using the GraphiQL Documentation Explorer

          • Using the InQL Burp Extension

        • Fuzzing for Command Injection

        • Summary

    • 15: Breaches and Bounties

      • The Breaches

        • Peloton

          • USPS Informed Visibility API

          • T-Mobile API Breach

        • The Bounties

          • The Price of Good API Keys

          • Private API Authorization Issues

          • Starbucks: The Breach That Never Was

          • An Instagram GraphQL BOLA

        • Summary

  • Conclusion

  • A: API Hacking Checklist

  • B: Additional Resources

Nội dung

Hacking APIs EAR LY EAR LY ACC ESS ACC ESS N O S T A R C H P R E S S E A R L Y A C C E S S P R O G R A M F E E D B A C K W E L C O M E Welcome to the Early Access edition of the as yet unpublished Hacking APIs by Corey J Ball As a prepublication title, this book may be incomplete and some chapters may not have been proofread Our goal is always to make the best books possible, and we look forward to hearing your thoughts If you have any comments or questions, email us at earlyaccessnostarch c.

THE STATE OF WEB API SECURITY

Preparing for API Security Testing

Khawaja, Gus Kali Linux Penetration Testing Bible Indianapolis, IN: Wiley, 2021.

Li, Vickie Bug Bounty Bootcamp: The Guide to Finding and Reporting Web

Vulnerabilities San Francisco: No Starch Press, 2021.

Weidman, Georgia Penetration Testing: A Hands-On Introduction to Hacking San Francisco: No Starch Press, 2014.

How Web Applications Work

Hoffman, Andrew Web Application Security: Exploitation and Countermeasures for Modern Web Applications Sebastopol, CA: O’Reilly, 2020.

“HTTP Response Status Codes.” MDN Web Docs https://developer.mozilla.org/ en-US/docs/Web/HTTP/Status.

Stuttard, Dafydd, and Marcus Pinto Web Application Hacker’s Handbook:

Finding and Exploiting Security Flaws Indianapolis, IN: Wiley, 2011.

The Anatomy of Web APIs

“API University: Best Practices, Tips & Tutorials for API Providers and Developers.” ProgrammableWeb https://www.programmableweb.com/ api-university.

Barahona, Dan “The Beginner’s Guide to REST API: Everything You Need to Know.” APIsec, June 22, 2020 https://www.apisec.ai/blog/ rest-api-and-its-significance-to-web-service-providers.

Madden, Neil API Security in Action Shelter Island, NY: Manning, 2020. Richardson, Leonard, and Mike Amundsen RESTful Web APIs Beijing: O’Reilly, 2013.

Siriwardena, Prabath Advanced API Security: Securing APIs with OAuth 2.0,

OpenID Connect, JWS, and JWE Berkeley, CA: Apress, 2014.

LAB SETUP

Setting Up an API Hacking System

“Introduction.” Postman Learning Center https://learning.postman.com/docs/ getting-started/introduction.

O’Gorman, Jim, Mati Aharoni, and Raphael Hertzog Kali Linux Revealed:

Mastering the Penetration Testing Distribution Cornelius, NC: Offsec

“Web Security Academy.” PortSwigger https://portswigger.net/web-security.

ATTACKING APIS

Discovering APIs

“API Directory.” ProgrammableWeb https://www.programmableweb.com/apis/ directory.

Doerrfeld, Bill “API Discovery: 15 Ways to Find APIs.” Nordic APIs, August

4, 2015 https://nordicapis.com/api-discovery-15-ways-to-find-apis.

Faircloth, Jeremy Penetration Tester’s Open Source Toolkit 4th ed Amsterdam: Elsevier, 2017.

“Welcome to the RapidAPI Hub.” RapidAPI https://rapidapi.com/hub.

Attacking API Authentication

PART I: THE STATE OF WEB API SECURITY

Chapter 0: Preparing for API Security Testing

Chapter 1: How Web Applications Work

Chapter 2: The Anatomy of Web APIs

Chapter 4: Setting Up an API Hacking System

Chapter 5: Setting Up Vulnerable API Targets

PART IV: REAL-WORLD API HACKING

Chapter 13: Evasive Techniques and Rate Limit Testing Chapter 14: Attacking GraphQL

The chapters in red are included in this Early Access PDF.

To my wonderful wife Kristin and our three beautiful daughters, Vivian, Charlise, and Ruby, your joyful distractions have brought immense happiness into my life, even if they occasionally led to minor mishaps You are my greatest treasures, and my love for you knows no bounds.

Corey Ball is a prominent cybersecurity consulting leader at Moss Adams, specializing in penetration testing services With over a decade of experience in IT and cybersecurity, he has worked across diverse sectors such as aerospace, agribusiness, energy, fintech, government services, and healthcare.

In addition to bachelor degrees in both English and philosophy from Sacramento State University, he holds the OSCP, CCISO, CEH, CISA, CISM, CRISC, and CGEIT industry certifications.

Alex Rifman, a seasoned expert in the security industry, specializes in defense strategies, incident response, threat intelligence, and risk management Currently, he leads customer success at APIsec, a company focused on API security, where he collaborates with clients to ensure the security of their APIs.

PART I: THE STATE OF WEB API SECURITY 1

Chapter 0: Preparing for API Security Testing

Chapter 1: How Web Applications Work

Chapter 2: The Anatomy of Web APIs

Chapter 4: Setting Up an API Hacking System 71

Chapter 5: Setting Up Vulnerable API Targets 109

PART IV: REAL-WORLD API HACKING 265

Chapter 13: Evasive Techniques and Rate Limit Testing 267

The Allure of Hacking Web APIs xxiv

Hacking the API Restaurant xxv

PART I: THE STATE OF WEB API SECURITY 1

0 PREPARING FOR API SECURITY TESTING 3

Threat Modeling an API Test 4

Which API Features You Should Test 6

A Note on Bug Bounty Scope 11

How APIs Fit into the Picture 25

2 THE ANATOMY OF WEB APIS 27

APIs in Action: Exploring Twitter’s API 48

Lack of Resources and Rate Limiting 59

4 SETTING UP AN API HACKING SYSTEM 71

Analyzing Web Apps with DevTools 72

Capturing and Modifying Requests with Burp Suite 75

Adding the Burp Suite Certificate 76

Crafting API Requests in Postman, an API Browser 84

Configuring Postman to Work with Burp Suite 95

Performing Reconnaissance with OWASP Amass 97

Discovering API Endpoints with Kiterunner 98

Scanning for Vulnerabilities with Nikto 99

Scanning for Vulnerabilities with OWASP ZAP 100

Discovering HTTP Parameters with Arjun 102

Lab #1: Enumerating the User Accounts in a REST API 103

5 SETTING UP VULNERABLE API TARGETS 109

Installing Docker and Docker Compose 110

The completely ridiculous API (crAPI) 111

Hacking APIs on TryHackMe and HackTheBox 115

Lab #2: Finding Your Vulnerable APIs 116

Finding Hidden Paths in Robots txt 139

Finding Sensitive Information with Chrome DevTools 139

Validating APIs with Burp Suite 142

Crawling URIs with OWASP ZAP 143

Brute-Forcing URIs with Gobuster 145

Discovering API Content with Kiterunner 146

Lab #3: Performing Active Recon for a Black Box Test 148

Adding API Authentication Requirements to Postman 164

Lab #4: Building a crAPI Collection and Discovering Excessive Data Exposure 174

Password Reset and Multifactor Authentication Brute-Force Attacks 181

Including Base64 Authentication in Brute-Force Attacks 185

Lab #5: Cracking a crAPI JWT Signature 197

Fuzzing Deep with Burp Suite 210

Fuzzing Wide for Improper Assets Management 214

Testing Request Methods with Wfuzz 216

Fuzzing “Deeper” to Bypass Input Sanitization 217

Lab #6: Fuzzing for Improper Assets Management Vulnerabilities 219

Testing for BFLA in Postman 228

Burp Suite Match and Replace 231

Lab #7: Finding Another User’s Vehicle Location 232

Automating Mass Assignment Attacks with Arjun and Burp Suite Intruder 241

Combining BFLA and Mass Assignment 242

Lab #8: Changing the Price of Items in an Online Store 243

Lab #9: Faking Coupons Using NoSQL Injection 261

PART IV: REAL-WORLD API HACKING 265

13 EVASIVE TECHNIQUES AND RATE LIMIT TESTING 267

Automating Evasion with Burp Suite 273

A Note on Lax Rate Limits 276

Rotating IP Addresses in Burp Suite 280

Reverse Engineering the GraphQL API 290

Directory Brute-Forcing for the GraphQL Endpoint 290

Cookie Tampering to Enable the GraphiQL IDE 292

Reverse Engineering the GraphQL Requests 294

Reverse Engineering a GraphQL Collection Using Introspection 296

Crafting Requests Using the GraphiQL Documentation Explorer 297

Using the InQL Burp Extension 298

The Price of Good API Keys 312

Starbucks: The Breach That Never Was 315

Envision a world where transferring money to a friend demands more than just a few clicks in an app, where tracking your daily steps, exercise, and nutrition necessitates juggling multiple applications, and where comparing airfares means painstakingly visiting each airline's website individually.

APIs have revolutionized the way companies collaborate and develop applications, acting as the essential link that connects various systems Their widespread adoption has significantly transformed enterprise operations, as highlighted by an Akamai report from October 2018, which revealed that API calls constituted a remarkable percentage of all web traffic.

83 percent of all web traffic.

Cybercriminals are increasingly targeting APIs due to their rich sources of sensitive information and frequent security vulnerabilities As valuable assets on the internet, APIs present a lucrative opportunity for malicious actors looking to exploit these weaknesses.

APIs are essential in application architecture, facilitating communication between users and backend systems For instance, when checking a bank balance or applying for a loan, APIs request and deliver sensitive information like account details and credit histories Positioned at a crucial intersection, APIs protect valuable data; however, if compromised by cybercriminals, they can lead to unauthorized access to sensitive information.

Despite the widespread adoption of APIs, security measures remain inadequate In a recent discussion with the chief information security officer of a century-old energy company, it was revealed that APIs are utilized extensively across the organization However, he emphasized a concerning trend: upon closer inspection, many APIs are found to have excessive permissions.

Developers face immense pressure to quickly fix bugs, release updates, and enhance functionalities, often leading to a rapid cycle of nightly builds and daily commits This fast-paced environment leaves little time to thoroughly assess the security implications of each change, resulting in the inadvertent introduction of undiscovered vulnerabilities into their products.

Lax API security practices can lead to serious consequences, as demonstrated by the US Postal Service's Informed Visibility API, which was designed for package tracking Although the API required user authentication to access information, once authenticated, individuals could view the account details of other users, compromising the privacy of 60 million users This incident highlights the critical need for robust security measures in API development to protect sensitive user data.

Peloton, the fitness company, utilizes APIs for its apps and equipment However, one of its APIs lacked authentication, enabling unauthorized requests to access account information from any of the four million Peloton devices This vulnerability exposed potentially sensitive user data, including that of prominent users like US President Joe Biden, highlighting the risks associated with unsecured endpoints.

The electronic payment firm Venmo utilizes APIs to connect its applications with financial institutions, but a marketing API inadvertently exposed sensitive transaction data, leading to the harvesting of 200 million transactions by malicious users This incident underscores a growing trend, as Gartner predicts API breaches will become the most common attack vector by 2022, with IBM reporting that two-thirds of cloud breaches stem from API misconfigurations Current application security solutions primarily focus on traditional attack types and vulnerabilities, utilizing automated scanners and web application firewalls, which are inadequate for addressing the unique security challenges posed by APIs.

API vulnerabilities are infrequent and vary significantly between different APIs, often differing from those seen in traditional applications A notable example is the USPS breach, which stemmed from a business logic flaw rather than a security misconfiguration This flaw allowed an authenticated user to unintentionally access another user's data, highlighting the issue of broken object level authorization Such vulnerabilities arise when application logic inadequately restricts access for authorized users.

Unique API logic flaws represent zero-day vulnerabilities specific to individual APIs, highlighting the need for resources like this book to educate penetration testers and bug bounty hunters on API security As security increasingly integrates into engineering and development processes, it is essential for modern engineering teams to prioritize API security, making this book a valuable guide for conducting security testing alongside functional and unit testing.

Effective API security testing requires a continuous and comprehensive approach, integrating testing into the development cycle to ensure that every release is thoroughly vetted before production Relying on infrequent tests, such as once or twice a year, is inadequate in keeping pace with rapid updates Identifying API vulnerabilities demands new skills, tools, and innovative strategies, highlighting the urgent need for enhanced API security measures in today's digital landscape.

Dan Barahona Chief Strategy Officer, APIsec.ai Inc.

Before we begin, I must thank and acknowledge some giants whose shoul- ders I have stood on for the creation of this book:

My family and friends for supporting me in all my endeavors.

API Fuzzing

“Fuzzing.” OWASP https://owasp.org/www-community/Fuzzing.

Exploiting API Authorization

Shkedy, Inon “A Deep Dive on the Most Critical API Vulnerability—BOLA (Broken Object Level Authorization).” https://inonst.medium.com.

Exploiting Mass Assignment

“Mass Assignment Cheat Sheet.” OWASP Cheat Sheet Series https:// c heatsheetseries.owasp.org/cheatsheets/Mass_Assignment_Cheat_Sheet.html.

REAL-WORLD API HACKING

THE STATE OF WEB API SECURITY 1

ATTACKING APIS 121

REAL-WORLD API HACKING 265

Ngày đăng: 11/04/2022, 15:02