SlideShare una empresa de Scribd logo
1 de 72
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

SAML / OpenID Connect / OAuth / SCIM 技術解説 - ID&IT 2014 #idit2014
SAML / OpenID Connect / OAuth / SCIM 技術解説  - ID&IT 2014 #idit2014SAML / OpenID Connect / OAuth / SCIM 技術解説  - ID&IT 2014 #idit2014
SAML / OpenID Connect / OAuth / SCIM 技術解説 - ID&IT 2014 #idit2014
Nov Matake
 

La actualidad más candente (20)

Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesOWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
 
全文検索でRedmineをさらに活用!
全文検索でRedmineをさらに活用!全文検索でRedmineをさらに活用!
全文検索でRedmineをさらに活用!
 
なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?なかったらINSERTしたいし、あるならロック取りたいやん?
なかったらINSERTしたいし、あるならロック取りたいやん?
 
Zabbixのパフォーマンスチューニング & インストール時の注意点
Zabbixのパフォーマンスチューニング & インストール時の注意点Zabbixのパフォーマンスチューニング & インストール時の注意点
Zabbixのパフォーマンスチューニング & インストール時の注意点
 
SAML / OpenID Connect / OAuth / SCIM 技術解説 - ID&IT 2014 #idit2014
SAML / OpenID Connect / OAuth / SCIM 技術解説  - ID&IT 2014 #idit2014SAML / OpenID Connect / OAuth / SCIM 技術解説  - ID&IT 2014 #idit2014
SAML / OpenID Connect / OAuth / SCIM 技術解説 - ID&IT 2014 #idit2014
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
インフラエンジニアってなんでしたっけ(仮)
インフラエンジニアってなんでしたっけ(仮)インフラエンジニアってなんでしたっけ(仮)
インフラエンジニアってなんでしたっけ(仮)
 
Node JS reverse shell
Node JS reverse shellNode JS reverse shell
Node JS reverse shell
 
JHipster overview
JHipster overviewJHipster overview
JHipster overview
 
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
【NGINXセミナー】API ゲートウェイとしてのNGINX Plus活用方法
 
脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよ脆弱性検査ツールってどうよ
脆弱性検査ツールってどうよ
 
MySQLトラブル解析入門
MySQLトラブル解析入門MySQLトラブル解析入門
MySQLトラブル解析入門
 
どうやって決める?kubernetesでのシークレット管理方法(Cloud Native Days 2020 発表資料)
どうやって決める?kubernetesでのシークレット管理方法(Cloud Native Days 2020 発表資料)どうやって決める?kubernetesでのシークレット管理方法(Cloud Native Days 2020 発表資料)
どうやって決める?kubernetesでのシークレット管理方法(Cloud Native Days 2020 発表資料)
 
The State of DevSecOps
The State of DevSecOpsThe State of DevSecOps
The State of DevSecOps
 
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
도커 무작정 따라하기: 도커가 처음인 사람도 60분이면 웹 서버를 올릴 수 있습니다!
 
20151205フルスクラッチcms作成のノウハウ With Laravel
20151205フルスクラッチcms作成のノウハウ With Laravel20151205フルスクラッチcms作成のノウハウ With Laravel
20151205フルスクラッチcms作成のノウハウ With Laravel
 
入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き入社1年目のプログラミング初心者がSpringを学ぶための手引き
入社1年目のプログラミング初心者がSpringを学ぶための手引き
 
これから始めるSpringのwebアプリケーション
これから始めるSpringのwebアプリケーションこれから始めるSpringのwebアプリケーション
これから始めるSpringのwebアプリケーション
 
Frans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides AhmedabadFrans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides Ahmedabad
 

Similar a How to Reverse Engineer Web Applications

Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
mlilley
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
catherinewall
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin
 
Java(ee) mongo db applications in the cloud
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 Gulati
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstepBuilding Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
guest9efd1a1
 
Building Server Applications Using Objective C And Gn Ustep
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
wangii
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
Yusuke Ando
 

Similar a How to Reverse Engineer Web Applications (20)

Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!
 
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...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
 
Practical Chaos Engineering
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos Engineering
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
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
 
Code transformation With Spoon
Code transformation With SpoonCode transformation With Spoon
Code transformation With Spoon
 
React native
React nativeReact native
React native
 
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...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Why 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 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
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
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
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
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
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
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...
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...
 
The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
Building Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstepBuilding Server Applications Using ObjectiveC And GNUstep
Building Server Applications Using ObjectiveC And GNUstep
 
Building Server Applications Using Objective C And Gn Ustep
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
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 

Más de Jarrod Overson

Más de Jarrod Overson (20)

Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
AppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is Evolving
 
How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019
 
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...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
 
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...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
 
Deepfakes - How they work and what it means for the future
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
 
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.
The State of Credential Stuffing and the Future of Account Takeovers.
 
The life of breached data and the attack lifecycle
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
 
The Life of Breached Data & The Dark Side of Security
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
 
Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16
 
Graphics Programming for Web Developers
Graphics Programming for Web DevelopersGraphics Programming for Web Developers
Graphics Programming for Web Developers
 
The Dark Side of Security
The Dark Side of SecurityThe Dark Side of Security
The Dark Side of Security
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014 Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014
 
Idiot proofing your code
Idiot proofing your codeIdiot proofing your code
Idiot proofing your code
 
Riot on the web - Kenote @ QCon Sao Paulo 2014
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
 
Managing JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - FluentManaging JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - Fluent
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
 
Managing JavaScript Complexity
Managing JavaScript ComplexityManaging JavaScript Complexity
Managing JavaScript Complexity
 

Último

一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理
F
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 

Último (20)

一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
Research Assignment - NIST SP800 [172 A] - Presentation.pptx
Research Assignment - NIST SP800 [172 A] - Presentation.pptxResearch Assignment - NIST SP800 [172 A] - Presentation.pptx
Research Assignment - NIST SP800 [172 A] - Presentation.pptx
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Call girls Service Canacona - 8250092165 Our call girls are sure to provide y...
Call girls Service Canacona - 8250092165 Our call girls are sure to provide y...Call girls Service Canacona - 8250092165 Our call girls are sure to provide y...
Call girls Service Canacona - 8250092165 Our call girls are sure to provide y...
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
PIC Microcontroller Structure & Assembly Language.ppsx
PIC Microcontroller Structure & Assembly Language.ppsxPIC Microcontroller Structure & Assembly Language.ppsx
PIC Microcontroller Structure & Assembly Language.ppsx
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 

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