With the follwing code I split a string, create a list, and given a specific pattern, substitute a random char with another one
comando = "/bin/cat /etc/passwd"
payloadMUT1 = comando
payloadMUT3 = re.split(r'/', payloadMUT1)
filteredarray = []
for i in payloadMUT3:
#I don't want special chars to get involved in the substitution process
filteredarray.extend(re.findall(r'\b[^\W\d_]+\b', i))
for a in filteredarray:
randomIndex = int(random.random() * len(a))
randomChar = a[randomIndex]
payloadMUT4 = a.replace(randomChar, '?')
Output:
?in
ca?
et?
pa??wd
How do I assemble all those values to build the whole ( updated ) string back?
This is the output I'm looking for:
/?in/ca? /et?/pa??wd
PS: /bin/cat /etc/passwd is just an example; it could be everything else, also a string with multiple slashes and spaces
Some more examples with complex strings:
/bin/find . -type f -iname "*.stuff" -exec egrep -H -i '[a-z]\.[a-z]\.[a-z]' {} \; -> /b?n/fi?d . -type f -iname "*.stuff" -exec egrep -H -i '[a-z]\.[a-z]\.[a-z]' {} \;
/usr/bin/ls | /bin/grep "something" -> /?sr/b?n/l? | /bi?/gre? "something"
/bin/curl http://111.111.111.111:1111/ -X POST -d "a=a&b=b" -> /?in/cur? http://111.111.111.111:1111/ -X POST -d "a=a&b=b"
You could first split the string by spaces, before splitting on the slash. This way, you can then recombine the paths, before joining them with spaces. However, it does require a few more lines, because of the 2 dimensional array to store each path.
comando = "/bin/cat /etc/passwd"
payloadMUT1 = comando
paths = payloadMUT1.split(' ')
strings = list(map(lambda p: re.split(r'/', p), paths))
print(strings)
filtered_paths = []
new_paths = []
for string_arr in strings:
#i don't want special chars to get involved in the substitution process
arr = []
for string in string_arr:
if string == '':
arr.append(string)
continue
arr.extend(re.findall(r'\b[^\W\d_]+\b', string))
filtered_paths.append(arr)
for path_arr in filtered_paths:
arr = []
for a in path_arr:
if a == '':
arr.append(a)
continue
randomIndex = int(random.random() * len(a))
randomChar = a[randomIndex]
payloadMUT4 = a.replace(randomChar, '?')
arr.append(payloadMUT4)
new_paths.append(arr)
new_paths = list(map(lambda e: '/'.join(e), new_paths))
print(' '.join(new_paths))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With