-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsolve.go
51 lines (39 loc) · 945 Bytes
/
solve.go
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
package main
import (
"bytes"
"os"
"strings"
"crypto/sha256"
pwn "github.com/7Rocky/gopwntools"
)
func getProcess() *pwn.Conn {
if len(os.Args) == 1 {
return pwn.Process("python3", "server.py")
}
hostPort := strings.Split(os.Args[1], ":")
return pwn.Remote(hostPort[0], hostPort[1])
}
func sendHash(io *pwn.Conn, msg []byte) string {
io.SendLineAfter([]byte("> "), []byte{'1'})
io.SendLineAfter([]byte("Enter your message: "), msg)
io.RecvUntil([]byte("Hash: "))
return strings.TrimSpace(io.RecvLineS())
}
func main() {
io := getProcess()
defer io.Close()
var flag []byte
prog := pwn.Progress("Flag")
for !bytes.ContainsRune(flag, '}') {
prog.Status(string(flag))
h := sendHash(io, bytes.Repeat([]byte{'\x00'}, len(flag)+1))
for c := byte(0x20); c < 0x7f; c++ {
s := sha256.Sum256(append(flag, c))
if pwn.Hex(s[:]) == h {
flag = append(flag, c)
break
}
}
}
prog.Success(string(flag))
}