-
Notifications
You must be signed in to change notification settings - Fork 2
/
hivMisc.go
136 lines (100 loc) · 3.08 KB
/
hivMisc.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
//{{{{{{{ Hive Miscelanious Functions and external sources }}}}}}}
//// Extra functions to help Hive with different tasks
// A. randomString (from: https://www.calhoun.io/creating-random-strings-in-go/)
//By Rebujacker - Alvaro Folgado Rueda as an open source educative project
package main
import (
"time"
"math/rand"
"strconv"
"regexp"
)
// Some Input Sanitation Functions (to Improve...)
func gmailInputWhite(input string) bool{
if (len(input) > 5000){
return false
}
return true
}
func accessKeysInputWhite(input string) bool{
var white = regexp.MustCompile(`^[a-zA-Z0-9\-\.\+_/=]{1,200}$`).MatchString
return white(input)
}
func rsaKeysInputWhite(input string) bool{
//var white = regexp.MustCompile(`^[a-zA-Z0-9\-\.\+_/=\s]$`).MatchString
if (len(input) > 5000){
return false
}
return true
}
func namesInputWhite(input string) bool{
var white = regexp.MustCompile(`^[a-zA-Z0-9]{1,20}$`).MatchString
return white(input)
}
func idsInputWhite(input string) bool{
var white = regexp.MustCompile(`^[a-zA-Z0-9\-]{1,20}$`).MatchString
return white(input)
}
func filesInputWhite(input string) bool{
var white = regexp.MustCompile(`^[\w.-]{1,20}$`).MatchString
return white(input)
}
func numbersInputWhite(input string) bool{
var white = regexp.MustCompile(`^[0-9]{1,200}$`).MatchString
return white(input)
}
func domainsInputWhite(input string) bool{
var white = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$`).MatchString
//For Ipv4 Address
var white2 = regexp.MustCompile(`^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$`).MatchString
var result = (white(input) || white2(input))
return result
}
func tcpPortInputWhite(input string) bool{
var white = regexp.MustCompile(`^()([1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$`).MatchString
return white(input)
}
func randomString(length int) string{
charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}
func randomTCP(usedPorts []string) string{
var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
var notUsedPorts []string
ports := makeRange(0,65535)
j := 0
for i,_ := range ports {
if !(stringInSlice(ports[i],usedPorts)){
ports[j] = ports[i]
j++
}
}
notUsedPorts = ports[:j]
return notUsedPorts[seededRand.Intn(len(notUsedPorts))]
}
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func makeRange(min, max int) []string {
a := make([]int, max-min+1)
valuesText := []string{}
for i := range a {
a[i] = min + i
}
for i := range a {
number := a[i]
text := strconv.Itoa(number)
valuesText = append(valuesText, text)
}
return valuesText
}