-
Notifications
You must be signed in to change notification settings - Fork 0
/
fingerd.go
56 lines (54 loc) · 1.05 KB
/
fingerd.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
52
53
54
55
56
package trygo
// Usage:
// client:
// $ sudo nc 127.0.0.1:73
// {input username}
// {return $HOME/.plan}
import (
"bufio"
"errors"
"flag"
"fmt"
"io/ioutil"
"net"
"os/user"
)
// Fingerd func
func Fingerd() {
flag.Parse()
ln, err := net.Listen("tcp", ":79")
if err != nil {
panic(err)
}
for {
conn, err := ln.Accept()
if err != nil {
continue
}
go handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
defer conn.Close()
reader := bufio.NewReader(conn)
usr, _, _ := reader.ReadLine()
if info, err := getUserInfo(string(usr)); err != nil {
conn.Write([]byte(err.Error()))
} else {
conn.Write(info)
}
}
func getUserInfo(usr string) ([]byte, error) {
u, e := user.Lookup(usr)
if e != nil {
fmt.Printf("[ERROR] user %s unknown!\n", usr)
return nil, e
}
data, err := ioutil.ReadFile(u.HomeDir + "/.plan")
if err != nil {
fmt.Printf("[OK] user %s does not have a .plan file!\n", usr)
return data, errors.New("User doesn't have a .plan file!\n")
}
fmt.Printf("[OK] user %s have a .plan file!\n", usr)
return data, nil
}