Compare commits
5 Commits
0.0.3
...
09110a4546
Author | SHA1 | Date | |
---|---|---|---|
09110a4546 | |||
0b4bac96e7 | |||
aba478e00d | |||
39beb75a71 | |||
ae754241ce |
39
.drone.yml
Normal file
39
.drone.yml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: fetch_dependencies
|
||||||
|
image: rust
|
||||||
|
volumes:
|
||||||
|
- name: rust_registry
|
||||||
|
path: /usr/local/cargo/registry
|
||||||
|
commands:
|
||||||
|
- cargo fetch
|
||||||
|
|
||||||
|
- name: code_quality
|
||||||
|
image: rust
|
||||||
|
volumes:
|
||||||
|
- name: rust_registry
|
||||||
|
path: /usr/local/cargo/registry
|
||||||
|
depends_on:
|
||||||
|
- fetch_dependencies
|
||||||
|
commands:
|
||||||
|
- rustup component add clippy
|
||||||
|
- cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: rust
|
||||||
|
volumes:
|
||||||
|
- name: rust_registry
|
||||||
|
path: /usr/local/cargo/registry
|
||||||
|
depends_on:
|
||||||
|
- code_quality
|
||||||
|
commands:
|
||||||
|
- cargo test
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: rust_registry
|
||||||
|
temp: {}
|
||||||
|
|
866
Cargo.lock
generated
866
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hidden_server"
|
name = "hidden_server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.22"
|
log = "0.4.27"
|
||||||
env_logger = "0.11.5"
|
env_logger = "0.11.5"
|
||||||
actix-web = "4"
|
actix-web = "4.10.2"
|
||||||
rand = "0.9.0-alpha.2"
|
rand = "0.9.0-alpha.2"
|
||||||
clap = { version = "4.5.16", features = ["derive"] }
|
clap = { version = "4.5.35", features = ["derive"] }
|
||||||
|
4
renovate.json
Normal file
4
renovate.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": ["local>renovate/presets"]
|
||||||
|
}
|
||||||
|
|
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod restricted_port;
|
31
src/main.rs
31
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
use actix_web::middleware::Logger;
|
use actix_web::middleware::Logger;
|
||||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
use actix_web::{App, HttpResponse, HttpServer, web};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use hidden_server::restricted_port::is_restricted_port;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ struct Args {
|
|||||||
#[arg(short('M'), long, default_value_t = 1000)]
|
#[arg(short('M'), long, default_value_t = 1000)]
|
||||||
max_port: u16,
|
max_port: u16,
|
||||||
/// Host this server will listen to
|
/// Host this server will listen to
|
||||||
#[arg(short, long, default_value="0.0.0.0")]
|
#[arg(short, long, default_value = "0.0.0.0")]
|
||||||
listen_host: String,
|
listen_host: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +43,20 @@ async fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
log::info!("Choosing a random port to start...");
|
log::info!("Choosing a random port to start...");
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
let port: u16 = args.min_port + rng.random::<u16>() % (args.max_port - args.min_port);
|
let mut port: u16;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
port = args.min_port + rng.random::<u16>() % (args.max_port - args.min_port);
|
||||||
|
|
||||||
|
if !is_restricted_port(port) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
log::info!("I chose a restricted port, I have to choose another one...");
|
||||||
|
}
|
||||||
|
|
||||||
|
log::info!("Can now start server...");
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
@ -54,3 +67,13 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::Args;
|
||||||
|
#[test]
|
||||||
|
fn verify_cli() {
|
||||||
|
use clap::CommandFactory;
|
||||||
|
Args::command().debug_assert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
89
src/restricted_port.rs
Normal file
89
src/restricted_port.rs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// Source : https://chromium.googlesource.com/chromium/src.git/+/refs/heads/master/net/base/port_util.cc
|
||||||
|
|
||||||
|
const RESTRICTED_PORTS: [u16; 80] = [
|
||||||
|
1, // tcpmux
|
||||||
|
7, // echo
|
||||||
|
9, // discard
|
||||||
|
11, // systat
|
||||||
|
13, // daytime
|
||||||
|
15, // netstat
|
||||||
|
17, // qotd
|
||||||
|
19, // chargen
|
||||||
|
20, // ftp data
|
||||||
|
21, // ftp access
|
||||||
|
22, // ssh
|
||||||
|
23, // telnet
|
||||||
|
25, // smtp
|
||||||
|
37, // time
|
||||||
|
42, // name
|
||||||
|
43, // nicname
|
||||||
|
53, // domain
|
||||||
|
69, // tftp
|
||||||
|
77, // priv-rjs
|
||||||
|
79, // finger
|
||||||
|
87, // ttylink
|
||||||
|
95, // supdup
|
||||||
|
101, // hostriame
|
||||||
|
102, // iso-tsap
|
||||||
|
103, // gppitnp
|
||||||
|
104, // acr-nema
|
||||||
|
109, // pop2
|
||||||
|
110, // pop3
|
||||||
|
111, // sunrpc
|
||||||
|
113, // auth
|
||||||
|
115, // sftp
|
||||||
|
117, // uucp-path
|
||||||
|
119, // nntp
|
||||||
|
123, // NTP
|
||||||
|
135, // loc-srv /epmap
|
||||||
|
137, // netbios
|
||||||
|
139, // netbios
|
||||||
|
143, // imap2
|
||||||
|
161, // snmp
|
||||||
|
179, // BGP
|
||||||
|
389, // ldap
|
||||||
|
427, // SLP (Also used by Apple Filing Protocol)
|
||||||
|
465, // smtp+ssl
|
||||||
|
512, // print / exec
|
||||||
|
513, // login
|
||||||
|
514, // shell
|
||||||
|
515, // printer
|
||||||
|
526, // tempo
|
||||||
|
530, // courier
|
||||||
|
531, // chat
|
||||||
|
532, // netnews
|
||||||
|
540, // uucp
|
||||||
|
548, // AFP (Apple Filing Protocol)
|
||||||
|
554, // rtsp
|
||||||
|
556, // remotefs
|
||||||
|
563, // nntp+ssl
|
||||||
|
587, // smtp (rfc6409)
|
||||||
|
601, // syslog-conn (rfc3195)
|
||||||
|
636, // ldap+ssl
|
||||||
|
989, // ftps-data
|
||||||
|
990, // ftps
|
||||||
|
993, // ldap+ssl
|
||||||
|
995, // pop3+ssl
|
||||||
|
1719, // h323gatestat
|
||||||
|
1720, // h323hostcall
|
||||||
|
1723, // pptp
|
||||||
|
2049, // nfs
|
||||||
|
3659, // apple-sasl / PasswordServer
|
||||||
|
4045, // lockd
|
||||||
|
5060, // sip
|
||||||
|
5061, // sips
|
||||||
|
6000, // X11
|
||||||
|
6566, // sane-port
|
||||||
|
6665, // Alternate IRC [Apple addition]
|
||||||
|
6666, // Alternate IRC [Apple addition]
|
||||||
|
6667, // Standard IRC [Apple addition]
|
||||||
|
6668, // Alternate IRC [Apple addition]
|
||||||
|
6669, // Alternate IRC [Apple addition]
|
||||||
|
6697, // IRC + TLS
|
||||||
|
10080, // Amanda
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Check out wether a port is a restricted port for major browsers
|
||||||
|
pub fn is_restricted_port(port: u16) -> bool {
|
||||||
|
RESTRICTED_PORTS.contains(&port)
|
||||||
|
}
|
Reference in New Issue
Block a user