---
description: HTTP basics and cookie manipulation
---

# Inventory Management

Apart from using Burp Suite, attackers can use the inspect element features of browsers with Ctrl - I.  Once open, by selecting the Application tab on the top and click the cookies button on the left hand side, it is shown a list of all our the cookies categorized per website. We can change the name and value of any cookie by double clicking it.Websites run on web servers. A web server is what is needed to essentially make the web site accessible on the wider internet. To communicate with a web server, the Hyper Text Transfer Protocol (HTTP) is used. HTTP usually works in the form of requests where the client (something like a browser) sends a request to complete a particular action to the website (technically the server). These acctions can range from logging in and retrieving pages to adding some data.

```
GET /login HTTP/1.1 [1]
Host: localhost:3000 [2]
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0 [3]
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [4]
Accept-Language: en-GB,en;q=0.5 [5]
Accept-Encoding: gzip, deflate [6]
Connection: close [7]
Upgrade-Insecure-Requests: 1 [8]

```

**\[1]** The HTTP verb that tells the server what kind of action the client is requesting. The most common types are:

* GET - used to retrieve resources (to pull a book off the shelf or open to a specific page of that book)
* POST - used to change the state on the server, to write something down

Both these requests can be implemented incorrectly which can lead to vulnerabilities.

The second part refers to the path the action is directed to (the client is telling the server to **get** the **login** page).

The thir part refers to the protocol (version 1.1 of the HTTP protocol).

Lines **\[2]-\[8]** are known as HTTP Headers. Headers are used by both the client and the server to pass extra information to each respective entity. Headers are in the form **Name:Value**.&#x20;

Here is some description of some of the request headers:

* **\[2]** Host - used to pass the domain name of the server. Useful in a situation where a server hosts multiple web sites so the server will know which page to pass back to the browser.
* **\[3]** User-Agent - specifies what browser made the request. Useful because different web pages render differently on web browsers so servers would know what exactly to serve depending on what browser requested it.

When the server receives the request, it responds to the action with an HTTP response. This is the response to the previous request:

```
HTTP/1.1 200 OK[1]
X-Powered-By: Express[2]
Content-Type: text/html; charset=utf-8[3]
Content-Length: 1493[3]
ETag: W/"5d5-ZdJhoKmkW86HklS/Wy+dOEaa80A"[4]
Date: Fri, 29 Nov 2019 00:20:52 GMT[5]
Connection: close[6]

<!DOCTYPE html>
<html>
```

**\[1]** The first part contains the version of the HTTP protocol that the server uses, and the second part is the **status/response code**. Response codes are used by the server to indicate the status of a request, and are divided into the following classes:

1. **1xx** - Information Requests
2. **2xx** - Successful Requests
3. **3xx** - Redirects
4. **4xx** - Client Errors
5. **5xx** - Server Errors

**\[2]-\[6]** are response headers used to pass information to the client. **\[2]** is prefaced with "X-", which is the format of a custom header (anytime we see something like that its worth finding out more).&#x20;

After **\[6]**, depending on whether the request is successful, the server will pass in content of a page (usually). The most common requested files are:

* HTML - syntax and language used to define the skeleton of a web page.
* JavaScript - language used to perform actions related to HTML.
* CSS - used to add styling to web pages.

Some important things to note about the HTTP protocol:

* HTTP is stateless - the server has no way to keep track of the order of requests the client is sending.
* HTTP is unencrypted and is usually used with TLS to form HTTPS, an encrypted form of HTTP which uses certificates to verify that the website really is what it claims to be.
* HTTP commonly runs on port 80 while HTTPS on 443.
* There are a lot more that goes into making a connection from a client to a server and HTTP is only part of that.

To keep track of what the client is doing, the server uses cookies.

Cookies are a key value pair in the form of name:value and can be used for various purposes. In this example cookies are used for session management, which refers to how the server keeps track of the actions performed by the client. Sessions are created with the following workflow:

* User sends username and password to the server to authenticate themselves
* Server checks if user details are correct and sets a cookie
* Every time the user performs an action, the browser send the cookie as part of the request to the server, which then checks the cookie to ensure the user is authorized to perform a particular action.

It is important to consider that cookie values will be encoded from time to time. A browser and server may not be able to interpret particular characters so the value placed in a cookie is encoded when its sent and decoded under the hood.&#x20;

An attacker would first try to identify how the cookies are used for session management. Using burp suite they would intercept every request mentioned in the flow above to examine how the server sets the cookie. Common hallmarks of insecure session management include:

* Using a fixed cookie value: if the cookie value is always the same, the attacker can use this to gain access to a user's account. Cookie values should be randomly generated whenever a user authenticates, so that attackers cant use it to gain persistent access to user's tokens.
* Using a predictable value as part of a cookie: if a server uses values such as username or numbers, an attacker could set his own cookie that a server would authenticate as a different user. Cookie values should be completely random.

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FUr_mwtgGqaapCL9S%2Fimage.png?alt=media\&token=7a4e0c43-383f-4ec8-85f8-f224abba43bd)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FXOS0SkOOjGPg5m4e%2Fimage.png?alt=media\&token=307dbc80-1432-4047-b684-d4c02350a078)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FYDi8OjRfQe6j-7Rf%2Fimage.png?alt=media\&token=101194f3-3842-43b0-a29b-ea334363bbdc)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FYPWEV61rbmKcTFH-%2Fimage.png?alt=media\&token=7ce39bba-24ad-4679-90f8-52fa48833d87)

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FYYSNWAQF4aaXMihs%2Fimage.png?alt=media\&token=f9b90313-e56e-4b8d-89c0-1da3a6ee34a8)

**1st step** -> swap the username _test1_ with _mcinventory_ and add the fixed cookie part of the value: _mcinventoryv4er9ll1!ss_

**2nd step** -> Encode it with base 64:

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FgLeg-TY7q-NVh_wj%2Fimage.png?alt=media\&token=9782a37f-3421-4af1-ba10-6a5542071d34)

**3rd step** -> Add the base64 encoded value to the cookie value in the browser and refresh the page:

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7Fh9zfPbKc_5QuL5m-%2Fimage.png?alt=media\&token=3095805e-544c-42f6-993a-3ee0564583de)

Answer:

![](https://3889206050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6DIEHtstePxj4NCmCC%2F-M7FJ8GGujfPN_I7I2M7%2F-M7FhPvPvNbInRj1i4k9%2Fimage.png?alt=media\&token=d3b6536a-9a48-4013-9ba0-f732d7795d69)



