$25k GitHub account takeover & justCTF 2023 CSRF+XSS writeup

Bug Bounty Reports Explained
13 Jun 202407:29

Summary

TLDRThis video explores the nuances of web application security vulnerabilities, highlighting how developers' assumptions can lead to security flaws. The presenter demonstrates two examples, one involving a GitHub account takeover that earned a $25,000 reward, and another showcasing a CTF challenge. The video delves into the intricacies of CSRF protection, the misuse of the HEAD method in frameworks, and the critical distinction between tokenizing and parsing in sanitization processes, which can inadvertently introduce XSS vulnerabilities. The speaker also invites viewers to participate in an upcoming CTF event to sharpen their hacking skills, emphasizing the importance of understanding these concepts in web security.

Takeaways

  • πŸ”’ Every security vulnerability often stems from a developer's incorrect assumption or an unexpected behavior from frameworks.
  • 🎯 The speaker created a CTF challenge inspired by a $25,000 GitHub account takeover incident.
  • πŸ›€οΈ In web applications, routes are typically defined by specifying the path, methods, and the function to handle requests, with CSRF protection often applied to state-changing requests.
  • πŸ”„ The HEAD method in HTTP can sometimes bypass CSRF protection if frameworks treat it similarly to GET, despite differences in request handling.
  • πŸ€Ήβ€β™‚οΈ The speaker invites participants to a CTF event organized by their team, justCatTheFish, emphasizing the opportunity to develop hacking skills.
  • πŸ“… The online teaser for the CTF event is scheduled from June 15th for 24 hours, with a link provided in the description for registration.
  • πŸ™ Sponsors such as Trail of Bits, OtterSec, HexRays, and SECFORCE are acknowledged for their support, with links to them in the description.
  • πŸ•΅οΈβ€β™‚οΈ The script discusses the nuances of sanitization in web applications, highlighting the difference between tokenizing and parsing HTML inputs.
  • 🧩 The mistake in the script's example was not in the sanitization logic but in how the input was tokenized, leading to a potential XSS vulnerability.
  • 🌐 The importance of understanding HTML namespaces is underscored, as tags behave differently across namespaces, affecting the effectiveness of security measures.
  • πŸŽ–οΈ The final payload in the script's example exploits an XSS vulnerability, which could be used to exfiltrate sensitive information like flags in a CTF challenge.
  • πŸ“š The speaker encourages viewers to check out another video for a write-up on a SQL injection task, providing a link on the screen.

Q & A

  • What is the primary cause of security vulnerabilities in web applications according to the video?

    -The primary cause of security vulnerabilities in web applications is developers making wrong assumptions, either through their own mistakes or due to the unexpected behavior of frameworks.

  • What is the purpose of the CTF challenge mentioned in the video?

    -The purpose of the CTF challenge is to demonstrate two examples of security vulnerabilities inspired by a $25,000 reward account takeover on GitHub, and to encourage participants to develop their hacking skills.

  • How does the CSRF protection work in the context of the video?

    -CSRF protection works by automatically requiring a CSRF token for all POST, PUT, DELETE, and other requests that are intended to change something on the server. It is not required for GET requests, which are only supposed to serve the response.

  • Why is the HEAD method significant in the context of the video?

    -The HEAD method is significant because many frameworks treat it the same as GET during the routing stage, but it can bypass CSRF protection if the if statement in the function checks specifically for GET, allowing access to the block of code that should be protected.

  • What is the difference between tokenizing and parsing in the context of the video?

    -Tokenizing is the process of breaking down code into tokens without applying namespace rules, while parsing applies these rules, which can lead to different outcomes especially when dealing with namespaces like SVG that can alter the behavior of tags.

  • How does the video explain the exploitation of the XSS vulnerability?

    -The video explains that the exploitation of the XSS vulnerability occurs when the sanitizer's tokenization process fails to recognize an XSS payload within an SVG namespace, allowing the script to execute in the browser.

  • What is the role of the 'textarea' tag in the context of the XSS vulnerability discussed in the video?

    -In the HTML namespace, the 'textarea' tag can only contain text, making it resistant to XSS payloads. However, when wrapped in an SVG tag, changing the namespace, it becomes vulnerable to XSS attacks.

  • What is the significance of the 'script' tag in the XSS vulnerability discussed?

    -The 'script' tag is significant because it is used to execute JavaScript code. In the video, it is shown that when the 'script' tag is within an SVG namespace, it can bypass sanitization and lead to an XSS attack.

  • What is the role of the CTF challenge organizer 'justCatTheFish' in the video?

    -The role of 'justCatTheFish' is to organize the CTF challenge, provide a platform for participants to develop their hacking skills, and to offer a new task for the current year's competition.

  • How can participants join the CTF challenge mentioned in the video?

    -Participants can join the CTF challenge by following the link provided in the video description, which leads to the event's registration or information page.

  • What is the significance of the sponsors mentioned in the video?

    -The sponsors, Trail of Bits, OtterSec, HexRays, and SECFORCE, are significant because they support the CTF challenge, making it possible for the event to occur and providing resources for the participants.

Outlines

00:00

πŸ›  Security Vulnerabilities and Developer Assumptions

The video script begins by discussing the common root of security vulnerabilities: developers' incorrect assumptions. It distinguishes between simple developer mistakes and complex framework behaviors that are difficult to predict. The speaker introduces a CTF challenge inspired by a $25,000 GitHub account takeover, which involves web application routing and handling different HTTP methods within the same function. The script highlights the importance of CSRF protection, which is automatically applied to state-changing requests, and the peculiarities of handling GET requests differently due to the absence of a body. The speaker invites viewers to participate in an upcoming CTF event organized by 'justCatTheFish' and thanks the sponsors for their support.

05:02

πŸ€” The Confusion Between Tokenization and Parsing in HTML

The second paragraph delves into the nuances of HTML processing, specifically the difference between tokenization and parsing. It clarifies that while both processes yield the same result for simple HTML, they diverge when HTML namespaces are involved, such as with SVG or MathML. The script uses the example of the 'textarea' tag, which behaves differently across namespaces, to illustrate how a seemingly harmless string of text can become an XSS vulnerability when wrapped in an SVG tag. The video aims to educate viewers on the importance of understanding these differences to prevent security flaws and encourages participation in the CTF to challenge and improve their skills. It also provides a link to a related video for further exploration of CTF tasks.

Mindmap

Keywords

πŸ’‘Security vulnerability

A security vulnerability is a flaw or weakness in a system that can be exploited to compromise the system's integrity, confidentiality, or availability. In the video, it is mentioned that security vulnerabilities often stem from developers making incorrect assumptions. Understanding these vulnerabilities is crucial for preventing attacks such as the one discussed in the CTF challenge.

πŸ’‘CSRF protection

CSRF (Cross-Site Request Forgery) protection is a security measure used to prevent unauthorized commands from being transmitted from a user that the web application trusts. In the video, it is explained that middleware is used to enforce CSRF protection for requests that change the server's state, such as POST, PUT, and DELETE requests, but not for GET requests.

πŸ’‘CTF challenge

CTF (Capture The Flag) challenge is a type of competition in which participants solve security-related tasks to capture 'flags.' In the video, the speaker discusses a CTF challenge inspired by a $25,000 account takeover on GitHub, highlighting the importance of such challenges in developing hacking skills.

πŸ’‘Routing

Routing is the process of determining how an application responds to a client request to a particular endpoint. The video explains how routes are defined in web applications, specifying the path, methods, and functions that handle the requests, and the implications of different HTTP methods on security.

πŸ’‘HTTP methods

HTTP methods are standardized request types used in web applications, such as GET, POST, PUT, DELETE, and HEAD. The video discusses how the HEAD method, which is often treated like GET by frameworks, can bypass CSRF protection due to differences in handling within the application logic.

πŸ’‘Middleware

Middleware is software that connects different components or applications, often used to manage communications and data exchange. In the video, middleware is used to automatically enforce CSRF protection, illustrating its role in enhancing application security.

πŸ’‘XSS (Cross-Site Scripting)

XSS is a type of security vulnerability where an attacker injects malicious scripts into content from otherwise trusted websites. The video describes an XSS exploit used in a CTF task, where the attacker manipulates HTML namespaces to bypass sanitization and execute scripts in the browser.

πŸ’‘HTML namespaces

HTML namespaces are used to distinguish between different types of content, such as HTML, MathML, and SVG. The video highlights how the same tag can behave differently in different namespaces, a crucial point in understanding how XSS attacks can exploit these differences.

πŸ’‘Tokenizer vs. Parser

A tokenizer breaks down text into smaller parts called tokens, while a parser analyzes the tokens to understand their structure. The video explains how a tokenizer ignoring namespaces can lead to security vulnerabilities, such as allowing XSS attacks by not recognizing the context of tags.

πŸ’‘Account takeover

Account takeover is a form of identity theft where an attacker gains unauthorized access to a user's account. In the video, an account takeover vulnerability in GitHub is used as an example to illustrate the potential impact of security flaws and the importance of protecting web applications.

Highlights

Every security vulnerability comes from a developer making a wrong assumption.

Frameworks sometimes do things so strange that it's hard to blame anyone for not understanding what happened.

The video shows two examples of security vulnerabilities and a CTF challenge inspired by a $25,000 account takeover on GitHub.

When creating a new route in a web application, you specify the path, methods, and the function that serves the request.

Different methods can be handled within the same function using an if statement.

CSRF protection requires a CSRF token for all POST, PUT, DELETE, and other requests that change something on the server.

CSRF protection is not required for GET requests that only serve a response.

Using the HEAD method can bypass CSRF protection and reach a block without a proper CSRF token.

A lot of frameworks treat the HEAD method the same as GET during routing, but they are separate at the controller level.

Exploiting this behavior can allow account takeover in GitHub by changing the description through an XSS vulnerability.

Sanitization code can fail when it does not properly handle HTML namespaces.

The same tag can behave differently in HTML and SVG namespaces.

A tokenizer does not apply namespace rules, making it possible to bypass sanitization.

Wrapping HTML in an SVG tag can make a payload look innocent to the sanitizer but execute in the browser.

Participating in CTF challenges is a great way to develop hacking skills.

Transcripts

play00:00

In a sense, every single security vulnerability

play00:02

comes from a developer making some wrong assumption.

play00:06

Just the difference is one time,

play00:09

it's just a mistake by the developer

play00:11

to make this assumption.

play00:12

And another time, frameworks do something so strange

play00:16

that it's hard to even blame anyone

play00:19

for not understanding what happened.

play00:21

In this video, I will show you two examples like this

play00:24

based on which I created a CTF challenge,

play00:28

which was actually inspired by a reward $25,000

play00:32

account takeover on GitHub.

play00:34

Enjoy.

play00:36

When you create a new route in a web application,

play00:39

you usually, regardless of the framework

play00:41

or the programming language, do something like this.

play00:44

You specify the path, you specify the methods,

play00:47

and you specify the function

play00:49

that wants to serve this particular request.

play00:52

Sometimes you may want to create different functions

play00:55

to handle different methods,

play00:57

but you can also handle different methods

play00:59

within the same function,

play01:01

just you have an if statement inside

play01:03

to serve something else for the get

play01:05

to just serve a static response

play01:07

and to actually process some parameters

play01:10

and make some changes if the request is post,

play01:12

put, delete, or whatever.

play01:14

Also, the implicit difference that you cannot see here

play01:18

is the CSRF protection.

play01:21

Both GitHub and my CTF task used middleware

play01:24

to protect against CSRFs,

play01:27

and the way it works is it automatically requires

play01:30

the CSRF token for all post, put, delete,

play01:34

and other requests that are supposed to change

play01:36

something on the server,

play01:38

and the CSRF protection is not required

play01:41

for requests like get

play01:42

that are only supposed to serve the response.

play01:45

Because of this, even with SameSite=None cookies,

play01:49

you couldn't reach this block without a proper CSRF token.

play01:54

If you could, in GitHub,

play01:56

it would allow you to take over the account,

play01:58

and in my CTF task, you would have to also exploit

play02:02

the XSS, to which I'll get later in this video.

play02:06

Just the question is how to do it,

play02:09

and I'll get to answer it in a second,

play02:11

but before I do, I'd like to invite you

play02:13

to take part in this year's CTF organized by my team,

play02:17

justCatTheFish.

play02:18

The task I'm showing you is my task from last year.

play02:21

Of course, for this year, I have a new one,

play02:23

and I promise you, it is a fun one,

play02:26

so you should definitely try.

play02:28

And apart from this, my teammates have also prepared

play02:30

amazing, amazing tasks,

play02:32

so you should definitely challenge yourself,

play02:34

because it's an amazing way to develop your hacking skills.

play02:38

The online teaser starts on 15th June and lasts 24 hours.

play02:43

The link is in the description.

play02:45

I'd also like to thank our sponsors,

play02:47

Trail of Bits, OtterSec, HexRays, and SECFORCE

play02:51

for making it possible.

play02:52

We have links to sponsors in the description,

play02:54

and remember, by checking them out,

play02:56

you support both me and my team.

play02:59

With this said, let's go back to our task.

play03:02

The trick is to use the head method,

play03:05

and you may ask, what head method?

play03:07

We can see in the controller,

play03:08

it's only supposed to route get and post,

play03:11

so how on earth do you get a head method here?

play03:14

But the thing is, a lot of frameworks on the routing stage

play03:18

treat head the same way as they treat get,

play03:21

because the logic is head will be the same thing as get,

play03:24

just the body of the response will be stripped

play03:27

before sending it to the client.

play03:29

So the head method will also be routed to the same function,

play03:33

but at this stage, with this if statement,

play03:37

it is no longer true.

play03:38

At this stage, head and get are separate methods,

play03:41

so if you have an if statement

play03:44

that checks if the method is get,

play03:46

it will also be false for the head method,

play03:50

which means the head method will not be,

play03:53

will not require the CSRF protection,

play03:56

yet you can get to this block down there.

play03:59

And yes, we do not have the request body,

play04:02

but the way parameters are processed,

play04:04

it is equivalent to have the request body with a post

play04:08

and to have URL parameters of a head.

play04:11

And this way, you could take over account in GitHub,

play04:15

and in my task, you could change the description

play04:19

where you had to exploit an XSS.

play04:21

And let's now take a look at it,

play04:22

because there is some robust, almost robust sanitization.

play04:28

And this is the code that was used

play04:30

to sanitize the description, and it is quite aggressive.

play04:33

It only allows a few basic tags with no attributes.

play04:37

And to my knowledge, you cannot execute JavaScript code

play04:40

if you cannot use either a script tag or some attributes.

play04:45

But this is not where the mistake was made.

play04:48

The mistake was made a few lines above this,

play04:51

here, when the code was not parsed, but tokenized.

play04:56

And if you are confused as to what on earth

play04:59

is the difference between tokenizing and parsing,

play05:01

I don't blame you.

play05:02

I also don't blame developers

play05:04

that do not know this difference,

play05:06

because most Stack Overflow answers are confused as well.

play05:11

Well, the difference between tokenizer and a parser

play05:15

with a simple HTML will be none.

play05:17

If you have a simple code like this,

play05:19

the outcome would be the same.

play05:22

But it becomes confusing when you introduce HTML namespaces,

play05:26

because every HTML tag has a namespace.

play05:30

Most of them, in most websites that we use,

play05:33

are just in the HTML namespace.

play05:35

But within the HTML, you can also embed objects

play05:39

from a math or SVG namespace.

play05:41

And the thing is, the same tag can behave differently

play05:45

in HTML namespace and in SVG namespace.

play05:48

For example, the text area tag in the HTML namespace

play05:52

can only contain text inside.

play05:54

So this code will not work.

play05:56

You can put any XSS payload from the world,

play06:00

and it will not execute until you close the textarea tag.

play06:04

Because of this, according to the rules I've shown you

play06:07

before, this payload is fine,

play06:09

because even though it looks like so,

play06:12

it does not contain the script tag.

play06:14

It only contains a text that looks like the script tag.

play06:18

But this stops being true when we wrap this in the SVG tag,

play06:22

which changes the namespace.

play06:24

And this is when we finally get to the difference

play06:27

between the tokenizer and the parser.

play06:29

The parser will apply these namespace rules to this,

play06:34

and we'll see the script tag being inside.

play06:37

The tokenizer will ignore the namespace,

play06:40

so it will still not see the XSS payload here.

play06:43

The browser, of course, parses our HTML,

play06:47

so this code will look innocent to the sanitizer,

play06:51

but it will execute in the browser,

play06:53

thus giving you the XSS.

play06:56

Once you had this, you could easily exfiltrate the flag,

play06:59

so this would be the final payload that you had to use.

play07:02

Last year, nine teams found a solution to my task,

play07:06

and we believe this year you can be one of them.

play07:09

Challenge yourself by participating in the CTF.

play07:12

The link is in the description.

play07:14

In the meantime, if you want to check another video

play07:17

with a CTF task, check out my write-up

play07:20

to LiveOverflow's SQL injection task.

play07:23

The link is on the screen right now.

play07:25

For now, thank you for watching, and goodbye.

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Web SecurityCTF ChallengeGitHub HackCSRF ProtectionXSS ExploitsDeveloper MistakesFramework FlawsSanitization IssuesNamespace ParsingSecurity Education