forked from oraoto/pib
-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathPhpShell.js
75 lines (53 loc) · 1.23 KB
/
PhpShell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { PhpBase } from './PhpBase.js';
const PhpBinary = require('./php-shell');
export class PhpWeb extends PhpBase
{
constructor(args = {})
{
super(PhpBinary, args);
}
}
if(globalThis.document)
{
const php = new PhpWeb;
const runScriptTag = element => {
const src = element.getAttribute('src');
if(src)
{
fetch(src).then(r => r.text()).then(r => {
php.run(r).then(exit=>console.log(exit));
});
return;
}
const inlineCode = element.innerText.trim();
console.log(inlineCode);
if(inlineCode)
{
php.run(inlineCode);
}
};
php.addEventListener('ready', () => {
const phpSelector = 'script[type="text/php"]';
const htmlNode = document.body.parentElement;
const observer = new MutationObserver((mutations, observer)=>{
for(const mutation of mutations)
{
for(const addedNode of mutation.addedNodes)
{
if(!addedNode.matches || !addedNode.matches(phpSelector))
{
continue;
}
runScriptTag(addedNode);
}
}
});
observer.observe(htmlNode, {childList: true, subtree: true});
const phpNodes = document.querySelectorAll(phpSelector);
for(const phpNode of phpNodes)
{
const code = phpNode.innerText.trim();
runScriptTag(phpNode);
}
});
}