-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftphoney.go
164 lines (144 loc) · 3.91 KB
/
ftphoney.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"bufio"
"database/sql"
"flag"
"fmt"
"github.com/cheynewallace/tabby"
_"github.com/mattn/go-sqlite3"
"log"
"net"
"strings"
"time"
)
func main() {
// All password are correct
var apc = flag.Bool("a",false,"All tested passwords are correct.")
// log connectons
var lc = flag.Bool("v",false,"Show conections in verbose mode.")
// Host
var h = flag.String("l","0.0.0.0:2121","Local Host ip:port. ")
var help = flag.Bool("h",false,"Help menu.")
var lg = flag.Bool("log",false,"Write logs.")
flag.Parse()
if (*help == true) {
help_m()
} else {
database,_ := sql.Open("sqlite3","./logs.db")
show_options(*apc,*lc,*lg)
setdb(database)
hp(*lc,*h,*apc,database,*lg)
}
}
// Honeypot starter service.
func hp(lc bool,host string,apc bool,database *sql.DB,lg bool) {
var ps string
var banner string = "220 (vsFTPd 3.0.3)"+"\n"
if (apc == true) {
ps = "230 Password ok, continue\n"
} else {
ps = "530 Incorrect password, not logged in\n"
}
init_server(lc,database,host,banner,ps,lg)
}
// Init server and wait for clients.
func init_server(lc bool,database *sql.DB,host string,banner string,ps string,lg bool) {
var id int = 1
serve, err := net.Listen("tcp", host)
if err != nil {
log.Fatal(err.Error())
}
println("- Listenig",host)
defer serve.Close()
for {
client, err := serve.Accept()
if err != nil {
log.Fatal(err.Error())
}
h := client.RemoteAddr()
if (lc == true) {
println(id,"- New Connection -> ",h.String())
}
go handle_conn(database,client, id, banner, ps,lg)
id++
}
}
// Handle connection, sending and receiving data.
func handle_conn(database *sql.DB,conn net.Conn,id int, banner string, ps string,lg bool) {
conn.Write([]byte(banner))
data, err := bufio.NewReader(conn).ReadString('\r')
if err != nil {
fmt.Println("Error reading:", err.Error())
}
//println(data)
ss0 := strings.Split(data, " ")
if (ss0[0] != "USER") {
conn.Write([]byte("500 Command not found\n"))
} else{
//println(id,"- User -> ",ss0[1])
conn.Write([]byte("331 User name ok, password required.\n"))
}
data0, err := bufio.NewReader(conn).ReadString('\r')
if err != nil {
fmt.Println("Error reading:", err.Error())
}
ss1 := strings.Split(data0," ")
if (ss1[0] != "PASS") {
conn.Write([]byte("500 Command not found.\n"))
} else {
conn.Write([]byte(ps))
//println(id,"- Password -> ",ss1[1])
}
conn.Close()
if (lg == true) {
d := ctime()
h := conn.RemoteAddr()
hs := h.String()
usr := ss0[1]
pssk := ss1[1]
loging(database,hs,d,usr,pssk)
}
}
// Set database.
// Create a new database and table if not exist,
// columns: id,datetime, ip, username, password.
func setdb(database *sql.DB) {
println("- Setting up database.")
state,_ := database.Prepare("CREATE TABLE IF NOT EXISTS frst (id INTEGER PRIMARY KEY,datetime TEXT,IP TEXT, username TEXT,password TEXT)")
state.Exec()
}
// Current date and time.
func ctime() string {
date := time.Now()
dat := date.Format(("02/Jan/2006 15:04:05"))
return dat
}
// Save information in database.
func loging(database *sql.DB,host string,dt string,user string,passkey string) {
state,_ := database.Prepare("INSERT INTO frst (datetime,IP,username,password) VALUES (?,?,?,?)")
state.Exec(dt,host,user,passkey)
}
// Show chosen options.
func show_options(apc bool,lc bool,lg bool) {
if (apc == true) {
println("- All tested password are correct:",apc)
}
if (lc == true) {
println("- Show connections in verbose mode:",lc)
}
if (lg == true) {
println("- All logs will be written:",lc)
println("!Too many threads may cause memory corruption in SQLite!")
}
}
// Help menu shown as a table.
func help_m() {
t := tabby.New()
t.AddHeader("COMMAND","DESCRIPTION","REQUIRED")
t.AddLine("-l","Local host and port. -l ip:port","No")
t.AddLine("-a","All tested password are correct.","No")
t.AddLine("-v","Show conections in verbose mode.","No")
t.AddLine("-log","Write logs.","No")
t.AddLine("-h","Help menu.")
t.Print()
}