Location Research Breakthrough Possible @S-Logix pro@slogix.in

Local Outlier Factor-Based Detection of Abnormal API-Call Attacks in OWASP crAPI Through Behavioral Anomaly Analysis

Description

Modern applications use Application Programming Interfaces (APIs) to provide authentication, user management, object access, transactions, and other application functionality. API requests contain behavioral characteristics such as HTTP methods, request paths, parameter structures, request frequency, response status codes, and other request-level attributes that can be analyzed for security monitoring.

API abuse can occur when an attacker generates unusual requests, repeatedly accesses API resources, manipulates request parameters, or performs operations that differ from normal application behavior. Such activities may be difficult to identify when detection relies exclusively on predefined signatures or fixed rules.

In this use case, OWASP crAPI is deployed within an isolated cybersecurity laboratory. Kali Linux is used as the controlled security-testing environment, while Ubuntu Linux hosts the application and machine-learning analysis workflow.

An existing public API security dataset is used as the data source for the machine-learning stage. The available API traffic records and their associated metadata are inspected to determine whether they contain suitable normal and attack-related request information. The selected records are processed to identify features suitable for the proposed experiment.

The public dataset is processed to establish a consistent numerical representation of API-request behavior. Local Outlier Factor (LOF), implemented through Scikit-learn, is used to identify observations whose local density differs significantly from the surrounding request population. LOF measures local density deviations rather than relying solely on a global boundary.

The trained anomaly-detection workflow is then evaluated using API requests generated by normal application activity and a controlled abnormal API-call scenario against the local OWASP crAPI application. The controlled test is performed only within the authorized laboratory.

Captured API requests are processed using the same feature-extraction pipeline used during training. The LOF model analyzes compatible request features and produces an anomaly prediction and associated score. The results are compared with the known laboratory test conditions to evaluate whether the selected behavioral features help identify abnormal activity.

The complete workflow is:
Public API Security Dataset
→
Dataset Inspection
→
Normal Request Selection
→
Data Preprocessing
→
Behavioral Feature Extraction
→
LOF Model Training
→
OWASP crAPI Deployment
→
Normal API Activity
→
Controlled Abnormal API-Call Simulation
→
API Request Capture
→
Consistent Feature Extraction
→
LOF Anomaly Detection
→
Suspicious Request Identification
→
Detection Result Validation
→
Performance Evaluation

Existing Security Problem

Application: OWASP crAPI

OWASP crAPI stands for Completely Ridiculous API. It is an intentionally vulnerable, API-driven application designed for security education, training, and testing. It provides API security scenarios that can be explored within an authorized laboratory environment.

In this use case, OWASP crAPI is deployed locally to generate normal API activity and controlled security-testing traffic.

Existing Problem:

API-driven applications may receive legitimate requests alongside unusual or potentially malicious API activity. Abnormal behavior can include unexpected request patterns, unusual parameter combinations, repeated access attempts, or request characteristics that differ from the normal application baseline.

Traditional signature-based detection may identify known patterns but can miss behavioral variations that do not match predefined signatures. Fixed thresholds can also produce false alerts when legitimate application behavior varies.

Behavioral anomaly detection provides an additional approach by learning the characteristics of a normal request population and identifying observations that differ from the local behavioral patterns.

The security problem is:
API-Driven Application
→
Normal API Request Activity
→
Unusual API-Call Behavior
→
Potential API Abuse
→
Request-Level Behavioral Differences
→
Limitations of Fixed Rules and Signatures
→
Potentially Missed Abnormal Requests
→
Requirement for Behavioral Anomaly Detection
→
Requirement for Controlled Detection Validation

The proposed solution uses an existing public API security dataset to prepare the training data, app lies Local Outlier Factor to suitable numerical request features, and evaluates the resulting detection workflow against normal and controlled abnormal API activity generated in the laboratory.

Attack

Specific Attack: Controlled Abnormal API-Call Attack Against OWASP crAPI

The controlled attack scenario evaluates whether unusual API-call behavior can be identified by the proposed LOF-based anomaly-detection workflow.

OWASP crAPI is deployed within the isolated laboratory environment. Kali Linux is used as the authorized security-testing system, while Ubuntu Linux hosts the application and analysis components.

The test begins with legitimate API activity to establish a baseline for the selected application operations. A controlled abnormal API-call scenario is then performed against the local application. The scenario generates requests that differ from the baseline according to selected, observable request characteristics.

The test may include an unusual sequence of requests or repeated access attempts against an authorized test endpoint. The exact test behavior is selected after the application endpoints and public dataset features have been reviewed. The experiment does not assume that every abnormal request is malicious; the known test condition is retained separately for evaluation.

The resulting API requests are captured and transformed into numerical features using the same preprocessing procedure applied to the training data.

LOF analyzes the request features and identifies observations that differ from their local behavioral neighborhood. The resulting predictions are compared with the known laboratory activity to assess detection effectiveness.

Attack Behavior:
Kali Linux Security-Testing Environment
→
OWASP crAPI Local Application
→
Normal API Request Activity
→
Controlled Abnormal API-Call Simulation
→
Unusual Request Characteristics
→
API Request and Response Capture
→
Request Preprocessing
→
Behavioral Feature Extraction
→
LOF Anomaly Analysis
→
Suspicious Request Identification
→
Comparison with Known Test Conditions
→
Detection Result Validation

Security Concept

Local Outlier Factor-Based API Behavioral Anomaly Detection

The primary security concept is Behavioral Anomaly Detection Using Local Outlier Factor.

The first objective is to establish a suitable representation of API-request behavior using an existing public API security dataset. The available records are inspected to determine which request fields can be used consistently for model training and later laboratory testing.

The second objective is to apply Local Outlier Factor to the processed numerical features. LOF estimates the local density of observations and compares each observation with the local density of its nearest neighbors. An observation with substantially lower local density may be identified as an outlier.

The third objective is to validate the anomaly-detection workflow using API requests generated by the local OWASP crAPI application. The captured requests are transformed into compatible features and analyzed by the trained model.

The final objective is to compare the model output with the known test conditions and determine whether the selected features help distinguish the controlled abnormal activity from the observed normal behavior.

The assessment follows:
Public API Security Dataset
→
Dataset Suitability Assessment
→
Normal Request Selection
→
Data Preprocessin
→
Behavioral Feature Extraction
→
LOF Model Training
→
Normal API Activity Collection
→
Controlled Abnormal API-Call Simulation
→
API Request Capture
→
Consistent Feature Extraction
→
LOF Anomaly Prediction
→
Suspicious Request Identification
→
Detection Performance Evaluation

Defensive Mechanism

The security concept defines the overall security strategy.

The following are the specific defensive mechanisms implemented.

Normal Behavioral Baseline:

Normal API-request characteristics are processed to establish a behavioral representation of the selected request population.

Purpose: Establish a reference representation of the API behavior used during the experiment.

Local Outlier Factor Anomaly Detection

LOF analyzes the local density of request-feature observations and identifies observations that differ from their nearest neighbors.

Purpose
  • Flag API requests that exhibit unusual behavioral characteristics compared with the learned baseline.

Consistent Feature Extraction

The same fitted preprocessing and feature-extraction configuration is applied to training data and compatible newly captured requests.

Purpose
  • Maintain consistent feature representations during model training and detection.

API Request Monitoring

API requests generated during normal application activity and controlled testing are captured for analysis.

Purpose
  • Preserve request-level evidence for behavioral anomaly detection and validation.

Suspicious Request Flagging

Requests identified as anomalous by LOF are marked for further security review.

Purpose
  • Help analysts prioritize unusual API activity for investigation.

Controlled Attack Validation

The anomaly predictions are compared with the known controlled test conditions.

Purpose
  • Evaluate whether the detection workflow identifies the intended abnormal API activity.

Detection Performance Evaluation

The results are assessed using available ground-truth information and controlled test evidence.

Purpose
  • Identify successful detections, false positives, missed anomalies, and limitations of the selected features.

Security Tools

Primary Vulnerable API Application: OWASP crAPI

OWASP crAPI provides the intentionally vulnerable API environment used for controlled security testing.

Purpose
  • Provide a local API testing target.
  • Generate legitimate application requests.
  • Support controlled abnormal API-call scenarios.
  • Provide an environment for validating detection results.

Security Testing Platform: Kali Linux

Kali Linux provides the controlled security-testing environment.

Purpose
  • Send authorized API test requests.
  • Generate normal and controlled abnormal request activity.
  • Support repeatable laboratory testing.
  • Preserve test context for detection validation.

Application and Analysis Environment: Ubuntu Linux

Ubuntu Linux hosts the local application and/or machine-learning analysis components according to the laboratory configuration.

Purpose
  • Run the required application components.
  • Execute Python-based data processing.
  • Run the LOF analysis workflow.
  • Store captured test evidence.

Virtualization Platform: VirtualBox

VirtualBox provides the isolated laboratory infrastructure.

Purpose
  • Host Ubuntu and Kali Linux virtual machines.
  • Separate the application from the security-testing environment.
  • Support controlled network communication.
  • Reduce the risk of unintended interaction with external systems.

HTTP/API Inspection Tool: OWASP ZAP

OWASP ZAP is used to inspect HTTP requests and responses associated with the local API testing.

Purpose
  • Inspect API traffic.
  • Capture relevant requests and responses.
  • Preserve request-level security evidence.
  • Support comparison of normal and controlled abnormal activity.

HTTP Request Tool: cURL

cURL is used to send reproducible HTTP/API requests to the authorized laboratory application.

Purpose
  • Generate legitimate API requests.
  • Send controlled test requests.
  • Observe response status codes.
  • Support repeatable testing.

Network Discovery Tool: Nmap

Nmap is used to identify services exposed by the authorized laboratory environment.

Purpose
  • Discover the local application service.
  • Identify the relevant listening port.
  • Verify the expected laboratory service exposure.

Programming and Automation Tool: Python

Python provides the primary implementation environment for the anomaly-detection workflow.

Purpose
  • Process dataset records.
  • Extract behavioral features.
  • Integrate LOF with captured API requests.
  • Automate anomaly analysis and evaluation.

Machine-Learning Library: Scikit-learn

Scikit-learn provides the Local Outlier Factor implementation.

Purpose
  • Fit the LOF model using selected training features.
  • Analyze local density deviations.
  • Generate anomaly predictions for compatible unseen requests.
  • Support anomaly-score analysis.

Data Processing Tool: Pandas

Pandas is used to load, filter, transform, and organize the existing dataset and captured API records.

Purpose
  • Inspect dataset structure.
  • Select suitable request records.
  • Organize captured API traffic.
  • Prepare features and evaluation results.

Numerical Processing Tool: NumPy

NumPy supports numerical operations during feature preparation and model processing.

Purpose
  • Prepare numerical feature arrays.
  • Support data transformations.
  • Assist with feature-matrix processing.

Dataset Source: Public API Security Dataset

An existing public API security dataset is used to obtain API-request records for the machine-learning experiment. The available records, metadata, and labels are examined to determine their suitability for normal behavioral analysis and anomaly-detection evaluation

Purpose
  • Provide existing API-request records for data analysis.
  • Support the selection of suitable normal request examples.
  • Provide data for behavioral feature extraction and LOF model training.
  • Support evaluation when compatible ground-truth labels are available.

Database: SQLite

SQLite provides local storage for captured requests and detection results.

Purpose
  • Store relevant request metadata.
  • Record LOF predictions and anomaly scores.
  • Maintain controlled test information.
  • Preserve evaluation results.

Process

STEP 01

Prepare the Isolated Cybersecurity Laboratory

  • Create the laboratory using VirtualBox.
  • Configure Ubuntu Linux as the application and analysis environment.
  • Configure Kali Linux as the controlled security-testing system.
  • Establish the intended laboratory network connectivity.
  • Verify that the virtual machines can communicate as required.
  • Confirm that all security testing is restricted to the authorized laboratory environment.
  • Record the relevant virtual-machine and network configuration.
Tools: VirtualBox + Ubuntu Linux + Kali Linux
STEP 02

Deploy OWASP crAPI

  • Deploy OWASP crAPI in the isolated laboratory using its documented setup procedure.
  • Configure the required application components.
  • Start the application services.
  • Verify that the application is operational.
  • Confirm that the API endpoints required for the experiment are accessible from the authorized testing environment.
  • Record the application address and relevant service configuration.
Tools: OWASP crAPI + Ubuntu Linux + VirtualBox
STEP 03

Establish the Normal API Activity Baseline

  • Access OWASP crAPI using its intended application functionality.
  • Perform legitimate application operations
  • Generate normal API requests through the application or an authorized client.
  • Inspect the corresponding requests and responses.
  • Record available request characteristics, such as HTTP method, path, parameters, timestamps, response status, and other suitable metadata.
  • Preserve representative normal-activity records for comparison with the controlled test.
Tools: OWASP crAPI + OWASP ZAP + cURL
STEP 04

Verify Local API Service Exposure

  • Identify the authorized OWASP crAPI laboratory target.
  • Perform controlled service discovery from Kali Linux.
  • Identify the relevant application service and listening port.
  • Verify that the service is reachable through the intended laboratory network.
  • Record the service exposure information.
  • Confirm that the application is not being tested through an unintended external target.
Tools: Kali Linux + Nmap
STEP 05

Obtain and Inspect the Public API Security Dataset

  • Obtain an existing public API security dataset from its available public source.
  • Review the dataset documentation, available fields, labels, and usage terms.
  • Inspect the available records to identify suitable normal API-request data for model training.
  • Determine which request attributes can be used for behavioral feature extraction and LOF analysis.
  • Assess whether the dataset features are compatible with API traffic captured from OWASP crAPI, and document any limitations.
Tools: Python + Pandas
STEP 06

Select Suitable Normal Request Records

  • Review the available dataset records and their labels.
  • Identify records that are appropriate for establishing a normal behavioral baseline
  • Exclude attack-related records from the normal-only training subset where the dataset labels support that distinction
  • Preserve relevant request attributes needed for feature extraction
  • Check the number and diversity of selected records
  • Record the selection criteria and the resulting dataset size
  • Do not assume that every record in the public dataset is suitable for LOF training.
Tools: Python + Pandas
STEP 07

Preprocess the Public Request Data

  • Load the selected records into the Python environment.
  • Inspect missing values, inconsistent fields, duplicated entries, and malformed records.
  • Clean or exclude unsuitable records where required.
  • Normalize the representation of relevant request attributes.
  • Convert supported categorical or numerical attributes into a consistent numerical representation.
  • Preserve the preprocessing configuration for use with compatible laboratory traffic.
  • Record the transformations applied to the selected dataset.
Tools: Python + Pandas + NumPy
STEP 08

Extract Behavioral Features

  • Identify the request characteristics that can be represented consistently in both the selected dataset and the captured OWASP crAPI traffic.
  • Where supported by the data, consider numerical features such as request size, parameter count, path structure, HTTP method encoding, response characteristics, or request-frequency measurements.
  • Use only fields that are actually available and can be derived consistently from the training and test data.
  • Fit the required encoders or transformations on the training data.
  • Transform the selected normal records into a numerical feature matrix.
  • Verify that the resulting features are suitable for LOF analysis.
Tools: Python + Pandas + NumPy + Scikit-learn
STEP 09

Configure and Train the LOF Model

  • Configure the Local Outlier Factor algorithm.
  • Select an appropriate neighborhood size and an initial contamination setting for the training experiment.
  • Enable novelty detection if the model will be used to predict on previously unseen API requests.
  • Fit the model using the selected normal behavioral features.
  • Preserve the fitted model and feature-processing configuration.
  • Check that the model can process the training feature matrix successfully.
  • Record the model parameters for reproducibility.
Tools: Python + Scikit-learn
STEP 10

Establish the Initial Anomaly Baseline

  • Review the LOF output associated with the training data.
  • Inspect the distribution of the model's abnormality scores.
  • Identify whether some selected normal records are flagged as outliers.
  • Review the characteristics of those records before treating them as errors or anomalies.
  • Adjust the preprocessing or model parameters only when justified by the data and validation procedure.
  • Preserve the final selected model configuration.
  • Document that the baseline represents the selected dataset rather than all possible OWASP crAPI behavior.
Tools: Python + Scikit-learn + Pandas
STEP 11

Validate the Feature Pipeline with Normal crAPI Traffic

  • Generate legitimate API requests against the local OWASP crAPI application.
  • Capture the corresponding requests and responses.
  • Apply the established preprocessing and feature-extraction configuration.
  • Verify that the resulting features match the input dimensions and ordering expected by the trained LOF model.
  • Provide the compatible features to the model's novelty-detection interface.
  • Record the resulting predictions and anomaly scores.
  • Review any normal application requests flagged as anomalous.
Tools: OWASP crAPI + OWASP ZAP + cURL + Python + Scikit-learn
STEP 12

Perform the Controlled Abnormal API-Call Simulation

  • Use Kali Linux as the authorized security-testing environment.
  • Target only the local OWASP crAPI application.
  • Select an API endpoint and request behavior appropriate to the controlled experiment.
  • Generate a limited sequence of abnormal API calls that differs from the established normal activity in observable request characteristics.
  • Record the test start time, end time, target endpoint, and known testing conditions.
  • Avoid destructive operations and requests against external systems.
  • Preserve the test context for subsequent detection validation.
Tools: Kali Linux + OWASP crAPI + cURL + OWASP ZAP
STEP 13

Capture and Validate the Controlled Test Requests

  • Capture the API requests and responses generated during the controlled test.
  • Identify the relevant records using the known test time window and available request metadata.
  • Preserve the original traffic evidence.
  • Inspect the request characteristics that differ from the normal baseline.
  • Verify that the captured records correspond to the intended laboratory activity.
  • Record missing fields or differences that could affect feature extraction.
  • Keep the known test condition separate from the model prediction.
Tools: OWASP ZAP + cURL + OWASP crAPI + Python
STEP 14

Preprocess and Extract Features from the Captured Requests

  • Load the captured API requests into the Python analysis workflow.
  • Apply the same preprocessing and feature-extraction configuration established during training.
  • Reuse the fitted transformations rather than fitting new encoders independently on the controlled attack records.
  • Verify that the features have the expected dimensions and ordering.
  • Check that the public dataset and laboratory traffic are sufficiently compatible for meaningful comparison.
  • If critical feature differences prevent valid comparison, revise the feature selection or document the limitation before proceeding.
  • Preserve the processed feature vectors with references to their original request records.
Tools: Python + Pandas + NumPy + Scikit-learn
STEP 15

Perform LOF-Based Anomaly Detection

  • Load the trained LOF model.
  • Provide the processed unseen API-request features to the model's novelty-detection interface
  • Generate anomaly predictions for the captured requests.
  • Record the associated anomaly scores where supported.
  • Identify requests classified as outliers by the model.
  • Compare the results with the characteristics of normal and controlled abnormal API activity.
  • Preserve the predictions and their original request references for further evaluation.
Tools: Python + Scikit-learn + Pandas
STEP 16

Validate Suspicious API Request Detection

  • Review the requests flagged by LOF.
  • Compare the predictions with the known controlled test conditions.
  • Determine whether the selected abnormal API-call behavior was identified by the model.
  • Review normal requests that were flagged as anomalous.
  • Review controlled abnormal requests that were not flagged.
  • Distinguish an anomalous prediction from proof that an attack occurred.
  • Record the detection findings and any limitations caused by dataset or feature incompatibility.
Tools: Python + Scikit-learn + OWASP crAPI + OWASP ZAP
STEP 17

Store Detection Evidence and Evaluation Results

  • Create the SQLite database for the experiment.
  • Define suitable tables for request metadata, processed feature references, LOF predictions, anomaly scores, controlled test conditions, and evaluation results.
  • Store relevant request information and prediction results.
  • Associate each result with its original request record.
  • Preserve the known test condition separately from the model's output.
  • Verify that the stored records can be retrieved for final analysis.
Tools: Python + SQLite + Pandas
STEP 18

Perform Final Detection Validation and Security Review

  • Repeat the workflow using legitimate crAPI activity and controlled abnormal API-call scenarios.
  • Review the public-data preprocessing and feature-extraction configuration.
  • Compare the normal and abnormal request predictions.
  • Evaluate the results against known controlled test conditions and suitable labelled data where available.
  • Calculate appropriate evaluation metrics when reliable ground truth exists.
  • Document false positives, missed anomalies, and feature-compatibility limitations.
  • Confirm that LOF is used for anomaly detection and that any blocking functionality is treated as a separate mechanism.
  • Finalize the experiment with the model configuration, captured evidence, anomaly results, and documented limitations.
Tools: Python + Scikit-learn + Pandas + SQLite + OWASP crAPI + OWASP ZAP + cURL + Kali Linux + Ubuntu Linux

Outcome

OWASP crAPI is deployed within an isolated VirtualBox laboratory to provide a controlled environment for API security testing.

The public Cisco–Ariel University API Security Challenge dataset is obtained and inspected to determine whether its available request records and metadata support the planned anomaly-detection experiment.

Suitable normal request records are selected from the existing dataset and processed into numerical features without manually fabricating the training dataset.

The Local Outlier Factor model is trained using the selected behavioral features, establishing a baseline for identifying observations that differ from their local neighborhood.

Normal API activity generated by OWASP crAPI is captured and processed using the same feature-extraction workflow, validating whether the training and laboratory request representations are compatible.

A controlled abnormal API-call scenario is performed against the local OWASP crAPI application using Kali Linux, generating known test activity for detection validation.

The captured requests are transformed into compatible numerical features and analyzed by the trained LOF model to produce anomaly predictions and associated scores

The model predictions are compared with the known laboratory test conditions to assess whether the selected features help identify the controlled abnormal API behavior

SQLite stores the relevant request metadata, model predictions, anomaly scores, and evaluation results, providing a structured record of the experiment.

The complete workflow demonstrates public-dataset preparation, normal behavior selection, LOF training, controlled API attack simulation, request capture, behavioral feature extraction, anomaly detection, and evidence-based validation. The final assessment documents the observed detection results and limitations without claiming that LOF automatically prevents or blocks attacks.