Giter Club home page Giter Club logo

portscanner's Introduction

Port Scanner

A basic Port Scanner ๐Ÿ”Ž using Python with an Express Server to test!

GitHub license GitHub code size in bytes GitHub last commit

Note: Please follow this link if you're a GSSoC participant. Keep watching this repo, we'll be opening more beginner-friendly issues.

With this port scanner, I just attempt to connectThis is a form of "reconnaissance" for hackers and penetration testers at various ports, and do nothing else. If I'm able to connect to open ports, then I know at least the port is open.

Pre-requisites ๐Ÿšจ

node-current GitHub top language

  • Python >= v2.7.0

    • Install Python from here.
  • Node.js >= v0.10.0

    • Install Node.js from here.
  • Pip >= v9.0.1

    • Install pip from here.

How to run? ๐Ÿš€

To run Port Scanner: (Via Terminal)

  • Open terminal and type npm install: This will install the dependencies (Express).

  • In the same terminal and type npm start: This will start multiple servers within the given range.

  • Open another terminal and type python src/scanner.py: Enter localhost or 127.0.0.1. It will scan all the ports and print the open ports.

Note: You can enter remote host if you want to scan the ports for any remote host. Check the DISCLAIMER.md before doing this.

To run Port Scanner: (Via UI)

Install flask

Make sure you have Python27\Scripts path added to your system's environment variables.

1. In PowerShell,

pip install flask

Install virtual environment

This step is required only if you are using Python2.7, skip this step when running Python3.X.

2. For Python 2, (via pip)

In PowerShell,

pip install virtualenv
virtualenv --help

Kindly check this if pip installation fails.

Create virtual environment

3. Create a venv folder inside src,

python -m virtualenv venv
\Python27\Scripts\virtualenv.exe venv

Activate the virtual environment

4. Activate venv,

venv\Scripts\activate

5. Run mainScanner.py,

pip install flask
python src/mainScanner.py

6. Go to the port url returned by your terminal.

To run IP Scanner:

  • Open terminal and type python src/ipscanner.py: Enter any IP address XXX.XXX.XXX.YYY. It will scan all the addresses in the range XXX.XXX.XXX.0 to XXX.XXX.XXX.255 and print the addresses which are live.

Configuration โš™๏ธ

The servers are opened at multiple ports, you can change the low range and high range for the ports to be listened by the Express server.

{
    "range": {
        "low": "1",
        "high": "8888"
    },
    "ipRange": {
        "low": "0",
        "high": "255"
    },
    "count": "10",
    "thread": { 
        "count": 8
    }
}
  • range.low: lowest port number (inclusive)
  • range.high: highest port number (exclusive)
  • ipRange.low: lowest IP address range (inclusive)
  • ipRange.high: highest IP address range (inclusive)
  • count: total number of ports
  • thread.count: total number of concurrent threads

Contributing ๐Ÿค

PRs Welcome CodeFactor Open Source Love

Please read our Code of Conduct.

We're accepting PRs for our open and unassigned issues. Please check CONTRIBUTING.md. We'd love your contributions! Kindly follow the steps below to get started:

1. Fork this repository.

2. Clone the forked repository.

git clone https://github.com/<your-github-username>/PortScanner

3. Navigate to the project directory.

cd PortScanner

4. Create a new branch.

git checkout -b <your_branch_name>

5. Make changes in source code.

6. Stage your changes and commit

git add .

git commit -m "<your_commit_message>"

7. Push your local commits to the remote repo.

git push -u origin <your_branch_name>

8. Create a PR to develop !

9. Congratulations! ๐ŸŽ‰ Sit and relax, you've made your contribution to Port Scanner project. โœŒ๏ธ โค๏ธ

Branching ๐Ÿšง

  • master branch is maintained and tested regulary for Python 2.

  • Please checkout feature/python3.8 if you're using Python 3.

git checkout feature/python3.8

Need for Multithreading โœ…

The ability of a process to execute multiple threads parallelly is called multithreading. Ideally, multithreading can significantly improve the performance of any program.

Imagine scanning substantial number of ports(range.high = 8888) consecutively. The process would require quite a long time.

This calls for the need of concurrency in different parts of this range(1-8888). That is, running different parts(1-1111, 1112-2222, 2223-3333...) of the same process at the same time. This would reduce the time required for completion by significant amount. The reduction in time can be related to the number of concurrent ranges(threads) being scanned simultaneously. Checkout the Performance Analysis for a follow up.

Performance using threads ๐ŸŽฏ

  • src/single/scanner.py: Scanner without thread
  • src/scanner.py: Scanner with multi threads
Range(low-high) src/single/scanner.py (in milliseconds) src/scanner.py (in milliseconds)
1-80 143243 30862

CONST_NUM_THREADS : 8

Performance on the basis of number of threads ๐Ÿ“‰

Range of ports: 1-80

Number of threads Execution time (in milliseconds) Compared Performances
2 71627 50 % faster
4 40808 71.51 % faster
8 37003 74.17 % faster
16 36870 74.26 % faster
32 32674 77.19 % faster

Performance Analysis

Performance Analysis

Blog

Medium Story

Open Source Programs

We're now a part of Leapcode. It helps you contribute to open-source projects right from your first PR to working on major projects. It's still under construction and hopeful to have their platform up pretty soon. Click here to get an early access.

Useful resources ๐Ÿ“š

  • Express: Node.js web framework used for creating server. Check server/index.js
  • Socket: Low-level networking interface in Python. Check src/scanner.py
  • Threading: Thread-based parallelism in python. Check src/scanner_thread.py
  • Flask: A micro web framework written in Python. Check src/mainScanner.py

Contributors ๐Ÿ†

GitHub issues GitHub pull requests

Name ๐ŸŽ–๏ธ Social Media ๐Ÿ‘‹ GitHub :octocat:
Vinit Shahdeo ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@vinitshahdeo
Kashish ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@Kashish121
Ishika Dubey ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@ishika1727

See the contribution graph here.

Admin

Vinit Shahdeo

License

FOSSA Status

TL;DR

Check out this gist if you're only looking for a Python script for scanning ports.


if (_.isAwesome(thisRepo)) {
  thisRepo.star(); // thanks in advance :p
}

GitHub followers Twitter Follow

This repository is intended for individuals to test their own equipment for weak security, and the author(@vinitshahdeo) will take no responsibility if it is put to any other use. Check DISCLAIMER.md

Made with Python Built with love

portscanner's People

Contributors

dependabot[bot] avatar fossabot avatar guptachitresh avatar ishika1727 avatar kashish121 avatar sohaib03 avatar vinitshahdeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

portscanner's Issues

[BUG] Indexes of the port list are getting used as ports rather than the actual PORT

Describe the bug
Bug 1: the ports list which generated using the values read from the config.json file is not getting used. Rather the index is getting used as port in the scan function. [Refer to screenshot 2]
Bug 2: Now because of the above bug, regardless of the low port value given in the config file, the port scanning starts from 0 onwards.
Bug 3: setdefaulttimeout function is only used in ipscanner.py file. Should be used across all the files where socket is being created
Bug 4: if the total number of ports to scan is less than number of threads, the logic implemented is not assigning the ports properly. between the threads. [Refer to screenshot 1]

Bug 5: This one is not a bug but an improvement on how the ports should get assigned to the threads. Currently, for example if there are 87 ports in total that needs to be scanned and the number of threads are 8, then the first 7 threads will get 10 ports each and the 8th thread will get 17 ports to scan. Now in practical scenarios, when the number of ports and the number of threads will be high, the last thread will have to scan additional number of ports compared to the other threads. (the number can become large)

Bug 6: Need to keep sanity checks for the config that is being read. For unexpected values, the program will crash.

To Reproduce
Add logs to print the port range, split_size and the thread number to analyze the situation. Refer to screenshots

Expected behavior
Mentioned is the description.

Screenshots
[screenshot 1] https://drive.google.com/file/d/1Wd2SQr6me0CG5QiJBf2P9Lt_JKqBybGS/view?usp=sharing
[screenshot 2] https://drive.google.com/file/d/199doKJWS2bw9L8oQnW0i1gfuqB3dP_dK/view?usp=sharing

Desktop (please complete the following information):

  • OS: MacOS, Windows, Linux
  • Browser: Chrome, Safari, Mozilla

Additional context
The above bugs are applicable for both python 2 and python 3
Will be raising a pull request with the above bug fixes.

[DOCUMENTATION] Analyze the efficiency of multithreading.

Performance of the tool port scanner is recorded in the README.md section here. The table created holds the statistical numbers for Windows OS. Let's see if the results corelate for other OS(s).

Tabulate the performance and have a corresponding pictorial representation for performance of scanning process in OS other than Windows.

image

empty input value crashes website

Describe the bug

pressing scan now with empty input value crashes website

image

Expected changes
we need to put required in the input field


image

Expected behavior

image

Enable dark mode

Having a toggle button on UI to switch to dark & light theme will be a great idea.

@ishika1727 can you please expand more on this in the comments section?

Add a description about multi-threading

Inside this section, please write a brief description (not more than 3 lines) stating why have we decided to go with multi threading.

It's always better if we share our findings/knowledge.

Port Scanner Form Component in React

As we've built many features to justify the one-liner description of this project i.e. a go-to networking tool, now it's time to revamp the existing UI.

Add a new component PortScannerForm.js which will take inputs for:

  • host to scan
  • lower range of ports
  • upper range of ports

This component should also have a button called SCAN. The scanning for open ports will start on clicking this button. Refer the image attached below for design

As of now, on clicking SCAN button, the values in the input fields should be displayed in console

P.S. : The basic frontend on react is available on feature/react branch in the folder network-scanner. Add your components in the same branch. Do not make any changes in App.js / index.js.

image

[BUG] Syntax error

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to after running python src/scanner.py
  2. Click on '....'
  3. Scroll down to '....'
  4. See error It will show error on line number 22(Syntax error)
    Screenshot (52)

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

[Feature] DNS Record Viewer

For a given hostname, fetch all the available DNS Records given below:

Record type Record contains
'A' IPv4 addresses (default)
'AAAA' IPv6 addresses
'ANY' any records
'CNAME' canonical name records
'MX' mail exchange records
'NAPTR' name authority pointer records
'NS' name server records
'PTR' pointer records
'SOA' start of authority records
'SRV' service records
'TXT' text records

Additional task: Explain briefly about all the records in UI.

The low & high range of ports in scanner.py is hardcoded

Reading config.json and using range.low and range.high in scanner.py


The range for ports shouldn't be hardcoded. It should be ideally fetched from config.json as it's being used in server/index.js.

for port in range(1,8888):  
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex((remoteServerIP, port))
        if result == 0:
            print "Port {}: 	 Open".format(port)
        sock.close()

[BUG] Duplicate generated ports causing infinite loop

Describe the bug

The random ports generated in /server/utils/randomNum.js will have to pass duplicate port numbers to /server/index.js when high - low < countofPorts. This renders index.js file to enter infinite loop.

To Reproduce

Steps to reproduce the behavior:

  1. Go to /
  2. Edit config.json for range.high-range.low < count .
  3. Open terminal and run npm start
  4. See error (infinite loop)

Expected behavior

If the provided range is less than countofPorts, show error and display a message.

[Feature] Include ipscanner feature in python3 .

The master branch of the repository is maintained for python2 whereas the feature/python3.8 branch is maintained for python3.

The 'ipscanner' feature in master ( src/ipscanner.py ) is compatible with python2, write the corresponding python3 code for 'ipscanner' and create a PR in feature/python3.8 branch.

[BUG] raw_input is not compatible in python 3

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

[BUG] scanner.py config.json file path error in python 3

Describe the bug
In feature/python3.8 the scanner.py config.json location is giving error.
To Reproduce
Steps to reproduce the behavior:

  1. Go to 'feature/python3.8' in '/src/single/' folder
  2. Run the scanner.py

Expected behavior
It should give the open ports. But it gives error 'file not found'

[Frontend] Responsive Navbar

Responsive navbar required for the current UI/UX for the project.

Make the required changes in the src/templates/index.html and src/static/index.css to add responsiveness in the navbar. In mobile view, navbar should toggle on button click and vary it's size according to screen size in desktop as well as mobile view.

[New Feature][Network Scanner] Add a feature for scanning IPs

Feature to be added: IP scanner ๐Ÿ”

Used for scanning the networks that are connected to several computers.

Follow the similar code structure and add a new file (ipScanner.py) in the root directory.

To make you understand why're we doing this:

image

Image Source

DISCLAIMER: This should be solely done for the learning purpose.

Feel free to post your thoughts here.

[Feature] Multithreading feature in python3 for corresponding python2 files

The master branch is maintained for python2 whereas the feature/python3.8 branch is maintained for python3. Multithreading feature is available in python2 as of now.

The multithreading feature has been used in the project to improve efficiency of the scanning process. Checkout 'Need for Multithreading' section in README.md for better understanding.

Create a PR in feature/python3.8 branch for the multithreading feature in python3.

The file correspondence in python2 - python3(master - feature/python3.8) can be understood as follows:

  1. src/single/scanner.py - scanner.py ( Port scanning feature without multithreading )
  2. src/multi/scanner_thread.py - (to be written in py3) Split processing function for multithreading.
  3. src/mainScanner.py - (to be written in py3) Port Scanning feature using multithreading.
  4. src/ipscanner - (to be written in py3) IP Scanning feature using multithreading.

Follow the same directory structure as in master.

[GH Pages] Too slow to load

PortScanner is taking much timemore than expected to load. There might be issue with my network but it's better to run an audit against it.

My assumption is the network calls to fetch external badges/emojis/images is consuming more time and making the page slower to load. Any workaround for the same?

add GitHub action to request review of PR

Is your feature request related to a problem? Please describe.
please add a GitHub action to request review of PR from maintainers

Describe the solution you'd like
we can set up GitHub action bot which will request review of PR from maintainers when a PR is created

[Frontend Feature] Add GUI for IPScanner

Currently this application has GUI for Portscanner only. Add GUI for IPScanner for increased functionality.

Must have:

An option(IPScanner) added in the navbar
Input box to enter IP address
CTA(Button) to start scanning
List of IPs (once the scanning is done)

Good to have:

A live timer to show the total scanning time
Some kind of indication (animation) in UI while scanning is happening in the background
Resume/Pause/Restart scanning options

Please go through the current UI once and do accordingly.

[Frontend] Add GUI with input fields for range + CTAs for scanning network

Currently this is a CLI based application, convert this into a GUI application to make the UX better!

  • Must have:

    • A window with menus (IP Scanning/Port Scanning)
    • Input box to enter host
    • Input fields to enter low & high range of ports
    • CTA(Button) to start scanning
    • List of Ports/IPs (once the scanning is done)
  • Good to have:

    • A live timer to show the total scanning time
    • Some kind of indication (animation) in UI while scanning is happening in the background
    • Resume/Pause/Restart scanning options
  • Extended feature

    • UI option to convert a host into its IP address
    • Display history: Last five scans in the following tabular form
Date & Time Host IP Address Total Scanning time
9:00 PM June 8, 2020 localhost 127.0.0.1 24 seconds

Recommended to use PyQt5 | Learn more here.

PS: Still open for discussions - feel free to suggest GUI frameworks(preferably from Python).

clear in supported in many terminal

Describe the bug
the command clear is not supporting on many terminal but cls can support on almost every terminal

Error
image

Should be like this
image

Expected behavior
image

[Design] UI Revamp 1.0

As we've built many features to justify the one-liner description of this project i.e. a go-to networking tool, now it's time to revamp the existing UI. Please refer #12 for further information as feature-wise.

Suggested tool: Figma

Screenshots of current UI:


Share your suggestions here before starting your design work!
Please let us know if you need more context.

Thanks:)
๐Ÿค—

[DESIGN] Logo required

A logo has a significant impact on a project's public perception. Logo grabs attention and makes a strong first impression and a foundation of the brand/project identity.

Since this project has no logo, design a good, formal, attractive and elegant logo for this project that stands for our objective and relates to the project identity. i.e. a go-to networking tool for scanning the networks.

  • Export in all formats with different standard dimensions.

    • PNG
    • SVG
    • JPG
  • Design favicon for the same.

  • Update the raw formats to the assets/raw folder.

Please discuss here before submitting a PR. Share your design idea here you've got one for the logo.

[BACKEND/FEATURE REQUEST] Detection and protection from malicious content - Imp hash.

Hostile, intrusive, and intentionally nasty, malware seeks to invade, damage, or disable computers, computer systems, networks, tablets, and mobile devices. Malware detection and prevention is one of the most concerned features of endpoint security.

One possible way of pulling off this feature is using imphash. Imp Hash can be used for signature based Malware detection in drives.

What is Imp Hash?
The Import Hash (ImpHash) is a hash over the imported functions by PE file. It is often used in malware analysis to identify malware binaries that belong to the same family.

Relevant links and resources:

What is expected?
This feature request should follow up a basic idea of scanning through the drives of a host system to detect the presence of any malicious content.

  • Python based code for scanning drives and paths entered by the user.
  • Paths entered can be taken as an input text file.
  • Output displayed should be a list of files identified as malicious content.

NOTE:
Additionally, the next stage of this feature could supposedly be on prevention or removal of these malicious content from the host. Content Disarming and Reconstruction(CRD) is one possible direction of this future work.

After jan2020 python2 is suspended

Describe the bug
The code base need to be shifted to python3

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'System with python3 support and configured path with python 3'
    2.Go to folder 'src'
  2. Scroll down to 'main ip scanne.py file'
  3. Run python the filename
  4. See the error for print statements

Expected behavior
successful run for python3

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Any with python
  • Version python3

Additional context
after jan 2020 python2 support officially ended

Documentation error

There is a minute error in documentation. Step 5 in How to run(UI) section says the following command python mainScanner.py where it should be python src/mainScanner.py

Error on running the Flask UI with Python 3

While working with Python 3 (version 3.9.1 on my local machine) and checking out to feature/python3.8 branch the following error occurs when trying to run the Flask UI:

File "/path/to/PortScanner/src/mainScanner.py", line 10, in <module>
    from multi.scanner_thread import split_processing
ImportError: bad magic number in 'multi': b'\x03\xf3\r\n'

I am assuming this is caused due to using more recent Python 3 version than the one specified in README.md.

Mentioning @Kashish121 as stated by @vinitshahdeo.

Originally this issue was discussed here.

Welcome to HackinCodes

๐Ÿ‘‹ Hello,

Thanks for showing your interest in HackinCodes.
Super glad to know that you're interested in contributing to Port Scanner project.

Introducing mentors below:

Name ๐ŸŽ–๏ธ Social Media ๐Ÿ‘‹ GitHub :octocat: Domain
Vinit Shahdeo ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@vinitshahdeo Full stack + Documentation
Kashish ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@Kashish121 Backend (Django)
Ishika Dubey ๐Ÿฆ Twitter
๐ŸŽ“ LinkedIn
@ishika1727 UI/UX

This thread is dedicated for open discussions. Feel free to ask your doubts here.

Before we start, I highly recommend all of you to go through the following medium articles:

Kindly note that the coding period starts from 16th August. The least you should know to contribute is basic understanding of git. We will be opening many issues pretty soon.

Keep watching this repo. ๐Ÿ‘๏ธ

๐Ÿค—

Regards,
Vinit ShahdeoProject Admin

Open Source Love

Timer Component in React

As we've built many features to justify the one-liner description of this project i.e. a go-to networking tool, now it's time to revamp the existing UI.

Add a new component Timer.js which will be enabled once the user starts scanning( scan button is clicked). Refer the image attached below for design.

As of now, create a button Timer in the Timer.js component along with the timer. The timer should start when Timer button is clicked

P.S. : The basic frontend on react is available on feature/react branch in the folder network-scanner. Add your components in the same branch. Do not make any changes in App.js / index.js.

image

[BACKEND/FEATURE REQUEST] Moving the backend from flask to Django.

The project currently stands on Python + Flask tech stack. Now it's time to move the tech stack to Python + Django.

The file mainScanner.py renders the output of the working code in frontend through flask. Replace this file to a new file which works for the current scanning processes and renders the output through Django.

Relevant links for this update: Django , develop branch, feature/python2.7 branch, feature/python3.8 branch, master branch.

Checkout feature/python2.7 and feature/python3.8 branches for the corresponding python versions of the project.
NOTE: The master branch is maintained for python2.

[Documentation]Update working of the project in docs

Analyze the working of the project and update the documentation in docs/Documentation.docx and docs/documentation.md.

Create a PR in feature/documentation branch.

PS: Checkout README.md for further details.

Add FAQs for GSSoC

As this project is shortlisted to accept contributions under GSSoC, it'll be a great idea to include a dedicated FAQ section for GSSoC in README.md

  • Check out the project here.
  • Check this for more info.

Refer to the FAQ section for GSSoC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.