0xbugatti About me
Web Application Reverse Engineering
- Appsec

Web Application Reverse Engineering

Step 1: Application Vector Analysis

  • Subdomains Analysis :

    • api.example.com → Backend api based functions
    • admin.example.com → Privileged operations
  • Technology and Architecture Fingerprinting

    • By ToolswhatwebWappalyzer
    • Architecture pattern

    • MVC (Model-View-Controller) Django, Ruby on Rails, Laravel.
      • Common Routes:
        • /users, /posts, /dashboard
      • Expected Responses:
        • HTML with server-side rendering.
      • Authentication Flow:
        • Cookies & sessions for login persistence.
    • MVVM / SPA Angular, Vue.js (if client-side rendering dominates).
      • Common Routes:
        • /api/v1/users, /api/v1/posts
      • Expected Responses:
        • JSON responses (minimal HTML).
      • Authentication Flow:
        • JWT (JSON Web Token) or OAuth-based authentication.
    • Microservices Architecture
      • Common Patterns:
        • Separate APIs and Subdomains handling different functionalities:
        • auth.api.com → Authentication
        • payment.api.com → Payment processing
        • user.api.com → User management
      • Expected Responses:
        • JSON responses
        • Redirection
      • Authentication Flow:
        • API Gateway handling requests, JWT-based authentication.
    • Monolithic: Few subdomains (wwwblogstatic).
  • Server-Side Rendered (SSR) vs. Single Page App (SPA)?

    • SSR → Backend routes dynamically generate HTML.
    • SPA → Heavy JavaScript with API-driven functionality.
  • Client-Heavy vs. Server-Heavy Logic?

    • Client-Heavy → Reverse JS & Frontend State Handling.
    • Server-Heavy → Extract Backend Routes & API Interaction.

Step 2: Application url Analysis

  • Path Analysis:

    Endpoints can be analyzed through their URI structure to infer potential functionality:

    1. Resource-Oriented Paths
      Example: /users/{id}/profile
      Indication: Typically follows RESTful CRUD (Create, Read, Update, Delete) patterns, suggesting operations on user profile resources. Common HTTP methods:
      • GET (Retrieve)
      • POST/PUT (Create/Update)
      • DELETE (Remove)
    2. Action-Oriented Paths
      Example: /checkout/payment
      Indication: Represents a transactional workflow, likely involving:
      • Payment processing
      • Order finalization
      • State transitions in a checkout sequence
  • Query Parameters Analysis:

    • ?action=edit → Implies a state-modifying function
    • ?format=json → Suggests an API endpoint

Step 3 :Function & API Analysis

API classifications and Analysis

AspectRESTful APIHTML Response (MVC-Based APIs)GraphQL APIMicroservices API
FormatJSONHTMLJSONJSON or other (varies per service)
Examplejson { "id": 1, "name": "John Doe", "email": "[email protected]" }html <html><head><title>User Profile</title></head><body><h1>John Doe</h1></body></html>json { "data": { "user": { "id": "1", "name": "John Doe" } } }JSON responses are common across different services.
Endpoint(s)Multiple structured endpoints (/users, /posts)Server-side rendered page (no true API)Single /graphql endpoint with flexible queriesSeparate subdomains for each microservice (e.g., auth.api.com, payment.api.com)
Request TypeStandard HTTP methods (GET, POST, PUT, DELETE)Typically a GET request for page renderingFlexible queries using POST requestsVaries per service (usually HTTP requests)
Data StructureKey-value pairs (JSON)HTML content with embedded dynamic dataKey-value pairs with flexible queries (only requested fields)Key-value pairs (JSON) with varied structures depending on service
Backend FunctionExposes specific functionality as a service, typically for data retrieval and managementServer-side rendered page with backend logic for rendering viewsExposes specific functionality based on queriesEach microservice exposes specific functionality related to its domain
Use CaseSuitable for applications needing data exchange with defined endpoints.Suitable for rendering pages directly on the server.Ideal for frontend applications with dynamic, flexible queries.Ideal for large systems with modular, isolated services (e.g., authentication, payment)
StateStateless (each request is independent and has its own state)Typically stateful (server retains session information)Stateless (requests are independent)Stateless (services can be independently scaled)
Example Use CaseE-commerce website: retrieving user profile (/users/1), posting data (/posts)Server-rendered user profile page with user dataFlexible user data retrieval: /graphql?query={user(id: 1){name}}Independent services for user management (auth.api.com), payments (payment.api.com)

Functions Mapping

  • CRUD Operations Endpoints
    • GET , POST methods for API Function Endpoints
    • PUT, PATCH, DELETE methods
  • Authentication Endpoints:
    • JWT (JSON Web Token): Commonly used in REST APIs and microservices. JWTs are typically passed in HTTP headers (e.g., Authorization: Bearer <token>).
    • OAuth2: Used for delegating authorization to external identity providers (e.g., Google, Facebook).
    • API Keys: Simple way to authenticate clients, especially in public APIs.
    • Basic Auth: Simple authentication mechanism but less secure.
    • Session-based Authentication: Typically used in MVC-based architectures, storing session data server-side.
  • Authorization Endpoints:
    • Role-based Access Control (RBAC): Restricting access to resources based on the user’s role.
    • Attribute-based Access Control (ABAC): More granular, where access is based on attributes (e.g., user’s department, region).
    • OAuth2 Scopes: For fine-grained access control in OAuth-based systems.
  • Rate Limiting Endpoints
    • Rate Limiting: Imposes a maximum number of requests per client, per unit of time (e.g., 100 requests per minute).
    • Token Bucket: Controls the rate at which requests are allowed. Tokens are added to a bucket at a fixed rate, and requests consume tokens from the bucket.
    • Leaky Bucket: Similar to Token Bucket but with a more predictable flow of requests.
  • Throttling Behavior Temporarily blocks further requests from a client once the limit is reached, or provides an error response such as HTTP 429 (Too Many Requests).

Step 4: Object and Data Analysis from Responses

Data Behavior

  • JSON Data
     - Lightweight structure (compared to XML).  - Compatibility with virtually all programming languages (Python, Java, Go, .NET, etc.).  - Easy conversion to objects in most languages (JSON.parse() in JavaScript, json.loads() in Python).  - Schema Design & Versioning  - JSON is schema-less, but API designers can enforce structure using JSON Schema.          - Versioning Strategies:       - Use URL versioning: /api/v1/users       - Use header-based versioning: Accept: application/vnd.company.v1+json       - Use field-based versioning: { "version": "1.0", "data": { ... } }
    • JSON responses  caching layers:     - Edge caching (CDN like Cloudflare, Akamai)     - Application-level caching (Redis, Memcached)     - HTTP Cache-Control headers (ETag, Last-Modified)
    • Compression techniques:     - Gzip or Brotli to reduce payload size.     - Minimizing JSON fields to avoid unnecessary data transfer.
    • Handling Large Data Sets   - Pagination techniques:       - Offset-based: /api/users?offset=0&limit=50       - Cursor-based: /api/users?cursor=eyJpZCI6IjEwMCJ9   - Batch Processing:       - Instead of multiple small requests, use batch endpoints:           json{"users": [1, 2, 3, 4, 5]}
  • HTML Data
    • SEO Benefits: Search engines can crawl SSR pages better than JS-heavy SPAs.
    • Fast initial load times: No need to wait for client-side JS execution.
    • Common in MVC frameworks:
      • Django (Python)render(request, 'template.html', context)
      • ASP.NET MVC (C#)return View(model)
      • Ruby on Railsrender "template.html.erb"
    • Templating & Reusability
      • Component-based HTML rendering:
        • Jinja2 (Python){% include "navbar.html" %}
        • Thymeleaf (Java Spring Boot)<th:block th:insert="navbar :: content" />
        • Handlebars (Node.js){{> partials/navbar}}
      • HTML Fragment APIs:
        • Used in frameworks like HTMX, Turbo to dynamically update parts of a page without a full refresh.
    • Performance Optimization
      • Minimizing HTML payloads:
        • Remove redundant elements.
        • Use lazy loading for images <img loading="lazy">.
      • Edge caching (CDN like Cloudflare, Fastly):
        • Cache full HTML responses for unauthenticated users.
  • GraphQL fetched Data
    • Data Modeling and Shcema

      • Defining a GraphQL Schema (SDL - Schema Definition Language)
      type User {
          id: ID!
          name: String!
          email: String
      }
      
      type Query {
          user(id: ID!): User
      }
      
      • Resolvers & Data Fetching Logic
      const resolvers = {
        Query: {
          user: (parent, args, context) => {
            return db.findUserById(args.id);
          }
        }
      };
      
    • Over-fetching & Under-fetching

      • REST: /api/users/1 → Returns fixed fields (id, name, email, address, etc.)
      • Fetches only what is needed.
    • Single Endpoint vs. Multiple Endpoints

      • REST: /api/users, /api/posts, /api/comments
      • GraphQL: /graphql handles all requests.
    • Query Optimization

      • Batching & Dataloader Pattern:
        • Instead of making multiple database calls, use DataLoader (Facebook’s library) to batch requests.
      • Pagination & Filtering: query { users(limit: 10, cursor: "xyz") { id name}}
    • GraphQL in Microservices

      • Federation (Apollo Federation)
        • Combines multiple GraphQL APIs into a single schema.
      • Hybrid Approach (REST + GraphQL)
        • Use GraphQL as a gateway for REST microservices.

Data Structure

Once server responses are obtained, analyze:

  • Field names & types (IDs, timestamps, relationships).
    • Primary keys (id)
      • Identifiers for database records (e.g., id).
      • Found in <p>, <div>, or embedded in data- attributes.
    • Date fields (created_at)
      • Indicates sorting & timeline features
  • Nested Objects Relationships (User → Posts):
    • Nested relationships (users → posts).
    • Used for structured data display (nested objects).
    • Represented in lists (<ul>, <li>) or tables (<table>).
  • Links (<a>)
    • Shows relationships between resources.
  • Forms (<form>)
    • Shows user-interaction points (e.g., login, search).
    • Forms indicate data submission points, similar to POST or PUT requests in REST APIs.
  • Pagination & Sorting:
    • Links like ?page=2 or ?sort=asc may be embedded in <a href="..."> elements.
    • Pagination in HTML is usually done through navigation buttons or numbered links:

Step 5: Functional Hypothesis Table Based on the URL Behavioral Mapping

Deconstruct URL path semantics to reconstruct system design.

URL PatternPredicted FunctionLikely Objects
/usersUser listing (index)User[]
/users/:idUser profile (read)User
/users/:id/editProfile editing (update)User, Form
/products/search?q=Product search (query)Product[]
/cart/add?item_id=Cart modification (mutate)Cart, Product
/users/42/profileFetching user profile dataUser { id, name, email }
/cart/add?product=12Adding item to a shopping cartCart { items[] }
/transactions/export.csvGenerates a transaction reportTransaction { id, total }

Step 6: Page-Function-Object Matrix and Callbacks review

PageFunctionsObjects UsedHTTP Calls
/productsloadProducts()Product[]GET /api/products
/cartcheckout()Cart, OrderPOST /api/checkout
/users/:idfetchUser()User, ProfileGET /api/users/:id

Step 7: Error Debugging

Frontend (Client-Side) Issues

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesParameter leads to multiple possible pagesReact, Angular, VueQuery parameter redirects to multiple choices (like in search results)Browser asks user for selectionUse stricter filtering or direct URL handling
400 Bad RequestMissing mandatory query parameterJavaScript (Vanilla, React, Angular)Missing id in URL queryApp crashes or defaults to empty resultUse fallback/default values or notify the user
400 Bad RequestMissing only existing parameterReact Router, Angular RouterURL or query string is emptyServer returns 400Ensure URL parameters are present before routing
422 Unprocessable EntityMissing or incorrect data type for parameterJavaScript, TypeScriptType mismatch (string instead of int)Throws JavaScript error or fails silentlyValidate data types using typeof or parseInt()
500 Internal Server ErrorWebAssembly type mismatchWASMInvalid memory read/writeApplication crashesPerform input validation and type-checking before execution

Backend (Server-Side) Issues

PHP Frameworks (Laravel, Symfony, CodeIgniter)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesParameter leads to multiple routesLaravel, SymfonyMultiple routes with similar parametersBrowser asks user for selectionUse more specific route definitions
400 Bad RequestMissing required route parameterLaravel, Symfonyid parameter missing in routeReturns 400 Bad RequestUse route validation or optional parameter handling
400 Bad RequestMissing only existing parameterCodeIgniterForm or query parameters are emptyServer returns 400Validate form data before submission
422 Unprocessable EntityInvalid data type in requestLaravel, Symfony, CodeIgniterMismatched data types (e.g., string instead of int)Returns 422Use validation middleware or request->validate()
500 Internal Server ErrorEmpty POST bodyLaravel, SymfonyMissing body fieldsServer returns 500Validate body content before processing
500 Internal Server ErrorDatabase query error (missing parameter)Symfony, LaravelQuery lacks a required parameter (id for find())Server returns 500Use findOrFail() or implement error handling for missing data
404 Not FoundRoute not found for parameterSymfony, CodeIgniterURL routing fails for missing or incorrect parametersServer returns 404Implement 404 error handling with custom messages

Java-based Frameworks (Spring Boot, Spring MVC)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesMultiple redirects or resource selectionsSpring Boot, Spring MVCMultiple endpoints serving similar resourcesBrowser is asked to chooseImplement canonical routing or stricter filtering
400 Bad RequestMissing required parameter in requestSpring Boot, Spring MVCQuery or form parameters are missing (id, name)Returns 400 Bad RequestValidate parameters before processing the request
400 Bad RequestMissing only existing parameterSpring MVCSingle parameter required for URLServer returns 400Use @RequestParam with default value or validation
422 Unprocessable EntityData type mismatch in requestSpring BootPassing a String where an int is requiredReturns 422Use @Valid annotation for request validation
500 Internal Server ErrorInvalid database query (missing parameter)Spring BootQuery expecting id is not passedReturns 500Ensure parameter validation in controller layer before query execution

C#/.NET Frameworks (ASP.NET, ASP.NET Core)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesMultiple routes handling same resourceASP.NET, ASP.NET CoreAmbiguous routes with similar parametersBrowser is asked to chooseUse route constraints and more specific routes
400 Bad RequestMissing required query parameterASP.NET, ASP.NET CoreQuery parameter id is missing in requestReturns 400Use model binding and validation attributes like [Required]
400 Bad RequestMissing only existing parameterASP.NETParameter missing from form or queryReturns 400Ensure that form/query validation is in place
422 Unprocessable EntityIncorrect parameter type (e.g., string for int)ASP.NET CoreType mismatch (e.g., string instead of int)Returns 422Use model validation to enforce correct types
500 Internal Server ErrorInvalid database queryASP.NET, ASP.NET CoreSQL query with missing parameterReturns 500Validate query parameters and handle missing fields

Ruby on Rails (Ruby)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesMultiple possible redirectionsRuby on RailsMultiple routes with the same resourceBrowser is asked to chooseUse stricter route definitions
400 Bad RequestMissing required parameterRuby on RailsRequired parameter (id) is missingReturns 400Use strong parameters and default values
500 Internal Server ErrorDatabase query failure (missing parameter)Ruby on RailsQuery expecting id but id is not passedReturns 500Use find_or_create or find_by with proper error handling

Python-based Frameworks (Django, Flask)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesParameter variation leads to multiple routesDjangoMultiple views with similar resource typesBrowser is asked to chooseUse explicit URL matching or path converters
400 Bad RequestMissing required parameterFlask, DjangoMissing id in URL or form dataReturns 400 Bad RequestEnsure parameter presence before processing
422 Unprocessable EntityIncorrect data typeDjango, Flaskstring parameter passed where integer is expectedReturns 422Use Django’s form validation or Flask’s request.args for type checking
500 Internal Server ErrorMissing data or parameters in DB queryFlask, DjangoQuery for missing parameter (id)Returns 500Use error handling or get_object_or_404 in Django

JavaScript-based Frameworks (Express.js, NestJS)

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesMultiple endpoints handle similar resourceExpress.js, NestJSAmbiguous query or routeBrowser is asked to chooseUse express.Router or @Controller to define explicit routes
400 Bad RequestMissing required query or route parameterExpress.js, NestJSMissing parameter (id, username) in URLReturns 400 Bad RequestValidate parameters using middleware or decorators (@Query, @Param)
422 Unprocessable EntityIncorrect data typeExpress.js, NestJSQuery parameter of wrong typeReturns 422Use validation pipes in NestJS or middleware in Express.js
500 Internal Server ErrorMissing or invalid bodyExpress.js, NestJSMissing body or malformed dataReturns 500Use middleware like express.json() or @Body() in NestJS to validate request bodies

Security Edge Cases & Caching

Error CodeScenarioTechnologyCauseExpected BehaviorFix
300 Multiple ChoicesRedirect loop due to misconfigured routingNginx, Apache, CloudflareConflicting redirects or query parametersInfinite redirection loopImplement canonical redirects, check for circular routes
400 Bad RequestProxy stripping of headers or parametersNginx, Apache, AWS ALBProxy strips or modifies headers or query paramsReturns 400Configure reverse proxies to preserve headers and query params
500 Internal Server ErrorWAF blocking or modifying parametersModSecurity, AWS WAFParameters flagged as maliciousWAF blocks requestUse allowlist rules or bypass WAF for trusted sources

Step 8: Generate Interactive Diagram

  1. Hierarchical Site Map
example.com
   ├── /home
   ├── /products
   │   ├── /:id
   │   └── /search
   ├── /cart
   │   ├── /checkout
   │   └── /payment
   └── /users
       ├── /login
       └── /:id
           ├── /profile
           └── /settings
  1. Entity-Relationship Diagram (ERD)
mermaid
   erDiagram
       USER ||--o{ ORDER : places
       ORDER ||--|{ PRODUCT : contains
       CART ||--o{ PRODUCT : includes
  1. Functional Flowchart
mermaid
   flowchart TD
       A[Home] -->|Browse| B[Products]
       B -->|Add to Cart| C[Cart]
       C -->|Checkout| D[Payment]
       D -->|Confirm| E[Order Completed]