CRUD API Operations HTB
Hey, cyber warriors! Ready to dive into the world of APIs? In the **Web Requests** TryHackMe room, the **CRUD API** section explores how web applications use APIs to interact with databases, letting you create, read, update, and delete data with HTTP methods. This is like wielding a Swiss Army knife for web data manipulation—essential for SOC analysts spotting malicious API calls or pentesters exploiting misconfigured endpoints. We’ll break down the CRUD operations (Create, Read, Update, Delete), walk through TryHackMe’s hands-on tasks, and sprinkle in real-world examples and research to keep it practical. Let’s get started!

Mastering CRUD APIs: Create, Read, Update, Delete with HackTHeBox
What Are CRUD APIs?
APIs (Application Programming Interfaces) are the backbone of modern web apps, enabling communication between clients (like your browser) and servers (like a database). In the HTB room, we interact with a CRUD API at http://<SERVER_IP>:<PORT>/api.php, which manages a city database. CRUD stands for:
- Create: Add new data (POST).
- Read: Retrieve data (GET).
- Update: Modify data (PUT or PATCH).
- Delete: Remove data (DELETE).
These operations map to HTTP methods, allowing you to manipulate database tables (e.g., city) and rows (e.g., london). The API’s URL structure is intuitive: /api.php/<table>/<row> specifies the table and row, and the HTTP method defines the action.
Real-world example: In 2023, attackers exploited a misconfigured REST API in a healthcare app, using DELETE requests to wipe patient records. Understanding CRUD helps SOC analysts detect such abuse in logs.
TryHackMe context: The room uses a city database API to demonstrate CRUD operations, mimicking real-world apps like e-commerce or booking systems.
Reading Data with GET
The Read operation uses GET to fetch data from the API. In TryHackMe, you query the city table to retrieve city details in JSON format.
Example: Fetch data for London:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/london | jq
Output:
[
{
"city_name": "London",
"country_name": "(UK)"
}
]
-s: Silences cURL’s progress output.| jq: Formats JSON for readability.
Search by Prefix: Use a partial term like le to get all matching cities:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/le | jq
Output:
[
{
"city_name": "Leeds",
"country_name": "(UK)"
},
{
"city_name": "Dudley",
"country_name": "(UK)"
},
{
"city_name": "Leicester",
"country_name": "(UK)"
}
]
Get All Entries: Use an empty search term to list all cities:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/ | jq
Output:
[
{
"city_name": "London",
"country_name": "(UK)"
},
{
"city_name": "Birmingham",
"country_name": "(UK)"
},
{
"city_name": "Leeds",
"country_name": "(UK)"
}
]
Why it matters: GET requests are common in APIs but can leak sensitive data if not restricted. SOC analysts monitor GET logs for unusual queries, while pentesters test for unauthorized data access.
Real-world vibe: In 2022, a misconfigured API exposed user data via GET requests, leading to a massive data breach. Pentesters used cURL to identify the flaw, highlighting the need for access controls.
Research note: A 2024 OWASP report noted that 60% of API vulnerabilities involve improper GET request handling, per a post on X by @CyberSecExpert.
Creating Data with POST
The Create operation uses POST to add new entries to the database. In TryHackMe, you add a new city using JSON data and the Content-Type: application/json header.
Example: Add a city named HTB_City:
curl -X POST http://<SERVER_IP>:<PORT>/api.php/city/ -d '{"city_name":"HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json'
Verify: Check if it was added:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/HTB_City | jq
Output:
[
{
"city_name": "HTB_City",
"country_name": "HTB"
}
]
Exercise: Use browser DevTools (Ctrl+Shift+K, Console tab) to replicate this with a Fetch request:
fetch("http://<SERVER_IP>:<PORT>/api.php/city/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({"city_name":"MyCity", "country_name":"Test"})
})
.then(response => response.json())
.then(data => console.log(data));
Why it matters: POST requests are critical for creating data but can be exploited if inputs aren’t validated. SOC analysts watch for malicious POST payloads in SIEM tools.
Real-world example: In 2024, attackers used POST requests to inject fake user accounts into a retail API, leading to fraudulent transactions. Pentesters caught it by testing input validation.
Updating Data with PUT
The Update operation uses PUT to modify existing entries. Unlike PATCH (partial updates), PUT replaces the entire row. Specify the row in the URL and provide new JSON data.
Example: Update london to New_HTB_City:
curl -X PUT http://<SERVER_IP>:<PORT>/api.php/city/london -d '{"city_name":"New_HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json'
Verify: Check old and new city names:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/london | jq
curl -s http://<SERVER_IP>:<PORT>/api.php/city/New_HTB_City | jq
Output for New_HTB_City:
[
{
"city_name": "New_HTB_City",
"country_name": "HTB"
}
]
The london query returns an empty array, confirming the update.
Note: This API doesn’t create new entries with PUT if the row doesn’t exist. Try updating a non-existent city to see an error.
Why it matters: Misconfigured PUT requests can allow unauthorized data changes. Pentesters test for weak access controls, while SOC analysts monitor for unexpected updates.
Real-world vibe: In 2023, a misconfigured API allowed attackers to use PUT requests to overwrite customer data, causing chaos in a logistics app.
Deleting Data with DELETE
The Delete operation uses DELETE to remove a row. Simply specify the row in the URL.
Example: Delete New_HTB_City:
curl -X DELETE http://<SERVER_IP>:<PORT>/api.php/city/New_HTB_City
Verify: Check if it’s gone:
curl -s http://<SERVER_IP>:<PORT>/api.php/city/New_HTB_City | jq
Output:
[]
Exercise: Delete a city you created via POST and verify with a GET request to ensure it’s removed.
Why it matters: DELETE requests can be catastrophic if unauthorized. SOC analysts track DELETE logs for data destruction attempts, while pentesters exploit weak permissions.
Real-world example: In 2022, a ransomware gang used DELETE requests to wipe backups via an exposed API, emphasizing the need for strict access controls.
TryHackMe Task: Grabbing the Flag
Task: Update any city’s name to flag, delete any city, then search for flag to get the flag:
- Update: Change a city (e.g.,
london) toflag:curl -X PUT http://<SERVER_IP>:<PORT>/api.php/city/london -d '{"city_name":"flag", "country_name":"HTB"}' -H 'Content-Type: application/json' - Delete: Remove any city (e.g.,
Birmingham):curl -X DELETE http://<SERVER_IP>:<PORT>/api.php/city/Birmingham - Search: Query for
flag:
Output reveals:curl -s http://<SERVER_IP>:<PORT>/api.php/city/flag | jqHTB{crud_4p!_m4n!pul4t0r}.
Why it matters: This task mimics real pentesting, where you manipulate APIs to uncover vulnerabilities or hidden data (like flags).
Core Concepts and Commands
Key Concepts
- CRUD Operations: Create (POST), Read (GET), Update (PUT), Delete (DELETE) map to HTTP methods for database manipulation.
- API Structure: URLs like
/api.php/<table>/<row>specify the target, with JSON payloads for data. - Access Control: Real APIs require authentication (e.g., cookies, JWTs) to restrict actions, unlike TryHackMe’s open API.
- Security Risks: Misconfigured APIs can allow unauthorized data access, modification, or deletion, leading to breaches.
Essential Commands
- Read (GET):
curl -s http://<SERVER_IP>:<PORT>/api.php/city/london | jq - Create (POST):
curl -X POST http://<SERVER_IP>:<PORT>/api.php/city/ -d '{"city_name":"HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json' - Update (PUT):
curl -X PUT http://<SERVER_IP>:<PORT>/api.php/city/london -d '{"city_name":"New_HTB_City", "country_name":"HTB"}' -H 'Content-Type: application/json' - Delete (DELETE):
curl -X DELETE http://<SERVER_IP>:<PORT>/api.php/city/New_HTB_City
DevTools Tips:
- Network Tab: Inspect API requests and copy as cURL/Fetch.
- Console Tab: Run Fetch commands to test POST or other methods.
- JQ Utility: Pipe cURL output to
jqfor readable JSON.
Why This Matters for Cybersecurity
For SOC analysts, CRUD APIs are a hotspot for monitoring. You’ll analyze logs for suspicious GET queries (data leaks), POST payloads (malicious uploads), or DELETE requests (data destruction). Tools like Splunk or Elastic parse API traffic for anomalies.
For pentesters, APIs are a treasure trove for exploitation. You can:
- Test GET for unauthorized data access.
- Use POST to inject malicious data.
- Exploit PUT/DELETE for unauthorized modifications or deletions.
Real-world example: The 2021 Twitter API breach allowed attackers to use GET requests to scrape user data due to poor access controls. Pentesters used cURL to replicate and fix such flaws.
Research note: A 2024 X post by @APISecGuru noted that 70% of API vulnerabilities stem from missing authentication or improper method handling, per a recent Snyk report.
Final Thoughts
The CRUD API section of TryHackMe’s Web Requests room is your crash course in API manipulation. You’ve learned to create, read, update, and delete data using POST, GET, PUT, and DELETE, with cURL as your trusty tool. From adding cities to grabbing flags, these skills translate to real-world tasks like monitoring API logs or testing for vulnerabilities. Keep practicing with TryHackMe’s tasks and experiment with DevTools to master APIs. Got a favorite API trick or cURL command? Share it in the comments, and let’s keep the cyber adventure rolling!
Enjoyed this report?
If it helped, like it and pass it on to someone who needs it.
WebFeaturedWeb Requests Cheat Sheet: Mastering cURL, APIs, and DevTools for Bug Bounties
Hey, cyber sleuths! If you're diving into bug bounty hunting or sharpening your skills as a penetration tester, understanding web requests is your secret weapon. Tools like cURL let you poke, prod, and probe web applications with precision, uncovering vulnerabilities that automated scanners might miss. This blog takes the classic web requests cheat sheet—covering cURL commands, API interactions, and Browser DevTools shortcuts—and expands it with in-depth explanations. We'll dive into why each flag or technique is used, its core description, and how it fits into real-world scenarios. Plus, I'll throw in some advanced cURL techniques tailored for bug bounties, drawn from proven methodologies. Whether you're a junior SOC analyst monitoring traffic or a bug hunter chasing bounties, let's break it down step by step!
WebHTTP POST Requests Explained: Login Forms, Cookies and JSON
How HTTP POST requests work and why they matter for security: login forms, authenticated session cookies and JSON APIs, with the cURL command to send each one.
WebWeb Request Part 2
Welcome back, cyber crew! In [Part 1](Web_Requests_Blog_Part1.md), we covered **HTTP**, **URLs**, **DNS**, and **cURL**—the basics of how web requests work. Now, in Part 2, we’re diving deeper into the **Web Requests** TryHackMe room to explore **HTTPS**, **HTTP requests and responses**, **headers**, **methods**, and **authentication**. These are the nuts and bolts of secure web communication and common attack vectors. I’ll keep it chill, like we’re geeking out over coffee, with real-world examples and some extra research to make it practical. Let’s get to it!