mirror of
https://github.com/bee-san/RustScan.git
synced 2026-11-07 17:02:04 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8aa9a44949 | ||
|
|
416602dd02 | ||
|
|
a2e7125e03 | ||
|
|
10acad243c | ||
|
|
5d69339cc7 | ||
|
|
d8fd12694c | ||
|
|
7d4084d06c | ||
|
|
365be75689 | ||
|
|
5ea316c5db | ||
|
|
b363529045 | ||
|
|
ed378f7fc8 | ||
|
|
aa3c591016 | ||
|
|
ef893fdcb8 | ||
|
|
b78a8ad0af | ||
|
|
7ad7e34abc | ||
|
|
e41393b4ad | ||
|
|
6d72037974 | ||
|
|
66486b2467 | ||
|
|
4b085d97f2 | ||
|
|
4785b75f9f | ||
|
|
3951c25dff | ||
|
|
071c437206 | ||
|
|
7d351f2025 | ||
|
|
8ce14c5690 | ||
|
|
6cf71a1529 | ||
|
|
50c74d63cf | ||
|
|
c1f9be150f | ||
|
|
0a13100185 | ||
|
|
b67aa40eae | ||
|
|
fb3c7c4ce2 | ||
|
|
4d4ef5ac51 | ||
|
|
022cc8725a | ||
|
|
e12a12fd04 | ||
|
|
999634cf9b | ||
|
|
c45f4d1b86 | ||
|
|
3f4c0c32cc | ||
|
|
a3a4cf9587 | ||
|
|
e17ec84867 | ||
|
|
0fbdda51d2 | ||
|
|
4de017250d | ||
|
|
08cbf08beb | ||
|
|
e5c51c3980 | ||
|
|
757653a30b | ||
|
|
c5d02c31f1 | ||
|
|
6906177ec2 | ||
|
|
276e0d193c | ||
|
|
965d3d780c | ||
|
|
67d34b5036 |
No files matched your search
@@ -56,6 +56,16 @@
|
||||
"contributions": [
|
||||
"bug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "imlonghao",
|
||||
"name": "imlonghao",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/4951333?v=4",
|
||||
"profile": "https://imlonghao.com",
|
||||
"contributions": [
|
||||
"bug",
|
||||
"maintenance"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
todo:
|
||||
keyword: "TODO"
|
||||
keyword: "// TODO"
|
||||
@@ -30,3 +30,19 @@ jobs:
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- run: rustup component add rustfmt
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
Generated
+175
-2
@@ -1,5 +1,14 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
@@ -162,6 +171,19 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "2.2.1"
|
||||
@@ -284,6 +306,15 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.15"
|
||||
@@ -293,6 +324,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
|
||||
dependencies = [
|
||||
"quick-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.42"
|
||||
@@ -392,6 +432,32 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn-mid",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.16"
|
||||
@@ -413,6 +479,12 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
@@ -428,6 +500,24 @@ version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
|
||||
|
||||
[[package]]
|
||||
name = "rlimit"
|
||||
version = "0.3.0"
|
||||
@@ -440,13 +530,16 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustscan"
|
||||
version = "1.2.0"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"clap",
|
||||
"colored",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"log",
|
||||
"rlimit",
|
||||
"shell-words",
|
||||
"structopt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -455,6 +548,12 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
|
||||
|
||||
[[package]]
|
||||
name = "shell-words"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6fa3938c99da4914afedd13bf3d79bcb6c277d1b2c398d23257a304d9e1b074"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.2"
|
||||
@@ -500,6 +599,30 @@ version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de2f5e239ee807089b62adce73e48c625e0ed80df02c7ab3f068f5db5281065c"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
"structopt-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "510413f9de616762a4fbeab62509bf15c729603b72d7cd71280fbca431b1c118"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.35"
|
||||
@@ -511,6 +634,26 @@ dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn-mid"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
@@ -520,6 +663,21 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
@@ -538,6 +696,12 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
|
||||
[[package]]
|
||||
name = "waker-fn"
|
||||
version = "1.0.0"
|
||||
@@ -645,6 +809,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
||||
+6
-3
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rustscan"
|
||||
version = "1.2.0"
|
||||
version = "1.4.0"
|
||||
authors = ["Bee <[email protected]>"]
|
||||
edition = "2018"
|
||||
description = "Faster Nmap Scanning with Rust"
|
||||
@@ -15,11 +15,14 @@ readme="README.md"
|
||||
|
||||
[dependencies]
|
||||
colored = "1.9.3"
|
||||
clap = "2.33.0"
|
||||
structopt = "0.3.15"
|
||||
async-std = "1.6.2"
|
||||
futures = "0.3"
|
||||
rlimit = "0.3.0"
|
||||
shell-words = "1.0.0"
|
||||
log = "0.4.0"
|
||||
env_logger = "0.7.1"
|
||||
|
||||
[package.metadata.deb]
|
||||
depends = "$auto, nmap"
|
||||
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
<p align="center">
|
||||
<img src="pictures/rustscan.png"><br>
|
||||
<u><b> Turns a 17 minutes Nmap scan into 19 seconds. </b></u><br> Find all open ports <b>fast</b> with Rustscan, automatically pipe them into Nmap.
|
||||
➡️
|
||||
<a href="https://discord.gg/r38pna">Discord</a> |
|
||||
<a href="https://github.com/RustScan/RustScan#-full-installation-guide">Installation Guide</a> |
|
||||
<a href="https://github.com/RustScan/RustScan#-usage">Usage Guide</a>
|
||||
⬅️
|
||||
<br>
|
||||
<img src="pictures/rustscan.png">
|
||||
</p>
|
||||
<p align="center">
|
||||
<u><b> Turns a 17 minutes Nmap scan into 19 seconds. </b></u><br> Find all open ports <b>fast</b> with RustScan, automatically pipe them into Nmap.
|
||||
</p>
|
||||
<p align="center">
|
||||
<img alt="AUR version" src="https://img.shields.io/aur/version/rustscan-bin">
|
||||
<img src="https://img.shields.io/badge/Built%20with-Rust-Purple">
|
||||
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/w/brandonskerritt/rustscan">
|
||||
<img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/rustscan/rustscan/total?label=GitHub%20Downloads">
|
||||
<img alt="Crates.io" src="https://img.shields.io/crates/d/rustscan?label=Cargo%20Downloads">
|
||||
<img alt="Discord" src="https://img.shields.io/discord/736614461313515576">
|
||||
<img alt="Actions" src="https://github.com/RustScan/RustScan/workflows/Continuous%20integration/badge.svg?branch=master">
|
||||
</p>
|
||||
<hr>
|
||||
|
||||
@@ -13,7 +25,7 @@
|
||||
| <p align="center"><a href="https://crates.io/crates/rustscan">🔧 Cargo (Universal) </a></p> | <p align="center"><a href="https://crates.io/crates/rust_scan"> Arch </a></p> | <p align="center"><a href="https://crates.io/crates/rust_scan"> HomeBrew </a></p> | <p align="center"><a href="https://crates.io/crates/rust_scan"> Kali / Debian </p> |
|
||||
| ---- | ---- | ---- | --- |
|
||||
| <p align="center"><img src="pictures/rust.png" /></p> | <p align="center"><img src="pictures/arch.png" /></p> | <p align="center"><img src="pictures/apple.png" /></p> | <p align="center"><img src="pictures/kali.png" /></p> |
|
||||
| `cargo install rustscan` | `yay -S rustscan-bin` | `brew tap brandonskerritt/rustscan && brew install rustscan` | [Read the install guide](https://github.com/brandonskerritt/RustScan/blob/master/README.md#%EF%B8%8F-debian--kali) |
|
||||
| `cargo install rustscan` | `yay -S rustscan` | `brew tap brandonskerritt/rustscan && brew install rustscan` | [Read the install guide](https://github.com/brandonskerritt/RustScan/blob/master/README.md#%EF%B8%8F-debian--kali) |
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -50,6 +62,7 @@ RustScans **only** job is to reduce the friction between finding open ports and
|
||||
* Saves you time by automatically piping it into Nmap. No more manual copying and pasting!
|
||||
* Does one thing and does it well. **Only** purpose is to improve Nmap, not replace it!
|
||||
* Let's you choose what Nmap commands to run, or uses the default.
|
||||
* IPv6 Support
|
||||
|
||||
# 🔭 Why RustScan?
|
||||
Why spend time running fast scans and manually copying the ports, or waiting for a 20 minute scan to finish when you can just do all 65k ports in less than a minute?
|
||||
@@ -96,8 +109,12 @@ Note: sometimes Rust doesn't add Cargo to the path. Please see [this issue](http
|
||||
## 🖥️ Debian / Kali
|
||||
|
||||
Download the .deb file from the releases page:
|
||||
|
||||
[https://github.com/brandonskerritt/RustScan/releases](https://github.com/brandonskerritt/RustScan/releases)
|
||||
Run the commpand `dpkg -i` on the file. Note: sometimes you can double click the file to achieve the same result.
|
||||
|
||||
Run the commpand `dpkg -i` on the file.
|
||||
|
||||
Note: sometimes you can double click the file to achieve the same result.
|
||||
|
||||
### 🥧 .deb file not working?
|
||||
The .deb file only works on AMD64 CPUs. If yours is different (such as a Raspberry Pi) or the .deb file doesn't work, it is easy to build the .deb file yourself.
|
||||
@@ -246,7 +263,7 @@ To run your own nmap commands, end the RustScan command with `-- -A` where `--`
|
||||
|
||||
RustScan automatically runs `nmap -vvv -p $PORTS $IP`. To make it run `-A`, execute the command `rustscan 127.0.0.1 -- -A`.
|
||||
|
||||
**Note**: due to how Nmap behaves, sometimes you cannot SIGINT ctrl+c to end the scan and it acts like it is running in the background, but printing to STD::OUT. There is nothing I can do about this, unless I create a TTY shell for the sole purpose of running Nmap. Sorry 😓 I'll try to fix in an upcoming release. If any Rust experts want to help, please do!
|
||||
If you want to run commands such as `--script (vuln and safe)`, you will need to enclose it in quotations like so `--script '"(vuln and safe) or default"'`.
|
||||
|
||||
## 🎯 Increasing speed / accuracy
|
||||
* Batch size
|
||||
@@ -270,7 +287,7 @@ Ciphey is an automated decryption tool using artifical intelligence & natural la
|
||||
[Check it out here!](https://github.com/ciphey/ciphey)
|
||||
## Contributors ✨
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
@@ -285,6 +302,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<td align="center"><a href="https://github.com/smackhack"><img src="https://avatars2.githubusercontent.com/u/48143394?v=4" width="100px;" alt=""/><br /><sub><b>smackhack</b></sub></a><br /><a href="#ideas-smackhack" title="Ideas, Planning, & Feedback">🤔</a> <a href="#example-smackhack" title="Examples">💡</a></td>
|
||||
<td align="center"><a href="http://bernardoamc.github.io/"><img src="https://avatars0.githubusercontent.com/u/428984?v=4" width="100px;" alt=""/><br /><sub><b>Bernardo Araujo</b></sub></a><br /><a href="https://github.com/brandonskerritt/RustScan/commits?author=bernardoamc" title="Code">💻</a> <a href="https://github.com/brandonskerritt/RustScan/issues?q=author%3Abernardoamc" title="Bug reports">🐛</a> <a href="#design-bernardoamc" title="Design">🎨</a></td>
|
||||
<td align="center"><a href="https://github.com/Isona"><img src="https://avatars2.githubusercontent.com/u/11759523?v=4" width="100px;" alt=""/><br /><sub><b>Izzy Whistlecroft</b></sub></a><br /><a href="https://github.com/brandonskerritt/RustScan/issues?q=author%3AIsona" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://imlonghao.com"><img src="https://avatars1.githubusercontent.com/u/4951333?v=4" width="100px;" alt=""/><br /><sub><b>imlonghao</b></sub></a><br /><a href="https://github.com/brandonskerritt/RustScan/issues?q=author%3Aimlonghao" title="Bug reports">🐛</a> <a href="#maintenance-imlonghao" title="Maintenance">🚧</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
+29
-4
@@ -1,6 +1,31 @@
|
||||
This is my first Rust project! As such, I expect there are many, many bugs involved or things that can be sped up.
|
||||
Howdy Space Cow-Person 🤠🌌
|
||||
|
||||
If you're looking to get involved, we make use of Good First Issues / Help Wanted tags. Click this link to see all the issues we could use help with!
|
||||
[https://github.com/brandonskerritt/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22](https://github.com/brandonskerritt/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)
|
||||
RustScan is always looking for contributors. Whether that's spelling mistakes or major changes, your help is **wanted** and welcomed here.
|
||||
|
||||
Please leave issues / pull requests, I'd love to learn more about this amazing language :)
|
||||
Before contributing, read our [code of conduct](https://github.com/RustScan/RustScan/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
TL;DR if you abuse members of our community you will be **perma-banned** with no chance to get unbanned. No warnings either. 🤗
|
||||
|
||||
RustScan has 2 major labels for GitHub issues you should look at:
|
||||
* Good First issue
|
||||
These are issues for newcomers to open source!
|
||||
[https://github.com/RustScan/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22](https://github.com/RustScan/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
|
||||
* Help wanted
|
||||
These are issues that aren't really for newcomers, but we could still do wiht help!
|
||||
[https://github.com/RustScan/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+label%3A%22help+wanted%22](https://github.com/RustScan/RustScan/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+label%3A%22help+wanted%22)
|
||||
|
||||
If you want to, solve the issue or comment on the issue for help.
|
||||
|
||||
The flow for contributing to open source software is:
|
||||
* Fork the repo
|
||||
* Make changes
|
||||
* Pull request to the repo
|
||||
|
||||
And then comment on the issue that you've done.
|
||||
|
||||
RustScan also has some `// TODO`'s in the codebase, which are meant more for the core team but we wouldn't say no to help with these issues.
|
||||
|
||||
If you have any feature suggestions or bugs, leave a GitHub issue. We welcome any and all support :D
|
||||
|
||||
## Rewarding you
|
||||
I cannot pay you :-( But, I can place your GitHub profile on the README under `#Contributors` as a thank you! :)
|
||||
@@ -0,0 +1,72 @@
|
||||
Rust room
|
||||
|
||||
# what is rust?
|
||||
* speed
|
||||
* saftey
|
||||
* cargo (pip but for rust)
|
||||
* Links to the rust book (the documentation for rust is literally an ebook)
|
||||
|
||||
# Toolings
|
||||
|
||||
|
||||
# Introduction
|
||||
* if statements
|
||||
* functions
|
||||
* variables
|
||||
* loops
|
||||
|
||||
Some basic questions like "how would u make variable x, how would u make a function named x" and so on
|
||||
|
||||
# Expressions
|
||||
* rust return statements (they're super weird)
|
||||
* What is an expression?
|
||||
|
||||
# Results object
|
||||
If something can fail in Rust, you **HAVE** to deal with the exception.
|
||||
|
||||
FOr example
|
||||
|
||||
```python3
|
||||
# python
|
||||
f = open("file.txt", 'r')
|
||||
```
|
||||
|
||||
But in Rust, you **cannot** open a file unless you write an exception for if that file does not exist.
|
||||
|
||||
In Rust, everything that can fail returns a <return> object. This means that you're never going to encounter an unexpected "file not found" or similar, because everything is accounted for.
|
||||
|
||||
# Borrow checker
|
||||
Variables not in scope are killed. In Python, I think you can do:
|
||||
|
||||
```
|
||||
if y = 6:
|
||||
x = 3
|
||||
else:
|
||||
x = 9
|
||||
```
|
||||
|
||||
But in Rust, the borrow checker will kill X the second the if is over. You cannot create variables inside a scope and use them out fo the scope.
|
||||
|
||||
You can however, do this
|
||||
|
||||
```
|
||||
let x = if y == 6 {3} else {9}
|
||||
```
|
||||
|
||||
This is a security feature, the borrow checker stops you from doing silly things with variables -- everything is either in scope or it's killed off.
|
||||
|
||||
# Multi-threading
|
||||
* Rayon
|
||||
* Turning a for loop into multi-threaded with one word (into_iter -> into_para_iter)
|
||||
# Async
|
||||
* Basic async 101
|
||||
* Making a web server with async rust and how rust ensures saftey with async
|
||||
|
||||
|
||||
# Packaging
|
||||
* Packaging your rust app
|
||||
* Okay not security related but it's really cool it's just 1 command `rust publish`
|
||||
|
||||
## TODO
|
||||
* Rust has an official discord (like, the one the Rust team uses to organise their codebase and create new features). I can ask them for their fave blueteam features of Rust :)
|
||||
* Ask if I'm allowed to include a link to the official discord of Rust. They only have like 2 help channels, the rest of the channels are for organising new features / work on the language itself. It's really cool to be able to see the language evole in Discord, rather than whatever C++ or Python uses (mailing lists I think)
|
||||
Binary file not shown.
+165
-129
@@ -1,195 +1,205 @@
|
||||
extern crate shell_words;
|
||||
|
||||
mod scanner;
|
||||
use scanner::Scanner;
|
||||
|
||||
use clap::{App, Arg, AppSettings};
|
||||
use colored::*;
|
||||
use std::time::Duration;
|
||||
use std::process::{exit, Command};
|
||||
use std::convert::TryInto;
|
||||
use futures::executor::block_on;
|
||||
use rlimit::Resource;
|
||||
use rlimit::{setrlimit, getrlimit};
|
||||
use rlimit::{getrlimit, setrlimit};
|
||||
use std::process::{exit, Command};
|
||||
use std::{net::IpAddr, time::Duration};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "rustscan", setting = structopt::clap::AppSettings::TrailingVarArg)]
|
||||
/// Fast Port Scanner built in Rust.
|
||||
/// WARNING Do not use this program against sensitive infrastructure since the
|
||||
/// specified server may not be able to handle this many socket connections at once.
|
||||
struct Opts {
|
||||
/// The IP address to scan
|
||||
ip: String,
|
||||
|
||||
///Quiet mode. Only output the ports. No Nmap. Useful for grep or outputting to a file.
|
||||
#[structopt(short, long)]
|
||||
quiet: bool,
|
||||
|
||||
/// The batch size for port scanning, it increases or slows the speed of
|
||||
/// scanning. Depends on the open file limit of your OS. If you do 65535
|
||||
/// it will do every port at the same time. Although, your OS may not
|
||||
/// support this.
|
||||
#[structopt(short, long, default_value = "4500")]
|
||||
batch_size: u64,
|
||||
|
||||
/// The timeout in milliseconds before a port is assumed to be closed.
|
||||
#[structopt(short, long, default_value = "1500")]
|
||||
timeout: u64,
|
||||
|
||||
/// Automatically ups the ULIMIT with the value you provided.
|
||||
#[structopt(short, long)]
|
||||
ulimit: Option<u64>,
|
||||
|
||||
/// IPv6 mode.
|
||||
#[structopt(short, long)]
|
||||
ipv6: bool,
|
||||
|
||||
/// The Nmap arguments to run.
|
||||
/// To use the argument -A, end RustScan's args with '-- -A'.
|
||||
/// Example: 'rustscan -T 1500 127.0.0.1 -- -A -sC'.
|
||||
/// This command adds -Pn -vvv -p $PORTS automatically to nmap.
|
||||
/// For things like --script '(safe and vuln)' enclose it in quotations marks \"'(safe and vuln)'\"")
|
||||
command: Vec<String>,
|
||||
}
|
||||
|
||||
/// Faster Nmap scanning with Rust
|
||||
/// If you're looking for the actual scanning, check out the module Scanner.
|
||||
fn main() {
|
||||
let matches = App::new("RustScan")
|
||||
.author("Bee https://github.com/brandonskerritt")
|
||||
.about("Fast Port Scanner built in Rust\nWARNING Do not use this program against sensitive infrastructure. The specified server may not be able to handle this many socket connections at once.")
|
||||
.version("1.2.0")
|
||||
.setting(AppSettings::TrailingVarArg)
|
||||
// logger
|
||||
env_logger::init();
|
||||
|
||||
// IP address is a required argument
|
||||
.arg(Arg::with_name("ip")
|
||||
.required(true)
|
||||
.index(1)
|
||||
.long("ip-address")
|
||||
.help("The IP address to scan"))
|
||||
.arg(Arg::with_name("b")
|
||||
.short("b")
|
||||
.long("batch")
|
||||
.takes_value(true)
|
||||
.default_value("4500")
|
||||
.help("Increases speed of scanning. The batch size for port scanning. Depends on your open file limit of OS. If you do 65535 it will do every port at the same time. Although, your OS may not support this."))
|
||||
.arg(Arg::with_name("T")
|
||||
.short("T")
|
||||
.long("timeout")
|
||||
.takes_value(true)
|
||||
.default_value("1500")
|
||||
.help("The timeout before a port is assumed to be close. In MS."))
|
||||
.arg(Arg::with_name("q")
|
||||
.short("-q")
|
||||
.long("quiet")
|
||||
.takes_value(false)
|
||||
.help("Quiet mode. Only output the ports. No Nmap. Useful for grep or outputting to a file."))
|
||||
.arg(Arg::with_name("u")
|
||||
.short("u")
|
||||
.long("ulimit")
|
||||
.help("Automatically ups the ULIMIT with the value you provided.")
|
||||
.takes_value(true))
|
||||
.arg(
|
||||
Arg::with_name("command")
|
||||
.help("The Nmap arguments to run. To use the argument -A, end RustScan's args with '-- -A'. To run EXAMPLE: 'rustscan -T 1500 127.0.0.1 -- -A -sC'. This argument auto runs nmap {your commands} -vvv -p $PORTS ")
|
||||
.takes_value(true)
|
||||
.multiple(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
||||
let ip = matches.value_of("ip").unwrap_or("None");
|
||||
let ulimit_arg = matches.value_of("u").unwrap_or("None");
|
||||
let quiet = if matches.is_present("q") { true } else { false };
|
||||
let command_matches= matches.values_of("command");
|
||||
let command_run: String = match command_matches {
|
||||
// We use the user supplied args
|
||||
Some(_x) => {
|
||||
// TODO x is the same as below, use that instead
|
||||
matches.values_of("command").unwrap().collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
// we default
|
||||
None => "-A -vvv".to_string()
|
||||
info!("Starting up");
|
||||
let mut opts = Opts::from_args();
|
||||
info!("Mains() `opts` arguments are {:?}", opts);
|
||||
|
||||
let user_nmap_options = if opts.command.is_empty() {
|
||||
"-A -vvv".to_string()
|
||||
} else {
|
||||
opts.command.join(" ")
|
||||
};
|
||||
|
||||
let mut batch_size: u64 = matches
|
||||
.value_of("b")
|
||||
.unwrap_or("None")
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
|
||||
if !quiet {
|
||||
if !opts.quiet {
|
||||
print_opening();
|
||||
}
|
||||
|
||||
// checks ulimit
|
||||
// Updates ulimit when the argument is set
|
||||
|
||||
// change ulimit size
|
||||
if !(ulimit_arg == "None") {
|
||||
let limit = ulimit_arg.parse::<u64>().unwrap();
|
||||
if !quiet{
|
||||
println!("Automatically upping ulimit to {}", ulimit_arg);
|
||||
// Automatically ups the ulimit
|
||||
if opts.ulimit.is_some() {
|
||||
let limit = opts.ulimit.unwrap();
|
||||
info!("Automatically upping ulimit");
|
||||
|
||||
if !opts.quiet {
|
||||
println!("Automatically upping ulimit to {}", limit);
|
||||
}
|
||||
let uresult = setrlimit(Resource::NOFILE, limit, limit);
|
||||
|
||||
match uresult {
|
||||
match setrlimit(Resource::NOFILE, limit, limit) {
|
||||
Ok(_) => {}
|
||||
Err(_) => {println!("ERROR. Failed to set Ulimit.")}
|
||||
Err(_) => println!("ERROR. Failed to set Ulimit."),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let (x, _) = getrlimit(Resource::NOFILE).unwrap();
|
||||
|
||||
// if maximum limit is lower than batch size
|
||||
// automatically re-adjust the batch size
|
||||
if x < batch_size.into() {
|
||||
if !quiet{
|
||||
if x < opts.batch_size {
|
||||
if !opts.quiet {
|
||||
println!("{}", "WARNING: Your file description limit is lower than selected batch size. Please considering upping this (how to is on the README). NOTE: this may be dangerous and may cause harm to sensitive servers. Automatically reducing Batch Size to match your limit, this process isn't harmful but reduces speed.".red());
|
||||
// TODO this is a joke please fix
|
||||
}
|
||||
|
||||
// if the OS supports high file limits like 8000
|
||||
// but the user selected a batch size higher than this
|
||||
// reduce to a lower number
|
||||
// basically, ubuntu is 8000
|
||||
// but i can only get it to work on < 5k in testing
|
||||
// 5k is default, so 3000 seems safe
|
||||
if x > 8000{
|
||||
batch_size = 3000
|
||||
}
|
||||
else {
|
||||
let ten: u64 = 100;
|
||||
batch_size = x - ten;
|
||||
}
|
||||
// if the OS supports high file limits like 8000
|
||||
// but the user selected a batch size higher than this
|
||||
// reduce to a lower number
|
||||
// basically, ubuntu is 8000
|
||||
// but i can only get it to work on < 5k in testing
|
||||
// 5k is default, so 3000 seems safe
|
||||
if x > 8000 {
|
||||
opts.batch_size = 3000
|
||||
} else {
|
||||
opts.batch_size = x - 100u64
|
||||
}
|
||||
}
|
||||
// else if the ulimit is higher than batch size
|
||||
// tell the user they can increase batch size
|
||||
// if the user set ulimit arg they probably know what they are doing so don't print this
|
||||
else if x + 2 > batch_size.into() && (ulimit_arg == "None"){
|
||||
if !quiet{
|
||||
// TODO this is a joke please fix
|
||||
let one: u64 = 1;
|
||||
println!("Your file description limit is higher than the batch size. You can potentially increase the speed by increasing the batch size, but this may cause harm to sensitive servers. Your limit is {}, try batch size {}.", x, x - one);
|
||||
else if x + 2 > opts.batch_size.into() && (opts.ulimit.is_none()) {
|
||||
if !opts.quiet {
|
||||
println!(
|
||||
"Your file description limit is higher than the batch size. You can potentially increase the speed by increasing the batch size, but this may cause harm to sensitive servers. Your limit is {}, try batch size {}.",
|
||||
x,
|
||||
x - 1u64
|
||||
);
|
||||
}
|
||||
}
|
||||
// the user has asked to automatically up the ulimit
|
||||
|
||||
// gets timeout
|
||||
let duration_timeout =
|
||||
matches
|
||||
.value_of("T")
|
||||
.unwrap_or("None")
|
||||
.parse::<u64>()
|
||||
.unwrap();
|
||||
let addr = match opts.ip.parse::<IpAddr>() {
|
||||
Ok(res) => res,
|
||||
Err(_) => panic!("Could not parse IP Address"),
|
||||
};
|
||||
|
||||
// 65535 + 1 because of 0 indexing
|
||||
let scanner = Scanner::new(ip, 1, 65536, batch_size.try_into().unwrap(), Duration::from_millis(duration_timeout), quiet);
|
||||
let scanner = Scanner::new(
|
||||
addr,
|
||||
1,
|
||||
65535,
|
||||
opts.batch_size.into(),
|
||||
Duration::from_millis(opts.timeout.into()),
|
||||
opts.quiet,
|
||||
);
|
||||
let scan_result = block_on(scanner.run());
|
||||
|
||||
// prints ports and places them into nmap string
|
||||
let nmap_str_ports: Vec<String> = scan_result.into_iter().map(|port| port.to_string()).collect();
|
||||
let nmap_str_ports: Vec<String> = scan_result
|
||||
.into_iter()
|
||||
.map(|port| port.to_string())
|
||||
.collect();
|
||||
|
||||
// if no ports are found, suggest running with less
|
||||
if nmap_str_ports.is_empty() {
|
||||
panic!("{} Looks like I didn't find any open ports. This is usually caused by a high batch size.
|
||||
\n*I used {} threads, consider lowering to {} with {} or a comfortable number lfor your system.
|
||||
\n Alternatively, increase the timeout if your ping is high. Rustscan -T 2000 for 2000 second timeout.", "ERROR".red(), batch_size, (batch_size / 2).to_string().green(), "'rustscan -b <batch_size> <ip address>'".green());
|
||||
\n*I used {} batch size, consider lowering to {} with {} or a comfortable number for your system.
|
||||
\n Alternatively, increase the timeout if your ping is high. Rustscan -T 2000 for 2000 second timeout.", "ERROR".red(),
|
||||
opts.batch_size,
|
||||
(opts.batch_size / 2).to_string().green(),
|
||||
"'rustscan -b <batch_size> <ip address>'".green());
|
||||
}
|
||||
|
||||
// Tells the user we are now switching to Nmap
|
||||
if !quiet{
|
||||
println!(
|
||||
"{}",
|
||||
"Starting nmap.".blue(),
|
||||
);
|
||||
if !opts.quiet {
|
||||
println!("{}", "Starting nmap.".blue(),);
|
||||
}
|
||||
|
||||
// nmap port style is 80,443. Comma seperated with no spaces.
|
||||
let ports_str = nmap_str_ports.join(",");
|
||||
|
||||
// if quiet mode is on, return ports and exit
|
||||
if quiet{
|
||||
println!("{:?}", ports_str);
|
||||
if opts.quiet {
|
||||
println!("{}", ports_str);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let string_format = format!("{} {} {} {} {} {}", command_run, "-Pn", "-vvv", "-p", &ports_str, ip);
|
||||
if !quiet{
|
||||
println!("The Nmap command to be run is {}", string_format);
|
||||
let nmap_args = if !opts.ipv6 {
|
||||
format!(
|
||||
"{} {} {} {} {} {}",
|
||||
&user_nmap_options, "-vvv", "-Pn", "-p", &ports_str, opts.ip
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{} {} {} {} {} {} {}",
|
||||
&user_nmap_options, "-vvv", "-Pn", "-6", "-p", &ports_str, opts.ip
|
||||
)
|
||||
};
|
||||
|
||||
if !opts.quiet {
|
||||
println!("The Nmap command to be run is {}", &nmap_args);
|
||||
}
|
||||
let command_list = string_format.split_whitespace();
|
||||
let vec = command_list.collect::<Vec<&str>>();
|
||||
let nmap_args = shell_words::split(&nmap_args).expect("failed to parse nmap arguments");
|
||||
|
||||
// Runs the nmap command and spawns it as a process.
|
||||
let mut child = Command::new("nmap")
|
||||
.args(&vec)
|
||||
.args(&nmap_args)
|
||||
.spawn()
|
||||
.expect("failed to execute nmap process");
|
||||
|
||||
child.wait().expect("failed to wait on nmap process");
|
||||
}
|
||||
|
||||
/// Prints the opening title of RustScan
|
||||
fn print_opening() {
|
||||
info!("Printing opening");
|
||||
let s = "
|
||||
_____ _ _____
|
||||
| __ \\ | | / ____|
|
||||
@@ -198,10 +208,36 @@ fn print_opening() {
|
||||
| | \\ \\ |_| \\__ \\ |_ ____) | (_| (_| | | | |
|
||||
|_| \\_\\__,_|___/\\__|_____/ \\___\\__,_|_| |_|
|
||||
Faster nmap scanning with rust.";
|
||||
println!(
|
||||
"{} \n {} \n {}",
|
||||
s.green(),
|
||||
"Automated Decryption Tool - https://github.com/ciphey/ciphey".green(),
|
||||
"Creator https://github.com/brandonskerritt".green()
|
||||
);
|
||||
println!("{}\n", s.green());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Scanner;
|
||||
use async_std::task::block_on;
|
||||
use std::{net::IpAddr, time::Duration};
|
||||
|
||||
#[test]
|
||||
fn does_it_run() {
|
||||
// Makes sure te program still runs and doesn't panic
|
||||
let addr = match "127.0.0.1".parse::<IpAddr>() {
|
||||
Ok(res) => res,
|
||||
Err(_) => panic!("Could not parse IP Address"),
|
||||
};
|
||||
let scanner = Scanner::new(addr, 1, 65535, 1000, Duration::from_millis(10), true);
|
||||
let scan_result = block_on(scanner.run());
|
||||
// if the scan fails, it wouldn't be able to assert_eq! as it panicked!
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
fn does_it_run_ivp6() {
|
||||
// Makes sure te program still runs and doesn't panic
|
||||
let addr = match "::1".parse::<IpAddr>() {
|
||||
Ok(res) => res,
|
||||
Err(_) => panic!("Could not parse IP Address"),
|
||||
};
|
||||
let scanner = Scanner::new(addr, 1, 65535, 1000, Duration::from_millis(10), true);
|
||||
let scan_result = block_on(scanner.run());
|
||||
// if the scan fails, it wouldn't be able to assert_eq! as it panicked!
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
}
|
||||
+92
-42
@@ -1,38 +1,57 @@
|
||||
use async_std::io;
|
||||
use async_std::net::TcpStream;
|
||||
use async_std::prelude::*;
|
||||
use colored::*;
|
||||
use futures::stream::FuturesUnordered;
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
net::{SocketAddr, Shutdown},
|
||||
io::ErrorKind,
|
||||
net::{IpAddr, Shutdown, SocketAddr},
|
||||
};
|
||||
use async_std::prelude::*;
|
||||
use futures::stream::FuturesUnordered;
|
||||
|
||||
/// The class for the scanner
|
||||
/// Host is data type IpAddr and is the host address
|
||||
/// start & end is where the port scan starts and ends
|
||||
/// batch_size is how many ports at a time should be scanned
|
||||
/// Timeout is the time RustScan should wait before declaring a port closed. As datatype Duration.
|
||||
/// Quiet is whether or not RustScan should print things, or wait until the end to print only open ports.
|
||||
/// ipv6 is whether or not this scan is an ipv6 scan.
|
||||
pub struct Scanner {
|
||||
host: String,
|
||||
start: u64,
|
||||
end: u64,
|
||||
host: IpAddr,
|
||||
start: u16,
|
||||
end: u16,
|
||||
batch_size: u64,
|
||||
timeout: Duration,
|
||||
quiet: bool,
|
||||
}
|
||||
|
||||
impl Scanner {
|
||||
pub fn new(host: &str, start: u64, end: u64, batch_size: u64, timeout: Duration, quiet: bool) -> Self {
|
||||
pub fn new(
|
||||
host: IpAddr,
|
||||
start: u16,
|
||||
end: u16,
|
||||
batch_size: u64,
|
||||
timeout: Duration,
|
||||
quiet: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
host: host.to_owned(),
|
||||
start,
|
||||
end,
|
||||
batch_size,
|
||||
timeout,
|
||||
quiet
|
||||
quiet,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(&self) -> Vec<u64> {
|
||||
let ports: Vec<u64> = (self.start..self.end).collect();
|
||||
let mut open_ports: std::vec::Vec<u64> = Vec::new();
|
||||
/// Runs scan_range with chunk sizes
|
||||
/// If you want to run RustScan normally, this is the entry point used
|
||||
/// Returns all open ports as Vec<u16>
|
||||
pub async fn run(&self) -> Vec<u16> {
|
||||
let ports: Vec<u16> = (self.start..self.end).collect();
|
||||
let mut open_ports: std::vec::Vec<u16> = Vec::new();
|
||||
// TODO change this to port size
|
||||
// to fix bug when we introduce custom port ranges
|
||||
|
||||
for range in ports.chunks(self.batch_size as usize) {
|
||||
let mut ports = self.scan_range(range).await;
|
||||
@@ -42,14 +61,15 @@ impl Scanner {
|
||||
open_ports
|
||||
}
|
||||
|
||||
async fn scan_range(&self, range: &[u64]) -> Vec<u64> {
|
||||
/// Given a range of ports, scan them all.
|
||||
/// Returns a vector of open ports.
|
||||
async fn scan_range(&self, range: &[u16]) -> Vec<u16> {
|
||||
let mut ftrs = FuturesUnordered::new();
|
||||
|
||||
for port in range {
|
||||
ftrs.push(self.scan_port(port));
|
||||
ftrs.push(self.scan_port(*port));
|
||||
}
|
||||
|
||||
let mut open_ports: Vec<u64> = Vec::new();
|
||||
let mut open_ports: Vec<u16> = Vec::new();
|
||||
while let Some(result) = ftrs.next().await {
|
||||
match result {
|
||||
Ok(port) => open_ports.push(port),
|
||||
@@ -60,39 +80,69 @@ impl Scanner {
|
||||
open_ports
|
||||
}
|
||||
|
||||
async fn scan_port(&self, port: &u64) -> io::Result<u64> {
|
||||
let addr = format!("{}:{}", self.host , port);
|
||||
|
||||
match addr.parse() {
|
||||
Ok(sock_addr) => match self.connect(sock_addr).await {
|
||||
Ok(stream_result) => {
|
||||
match stream_result.shutdown(Shutdown::Both) {
|
||||
_ => {}
|
||||
}
|
||||
if !self.quiet {
|
||||
println!("Open {}", port.to_string().purple());
|
||||
}
|
||||
|
||||
Ok(*port)
|
||||
/// Given a port, scan it.
|
||||
/// Turns the address into a SocketAddr
|
||||
/// Deals with the <result> type
|
||||
/// If it experiences error ErrorKind::Other then too many files are open and it Panics!
|
||||
/// ese any other error, it returns the error in Result as a string
|
||||
/// If no errors occur, it returns the port number in Result to signify the port is open.
|
||||
/// This function mainly deals with the logic of Results handling.
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// self.scan_port(10:u16)
|
||||
/// ```
|
||||
/// Note: `self` must contain `self.host`.
|
||||
async fn scan_port(&self, port: u16) -> io::Result<u16> {
|
||||
let addr = SocketAddr::new(self.host, port);
|
||||
// println!("{:?}", addr);
|
||||
match self.connect(addr).await {
|
||||
Ok(x) => {
|
||||
// match stream_result.shutdown(Shutdown::Both)
|
||||
info!("Shutting down stream");
|
||||
match x.shutdown(Shutdown::Both) {
|
||||
_ => {}
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::Other => {
|
||||
eprintln!("{:?}", e); // in case we get too many open files
|
||||
panic!("Too many open files. Please reduce batch size. The default is 5000. Try -b 2500.");
|
||||
}
|
||||
_ => Err(io::Error::new(io::ErrorKind::Other, e.to_string())),
|
||||
},
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("Unable to convert to socket address {:?}", e);
|
||||
panic!("Unable to convert to socket address");
|
||||
if !self.quiet {
|
||||
println!("Open {}", port.to_string().purple());
|
||||
}
|
||||
// if connection successful
|
||||
// shut down stream
|
||||
// return port
|
||||
Ok(port)
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::Other => {
|
||||
panic!("Too many open files. Please reduce batch size. The default is 5000. Try -b 2500.");
|
||||
}
|
||||
_ => Err(io::Error::new(io::ErrorKind::Other, e.to_string())),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Performs the connection to the socket with timeout
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// let port: u16 = 80
|
||||
/// // Host is an IpAddr type
|
||||
/// let host = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
|
||||
/// let addr = SocketAddr::new(host, port)
|
||||
/// self.connect(addr)
|
||||
/// // returns Result which is either Ok(stream) for port is open, or Er for port is closed.
|
||||
/// // Timesout after self.timeouts seconds
|
||||
/// ```
|
||||
async fn connect(&self, addr: SocketAddr) -> io::Result<TcpStream> {
|
||||
let stream = io::timeout(self.timeout, async move { TcpStream::connect(addr).await }).await?;
|
||||
let stream =
|
||||
io::timeout(self.timeout, async move { TcpStream::connect(addr).await }).await?;
|
||||
info!("Returning okay from connect");
|
||||
Ok(stream)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn does_it_run() {
|
||||
// TODO run functions here
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user