- 新增 internal/protect/elf.go:追加 PT_LOAD 段(搬 phdr 表)+ 改 e_entry,PE/ELF 统一走 PatchAuto - 壳 assets/elfstub64.bin:无 libc 纯 syscall 实现(登录 POST / 关回显读口令 / hostname 作设备 ID) - Runner 产物命名:无扩展名不再硬加 .exe - Info 字段扩到 uint64 以容纳 ELF 地址;上传白名单放行 .elf/无扩展名 - cmd/elfpack:命令行 ELF 打包工具 - 单测:结构校验 + 非 x86_64 精确拒绝 - 实测:/bin/ls、PIE、非 PIE 三种目标;正确口令放行、错误口令/断网/403 拦截;设备绑定写入 user_devices
39 lines
1006 B
Go
39 lines
1006 B
Go
// elfpack:命令行给 ELF 打壳(运维/调试用)
|
|
// 用法: elfpack <目标ELF> <输出> <cfg.json>
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"verification-platform-backend/internal/protect"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) != 4 {
|
|
fmt.Fprintln(os.Stderr, "用法: elfpack <目标ELF> <输出> <cfg.json>")
|
|
os.Exit(2)
|
|
}
|
|
src, err := os.ReadFile(os.Args[1])
|
|
must(err)
|
|
cfg, err := os.ReadFile(os.Args[3])
|
|
must(err)
|
|
det := protect.DetectFile(src, filepath.Base(os.Args[1]))
|
|
out, info, err := protect.PatchAuto(src, cfg, filepath.Base(os.Args[1]))
|
|
must(err)
|
|
must(os.WriteFile(os.Args[2], out, 0o755))
|
|
fmt.Printf("kind=%s arch=%s %d → %d 字节\n", det.Kind, det.Arch, len(src), info.OutSize)
|
|
fmt.Printf("入口 %#x → %#x 段 vaddr=%#x size=%d\n", info.EntryOld, info.EntryNew, info.SecRVA, info.SecSize)
|
|
if info.Note != "" {
|
|
fmt.Println("说明:", info.Note)
|
|
}
|
|
}
|
|
|
|
func must(err error) {
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, "error:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|