<?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: Pranav Joglekar</title>
    <description>The latest articles on Forem by Pranav Joglekar (@pranav2612000).</description>
    <link>https://forem.com/pranav2612000</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%2F422774%2Ff9acda15-65d2-43cb-a271-9c5bb6869080.jpeg</url>
      <title>Forem: Pranav Joglekar</title>
      <link>https://forem.com/pranav2612000</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pranav2612000"/>
    <language>en</language>
    <item>
      <title>Move commits from one branch to another</title>
      <dc:creator>Pranav Joglekar</dc:creator>
      <pubDate>Fri, 11 Jun 2021 19:33:18 +0000</pubDate>
      <link>https://forem.com/pranav2612000/move-commits-from-one-branch-to-another-fil</link>
      <guid>https://forem.com/pranav2612000/move-commits-from-one-branch-to-another-fil</guid>
      <description>&lt;h3&gt;
  
  
  Scenario:
&lt;/h3&gt;

&lt;p&gt;You encountered a production issue. Immediately you stopped doing whatever you were working on and started fixing the bug. After fixing the bug you observe that you fixed the bug on a different branch. Now you want to move a certain number of commits from a branch A to branch B.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;To move a small number of commits from A to B, use the &lt;code&gt;git cherry-pick&lt;/code&gt; command&lt;/p&gt;

&lt;p&gt;Say, you have the following branches&lt;/p&gt;

&lt;h4&gt;
  
  
  Branch A
&lt;/h4&gt;

&lt;p&gt;P ----- Q ----- R ------ S&lt;/p&gt;

&lt;h4&gt;
  
  
  Branch B
&lt;/h4&gt;

&lt;p&gt;F ----- G ----- H&lt;/p&gt;

&lt;p&gt;(Note: P, Q, R, S, F, G, H are all commit hashes/ids)&lt;/p&gt;

&lt;p&gt;and you want to move commits Q &amp;amp; R to B(in front of H). You can do the following by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout branchB
git cherry-pick Q
git cherry-pick R
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will result in&lt;/p&gt;

&lt;p&gt;Branch B&lt;/p&gt;

&lt;p&gt;F ----- G ----- H ----- Q ----- R&lt;/p&gt;

&lt;p&gt;Basically, we first checkout to the branch where we want to add the commits, and cherry-pick the commits we want to move, in the order in which they appear in the first branch. Ensuring that the commits being cherry-picked are in sequential order is important or can result in complications.&lt;/p&gt;

&lt;p&gt;Like I said, this method works if the number of commits is small, but to move a large number of commits we can use a better method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;branchname where commits are to be moved&amp;gt;
git rebase --onto &amp;lt;SHA of most recent commit in branchB&amp;gt; &amp;lt;SHA of the commit before the commit that is to be moved&amp;gt; &amp;lt;SHA of the last commit that is to be moved&amp;gt;
git rebase HEAD &amp;lt;branchname where commits are to be moved&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, for the above example - moving Q &amp;amp; R to branch B, the commands would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout branchB
git rebase --onto H P R
git rebase HEAD branchB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These two tricks should be enough for moving commits between branches.&lt;/p&gt;

&lt;p&gt;To read more of such git tips visit my blog - &lt;a href="https://pranavjoglekarcodes.web.app/blogs/posts/2021/git_tricks_1/"&gt;https://pranavjoglekarcodes.web.app/blogs/posts/2021/git_tricks_1/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>versioncontrol</category>
      <category>devops</category>
    </item>
    <item>
      <title>Set up NextJS, TailwindCSS and TypeScript</title>
      <dc:creator>Pranav Joglekar</dc:creator>
      <pubDate>Sun, 31 Jan 2021 15:40:40 +0000</pubDate>
      <link>https://forem.com/pranav2612000/set-up-nextjs-tailwindcss-and-typescript-2bkd</link>
      <guid>https://forem.com/pranav2612000/set-up-nextjs-tailwindcss-and-typescript-2bkd</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O6Oy-nOW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/guscblvulxo3b7tgsakx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O6Oy-nOW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/guscblvulxo3b7tgsakx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Hello everyone. In this post, I am going to explain how to set up a project using NextJS, TailwindCSS and TypeScript. This blog will also serve as a guide for me to refer to in the future. This guide is not a in-depth guide to all the commands, but is rather is a kind of checklist you can refer too. I am assuming you have basic knowledge of running node applications.&lt;br&gt;
Lets start.&lt;/p&gt;
&lt;h1&gt;
  
  
  Installing NextJS
&lt;/h1&gt;

&lt;p&gt;The first step is installing nextJS. If you haven't created a npm checked directory yet. Create a new directory, cd into it and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically generate a package.json file for you, with all default values.&lt;/p&gt;

&lt;p&gt;The next step is to install next and other dependencies required to run the web-application. Here's how we do this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install next react react-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once Next and React is successfully installed, we modify the npm scripts in package.json so that they run the appropriate scripts desired while developing and building next applications. Modify the scripts property in package.json to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  "dev": "next dev", // starts next in development mode
  "build": "next build", //builds the application for production usage
  "start": "next start" // starts a nexjs production server
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should complete the setup. Lets add some simple files to verify everything works as expected. Create a src/pages/ folder ( NextJS automatically serves files from this directory). Add an index.js file to this directory. Add a basic hello world react page to this file. Once done with this, type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to start the development environment. You should now be able to see your hello-world react page at the root (/) of the application on the appropriate port.&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding TailwindCSS
&lt;/h1&gt;

&lt;p&gt;Once we have finished setting up with NextJS, lets install TailwindCSS to help us with designing the application.&lt;br&gt;
Let's start with installing Tailwind and required dependencies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install tailwindcss@latest postcss@latest autoprefixer@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Tailwind requires certain config files to run(see tailwind.config.js &amp;amp; postcss.config.js ). To install these run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a minimal tailwind.config.js file at the root of the project&lt;/p&gt;

&lt;p&gt;The next step is to configure tailwind to remove unused styles in production builds. We do this by modifying the &lt;code&gt;purge&lt;/code&gt; parameter created in tailwind.config.js to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completes the tailwind setup. The next step is to include tailwind with the css this is done by including&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the global css file. If you havent created a global css file yet, create a new file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/styles/globals.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and add the above tailwind directives to it.&lt;/p&gt;

&lt;p&gt;Finally we import the css file into the jsx components. The way of doing this with nextJS is by creating a new &lt;code&gt;src/pages/_app.js&lt;/code&gt; file which contains&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '../styles/globals.css' // or the location of your css file

function MyApp({ Component, pageProps }) {
  return &amp;lt;Component {...pageProps} /&amp;gt;
}

export default MyApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds the css to all pages, and you can use tailwind on all pages.&lt;br&gt;
We can now start styling our components using the amazing TailwindCSS&lt;/p&gt;
&lt;h1&gt;
  
  
  Adding TypeScript support
&lt;/h1&gt;

&lt;p&gt;First, we create an empty &lt;code&gt;tsconfig.js&lt;/code&gt; file at the root of the directory. This specifies the next executable that we are using typescript in this project.&lt;/p&gt;

&lt;p&gt;Again, the next step is installing typescript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev typescript @types/react @types/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, start the development server with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, nextJS does 2 things. It automatically populates the tsconfig.js file(You can change the configurations later) and it creates the next-env.d.ts file, which ensures Next.js types are picked up by the TypeScript compiler. You should not touch this file.&lt;/p&gt;

&lt;h1&gt;
  
  
  Coda
&lt;/h1&gt;

&lt;p&gt;That's it. This completes the short tutorial. Reach out to me if you are facing issues with following the tutorial, or are facing any issues setting up these frameworks.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting up precommit hooks for prettier, EsLint, jest</title>
      <dc:creator>Pranav Joglekar</dc:creator>
      <pubDate>Sun, 10 Jan 2021 19:13:08 +0000</pubDate>
      <link>https://forem.com/pranav2612000/setting-up-precommit-hooks-for-prettier-eslint-jest-3lnb</link>
      <guid>https://forem.com/pranav2612000/setting-up-precommit-hooks-for-prettier-eslint-jest-3lnb</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Hello Developers. Today I am going to explain how to set up pre-commit hooks for prettier, EsLint &amp;amp; jest for your project.&lt;br&gt;
Let me first explain what these are and their importance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jest&lt;/strong&gt; is a javascript testing framework that can be used with many popular javascript frameworks. It allows us to run multiple tests and test suites and view the results in beautiful formats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EsLint&lt;/strong&gt; is a static code analyzer and javascript linter for your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;prettier&lt;/strong&gt; is a code formatter that helps you in formatting your code.&lt;/p&gt;
&lt;h1&gt;
  
  
  Why are these required
&lt;/h1&gt;

&lt;p&gt;As your application grows bigger, it gets difficult and costly to test your whole application. This also increases the possibility of bugs creeping into your application. You cannot be confident of the changes you made which in turn also slows down development. All these problems can be solved if you have tests that can automatically run and test your applications. Jest helps you write and run these tests and shows you the results of these tests.&lt;/p&gt;

&lt;p&gt;Also, as the product grows, the number of people working on the codebase also increases. Each developer has his own style of formatting code. If everyone is allowed to use their own styles, the code written by one developer starts being esoteric to others. This again increases bugs in the software and slows down the development process. But, at the same time, developers do not like to be forced to follow standards. This is where prettier and Eslint come in. Eslint searches your code statically for javascript errors and ensures that the codebase is linted according to the standards specified. Prettier also formats your code so that it follows common standards. This ensures your code remains standardized and maintainable. &lt;/p&gt;
&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;Lets start with installing these tools. As usual, npm makes the installation process very easy&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install prettier --save-dev
npm install eslint --save-dev
npm install jest --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the --save-dev flag ensures that the packages are saved as a devDependency&lt;/p&gt;

&lt;p&gt;Along with these, to configure eslint to use prettier, we need some other packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install eslint-plugin-prettier --save-dev
npm install eslint-config-prettier --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Configuration
&lt;/h1&gt;

&lt;p&gt;Since this tutorial is based on add a pre-commit hook, I will not go into the details about setting up jest tests. You can find various articles on the way to set up and run these tests.&lt;/p&gt;

&lt;p&gt;For configuration prettier, create a .prettierrc file in the repository's root directory. Add the following to 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;{
  "printWidth": 85,
  "arrowParens": "always",
  "semi": true,
  "tabWidth": 2,
  "useTabs": false,
  "singleQuote": true,
  "trailingComma": "none",
  "bracketSpacing": true,
  "jsxBracketSameLine": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a sample prettier configuration file - which defines how the code is to be formatted. This file states that all statements should end with a semi-colon. There shouldn't be a trailing comma, and angular brackets should be on the same line as the function. All tabs should be changed to spaces and the indentation width should be 2 spaces. You can create your own file by referring to the various configurations allowed by prettier.&lt;/p&gt;

&lt;p&gt;For configuring EsLint, create a .eslintrc.json file. Here's a sample configuration for this file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "env": {
    "browser": true,
    "es6": true,
    "jest": true
  },
  "extends": ["plugin:prettier/recommended"],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },
  "plugins": ["prettier"],
  "rules": {
    "semi": [2, "always"],
    "react/no-unescaped-entities": 0,
    "react/prop-types": 0,
    "react/jsx-key": 0,
    "react/no-find-dom-node": 0,
    "no-unused-vars": 0,
    "no-array-constructor": 0,
    "new-cap": 0,
    "space-before-function-paren": 0,
    "prettier/prettier": "error"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file contains a lot of configuration info, but the important parts are the plugins part which tells eslint which plugin to use, and the rules that eslint should check for. Along with this configuration file, you also need to add a .eslintignore file to define the files and folders that are to be ignored by eslint. Here's a simple file which ignores the node_modules and the build folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**/build/*
**/dependencies/*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completes the configuration step.&lt;/p&gt;

&lt;h1&gt;
  
  
  Execution
&lt;/h1&gt;

&lt;p&gt;To run jest automated test, just type&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;This should run all the tests and show you the results of the tests in your terminal.&lt;/p&gt;

&lt;p&gt;To run eslint type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;i.e eslint &lt;br&gt;
eslint recursively checks all folders from the folder_name to search for lining errors and prints them on the screen. To automatically fix those errors. Type&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This should fix all the automatically fixable errors.&lt;/p&gt;

&lt;p&gt;To just run prettier type,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will run prettier recursively for all files inside the current directory and updating them in-place if it finds any inconsistencies&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up precommit hook
&lt;/h1&gt;

&lt;p&gt;With jest, eslint and prettier configured and executing successfully, the last step is to set up a pre-commit hook to run these tools automatically, every time a developer commits some changes to the repository. This will reduce the burden of running these scripts every time, before committing and also prevent cases where a developer may forget to run some of these tools.&lt;/p&gt;

&lt;p&gt;To set up this pre-commit hook, we would be using 2 more tools. husky and lint-staged, install those tools using, yes you guessed it right, npm&lt;br&gt;
npm install husky lint-staged --save-dev&lt;/p&gt;

&lt;p&gt;Update your package.json to contain the following fields&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;... // other contents of package.json
"devDependencies": {
    ... // all your dev dependencies would be here.
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,jsx}": [
      "prettier --write",
      "eslint --fix",
      "jest --findRelatedTests",
      "git add"
    ],
    "*.{html,css,less,ejs,json}": [
      "prettier --write",
      "git add"
    ]
  }
} // close package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;husky sets up a pre-commit hook. It calls lint-staged before every commit. Depending on the type of file that is being committed, lint-staged runs certain commands. For E.g if it is a .js or .jsx file it runs prettier --write and eslint --fix on the file to update the file to appropriate standard, and then tests a subset of the tests to ensure that the changes do not cause tests to fail. If everything works, it adds the file to the staging area and commits it.&lt;/p&gt;

&lt;p&gt;This way, all files being committed by you, are automatically&lt;br&gt;
 formatted to ensure that they follow the code formatting rules, without you having to worry about it.&lt;/p&gt;

&lt;p&gt;That's it. You're done.&lt;br&gt;
Reach out to me if you need help setting up your project. I'll be happy to help.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Phishinder: A phishing detection tool</title>
      <dc:creator>Pranav Joglekar</dc:creator>
      <pubDate>Sun, 11 Oct 2020 20:13:32 +0000</pubDate>
      <link>https://forem.com/pranav2612000/phishinder-a-phishing-detection-tool-3ff0</link>
      <guid>https://forem.com/pranav2612000/phishinder-a-phishing-detection-tool-3ff0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This blog is about a &lt;strong&gt;phishing detection tool&lt;/strong&gt;, I have created(&lt;em&gt;Work in Progress&lt;/em&gt;) which takes an URL as an input and returns whether the URL is a &lt;strong&gt;malicious&lt;/strong&gt; phishing site or a &lt;strong&gt;legitimate&lt;/strong&gt; one. I’ve explained how I’ve created this tool(and how you can too) and how it is used. Let's understand what &lt;strong&gt;phishing&lt;/strong&gt; is before we start.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Phishing&lt;/strong&gt; is a criminal mechanism employing both social engineering and technical tricks to steal consumers’ personal identity data and financial account credentials. &lt;strong&gt;Social engineering&lt;/strong&gt; schemes use spoofed e-mails, purporting to be from legitimate businesses and agencies, designed to lead consumers to &lt;strong&gt;counterfeit&lt;/strong&gt; websites that trick recipients into divulging financial data such as usernames and passwords. As systems become more and more secure, humans are becoming weaker and lazier. Attackers use &lt;strong&gt;social engineering techniques&lt;/strong&gt;, creating fake emails which redirect users to &lt;strong&gt;malicious&lt;/strong&gt; websites(very similar to the original ones). When users enter their &lt;strong&gt;secret information&lt;/strong&gt; on such websites, this secret information is transferred to the attacker, allowing attackers to gain your identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the Tool
&lt;/h2&gt;

&lt;p&gt;To use the &lt;strong&gt;tool&lt;/strong&gt;, users would first need to clone a copy from &lt;a href="https://github.com/Pranav2612000/phishinder"&gt;the repo&lt;/a&gt;. Then the required dependencies need to be installed using &lt;em&gt;pip -r requirements.txt&lt;/em&gt;&lt;br&gt;
Users can then run&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;code python3 phishinder.py&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 to start the program, and enter an URL which is to be checked once the prompt asks for it. The result will be printed back on the screen&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iXOBSZ61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/blu6tamwpez9e521h1jj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iXOBSZ61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/blu6tamwpez9e521h1jj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wfOCBRsP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rspd2tswo4pqxd6cfuz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wfOCBRsP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rspd2tswo4pqxd6cfuz0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Links:
&lt;/h2&gt;

&lt;p&gt;Link to Repo: &lt;a href="https://github.com/Pranav2612000/phishinder"&gt;Here&lt;/a&gt;&lt;br&gt;
Link to notebook: &lt;a href="https://colab.research.google.com/drive/1_CnjWOocwkhtumgrhAYkm0D4BfGZ4CCx#scrollTo=po1WFNp3XLa3"&gt;Here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;program&lt;/strong&gt; takes the url name as its input, and returns whether the url is &lt;strong&gt;malicious or not&lt;/strong&gt; to the user. I am using &lt;strong&gt;machine-learning&lt;/strong&gt; techniques to classify a website into malicious and safe categories. Details about the &lt;strong&gt;model&lt;/strong&gt; will be explained later.&lt;br&gt;
I’ve built this tool in &lt;strong&gt;python&lt;/strong&gt; as it provides helpful libraries*(e.g requests, beautifulsoup)* and a lot of packages which makes it easier to gather data about the site. Python also makes it easier to train and deploy ML models.&lt;/p&gt;
&lt;h2&gt;
  
  
  Part-I Training the Model
&lt;/h2&gt;

&lt;p&gt;I have used the &lt;a href="https://archive.ics.uci.edu/ml/datasets/phishing+websites"&gt;&lt;strong&gt;Phishing Websites Dataset&lt;/strong&gt;&lt;/a&gt; dataset to train the &lt;strong&gt;ML model&lt;/strong&gt; . The dataset consists of 30 &lt;strong&gt;columns or features&lt;/strong&gt; each equally important in detecting whether a site is malicious or not. The columns along with a brief description of each is given in the &lt;strong&gt;Appendix A&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's get started, first install all the required dependencies.&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="err"&gt;!&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt;
&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then import them&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, open the dataset. (This command may differ for you depending on the location and name of the dataset)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Phishing.csv"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Play around with the dataset a bit - understand it’s values, dimensions, what preprocessing operations are required. We observe that the input takes 3 values -1, 0, 1 and the output takes two values -1 for malicious and 1 for safe. &lt;br&gt;
For a basic model, No special input preprocessing was needed. We’ll change the output a bit, so that the column is called Result and has two values 0 for malicious and 1 for safe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'Result'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Class'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;inplace&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;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Class'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Class'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;map&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets split the data into training and testing sets&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;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.model_selection&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iloc&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="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;astype&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iloc&lt;/span&gt;&lt;span class="p"&gt;[:,&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;astype&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the sake of this article, I’ll be using the &lt;strong&gt;Logistic Regression&lt;/strong&gt;. You may try out different models, with hyperparameter tuning to get better results. Various blogs have also used Deep Learning Methods for training the model. These have been added in &lt;strong&gt;Appendix B&lt;/strong&gt;.&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;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.linear_model&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LogisticRegression&lt;/span&gt;
&lt;span class="n"&gt;lr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;LogisticRegression&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the results of this model,&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;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.metrics&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;accuracy_score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;classification_report&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Accuracy Score for logistic regression: {}%'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;accuracy_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Classification Report:'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;classification_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;target_names&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Malicious Websites"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Normal Websites"&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMicL9mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8oaot7h8xip9bf1mwrxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMicL9mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8oaot7h8xip9bf1mwrxn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, let's dump the model to a file so that it can be conveniently used later in programs.&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;from&lt;/span&gt; &lt;span class="nn"&gt;sklearn.externals&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;
&lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"phishing_detection.pkl"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completes with the Machine Learning Part of the tutorial&lt;/p&gt;

&lt;h2&gt;
  
  
  Part II Developing the python tool
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VBG8OYcD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6oa9wctw90n3c1i78guv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VBG8OYcD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6oa9wctw90n3c1i78guv.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yup. Now we have a working model ready, but how do we use this model? It requires data in the form of -1,0,1 values of 30 fields and there is no direct way to get those for a website. Here’s where the 2nd part comes in. Given a website name from the user, we’ll try to get the values of each of the 30 features( listed in &lt;strong&gt;Appendix A&lt;/strong&gt;). Once we have the values of the 30 features we can use the model to get its output, which informs us whether a site is malicious or not.&lt;/p&gt;

&lt;p&gt;First, let's import the dependencies we’ll be needing. Use pip to install the packages not available in your system. You can also use pip install -r requirements.txt to automatically install all packages required.&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="nn"&gt;joblib&lt;/span&gt; &lt;span class="c1"&gt;#importing the model
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;dns&lt;/span&gt; &lt;span class="c1"&gt;# getting dns info about url
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;dns.resolver&lt;/span&gt; &lt;span class="c1"&gt;#getting dns info about url 
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;whois&lt;/span&gt; &lt;span class="c1"&gt;# getting whois info about url
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;dateutil.relativedelta&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;relativedelta&lt;/span&gt; &lt;span class="c1"&gt;#time calculations required in feature #9
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;urllib.request&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urlopen&lt;/span&gt; &lt;span class="c1"&gt;# access the url
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;bs4&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&lt;/span&gt; &lt;span class="c1"&gt;# scraping the url
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;favicon&lt;/span&gt; &lt;span class="c1"&gt;# required for feature #10
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;csv&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;randint&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;shutil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the ML model to a variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;phisher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;joblib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"./phishing_detection.pkl"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the input to the ML model. Initialize it to all 0s&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;site&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;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="n"&gt;site&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;append&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get name of the url to be checked from the user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Enter name of website(with https)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get the name of the url without the trailing http/https, and perform operations on the url to scrape the webpage and obtain information pertaining to its DNS records and WHOIS entries&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;path_start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;':'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;path_start&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;bs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BeautifulSoup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'html.parser'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;bs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;domain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;whois&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;domain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;dnsresult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resolver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'A'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;dnsresult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next part is filling the 30 features. For the sake of brevity, I’ll be covering only some of the 30 features. The implementation of the remaining features can be found in the repo(Link above). You can also reach out anytime, if you are interested to know more.&lt;/p&gt;

&lt;p&gt;URLs with length greater than 60 have a chance of being malicious.&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;site&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;site&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Phishing Sites are shortlisted and have not phishing records&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="nn"&gt;dns&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;dns.resolver&lt;/span&gt;
&lt;span class="n"&gt;dnsresult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resolver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'A'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dnsresult&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;site&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="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;site&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="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Malicious sites usually redirect a lot of times before reaching the actual site&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&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="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'2'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="n"&gt;site&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="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="n"&gt;site&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="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: These are just some of the features. More features can be found on the repo. I am still working on some of those, but the program still gives good results using only the ones which have been implemented and substituting -1 for the rest.&lt;br&gt;
The comprehensive code, along with the packages required can be obtained through the repo. The code is simple and self-explanatory, so I won’t be talking about it much in this post.&lt;/p&gt;

&lt;p&gt;Once the input data is filled, we pass it to the model for prediction, the model prediction is converted to human-understandable output and printed on the screen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;results = ["Malicious", "Safe"]
print(results[int(phisher.predict(site))])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This completes the implementation of the tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future Scope:
&lt;/h2&gt;

&lt;p&gt;The same algorithm can be packaged in the form of a &lt;strong&gt;REST Service&lt;/strong&gt; to be consumed. I plan to build a &lt;strong&gt;browser extension&lt;/strong&gt;, which uses this API to detect if sites are malicious or not. If a malicious site is found, the browser extension would stop executing the javascript of the page, which would also prevent other types of attacks. The user needs to open the extension and explicitly allow this site to run. This extra effort will also prevent lazy/non-tech users who tend to ignore browser warnings from phishing attacks.&lt;/p&gt;

&lt;h4&gt;
  
  
  PS:
&lt;/h4&gt;

&lt;p&gt;Looking for contributors to help with the project. Feel free to reach out to suggest improvements, ask questions or discuss more on this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RlkX91RU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0i4ed8a5ojgmda1il3a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RlkX91RU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0i4ed8a5ojgmda1il3a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix A
&lt;/h2&gt;

&lt;h3&gt;
  
  
  URL Based Features
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;IP address - If an IP address is used as an alternative of the domain name in the URL, such as “&lt;a href="http://125.98.3.123/fake.html%E2%80%9D"&gt;http://125.98.3.123/fake.html”&lt;/a&gt;, users can be sure that someone is trying to steal their personal information.&lt;/li&gt;
&lt;li&gt;Long URL -  Phishers use long URL to hide the doubtful part in the address bar.&lt;/li&gt;
&lt;li&gt;URL Shortening - Phishers use url shortening services to create real looking address&lt;/li&gt;
&lt;li&gt;URL’s having @ symbol - Using “@” symbol in the URL leads the browser to ignore everything preceding the “@” symbol and the real address often follows the “@”&lt;/li&gt;
&lt;li&gt;Redirection using // - The existence of “//” within the URL path means that the user will be redirected to another website. An example of such URL’s is: “&lt;a href="http://www.legitimate.com//http://www.phishing.com%E2%80%9D"&gt;http://www.legitimate.com//http://www.phishing.com”&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Presence of - : The dash symbol is rarely used in legitimate URLs. Phishers tend to add prefixes or suffixes separated by (-) to the domain name so that users feel that they are dealing with a legitimate webpage.&lt;/li&gt;
&lt;li&gt;Presence of subdomains - websites having more than 3 subdomains are considered unsecure&lt;/li&gt;
&lt;li&gt;Presence of HTTPS: Websites without https or with certificate of unknown authorities are considered insecure&lt;/li&gt;
&lt;li&gt;Domain Registration Length - Malicious websites are short lived - created utmost a year back&lt;/li&gt;
&lt;li&gt;Favicon - Favicon icons loaded from another domain?&lt;/li&gt;
&lt;li&gt;Ports - malicious site servers usually have non-standard ports open too.&lt;/li&gt;
&lt;li&gt;Https in domain: phishers add https in domain to trick users&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  B) Abnormality features:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Images from different domain: Malicious websites usually load images from other domains.&lt;/li&gt;
&lt;li&gt;URLs of Anchor - Malicious websites usually have hyperlinks to different domains&lt;/li&gt;
&lt;li&gt;Content of meta tag - Malicious websites usually have meta links to another domain&lt;/li&gt;
&lt;li&gt;Server Form Handler - If the form submits data to a different domain, the site has a high chance of being suspicious&lt;/li&gt;
&lt;li&gt;Client-side mailto: If the website submits form data to an email using mailto, it is malicious&lt;/li&gt;
&lt;li&gt;Presence in whois - if the website doesn’t have entry in whois, it may be malicious&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  C) HTML/Javascript features
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Forwarding - if the url redirect greater than 3 times, it is malicious&lt;/li&gt;
&lt;li&gt;Fake-statusbar - check if javascript contains code, especially “onmouseover” to display fake statusbar&lt;/li&gt;
&lt;li&gt;Right-click disabled - most phishing sites have right click disabled&lt;/li&gt;
&lt;li&gt;Presence of pop-ups: most malicious sites have pop-ups to submit forms&lt;/li&gt;
&lt;li&gt;Invisible iframes - if a site contains invisible iframes(frameBorder attribute), the site is phishing data&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  D) Domain based features:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Age of Domain - The domain name should be older than atleast 1 year for the site to be valid&lt;/li&gt;
&lt;li&gt;DNS Records - Absence of records, or unknown records&lt;/li&gt;
&lt;li&gt;Traffic - Phishing sites live for a short time and so do not have a lot of traffic&lt;/li&gt;
&lt;li&gt;Pagerank - phishing sites have lower pagerank value&lt;/li&gt;
&lt;li&gt;Google Indes: phishing sites have lower google index&lt;/li&gt;
&lt;li&gt;Number of links pointing to page: phishing sites have low number of sites pointing to them&lt;/li&gt;
&lt;li&gt;Statistical reports: is the site found in cites like phishTank&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Appendix B - Different ML Models
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://towardsdatascience.com/phishing-domain-detection-with-ml-5be9c99293e5"&gt;https://towardsdatascience.com/phishing-domain-detection-with-ml-5be9c99293e5&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medium.com/intel-software-innovators/detecting-phishing-websites-using-machine-learning-de723bf2f946"&gt;https://medium.com/intel-software-innovators/detecting-phishing-websites-using-machine-learning-de723bf2f946&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.researchgate.net/publication/269032183_Detection_of_phishing_URLs_using_machine_learning_techniques"&gt;https://www.researchgate.net/publication/269032183_Detection_of_phishing_URLs_using_machine_learning_techniques&lt;/a&gt;&lt;br&gt;
&lt;a href="https://archive.ics.uci.edu/ml/datasets/phishing+websites"&gt;https://archive.ics.uci.edu/ml/datasets/phishing+websites&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>phishing</category>
      <category>hacking</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Introduction to Kerberos</title>
      <dc:creator>Pranav Joglekar</dc:creator>
      <pubDate>Sun, 16 Aug 2020 19:07:06 +0000</pubDate>
      <link>https://forem.com/pranav2612000/introduction-to-kerberos-28of</link>
      <guid>https://forem.com/pranav2612000/introduction-to-kerberos-28of</guid>
      <description>&lt;p&gt;This post is for those(like me) who have heard the term Kerberos being used a lot of times but have never really understood what it is or what it is used for. I do not claim myself to be an expert on this topic, and please point out my mistakes if any, I’ll immediately update my post.&lt;/p&gt;

&lt;p&gt;First things first…&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Kerberos?
&lt;/h1&gt;

&lt;p&gt;According to Wikipedia, &lt;br&gt;
&lt;em&gt;Kerberos is a computer-network authentication protocol that works on the basis of tickets to allow nodes communicating over a non-secure network to prove their identity to one another in a secure manner.&lt;/em&gt;  &lt;/p&gt;

&lt;p&gt;Simply put, this means that Kerberos is a network security protocol, that authenticates service requests between hosts over an unsecure network( like the internet). It uses strong cryptographic principles to help clients proved their identity to the server(and vice versa)&lt;br&gt;
This prevents malicious attackers from trying to steal client identities. We’ll how this is done in the next sections.&lt;/p&gt;

&lt;p&gt;Kerberos derives its name from Cerberus, a three headed dog in greek mythology. Similar, to the three headed dog, Kerberos has 3 important parts present in Key Distribution Center:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kerberos Database&lt;/li&gt;
&lt;li&gt;Ticket Granting Service&lt;/li&gt;
&lt;li&gt;Authenticating Service&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’ll be explaining each component in detail.&lt;/p&gt;

&lt;h1&gt;
  
  
  Terminology
&lt;/h1&gt;

&lt;p&gt;Lets start with same basic terms you’ll see when dealing with Kerberos&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tickets&lt;/strong&gt; - Tickets(Kerberos tickets/Kerberos Credentials) are a set of electronic information that can be used to verify your identity. Just like you need tickets to enter a train or a bus, you need kerberos tickets to get access to certain services secured by Kerberos.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Principals&lt;/strong&gt; - Principals are unique entities to which tickets can be assigned.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Key Distribution Center&lt;/strong&gt; - This is the central server responsible for authentication. It is split into 3 important parts -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Kerberos Database&lt;/strong&gt; - The kerberos database is the database which stores information about each principal, its passwords and its administrative information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication Server&lt;/strong&gt; - The server used for authentication clients and principals. This is the server responsible for handling the initial authentication request from clients. This issues a ticket called the Ticket Granting Ticket(TGT) which acts as a proof that the client is authenticated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ticket Granting Server&lt;/strong&gt; - This is the server used for issuing service tickets to authenticated clients.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Lifetime of a request
&lt;/h1&gt;

&lt;p&gt;Let us now look at how authentication takes place using Kerberos. Say a User Alice wants to access a service, say a SQL Database. Following are the steps that take place&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Alice sends a request to the &lt;strong&gt;AS&lt;/strong&gt;(Authentication Server). This request contains the credentials for Alice along with some other details required for authentication. The password is not actually sent over the network(It is never safe to send passwords over the network), but all this data is encrypted using Alice’s password and this encrypted data is transmitted to the AS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: The &lt;strong&gt;AS&lt;/strong&gt;(Authentication Server) decrypts Alice’s data. This is possible as the Authentication Server has access to passwords of all users(through the Kerberos Database). After decrypting it checks if the data is valid and untampered(to prevent attacks like the replay attack). If it is able to decrypt the data, and it finds the data is untampered, the &lt;strong&gt;AS&lt;/strong&gt; sends her a &lt;strong&gt;TGT&lt;/strong&gt;(Ticket Granting Ticket) back. The &lt;strong&gt;TGT&lt;/strong&gt; is a ticket that, as its name suggests, is used to ask for tickets to other services. The TGT contains a &lt;strong&gt;session key&lt;/strong&gt;(you’ll understand its importance soon) along with some other data. This &lt;strong&gt;TGT&lt;/strong&gt; is encrypted using a Kerberos admin password(which can be assumed to be impossible to crack) and the encrypted data is sent to Alice. The &lt;strong&gt;AS&lt;/strong&gt; server also sends the session key separately(outside the TGT), but this time the key is encrypted using the user’s(Alice’s) password. So, the session key is sent to Alice, encrypted in 2 ways - using the admin password, and using Alice’s password. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Now Alice receives 2 pieces of data - The first is the &lt;strong&gt;TGT&lt;/strong&gt;, that it cannot decrypt and read(since it is encrypted using the admin password, and Alice doesn’t have access to it), and the second is the &lt;strong&gt;session key&lt;/strong&gt;, which was encrypted using her password, and so can be accessed and read by her. Once Alice has the &lt;strong&gt;session key&lt;/strong&gt;, she sends a request to the &lt;strong&gt;TGS&lt;/strong&gt;(Ticket Granting Server). This request contains the (encrypted)TGT she received from AS along with her username, the service name she wants to access(SQL), the current timestamp, and other data encrypted using the session key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: The &lt;strong&gt;TGS&lt;/strong&gt; now receives the &lt;strong&gt;TGT&lt;/strong&gt;. It decodes the TGT to get the session key. It uses this &lt;strong&gt;session key&lt;/strong&gt; to decrypt the user data, that was sent along with the &lt;strong&gt;TGT&lt;/strong&gt;. After decrypting this data, the Ticket Granting Server now can be assured that it was Alice who was making the requests, and she wants to access the SQL server. The Ticket Granting Service then sends Alice a &lt;strong&gt;Service Ticket&lt;/strong&gt;(encrypted using the service password) and a new session key. This is similar to Step 2, only this time a service password is used instead of an admin password.&lt;br&gt;
(An important point to note here, is that the TGS is not responsible for checking if Alice has the proper rights to access the SQL, which is to be decided by the target server(SQL). The TGS only verifies whether the user(Alice) is the one who claims she is and not an imposter)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Again, this step is similar to step 3, Alice is unable to decrypt the Service Ticket, but she can obtain the new &lt;strong&gt;session key&lt;/strong&gt; by decrypting the second part of the request using her password. Using this session key, she encrypts the data to be sent to the target server(SQL) and sends this data with the Service Ticket&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: The &lt;strong&gt;Target Server&lt;/strong&gt;(SQL Server) decrypts the Service Ticket. It can do this because the ticket was encrypted by TGS using its password. It gets the session key after decryption and uses this to decrypt user request that was sent. It can then act on this request accordingly.&lt;/p&gt;

&lt;p&gt;In this way Kerberos ensures authentication of a user in a complex system.&lt;/p&gt;

&lt;h1&gt;
  
  
  Problems with Kerberos
&lt;/h1&gt;

&lt;p&gt;Kerberos, like any other system, is not impenetrable. Here are some attacks possible. I’ll leave the details about the attacks for you to explore.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Golden Ticket Attack&lt;/li&gt;
&lt;li&gt;Silver Ticket Attack&lt;/li&gt;
&lt;li&gt;Brute Force Attack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel to reach out if you have any doubts, or to correct me about this article.&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=snGeZlDQL2Q"&gt;https://www.youtube.com/watch?v=snGeZlDQL2Q&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.simplilearn.com/what-is-kerberos-article"&gt;https://www.simplilearn.com/what-is-kerberos-article&lt;/a&gt;&lt;br&gt;
&lt;a href="https://web.mit.edu/kerberos/"&gt;https://web.mit.edu/kerberos/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>todayilearned</category>
      <category>kerberos</category>
      <category>authentication</category>
    </item>
  </channel>
</rss>
