Skip to content

Commit d28759b

Browse files
committed
[+] Fix bug in RaaS language parsing
1 parent dd185c4 commit d28759b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/context/server.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/WangYihang/Platypus/lib/util/hash"
14+
"github.com/WangYihang/Platypus/lib/util/fs"
1415
"github.com/WangYihang/Platypus/lib/util/log"
1516
humanize "github.com/dustin/go-humanize"
1617
"github.com/jedib0t/go-pretty/table"
@@ -153,17 +154,18 @@ func (s *TCPServer) Run() {
153154
}
154155

155156
// step 2: parse language
156-
language := "bash"
157-
if len(target) > 0 {
158-
// language is the last element of target
159-
language = strings.Replace(target[len(target)-1], ".", "", -1)
157+
// language is the last element of target
158+
language := strings.Replace(target[len(target)-1], ".", "", -1)
159+
templateFilename := fmt.Sprintf("lib/template/rsh/%s.tpl", language)
160+
if language == "" || !fs.FileExists(templateFilename) {
161+
language = "bash"
160162
}
161163

162164
// step 3: read template
163165
// template rendering in golang tastes like shit,
164166
// here we will trying to use string replace temporarily.
165167
// read reverse shell template file from lib/template/rsh/*
166-
templateFilename := fmt.Sprintf("lib/template/rsh/%s.tpl", language)
168+
templateFilename = fmt.Sprintf("lib/template/rsh/%s.tpl", language)
167169
templateContent, _ := ioutil.ReadFile(templateFilename)
168170

169171
// step 4: render target host and port into template

lib/util/fs/file.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package fs
22
import (
3+
"os"
34
"io/ioutil"
45
)
56

6-
func listFiles(path string) func(string) []string {
7+
func ListFiles(path string) func(string) []string {
78
return func(line string) []string {
89
names := make([]string, 0)
910
files, _ := ioutil.ReadDir(path)
@@ -12,4 +13,14 @@ func listFiles(path string) func(string) []string {
1213
}
1314
return names
1415
}
15-
}
16+
}
17+
18+
// fileExists checks if a file exists and is not a directory before we
19+
// try using it to prevent further errors.
20+
func FileExists(filename string) bool {
21+
info, err := os.Stat(filename)
22+
if os.IsNotExist(err) {
23+
return false
24+
}
25+
return !info.IsDir()
26+
}

0 commit comments

Comments
 (0)