[#thread š§µ] For this second day of #CyberAdvent (2/24), we will be talking about a common #PrivilegeEscalation when using the * (wildcard) in shell scripts. Almost everyone has used at least once the * (wildcard) in a shell script but what really happens with the #wildcard ? š¦
[#thread š§µ(2/7)] We will take as an example this shell script, performing a backup of a website using tar and a wildcard:
[#thread š§µ(3/7)] In this script, the shell replaces the wildcard with matching files from the current directory then executes the command. The * character is never sent to the command (TAR in our case) instead a list of matched files will be sent as arguments to the command.
The thing is, filenames can be interpreted as options by the program if you create filenames beginning with dashes. WTF is going on here ?
[#thread š§µ(4/7)] If we list files using ls * in a folder with normal files in it, everything goes well and we have the expected output:
[#thread š§µ(5/7)] Now if an attacker can create files in this folder and creates files beginning with dashes like in program options, the wildcard will be replaced by these files, and these filenames will be treated as options:
[#thread š§µ(6/7)] After the wildcard expansion in the shell, the command will be transformed from ls * to:
ls -lha file1 file2 file3
And the filenames beginning with dashes will be considered as options and will be interpreted by ls:
[#thread š§µ(7/7)] As an attacker we can leverage this behavior to exploit the program to escalate our privileges using legitimate program options to execute commands. Many of these techniques to exploit well known programs on linux can be found here:
[#thread š§µ] For this third day of #CyberAdvent (3/24), I'll tell you a story. The story of how I gained root access to a server by leveraging a really fun feature in a web application. This #pentest#writeup will explain the complete process from recon to root. š¦
[#thread š§µ(2/9)] In the recon phase of my pentest, as usual I was performing a port scan. In the output from nmap, I saw an uncommon port 86 with an HTTP server running "Micro Focus DSD 1.0.0":
[#thread š§µ(3/9)] When going on the page from a browser, surprise š„³š we have an unauthenticated access! This is cool, but I never saw this app before so I didn't know whether we could exploit it simply or not!
[thread] Did you know that ssh tries to authenticate with stored keys BEFORE the key specified with -i in the command line ? I just noticed this, the hard way š.
Let's imagine you have more than 5 keys loaded in your ssh agent. When authenticating to a remote server, you get:
After this message, ssh tries to authenticate with the keys in the order listed above. Why is that a problem ?
Because most servers have a default configuration with MaxAuthTries set to 6. After 6 tries, you will get a "Too many authentication failures" error.
So, ssh tries to authenticate with the keys in the order listed above, but gets disconnected after 6 tries. This means that if your agent has more than 6 stored keys, the key specified with -i is never used. This means you can't login to a remote server and you might not know why