fscan/Plugins/memcached.go

40 lines
1.0 KiB
Go
Raw Normal View History

2020-12-29 01:17:10 -08:00
package Plugins
import (
"fmt"
"github.com/shadow1ng/fscan/common"
"net"
"strings"
"time"
)
2021-03-30 03:12:54 -07:00
func MemcachedScan(info *common.HostInfo) (err error) {
2021-04-20 09:13:04 -07:00
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
2020-12-29 01:17:10 -08:00
client, err := net.DialTimeout("tcp", realhost, time.Duration(info.Timeout)*time.Second)
2021-09-10 05:32:51 -07:00
defer func() {
if client != nil{
client.Close()
}
}()
2020-12-29 01:17:10 -08:00
if err == nil {
2021-03-30 03:12:54 -07:00
err = client.SetDeadline(time.Now().Add(time.Duration(info.Timeout) * time.Second))
2020-12-29 01:17:10 -08:00
if err == nil {
2021-03-30 03:12:54 -07: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-20 09:13:04 -07:00
errlog := fmt.Sprintf("[-] Memcached %v:%v %v", info.Host, info.Ports, err)
2021-03-30 03:12:54 -07:00
common.LogError(errlog)
}
2020-12-29 01:17:10 -08:00
}
}
}
2021-03-30 03:12:54 -07:00
return err
2020-12-29 01:17:10 -08:00
}