2020-12-29 17:17:10 +08:00
|
|
|
package Plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-12-18 21:56:08 +08:00
|
|
|
"github.com/shadow1ng/fscan/Config"
|
2020-12-29 17:17:10 +08:00
|
|
|
"github.com/shadow1ng/fscan/common"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-12-18 21:56:08 +08:00
|
|
|
func MemcachedScan(info *Config.HostInfo) (err error) {
|
2021-04-21 00:13:04 +08:00
|
|
|
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
|
2022-07-03 23:41:39 +08:00
|
|
|
client, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.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 {
|
2022-07-03 23:41:39 +08:00
|
|
|
err = client.SetDeadline(time.Now().Add(time.Duration(common.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
|
|
|
}
|