Webklex / romb

MIT License
7 stars 1 forks source link

ROMB - Rust bomb

Sounds more dramatic than it is...

How I tried to learn rust in 6 days

Prolog

I'm usually creating web apps with php, js, go or python. I've played around with C, C++ and C# but never used them in a bigger project.

So why rust? I've heard a lot of people talk about it. It's supposed to be pretty fast and provides some additional features which, regarding app security, are great as well. At the end d0nutptr motivated me to participate in his giveaway/challenge.

Scope & Description

I recently thought about what would happen if you try to race against a firewall / IDS; Are they fast enough, or could you "squeeze" in a bunch of request before the client gets blocked? Basically a one-shot port scan.

This application will scan a port range of a given target simultaneously, in an attempt to race against a firewall IDS. The result can be saved or printed as csv, json or xml.

The application should:

Nice to have:

Result & Conclusion

Well the time has come to an end. I had a lot of plans and even though I failed to realize all of them, I'm still a bit proud of having realized at least the core feature (port check). This might not sound like much but for my first steps at rust, I'm pretty happy with it :)

The exports and udp / response filtering support is still missing, the code isn't cleaned up and the Options are never used. Oh and you can't spawn more than ~16337 threads - I still haven't figured out why that's the case.

I spend the most time trying to understand how Response works and how to handle errors. I'm still not fully sure, but I feel comfortable to play around with them some more. Rust definitely isn't like any other language I've played around with. It is extremely strict, has a unique logic and app "life cycle".

Have I failed my quest? Yes and no, the application isn't finished but my second goal, to learn some rust was a success!

I tried to document my journey and took some notes along the way. Those are all listed below under Timeline.

Timeline

1. Development / IDE setup

2. Created a new rust project inside the IDE

3. Build the application

struct Scanner { handles: Vec<JoinHandle<()>>, barrier: Arc,

target: String, start_port: u16, max_port: u16, timeout: Duration }

- The Scanner struct now need to have some methods
    - Searching for "rust struct methods"
        - https://doc.rust-lang.org/book/ch05-03-method-syntax.html
        - `impl StructName` is the magic syntax
    - Turns out you have to use `&mut self` instead of `self` if the method "mutates?" / updates an attribute
    - `pub(crate)` in front of a function makes it accessible outside the file
- The scanner might need some options, so I added a new struct called `Options` and added it to the Scanner
```rust
struct Options {
    pub response: bool, // Check if the connection returns any bytes
    pub udp: bool,      // use udp
    pub tcp: bool       // use tcp
}