Logical Bug which let me stop Users from Creating Ads at a Website
The server did not verify that the user who submitted the first step of ad creation was the same user who first accessed the redirect URL containing the ad ID. An attacker could guess the next ad ID and repeatedly request it, becoming the owner of the ad before the legitimate user, thereby preventing the user from completing the ad.
Published on bugwriteups.tech
Logical Bugs May 17, 2020 0 736 Add to Reading List
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
The target is a private bug bounty program, so the site is referred to here as Site.xyz. The application is a marketplace for used cars: users can buy and sell old cars, and there is a forum where users post articles, comment and like each other's posts. Selling a car requires posting an ad, and posting an ad requires paying the site an amount. After payment, moderators approve the ad, and once approved it is visible to everyone on the site.
The vulnerability sits in the ad creation feature. Creating an ad completely takes five steps, and the flaw is between step 1 and step 2. Step 1 is where the user enters the details of the car. Step 2 is where the user fills in contact details.

The author classifies the bug as a logical flaw: a case where an attacker can use or manipulate the working flow or data flow of an application harmfully. The technical impact is described as low, but the business impact is described as high.
Setup
The researcher used two accounts, opened in two different browsers, plus Burp Suite (Repeater and Intruder). No versions are given.
Finding it
After submitting step 1, the browser sends a POST request to the server. In that request the parameter PostModel.AdvertId is set to 0, which suggests that no ad id has been allocated yet at step 1.

The researcher sent the request to Repeater and submitted it, and got a 302 response.

The 302 redirection URL looks like:
site.xyz/advert/details?advertid=4251070&sh=user
Because AdvertId appears in that URL, the flow became clear: after step 1 the server allocates a specific id to the ad and sends a 302 redirect to continue with step 2.

Exploitation
Step 1: cross-account reuse of the redirect URL
The researcher created two accounts and opened them in different browsers. He submitted step 1 on the first browser through Burp and got a 302 response. He copied the redirection URL and opened it in the second browser. It worked: he could fill in step 2 on the second browser.
He then tried to access the same URL on the first browser and got a 403 unauthorized error.
The reasoning drawn from this: the server sends a 302 after step 1, the redirect URL contains advertId, and the first time that URL is opened the server determines the owner of the ad. The server does not check that the same user who submitted step 1 is the one opening the 302 redirection URL. So whoever sends the redirect URL to the server first becomes the owner of the ad, and nobody can access the ad after that first request.
At this point it was only a theory. In practice the user receives the redirect URL after step 1, and nobody can know either the AdvertId or the redirection URL except the owner. The researcher therefore focused on guessing AdvertId.
Step 2: confirming the id scheme
He created two ads and found that the site uses an increment function to determine the id of an ad. If the id of the first ad is 1000, the id of the second ad is 1001: for every ad, 1 is added to the id.

Step 3: racing the victim's first request
He created a dummy ad and found its id was 4251070, so the next ad would be 4251071. From the attacker account he sent the request to Intruder and changed the id to 4251071 in the URL. He set the payload type to null payloads and the payload options to continue indefinitely, then started the attack with 100 threads, so the specific request was sent continuously with 100 threads until he stopped it. The URL being sent continuously was:
site.xyz/advert/details?advertid=4251071&sh=user
Initially the attack got a 404 response, because at that time no ad existed with the value 4251071. Then, from another account, he started to create an ad. After finishing step 1, the server allocated 4251071 as the id of that ad and sent a 302 response to the browser.
At that moment the browser would send site.xyz/advert/details?advertid=4251071&sh=user to the server, but before it did, Intruder sent the request, because it was continuously sending the same request with 100 threads. The success ratio between attacker and user is therefore 100:1: there are 100 times more chances that the server receives the attacker's request first than the user's.
The server received the attacker's request first and set the attacker as the owner of the ad. The user could no longer access the ad. In Intruder, 200 responses started to arrive because 4251071 now existed and was accessible by the attacker. If the user tried to access the ad with id 4251071, he would receive a 403 error.
Step 4: making it continuous
The researcher notes that running this method continuously requires a script. He did not write one, but showed in the report that a script can be written:
id= 4251071
While 1==1:
##Code to check the response of the request
if response == 404:
continue
elif response == 200:
id+=1
continue
The idea is to keep requesting the next id; while the response is 404 the ad does not exist yet, and once a 200 comes back the attacker has taken ownership, so the id is incremented and the loop continues.
Root cause
The server allocates the ad id at step 1 and then relies on the redirect URL containing that id as the way to continue the flow. Ownership of the ad is decided by whichever request for that advertId reaches the server first, and the server does not verify that the user opening the redirect URL is the same user who submitted step 1. Because ids are sequential (each new ad adds 1 to the previous id), the next id is predictable, and because the attacker can send requests for that id continuously with many threads, the attacker's request is likely to arrive before the legitimate user's browser follows the 302. The report does not describe any server-side check that would have prevented this.
Impact
According to the report, the site has no technical impact but the following business impacts:
- No user can create ads at the site, because after the attack the specific ad belongs to the attacker.
- Creating an ad requires the user to pay the site an amount; if users are unable to create ads, the income of the site is affected.
The author describes the technical impact as low and the business impact as high.
Fix
The report does not state what was changed. Based on the described behaviour, the ownership decision should not depend on which request for an advertId arrives first: the server should bind the ad to the authenticated user who submitted step 1 and reject any other user opening the redirect URL, and it should not let an unrelated request claim an ad merely by being first.
Variants to test
- Sequential id allocation in multi-step forms. Start a flow that allocates an object id at an early step, then check whether the id increments by one per object. A positive result is being able to predict the next id from two of your own objects.
- First-request-wins ownership. Open the continuation URL of a flow you started in a second session or account. A positive result is that the second session can continue the flow, and the original session then gets 403.
- Race with many threads on the predicted id. Send requests for the next id continuously with a high thread count while a second account completes the step that allocates it. A positive result is a 200 for the attacker and a 403 for the legitimate user on the same id.
- Response-code driven automation. Poll the next id and branch on 404 versus 200, incrementing on success. A positive result is that the loop keeps taking ownership of each newly created object as it appears.
What happened, in plain words
A security researcher found a bug on a website where people buy and sell used cars. The site lets anyone post an ad to sell a car, but only after paying a fee and getting the ad approved by moderators. The researcher discovered that he could take over someone else's ad while that person was still creating it, and the real owner then received a 403 error. In the end, an attacker could stop other users from creating ads at all.
The bug is called a logical flaw. That means the website's code does what it was programmed to do, but the order of steps or the rules it follows can be abused. A simple comparison: imagine a cloakroom where you hand in your coat and get a ticket with a number. If the attendant gives the coat to whoever shows up first with that number, without checking who you are, then anyone who guesses the number can walk away with your coat. The website worked a bit like that.
The technical impact is described as low, but the business impact is described as high, because the site earns money from ads and the bug could stop ads from being created.

About the web application
The site has several features. Users can buy old used cars and sell their old cars. There is a forum where users post articles about cars, and anyone can comment on or like other people's posts. To sell a car, a user has to post an ad. Posting an ad costs money. After payment, moderators approve the ad, and once approved, everyone on the site can see it.
This was a private bug bounty program, so the researcher could not name the site. Throughout the report the site is called Site.xyz.
A bug bounty program is an arrangement where a company invites independent researchers to look for security problems in its systems and report them, often in exchange for a reward. A private program means only invited researchers can take part, and the details are not public.
What type of vulnerability is it?
The bug is a logical flaw. If an attacker can use or manipulate the working flow or the data flow of an application in a harmful way, that is called a logical flaw. The researcher found this one in the ad creation feature.
Two terms worth unpacking here. The working flow (or data flow) is the sequence of steps an application expects a user to follow: fill in this form, then that form, then pay, and so on. A logical flaw is when the steps themselves are fine but the rules connecting them can be bent. Compare it to a queue at a ticket counter: nothing is broken, but if the person at the front can take a ticket belonging to someone behind them, the queue can be abused.
Working flow of the feature
Creating an ad completely takes five steps. The bug sits between step 1 and step 2.
- Step 1: the user enters the details of his car.
- Step 2: the user fills in his contact details.
After submitting step 1, the browser sends a request to the server. A request is simply a message the browser sends to a website's computer (the server) asking it to do something, such as save a form or show a page. The server replies with a response.

The screenshot shows that request. In it, the value of the PostModel.AdvertId parameter is set to 0. A parameter is a named piece of data sent along with a request, like a field on a paper form. PostModel.AdvertId is the field that is supposed to hold the ad's identifier, and it is 0 at this point. That suggests no ad id has been allocated yet at step 1.
The researcher sent the request to the Repeater and submitted it. Repeater is a tool inside Burp Suite, a program security testers use to watch and modify the traffic between a browser and a website. Repeater lets you take a single captured request, edit it, and send it again as many times as you like, which is useful for experimenting without clicking through the site each time.
He got a 302 response.

A 302 response is a standard HTTP status code meaning "redirect": the server is telling the browser "the thing you asked for is somewhere else, go to this other address instead". HTTP status codes are three-digit numbers servers use to describe the result of a request. You will meet a few in this report: 302 (redirect), 404 (not found), 200 (OK, here is the content) and 403 (forbidden, you are not allowed).
The 302 redirection URL looked like this:
site.xyz/advert/details?advertid=4251070&sh=user
Line by line, in plain words:
site.xyzis the address of the website (a stand-in name, as explained above)./advert/detailsis the page on the site that shows the details of an ad.?marks the start of the query string, the part of a URL that carries extra data.advertid=4251070is a parameter namedadvertidwith the value4251070. This is the ad's identifier.&separates one parameter from the next.sh=useris a second parameter with the valueuser.
Because AdvertId appears in that URL, the flow became clear: after step 1 the server allocates a specific id to the ad and sends a 302 redirect so the browser continues with step 2.

My play with the logic
The researcher created two accounts and opened them in two different browsers. He tried to create an ad. He submitted step 1 on the first browser through Burp and got a 302 response. He copied the redirection URL and opened it in the second browser. It worked: he could fill in step 2 on the second browser.
He then tried to access the same URL on the first browser and got a 403 unauthorized error. A 403 means the server understood the request but refuses to allow it, usually because the person making it is not permitted.
The reasoning drawn from this: the server sends a 302 after step 1, the redirect URL contains advertId, and the first time that URL is opened the server decides who owns the ad. The server does not check that the same user who submitted step 1 is the one opening the 302 redirection URL. So whoever sends the redirect URL to the server first becomes the owner of the ad, and nobody can access the ad after that first request.
At this point it was only a theory. In practice the user receives the redirect URL after step 1, and nobody can know either the AdvertId or the redirection URL except the owner. The researcher therefore focused on guessing AdvertId.
How I made it work
He created two ads and found that the site uses an increment function to determine the id of an ad. If the id of the first ad is 1000, the id of the second ad is 1001: for every ad, 1 is added to the id.
An increment function just means the site counts up by one each time. This matters because it makes the next id predictable: if you know one id, you can guess the next one. Compare it to numbered tickets at a bakery: if the customer before you has ticket 57, you can be fairly sure the next one is 58.

He created a dummy ad and found its id was 4251070, so the next ad would be 4251071. From the attacker account he sent the request to the Intruder and changed the id to 4251071 in the URL. Intruder is another Burp Suite tool that sends the same request over and over, optionally changing a chosen part each time. He set the payload type to null payloads and the payload options to continue indefinitely, then started the attack with 100 threads, so the specific request was sent continuously with 100 threads until he stopped it.
A payload in this context is the value the tool inserts into the request on each attempt. A null payload means no value is inserted, so the request is simply repeated unchanged. A thread is one line of work the tool runs at the same time as the others; 100 threads means 100 copies of the request are being sent in parallel. "Continue indefinitely" means the tool keeps going until it is stopped by hand.
The URL being sent continuously was:
site.xyz/advert/details?advertid=4251071&sh=user
This is the same kind of URL as before, with the guessed next id 4251071 in place of the known one. The idea is to be the first to ask for that id once it exists.
Initially the attack got a 404 response, because at that time no ad existed with the value 4251071. A 404 means "not found": the server has nothing at that address. Then, from another account, he started to create an ad. After finishing step 1, the server allocated 4251071 as the id of that ad and sent a 302 response to the browser.
At that moment the browser would send site.xyz/advert/details?advertid=4251071&sh=user to the server, but before it did, Intruder sent the request, because it was continuously sending the same request with 100 threads. The success ratio between attacker and user is therefore 100:1: there are 100 times more chances that the server receives the attacker's request first than the user's.
This is a race condition: two parties are trying to do something at almost the same moment, and the outcome depends on who gets there first. The attacker does not need to be faster in any clever way; he just floods the server with attempts so that one of them is likely to land first.
The server received the attacker's request first and set the attacker as the owner of the ad. The user could no longer access the ad. In Intruder, 200 responses started to arrive because 4251071 now existed and was accessible by the attacker. A 200 means "OK, here is the content". If the user tried to access the ad with id 4251071, he would receive a 403 error.
How to make it work continuously
The researcher notes that running this method continuously requires a script. He did not write one, but showed in the report that a script can be written:
id= 4251071
While 1==1:
##Code to check the response of the request
if response == 404:
continue
elif response == 200:
id+=1
continue
Line by line, in plain words:
id= 4251071sets the starting id to the next ad id the attacker expects.While 1==1:is a loop that never ends, because 1 always equals 1. Everything indented below it repeats forever.##Code to check the response of the requestis a comment, a note for humans that the program ignores.if response == 404:checks whether the server said "not found".continuemeans go back to the top of the loop and try again with the same id, because the ad does not exist yet.elif response == 200:checks whether the server said "OK".id+=1adds one to the id, moving on to the next ad.continuegoes back to the top of the loop.
The idea is to keep requesting the next id; while the response is 404 the ad does not exist yet, and once a 200 comes back the attacker has taken ownership, so the id is incremented and the loop continues.
Impact
According to the report, the site has no technical impact but the following business impacts:
- No user can create ads at the site, because after the attack the specific ad belongs to the attacker.
- Creating an ad requires the user to pay the site an amount; if users are unable to create ads, the income of the site is affected.
The author describes the technical impact as low and the business impact as high.
Root cause
The server allocates the ad id at step 1 and then relies on the redirect URL containing that id as the way to continue the flow. Ownership of the ad is decided by whichever request for that advertId reaches the server first, and the server does not verify that the user opening the redirect URL is the same user who submitted step 1. Because ids are sequential (each new ad adds 1 to the previous id), the next id is predictable, and because the attacker can send requests for that id continuously with many threads, the attacker's request is likely to arrive before the legitimate user's browser follows the 302. The report does not describe any server-side check that would have prevented this.
Fix
The report does not state what was changed. Based on the described behaviour, the ownership decision should not depend on which request for an advertId arrives first: the server should bind the ad to the authenticated user who submitted step 1 and reject any other user opening the redirect URL, and it should not let an unrelated request claim an ad merely by being first.
Variants to test
- Sequential id allocation in multi-step forms. Start a flow that allocates an object id at an early step, then check whether the id increments by one per object. A positive result is being able to predict the next id from two of your own objects.
- First-request-wins ownership. Open the continuation URL of a flow you started in a second session or account. A positive result is that the second session can continue the flow, and the original session then gets 403.
- Race with many threads on the predicted id. Send requests for the next id continuously with a high thread count while a second account completes the step that allocates it. A positive result is a 200 for the attacker and a 403 for the legitimate user on the same id.
- Response-code driven automation. Poll the next id and branch on 404 versus 200, incrementing on success. A positive result is that the loop keeps taking ownership of each newly created object as it appears.
Glossary
- Bug bounty program: an arrangement where a company invites independent researchers to find and report security problems, often for a reward.
- Private program: a bug bounty program open only to invited researchers, with details not made public.
- Logical flaw: a bug where the application's rules or step order can be abused, even though the code works as written.
- Working flow / data flow: the sequence of steps an application expects a user to follow, and the data passed along them.
- Request: a message a browser sends to a server asking it to do something.
- Response: the server's reply to a request.
- Parameter: a named piece of data sent with a request, like a field on a form.
- Query string: the part of a URL after
?that carries extra data as name=value pairs. - HTTP status code: a three-digit number in a response describing the result, such as 200, 302, 403 or 404.
- 302: a redirect; the server tells the browser to go to another address.
- 404: not found; the server has nothing at that address.
- 200: OK; the request succeeded and the content follows.
- 403: forbidden; the server refuses to allow the request.
- Burp Suite: a tool security testers use to capture, inspect and modify traffic between a browser and a website.
- Repeater: a Burp Suite tool for editing and resending a single captured request.
- Intruder: a Burp Suite tool for sending the same request many times, optionally changing a chosen part each time.
- Payload: the value a tool inserts into a request on each attempt; a null payload inserts nothing.
- Thread: one line of work running at the same time as others; more threads means more parallel requests.
- Increment function: a counter that adds one each time, making the next value predictable.
- Race condition: a situation where two parties act at almost the same moment and the outcome depends on who arrives first.
- Authenticated user: a user the server has verified, usually by login.