[TOC] # Application Logic Application logic also called Business logic encompasses set of rules that defined how the application operates. Login Logic ![圖片](https://hackmd.io/_uploads/B1gK1c1O0.png) # Logic Flaw Vulnerability Logic flaws occurs when attacker can circumvent the rules. We can send invalid or unexpected value to the server .triggering unexpected behavior >Logic flaw is difficult be detective by auto scanner bug bounty hunters (Target) ## Arise Logic Flaw typically arise due to the developer making flaw assumption about how the user interact with application. Common factor of logic flaw include: - Inadequate Validation of user input - Complication systems or large code Common Functions may have logic flow - Authentication - Transactions ## Impact The impact of this vulnerability depend on functionality it is related to. # Type of Logic flawed Identify and Exploit Business Logic flawed individual unique, but we can grouped base on their initial design mistakes. ## Excessive Trust in Client-Side Controls Developer suppose user can only interact with server through the browser. -> The assumption of Business logic Flaw `Browser(JavaScript/HTML/CSS) <--> Application` ![圖片](https://hackmd.io/_uploads/H18DXcJd0.png) In fact we can utilize the proxy to intercept the request from the browser and modify the value, and send the manipulated data back to the application ->Bypass Front End Control Browser <--> Proxy(Malicious Tamper) <--> Application ![圖片](https://hackmd.io/_uploads/Syle491dR.png) ### LAB 1 - Excessive Trust Client-Side Control #### Mapping the target & Recon ![圖片](https://hackmd.io/_uploads/Ski_Lg_8a.png) #### Analysis Attack Surface ==Evaluated User Input== ![圖片](https://hackmd.io/_uploads/BJ1PveuI6.png) Sending the product price from the client to the server is a risky behavior. #### Exploit ![圖片](https://hackmd.io/_uploads/ByV1OedLT.png) ![圖片](https://hackmd.io/_uploads/BkdZdgu86.png) We can try to buy it with a price of 0.10. ![圖片](https://hackmd.io/_uploads/BJDqued8a.png) ![圖片](https://hackmd.io/_uploads/HJ-T_gdIT.png) Solved! ### LAB-2 : 2FA can be triggered by another User and Brute force #### Mapping the target and Recon - Crawl Target (Scanner) - Manually testing functionality #### Analysis Attack Surface - Parameters ![圖片](https://hackmd.io/_uploads/ByxC2guIa.png) - Two-Factor Authentication Flows User (login) -> Security Code (email) -> /myaccount #### Identifying Analysis Authentication Behavior When we login in, we will receive the 2FA mail POST /login ![圖片](https://hackmd.io/_uploads/S1xuGz_IT.png) It will set-cookie There have two parameters. one is verify, another is session. GET /login2 ![圖片](https://hackmd.io/_uploads/Sy0qMzu8p.png) Every time we resend the `/login2` GET request, our mail will receive 2FA security code ![圖片](https://hackmd.io/_uploads/r1TWQfOUT.png) verify parameter -> potential generation of 2FA code ![圖片](https://hackmd.io/_uploads/BJYIXfOLT.png) If the verify parameter is not valid for the user or not a winner, we will not receive the mail. ![圖片](https://hackmd.io/_uploads/r1J6QfOU6.png) ![圖片](https://hackmd.io/_uploads/ryw0XM_86.png) ![圖片](https://hackmd.io/_uploads/Hy3yVMO8a.png) So, we can tamper the cookie value to trigger the specific user generate security code This vulnerability is flaw assumption about Supposing user didn't temper the cookie value in client side!! #### Exploit When we trigger the Carlos's 2FA security code and send it to Carlos's email. There is no protection with brute force login!! We can attempt to brute force to guess Carlos's security code. ![圖片](https://hackmd.io/_uploads/rJeZcMuUp.png) ![圖片](https://hackmd.io/_uploads/HJYJqfdIT.png) ![圖片](https://hackmd.io/_uploads/SyOUYGuUT.png) ![圖片](https://hackmd.io/_uploads/Skj3FGuU6.png) ![圖片](https://hackmd.io/_uploads/ryqctMuUT.png) Solved !! ## Unconventional Input When developers only consider situations and restrict on the front-end JavaScript code, it becomes easy to tamper with values using a proxy. ### LAB-High Level logic vulnerability #### Mapping the Target & Recon ![圖片](https://hackmd.io/_uploads/SkDEUQ_8a.png) #### Analysis Attack Surface ![圖片](https://hackmd.io/_uploads/B1esv7OI6.png) ![圖片](https://hackmd.io/_uploads/HkCDw7dIa.png) If the quantity is negative, it may affect the price and become negative!!! We can try testing the quantity parameter if the restrict logic is implemented on the front-end client !! #### Identify ![圖片](https://hackmd.io/_uploads/BJJ3vX_La.png) #### Exploit If want to buy Jacket we can ![圖片](https://hackmd.io/_uploads/B1fsdQdU6.png) ![圖片](https://hackmd.io/_uploads/SyJGFQ_IT.png) ![圖片](https://hackmd.io/_uploads/H1yQYQu8a.png) Solved!! ### LAB-Low Level Logic Flaw #### Mapping the Target ![圖片](https://hackmd.io/_uploads/HkxNb8KU6.png) #### Analysis Attack Surface Parameters ![圖片](https://hackmd.io/_uploads/SkTPbLY86.png) We know Total price = price * quantity Functionality - Place Order We can attempt to test the quantity parameter to find the designed flaw #### Identify Logic Flawed Quantity is not supposed to be negative But we can attempt to buy a huge number of products to determine if there is an overflow issue with the price variable. ![圖片](https://hackmd.io/_uploads/HyB3GUYLp.png) ![圖片](https://hackmd.io/_uploads/HyB3GUYLp.png) PHP Integer OverFlow ![圖片](https://hackmd.io/_uploads/r1IWWUYU6.png) Now we discover there is an integer overflow issue Furthermore, after continuous purchases of the jacket, the price becomes positive ![圖片](https://hackmd.io/_uploads/B1FIXIFLT.png) #### Exploit We can buy another product to make the price less than the current credit we have. ![圖片](https://hackmd.io/_uploads/r1RuNIFLa.png) ![圖片](https://hackmd.io/_uploads/BJwKELtL6.png) ![圖片](https://hackmd.io/_uploads/HkMcN8F86.png) Solved !! ### LAB 3 - Inconsistent handling of exceptional input / Input not check length But check permission have length limit ! #### Mapping the target # Recon ![圖片](https://hackmd.io/_uploads/HkrTo8tUa.png) Discovering Contain /admin ![圖片](https://hackmd.io/_uploads/Hk7ZfvYL6.png) #### Analysis Attack Surface ![圖片](https://hackmd.io/_uploads/HyZQhUFL6.png) - [x] Evaluated User Input Functionality - Register Processing ![圖片](https://hackmd.io/_uploads/SJ7C5ItUT.png) ![圖片](https://hackmd.io/_uploads/H1LgiIt8T.png) ![圖片](https://hackmd.io/_uploads/ByEYsUFL6.png) #### Identify Testing Register functionality - Same Account Testing (space)meowhecker ![圖片](https://hackmd.io/_uploads/H1TaAItUT.png) ![圖片](https://hackmd.io/_uploads/S1miC8t86.png) Evaluated User Input - Username ![圖片](https://hackmd.io/_uploads/SkXFMDYLp.png) - Email ![圖片](https://hackmd.io/_uploads/Byl2zwK8p.png) ![圖片](https://hackmd.io/_uploads/r11mXDK8p.png) ![圖片](https://hackmd.io/_uploads/HkX5mwFU6.png) ![圖片](https://hackmd.io/_uploads/Hy4UNvYIT.png) There is inconsistent handling of email input Register allows us to use a very long email to register But my-account will automatically intercept too long email strings #### Exploit Normal User ![圖片](https://hackmd.io/_uploads/ryW0EwK8a.png) If the my-account endpoint will automatically intercept too long email strings, and this value will be processed by some validation, it could be exploited. ``` intercept(emial) emaill = 'meow......(intenal-email)@our-email-server' .... If (email = internal-email){ do some thing ~~~ } ``` Measure Email offset XD pattern ``` Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3Aw4Aw5Aw6Aw7Aw8Aw9Ax0Ax1Ax2Ax3Ax4Ax5Ax6Ax7Ax8Ax9Ay0Ay1Ay2Ay3Ay4Ay5Ay6Ay7Ay8Ay9Az0Az1Az2Az3Az4Az5Az6Az7Az8Az9Ba0Ba1Ba2Ba3Ba4Ba5Ba6Ba7Ba8Ba9Bb0Bb1Bb2Bb3Bb4 ``` ![圖片](https://hackmd.io/_uploads/SyD5dwtU6.png) ![圖片](https://hackmd.io/_uploads/rJUouPKUa.png) ![圖片](https://hackmd.io/_uploads/S1wTuvtU6.png) It allow 255 Char ![圖片](https://hackmd.io/_uploads/r1ibzdtUT.png) ``` baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%40dontwannacry.com.exploit-0a5e00dd04fcc30180d6b10801da00f0.exploit-server.net ``` ![圖片](https://hackmd.io/_uploads/SkjIGOY8p.png) ![圖片](https://hackmd.io/_uploads/SkBiV_Y86.png) ![圖片](https://hackmd.io/_uploads/r1M6EOY8T.png) Solved!! ## Making Flawed Assumption about user behavior One of the common Flawed assumption is macing flawed assumption about user behavior ### Excessive trust the Registered User In Some application, when the user passed the strict control initially, it will be seen as trusted, Resulting lax enforcement control. Business rule and security measure probably not consistent implement over the application This can lead to potentially dangerous loopholes ### LAB- Register User can Modify mail to Internal Mail #### Mapping the target & Recon ![圖片](https://hackmd.io/_uploads/SyemlKtIa.png) Content Discover ![圖片](https://hackmd.io/_uploads/r11AyYt8a.png) #### Analysis Attack Surface login change email register Parameters ![圖片](https://hackmd.io/_uploads/SytueYF86.png) /my-account/change-email -> probably allow the user already been Email authenticate to change arbitrary mail to sensitive or internal mail #### Identify ![圖片](https://hackmd.io/_uploads/SkoRWFY8T.png) ![圖片](https://hackmd.io/_uploads/HksgfKYUa.png) #### Exploit ![圖片](https://hackmd.io/_uploads/r1iZftFLp.png) Solved !! ### Remove Parameters or value Browser may prevent the user form submitting a form without a request value When probing for this flawed assumption, we should remove each parameter in turn and observe the response. - One remove the parameter at a time to ensure all related code path are archived - Deleting the value or the name of parameter and value separately. ![圖片](https://hackmd.io/_uploads/r1PR_RsU6.png) URL, Post Data, Cookie ### LAB- Server-side no to check Current password parameter whether exists ? #### Mapping Target & Recon Crawl & Manual & Content Discovery ![圖片](https://hackmd.io/_uploads/Sykup0oUT.png) #### Analysis Attacker Surface Parameters ![圖片](https://hackmd.io/_uploads/BkcF00sLT.png) Application Functionality - Change Email issue: Didn't require the password but it have CSRF token ! - Change Password - Admin interface `/admin` ![圖片](https://hackmd.io/_uploads/HyklpAj86.png) #### Identify ![圖片](https://hackmd.io/_uploads/B1eTfknUp.png) we could use proxy bypass the front-end control - CSRF ![圖片](https://hackmd.io/_uploads/BJSjM13IT.png) - username ![圖片](https://hackmd.io/_uploads/ryp-mJh8a.png) ![圖片](https://hackmd.io/_uploads/HkHP7knLT.png) - password ![圖片](https://hackmd.io/_uploads/BJXeNy2Lp.png) ![圖片](https://hackmd.io/_uploads/ByFVNJ2Ua.png) There is flawed assumption to allow us the change the password without the current password #### Exploit Username -> controllable Current-password-require -> bypass Change the administrator password to escape privilege ![圖片](https://hackmd.io/_uploads/rJqQH1hIp.png) ![圖片](https://hackmd.io/_uploads/SJBPBJn8p.png) Solved !! ### LAB Removing Token Parameter to reset password #### Mapping the Target & Recon #### Analysis Attack surface parameters ![圖片](https://hackmd.io/_uploads/ByPool2Lp.png) Functionality - Reset password - Email Change #### Identify Evaluated Reset Password functionality Reset password URL `/forgot-password?temp-forgot-password-token=3jg5m8ar4pdyqqfh3cpbhgqv9mn2861h` parameter ![圖片](https://hackmd.io/_uploads/r12UhxnUp.png) - Token ![圖片](https://hackmd.io/_uploads/rJYFAl3Ip.png) - User ![圖片](https://hackmd.io/_uploads/B15qCe38T.png) ![圖片](https://hackmd.io/_uploads/BkE11ZhUp.png) Here, we found the interesting response 302 found #### Exploit We can attempt to login in carlos:meowhecker ![圖片](https://hackmd.io/_uploads/ryT6Cx38T.png) Solved ! ### Intend Sequence Many application rely on predefined workflow to complete certain functionality - multi-factor authentication - transactions .. If attacker didn't follow the intend sequence, the flawed assumption will be exploited to bypass some necessary Step and compromise whole application !!! ### LAB Management page not check 2FA session ![圖片](https://hackmd.io/_uploads/Bk0dd6muC.png) #### Mapping ![圖片](https://hackmd.io/_uploads/H1Iqu6XdA.png) #### Identify & Exploit ![圖片](https://hackmd.io/_uploads/HyYzK6Qd0.png) ![圖片](https://hackmd.io/_uploads/S1S4tTmdC.png) Solved ### LAB- Insufficient Workflow validation #### Mapping the Target & Recon ![圖片](https://hackmd.io/_uploads/rkFqi6m_C.png) #### Analysis Attack Surface Parameter ![圖片](https://hackmd.io/_uploads/SkQ77L3Ia.png) Functionality - change-email - place order #### Identify & Exploit Testing Place order -> normal workflow ![圖片](https://hackmd.io/_uploads/HJD1NInUp.png) Skip certain Step testing `/cart/checkout` I think it probably check current credit have to great then the the price of the product we add jacket to our car And skip `checkout` ![圖片](https://hackmd.io/_uploads/BkYeBU2LT.png) We buy the jacket (1337.00) **Your order is on its way!** ### LAB- Drop the identify select request to privilege escalate #### Mapping the Target & Recon ![圖片](https://hackmd.io/_uploads/r1oMd8h8p.png) #### Analysis Attack Surface Parameters Functionality - Select role - user - content auther ![圖片](https://hackmd.io/_uploads/HyKEOL2UT.png) #### Identify & Exploit Select ROle ![圖片](https://hackmd.io/_uploads/BJp3uI2LT.png) Attempting to skip the select-role Due to the request of select-role is following the login Post request. we can utilize Intercept to drop the request. ![圖片](https://hackmd.io/_uploads/By1rWXpUp.png) ``` LOGIN:session yKwfwfSO9hYMnuMbTlIT5Sl35krlWG56 ``` DROP ![圖片](https://hackmd.io/_uploads/SyhwbmpL6.png) back to home page ![圖片](https://hackmd.io/_uploads/rk1QF07_R.png) solved !! ## Domain-specific Flawed In real word testing, we will encounter various business domain site. IF we want to find the Business logic flaws in those site, Reading the specific document or asking the expert to understand the specific domain knowledge is necessary. It will help us to identify the logic flaw more easy in application context. ### LAB-Flawed enforcement of business logic #### Mapping the Target & Recon #### Analysis Attack Surface Functionality - Place Order -> cart/checkerout - Sing up newsletter -> We will receive new Coupon (haha) -401 price WorkFlow Place Order + Coupon ![圖片](https://hackmd.io/_uploads/BJWWHVTIT.png) ![圖片](https://hackmd.io/_uploads/r1ozrVT8a.png) Not enough store credit for this purchase #### Identify Try the skip Check out steps ![圖片](https://hackmd.io/_uploads/B12j84aUT.png) ![圖片](https://hackmd.io/_uploads/SJYQ6VaUa.png) Fail ! Testing Sing up newsletter ![圖片](https://hackmd.io/_uploads/SJgN54p8p.png) ``` SIGNUP30 ``` ![圖片](https://hackmd.io/_uploads/Sy2w546Up.png) I guess it will only check the current Coupon are applied, so we can swap the both coupon to bypass the exists coupon limit. ![圖片](https://hackmd.io/_uploads/rytooV68T.png) #### Exploit ![圖片](https://hackmd.io/_uploads/HJxU2VaIp.png) ![圖片](https://hackmd.io/_uploads/SkrP3V6IT.png) Solved !! ### LAB-Infinite money logic flawed #### Mapping the Target & Recon ![圖片](https://hackmd.io/_uploads/BkbbyBaLa.png) #### Analysis Attack Surface Parameters ![圖片](https://hackmd.io/_uploads/r1e904TIp.png) Functionality - Gift code - Update email - Coupon - Place Order #### Identify & Exploit --> Testing Gift code ![圖片](https://hackmd.io/_uploads/H1yWAEaLp.png) gift code ``` b5QqZ0nyJa ``` ![圖片](https://hackmd.io/_uploads/Hy9SRNTL6.png) ![圖片](https://hackmd.io/_uploads/B1fUAE6Ua.png) IF we buy the magic-car again ![圖片](https://hackmd.io/_uploads/HJj6grTLa.png) ![圖片](https://hackmd.io/_uploads/ByyJWHpIT.png) Using Macro automatically increase the money ![圖片](https://hackmd.io/_uploads/By5aLda8T.png) ![圖片](https://hackmd.io/_uploads/rJVZwuaIa.png) ![圖片](https://hackmd.io/_uploads/Hk6zwuaLa.png) ![圖片](https://hackmd.io/_uploads/ry_yq_TIa.png) ![圖片](https://hackmd.io/_uploads/HJfSwOTUp.png) ![圖片](https://hackmd.io/_uploads/S17vvdaIa.png) ![圖片](https://hackmd.io/_uploads/Hk9U9_aL6.png) setting Scope ![圖片](https://hackmd.io/_uploads/SyJJ3Ia8T.png) If we macro setting is finished , we can use the repeater or intruder to increase our money !!! Send to intruder ``` GET /product?productId=1&x=§1§ ``` ![圖片](https://hackmd.io/_uploads/Bk1kidTUa.png) Send 500 -> `3*500 = 1500` ![圖片](https://hackmd.io/_uploads/ryKGsdTLp.png) Threading = 1 ==impotent!!== These is a workflow. we can't use multi-threading ![圖片](https://hackmd.io/_uploads/B1U9supIp.png) ![圖片](https://hackmd.io/_uploads/H1fu2dp8p.png) ![圖片](https://hackmd.io/_uploads/BkpvrKp86.png) ![圖片](https://hackmd.io/_uploads/rkb9rtp8T.png) Solved ## Providing an Encryption oracle (skip !!!) ## Email Address parser discrepancies Email Format -> local-part@domain ![圖片](https://hackmd.io/_uploads/rJegmLQ50.png) Some website will extract the domain form the email to determine which organizations send the mail But we can Attempt to manipulate the mail address to access some sensitive functionality. e.g. ### Survey #### Quoted characters RFC Document https://datatracker.ietf.org/doc/html/rfc2822#section-3.2.2 local-part 通常有特殊含義的字符時,會用雙引號包起來 ``` "user.name"@example.com 被解析為 user.name@example.com,其中點號(.)被保留,而不會引起語法錯誤。 "user"name"@example.com 被解析為 user"name@example.com,其中引號(")是 local-part 的一部分,反斜杠讓它能夠合法存在。 --------------------------------- "\""@example.com Local-Part -> " Domain -> example.com "@"@example.com Local-Part -> @ Domain -> example.com ``` #### FWS / Comments https://datatracker.ietf.org/doc/html/rfc2822#section-3.2.3 Folding White Space 是電子郵件格式中為了增強可讀性和兼容性而設計的機制,允許在適當的位置對長行內容進行折疊 在過長地方&空白字符處 插入-> CRLF (Carriage Return Line Feed) ``` (foo)user@(bar)example.com foo and bar -> be ignore by parser local-part = user domain = example.com ``` #### UUCP (Unix to Unix copy protocol UUCP is an ancient protocol Using situation -> No internet / low bandwidth ``` meowhecker.com!meowhacker Local Part -> meowhecker domain -> meowhecker.com ``` Sendmail(電子郵件伺服器) 8.15.2. ``` oastify.com!collab\@example.com \@ -> escape @ ``` Postfix (電子郵件伺服器) 3.6.4 ``` collab%psres.net(@example.com 1. -> example.com 2. -> collab%psres.net ``` ### Parser discrepancies #### unicode overflow Attempting Bypass multiple '@' limitation ! PHP char function