fscan/Plugins/memcached.go

40 lines
1.1 KiB
Go
Raw Normal View History

2020-12-29 17:17:10 +08:00
package Plugins
import (
"fmt"
"strings"
"time"
2023-06-09 08:13:56 -04:00
"github.com/shadow1ng/fscan/common"
2020-12-29 17:17:10 +08:00
)
2023-06-09 08:13:56 -04:00
func MemcachedScan(info common.HostInfo, flags common.Flags) (err error) {
2021-04-21 00:13:04 +08:00
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
2023-06-09 08:13:56 -04:00
client, err := common.WrapperTcpWithTimeout("tcp", realhost, common.Socks5{Address: flags.Socks5Proxy}, time.Duration(flags.Timeout)*time.Second)
2021-09-10 20:32:51 +08:00
defer func() {
2022-07-03 23:41:39 +08:00
if client != nil {
2021-09-10 20:32:51 +08:00
client.Close()
}
}()
2020-12-29 17:17:10 +08:00
if err == nil {
2023-06-09 08:13:56 -04:00
err = client.SetDeadline(time.Now().Add(time.Duration(flags.Timeout) * time.Second))
2020-12-29 17:17:10 +08:00
if err == nil {
2021-03-30 18:12:54 +08:00
_, err = client.Write([]byte("stats\n")) //Set the key randomly to prevent the key on the server from being overwritten
if err == nil {
rev := make([]byte, 1024)
n, err := client.Read(rev)
if err == nil {
if strings.Contains(string(rev[:n]), "STAT") {
result := fmt.Sprintf("[+] Memcached %s unauthorized", realhost)
common.LogSuccess(result)
}
} else {
2021-04-21 00:13:04 +08:00
errlog := fmt.Sprintf("[-] Memcached %v:%v %v", info.Host, info.Ports, err)
2021-03-30 18:12:54 +08:00
common.LogError(errlog)
}
2020-12-29 17:17:10 +08:00
}
}
}
2021-03-30 18:12:54 +08:00
return err
2020-12-29 17:17:10 +08:00
}