Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22390624
index.mjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
index.mjs
View Options
import
express
from
"express"
;
import
{
readFile
}
from
"node:fs/promises"
;
import
{
execSync
}
from
"node:child_process"
;
import
{
Server
}
from
"socket.io"
;
import
{
io
}
from
"socket.io-client"
;
import
{
build_html
}
from
"har-analyzer"
import
fileUpload
from
"express-fileupload"
;
const
app
=
express
();
import
multer
from
"multer"
const
upload
=
multer
();
async
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
console
.
log
(
"Waiting for full boot..."
);
// bidirectional forwarding
// Wait untill the connection
const
back
=
io
(
"ws://android:3000"
,
{
reconnectionAttempts
:
1000000
,
reconnectionDelay
:
100
,
});
while
(
!
back
.
connected
)
{
await
sleep
(
100
);
}
console
.
log
(
"Boot detected! activating endpoints"
);
app
.
use
(
express
.
urlencoded
({
extended
:
false
}));
app
.
use
(
express
.
static
(
"/code/dist"
));
//GET
app
.
get
(
"/favicon.ico"
,
function
(
_req
,
res
)
{
res
.
sendFile
(
"/code/favicon.ico"
);
});
app
.
get
(
"/htmx.js"
,
function
(
_req
,
res
)
{
res
.
sendFile
(
"/code/node_modules/htmx.org/dist/htmx.min.js"
);
});
app
.
get
(
"/socket.io.js"
,
function
(
_req
,
res
)
{
res
.
sendFile
(
"/code/node_modules/socket.io/client-dist/socket.io.js"
);
});
app
.
get
(
"/"
,
async
function
(
req
,
res
)
{
let
fileData
=
(
await
readFile
(
"/code/index.html"
)).
toString
();
fileData
=
fileData
.
replace
(
"___screenshotDelayMs___"
,
process
.
env
.
screenshotDelayMs
);
res
.
setHeader
(
"Content-Type"
,
"text/html"
);
res
.
setHeader
(
"Content-Disposition"
,
"inline"
);
res
.
send
(
fileData
);
});
//POST
app
.
use
(
express
.
text
({
limit
:
"500mb"
}));
app
.
post
(
"/inspect_har"
,
upload
.
none
(),
async
function
(
req
,
res
)
{
let
body
=
req
.
body
;
let
har_req
=
await
fetch
(
"http://mitmproxy:9111/get_har"
)
let
har
=
await
har_req
.
text
();
let
private_data
;
if
(
body
.
private_data
)
private_data
=
JSON
.
parse
(
body
.
private_data
);
res
.
setHeader
(
"Content-Type"
,
"text/html"
);
console
.
log
(
private_data
);
res
.
send
(
build_html
(
har
,
private_data
));
});
app
.
get
(
"/download_har"
,
upload
.
none
(),
async
function
(
req
,
res
,
next
)
{
try
{
let
har_req
=
await
fetch
(
"http://mitmproxy:9111/get_har"
)
let
har
=
await
har_req
.
text
();
res
.
status
(
200
).
send
(
har
);
}
catch
(
e
)
{
next
(
e
)
}
});
app
.
get
(
"/get_intercept_stats"
,
upload
.
none
(),
async
function
(
_req
,
res
,
next
)
{
try
{
let
req
=
await
fetch
(
"http://mitmproxy:9111/get_stats"
)
let
stats
=
await
req
.
text
();
res
.
status
(
200
).
send
(
stats
);
}
catch
(
e
)
{
next
(
e
);
}
});
app
.
use
(
fileUpload
());
app
.
post
(
"/upload_apk"
,
async
function
(
req
,
res
)
{
try
{
if
(
!
req
.
files
||
Object
.
keys
(
req
.
files
).
length
===
0
)
{
return
res
.
status
(
400
).
send
(
"No files were uploaded."
);
}
execSync
(
"rm -rf /shared_buffer/*"
);
if
(
Array
.
isArray
(
req
.
files
.
app
))
{
for
(
const
[
idx
,
file
]
of
req
.
files
.
app
.
entries
())
{
let
uploadPath
=
"/shared_buffer/app"
+
idx
+
".apk"
;
await
file
.
mv
(
uploadPath
);
}
}
else
{
let
uploadPath
=
"/shared_buffer/app"
+
0
+
".apk"
;
await
req
.
files
.
app
.
mv
(
uploadPath
);
}
back
.
emit
(
"install"
);
res
.
send
(
"Files uploaded!"
);
}
catch
(
e
){}
});
let
server
=
app
.
listen
(
8080
,
()
=>
console
.
log
(
"Listening in port 8080"
));
const
front
=
new
Server
(
server
);
// forwarding the messages
front
.
on
(
"connection"
,
(
socket
)
=>
{
socket
.
onAny
((
event
,
...
args
)
=>
{
if
(
back
.
connected
)
{
back
.
emit
(
event
,
...
args
);
}
else
{
console
.
log
(
"Front tried to send: "
,
event
,
...
args
);
}
});
});
back
.
onAny
((
event
,
...
args
)
=>
{
front
.
emit
(
event
,
...
args
);
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 15:31 (1 d, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1227219
Default Alt Text
index.mjs (3 KB)
Attached To
Mode
R134 rentgen-android
Attached
Detach File
Event Timeline