blob: 527cc2244a0f9393a2461db6fe31cace6e52feb5 (
plain)
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
|
package server
import (
"os"
"regexp"
"github.com/spiral/errors"
)
// pattern for the path finding
const pattern string = `^\/*([A-z0-9/.:-]+\.(php|sh|ph))$`
func (server *Plugin) scanCommand(cmd []string) error {
const op = errors.Op("server_command_scan")
r, err := regexp.Compile(pattern)
if err != nil {
return err
}
for i := 0; i < len(cmd); i++ {
if r.MatchString(cmd[i]) {
// try to stat
_, err := os.Stat(cmd[i])
if err != nil {
return errors.E(op, err)
}
// stat successful
return nil
}
}
return errors.E(errors.Str("scan failed, possible path not found"), op)
}
|