Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
noraj committed Mar 2, 2023
1 parent 52f44f4 commit d084f5f
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.cr]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: noraj
issuehunt: noraj
ko_fi: noraj
liberapay: noraj
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/lib/
/bin/miniss
/bin/miniss.o
/bin/miniss.dwarf
/.shards/
*.dwarf
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crystal 1.7.2
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# miniss

**miniss** (_mini ss_) displays a list of open listening sockets. It is a minimal alternative to `ss` or `netstat`.

The goal of **miniss** is not to reinvent the wheel but rather to offer a static binary that can be deployed by pentester or CTF players on containers or hardened environnement where the classical `ss` or `netstat` binaries have been removed.

## Installation

TODO: Write installation instructions here

## Usage

```
./miniss
```

## Features

- Information displayed:
- local address, remote address, state, username, uid
- Type of sockets:
- [x] TCP
- [ ] UDP
- IP version:
- [x] IPv4
- [ ] IPv6

## Author

- [noraj](https://pwn.by/noraj/) - creator and maintainer
1 change: 1 addition & 0 deletions bin/miniss.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "miniss/cli"
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[0.0.1]

- Early alpha release
23 changes: 23 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TODO:

- Code:
- Create a socket class for socket objects
- Refactor code between cli & lib
- IPv6 support
- Doc:
- https://crystal-lang.org/reference/1.7/syntax_and_semantics/documenting_code.html
- https://crystal-lang.org/reference/1.7/man/crystal/#crystal-docs
- https://github.com/GeopJr/vitepressify
- Lint:
- https://github.com/crystal-ameba/ameba
- Test:
- https://github.com/ysbaddaden/minitest.cr
- https://crystal-lang.org/api/1.7.2/Spec.html
- Optparse:
- https://github.com/chenkovsky/docopt.cr
- Color:
- https://crystal-lang.org/api/1.7.2/Colorize.html
- Shard registries:
- https://github.com/shardbox/catalog/blob/master/README.md
- Branding:
- Make a logo
20 changes: 20 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Compile:

https://github.com/crystal-lang/crystal/issues/9285#issuecomment-1445493032

```
crystal build src/miniss.cr --release --static -o bin/miniss
shards build --release --static
docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:1.7.2-alpine \
crystal build src/miniss.cr --release --static -o bin/miniss
docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:1.7.2-alpine \
shards build --release --static
$ llvm-config --host-target
$ docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:1.7.2-alpine \
crystal build src/miniss.cr --release --static -o bin/miniss --cross-compile --target x86_64-pc-linux-gnu
$ docker run --rm -it -v $PWD:/workspace -w /workspace crystallang/crystal:1.7.2-alpine \
cc bin/miniss.o -o bin/miniss -rdynamic -static -L/usr/bin/../lib/crystal -lpcre -lm -lgc -lpthread -levent -lrt -lpthread -ldl
```

7 changes: 7 additions & 0 deletions docs/creating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Contributing

1. Fork it (<https://github.com/your-github-user/miniss/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
2 changes: 2 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Development

23 changes: 23 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: miniss
version: 0.0.1
description: Displays a list of open listening sockets. It is a minimal alternative to ss or netstat.

authors:
- Alexandre ZANNI <alexandre.zanni@europe.com>

targets:
miniss:
main: src/cli.cr

executables:
- miniss

crystal: "~> 1.7.2"

license: MIT
documentation: https://github.com/noraj/miniss/tree/master/docs
homepage: https://github.com/noraj/miniss
repository: https://github.com/noraj/miniss

dependencies:
development_dependencies:
3 changes: 3 additions & 0 deletions src/cli.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "./miniss/cli/cmd"

Miniss::Cli.run
6 changes: 6 additions & 0 deletions src/miniss.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "./miniss/*"
require "./miniss/etc/**"
# TODO: Write documentation for `Miniss`
module Miniss
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
end
10 changes: 10 additions & 0 deletions src/miniss/addr.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "../miniss"

module Miniss
def self.decode_addr(addr)
ip, port = addr.split(":", remove_empty: true)
ip = ip.scan(/.{2}/).reverse_each.join('.'){ |x| x[0].to_i(16) }
port = port.to_i(16).to_s
"#{ip}:#{port}"
end
end
19 changes: 19 additions & 0 deletions src/miniss/cli/cmd.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "../../miniss"

# :nodoc:
module Miniss::Cli
def self.run
puts "local address".ljust(22) + "remote address".ljust(22) + "state".ljust(12) + "username (uid)"
File.read_lines("/proc/net/tcp").each_with_index do |line, i|
entry = line.split(" ", remove_empty: true)
unless i == 0 # skip headers
laddr = Miniss.decode_addr(entry[1])
raddr = Miniss.decode_addr(entry[2])
state = Miniss::TCP_STATES[entry[3]]
uid = entry[7]
uname = Miniss::Etc.getpwuid(uid)
puts "#{laddr.ljust(22)}#{raddr.ljust(22)}#{state.ljust(12)}#{uname} (#{uid})"
end
end
end
end
20 changes: 20 additions & 0 deletions src/miniss/constants.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "../miniss"

module Miniss
TCP_STATES = { # /usr/src/linux/include/net/tcp_states.h
"00" => "UNKNOWN",
"FF" => "UNKNOWN",
"01" => "ESTABLISHED",
"02" => "SYN_SENT",
"03" => "SYN_RECV",
"04" => "FIN_WAIT1",
"05" => "FIN_WAIT2",
"06" => "TIME_WAIT",
"07" => "CLOSE",
"08" => "CLOSE_WAIT",
"09" => "LAST_ACK",
"0A" => "LISTEN",
"0B" => "CLOSING",
"0C" => "NEW_SYN_RECV"
}
end
8 changes: 8 additions & 0 deletions src/miniss/etc/etc.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Miniss::Etc
def self.getpwuid(uid)
File.read_lines("/etc/passwd").each_with_index do |line, i|
entry = line.split(":", remove_empty: false)
return entry[0] if entry[2] == uid
end
end
end

0 comments on commit d084f5f

Please sign in to comment.