How to Reverse Engineer Web Applications

Jarrod Overson
Jarrod OversonDirector at Shape Security
Reverse Engineer Web Applications
How to
First things first
Prerequisites
• node.js ( web tools are made with node first )
• npm ( comes with node )
Nice-to-haves
• Visual Studio code ( or suitable code editor )
• git ( because it's be?er than cvs )
First things first
Lab repository
h5ps://github.com/jsoverson/workshop-reverse-engineering
-or-
Zipfile: h5p://bit.ly/reveng-webapps
Reverse Engineer Web Applications
How to
Challenge #1
1. Web applica,ons have grown extremely complex.
https://github.com/jsoverson/workshop-reverse-engineering
Web 101
https://github.com/jsoverson/workshop-reverse-engineering
Web 101
GET / HTTP/1.1
Host: www.google.com
Connection: keep-alive
User-Agent: Chrome/72.0.3626.96 Safari/537.36 (…)
HTTP/1.1 200 OK
Date: Tue, 19 Feb 2019 21:34:08 GMT
Content-Type: text/html
Content-Length: 1932
<!doctype HTML>(…)
https://github.com/jsoverson/workshop-reverse-engineering
Web 101
https://github.com/jsoverson/workshop-reverse-engineering
Challenge #2
1. Web applica,ons have grown extremely complex.
2. Limited ability to run old versions of resources or use old APIs.
https://github.com/jsoverson/workshop-reverse-engineering
99% of websites assume connecHvity
https://github.com/jsoverson/workshop-reverse-engineering
Challenge #3
1. Web applica,ons have grown extremely complex.
2. Limited ability to run old versions of resources or use old APIs.
3. Web site resources can change frequently.
https://github.com/jsoverson/workshop-reverse-engineering
https://github.com/jsoverson/workshop-reverse-engineering
https://github.com/jsoverson/workshop-reverse-engineering
Challenge #4
1. Web applica,ons have grown extremely complex.
2. Limited ability to run old versions of resources or use old APIs.
3. Web sites and APIs can change frequently.
4. Web browsers change frequently.
https://github.com/jsoverson/workshop-reverse-engineering
A year of
Chrome
A year of
FireFox
https://github.com/jsoverson/workshop-reverse-engineering
Challenge #5
1. Web applica,ons have grown extremely complex.
2. Limited ability to run old versions of resources or use old APIs.
3. Web sites and APIs can change frequently.
4. Web browsers change frequently.
5. Actual aDackers are leading to more effec,ve countermeasures.
https://github.com/jsoverson/workshop-reverse-engineering
Website a?acks are a serious problem
>3 billion a5acks in 1 week for 1 customer on 1 page
https://github.com/jsoverson/workshop-reverse-engineering
And have an industry around protecHng them
https://github.com/jsoverson/workshop-reverse-engineering
And have an industry around protecHng them
That's Me!
https://github.com/jsoverson/workshop-reverse-engineering
So how do you hack web apps?
1. Drive the browser programmaHcally
2. Simulate and intercept "system" calls
3. Reuse as much applicaHon code as possible
Lab work
Lab 0 Lab 1 Lab 2
1. ExtracHng logic
2. ExtracHng logic
resiliently
3. Transforming with
scope awareness
1. AutomaHng a browser
2. IntercepHng requests
3. Modifying responses
4. RewriHng JS on the fly
with a mocked
environment
1. Understanding Intent

in JavaScript
Lab Format
lab-#.#/
├── answer
│   └── answer-#.#.js
├── test
│   └── test.js
├── work
│   └── lab-#.#.js
└── package.json
Node/npm basics
node [script.js]
npm install
npm install [specific package]
h?ps://gitpod.io/
h?ps://try-puppeteer.appspot.com/
Lab 0.1
Understanding Intent in JavaScript
Payload A is the first script of three found in an exploited dependency of npm
package event-stream.
Background
De-obfuscate payload-A.js and idenHfy how it is loading the second payload.
Goal
Lab 0.1
Understanding Intent in JavaScript
• Format your code with ⌘+⇧+P or ^+⇧+P to open command pale?e then
"Format Document"
• Rename variables by pressing F2 when cursor is over an idenHfier.
• There is a helper file that includes addiHonal encoded strings.

(The first and second strings in the helper file are beyond the scope of this lab.)
• process.env contains the environment variables at Hme of execuHon
Tips
Lab Series 1
ProgrammaHcally manipulaHng JavaScript
Lab 1.1
ProgrammaHcally extract logic from JavaScript
Common JavaScript best pracHces and bundlers produce code that has a
minimal public footprint, limiHng the ability to hook into exisHng logic.
Background
Use the Shif parser and code generator to read payload-A.js and extract its
e funcOon and export it as an unhex method in our node script.
Goal
Lab 1.1
Using parsers
parse(originalSource) ! Abstract Syntax Tree (AST)
codegen(AST) ! newSource
Lab 1.1
VariableDeclarationStatement
What is an AST?
Lab 1.1
VariableDeclaration
What is an AST?
Lab 1.1
VariableDeclarator
What is an AST?
Lab 1.1
What is an AST?
BindingIdentifier
LiteralStringExpression
Lab 1.1
What is an AST?
Lab 1.1
What is an AST?
"Hello WOPRs"
Lab 1.1
ProgrammaHcally extract logic from JavaScript
Common JavaScript best pracHces and bundlers produce code that has a
minimal public footprint, limiHng the ability to hook into exisHng logic.
Background
Use the Shif parser and code generator to read payload-A.js and extract its
e funcOon and export it as an unhex method in our node script.
Goal
Lab 1.1
ProgrammaHcally extract logic from JavaScript
• Don't overthink it - you're just deeply accessing a property in an object.
• console.log() as you make your way down the tree, e.g.
console.log(tree.expressions[0]);
• Copy/paste payload-A.js into astexplorer.net for an interacHve UI
Tips
Lab 1.2
Resiliently extract logic from JavaScript
ExtracHng and manipulaHng JavaScript requires that the code be resilient to
changes in the input source.
Background
Use a traversal method to pick out the same funcHon from lab 1.1 by
inspecHng the AST node of the funcHon and idenHfying it by its shape or
a?ributes.
Goal
Lab 1.2
Resiliently extract logic from JavaScript
• allNodes contains a list of all nodes in the AST.
• You can iterate over that list and check every node for properHes that
represent the node you want to target.
• You probably want to check if node.type === 'FunctionDeclaration'
• You can then check the funcHon name to make sure it is equal to 'e'
Tips
Lab 1.3
Rewrite JavaScript taking scope and context into account
RewriHng JavaScript requires tools that are aware of the enHre program's scope
and context.
Background
Use shift-scope to rename global variables "a" and "b" to "first" and
"second"
Goal
Analyzing Scope
Analyzing Scope
const scope = analyzeScope(AST)
Analyzing Scope
Scope
! children
! type
! astNode
! variableList
Child scopes
Global / Script / FuncHon etc
The root node
The variables declared or
referenced in this scope
Analyzing Scope
const lookupTable = new ScopeLookup(scope)
const identifier = /* node from AST */
const lookup = lookupTable.variableMap.get(identifier)
Lab 1.3
Rewrite JavaScript taking scope and context into account
RewriHng JavaScript requires tools that are aware of the enHre program's scope
and context.
Background
Use shift-scope to rename global variables "a" and "b" to "first" and
"second"
Goal
Lab 1.3
Rewrite JavaScript taking scope and context into account
• The argument to lookupTable.variableMap.get() should be the
idenHfier node itself, not a string.
• There are variables already defined that reference the AST nodes.
• Each lookup returns a list of entries with declaraHons and references. You
need to change both declaraHons and references to fully rename an idenHfier.
Tips
Lab Series 2
ProgrammaHcally controlling a browser
Lab Series 2
Notes:
The Puppeteer npm package downloads Chrome on
every install. If internet is flakey, download it once and
copy node_modules/puppeteer from one lab to
another
Lab 2.1
ProgrammaHcally control a browser with Puppeteer
Web applicaHon analysis needs to be completely automated, otherwise
everything depending on a manual step risks breaking when anything changes.
Background
Set up a base environment that controls Chrome with Puppeteer and nodejs.
Goal
What is Puppeteer?
Puppeteer is a nodejs library that provides a high-level API
to control Chrome over the DevTools Protocol.
Puppeteer runs headless by default, but can be configured
to run full (non-headless) Chrome or Chromium.
Puppeteer API
puppeteer.launch();
puppeteer.connect();
browser
Browser instance
browser.pages();
browser.newPage();
page
( Tab )
Page instance
page.goto();
page.evaluate();
element
page.$();
page.$$();
Element instance
element.click();
element.type(…);
element.tap();
Lab 2.1
ProgrammaHcally control a browser with Puppeteer
• The Puppeteer API is fantasHc : h?p://bit.ly/puppeteer-api
• You need to get a browser instance from puppeteer
• You need to get a page instance from browser
• You need to go to a url of your choice, e.g. h?ps://example.com
Tips
Lab 2.2
Intercept requests via the Chrome Devtools Protocol
IntercepHng, inspecHng, and modifying inbound and outbound communicaHon
is a criHcal part of any reverse engineering effort.
Background
Use the Chrome Devtools Protocol directly to intercept all Script resources,
log the URL to the terminal, and then conHnue the request.
Goal
What is Chrome Devtools Protocol?
The Chrome DevTools Protocol allows for tools to
instrument, inspect, debug and profile Chromium, Chrome
and other Blink-based browsers.
@jsoverson
http://bit.ly/chrome-devtools-protocol
IniHaHng a CDP Session
const client = page.target().createCDPSession();
Sending commands
client.send(“command”);
client.send(“command”, {options…});
client.on(“event”, listener);
IntercepHng Network Traffic
(pseudo code)
send(“Network.enable”);
send(“Network.setRequestInterception”, patterns);
on(“Network.requestIntercepted”, (evt) => {
/* modify request or response */
send(
“Network.continueInterceptedRequest”,
request
)
})
Lab 2.2
Intercept requests via the Chrome Devtools Protocol
IntercepHng, inspecHng, and modifying inbound and outbound communicaHon
is a criHcal part of any reverse engineering effort.
Background
Use the Chrome Devtools Protocol directly to intercept all Script resources,
log the URL to the terminal, and then conHnue the request.
Goal
Lab 2.2
Intercept requests via the Chrome Devtools Protocol
• The Puppeteer API is fantasHc : h?p://bit.ly/puppeteer-api
• This is purely in the Network domain
• Remind me to flip back to the pseudo-code if you're stuck.
Tips
Lab 2.3
Modify intercepted requests
Modifying intercepted requests requires recreaHng an enHre HTTP response
and passing it along as the original.
Background
Retrieve the original script body and append a `console.log()` statement to
the end of the script that simply logs a message.
Goal
IntercepHng Network Traffic
(pseudo code)
send(“Network.enable”);
send(“Network.setRequestInterception”, patterns);
on(“Network.requestIntercepted”, (evt) => {
send(
“Network.continueInterceptedRequest”,
request
)
})
const response =
send(“Network.getResponseBodyForInterception”, interceptionId);
Modifying a Response
(pseudo code)
const response =
send('Network.getResponseBodyForInterception', interceptionId);
const body = response.base64Encoded
? atob(response.body)
: response.body;
send('Network.continueInterceptedRequest', {
interceptionId,
rawResponse: btoa( /* Complete HTTP Response */)
});
HTTP Requests & Responses
Lab 2.3
Modify intercepted requests
Modifying intercepted requests requires recreaHng an enHre HTTP response
and passing it along as the original.
Background
Retrieve the original script body and append a `console.log()` statement to
the end of the script that simply logs a message.
Goal
Lab 2.3
Modify intercepted requests
• Rely on the Chrome Devtools Protocol documentaHon : h?ps://bit.ly/chrome-
devtools-protocol
• What you add to each script is up to you, it's user choice as long as it is
observable.
• The last TODO requires reading the CDP documentaHon.
Tips
Final Lab
Meaningfully rewrite a script to intercept its access to browser APIs
IntercepHng a script's access to standard APIs allows you to guide its execuHon
in the direcHon you want without modifying its internals.
Background
Wrap the example site's script to intercept access to document.locaHon to
make the script think it is hosted elsewhere & inject code that exposes the
seed
Goal
1 of 72

Recommended

SSRF For Bug Bounties by
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug BountiesOWASP Nagpur
412 views36 slides
Frans Rosén Keynote at BSides Ahmedabad by
Frans Rosén Keynote at BSides AhmedabadFrans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides AhmedabadSecurity BSides Ahmedabad
1.6K views92 slides
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour by
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourSoroush Dalili
52.9K views60 slides
Ruby on Rails Presentation by
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentationadamcookeuk
10K views60 slides
Building Advanced XSS Vectors by
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS VectorsRodolfo Assis (Brute)
7.8K views61 slides
How to steal and modify data using Business Logic flaws - Insecure Direct Obj... by
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...Frans Rosén
7.2K views40 slides

More Related Content

What's hot

Regular Expression Injection by
Regular Expression InjectionRegular Expression Injection
Regular Expression InjectionNSConclave
718 views17 slides
Waf bypassing Techniques by
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing TechniquesAvinash Thapa
26.4K views47 slides
Secure Code Warrior - CRLF injection by
Secure Code Warrior - CRLF injectionSecure Code Warrior - CRLF injection
Secure Code Warrior - CRLF injectionSecure Code Warrior
173 views6 slides
Api security-testing by
Api security-testingApi security-testing
Api security-testingn|u - The Open Security Community
779 views24 slides
Bug Bounty Basics by
Bug Bounty BasicsBug Bounty Basics
Bug Bounty BasicsHackerOne
4.2K views20 slides
Thick client pentesting_the-hackers_meetup_version1.0pptx by
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxAnurag Srivastava
1.7K views32 slides

What's hot(20)

Regular Expression Injection by NSConclave
Regular Expression InjectionRegular Expression Injection
Regular Expression Injection
NSConclave718 views
Waf bypassing Techniques by Avinash Thapa
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing Techniques
Avinash Thapa26.4K views
Bug Bounty Basics by HackerOne
Bug Bounty BasicsBug Bounty Basics
Bug Bounty Basics
HackerOne4.2K views
Thick client pentesting_the-hackers_meetup_version1.0pptx by Anurag Srivastava
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
Anurag Srivastava1.7K views
Attacking thru HTTP Host header by Sergey Belov
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
Sergey Belov1.8K views
HTTP Request Smuggling via higher HTTP versions by neexemil
HTTP Request Smuggling via higher HTTP versionsHTTP Request Smuggling via higher HTTP versions
HTTP Request Smuggling via higher HTTP versions
neexemil9.5K views
How to Prevent RFI and LFI Attacks by Imperva
How to Prevent RFI and LFI AttacksHow to Prevent RFI and LFI Attacks
How to Prevent RFI and LFI Attacks
Imperva9.9K views
Node JS reverse shell by Madhu Akula
Node JS reverse shellNode JS reverse shell
Node JS reverse shell
Madhu Akula4.9K views
Privilege escalation from 1 to 0 Workshop by Hossam .M Hamed
Privilege escalation from 1 to 0 Workshop Privilege escalation from 1 to 0 Workshop
Privilege escalation from 1 to 0 Workshop
Hossam .M Hamed1K views
Rest API with Swagger and NodeJS by Luigi Saetta
Rest API with Swagger and NodeJSRest API with Swagger and NodeJS
Rest API with Swagger and NodeJS
Luigi Saetta870 views
Advanced SQL Injection by amiable_indian
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
amiable_indian31.4K views
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016 by Frans Rosén
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Frans Rosén9.2K views
Container Security by Jie Liau
Container SecurityContainer Security
Container Security
Jie Liau577 views
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T... by Edureka!
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Edureka!1.7K views
Bypass file upload restrictions by Mukesh k.r
Bypass file upload restrictionsBypass file upload restrictions
Bypass file upload restrictions
Mukesh k.r31.8K views

Similar to How to Reverse Engineer Web Applications

Write code that writes code! by
Write code that writes code!Write code that writes code!
Write code that writes code!Jason Feinstein
110 views96 slides
Write code that writes code! A beginner's guide to Annotation Processing - Ja... by
Write code that writes code! A beginner's guide to Annotation Processing - Ja...Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...DroidConTLV
531 views96 slides
Practical Chaos Engineering by
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos EngineeringSIGHUP
517 views32 slides
Build Great Networked APIs with Swift, OpenAPI, and gRPC by
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCTim Burks
1.4K views47 slides
Code transformation With Spoon by
Code transformation With SpoonCode transformation With Spoon
Code transformation With SpoonGérard Paligot
1.7K views92 slides
React native by
React nativeReact native
React nativeMohammed El Rafie Tarabay
3.9K views118 slides

Similar to How to Reverse Engineer Web Applications(20)

Write code that writes code! A beginner's guide to Annotation Processing - Ja... by DroidConTLV
Write code that writes code! A beginner's guide to Annotation Processing - Ja...Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
DroidConTLV531 views
Practical Chaos Engineering by SIGHUP
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos Engineering
SIGHUP517 views
Build Great Networked APIs with Swift, OpenAPI, and gRPC by Tim Burks
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks1.4K views
Code transformation With Spoon by Gérard Paligot
Code transformation With SpoonCode transformation With Spoon
Code transformation With Spoon
Gérard Paligot1.7K views
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod... by Codemotion
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
Codemotion1.5K views
Why scala is not my ideal language and what I can do with this by Ruslan Shevchenko
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
Ruslan Shevchenko939 views
Lunch and learn as3_frameworks by Yuri Visser
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
Yuri Visser653 views
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage by mlilley
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
mlilley20.5K views
Cannibalising The Google App Engine by catherinewall
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall3.9K views
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript by John Stevenson
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
John Stevenson1.1K views
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong by PROIDEA
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
PROIDEA98 views
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift by Diego Freniche Brito
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P... by Pantheon
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Pantheon1.1K views
The future of server side JavaScript by Oleg Podsechin
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin1.8K views
Java(ee) mongo db applications in the cloud by Shekhar Gulati
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
Shekhar Gulati3.7K views
Building Server Applications Using ObjectiveC And GNUstep by guest9efd1a1
Building Server Applications Using ObjectiveC And GNUstepBuilding Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
guest9efd1a14.3K views
Building Server Applications Using Objective C And Gn Ustep by wangii
Building Server Applications Using Objective C And Gn UstepBuilding Server Applications Using Objective C And Gn Ustep
Building Server Applications Using Objective C And Gn Ustep
wangii537 views
20100730 phpstudy by Yusuke Ando
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
Yusuke Ando1.1K views

More from Jarrod Overson

Practical WebAssembly with Apex, wasmRS, and nanobus by
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusJarrod Overson
55 views53 slides
AppSecCali - How Credential Stuffing is Evolving by
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingJarrod Overson
595 views44 slides
How Credential Stuffing is Evolving - PasswordsCon 2019 by
How Credential Stuffing is Evolving - PasswordsCon 2019How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019Jarrod Overson
278 views54 slides
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su... by
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...Jarrod Overson
1.4K views73 slides
Analysis of an OSS supply chain attack - How did 8 millions developers downlo... by
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Jarrod Overson
416 views97 slides
Deepfakes - How they work and what it means for the future by
Deepfakes - How they work and what it means for the futureDeepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the futureJarrod Overson
4K views64 slides

More from Jarrod Overson(20)

Practical WebAssembly with Apex, wasmRS, and nanobus by Jarrod Overson
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
Jarrod Overson55 views
AppSecCali - How Credential Stuffing is Evolving by Jarrod Overson
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is Evolving
Jarrod Overson595 views
How Credential Stuffing is Evolving - PasswordsCon 2019 by Jarrod Overson
How Credential Stuffing is Evolving - PasswordsCon 2019How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019
Jarrod Overson278 views
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su... by Jarrod Overson
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
Jarrod Overson1.4K views
Analysis of an OSS supply chain attack - How did 8 millions developers downlo... by Jarrod Overson
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Jarrod Overson416 views
Deepfakes - How they work and what it means for the future by Jarrod Overson
Deepfakes - How they work and what it means for the futureDeepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the future
Jarrod Overson4K views
The State of Credential Stuffing and the Future of Account Takeovers. by Jarrod Overson
The State of Credential Stuffing and the Future of Account Takeovers.The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.
Jarrod Overson1.2K views
The life of breached data and the attack lifecycle by Jarrod Overson
The life of breached data and the attack lifecycleThe life of breached data and the attack lifecycle
The life of breached data and the attack lifecycle
Jarrod Overson399 views
The Life of Breached Data & The Dark Side of Security by Jarrod Overson
The Life of Breached Data & The Dark Side of SecurityThe Life of Breached Data & The Dark Side of Security
The Life of Breached Data & The Dark Side of Security
Jarrod Overson935 views
Shape Security @ WaffleJS October 16 by Jarrod Overson
Shape Security @ WaffleJS October 16Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16
Jarrod Overson732 views
Graphics Programming for Web Developers by Jarrod Overson
Graphics Programming for Web DevelopersGraphics Programming for Web Developers
Graphics Programming for Web Developers
Jarrod Overson995 views
The Dark Side of Security by Jarrod Overson
The Dark Side of SecurityThe Dark Side of Security
The Dark Side of Security
Jarrod Overson1.4K views
Maintainability SFJS Sept 4 2014 by Jarrod Overson
Maintainability SFJS Sept 4 2014 Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014
Jarrod Overson1.6K views
Riot on the web - Kenote @ QCon Sao Paulo 2014 by Jarrod Overson
Riot on the web - Kenote @ QCon Sao Paulo 2014Riot on the web - Kenote @ QCon Sao Paulo 2014
Riot on the web - Kenote @ QCon Sao Paulo 2014
Jarrod Overson1.4K views
Managing JavaScript Complexity in Teams - Fluent by Jarrod Overson
Managing JavaScript Complexity in Teams - FluentManaging JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - Fluent
Jarrod Overson1.8K views
Real World Web components by Jarrod Overson
Real World Web componentsReal World Web components
Real World Web components
Jarrod Overson8.4K views
Managing JavaScript Complexity by Jarrod Overson
Managing JavaScript ComplexityManaging JavaScript Complexity
Managing JavaScript Complexity
Jarrod Overson14.9K views

Recently uploaded

40th TWNIC Open Policy Meeting: APNIC PDP update by
40th TWNIC Open Policy Meeting: APNIC PDP update40th TWNIC Open Policy Meeting: APNIC PDP update
40th TWNIC Open Policy Meeting: APNIC PDP updateAPNIC
151 views20 slides
The Boys – Season 4 by
The Boys – Season 4The Boys – Season 4
The Boys – Season 4phamthebach2210
7 views2 slides
ARNAB12.pdf by
ARNAB12.pdfARNAB12.pdf
ARNAB12.pdfArnabChakraborty499766
5 views83 slides
ATPMOUSE_융합2조.pptx by
ATPMOUSE_융합2조.pptxATPMOUSE_융합2조.pptx
ATPMOUSE_융합2조.pptxkts120898
35 views70 slides
Penetration Testing for Cybersecurity Professionals by
Penetration Testing for Cybersecurity ProfessionalsPenetration Testing for Cybersecurity Professionals
Penetration Testing for Cybersecurity Professionals211 Check
52 views17 slides
Liberando a produccion con confidencia.pdf by
Liberando a produccion con confidencia.pdfLiberando a produccion con confidencia.pdf
Liberando a produccion con confidencia.pdfAndres Almiray
8 views49 slides

Recently uploaded(15)

40th TWNIC Open Policy Meeting: APNIC PDP update by APNIC
40th TWNIC Open Policy Meeting: APNIC PDP update40th TWNIC Open Policy Meeting: APNIC PDP update
40th TWNIC Open Policy Meeting: APNIC PDP update
APNIC151 views
ATPMOUSE_융합2조.pptx by kts120898
ATPMOUSE_융합2조.pptxATPMOUSE_융합2조.pptx
ATPMOUSE_융합2조.pptx
kts12089835 views
Penetration Testing for Cybersecurity Professionals by 211 Check
Penetration Testing for Cybersecurity ProfessionalsPenetration Testing for Cybersecurity Professionals
Penetration Testing for Cybersecurity Professionals
211 Check52 views
Liberando a produccion con confidencia.pdf by Andres Almiray
Liberando a produccion con confidencia.pdfLiberando a produccion con confidencia.pdf
Liberando a produccion con confidencia.pdf
Andres Almiray8 views
40th TWNIC OPM: On LEOs (Low Earth Orbits) and Starlink Download by APNIC
40th TWNIC OPM: On LEOs (Low Earth Orbits) and Starlink Download40th TWNIC OPM: On LEOs (Low Earth Orbits) and Starlink Download
40th TWNIC OPM: On LEOs (Low Earth Orbits) and Starlink Download
APNIC159 views
cis5-Project-11a-Harry Lai by harrylai126
cis5-Project-11a-Harry Laicis5-Project-11a-Harry Lai
cis5-Project-11a-Harry Lai
harrylai1269 views
40th TWNIC Open Policy Meeting: A quick look at QUIC by APNIC
40th TWNIC Open Policy Meeting: A quick look at QUIC40th TWNIC Open Policy Meeting: A quick look at QUIC
40th TWNIC Open Policy Meeting: A quick look at QUIC
APNIC152 views
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptx by LeasedLinesQuote
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptxCracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptx
Cracking the Code Decoding Leased Line Quotes for Connectivity Excellence.pptx
WITS Deck by W.I.T.S.
WITS DeckWITS Deck
WITS Deck
W.I.T.S.37 views
The Dark Web : Hidden Services by Anshu Singh
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden Services
Anshu Singh23 views

How to Reverse Engineer Web Applications

  • 1. Reverse Engineer Web Applications How to
  • 2. First things first Prerequisites • node.js ( web tools are made with node first ) • npm ( comes with node ) Nice-to-haves • Visual Studio code ( or suitable code editor ) • git ( because it's be?er than cvs )
  • 3. First things first Lab repository h5ps://github.com/jsoverson/workshop-reverse-engineering -or- Zipfile: h5p://bit.ly/reveng-webapps
  • 4. Reverse Engineer Web Applications How to
  • 5. Challenge #1 1. Web applica,ons have grown extremely complex. https://github.com/jsoverson/workshop-reverse-engineering
  • 7. Web 101 GET / HTTP/1.1 Host: www.google.com Connection: keep-alive User-Agent: Chrome/72.0.3626.96 Safari/537.36 (…) HTTP/1.1 200 OK Date: Tue, 19 Feb 2019 21:34:08 GMT Content-Type: text/html Content-Length: 1932 <!doctype HTML>(…) https://github.com/jsoverson/workshop-reverse-engineering
  • 9. Challenge #2 1. Web applica,ons have grown extremely complex. 2. Limited ability to run old versions of resources or use old APIs. https://github.com/jsoverson/workshop-reverse-engineering
  • 10. 99% of websites assume connecHvity https://github.com/jsoverson/workshop-reverse-engineering
  • 11. Challenge #3 1. Web applica,ons have grown extremely complex. 2. Limited ability to run old versions of resources or use old APIs. 3. Web site resources can change frequently. https://github.com/jsoverson/workshop-reverse-engineering
  • 14. Challenge #4 1. Web applica,ons have grown extremely complex. 2. Limited ability to run old versions of resources or use old APIs. 3. Web sites and APIs can change frequently. 4. Web browsers change frequently. https://github.com/jsoverson/workshop-reverse-engineering
  • 15. A year of Chrome A year of FireFox https://github.com/jsoverson/workshop-reverse-engineering
  • 16. Challenge #5 1. Web applica,ons have grown extremely complex. 2. Limited ability to run old versions of resources or use old APIs. 3. Web sites and APIs can change frequently. 4. Web browsers change frequently. 5. Actual aDackers are leading to more effec,ve countermeasures. https://github.com/jsoverson/workshop-reverse-engineering
  • 17. Website a?acks are a serious problem >3 billion a5acks in 1 week for 1 customer on 1 page https://github.com/jsoverson/workshop-reverse-engineering
  • 18. And have an industry around protecHng them https://github.com/jsoverson/workshop-reverse-engineering
  • 19. And have an industry around protecHng them That's Me! https://github.com/jsoverson/workshop-reverse-engineering
  • 20. So how do you hack web apps?
  • 21. 1. Drive the browser programmaHcally 2. Simulate and intercept "system" calls 3. Reuse as much applicaHon code as possible
  • 22. Lab work Lab 0 Lab 1 Lab 2 1. ExtracHng logic 2. ExtracHng logic resiliently 3. Transforming with scope awareness 1. AutomaHng a browser 2. IntercepHng requests 3. Modifying responses 4. RewriHng JS on the fly with a mocked environment 1. Understanding Intent
 in JavaScript
  • 23. Lab Format lab-#.#/ ├── answer │   └── answer-#.#.js ├── test │   └── test.js ├── work │   └── lab-#.#.js └── package.json
  • 24. Node/npm basics node [script.js] npm install npm install [specific package]
  • 27. Lab 0.1 Understanding Intent in JavaScript Payload A is the first script of three found in an exploited dependency of npm package event-stream. Background De-obfuscate payload-A.js and idenHfy how it is loading the second payload. Goal
  • 28. Lab 0.1 Understanding Intent in JavaScript • Format your code with ⌘+⇧+P or ^+⇧+P to open command pale?e then "Format Document" • Rename variables by pressing F2 when cursor is over an idenHfier. • There is a helper file that includes addiHonal encoded strings.
 (The first and second strings in the helper file are beyond the scope of this lab.) • process.env contains the environment variables at Hme of execuHon Tips
  • 29. Lab Series 1 ProgrammaHcally manipulaHng JavaScript
  • 30. Lab 1.1 ProgrammaHcally extract logic from JavaScript Common JavaScript best pracHces and bundlers produce code that has a minimal public footprint, limiHng the ability to hook into exisHng logic. Background Use the Shif parser and code generator to read payload-A.js and extract its e funcOon and export it as an unhex method in our node script. Goal
  • 31. Lab 1.1 Using parsers parse(originalSource) ! Abstract Syntax Tree (AST) codegen(AST) ! newSource
  • 35. Lab 1.1 What is an AST? BindingIdentifier LiteralStringExpression
  • 36. Lab 1.1 What is an AST?
  • 37. Lab 1.1 What is an AST? "Hello WOPRs"
  • 38. Lab 1.1 ProgrammaHcally extract logic from JavaScript Common JavaScript best pracHces and bundlers produce code that has a minimal public footprint, limiHng the ability to hook into exisHng logic. Background Use the Shif parser and code generator to read payload-A.js and extract its e funcOon and export it as an unhex method in our node script. Goal
  • 39. Lab 1.1 ProgrammaHcally extract logic from JavaScript • Don't overthink it - you're just deeply accessing a property in an object. • console.log() as you make your way down the tree, e.g. console.log(tree.expressions[0]); • Copy/paste payload-A.js into astexplorer.net for an interacHve UI Tips
  • 40. Lab 1.2 Resiliently extract logic from JavaScript ExtracHng and manipulaHng JavaScript requires that the code be resilient to changes in the input source. Background Use a traversal method to pick out the same funcHon from lab 1.1 by inspecHng the AST node of the funcHon and idenHfying it by its shape or a?ributes. Goal
  • 41. Lab 1.2 Resiliently extract logic from JavaScript • allNodes contains a list of all nodes in the AST. • You can iterate over that list and check every node for properHes that represent the node you want to target. • You probably want to check if node.type === 'FunctionDeclaration' • You can then check the funcHon name to make sure it is equal to 'e' Tips
  • 42. Lab 1.3 Rewrite JavaScript taking scope and context into account RewriHng JavaScript requires tools that are aware of the enHre program's scope and context. Background Use shift-scope to rename global variables "a" and "b" to "first" and "second" Goal
  • 44. Analyzing Scope const scope = analyzeScope(AST)
  • 45. Analyzing Scope Scope ! children ! type ! astNode ! variableList Child scopes Global / Script / FuncHon etc The root node The variables declared or referenced in this scope
  • 46. Analyzing Scope const lookupTable = new ScopeLookup(scope) const identifier = /* node from AST */ const lookup = lookupTable.variableMap.get(identifier)
  • 47. Lab 1.3 Rewrite JavaScript taking scope and context into account RewriHng JavaScript requires tools that are aware of the enHre program's scope and context. Background Use shift-scope to rename global variables "a" and "b" to "first" and "second" Goal
  • 48. Lab 1.3 Rewrite JavaScript taking scope and context into account • The argument to lookupTable.variableMap.get() should be the idenHfier node itself, not a string. • There are variables already defined that reference the AST nodes. • Each lookup returns a list of entries with declaraHons and references. You need to change both declaraHons and references to fully rename an idenHfier. Tips
  • 49. Lab Series 2 ProgrammaHcally controlling a browser
  • 50. Lab Series 2 Notes: The Puppeteer npm package downloads Chrome on every install. If internet is flakey, download it once and copy node_modules/puppeteer from one lab to another
  • 51. Lab 2.1 ProgrammaHcally control a browser with Puppeteer Web applicaHon analysis needs to be completely automated, otherwise everything depending on a manual step risks breaking when anything changes. Background Set up a base environment that controls Chrome with Puppeteer and nodejs. Goal
  • 52. What is Puppeteer? Puppeteer is a nodejs library that provides a high-level API to control Chrome over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.
  • 57. Lab 2.1 ProgrammaHcally control a browser with Puppeteer • The Puppeteer API is fantasHc : h?p://bit.ly/puppeteer-api • You need to get a browser instance from puppeteer • You need to get a page instance from browser • You need to go to a url of your choice, e.g. h?ps://example.com Tips
  • 58. Lab 2.2 Intercept requests via the Chrome Devtools Protocol IntercepHng, inspecHng, and modifying inbound and outbound communicaHon is a criHcal part of any reverse engineering effort. Background Use the Chrome Devtools Protocol directly to intercept all Script resources, log the URL to the terminal, and then conHnue the request. Goal
  • 59. What is Chrome Devtools Protocol? The Chrome DevTools Protocol allows for tools to instrument, inspect, debug and profile Chromium, Chrome and other Blink-based browsers.
  • 61. IniHaHng a CDP Session const client = page.target().createCDPSession();
  • 63. IntercepHng Network Traffic (pseudo code) send(“Network.enable”); send(“Network.setRequestInterception”, patterns); on(“Network.requestIntercepted”, (evt) => { /* modify request or response */ send( “Network.continueInterceptedRequest”, request ) })
  • 64. Lab 2.2 Intercept requests via the Chrome Devtools Protocol IntercepHng, inspecHng, and modifying inbound and outbound communicaHon is a criHcal part of any reverse engineering effort. Background Use the Chrome Devtools Protocol directly to intercept all Script resources, log the URL to the terminal, and then conHnue the request. Goal
  • 65. Lab 2.2 Intercept requests via the Chrome Devtools Protocol • The Puppeteer API is fantasHc : h?p://bit.ly/puppeteer-api • This is purely in the Network domain • Remind me to flip back to the pseudo-code if you're stuck. Tips
  • 66. Lab 2.3 Modify intercepted requests Modifying intercepted requests requires recreaHng an enHre HTTP response and passing it along as the original. Background Retrieve the original script body and append a `console.log()` statement to the end of the script that simply logs a message. Goal
  • 67. IntercepHng Network Traffic (pseudo code) send(“Network.enable”); send(“Network.setRequestInterception”, patterns); on(“Network.requestIntercepted”, (evt) => { send( “Network.continueInterceptedRequest”, request ) }) const response = send(“Network.getResponseBodyForInterception”, interceptionId);
  • 68. Modifying a Response (pseudo code) const response = send('Network.getResponseBodyForInterception', interceptionId); const body = response.base64Encoded ? atob(response.body) : response.body; send('Network.continueInterceptedRequest', { interceptionId, rawResponse: btoa( /* Complete HTTP Response */) });
  • 69. HTTP Requests & Responses
  • 70. Lab 2.3 Modify intercepted requests Modifying intercepted requests requires recreaHng an enHre HTTP response and passing it along as the original. Background Retrieve the original script body and append a `console.log()` statement to the end of the script that simply logs a message. Goal
  • 71. Lab 2.3 Modify intercepted requests • Rely on the Chrome Devtools Protocol documentaHon : h?ps://bit.ly/chrome- devtools-protocol • What you add to each script is up to you, it's user choice as long as it is observable. • The last TODO requires reading the CDP documentaHon. Tips
  • 72. Final Lab Meaningfully rewrite a script to intercept its access to browser APIs IntercepHng a script's access to standard APIs allows you to guide its execuHon in the direcHon you want without modifying its internals. Background Wrap the example site's script to intercept access to document.locaHon to make the script think it is hosted elsewhere & inject code that exposes the seed Goal