text
stringlengths
0
1.99k
What happens is that, inet_aton() will succeed in converting the IP address
as long as the initial part of the string is a valid IP address format.
After parsing "192.168.1.1", inet_aton() will encounter " `C`". These
characters are not valid for an IP address and are simply ignored by
inet_aton(). Consequently, structs in_addr will contain the binary
representation of the IP address "192.168.1.1".
$ U ;A` --dport 5`BB` -j DNAT --to 192.168.1.1 `C`:6`DDD
...
sh: --dport: command not found
sh: -j: command not found
sh: :6: command not found
sh: ABBCDDD: command not found
$ U ;A` -d 192.168.1.1 `C` --dport `DDDD -j ACCEPT
...
sh: -d: command not found
sh: --dport: command not found
sh: ACDDDD: command not found
All security checks have been bypassed, leaving 7 (or 6) characters to
carry out the command injection in case the IP is 192.168.1.1 and 9 (or 8)
if IP have 10.10.0.1 as format. As it can be understood, the format of the
IP of the target will have a consequence on the number of characters
controllable for the injection. Depending on the vendor, different default
IPs can be defined for their network equipment, but the format of the two
IPs mentioned above are generally the most common.
---------------------------------------------------------------------------
--[ 8. Claiming supremacy over the mats
As it may be evident, the intriguing aspect arises when attempting to
answer the question: How can arbitrary commands be executed when only 7
characters are known to be controllable?
The answer is, to take advantage of globbing. Globbing is the process of
pattern matching for filenames and behaves similarly across shells like sh,
bash, ash, and dash, as they all follow POSIX standards. Common globbing
patterns such as *, ?, and [...] are supported in all these shells,
allowing users to match groups of files using wildcards. However, bash
stands out by offering advanced features like extended globbing and
recursive globbing with **, which are not available in ash, dash, or sh,
which are more minimalistic and focus on speed and efficiency.
The order in which files are matched during globbing in shells generally
follows lexicographical order, but it may vary depending on the system's
locale. Typically, in UTF-8 or ASCII environments, files starting with
digits come first, followed by uppercase letters and then lowercase
letters. For files whose filenames contain special characters, different
behavior have been observed where they may be listed either first or last.
While the basic globbing behavior is consistent across all shells,
differences may arise if the locale changes, affecting how special
characters, numbers, and letters are ordered. Here is a simple example.
Consider the previous virtual machine, if files are created using the
command below.
$ touch .A .B .a .b .1
The following command is used with as shell bash (or zsh).
$ echo .?
.1 .a .A .b .B
However, with ash (BusyBox version), the following result is obtained.
$ echo .?
.. .1 .A .B .a .b
After a little investigation the discrepancies may come from the locale
differences between interpreters. ash use the C locale (also known as the
POSIX locale) which is the default system locale that is typically used in
Unix-like operating systems when no specific locale is set. And the related
sorting does not take into account accents, case sensitivity, or linguistic
rules. Characters are sorted in the following order (ASCII values of
characters).
- Digits (0-9) first.
- Uppercase letters (A-Z) next.
- Lowercase letters (a-z) last.
- Special characters (like !, #, etc.) have a predefined order, which is
based on their ASCII values.
It is time to put little dishes into the big ones and mix all the
ingredients together to make a good soup. To do this, the first thing we
need to do is define the only limitation that our technique confronts us
with.
As a stager is about to be created, the current directory of the
process being exploited (upnpd) must be writable. The CWD environment
variable typically refers to the current working directory of the shell or
process. It holds the path of the directory in which the process is running
or where it was launched from (however, it is important to note that CWD is
not a standard environment variable in all systems—it's more commonly used
in certain applications or scripts to track the current directory).
Alternatively, the /proc/self/cwd symbolic link in Linux can be used to
track the current working directory of a running process by pointing to the
directory in which the process is currently operating. Since /proc/self
refers to the current process, accessing /proc/self/cwd provides the
absolute path to that process’s working directory. It is to be noted that