mirror of
https://github.com/kgretzky/evilginx2
synced 2026-06-08 15:15:53 +00:00
49 lines
910 B
Go
49 lines
910 B
Go
package core
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func GenRandomToken() string {
|
|
rdata := make([]byte, 64)
|
|
rand.Read(rdata)
|
|
hash := sha256.Sum256(rdata)
|
|
token := fmt.Sprintf("%x", hash)
|
|
return token
|
|
}
|
|
|
|
func GenRandomString(n int) string {
|
|
const lb = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
b := make([]byte, n)
|
|
for i := range b {
|
|
t := make([]byte, 1)
|
|
rand.Read(t)
|
|
b[i] = lb[int(t[0])%len(lb)]
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func GenRandomAlphanumString(n int) string {
|
|
const lb = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
b := make([]byte, n)
|
|
for i := range b {
|
|
t := make([]byte, 1)
|
|
rand.Read(t)
|
|
b[i] = lb[int(t[0])%len(lb)]
|
|
}
|
|
return string(b)
|
|
}
|
|
|
|
func CreateDir(path string, perm os.FileMode) error {
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
err = os.Mkdir(path, perm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|