-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependency_controller.go
More file actions
66 lines (55 loc) · 1.55 KB
/
dependency_controller.go
File metadata and controls
66 lines (55 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"strings"
)
// InjectDependencyCheck appends a Python pre-flight check to the generated script
func InjectDependencyCheck(scriptPath string) {
if !strings.HasSuffix(scriptPath, ".py") {
return
}
content, err := os.ReadFile(scriptPath)
if err != nil {
fmt.Printf("[-] Failed to read generated script for dependency check: %v\n", err)
return
}
preflight := `
import sys
import importlib.util
def __preflight_check():
required_deps = {
'pwntools': 'pwn',
'requests': 'requests',
'impacket': 'impacket'
}
missing = []
for friendly_name, module_name in required_deps.items():
if importlib.util.find_spec(module_name) is None:
missing.append(friendly_name)
if missing:
print(f"[-] Pre-flight check failed! Missing dependencies: {', '.join(missing)}")
print("[*] Please install them before running the exploit.")
sys.exit(1)
__preflight_check()
`
scriptStr := string(content)
var newContent string
// Check if there's a shebang line
if strings.HasPrefix(scriptStr, "#!") {
nl := strings.Index(scriptStr, "\n")
if nl != -1 {
newContent = scriptStr[:nl+1] + preflight + scriptStr[nl+1:]
} else {
newContent = preflight + scriptStr
}
} else {
newContent = preflight + scriptStr
}
err = os.WriteFile(scriptPath, []byte(newContent), 0755)
if err != nil {
fmt.Printf("[-] Failed to inject dependency check: %v\n", err)
} else {
fmt.Printf("[+] Pre-flight dependency check injected into %s\n", scriptPath)
}
}