<?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: c org</title>
    <description>The latest articles on DEV Community by c org (@chriskennedylol).</description>
    <link>https://dev.to/chriskennedylol</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%2F813378%2Fba250f25-cf48-41e4-b0ef-c387fbc34fa1.jpeg</url>
      <title>DEV Community: c org</title>
      <link>https://dev.to/chriskennedylol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chriskennedylol"/>
    <language>en</language>
    <item>
      <title>Still Remember IndexedDB?</title>
      <dc:creator>c org</dc:creator>
      <pubDate>Wed, 13 Jul 2022 16:38:18 +0000</pubDate>
      <link>https://dev.to/chriskennedylol/still-remember-indexeddb-1ja4</link>
      <guid>https://dev.to/chriskennedylol/still-remember-indexeddb-1ja4</guid>
      <description>&lt;p&gt;We remember that there was a browser storage called IndexedDB like web storage and cookie.&lt;/p&gt;

&lt;p&gt;IndexedDB is a large-scale, NoSQL storage system. It lets you store just about anything in the user’s browser. In addition to the usual search, get, and put actions, IndexedDB also supports transactions.&lt;/p&gt;

&lt;p&gt;In this article, we’ll focus on the following.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Why do we need IndexedDB?
-How do we use an IndexedDB in our applications?
-Features of IndexedDB
-Limitations of IndexedDB
-Is IndexedDB right for your applications?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Why do we need IndexedDB?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Indexed DB is considered more powerful than localStorage!&lt;/p&gt;

&lt;p&gt;Do you know the reason behind it? Let’s find out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can store much bigger volumes of data than localStorage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There is no particular limit like in localStorage (between 2.5MB and 10MB). The maximum limit is based on the browser and the disk space. For example, Chrome and Chromium-based browsers allow up to 80% disk space. If you have 100GB, Indexed DB can use up to 80GB of space, and 60GB by a single origin. Firefox allows up to 2GB per origin while Safari allows up to 1GB per origin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can store any kind of value based on { key: value } pairs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Higher flexibility to store different data types. This means not only strings but also binary data (ArrayBuffer objects, Blob objects, etc.). It uses an object store to hold data internally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Provides lookup interfaces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is not available in other browser storage options such as localStorage and sessionStorage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Useful for web applications that don’t require a persistent internet connection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IndexedDB can be very useful for applications that work both online and offline. For example, this can be used for client-side storage in Progressive Web Apps (PWAs).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application state can be stored&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By storing the application state for recurring users, the performance of your application can be increased drastically. Later on, the application can sync-up with the backend server and update the application via lazy loading.&lt;/p&gt;

&lt;p&gt;Let’s have a look at the structure of the IndexedDB which can store multiple databases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do we use Indexed DB in our applications?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the following section, we’ll look at how to bootstrap an application with IndexedDB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Open the database connection using “window.indexedDB"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const openingRequest = indexedDB.open('UserDB', 1);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Create object store&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once the database connection is open, the onupgradeneeded event will be fired, which can be used to create object stores.&lt;/p&gt;

&lt;p&gt;`// Create the UserDetails object store and indexesrequest.onupgradeneeded = (event) =&amp;gt; {&lt;br&gt;
     let db = event.target.result;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // Create the UserDetails object store 
 // with auto-increment id
 let store = db.createObjectStore('UserDetails', {
     autoIncrement: true
 });

 // Create an index on the NIC property
 let index = store.createIndex('nic', 'nic', {
     unique: true
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Insert data into the object store###&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once a connection is opened to the database, the data can be managed inside the onsuccess event handler. Inserting data happens in 4 steps.&lt;/p&gt;

&lt;p&gt;`function insertUser(db, user) {&lt;br&gt;
    // Create a new transaction&lt;br&gt;
    const txn = db.transaction('User', 'readwrite');&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Get the UserDetails object store
const store = txn.objectStore('UserDetails');    // Insert a new record
let query = store.put(user);

// Handle the success case
query.onsuccess = function (event) {
    console.log(event);
};

// Handle the error case
query.onerror = function (event) {
    console.log(event.target.errorCode);
}

// Close the database once the transaction completes
txn.oncomplete = function () {
    db.close();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Once the insertion function is created, the onsuccess event handler of the request can be used to insert more records.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;request.onsuccess = (event) =&amp;gt; {&lt;br&gt;
   const db = event.target.result;   insertUser(db, {&lt;br&gt;
     email: 'john.doe@outlook.com',&lt;br&gt;
     firstName: 'John',&lt;br&gt;
     lastName: 'Doe',&lt;br&gt;
   });   insertUser(db, {&lt;br&gt;
     email: 'ann.doe@gmail.com',&lt;br&gt;
     firstName: 'Ann',&lt;br&gt;
     lastName: 'Doe'&lt;br&gt;
   });&lt;br&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are many operations that can be performed on the IndexedDB. Some of them are as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Read/search data from object stores by key
-Read/search data from object stores by index
-Update data of a record
-Delete a record
-Migrate from a previous version of a database, etc.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you need insights about how to achieve the above, let me know in the comments section below. You can refer here for more information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features of Indexed DB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-Has an asynchronous API&lt;br&gt;
-Supports transactions for reliability&lt;br&gt;
-Supports versioning&lt;br&gt;
-Private to domain&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is IndexedDB right for your application?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Based on the many features provided by IndexedDB, the answer to this million-dollar question could be Yes! However, before jumping to a conclusion, ask yourself the following questions.&lt;/p&gt;

&lt;p&gt;-Does your application require offline access?&lt;br&gt;
-Do you need to store a large amount of data on the client-side?&lt;br&gt;
-Do you need to quickly locate/search data in a large set of data?&lt;br&gt;
-Does your application access the client-side storage using the supported browsers by IndexedDB?&lt;br&gt;
-Do you need to store various types of data including JavaScript objects?&lt;br&gt;
-Does writing/reading from client-side storage need to be non-blocking?&lt;/p&gt;

&lt;p&gt;If the answer to all of the above questions is Yes, IndexedDB is the best option for you. But if such functionality is not required, you might as well choose a storage method such as localStorage because it provides widespread browser adoption and features an easy-to-use API.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>html</category>
      <category>database</category>
    </item>
    <item>
      <title>How to HACK Nginx</title>
      <dc:creator>c org</dc:creator>
      <pubDate>Sat, 09 Jul 2022 22:20:08 +0000</pubDate>
      <link>https://dev.to/chriskennedylol/how-to-hack-nginx-521l</link>
      <guid>https://dev.to/chriskennedylol/how-to-hack-nginx-521l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.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%2Fcg6loblf9351py2xdeig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fcg6loblf9351py2xdeig.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nginx is being used in the wild since a while now. We all have seen NGINX name somewhere while coding/hacking. NGINX has always been a target for hackers/bug bounty hunters due to a lot of misconfigurations in it, and as a security researcher/bug bounty hunter, hacking a web server always fascinates us. Today we will see how we can ACTUALLY hack a NGINX if it is vulnerable, and try to pick some bucks from it.&lt;/p&gt;

&lt;p&gt;Well, if you are new to this topic, and somehow don’t know how NGINX as a server works, here is a description from internet:- &lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Nginx is built to offer low memory usage and high concurrency. Rather than creating new processes for each web request, Nginx uses an asynchronous, event-driven approach where requests are handled in a single thread. With Nginx, one master process can control multiple worker processes. The master maintains the worker processes, while the workers do the actual processing. Because Nginx is asynchronous, each request can be executed by the worker concurrently without blocking other requests.”&lt;/em&gt;&lt;br&gt;
 You can obviously do a lot of stuff with the help of NGINX:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reverse proxy with caching&lt;/li&gt;
&lt;li&gt;IPv6&lt;/li&gt;
&lt;li&gt;Load balancing&lt;/li&gt;
&lt;li&gt;FastCGI support with caching&lt;/li&gt;
&lt;li&gt;WebSockets&lt;/li&gt;
&lt;li&gt;Handling of static files, index files, and auto-indexing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So once we are clear how it works, our topics start..and the point is in which phase misconfigurations happen? Well, there are lot of things which can go other way if we don’t configure it properly. If you will go back in history, NGINX SPDY heap buffer overflow was exploited in 2014. To exploit this, the attacker can execute arbitrary code by specially crafting a request to cause a heap memory buffer overflow. This would gravely affect the web server. Also in 2020, PHP Remote Code Execution Vulnerability was found in NGINX which was severe and it was considered one of the most critical findings in this product ever. You can read more about them on internet. I leave it on you.&lt;/p&gt;

&lt;p&gt;Since NGINX is the most common web server which is used these days, a lot of security issues are there too. We are talking about these today:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing root location&lt;/li&gt;
&lt;li&gt;Alias LFI Misconfiguration&lt;/li&gt;
&lt;li&gt;Raw backend response reading&lt;/li&gt;
&lt;li&gt;Unsafe variable use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Missing root location:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Check the below code snippet:-&lt;/p&gt;

&lt;p&gt;`server {&lt;br&gt;
 root /etc/nginx;&lt;/p&gt;

&lt;p&gt;location /hack.txt {&lt;br&gt;
  try_files $uri $uri/ =404;&lt;br&gt;
  proxy_pass &lt;a href="http://127.0.0.1:1212/" rel="noopener noreferrer"&gt;http://127.0.0.1:1212/&lt;/a&gt;;&lt;br&gt;
 }&lt;br&gt;
}&lt;br&gt;
`&lt;br&gt;
In NGINX, root directive specifies the root folder. In this example, root file is defined as /etc/nginx, it means that we can go ahead look upto nginx and files within it. So here if you will send a simple request like GET /nginx.conf it will reveal some sensitive info such as configuration of nginx and other stuff. Since “/” can handle any request, we can send a sensitive endpoint through it. In some cases it is possible to reach other configuration files and access logs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Alias LFI Misconfiguration:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is always recommended to check “location” statements under NGINX configuration. If you find something like:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;location /imgs {&lt;br&gt;
alias /path/images/&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can go ahead and perform a LFI here. How? Expand it to &lt;strong&gt;/imgs../secret.txt&lt;/strong&gt; and it will transform to &lt;strong&gt;/path/images/../secret.txt&lt;/strong&gt;. You can read more about it here:- &lt;a href="https://www.acunetix.com/vulnerabilities/web/path-traversal-via-misconfigured-nginx-alias/" rel="noopener noreferrer"&gt;LFI/Path traversal.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Raw backend response reading:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Nginx’s &lt;code&gt;proxy_pass&lt;/code&gt;, there’s the possibility to intercept errors and HTTP headers created by the backend. This is very useful if you want to hide internal error messages and headers so they are instead handled by Nginx. Nginx will automatically serve a custom error page if the backend answers with one.&lt;br&gt;
Imagine there is an application like this:-&lt;/p&gt;

&lt;p&gt;And it has following directives in NGINX:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http {&lt;br&gt;
error_page 500 /html/error.html;&lt;br&gt;
proxy_intercept_errors on;&lt;br&gt;
proxy_hide_header Secret-Header;&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So if we send a simple GET request, our response will be something like this:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HTTP/1.1 500 Internal Server Error&lt;br&gt;
Server: nginx/1.10.3&lt;br&gt;
Content-Type: text/html&lt;br&gt;
Content-Length: 15&lt;br&gt;
Connection: close&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But what if we try to send an invalid request and check what happens next? Something like this:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GET /? XTTP/1.1&lt;br&gt;
Host: 127.0.0.1&lt;br&gt;
Connection: close&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If its vulnerable we should get a response with secret info:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;XTTP/1.1 500 Error&lt;br&gt;
Content-Type: text/html&lt;br&gt;
Secret-Header: secret&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Unsafe variable use:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A vulnerable NGINX configuration will look like this:-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;location / {&lt;br&gt;
return 302 https://abcd.com$uri;&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The new line characters for HTTP requests are \r (Carriage Return) and \n (Line Feed). URL-encoding the new line characters results in the following representation of the characters %0d%0a. When these characters are included in a request like &lt;a href="http://localhost/%0d%0aHacker:%20test" rel="noopener noreferrer"&gt;http://localhost/%0d%0aHacker:%20test&lt;/a&gt; to a server with the misconfiguration, the server will respond with a new header named HACKER since the $uri variable contains the URL-decoded new line characters&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HTTP/1.1 302 Moved Temporarily&lt;br&gt;
Server: nginx/1.19.3&lt;br&gt;
Content-Type: text/html&lt;br&gt;
Content-Length: 200&lt;br&gt;
Connection: keep-alive&lt;br&gt;
Location: https://abcd.com/&lt;br&gt;
Hacker: test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- proxy_pass and internal directives:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The proxy_pass directive can be used to redirect internally requests to other servers internal or external. The internal directive is used to make it clear to Nginx that the location can only be accessed internally.&lt;/p&gt;

&lt;p&gt;These were some common attack scenarios which arise in NGINX. There are obviously a lot of buffer overflows reported in this product, and it is always recommended to check everything which you can do on a particular server. Since NGINX is used as a load balancer as well, DOS is also possible there. However, the more they update the product, old vulns are getting vanished there. Since it is being used a lot, chances are new vulnerabilities will arise.&lt;/p&gt;

&lt;p&gt;I hope you got something from this blog. Old folks know a lot of things, which are mentioned in this blog, are already available in this blog, so not a lot for those guys. But if you are new, you will surely get some good knowledge from it. I hope it helps you to learn a couple of things.&lt;/p&gt;

&lt;p&gt;Now ready to hack.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
