-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_linux.go
More file actions
60 lines (51 loc) · 1.65 KB
/
func_linux.go
File metadata and controls
60 lines (51 loc) · 1.65 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
//go:build linux
// +build linux
package main
import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"github.com/creack/pty" // used for sending user keyboard commands to hashcat/mdxfind
)
// sendX func
func linuxSendCmd(cmd string, stdin io.Writer) {
io.WriteString(stdin, cmd)
}
// initialize OS specific logic
func initializeAndExecute(cmdStr string, timeT int, crackT int, debug bool) {
cmdSlice := strings.Fields(cmdStr)
cmdName := cmdSlice[0]
cmdArgs := cmdSlice[1:]
cmd := exec.Command(cmdName, cmdArgs...)
ptmx, err := pty.Start(cmd) // start command with pty
if err != nil {
fmt.Fprintln(os.Stderr, "Error starting command with PTY:", err)
return
}
defer func() { _ = ptmx.Close() }() // close pty
// Runner-specific sendB / sendQ behavior
switch currentRunner {
case RunnerHashcat:
// hashcat: "b" to bypass, "q" to quit
sendB = func(stdin io.Writer) { linuxSendCmd("b", stdin) }
sendQ = func(stdin io.Writer) { linuxSendCmd("q", stdin) }
case RunnerMDXFind:
// mdxfind: no bypass/quit keys; use Ctrl+C for both
sendB = func(stdin io.Writer) { linuxSendCmd("\x03", stdin) } // Ctrl+C
fmt.Println("Sending quit signal...")
sendQ = func(stdin io.Writer) { linuxSendCmd("\x03", stdin) } // Ctrl+C
fmt.Println("Sending quit signal...")
default:
// fail-safe: use Ctrl+C if Runner unknown
sendB = func(stdin io.Writer) { linuxSendCmd("\x03", stdin) }
fmt.Println("Sending quit signal...")
sendQ = func(stdin io.Writer) { linuxSendCmd("\x03", stdin) }
fmt.Println("Sending quit signal...")
}
// listen for user commands
go ReadUserInput(ptmx)
// initialize common logic
initializeAndExecuteCommon(timeT, crackT, debug, ptmx, ptmx)
}