142 Commits

Author SHA1 Message Date
kpcyrd
8951147b9a Release v0.10.0 2019-02-28 17:20:24 +01:00
kpcyrd
2886596893 Add tests for json functions 2019-02-28 16:29:00 +01:00
kpcyrd
e896e11d7c Add ddwrt script 2019-02-28 16:29:00 +01:00
kpcyrd
cbb6a87ca2 Merge pull request #80 from kpcyrd/ring
Bump ring for aarch64 support
2019-02-28 16:26:10 +01:00
kpcyrd
09e1514391 Bump ring 2019-02-27 18:10:46 +01:00
kpcyrd
8a6f8aaca0 Merge pull request #79 from kpcyrd/docs
Document structs
2019-02-27 16:36:01 +01:00
kpcyrd
a22caa4ef4 Skip lto to avoid compiler bug 2019-02-27 14:40:19 +01:00
kpcyrd
e3a84dfe89 Document structs 2019-02-24 20:50:03 +01:00
kpcyrd
b938d9c7f5 Refactor structs 2019-02-24 17:08:18 +01:00
kpcyrd
454a769f84 Merge pull request #78 from kpcyrd/breaches
Add breaches
2019-02-23 22:03:29 +01:00
kpcyrd
8150ad9483 Support multiple passwords per breach
Also update password-less links to a breach if we insert a 2nd link that
contains a password between the same breach and email.
2019-02-21 16:22:09 +01:00
kpcyrd
b9fddedbb5 Fix <= and >= in db queries 2019-02-19 16:58:54 +01:00
kpcyrd
b48c8728fd Add breaches to database 2019-02-19 16:43:36 +01:00
kpcyrd
af9087b80b Merge pull request #75 from kpcyrd/accounts
Add accounts
2019-02-19 16:30:10 +01:00
kpcyrd
b8b535c19a Disable docker test because of max build time 2019-02-15 18:39:10 +01:00
kpcyrd
344d28ec56 Add function to test sn0int semver 2019-02-15 14:29:07 +01:00
kpcyrd
30d3c1ac56 Set useragent for api client correctly 2019-02-15 14:24:14 +01:00
kpcyrd
0748297a42 Improve namechk error handling 2019-02-15 14:20:06 +01:00
kpcyrd
e9d9e9925a Add first attempt on namechk script 2019-02-14 17:14:36 +01:00
kpcyrd
c0c2c31b65 Add displayname field 2019-02-14 16:07:39 +01:00
kpcyrd
17f4682476 Add accounts to database 2019-02-12 16:38:07 +01:00
kpcyrd
4ce8f00ad8 Add additional context to download failures 2019-02-12 15:13:06 +01:00
kpcyrd
e5a9f4cfba Document optional dependencies on debian 2019-02-12 15:01:12 +01:00
kpcyrd
fcc6509a69 Make unknown script metadata non-fatal 2019-02-10 07:00:23 +01:00
kpcyrd
14339dea2f Fix mremap seccomp filter 2019-02-09 19:00:44 +01:00
kpcyrd
c849c57435 Release v0.9.1 2019-02-03 03:46:28 +01:00
kpcyrd
e4254bec17 Update docs 2019-02-03 03:45:23 +01:00
kpcyrd
980e6b55f4 Merge pull request #71 from kpcyrd/seccomp-i686
Adjust sandbox for i686
2019-02-03 03:43:08 +01:00
kpcyrd
2712bdaeea Update boxxy commands 2019-02-02 23:37:47 +01:00
kpcyrd
c0a63b0620 Don't kill the process at open, return error 2019-02-02 22:49:21 +01:00
kpcyrd
12754d1c7a Add integration test script 2019-02-02 16:57:39 +01:00
kpcyrd
0ae36e4976 Adjust sandbox for i686 2019-02-02 15:33:42 +01:00
kpcyrd
2972aa2480 Whitelist missing writev and readv syscalls 2019-01-31 23:59:31 +01:00
kpcyrd
874b317c95 Fix broken rst links 2019-01-31 17:24:07 +01:00
kpcyrd
ca66674f33 Split install instructions into debian and ubuntu 2019-01-31 17:19:24 +01:00
kpcyrd
6c81fe72b0 Add github issue template 2019-01-30 23:34:57 +01:00
kpcyrd
89402fe6e8 Bump module versions 2019-01-30 22:32:19 +01:00
kpcyrd
745cd01419 Update osx install instructions 2019-01-30 22:12:13 +01:00
kpcyrd
e3105165e0 Release v0.9.0 2019-01-29 02:40:32 +01:00
kpcyrd
a37fc3e0b3 Merge pull request #67 from kpcyrd/bump
Bump dependencies
2019-01-29 02:36:24 +01:00
kpcyrd
cbb8ca675e Fix cargo install instructions 2019-01-29 01:11:17 +01:00
kpcyrd
7f622a8c24 Bump dependencies 2019-01-29 01:11:02 +01:00
kpcyrd
b9d990caae Merge pull request #63 from kpcyrd/datetime
Add datetime function
2019-01-28 02:33:43 +01:00
kpcyrd
6856f3333f Fix datetime format for deserialize 2019-01-28 01:04:14 +01:00
kpcyrd
653651555f Add function to get current datetime 2019-01-23 21:09:39 +01:00
kpcyrd
d973bcc796 Merge pull request #62 from kpcyrd/db-add-ttl
Add db_add_ttl function
2019-01-21 20:50:30 +01:00
kpcyrd
d772d82d57 Relax workspace name rules 2019-01-21 19:57:57 +01:00
kpcyrd
0d722837db Workaround travis-cache inactitiy bug 2019-01-21 14:11:19 +01:00
kpcyrd
8695d4490d Enable Write-Ahead logging to resolve locking issue 2019-01-21 14:09:52 +01:00
kpcyrd
3b7b78ed4d Automatically clear expired entities from db 2019-01-21 08:11:20 +01:00
kpcyrd
c6ac0ede23 Update dependencies 2019-01-21 07:28:57 +01:00
kpcyrd
bfb06499c9 Add function to add to db with ttl until expiry 2019-01-21 01:07:51 +01:00
kpcyrd
9a8830fa53 Add passive arp scanner 2019-01-19 15:46:04 +01:00
kpcyrd
f00c1250f1 Merge branch 'sockets' 2019-01-19 15:38:04 +01:00
kpcyrd
9247d0fded Add module thunderbird-autoconfig 2019-01-19 03:06:11 +01:00
kpcyrd
83ad8c355f Add well-known urls scanner 2019-01-19 02:53:08 +01:00
kpcyrd
98bfee2778 Merge pull request #61 from kpcyrd/json
Add json output for select
2019-01-19 02:50:57 +01:00
kpcyrd
dd0966883d Don't display progress indicator in some cases 2019-01-19 01:11:10 +01:00
kpcyrd
3b9fe5ba6c Add json option to select 2019-01-19 00:28:18 +01:00
kpcyrd
8f38f80ac6 Document sock_* functions 2019-01-18 02:53:51 +01:00
kpcyrd
df7c3b69f4 Add subcommand to create new module 2019-01-18 02:44:46 +01:00
kpcyrd
cf7eb20d95 Use socks5 if set and automatically resolve dns 2019-01-17 18:21:08 +01:00
kpcyrd
8a4b8be0e7 Add socket functions and smtp-check script 2019-01-16 22:17:53 +01:00
kpcyrd
b97aeda086 Improve sn0int publish output 2019-01-14 18:19:21 +01:00
kpcyrd
064b3d7c01 Bump module versions 2019-01-13 01:29:23 +01:00
kpcyrd
3d2f80c9bb Update install instruction link 2019-01-13 01:23:25 +01:00
kpcyrd
686e1e5119 Release v0.8.1 2019-01-13 01:04:03 +01:00
kpcyrd
913e9a9f4f Update feature list format 2019-01-13 01:02:55 +01:00
kpcyrd
7a1cf34646 Update readme table of contents 2019-01-12 11:42:49 +01:00
kpcyrd
ed5e913275 Merge pull request #58 from kpcyrd/dns-cache
Add a dns-cache
2019-01-12 11:37:52 +01:00
kpcyrd
be2e859efd Merge some examples 2019-01-12 09:58:30 +01:00
kpcyrd
ef711c4fae Bump dependencies 2019-01-12 09:30:50 +01:00
kpcyrd
e8a8072349 Travis: skip sqlite install on osx 2019-01-12 08:58:32 +01:00
kpcyrd
592d697888 Remove some unused code 2019-01-12 05:04:11 +01:00
kpcyrd
f8807b7a60 Use chrootable-https dns cache 2019-01-12 04:35:05 +01:00
kpcyrd
40b97d74b4 Fix san extension parser bug 2019-01-10 21:08:54 +01:00
kpcyrd
4b8cc88871 Document sandbox 2019-01-10 08:04:34 +01:00
kpcyrd
3136ed522e Update module versions 2019-01-10 01:07:09 +01:00
kpcyrd
5cb3460ef4 Release v0.8.0 2019-01-07 03:28:39 +01:00
kpcyrd
bfe589e5a0 Use x509 parser in ctlogs module 2019-01-07 02:41:30 +01:00
kpcyrd
a29d3b1739 Use alpine dockerfile again 2019-01-07 01:16:34 +01:00
kpcyrd
f01f299e02 Connect iwdump module to database 2019-01-06 21:33:46 +01:00
kpcyrd
b0f25110a3 Expose select to non-interactive mode 2019-01-06 21:24:00 +01:00
kpcyrd
494e503d84 Add CONTRIBUTING.md 2019-01-06 18:36:05 +01:00
kpcyrd
27608f9bdd Suggest running help on unknown command 2019-01-06 16:37:28 +01:00
kpcyrd
b429355a46 Add git webroot scanner 2019-01-06 16:32:42 +01:00
kpcyrd
0b9474fdbd Link to webirc 2019-01-04 01:30:26 +01:00
kpcyrd
97ea7daef8 Connect dhcpd parser to database 2019-01-02 04:18:00 +01:00
kpcyrd
a39c901b2f Merge pull request #57 from kpcyrd/options
Introduce an option system
2019-01-01 22:30:17 +01:00
kpcyrd
8ccccea367 Introduce an option system 2019-01-01 20:25:54 +01:00
kpcyrd
5df4f180e5 Add dhcpd and iw station dump parser 2019-01-01 06:43:59 +01:00
kpcyrd
b49d97e55c Merge pull request #53 from kpcyrd/networks
Add networks and devices
2019-01-01 05:52:49 +01:00
kpcyrd
570c6b4225 Generate readme toc from docs/ 2019-01-01 02:27:07 +01:00
kpcyrd
6fbebd8544 Document proxy config 2019-01-01 01:57:13 +01:00
kpcyrd
86c2b91c73 Exclude unneeded open syscall 2019-01-01 01:38:51 +01:00
kpcyrd
db2203b286 Merge pull request #56 from kpcyrd/socks5
Add socks5 support
2019-01-01 01:37:02 +01:00
kpcyrd
1772d8b9e3 Fix docker hub 2018-12-31 18:20:33 +01:00
kpcyrd
9814167212 Add docker usage instructions 2018-12-31 04:01:29 +01:00
kpcyrd
5b039fe0eb Add socks5 support 2018-12-31 03:49:50 +01:00
kpcyrd
9d414da7d4 Merge pull request #54 from kpcyrd/selftest
Add features to support selftest
2018-12-31 03:44:55 +01:00
kpcyrd
b828f2d6f0 Update description 2018-12-29 16:11:34 +01:00
kpcyrd
06ae0958ec Introduce help command
Resolve #55
2018-12-28 05:00:45 +01:00
kpcyrd
2747e5a1c5 Add table of contents to readme 2018-12-28 04:14:44 +01:00
kpcyrd
6e210acc90 Add features to support selftest 2018-12-26 14:37:18 +01:00
kpcyrd
653b1bd340 Add ipaddr to device table 2018-12-26 00:19:26 +01:00
kpcyrd
0b719b832c Add devices and networks 2018-12-25 14:55:11 +01:00
kpcyrd
7dcb950899 Add ieee iab and oui to repo 2018-12-25 13:10:48 +01:00
kpcyrd
41e8b4f047 Release v0.7.0 2018-12-24 02:43:39 +01:00
kpcyrd
145b6dfa9a Add reverse dns and description for ips 2018-12-24 01:14:02 +01:00
kpcyrd
5368ef3e52 Allow keyring as source argument 2018-12-23 23:44:48 +01:00
kpcyrd
a95ba52e97 Add phpmyadmin url bruteforce 2018-12-23 19:45:55 +01:00
kpcyrd
e578b4eea7 Merge pull request #50 from kpcyrd/phone
Support phonenumbers
2018-12-23 19:41:06 +01:00
kpcyrd
b9e920d890 Fix tests 2018-12-23 18:41:19 +01:00
kpcyrd
765a9d161c Refactor entity formatting 2018-12-23 17:17:25 +01:00
kpcyrd
fcd8867a15 clippy fixes 2018-12-23 17:17:25 +01:00
kpcyrd
0928ea12c6 Ask the user to grant access to credentials 2018-12-23 17:17:25 +01:00
kpcyrd
641f46892b Connect keyring to modules 2018-12-23 17:17:25 +01:00
kpcyrd
776d02e8cc Automatically encode input in log functions 2018-12-23 17:17:25 +01:00
kpcyrd
0db0dd263e Add twilio lookup prototype 2018-12-23 17:17:25 +01:00
kpcyrd
73ac953ee4 Rename and document accesskey command to keyring 2018-12-23 17:17:25 +01:00
kpcyrd
3b4381cf3b Add accesskey manager 2018-12-23 17:17:25 +01:00
kpcyrd
3c853b83d4 Add more fields to phonenumber table 2018-12-23 17:17:25 +01:00
kpcyrd
93d6fb12a7 Add phonenumbers to database 2018-12-23 17:17:25 +01:00
kpcyrd
2f4fa798c1 Refactor module loader 2018-12-21 03:07:09 +01:00
kpcyrd
426ec77eb3 Remove obsolete update command 2018-12-21 02:49:35 +01:00
kpcyrd
40efb237d7 Replace dockerfile with debian for now 2018-12-20 23:42:10 +01:00
kpcyrd
ffc8ce6a3c Bump some module versions 2018-12-20 20:43:33 +01:00
kpcyrd
8f16948443 Merge pull request #49 from kpcyrd/async-chrootable
Port to async chrootable-https
2018-12-12 01:59:02 +01:00
kpcyrd
3a84395551 Port to async chrootable-https 2018-12-12 00:25:40 +01:00
kpcyrd
d8923f4b46 Bump dependencies 2018-12-10 14:53:47 +01:00
kpcyrd
699c242136 Merge pull request #48 from kpcyrd/rocket-4
Port to rocket 0.4
2018-12-10 14:50:51 +01:00
kpcyrd
347da4825c Remove custom_derive feature 2018-12-10 03:43:43 +01:00
kpcyrd
55cba1e04d Improve error messages 2018-12-10 02:08:55 +01:00
kpcyrd
f6559668c2 Improve error handling 2018-12-10 02:08:55 +01:00
kpcyrd
b42323d63c Move cache-control headers to registry code 2018-12-10 02:08:55 +01:00
kpcyrd
e3ee1a7f20 Move security headers to registry code 2018-12-10 02:08:55 +01:00
kpcyrd
75c888c473 Port to latest rocket version 2018-12-10 02:08:55 +01:00
kpcyrd
5735af29b2 Merge pull request #47 from kpcyrd/2018
Port to rust 2018 edition
2018-12-10 02:07:05 +01:00
kpcyrd
212aa9601e Port sn0int-registry to 2018 edition 2018-12-09 15:27:42 +01:00
kpcyrd
5582892763 Port sn0int-common to 2018 edition 2018-12-09 15:19:27 +01:00
kpcyrd
7b91e6f872 Port to 2018 edition 2018-12-09 15:17:50 +01:00
kpcyrd
d77b2b39e0 cargo fix --edition 2018-12-09 15:17:50 +01:00
186 changed files with 39903 additions and 3024 deletions

View File

@@ -1,6 +1,9 @@
target
Dockerfile
.dockerignore
docker
docs
ci
.git
.gitignore
*.sw[op]

View File

@@ -1,6 +1,7 @@
language: rust
cache: cargo
# upload takes too long on windows and gets killed due to inactivity
#cache: cargo
matrix:
include:

32
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,32 @@
# How to contribute
To contribute to sn0int, clone the repository and make sure both the build and
tests pass for you:
git clone https://github.com/kpcyrd/sn0int.git
cd sn0int
# build the project
cargo build
# run regular tests
cargo test
# run tests depending on the network
# these might fail if a service is down
cargo test -- --ignored
The project is loosely structured into a few folders:
- `src/models/` - database models
- `src/runtime/` - the stdlib that's exposed to lua
- `src/engine/` - code related to lua
- `src/sandbox/` - code related to sandboxing
- `src/cmd/` - cli commands
- `src/` - misc modules
After you're done, make sure the build completes without any warnings and both
tests pass successfully:
cargo test
cargo test -- --ignored
If you want to introduce a new feature feel free to open an issue first to make
sure your feature is a good fit for the project before implementing it.

2093
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,33 @@
[package]
name = "sn0int"
version = "0.6.0"
description = "OSINT framework and package manager"
version = "0.10.0"
description = "Semi-automatic OSINT framework and package manager"
authors = ["kpcyrd <git@rxv.cc>"]
license = "GPL-3.0"
repository = "https://github.com/kpcyrd/sn0int"
categories = ["command-line-utilities"]
readme = "README.md"
edition = "2018"
[profile.release]
# skip lto to avoid compiler bug:
# https://github.com/kpcyrd/sn0int/issues/77
# https://github.com/rust-lang/rust/issues/58674
opt-level = 1
lto = false
[badges]
travis-ci = { repository = "kpcyrd/sn0int" }
[workspace]
members = ["sn0int-registry/sn0int-common",
"sn0int-registry"]
# rocket is broken and blocks the whole workspace, removing
#members = ["sn0int-registry/sn0int-common",
# "sn0int-registry"]
members = ["sn0int-registry/sn0int-common"]
[dependencies]
sn0int-common = { version="0.3.0", path="sn0int-registry/sn0int-common" }
rustyline = "2"
sn0int-common = { version="0.5.0", path="sn0int-registry/sn0int-common" }
rustyline = "3"
log = "0.4"
env_logger = "0.6"
hlua-badtouch = "0.4"
@@ -28,11 +38,13 @@ colored = "1.6"
lazy_static = "1.0"
shellwords = "1.0"
publicsuffix = { version="1.5", default-features=false }
diesel = { version = "1.0.0", features = ["sqlite"] }
diesel = { version = "1.0.0", features = ["sqlite", "chrono"] }
diesel_migrations = { version = "1.3.0", features = ["sqlite"] }
chrono = { version = "0.4", features = ["serde"] }
dirs = "1.0"
url = "1.7"
chrootable-https = "0.5.0"
#chrootable-https = { path = "../chrootable-https" }
chrootable-https = "0.9"
base64 = "0.10"
kuchiki = "0.7.2"
serde_urlencoded = "0.5"
@@ -47,22 +59,32 @@ maplit = "1.0.1"
sloppy-rfc4880 = "0.1.2"
regex = "1.0"
toml = "0.4"
maxminddb = "0.10.0"
maxminddb = "0.13"
tar = "0.4.17"
libflate = "0.1.14"
threadpool = "1.7"
x509-parser = "0.4.0"
der-parser = "1.1.0"
nom = "4.1.1"
atty = "0.2"
bufstream = "0.1.4"
tokio = "0.1.14"
semver = "0.9"
[target.'cfg(target_os="linux")'.dependencies]
caps = "0.3"
syscallz = "0.8"
nix = "0.12"
#syscallz = { path="../syscallz-rs" }
syscallz = "0.11"
nix = "0.13"
[target.'cfg(target_os="openbsd")'.dependencies]
pledge = "0.3.1"
unveil = "0.2.0"
[dev-dependencies]
boxxy = "0.8"
#boxxy = { path = "../boxxy-rs" }
boxxy = "0.9"
#[patch.crates-io]
#rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev="c86f4312fb273c0380fb76a97bfb7fc227800542" }
#rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket.git", rev="c86f4312fb273c0380fb76a97bfb7fc227800542" }

29
ISSUE_TEMPLATE.md Normal file
View File

@@ -0,0 +1,29 @@
<!--
Hello!
If you want to report a bug we added some common questions below that help us analyse your issue faster.
All of these are optional so feel free to remove anything that doesn't apply.
-->
please describe your issue here
---
## Versions
- **rustc --version:**
- **cargo --version:**
- **sn0int --version:**
- **uname -a:**
## Environment
- **Operating System/Distro:**
- **Installed from (source/apt/pacman/brew/docker):**
<!--
Thank you!
We'll try to respond as quickly as possible.
-->

View File

@@ -14,3 +14,8 @@ test:
(cd sn0int-registry; cargo test)
cargo test
cargo test -- --ignored
update:
get-oui -v -u http://standards-oui.ieee.org/oui/oui.txt -f data/ieee-oui.txt
get-iab -v -u http://standards-oui.ieee.org/iab/iab.txt -f data/ieee-iab.txt
rm -f data/ieee-*.txt.bak

119
README.md
View File

@@ -7,20 +7,22 @@
[docs-img]: https://readthedocs.org/projects/sn0int/badge/?version=latest
[docs]: https://sn0int.readthedocs.io/en/latest/?badge=latest
sn0int is an OSINT framework and package manager. It was built for IT security
professionals and bug hunters to gather intelligence about a given target or
about yourself. sn0int is enumerating attack surface by semi-automatically
processing public information and mapping the results in a unified format for
followup investigations.
sn0int is a semi-automatic OSINT framework and package manager. It was built
for IT security professionals and bug hunters to gather intelligence about a
given target or about yourself. sn0int is enumerating attack surface by
semi-automatically processing public information and mapping the results in a
unified format for followup investigations.
Among other things, sn0int is currently able to:
- [X] Harvest subdomains from certificate transparency logs
- [X] Harvest subdomains from various passive dns logs
- [X] Sift through subdomain results for publicly accessible websites
- [X] Harvest emails from pgp keyservers
- [X] Enrich ip addresses with ASN and geoip info
- [X] Harvest subdomains from the wayback machine
- Harvest subdomains from certificate transparency logs
- Harvest subdomains from various passive dns logs
- Sift through subdomain results for publicly accessible websites
- Harvest emails from pgp keyservers
- Enrich ip addresses with ASN and geoip info
- Harvest subdomains from the wayback machine
- Gather information about phonenumbers
- Bruteforce interesting urls
sn0int is heavily inspired by recon-ng and maltego, but remains more flexible
and is fully opensource. None of the investigations listed above are hardcoded
@@ -30,17 +32,98 @@ them with other users by publishing them to the sn0int registry. This allows
you to ship updates for your modules on your own since you don't need to send a
pull request.
Join us on IRC: <ircs://irc.hackint.org/#sn0int>
Join us on IRC: [irc.hackint.org:6697/#sn0int](https://webirc.hackint.org/#irc://irc.hackint.org/#sn0int)
[![asciicast](https://asciinema.org/a/shZ3TVY1o0opGFln3Oi2DAMCB.svg)](https://asciinema.org/a/shZ3TVY1o0opGFln3Oi2DAMCB)
## Installation
## Getting started
- Archlinux: `pacman -S sn0int`
- Alpine: `apk add --no-cache sqlite-dev libseccomp-dev cargo` + build from source
- Debian: `apt install libsqlite3-dev libseccomp-dev` + build from source
- OpenBSD: `pkg_add sqlite3` + build from source
- OSX: `brew install sqlite3` + build from source
- [Installation](https://sn0int.readthedocs.io/en/latest/install.html)
- [Archlinux](https://sn0int.readthedocs.io/en/latest/install.html#archlinux)
- [Mac OSX](https://sn0int.readthedocs.io/en/latest/install.html#mac-osx)
- [Debian testing/Debian sid/Kali](https://sn0int.readthedocs.io/en/latest/install.html#debian-testing-debian-sid-kali)
- [Ubuntu/Debian stable](https://sn0int.readthedocs.io/en/latest/install.html#ubuntu-debian-stable)
- [Docker](https://sn0int.readthedocs.io/en/latest/install.html#docker)
- [Alpine](https://sn0int.readthedocs.io/en/latest/install.html#alpine)
- [OpenBSD](https://sn0int.readthedocs.io/en/latest/install.html#openbsd)
- [Windows](https://sn0int.readthedocs.io/en/latest/install.html#windows)
- [Running your first investigation](https://sn0int.readthedocs.io/en/latest/usage.html)
- [Installing the default modules](https://sn0int.readthedocs.io/en/latest/usage.html#installing-the-default-modules)
- [Adding something to scope](https://sn0int.readthedocs.io/en/latest/usage.html#adding-something-to-scope)
- [Running a module](https://sn0int.readthedocs.io/en/latest/usage.html#running-a-module)
- [Running followup modules on the results](https://sn0int.readthedocs.io/en/latest/usage.html#running-followup-modules-on-the-results)
- [Unscoping entities](https://sn0int.readthedocs.io/en/latest/usage.html#unscoping-entities)
- [Scripting](https://sn0int.readthedocs.io/en/latest/scripting.html)
- [Write your first module](https://sn0int.readthedocs.io/en/latest/scripting.html#write-your-first-module)
- [Publish your module](https://sn0int.readthedocs.io/en/latest/scripting.html#publish-your-module)
- [Reading data from stdin](https://sn0int.readthedocs.io/en/latest/scripting.html#reading-data-from-stdin)
- [Database](https://sn0int.readthedocs.io/en/latest/database.html)
- [db_add](https://sn0int.readthedocs.io/en/latest/database.html#db-add)
- [db_update](https://sn0int.readthedocs.io/en/latest/database.html#db-update)
- [db_select](https://sn0int.readthedocs.io/en/latest/database.html#db-select)
- [Keyring](https://sn0int.readthedocs.io/en/latest/keyring.html)
- [Managing the keyring](https://sn0int.readthedocs.io/en/latest/keyring.html#managing-the-keyring)
- [Using access keys in scripts](https://sn0int.readthedocs.io/en/latest/keyring.html#using-access-keys-in-scripts)
- [Using access keys as source argument](https://sn0int.readthedocs.io/en/latest/keyring.html#using-access-keys-as-source-argument)
- [Configuration](https://sn0int.readthedocs.io/en/latest/config.html)
- [Configuring a proxy](https://sn0int.readthedocs.io/en/latest/config.html#configuring-a-proxy)
- [Sandbox](https://sn0int.readthedocs.io/en/latest/sandbox.html)
- [Linux](https://sn0int.readthedocs.io/en/latest/sandbox.html#linux)
- [OpenBSD](https://sn0int.readthedocs.io/en/latest/sandbox.html#openbsd)
- [IPC Protocol](https://sn0int.readthedocs.io/en/latest/sandbox.html#ipc-protocol)
- [Limitations](https://sn0int.readthedocs.io/en/latest/sandbox.html#limitations)
- [Diagnosing a sandbox failure](https://sn0int.readthedocs.io/en/latest/sandbox.html#diagnosing-a-sandbox-failure)
- [Function reference](https://sn0int.readthedocs.io/en/latest/reference.html)
- [clear_err](https://sn0int.readthedocs.io/en/latest/reference.html#clear-err)
- [datetime](https://sn0int.readthedocs.io/en/latest/reference.html#datetime)
- [db_add](https://sn0int.readthedocs.io/en/latest/reference.html#db-add)
- [db_add_ttl](https://sn0int.readthedocs.io/en/latest/reference.html#db-add-ttl)
- [db_select](https://sn0int.readthedocs.io/en/latest/reference.html#db-select)
- [db_update](https://sn0int.readthedocs.io/en/latest/reference.html#db-update)
- [dns](https://sn0int.readthedocs.io/en/latest/reference.html#dns)
- [error](https://sn0int.readthedocs.io/en/latest/reference.html#error)
- [asn_lookup](https://sn0int.readthedocs.io/en/latest/reference.html#asn-lookup)
- [geoip_lookup](https://sn0int.readthedocs.io/en/latest/reference.html#geoip-lookup)
- [html_select](https://sn0int.readthedocs.io/en/latest/reference.html#html-select)
- [html_select_list](https://sn0int.readthedocs.io/en/latest/reference.html#html-select-list)
- [http_mksession](https://sn0int.readthedocs.io/en/latest/reference.html#http-mksession)
- [http_request](https://sn0int.readthedocs.io/en/latest/reference.html#http-request)
- [http_send](https://sn0int.readthedocs.io/en/latest/reference.html#http-send)
- [info](https://sn0int.readthedocs.io/en/latest/reference.html#info)
- [json_decode](https://sn0int.readthedocs.io/en/latest/reference.html#json-decode)
- [json_decode_stream](https://sn0int.readthedocs.io/en/latest/reference.html#json-decode-stream)
- [json_encode](https://sn0int.readthedocs.io/en/latest/reference.html#json-encode)
- [keyring](https://sn0int.readthedocs.io/en/latest/reference.html#keyring)
- [last_err](https://sn0int.readthedocs.io/en/latest/reference.html#last-err)
- [pgp_pubkey](https://sn0int.readthedocs.io/en/latest/reference.html#pgp-pubkey)
- [pgp_pubkey_armored](https://sn0int.readthedocs.io/en/latest/reference.html#pgp-pubkey-armored)
- [print](https://sn0int.readthedocs.io/en/latest/reference.html#print)
- [psl_domain_from_dns_name](https://sn0int.readthedocs.io/en/latest/reference.html#psl-domain-from-dns-name)
- [regex_find](https://sn0int.readthedocs.io/en/latest/reference.html#regex-find)
- [regex_find_all](https://sn0int.readthedocs.io/en/latest/reference.html#regex-find-all)
- [sleep](https://sn0int.readthedocs.io/en/latest/reference.html#sleep)
- [sock_connect](https://sn0int.readthedocs.io/en/latest/reference.html#sock-connect)
- [sock_send](https://sn0int.readthedocs.io/en/latest/reference.html#sock-send)
- [sock_recv](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recv)
- [sock_sendline](https://sn0int.readthedocs.io/en/latest/reference.html#sock-sendline)
- [sock_recvline](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvline)
- [sock_recvall](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvall)
- [sock_recvline_contains](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvline-contains)
- [sock_recvline_regex](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvline-regex)
- [sock_recvn](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvn)
- [sock_recvuntil](https://sn0int.readthedocs.io/en/latest/reference.html#sock-recvuntil)
- [sock_sendafter](https://sn0int.readthedocs.io/en/latest/reference.html#sock-sendafter)
- [sock_newline](https://sn0int.readthedocs.io/en/latest/reference.html#sock-newline)
- [status](https://sn0int.readthedocs.io/en/latest/reference.html#status)
- [stdin_readline](https://sn0int.readthedocs.io/en/latest/reference.html#stdin-readline)
- [url_decode](https://sn0int.readthedocs.io/en/latest/reference.html#url-decode)
- [url_encode](https://sn0int.readthedocs.io/en/latest/reference.html#url-encode)
- [url_escape](https://sn0int.readthedocs.io/en/latest/reference.html#url-escape)
- [url_join](https://sn0int.readthedocs.io/en/latest/reference.html#url-join)
- [url_parse](https://sn0int.readthedocs.io/en/latest/reference.html#url-parse)
- [url_unescape](https://sn0int.readthedocs.io/en/latest/reference.html#url-unescape)
- [utf8_decode](https://sn0int.readthedocs.io/en/latest/reference.html#utf8-decode)
- [x509_parse_pem](https://sn0int.readthedocs.io/en/latest/reference.html#x509-parse-pem)
## License

View File

@@ -1,3 +1,5 @@
stage1
ls
echo checkpoint1
id
echo sandbox fail

123
ci/integration.py Executable file
View File

@@ -0,0 +1,123 @@
#!/usr/bin/env python3
import subprocess
from subprocess import DEVNULL, PIPE
import tempfile
import json
import sys
def _sn0int(tempdir, binary, args, piped_stdout=False):
return subprocess.Popen(
['/usr/bin/env', 'HOME='+tempdir, binary] + args,
stdin=PIPE,
stdout=PIPE if piped_stdout else None,
)
def sn0int(tempdir, binary, cmds):
p = _sn0int(tempdir, binary, [])
for cmd in cmds:
p.stdin.write((cmd + '\n').encode('utf-8'))
p.communicate()
if p.returncode != 0:
raise Exception('process failed')
def sn0int_select(tempdir, binary, query):
p = _sn0int(tempdir, binary, ['select', '--json'] + query, piped_stdout=True)
stdout, _ = p.communicate()
lines = filter(None, stdout.decode('utf-8').split('\n'))
return [json.loads(x) for x in lines]
def main(tempdir, binary):
print('[*] setting up workspace')
sn0int(tempdir, binary, [])
print('[*] adding domain')
sn0int(tempdir, binary, [
'add domain',
'example.com',
'select domains',
])
print('[*] testing db for domain')
domains = sn0int_select(tempdir, binary, ['domains'])
assert domains == [{'id': 1, 'value': 'example.com', 'unscoped': False}]
print('[*] installing modules')
sn0int(tempdir, binary, [
'mod install kpcyrd/ctlogs',
'mod install kpcyrd/dns-resolve',
'mod install kpcyrd/url-scan',
'mod install kpcyrd/geoip',
])
print('[*] running ctlogs')
sn0int(tempdir, binary, [
'use ctlogs',
'run',
'select subdomains',
])
print('[*] testing db for subdomains')
subdomains = sn0int_select(tempdir, binary, ['subdomains'])
assert {x['value'] for x in subdomains} == {
'www.example.com',
'm.example.com',
'dev.example.com',
'products.example.com',
'support.example.com',
}
print('[*] running dns-resolve')
sn0int(tempdir, binary, [
'use dns-resolve',
'run',
'select ipaddrs',
])
print('[*] testing db for ipaddrs')
ipaddrs = sn0int_select(tempdir, binary, ['ipaddrs'])
assert len(ipaddrs) >= 1
print('[*] running url-scan')
sn0int(tempdir, binary, [
'use url-scan',
'run',
'select urls',
])
print('[*] testing db for urls')
urls = sn0int_select(tempdir, binary, ['urls'])
assert {(x['value'], x['status']) for x in urls} == {
('http://www.example.com/', 200),
('https://www.example.com/', 200),
}
print('[*] running geoip')
sn0int(tempdir, binary, [
'use geoip',
'run',
'select ipaddrs',
])
print('[*] testing db for ipaddrs again')
ipaddrs2 = sn0int_select(tempdir, binary, ['ipaddrs'])
assert ipaddrs != ipaddrs2
print('')
print('\t###########')
print('\t# SUCCESS #')
print('\t###########')
print('')
if __name__ == '__main__':
try:
binary = sys.argv[1]
except IndexError:
print('Usage: %s target/release/sn0int' % sys.argv[0])
else:
with tempfile.TemporaryDirectory(prefix='sn0int-') as tempdir:
main(tempdir, binary)

View File

@@ -9,8 +9,8 @@ case "$1" in
ci/run.sh build
wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz \
https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz
cargo run --example maxmind-dl -- -e GeoLite2-City.tar.gz GeoLite2-City.mmdb GeoLite2-City.mmdb
cargo run --example maxmind-dl -- -e GeoLite2-ASN.tar.gz GeoLite2-ASN.mmdb GeoLite2-ASN.mmdb
cargo run --example maxmind -- dl -e GeoLite2-City.tar.gz GeoLite2-City.mmdb GeoLite2-City.mmdb
cargo run --example maxmind -- dl -e GeoLite2-ASN.tar.gz GeoLite2-ASN.mmdb GeoLite2-ASN.mmdb
cargo test --verbose
cargo test --verbose -- --ignored
;;

View File

@@ -5,9 +5,6 @@ case "$1" in
sudo apt update
sudo apt install libsqlite3-dev libseccomp-dev
;;
osx)
brew install sqlite3
;;
windows)
curl -fsS --retry 3 --retry-connrefused -o sqlite3.zip https://sqlite.org/2017/sqlite-dll-win64-x64-3160200.zip
7z e sqlite3.zip -y

View File

@@ -0,0 +1,15 @@
FROM alpine:edge
RUN apk add --no-cache sqlite-dev libseccomp-dev
RUN apk add --no-cache --virtual .build-rust rust cargo
WORKDIR /usr/src/sn0int
COPY . .
RUN cargo build --release --verbose
RUN strip target/release/sn0int
FROM alpine:edge
RUN apk add --no-cache libgcc sqlite-libs libseccomp
COPY --from=0 /usr/src/sn0int/target/release/sn0int /usr/local/bin/sn0int
VOLUME ["/data", "/cache"]
ENV XDG_DATA_HOME=/data \
XDG_CACHE_HOME=/cache
ENTRYPOINT ["sn0int"]

View File

@@ -0,0 +1,16 @@
FROM rust
RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/sn0int
COPY . .
RUN cargo build --release --verbose
RUN strip target/release/sn0int
FROM debian
RUN apt-get update -q && apt-get install -yq libsqlite3-dev libseccomp-dev \
&& rm -rf /var/lib/apt/lists/*
COPY --from=0 /usr/src/sn0int/target/release/sn0int /usr/local/bin/sn0int
VOLUME ["/data", "/cache"]
ENV XDG_DATA_HOME=/data \
XDG_CACHE_HOME=/cache
ENTRYPOINT ["sn0int"]

2
contrib/html-toc2md.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
perl -n -e '/toctree-l(\d).*href="([^"]+)">(.+)<\/a/ && print $1==2?" ":"", "- [$3](https://sn0int.readthedocs.io/en/latest/$2)\n"' < docs/_build/html/index.html

0
data/.gitkeep Normal file
View File

4595
data/ieee-iab.txt Normal file

File diff suppressed because it is too large Load Diff

25800
data/ieee-oui.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -138,7 +138,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('man', 'sn0int', 'OSINT framework and package manager',
('man', 'sn0int', 'Semi-automatic OSINT framework and package manager',
[author], 1)
]

17
docs/config.rst Normal file
View File

@@ -0,0 +1,17 @@
Configuration
=============
This file documents the config file at ``~/.config/sn0int.toml``. By default
this file does not exist and a default configuration is used instead.
Configuring a proxy
-------------------
To enable a proxy, add the following to your config file::
[network]
proxy = "127.0.0.1:9050"
This forces everything through tor and restricts all other functions that
depend on the network. For example the ``dns`` function is fully disabled if a
proxy is configured.

View File

@@ -1,20 +1,22 @@
sn0int
======
sn0int is an OSINT framework and package manager. It was built for IT security
professionals and bug hunters to gather intelligence about a given target or
about yourself. sn0int is enumerating attack surface by semi-automatically
processing public information and mapping the results in a unified format for
followup investigations.
sn0int is a semi-automatic OSINT framework and package manager. It was built
for IT security professionals and bug hunters to gather intelligence about a
given target or about yourself. sn0int is enumerating attack surface by
semi-automatically processing public information and mapping the results in a
unified format for followup investigations.
Among other things, sn0int is currently able to:
- [X] Harvest subdomains from certificate transparency logs
- [X] Harvest subdomains from various passive dns logs
- [X] Sift through subdomain results for publicly accessible websites
- [X] Harvest emails from pgp keyservers
- [X] Enrich ip addresses with ASN and geoip info
- [X] Harvest subdomains from the wayback machine
- Harvest subdomains from certificate transparency logs
- Harvest subdomains from various passive dns logs
- Sift through subdomain results for publicly accessible websites
- Harvest emails from pgp keyservers
- Enrich ip addresses with ASN and geoip info
- Harvest subdomains from the wayback machine
- Gather information about phonenumbers
- Bruteforce interesting urls
sn0int is heavily inspired by recon-ng and maltego, but remains more flexible
and is fully opensource. None of the investigations listed above are hardcoded
@@ -24,7 +26,7 @@ them with other users by publishing them to the sn0int registry. This allows
you to ship updates for your modules on your own since you don't need to send a
pull request.
Join us on IRC: ircs://irc.hackint.org/#sn0int
Join us on IRC: `irc.hackint.org:6697/#sn0int <https://webirc.hackint.org/#irc://irc.hackint.org/#sn0int>`_
Getting Started
---------------
@@ -37,4 +39,8 @@ Getting Started
usage
scripting
database
structs
keyring
config
sandbox
reference

View File

@@ -10,15 +10,48 @@ Archlinux
$ pacman -S sn0int
Debian/Ubuntu/Kali
------------------
Mac OSX
-------
.. code-block:: bash
$ apt install libsqlite3-dev libseccomp-dev
$ brew install sn0int
Debian testing/Debian sid/Kali
------------------------------
Note that debian `doesn't ship the geoip2-database
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=757723>`_ so we're going to
download them automatically during the first run.
.. code-block:: bash
$ apt install build-essential cargo libsqlite3-dev libseccomp-dev publicsuffix
$ git clone https://github.com/kpcyrd/sn0int.git
$ cd sn0int
$ cargo install -f
$ cargo install -f --path .
Ubuntu/Debian stable
--------------------
cargo in the repos is too old and the build is `going to fail
<https://github.com/kpcyrd/sn0int/issues/68>`_. You should either install the
most recent rust version with `rustup <https://rustup.rs/>`_ or use the docker
instructions instead.
.. code-block:: bash
$ apt install build-essential libsqlite3-dev libseccomp-dev publicsuffix
$ git clone https://github.com/kpcyrd/sn0int.git
$ cd sn0int
$ cargo install -f --path .
Docker
------
.. code-block:: bash
$ docker run --rm --init -it -v $PWD/.cache:/cache -v $PWD/.data:/data kpcyrd/sn0int
Alpine
------
@@ -28,7 +61,7 @@ Alpine
$ apk add --no-cache sqlite-dev libseccomp-dev cargo
$ git clone https://github.com/kpcyrd/sn0int.git
$ cd sn0int
$ cargo install -f
$ cargo install -f --path .
OpenBSD
-------
@@ -38,17 +71,7 @@ OpenBSD
$ pkg_add sqlite3
$ git clone https://github.com/kpcyrd/sn0int.git
$ cd sn0int
$ cargo install -f
Mac OSX
-------
.. code-block:: bash
$ brew install sqlite3
$ git clone https://github.com/kpcyrd/sn0int.git
$ cd sn0int
$ cargo install -f
$ cargo install -f --path .
Windows
-------
@@ -63,4 +86,4 @@ This is not recommended and only passively maintained. Please prefer linux in a
$ 7z e sqlite3.zip -y
$ "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\lib.exe" /def:sqlite3.def /OUT:sqlite3.lib /machine:x64
$ export SQLITE3_LIB_DIR="$TRAVIS_BUILD_DIR"
$ cargo install -f
$ cargo install -f --path .

73
docs/keyring.rst Normal file
View File

@@ -0,0 +1,73 @@
Keyring
=======
A common problem is that you need either an api key or a username/password
combination. Instead of hardcoding it in the script you should request them
from the keyring. In order to do this you need to request permissions to those
credentials.
Managing the keyring
--------------------
The keyring is a simple namespaced key-value store::
[sn0int][default] > keyring add aws:AKIAIOSFODNN7EXAMPLE
Secretkey: keep-this-secret
[sn0int][default] > keyring list
aws:AKIAIOSFODNN7EXAMPLE
[sn0int][default] >
[sn0int][default] > keyring list aws
aws:AKIAIOSFODNN7EXAMPLE
[sn0int][default] > keyring list instagram
[sn0int][default] >
[sn0int][default] > keyring get aws:AKIAIOSFODNN7EXAMPLE
Namespace: "aws"
Access Key: "AKIAIOSFODNN7EXAMPLE"
Secret: "keep-this-secret"
[sn0int][default] >
If the service uses a username-password combination, set the username as the
access key and the password as the secret.
If the service uses only a secret key for the api, set the secret key as the
access key and leave the secret blank.
A script doesn't automatically get access to requested keyring namespaces.
Instead the user is asked to confirm those requests to limit abusive scripts.
Using access keys in scripts
----------------------------
We can request all keys of a certain namespace in our script metadata. This is
going to prompt the user to grant the script access. This can be done for
multiple namespaces in the same script:
.. code-block:: lua
-- Keyring-Access: aws
-- Keyring-Access: asdf
If the user granted us access to those keys we can read them with ``keyring``:
.. code-block:: lua
creds = keyring('aws')
print(creds[1]['accesskey'])
print(creds[1]['secretkey'])
This returns a list of all keys in that namespace. Any empty list is returned
if the user doesn't have any keys in that namespace.
Using access keys as source argument
------------------------------------
We can also use the access keys as source argument. This is useful if each
account has access to different things and we want to read through all of them.
Since access key permissions are granted per namespace we need to specify which
credentials we want to use.
.. code-block:: lua
-- Keyring-Access: aws
-- Source: keyring:aws

View File

@@ -10,4 +10,5 @@ todo
:glob:
usage
config
reference

View File

@@ -13,6 +13,16 @@ Clear the last recorded error from the internal state. See also last_err_.
clear_err()
end
datetime
--------
Return current time in UTC. This function is suitable to determine datetimes
for ``DATETIME`` database fields.
.. code-block:: lua
now = datetime()
db_add
------
@@ -25,6 +35,23 @@ may fail or return ``nil``. See `db_add <database.html#db-add>`__ for details.
value='example.com',
})
db_add_ttl
----------
Add a temporary entity to the database. This is commonly used to insert
temporary links that automatically expire over time. If the entity already
exists and is also marked as temporary the new ttl is going to replace the old
ttl. If the entity already exists but never expires we are not going to add a
ttl.
.. code-block:: lua
-- this link is valid for 2min
domain_id = db_add('network-device', {
network_id=1,
device_id=13,
}, 120)
db_select
---------
@@ -73,15 +100,20 @@ This function accepts the following options:
.. code-block:: lua
x = dns('example.com', {
record='A'
records = dns('example.com', {
record='A',
})
if last_err() then return end
if records['error'] ~= nil then return end
records = records['answers']
.. note::
DNS replies with an error code set are not causing a change to
``last_err()``. You have to test for this explicitly.
.. note::
This function is unavailable if a socks5 proxy is configured.
error
-----
@@ -261,10 +293,23 @@ Encode a datastructure into a string.
})
print(x)
keyring
-------
Request all keys from a given namespace. See the `keyring <keyring.html>`__
section for details.
.. code-block:: lua
creds = keyring('aws')
print(creds[1]['accesskey'])
print(creds[1]['secretkey'])
last_err
--------
Returns infos about the last error we've observed, if any. Returns ``nil`` otherwise.
Returns infos about the last error we've observed, if any. Returns ``nil``
otherwise.
.. code-block:: lua
@@ -345,12 +390,12 @@ psl_domain_from_dns_name
------------------------
Returns the parent domain according to the public suffix list. For
``www.a.b.c.d.example.com`` this is going to be ``example.com``.
``www.a.b.c.d.example.co.uk`` this is going to be ``example.co.uk``.
.. code-block:: lua
domain = psl_domain_from_dns_name('www.a.b.c.d.example.com')
print(domain == 'example.com')
domain = psl_domain_from_dns_name('www.a.b.c.d.example.co.uk')
print(domain == 'example.co.uk')
regex_find
----------
@@ -395,6 +440,116 @@ only used for debugging.
sleep(1)
sock_connect
------------
Create a tcp connection.
.. code-block:: lua
sock = sock_connect("127.0.0.1", 1337)
sock_send
---------
Send data to the socket.
.. code-block:: lua
sock_send(sock, "hello world")
sock_recv
---------
Receive up to 4096 bytes from the socket.
.. code-block:: lua
x = sock_recv(sock)
sock_sendline
-------------
Send a string to the socket. A newline is automatically appended to the string.
.. code-block:: lua
sock_sendline(sock, line)
sock_recvline
-------------
Receive a line from the socket. The line includes the newline.
.. code-block:: lua
x = sock_recvline(sock)
sock_recvall
------------
Receive all data from the socket until EOF.
.. code-block:: lua
x = sock_recvall(sock)
sock_recvline_contains
----------------------
Receive lines from the server until a line contains the needle, then return
this line.
.. code-block:: lua
x = sock_recvline_contains(sock, needle)
sock_recvline_regex
-------------------
Receive lines from the server until a line matches the regex, then return this
line.
.. code-block:: lua
x = sock_recvline_regex(sock, "^250 ")
sock_recvn
----------
Receive exactly n bytes from the socket.
.. code-block:: lua
x = sock_recvn(sock, 4)
sock_recvuntil
--------------
Receive until the needle is found, then return all data including the needle.
.. code-block:: lua
x = sock_recvuntil(sock, needle)
sock_sendafter
--------------
Receive until the needle is found, then write data to the socket.
.. code-block:: lua
sock_sendafter(sock, needle, data)
sock_newline
------------
Overwrite the default ``\n`` newline.
.. code-block:: lua
sock_newline(sock, "\r\n")
status
------
@@ -416,6 +571,40 @@ Read a line from stdin. The final newline is not removed.
.. note::
This only works with `sn0int run --stdin`.
url_decode
----------
Parse a query string into a map. For raw percent decoding see url_unescape_.
.. code-block:: lua
v = url_decode('a=b&c=d')
print(v['a'] == 'b')
print(v['c'] == 'd')
url_encode
----------
Encode a map into a query string. For raw percent encoding see url_escape_.
.. code-block:: lua
v = url_encode({
a='b',
c='d',
})
print(v == 'a=b&c=d')
url_escape
----------
Apply url escaping to a string.
.. code-block:: lua
v = url_escape('foo bar?')
print(v == 'foo%20bar%3F')
url_join
--------
@@ -445,11 +634,21 @@ Parse a url into its components. The following components are returned:
.. code-block:: lua
url = url_parse("https://example.com")
url = url_parse('https://example.com')
print(url['scheme'] == 'https')
print(url['host'] == 'example.com')
print(url['path'] == '/')
url_unescape
------------
Remove url escaping of a string.
.. code-block:: lua
v = url_unescape('foo%20bar%3F')
print(v == 'foo bar?')
utf8_decode
-----------

147
docs/sandbox.rst Normal file
View File

@@ -0,0 +1,147 @@
Sandbox
=======
Scripts are generally considered to be untrusted and executed exclusively in a
child process. It's important to note that there's a basic sandbox that's
active on every operating system, and there's a second line of defense on
supported operating systems.
The first line of defense is the restrictive stdlib. It's assumed that and
attacker gains full control over the lua code and is able to call any function
with arbitrary arguments. The stdlib only provides functions that are
considered safe, so for example it's not possible to start a process or open a
file.
The second line of defense is supposed to make sure the system isn't
compromised even if the first layer is fully broken and an attacker gains full
control over the child process.
Right now this is only supported on linux and openbsd.
Linux
-----
On linux we use seccomp to filter all syscalls that we don't need. We also use
chroot to disable filesystem access. It's recommended to install the sn0int
binary with ``cap_sys_chroot`` to make sure unprivileged users can use chroot.
The chroot location is hard coded and all capabilities are removed after the
chroot is done or if no chroot is going to happen.
OpenBSD
-------
On openbsd we're using ``pledge`` to restrict syscalls and ``unveil`` to
restrict filesystem access.
IPC Protocol
------------
The parent process and the child process communicate using an IPC protocol that
is line-based json.
For a simple hello world the parent process is only going to send a single line
to the child process. This line contains:
- The function argument
- The dns config
- Keys that the module has been given access to
- The module metadata and code
- Options, if any
- A socks5 proxy, if any
- The log level
.. code-block:: json
{"arg":null,"dns_config":{"ns":["1.1.1.1:53","1.0.0.1:53"],"tcp":false,"timeout":{"nanos":0,"secs":3}},"keyring":[],"module":{"author":"anonymous","description":"basic selftest","keyring_access":[],"name":"selftest","script":{"code":"-- Description: basic selftest\n-- Version: 0.1.0\n-- License: GPL-3.0\n\nfunction run()\n -- nothing to do here\nend\n"},"source":null,"version":"0.1.0"},"options":{},"proxy":null,"verbose":2}
Saving this line in a file called ``start.json`` and sending it to a sandbox
process should result in the following output::
$ sn0int sandbox foobar < start.json
{"Exit":"Ok"}
$
This line tells us that the script terminated successfully.
There are some functions that cause a notification to the parent process. We
are going to add a call to the ``info()`` function to our module:
.. code-block:: json
{"arg":null,"dns_config":{"ns":["1.1.1.1:53","1.0.0.1:53"],"tcp":false,"timeout":{"nanos":0,"secs":3}},"keyring":[],"module":{"author":"anonymous","description":"basic selftest","keyring_access":[],"name":"selftest","script":{"code":"-- Description: basic selftest\n-- Version: 0.1.0\n-- License: GPL-3.0\n\nfunction run()\n info('ohai')\nend\n"},"source":null,"version":"0.1.0"},"options":{},"proxy":null,"verbose":2}
This is going to print an additional event::
$ sn0int sandbox foobar < start2.json
{"Log":{"Info":"\"ohai\""}}
{"Exit":"Ok"}
$
There are some functions that block the child process until the parent process
sent a reply. These functions are mostly database related functions, since the
child doesn't have direct database access. To demonstrate this, we're going to
write two lines to our file this time, one is the init line and the second one
is the reply for the database event:
.. code-block:: json
{"arg":null,"dns_config":{"ns":["1.1.1.1:53","1.0.0.1:53"],"tcp":false,"timeout":{"nanos":0,"secs":3}},"keyring":[],"module":{"author":"anonymous","description":"basic selftest","keyring_access":[],"name":"selftest","script":{"code":"-- Description: basic selftest\n-- Version: 0.1.0\n-- License: GPL-3.0\n\nfunction run()\n x = db_add('domain', {value=\"example.com\"})\n info(x)\nend\n"},"source":null,"version":"0.1.0"},"options":{},"proxy":null,"verbose":2}
{"Ok":1337}
Results in the following output::
$ target/release/sn0int sandbox foobar < start3.json
{"Database":{"Insert":{"Domain":{"value":"example.com"}}}}
{"Log":{"Info":"1337.0"}}
{"Exit":"Ok"}
$
The first line is a database event and indicates that the child wants to insert
data. After printing this line the child tries to read a line from stdin, this
is why we needed to write two lines to our json file this time. In the second
line the child learns if the insert was successful and which id was assigned to
that entity.
Limitations
-----------
There are some limitations that you should be aware:
- Network access is available and network namespaces aren't isolated. This
means scripts have access to your local network, the internet and also your
localhost loopback interface.
- If chroot is unavailable an attacker could connect to unix domain sockets.
Diagnosing a sandbox failure
----------------------------
You might experience a sandbox failure, especially on architectures that are
less popular. This usually looks like this::
[sn0int][example][kpcyrd/ctlogs] > run
[-] Failed "example.com": EOF while parsing a value at line 1 column 0
[+] Finished kpcyrd/ctlogs (1 errors)
A module that never finishes could also mean an IO thread inside the worker got
killed by the sandbox.
You can try to diagnose this yourself with strace::
strace -f sn0int run -vv ctlogs 2>&1 | tee strace.log
Open ``strace.log``, look out for syscalls that didn't return by searching for
``= ?`` and ignore calls to exit and similar. You are looking for something
like this::
seccomp(SECCOMP_SET_MODE_FILTER, 0, {len=48, filter=0xdd59094e490}) = 0
write(1, "[+] activated!\n", 15[+] activated!
) = 15
getresuid( <unfinished ...>) = ?
+++ killed by SIGSYS (core dumped) +++
This would indicate a call to ``getresuid`` which was not allowed by the
seccomp filter.
If you don't want to diagnose this yourself open a new bug report with as much
information as possible, specifically which distro, which release and which
architecture you're using.

View File

@@ -18,8 +18,12 @@ free to change that to something else::
Every module we're adding to ``~/repos/sn0int-modules`` is now going to be
picked up by sn0int.
Let's add our first module by opening ``~/repos/sn0int-modules/first.lua``.
There's a bit of boilerplate that every module needs to load successfully:
Make sure you're still in the right folder and add your first module::
sn0int new first.lua
This is going to generate some boilerplate for you that every module needs to
load successfully. Afterwards we can edit it like this:
.. code-block:: lua
@@ -125,7 +129,7 @@ our scope and set it to resolvable if ``error`` is ``nil``.
if last_err() then return end
if records['error'] == nil then
db_add('subdomain', arg, {
db_add('subdomain', {
domain_id=arg['id'],
value=subdomain,
resolvable=true,
@@ -159,7 +163,7 @@ After putting everything together, our final module looks like this:
if last_err() then return end
if records['success'] ~= nil then
db_add('subdomain', arg, {
db_add('subdomain', {
domain_id=arg['id'],
value=subdomain,
resolvable=true,
@@ -188,3 +192,40 @@ your identity.
Afterwards publish your module with::
sn0int publish ./first.lua
Reading data from stdin
-----------------------
Sometimes you need to read data that can't be easily accessed from within the
sandbox, like output of other programms or file content. In that case you can
write a module that reads from stdin:
.. code-block:: lua
-- Description: Read from stdin
-- Version: 0.1.0
-- License: GPL-3.0
function run()
while true do
x = stdin_readline()
if x == nil then
break
end
info(x)
end
end
Write it to a file and run it like this::
% echo hello | sn0int run --stdin -vvf stdin.lua
[*] anonymous/stdin : "hello\n"
[+] Finished anonymous/stdin
%
This is going to read one line at a time and allows you to process it with
regular expressions and add data to the database.
.. note::
If you get an error like ``Failed to read stdin: "stdin is unavailable"``
make sure the ``--stdin`` flag is set.

221
docs/structs.rst Normal file
View File

@@ -0,0 +1,221 @@
Structs
=======
This section describes all supported structs in depth. Please refer to this
section if in doubt about the correct usage of fields to ensure
interoperability between modules.
Domains
-------
Represents a registerable domain as defined by the `public suffix list
<https://publicsuffix.org/>`_. If in doubt check `psl_domain_from_dns_name
<reference.html#psl-domain-from-dns-name>`_.
``value``
The domain name, like ``example.co.uk``.
Subdomains
----------
A subdomain of a `domain <#domains>`_. The depth is arbitrary, so
``foo.example.co.uk`` and ``foo.bar.example.co.uk`` are both valid subdomains
of ``example.co.uk``.
``value``
The subdomain, like ``foo.bar.example.co.uk``.
``domain_id``
The numeric id of a domain struct.
``resolvable``
Whether the subdomain can be resolved to a A/AAAA record. nil if unknown.
IpAddrs
-------
An ip address. Note that most of these fields are geoip related and an
approximation instead of an actual location.
``value``
The ip address.
``family``
The address family of the ip address, either ``4`` or ``6``.
``continent``
The continent associated with this ip address.
``continent_code``
The continent code of the ``continent`` field, eg ``NA``.
``country``
The country associated with this ip address.
``country_code``
The country code of the ``country`` field, eg ``US``.
``city``
The city associated with this ip address.
``latitude``
Latitude associated with this ip address.
``longitude``
Longitude associated with this ip address.
``asn``
The number of the autonomous system this ip belongs to.
``as_org``
The organization of the autonomous system this ip belongs to.
``description``
This field is sn0int internal if we have additional information about this
ip address, for example technical identifiers from aws.
``reverse_dns``
The reverse dns name setup for this ip address.
URLs
----
``subdomain_id``
The numeric id of a subdomain struct.
``value``
The url, including a schema, hostname and path.
``status``
The http status code, like ``200``.
``body``
The raw response body. This can be any mime type.
``online``
Whether or not the url gives a http response (even if it's an error).
``title``
The parsed ``<title>`` of the page, if available.
``redirect``
If the server replied with a redirect, this is the url it redirected to.
Emails
------
``value``
The email address.
``valid``
Whether that email address is valid or has been disabled.
Phonenumbers
------------
``value``
The phone number in E.164 format (+491234567)
``name``
An alias we can assign to this phone number. This alias is sn0int internal.
``valid``
Whether the number is assigned to a customer.
``last_online``
The last time this number has been online.
``country``
The country this number is associated with.
``carrier``
The name of the carrier this numer is registered with.
``line``
The type of the phone number, can be ``landline``, ``mobile`` or ``voip``.
``is_ported``
Whether this number has been ported to a different carrier.
``last_ported``
The last time this number has been ported.
``caller_name``
The name of the owner of the phone number.
``caller_type``
The type of caller, eg ``business`` or ``consumer``.
Devices
-------
``value``
The devices mac address or another identifier if needed.
``name``
An alias we can assign to this device. This alias is sn0int internal.
``hostname``
The hostname configured on the device.
``vendor``
The hardware vendor of the device. This is usually derived from the mac
address.
``last_seen``
The last time we've observed the device somewhere.
Networks
--------
A wired or wireless network at a specific location that a device could be
connected to.
``value``
The network name. This can be an ssid or any other identifier but should be
unique.
``latitude``
Latitude of the networks location.
``longitude``
Longitude of the networks location.
Accounts
--------
A users account or profile on a webservice, like github or instagram.
``service``
The identifier of the service/website. It's recommended to use the websites
domain for this as defined in `Domains`_.
``username``
The users unique identifier, like the login name. If the login name is not
known or the system doesn't use login names, use the email address instead.
``displayname``
The users display name. This name is often not unique and may contain the
users real name.
``email``
The email address associated with the account.
``url``
The url of the public profile if available.
``last_seen``
The last time this account has been active/online.
Breaches
--------
Either a breach of a specific website, a breach compilation or a breach
notification service.
``value``
The name of the breach, breach compilation or notification service.
Relations
---------
Relations are linking two structs together. The link may contain additional information.
subdomain_ipaddr
~~~~~~~~~~~~~~~~
Links an ip address to a subdomain.
``subdomain_id``
The numeric id of a subdomain struct.
``ip_addr_id``
The numeric id of an ip addr struct.
network_device
~~~~~~~~~~~~~~
Links a device to a network. This is commonly used with ``db_add_ttl`` so the
link automatically expires. This is frequently used to monitor networks for
known and unknown devices.
``network_id``
The numeric id of a network struct.
``device_id``
The numeric id of a device struct.
``ipaddr``
The ip address assigned to the device.
``last_seen``
The last time we've seen the device on that network.
breach_email
~~~~~~~~~~~~
Links an email to a breach. If we know the password as well we can add it to
the link. If we don't know the password we can leave it blank and fill it
later. An email can be linked to a breach multiple times with different
passwords. There is a special upserting logic in place to support this.
``breach_id``
The numeric id of a breach struct.
``email_id``
The numeric id of an email struct.
``password``
The password for that email in the breach.

View File

@@ -1,32 +0,0 @@
extern crate sn0int;
extern crate env_logger;
extern crate maxminddb;
use std::env;
use sn0int::errors::*;
use sn0int::geoip::{AsnDB, Maxmind};
fn run() -> Result<()> {
let asndb = AsnDB::open_or_download()?;
for arg in env::args().skip(1) {
let ip = arg.parse()?;
let asn = asndb.lookup(ip)?;
println!("{:#?}", asn);
}
Ok(())
}
fn main() {
env_logger::init();
if let Err(err) = run() {
eprintln!("Error: {}", err);
for cause in err.iter_chain().skip(1) {
eprintln!("Because: {}", cause);
}
std::process::exit(1);
}
}

View File

@@ -1,31 +0,0 @@
extern crate sn0int;
extern crate env_logger;
use std::env;
use sn0int::errors::*;
use sn0int::geoip::{GeoIP, Maxmind};
fn run() -> Result<()> {
let geoip = GeoIP::open_or_download()?;
for arg in env::args().skip(1) {
let ip = arg.parse()?;
let lookup = geoip.lookup(ip)?;
println!("{:#?}", lookup);
}
Ok(())
}
fn main() {
env_logger::init();
if let Err(err) = run() {
eprintln!("Error: {}", err);
for cause in err.iter_chain().skip(1) {
eprintln!("Because: {}", cause);
}
std::process::exit(1);
}
}

View File

@@ -1,50 +0,0 @@
extern crate sn0int;
extern crate env_logger;
extern crate chrootable_https;
#[macro_use] extern crate log;
// workaround for rustc 1.29.2 support
#[cfg(not(target_os = "openbsd"))]
extern crate structopt;
#[cfg(target_os = "openbsd")]
#[macro_use] extern crate structopt;
use sn0int::errors::*;
use sn0int::geoip::{GeoIP, Maxmind};
use sn0int::paths;
use std::fs;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub struct Args {
url: String,
filter: String,
target: String,
#[structopt(short="e", long="extract-only")]
extract_only: bool,
}
fn run() -> Result<()> {
let args = Args::from_args();
debug!("{:?}", args);
let path = paths::cache_dir()?.join(&args.target);
if args.extract_only {
let body = fs::read(&args.url)?;
sn0int::archive::extract(&mut &body[..], &args.filter, path)?;
} else {
GeoIP::download(path, &args.filter, &args.url)?;
}
Ok(())
}
fn main() {
env_logger::init();
if let Err(err) = run() {
eprintln!("Error: {}", err);
for cause in err.iter_chain().skip(1) {
eprintln!("Because: {}", cause);
}
std::process::exit(1);
}
}

104
examples/maxmind.rs Normal file
View File

@@ -0,0 +1,104 @@
extern crate sn0int;
extern crate env_logger;
extern crate chrootable_https;
#[macro_use] extern crate log;
// workaround for rustc 1.29.2 support
#[cfg(not(target_os = "openbsd"))]
extern crate structopt;
#[cfg(target_os = "openbsd")]
#[macro_use] extern crate structopt;
use sn0int::errors::*;
use sn0int::geoip::{AsnDB, GeoIP, Maxmind};
use sn0int::paths;
use std::fs;
use std::net::IpAddr;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub enum Args {
#[structopt(name="dl")]
Download(Download),
#[structopt(name="asn")]
Asn(AsnArgs),
#[structopt(name="geoip")]
GeoIP(GeoIPArgs),
}
#[derive(Debug, StructOpt)]
pub struct Download {
url: String,
filter: String,
target: String,
#[structopt(short="e", long="extract-only")]
extract_only: bool,
}
impl Download {
fn run(&self) -> Result<()> {
let path = paths::cache_dir()?.join(&self.target);
if self.extract_only {
let body = fs::read(&self.url)?;
sn0int::archive::extract(&mut &body[..], &self.filter, path)?;
} else {
GeoIP::download(path, &self.filter, &self.url)?;
}
Ok(())
}
}
#[derive(Debug, StructOpt)]
pub struct AsnArgs {
ip: IpAddr,
}
impl AsnArgs {
fn run(&self) -> Result<()> {
let asndb = AsnDB::open_or_download()?;
let asn = asndb.lookup(self.ip)?;
println!("{:#?}", asn);
Ok(())
}
}
#[derive(Debug, StructOpt)]
pub struct GeoIPArgs {
ip: IpAddr,
}
impl GeoIPArgs {
fn run(&self) -> Result<()> {
let geoip = GeoIP::open_or_download()?;
let lookup = geoip.lookup(self.ip)?;
println!("{:#?}", lookup);
Ok(())
}
}
fn run() -> Result<()> {
let args = Args::from_args();
debug!("{:?}", args);
match args {
Args::Download(args) => args.run(),
Args::Asn(args) => args.run(),
Args::GeoIP(args) => args.run(),
}
}
fn main() {
env_logger::init();
if let Err(err) = run() {
eprintln!("Error: {}", err);
for cause in err.iter_chain().skip(1) {
eprintln!("Because: {}", cause);
}
std::process::exit(1);
}
}

View File

@@ -1,20 +1,67 @@
extern crate sn0int;
use std::env;
use std::thread;
use std::time::Duration;
use sn0int::term::{SPINNERS, Spinner};
use sn0int::term::{SPINNERS, Spinner, StackedSpinners};
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub enum Args {
#[structopt(name="single")]
Single(Single),
#[structopt(name="stacked")]
Stacked(Stacked),
}
#[derive(Debug, StructOpt)]
pub struct Single {
idx: usize,
#[structopt(long="ticks", default_value="100")]
ticks: usize,
}
impl Single {
fn run(&self) {
let mut s = Spinner::new(SPINNERS[self.idx], "Demo".to_string());
for _ in 0..self.ticks {
thread::sleep(Duration::from_millis(100));
s.tick();
}
s.finish("Done".to_string());
}
}
#[derive(Debug, StructOpt)]
pub struct Stacked {
}
impl Stacked {
fn run(&self) {
let mut stack = StackedSpinners::new();
stack.add("1".into(), String::from("spinner1"));
stack.add("2".into(), String::from("spinner2"));
stack.add("3".into(), String::from("spinner3"));
for x in 1..=3 {
for _ in 0..50 {
thread::sleep(Duration::from_millis(100));
stack.tick();
}
// stack.log("ohai");
stack.remove(&x.to_string());
}
stack.clear();
// stack.finish("Done".to_string());
}
}
fn main() {
let idx = env::args().skip(1).next().expect("Expected argv[1]");
let idx = idx.parse::<usize>().expect("argv[1] is not a number");
let mut s = Spinner::new(SPINNERS[idx], "Demo".to_string());
for _ in 0..100 {
thread::sleep(Duration::from_millis(100));
s.tick();
let args = Args::from_args();
match args {
Args::Single(args) => args.run(),
Args::Stacked(args) => args.run(),
}
s.finish("Done".to_string());
}

View File

@@ -1,25 +0,0 @@
extern crate sn0int;
use sn0int::term::StackedSpinners;
use std::thread;
use std::time::Duration;
fn main() {
let mut stack = StackedSpinners::new();
stack.add("1".into(), String::from("spinner1"));
stack.add("2".into(), String::from("spinner2"));
stack.add("3".into(), String::from("spinner3"));
for x in 1..=3 {
for _ in 0..50 {
thread::sleep(Duration::from_millis(100));
stack.tick();
}
// stack.log("ohai");
stack.remove(&x.to_string());
}
stack.clear();
// stack.finish("Done".to_string());
}

View File

@@ -0,0 +1 @@
DROP TABLE phonenumbers;

View File

@@ -0,0 +1,16 @@
CREATE TABLE phonenumbers (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
name VARCHAR,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
valid BOOLEAN,
last_online DATETIME,
country VARCHAR,
carrier VARCHAR,
line VARCHAR,
is_ported BOOLEAN,
last_ported DATETIME,
caller_name VARCHAR,
caller_type VARCHAR,
CONSTRAINT phonenumber_unique UNIQUE (value)
);

View File

@@ -0,0 +1,27 @@
PRAGMA foreign_keys=off;
CREATE TABLE _ipaddrs_new (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
family VARCHAR NOT NULL,
value VARCHAR NOT NULL,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
continent VARCHAR,
continent_code VARCHAR,
country VARCHAR,
country_code VARCHAR,
city VARCHAR,
latitude FLOAT,
longitude FLOAT,
asn INTEGER,
as_org VARCHAR,
CONSTRAINT ipaddr_unique UNIQUE (value)
);
INSERT INTO _ipaddrs_new (id, family, value, unscoped, continent, continent_code, city, latitude, longitude, asn, as_org)
SELECT id, family, value, unscoped, continent, continent_code, city, latitude, longitude, asn, as_org
FROM ipaddrs;
DROP TABLE ipaddrs;
ALTER TABLE _ipaddrs_new RENAME TO ipaddrs;
PRAGMA foreign_keys=on;

View File

@@ -0,0 +1,2 @@
ALTER TABLE ipaddrs ADD COLUMN description VARCHAR;
ALTER TABLE ipaddrs ADD COLUMN reverse_dns VARCHAR;

View File

@@ -0,0 +1,3 @@
DROP TABLE network_devices;
DROP TABLE networks;
DROP TABLE devices;

View File

@@ -0,0 +1,30 @@
CREATE TABLE networks (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
latitude FLOAT,
longitude FLOAT,
CONSTRAINT network_unique UNIQUE (value)
);
CREATE TABLE devices (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
name VARCHAR,
hostname VARCHAR,
vendor VARCHAR,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
last_seen DATETIME,
CONSTRAINT device_unique UNIQUE (value)
);
CREATE TABLE network_devices (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
network_id INTEGER NOT NULL,
device_id INTEGER NOT NULL,
ipaddr VARCHAR,
last_seen DATETIME,
FOREIGN KEY(network_id) REFERENCES networks(id) ON DELETE CASCADE,
FOREIGN KEY(device_id) REFERENCES devices(id) ON DELETE CASCADE,
CONSTRAINT network_device_unique UNIQUE (network_id, device_id)
);

View File

@@ -0,0 +1 @@
DROP TABLE ttls;

View File

@@ -0,0 +1,7 @@
CREATE TABLE ttls (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
family VARCHAR NOT NULL,
key INTEGER NOT NULL,
expire DATETIME NOT NULL,
CONSTRAINT ttl_unique UNIQUE (family, key)
);

View File

@@ -0,0 +1 @@
DROP TABLE accounts;

View File

@@ -0,0 +1,12 @@
CREATE TABLE accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
service VARCHAR NOT NULL,
username VARCHAR NOT NULL,
displayname VARCHAR,
email VARCHAR,
url VARCHAR,
last_seen DATETIME,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
CONSTRAINT account_unique UNIQUE (value)
);

View File

@@ -0,0 +1,2 @@
DROP TABLE breach_emails;
DROP TABLE breaches;

View File

@@ -0,0 +1,16 @@
CREATE TABLE breaches (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
value VARCHAR NOT NULL,
unscoped BOOLEAN DEFAULT 0 NOT NULL,
CONSTRAINT breach_unique UNIQUE (value)
);
CREATE TABLE breach_emails (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
breach_id INTEGER NOT NULL,
email_id INTEGER NOT NULL,
password VARCHAR,
FOREIGN KEY(breach_id) REFERENCES breaches(id) ON DELETE CASCADE,
FOREIGN KEY(email_id) REFERENCES emails(id) ON DELETE CASCADE,
CONSTRAINT breach_emails_unique UNIQUE (breach_id, email_id, password)
);

View File

@@ -1,10 +1,20 @@
-- Description: Parse arp-scan output
-- Version: 0.1.0
-- Version: 0.3.0
-- License: GPL-3.0
-- sudo arp-scan -qglI wlp3s0
function run()
network = getopt('network')
if not network then
return 'network option is missing'
end
network_id = db_select('network', network)
if not network_id then
return 'network not found in database'
end
while true do
x = stdin_readline()
if x == nil then
@@ -13,9 +23,23 @@ function run()
m = regex_find('(.+)\t(.+)', x)
if m ~= nil then
ip = m[2]
ipaddr = m[2]
mac = m[3]
info(json_encode({ip, mac}))
now = datetime()
device_id = db_add('device', {
value=mac,
last_seen=now,
})
if last_err() then return end
db_add_ttl('network-device', {
network_id=network_id,
device_id=device_id,
ipaddr=ipaddr,
last_seen=now,
}, 300)
if last_err() then return end
end
end
end

View File

@@ -1,5 +1,5 @@
-- Description: Try a zone transfer for subdomains
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: domains
-- License: GPL-3.0
@@ -39,7 +39,7 @@ end
function iter_axfr(zone, arg)
local name, r, m, domain
debug(json_encode(arg))
debug(arg)
name = arg[1]
r = arg[2]

View File

@@ -1,5 +1,5 @@
-- Description: Query for CNAMES to find subdomains
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: subdomains
-- License: GPL-3.0

View File

@@ -1,11 +1,59 @@
-- Description: Query certificate transparency logs to discover subdomains
-- Version: 0.1.0
-- Version: 0.4.0
-- Source: domains
-- License: GPL-3.0
function run(arg)
session = http_mksession()
function each_name(name)
local domain_id, psl_domain
if seen[name] == 1 then
return
end
seen[name] = 1
debug(name)
if name:find('*.') == 1 then
-- ignore wildcard domains
return
end
-- the cert might be valid for subdomains that do not belong to the
-- domain we started with
psl_domain = psl_domain_from_dns_name(name)
domain_id = domains[psl_domain]
if domain_id == nil then
if any_domain then
-- unknown domains should be added to database
domain_id = db_add('domain', {
value=psl_domain,
})
else
-- only use domains that are already in scope
domain_id = db_select('domain', psl_domain)
end
-- if we didn't get a valid id, skip
if domain_id == nil then
return
end
domains[psl_domain] = domain_id
end
db_add('subdomain', {
domain_id=domain_id,
value=name,
})
end
function run(arg)
full = getopt('full') ~= nil
any_domain = getopt('any-domain') ~= nil
domains = {}
domains[arg['value']] = arg['id']
session = http_mksession()
req = http_request(session, 'GET', 'https://crt.sh/', {
query={
q='%.' .. arg['value'],
@@ -17,7 +65,7 @@ function run(arg)
if last_err() then return end
if resp['status'] ~= 200 then return 'http error: ' .. resp['status'] end
certs = json_decode_stream(resp['text'])
certs = json_decode(resp['text'])
if last_err() then return end
seen = {}
@@ -25,22 +73,32 @@ function run(arg)
i = 1
while i <= #certs do
c = certs[i]
-- print(c)
debug(c)
name = c['name_value']
debug(json_encode(name))
if name:find("*.") == 1 then
-- ignore wildcard domains
seen[name] = 1
end
if seen[name] == nil then
db_add('subdomain', {
domain_id=arg['id'],
value=name,
if full then
-- fetch certificate
id = c['min_cert_id']
req = http_request(session, 'GET', 'https://crt.sh/', {
query={
d=id .. '', -- TODO: find nicer way for tostring
}
})
seen[name] = 1
resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then return 'http error: ' .. resp['status'] end
-- iterate over all valid names
crt = x509_parse_pem(resp['text'])
if last_err() then return end
names = crt['valid_names']
j = 1
while j <= #names do
each_name(names[j])
j = j+1
end
else
each_name(c['name_value'])
end
i = i+1

View File

@@ -0,0 +1,91 @@
-- Description: Export dhcp leases from ddwrt webinterface
-- Version: 0.1.0
-- License: GPL-3.0
function run()
network = getopt('network')
if not network then
return 'network option is missing'
end
network_id = db_select('network', network)
if not network_id then
return 'network not found in database'
end
skip_redacted = not getopt('use-redacted')
router = getopt('router') -- http://192.0.2.1/
if not router then
return 'router option is missing (http://192.0.2.1/)'
end
username = getopt('user')
password = getopt('password')
options = {}
if username and password then
options['basic_auth'] = {username, password}
end
-- request status page
session = http_mksession()
url = url_join(router, '/Info.live.htm')
req = http_request(session, 'GET', url, options)
resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then
return 'http error: ' .. resp['status']
end
txt = resp['text']
debug(txt)
-- extract leases from response
dhcp_section = regex_find('\\{dhcp_leases:: ([^\\}]+)\\}', txt)
if last_err() then return end
if not dhcp_section then
return 'Failed to get dhcp lease section'
end
leases = regex_find_all('\'([^\']+)\',\'([^\']+)\',\'([^\']+)\',\'[^\']+\',\'[^\']+\'', dhcp_section[2])
if last_err() then return end
now = datetime()
-- add devices to database
local i = 1
while i <= #leases do
local hostname = leases[i][2]
local ipaddr = leases[i][3]
local macaddr = leases[i][4]
debug({
hostname=hostname,
ipaddr=ipaddr,
macaddr=macaddr,
})
if skip_redacted and macaddr:match('^xx:xx:') then
info('Skipping redacted macaddr')
else
local device = {
value=macaddr,
last_seen=now,
}
if hostname ~= '*' then
device['hostname'] = hostname
end
local device_id = db_add('device', device)
db_add_ttl('network-device', {
network_id=network_id,
device_id=device_id,
ipaddr=ipaddr,
last_seen=now,
}, 120)
end
i = i+1
end
end

32
modules/dev/dns-ptr.lua Normal file
View File

@@ -0,0 +1,32 @@
-- Description: Run reverse dns lookups
-- Version: 0.1.0
-- Source: ipaddrs
-- License: GPL-3.0
function run(arg)
if arg['family'] == '4' then
m = regex_find('^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$', arg['value'])
q = m[5] .. '.' .. m[4] .. '.' .. m[3] .. '.' .. m[2] .. '.in-addr.arpa'
debug('Resolving: ' .. q)
records = dns(q, {
record='PTR',
})
if last_err() then return end
if records['error'] ~= nil then return end
records = records['answers']
i = 1
while records[i] ~= nil do
r = records[i][2]
if r['PTR'] then
db_update('ipaddr', arg, {
reverse_dns=r['PTR'],
})
if last_err() then return end
end
i = i+1
end
end
end

View File

@@ -1,5 +1,5 @@
-- Description: Query subdomains to discovery ip addresses and verify the record is visible
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: subdomains
-- License: GPL-3.0

View File

@@ -0,0 +1,28 @@
-- Description: Search for git checkouts in webroot
-- Version: 0.1.0
-- Source: urls
-- License: GPL-3.0
function run(arg)
url = url_join(arg['value'], '.git/HEAD')
session = http_mksession()
req = http_request(session, 'GET', url, {})
reply = http_send(req)
if last_err() then return end
if reply['status'] ~= 200 then
return
end
if not regex_find('^ref: ', reply['text']) then
return
end
db_add('url', {
subdomain_id=arg['subdomain_id'],
value=url,
status=reply['status'],
body=reply['text'],
})
end

76
modules/dev/github.lua Normal file
View File

@@ -0,0 +1,76 @@
-- Description: Collect data from github profiles
-- Version: 0.1.0
-- Source: accounts:github.com
-- License: GPL-3.0
function api_get(url)
local req = http_request(session, 'GET', url, {})
local resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then return 'invalid status code' end
local data = json_decode(resp['text'])
if last_err() then return end
return data
end
function scan4email(username)
local url = 'https://api.github.com/users/' .. username .. '/repos'
local repos = api_get(url)
if last_err() then return end
i = 1
while i <= #repos do
local repo = repos[i]
debug(repo)
local commits = api_get(repo['url'] .. '/commits')
if last_err() then return end
j = 1
while j <= #commits do
local commit = commits[j]
debug(commit)
if commit['author']['login'] == username then
-- name = commit['commit']['author']['name']
local email = commit['commit']['author']['email']
return email
end
if commit['committer']['login'] == username then
-- name = commit['commit']['committer']['name']
local email = commit['commit']['committer']['email']
return email
end
j = j+1
end
i = i+1
end
end
function run(arg)
session = http_mksession()
local url = 'https://api.github.com/users/' .. arg['username']
local data = api_get(url)
if last_err() then return end
debug(data)
-- company = data['company']
-- location = data['location']
-- homepage = data['blog']
local email = data['email']
if not email and not arg['email'] then
email = scan4email(arg['username'])
if last_err() then return end
end
db_update('account', arg, {
url=data['html_url'],
displayname=data['name'],
email=email,
})
end

36
modules/dev/instagram.lua Normal file
View File

@@ -0,0 +1,36 @@
-- Description: Collect data from instagram profiles
-- Version: 0.1.0
-- Source: accounts:instagram.com
-- License: GPL-3.0
function run(arg)
local session = http_mksession()
local url = 'https://www.instagram.com/' .. arg['username'] .. '/'
local req = http_request(session, 'GET', url, {})
local resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then return 'invalid status code' end
local html = resp['text']
local ld = html_select(html, 'script[type="application/ld+json"]')
if last_err() then return end
debug(ld)
local ld = json_decode(ld['text'])
if last_err() then return end
debug(ld)
if ld['email'] then
db_add('email', {
value=ld['email'],
})
end
-- homepage=ld['url']
db_update('account', arg, {
displayname=ld['name'],
email=ld['email'],
url=url,
})
end

View File

@@ -0,0 +1,78 @@
-- Description: Parse isc-dhcpd dhcpd.leases(5)
-- Version: 0.2.0
-- License: GPL-3.0
-- cat /var/lib/dhcpd/dhcpd.leases
function add(lease)
if not lease['active'] then return end
now = datetime()
device_id = db_add('device', {
value=lease['mac'],
hostname=lease['hostname'],
last_seen=now,
})
if last_err() then return end
db_add_ttl('network-device', {
network_id=network_id,
device_id=device_id,
ipaddr=lease['ipaddr'],
last_seen=now,
}, 180)
if last_err() then return end
end
function each_line(x)
debug(x)
m = regex_find('^lease (\\S+) \\{\n$', x)
if m then
lease = {}
debug('ipaddr=' .. m[2])
lease['ipaddr'] = m[2]
end
m = regex_find('^\\s*hardware ethernet (\\S+);\n$', x)
if m then
debug('mac=' .. m[2])
lease['mac'] = m[2]
end
m = regex_find('^\\s*client-hostname \"(.+)\";\n$', x)
if m then
debug('hostname=' .. m[2])
lease['hostname'] = m[2]
end
m = regex_find('^\\s*binding state active;\n$', x)
if m then
debug('active=true')
lease['active'] = true
end
m = regex_find('^\\}\n$', x)
if m then
add(lease)
end
end
function run()
network = getopt('network')
if not network then
return 'network option is missing'
end
network_id = db_select('network', network)
if not network_id then
return 'network not found in database'
end
while true do
x = stdin_readline()
if x == nil then
break
end
if not regex_find('^\\s*(#.*|\\s*)\n$', x) then
each_line(x)
end
end
end

View File

@@ -0,0 +1,77 @@
-- Description: Parse iw station dump
-- Version: 0.2.0
-- License: GPL-3.0
-- iw dev wlan0 station dump
function add(client)
if
client['authenticated'] == 'yes' and
client['authorized'] == 'yes' and
client['mac']
then
debug(client)
now = datetime()
device_id = db_add('device', {
value=client['mac'],
last_seen=now,
})
if last_err() then return end
db_add_ttl('network-device', {
network_id=network_id,
device_id=device_id,
last_seen=now,
}, 180)
if last_err() then return end
end
client = nil
end
function each_line(x)
debug(x)
m = regex_find('^Station (\\S+)', x)
if m then
if client then
add(client)
end
client = {}
client['mac'] = m[2]
debug('mac=' .. m[2])
end
m = regex_find('^\\s+([^:]+):\\s*(.+)\n$', x)
if m and client then
client[m[2]] = m[3]
debug(m[2] .. '=' .. m[3])
end
end
function run()
network = getopt('network')
if not network then
return 'network option is missing'
end
network_id = db_select('network', network)
if not network_id then
return 'network not found in database'
end
client = nil
while true do
x = stdin_readline()
if x == nil then
break
end
each_line(x)
end
if client then
add(client)
end
end

90
modules/dev/namechk.lua Normal file
View File

@@ -0,0 +1,90 @@
-- Description: Find accounts by username with namechk.com
-- Version: 0.1.0
-- Source: accounts
-- License: GPL-3.0
function get_services(html)
local divs = html_select_list(html, '.service')
if last_err() then return end
local services = {}
local i = 1
while i <= #divs do
services[i] = divs[i]['attrs']['data-name']
i = i+1
end
return services
end
function run(arg)
-- setup session
local session = http_mksession()
local req = http_request(session, 'GET', 'https://namechk.com/', {})
local resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then return 'http error: ' .. resp['status'] end
local token = html_select(resp['text'], 'input[name="authenticity_token"]')
local auth_token = token['attrs']['value']
local headers = {}
headers['X-CSRF-Token'] = authenticity_token
local services = get_services(resp['text'])
debug({
auth_token=auth_token,
services=services,
})
-- trigger the scan
local req = http_request(session, 'POST', 'https://namechk.com/', {
headers=headers,
form={
authenticity_token=auth_token,
q=arg['username'],
}
})
local resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then return 'http error: ' .. resp['status'] end
debug(resp)
local scan = json_decode(resp['text'])
if last_err() then return end
local scan_token = scan['valid']
-- get results
local i = 1
while i <= #services do
debug(services[i])
local req = http_request(session, 'POST', 'https://namechk.com/services/check', {
headers=headers,
form={
token=scan_token,
fat=auth_token,
service=services[i],
}
})
local resp = http_send(req)
if last_err() then return end
if resp['status'] == 200 then
local acc = json_decode(resp['text'])
if last_err() then return end
debug(acc)
if acc ~= nil and not acc['available'] and acc['status'] == 'unavailable' then
db_add('account', {
service=services[i],
username=arg['username'],
url=acc['callback_url'],
})
end
end
i = i+1
end
end

View File

@@ -1,5 +1,5 @@
-- Description: Query alienvault otx passive dns for subdomains of a domain
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: domains
-- License: GPL-3.0

View File

@@ -0,0 +1,79 @@
-- Description: Passive arp-scanner with sniffglue
-- Version: 0.1.0
-- License: GPL-3.0
-- sudo sniffglue -jv enp0s25
function each_frame(frame)
if not frame['Ether'] then return end
local arp = frame['Ether'][2]['Arp']
if not arp then return end
if arp['Request'] then
arp = arp['Request']
elseif arp['Reply'] then
arp = arp['Reply']
else
-- unknown, abort
return
end
debug(arp)
-- TODO: this might change to a string in the future
local mac = mac(arp['src_mac'])
local ipaddr = arp['src_addr']
debug({src_mac=mac, src_addr=ipaddr})
local now = datetime()
local device_id = db_add('device', {
value=mac,
last_seen=now,
})
if last_err() then return end
db_add_ttl('network-device', {
network_id=network_id,
device_id=device_id,
ipaddr=ipaddr,
last_seen=now,
}, 120)
if last_err() then return end
end
function mac(m)
return
hex({m[1]}) .. ':' ..
hex({m[2]}) .. ':' ..
hex({m[3]}) .. ':' ..
hex({m[4]}) .. ':' ..
hex({m[5]}) .. ':' ..
hex({m[6]})
end
function run()
network = getopt('network')
if not network then
return 'network option is missing'
end
network_id = db_select('network', network)
if not network_id then
return 'network not found in database'
end
while true do
local x = stdin_readline()
if x == nil then
break
end
local frame = json_decode(x)
if last_err() then return end
each_frame(frame)
if last_err() then return end
end
end

106
modules/dev/phpmyadmin.lua Normal file
View File

@@ -0,0 +1,106 @@
-- Description: Search for phpmyadmin
-- Version: 0.1.0
-- Source: urls
-- License: GPL-3.0
function run(arg)
paths = {
"phpmyadmin/index.php",
"phpMyAdmin/index.php",
"pmd/index.php",
"pma/index.php",
"PMA/index.php",
"PMA2/index.php",
"pmamy/index.php",
"pmamy2/index.php",
"mysql/index.php",
"admin/index.php",
"db/index.php",
"dbadmin/index.php",
"web/phpMyAdmin/index.php",
"admin/pma/index.php",
"admin/PMA/index.php",
"admin/mysql/index.php",
"admin/mysql2/index.php",
"admin/phpmyadmin/index.php",
"admin/phpMyAdmin/index.php",
"admin/phpmyadmin2/index.php",
"mysqladmin/index.php",
"mysql-admin/index.php",
"mysql_admin/index.php",
"phpadmin/index.php",
"phpAdmin/index.php",
"phpmyadmin0/index.php",
"phpmyadmin1/index.php",
"phpmyadmin2/index.php",
"phpMyAdmin-4.4.0/index.php",
"myadmin/index.php",
"myadmin2/index.php",
"xampp/phpmyadmin/index.php",
"phpMyadmin_bak/index.php",
"www/phpMyAdmin/index.php",
"tools/phpMyAdmin/index.php",
"phpmyadmin-old/index.php",
"phpMyAdminold/index.php",
"phpMyAdmin.old/index.php",
"pma-old/index.php",
"claroline/phpMyAdmin/index.php",
"typo3/phpmyadmin/index.php",
"phpma/index.php",
"phpmyadmin/phpmyadmin/index.php",
"phpMyAdmin/phpMyAdmin/index.php",
"phpMyAbmin/index.php",
"phpMyAdmin__/index.php",
"phpMyAdmin+++---/index.php",
"v/index.php",
"phpmyadm1n/index.php",
"phpMyAdm1n/index.php",
"shaAdmin/index.php",
"phpMyadmi/index.php",
"phpMyAdmion/index.php",
"MyAdmin/index.php",
"phpMyAdmin1/index.php",
"phpMyAdmin123/index.php",
"pwd/index.php",
"phpMyAdmina/index.php",
"program/index.php",
"shopdb/index.php",
"phppma/index.php",
"phpmy/index.php",
"mysql/admin/index.php",
"mysql/dbadmin/index.php",
"mysql/sqlmanager/index.php",
"mysql/mysqlmanager/index.php",
"wp-content/plugins/portable-phpmyadmin/wp-pma-mod/index.php",
}
session = http_mksession()
i = 1
while i <= #paths do
p = paths[i]
url = url_join(arg['value'], p)
debug(url)
req = http_request(session, 'GET', url, {
timeout=5000
})
reply = http_send(req)
debug(reply)
if last_err() then
clear_err()
else
if reply['status'] == 200 then
db_add('url', {
subdomain_id=arg['subdomain_id'],
value=url,
status=reply['status'],
body=reply['text'],
})
end
end
i = i+1
end
end

View File

@@ -0,0 +1,90 @@
-- Description: Verify email address by asking the smtp server
-- Version: 0.1.0
-- Source: emails
-- License: GPL-3.0
function find_mx(domain)
local records, i, r
records = dns(domain, {
record='MX',
})
if last_err() then return end
if records['error'] ~= nil then return end
records = records['answers']
-- debug(records)
i = 1
while i <= #records do
r = records[i][2]['MX']
if r then
debug('mx: ' .. r[2])
return r[2]
end
i = i+1
end
end
function run(arg)
-- extract domain
domain = arg['value']:match('@(.*)')
if doman ~= nil then
-- malformed domain
return
end
-- mx lookup
mx = find_mx(domain)
if last_err() then return end
if not mx then return end
-- create connection
c = sock_connect(mx, 25, {})
if last_err() then return end
l = sock_recvline(c)
if last_err() then return end
debug(l)
-- send hello
sock_sendline(c, 'ehlo localhost')
if last_err() then return end
l = sock_recvline_regex(c, '^250 ')
if last_err() then return end
debug(l)
-- send email
sock_sendline(c, 'mail from:<root@localhost>')
if last_err() then return end
l = sock_recvline(c)
if last_err() then return end
debug(l)
-- send rcpt
sock_sendline(c, 'rcpt to:<' .. arg['value'] .. '>')
if last_err() then return end
l = sock_recvline(c)
if last_err() then return end
debug(l)
-- check status
verified = nil
if l:match('^2') then
debug('email is valid')
verified = true
elseif l:match('^5') then
debug('email is invalid')
verified = false
elseif l:match('^4') then
debug('unknown status, temporary delivery failure')
end
if verified ~= nil then
db_update('email', arg, {
valid=verified,
})
end
end

View File

@@ -1,5 +1,5 @@
-- Description: Query ThreatMiner passive dns for subdomains of an ip address
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: ipaddrs
-- License: GPL-3.0

View File

@@ -1,5 +1,5 @@
-- Description: Query ThreatMiner passive dns for subdomains of a domain
-- Version: 0.1.0
-- Version: 0.2.0
-- Source: domains
-- License: GPL-3.0

View File

@@ -0,0 +1,48 @@
-- Description: Query thunderbird autoconfig db for subdomains
-- Version: 0.1.0
-- Source: domains
-- License: GPL-3.0
function run(arg)
session = http_mksession()
-- check if an autoconfig exists without disclosing our target yet
req = http_request(session, 'GET', 'https://autoconfig.thunderbird.net/v1.1/', {})
resp = http_send(req)
if last_err() then return end
if resp['status'] ~= 200 then
return 'index request failed'
end
if resp['text']:find(arg['value'], 1, true) == nil then
debug('no autoconfig available')
return
end
-- request config
req = http_request(session, 'GET', 'https://autoconfig.thunderbird.net/v1.1/' .. arg['value'], {})
resp = http_send(req)
if last_err() then return end
m = regex_find_all('<hostname>([^<]+)</hostname>', resp['text'])
i = 1
while i <= #m do
subdomain = m[i][2]
domain = psl_domain_from_dns_name(subdomain)
if last_err() then return end
domain_id = db_select('domain', domain)
if last_err() then return end
db_add('subdomain', {
domain_id=domain_id,
value=subdomain,
})
if last_err() then return end
i = i+1
end
end

View File

@@ -0,0 +1,48 @@
-- Description: Retrieve additional information about a phone number
-- Version: 0.1.0
-- Source: phonenumbers
-- Keyring-Access: twilio
-- License: GPL-3.0
function run(arg)
number = url_escape(arg['value'])
--url = 'https://lookups.twilio.com/v1/PhoneNumbers/' .. number
url = 'https://lookups.twilio.com/v1/PhoneNumbers/' .. number .. '?Type=carrier&Type=caller-name'
--debug(url)
key = keyring('twilio')[1]
if not key then
return 'Missing required twilio access key'
end
session = http_mksession()
req = http_request(session, 'GET', url, {
basic_auth={key['access_key'], key['secret_key']},
})
reply = http_send(req)
if last_err() then return end
if reply['status'] ~= 200 then
return 'api returned error'
end
v = json_decode(reply['text'])
if last_err() then return end
debug(v)
update = {}
update['country'] = v['country_code']
if v['carrier'] then
update['carrier'] = v['carrier']['name']
update['line'] = v['carrier']['type']
end
if v['caller_name'] then
update['caller_name'] = v['caller_name']['caller_name']
update['caller_type'] = v['caller_name']['caller_type']
end
db_update('phonenumber', arg, update)
end

View File

@@ -1,5 +1,5 @@
-- Description: Scan subdomains for websites
-- Version: 0.1.0
-- Version: 0.3.0
-- Source: subdomains
-- License: GPL-3.0
@@ -19,7 +19,6 @@ function request(subdomain_id, url)
value=url,
status=reply['status'],
body=reply['text'],
redirect=reply['headers']['location'],
}
redirect = reply['headers']['location']
@@ -29,9 +28,9 @@ function request(subdomain_id, url)
db_add('url', obj)
-- info(json_encode(reply['status']))
-- info(json_encode(reply['headers']['location']))
-- info(json_encode(reply['text']))
-- debug(reply['status'])
-- debug(reply['headers']['location'])
-- debug(reply['text'])
end
function run(arg)

View File

@@ -1,5 +1,5 @@
-- Description: Discover subdomains from wayback machine
-- Version: 0.1.0
-- Version: 0.3.0
-- Source: domains
-- License: GPL-3.0
@@ -32,7 +32,7 @@ function run(arg)
i = 2
while o[i] do
url = o[i][3]
debug(json_encode(url))
debug(url)
parts = url_parse(url)
if last_err() then

View File

@@ -0,0 +1,64 @@
-- Description: Scan for known /.well-known/ locations
-- Version: 0.1.0
-- Source: urls
-- License: GPL-3.0
function run(arg)
-- https://www.iana.org/assignments/well-known-uris/well-known-uris.xhtml
-- https://en.wikipedia.org/wiki/List_of_/.well-known/_services_offered_by_webservers
-- TODO: check if every location causes a 200/redirect
locations = {
{path='security.txt'}, -- expect 200
{path='dnt-policy.txt'}, -- expect 200
{path='caldav', redirect=true}, -- expect redirect
{path='autoconfig/mail/config-v1.1.xml'}, -- expect 200
{path='assetlinks.json'}, -- expect 200
{path='apple-app-site-association'}, -- expect 200
{path='keybase.txt'}, -- expect 200
{path='apple-developer-merchantid-domain-association'}, -- expect 200
{path='openpgpkey'}, -- expect 200
{path='change-password', redirect=true}, -- expect redirect
}
session = http_mksession()
i = 1
while i <= #locations do
path = locations[i]['path']
expect_redirect = locations[i]['redirect']
url = url_join(arg['value'], '/.well-known/' .. path)
debug(url)
req = http_request(session, 'GET', url, {
timeout=5000,
})
reply = http_send(req)
debug(reply)
if last_err() then
clear_err()
else
status = reply['status']
if (status == 200 and not expect_redirect) or (expect_redirect and status >= 300 and status < 400) then
obj = {
subdomain_id=arg['subdomain_id'],
value=url,
status=reply['status'],
body=reply['text'],
}
redirect = reply['headers']['location']
if redirect then
obj['redirect'] = url_join(url, redirect)
end
db_add('url', obj)
end
end
i = i+1
end
end

View File

@@ -1,6 +1,5 @@
-- Description: Test error handling
-- Version: 0.1.0
-- Source: domains
-- License: GPL-3.0
function run()

15
modules/harness/ip.lua Normal file
View File

@@ -0,0 +1,15 @@
-- Description: Show your ip
-- Version: 0.1.0
-- License: GPL-3.0
function get(url)
req = http_request(session, 'GET', url, {})
r = http_send(req)
info(r['text'])
end
function run()
session = http_mksession()
get('https://icanhazip.com')
get('https://icanhazptr.com')
end

View File

@@ -0,0 +1,9 @@
-- Description: Request access to keyring
-- Version: 0.1.0
-- Keyring-Access: twilio
-- License: GPL-3.0
function run(arg)
keys = keyring('twilio')
debug(keys)
end

View File

@@ -0,0 +1,9 @@
-- Description: Request access to keyring
-- Version: 0.1.0
-- Source: keyring:twilio
-- Keyring-Access: twilio
-- License: GPL-3.0
function run(arg)
info(arg)
end

View File

@@ -0,0 +1,7 @@
-- Description: Read an option
-- Version: 0.1.0
-- License: GPL-3.0
function run()
info(getopt('hello'))
end

View File

@@ -0,0 +1,8 @@
-- Description: basic selftest
-- Version: 0.1.0
-- License: GPL-3.0
function run()
-- nothing to do here
info('ohai')
end

View File

@@ -8,6 +8,6 @@ function run()
if x == nil then
break
end
info(json_encode(x))
info(x)
end
end

View File

@@ -0,0 +1,18 @@
-- Description: Send a hello to a server on port 1337
-- Version: 0.1.0
-- License: GPL-3.0
function run()
addr = getopt('addr')
if not addr then
return 'addr is not set'
end
-- create connection
c = sock_connect(addr, 1337, {})
if last_err() then return end
-- send ohai
sock_sendline(c, 'ohai')
if last_err() then return end
end

9
modules/harness/ttl.lua Normal file
View File

@@ -0,0 +1,9 @@
-- Description: Add an expiring domain
-- Version: 0.1.0
-- License: GPL-3.0
function run()
db_add_ttl('domain', {
value='example.com',
}, 30)
end

View File

@@ -1,16 +1,17 @@
[package]
name = "sn0int-registry"
version = "0.4.0"
version = "0.5.0"
description = "sn0int registry"
authors = ["kpcyrd <git@rxv.cc>"]
license = "GPL-3.0"
repository = "https://github.com/kpcyrd/sn0int"
edition = "2018"
[dependencies]
sn0int-common = { version="0.3.0", path="sn0int-common" }
rocket = "0.3.16"
rocket_codegen = "0.3.16"
rocket_contrib = { version = "0.3.16", features = ["handlebars_templates"] }
sn0int-common = { version="0.5.0", path="sn0int-common" }
rocket = { version = "0.4", default-features=false }
rocket_failure = { version = "0.1.2", features = ["with-rocket"] }
rocket_contrib = { version = "0.4", features = ["handlebars_templates"] }
diesel = { version = "1.3", features = ["postgres", "r2d2"] }
diesel_migrations = { version = "1.3.0", features = ["postgres"] }
@@ -22,7 +23,7 @@ failure = "0.1"
url = "1.0"
log = "0.4"
semver = "0.9.0"
lazy_static = "1.1"
lazy_static = "1"
blake2 = "0.8.0"
hex = "0.3.1"
maplit = "1.0.1"
@@ -32,3 +33,7 @@ serde_derive = "1.0"
serde_json = "1.0"
dotenv = "0.13"
[patch.crates-io]
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev="c86f4312fb273c0380fb76a97bfb7fc227800542" }
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket.git", rev="c86f4312fb273c0380fb76a97bfb7fc227800542" }

View File

@@ -1,13 +1,16 @@
[package]
name = "sn0int-common"
version = "0.3.0"
version = "0.5.0"
description = "Common code for sn0int"
authors = ["kpcyrd <git@rxv.cc>"]
license = "GPL-3.0"
repository = "https://github.com/kpcyrd/sn0int"
edition = "2018"
[dependencies]
serde = "1.0"
serde_derive = "1.0"
#rocket_failure = { path = "../../../rocket_failure" }
rocket_failure = "0.1.1"
failure = "0.1"
nom = "4.0"

View File

@@ -1,23 +1,3 @@
use errors::*;
#[derive(Debug, Serialize, Deserialize)]
pub enum ApiResponse<T> {
#[serde(rename="success")]
Success(T),
#[serde(rename="error")]
Error(String),
}
impl<T> ApiResponse<T> {
pub fn success(self) -> Result<T> {
match self {
ApiResponse::Success(x) => Ok(x),
ApiResponse::Error(err) => bail!("Api returned error: {:?}", err),
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WhoamiResponse {
pub user: String,

View File

@@ -1,7 +1,9 @@
use errors::*;
use crate::errors::*;
use nom;
use nom::types::CompleteStr;
use serde::{de, Serialize, Serializer, Deserialize, Deserializer};
use std::fmt;
use std::result;
use std::str::FromStr;
@@ -32,7 +34,7 @@ named!(module<CompleteStr, ModuleID>, do_parse!(
named!(token<CompleteStr, CompleteStr>, take_while1!(valid_char));
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ModuleID {
pub author: String,
pub name: String,
@@ -54,6 +56,24 @@ impl FromStr for ModuleID {
}
}
impl Serialize for ModuleID {
fn serialize<S>(&self, serializer: S) -> result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
impl<'de> Deserialize<'de> for ModuleID {
fn deserialize<D>(deserializer: D) -> result::Result<Self, D::Error>
where D: Deserializer<'de>
{
let s = String::deserialize(deserializer)?;
FromStr::from_str(&s).map_err(de::Error::custom)
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -4,10 +4,12 @@
pub mod api;
pub mod errors;
pub use errors::*;
pub use crate::errors::*;
pub mod metadata;
pub mod id;
pub use id::*;
pub use crate::id::*;
pub use rocket_failure::StrictApiResponse as ApiResponse;
#[cfg(test)]
mod tests {

View File

@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use std::str::FromStr;
@@ -8,6 +8,7 @@ pub enum EntryType {
Description,
Version,
Source,
KeyringAccess,
License,
}
@@ -19,6 +20,7 @@ impl FromStr for EntryType {
"Description" => Ok(EntryType::Description),
"Version" => Ok(EntryType::Version),
"Source" => Ok(EntryType::Source),
"Keyring-Access" => Ok(EntryType::KeyringAccess),
"License" => Ok(EntryType::License),
x => bail!("Unknown EntryType: {:?}", x),
}
@@ -32,19 +34,37 @@ pub enum Source {
IpAddrs,
Urls,
Emails,
PhoneNumbers,
Networks,
Devices,
Accounts(Option<String>),
KeyRing(String),
}
impl FromStr for Source {
type Err = Error;
fn from_str(s: &str) -> Result<Source> {
match s {
"domains" => Ok(Source::Domains),
"subdomains" => Ok(Source::Subdomains),
"ipaddrs" => Ok(Source::IpAddrs),
"urls" => Ok(Source::Urls),
"emails" => Ok(Source::Emails),
x => bail!("Unknown Source: {:?}", x),
let (key, param) = if let Some(idx) = s.find(':') {
let (a, b) = s.split_at(idx);
(a, Some(&b[1..]))
} else {
(s, None)
};
match (key, param) {
("domains", None) => Ok(Source::Domains),
("subdomains", None) => Ok(Source::Subdomains),
("ipaddrs", None) => Ok(Source::IpAddrs),
("urls", None) => Ok(Source::Urls),
("emails", None) => Ok(Source::Emails),
("phonenumbers", None) => Ok(Source::PhoneNumbers),
("networks", None) => Ok(Source::Networks),
("devices", None) => Ok(Source::Devices),
("accounts", param) => Ok(Source::Accounts(param.map(String::from))),
("keyring", Some(param)) => Ok(Source::KeyRing(param.to_string())),
(x, Some(param)) => bail!("Unknown Source: {:?} ({:?})", x, param),
(x, None) => bail!("Unknown Source: {:?}", x),
}
}
}
@@ -80,6 +100,7 @@ pub struct Metadata {
pub description: String,
pub version: String,
pub source: Option<Source>,
pub keyring_access: Vec<String>,
pub license: License,
}
@@ -97,6 +118,7 @@ impl FromStr for Metadata {
EntryType::Description => data.description = Some(v),
EntryType::Version => data.version = Some(v),
EntryType::Source => data.source = Some(v),
EntryType::KeyringAccess => data.keyring_access.push(v),
EntryType::License => data.license = Some(v),
}
}
@@ -110,6 +132,7 @@ pub struct NewMetadata<'a> {
pub description: Option<&'a str>,
pub version: Option<&'a str>,
pub source: Option<&'a str>,
pub keyring_access: Vec<&'a str>,
pub license: Option<&'a str>,
}
@@ -121,6 +144,9 @@ impl<'a> NewMetadata<'a> {
Some(x) => Some(x.parse()?),
_ => None,
};
let keyring_access = self.keyring_access.into_iter()
.map(String::from)
.collect();
let license = self.license.ok_or_else(|| format_err!("License is required"))?;
let license = license.parse()?;
@@ -128,6 +154,7 @@ impl<'a> NewMetadata<'a> {
description: description.to_string(),
version: version.to_string(),
source,
keyring_access,
license,
})
}
@@ -168,6 +195,7 @@ mod tests {
version: "1.0.0".to_string(),
license: License::WTFPL,
source: Some(Source::Domains),
keyring_access: Vec::new(),
});
}
@@ -183,6 +211,7 @@ mod tests {
version: "1.0.0".to_string(),
license: License::WTFPL,
source: None,
keyring_access: Vec::new(),
});
}
@@ -206,4 +235,28 @@ mod tests {
"#);
assert!(metadata.is_err());
}
#[test]
fn verify_keyring_source() {
let x = Source::from_str("keyring:foo").unwrap();
assert_eq!(x, Source::KeyRing("foo".to_string()));
let x = Source::from_str("keyring:").unwrap();
assert_eq!(x, Source::KeyRing("".to_string()));
}
#[test]
fn verify_invalid_keyring_source() {
let x = Source::from_str("keyring");
assert!(x.is_err());
}
#[test]
fn verify_account_source() {
let x = Source::from_str("accounts").unwrap();
assert_eq!(x, Source::Accounts(None));
let x = Source::from_str("accounts:github.com").unwrap();
assert_eq!(x, Source::Accounts(Some("github.com".into())));
}
}

View File

@@ -2,12 +2,12 @@ use blake2::{Blake2b, Digest};
pub static FAVICON: &[u8] = include_bytes!("../assets/favicon.ico");
pub static STYLE_SHEET: &str = include_str!("../assets/style.css");
pub static STYLE_SHEET: &[u8] = include_bytes!("../assets/style.css");
lazy_static! {
pub static ref ASSET_REV: String = {
let mut h = Blake2b::new();
h.input(STYLE_SHEET.as_bytes());
h.input(STYLE_SHEET);
hex::encode(&h.result()[0..8])
};
}

View File

@@ -1,10 +1,10 @@
use errors::*;
use crate::errors::*;
use diesel::pg::PgConnection;
use oauth2::basic::BasicClient;
use oauth2::prelude::*;
use oauth2::{AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, RedirectUrl, TokenUrl};
use github::GithubAuthenticator;
use models::AuthToken;
use crate::github::GithubAuthenticator;
use crate::models::AuthToken;
use url::Url;
use std::env;

View File

@@ -1,10 +1,10 @@
use errors::*;
use models::AuthToken;
use db::Connection;
use crate::errors::*;
use crate::models::AuthToken;
use crate::db::Connection;
use rocket::http::Status;
use rocket::{Request, Outcome};
use rocket::request::{self, FromRequest};
use github::GithubAuthenticator;
use crate::github::GithubAuthenticator;
pub struct AuthHeader(String);

View File

@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use std::io;
use std::thread;
use std::time::Duration;

View File

@@ -1,30 +1,4 @@
pub use failure::{Error, ResultExt};
pub type Result<T> = ::std::result::Result<T, Error>;
use rocket::Request;
use rocket::http::Status;
use rocket::response::{self, Responder};
#[derive(Debug)]
pub struct ApiError(Error);
#[derive(Serialize)]
pub struct ErrorResponse {
pub status: &'static str,
pub message: String,
}
pub type ApiResult<T> = ::std::result::Result<T, ApiError>;
impl<'r> Responder<'r> for ApiError {
fn respond_to(self, _: &Request) -> response::Result<'static> {
error!("Error: {:?}", self.0);
Err(Status::InternalServerError)
}
}
impl From<Error> for ApiError {
fn from(error: Error) -> ApiError {
ApiError(error)
}
}
pub use rocket_failure::errors::*;

View File

@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use std::env;
use reqwest;

View File

@@ -1,15 +1,10 @@
#![allow(proc_macro_derive_resolution_fallback)]
#![warn(unused_extern_crates)]
#![feature(plugin)]
#![feature(custom_derive)]
#![plugin(rocket_codegen)]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate sn0int_common;
extern crate rocket;
#[macro_use] extern crate rocket;
#[macro_use] extern crate rocket_contrib;
extern crate dotenv;
extern crate blake2;
extern crate serde_json;
#[macro_use] extern crate rocket_failure;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate log;
#[macro_use] extern crate maplit;
@@ -17,17 +12,15 @@ extern crate serde_json;
#[macro_use] extern crate failure;
#[macro_use] extern crate diesel;
#[macro_use] extern crate diesel_migrations;
extern crate diesel_full_text_search;
extern crate oauth2;
extern crate url;
extern crate reqwest;
extern crate semver;
use rocket_contrib::{Json, Value, Template};
use rocket::fairing::AdHoc;
use rocket::http::Header;
use rocket_contrib::json::{Json, JsonValue};
use rocket_contrib::templates::Template;
use dotenv::dotenv;
use std::env;
use errors::*;
use crate::errors::*;
pub mod assets;
pub mod auth;
@@ -42,21 +35,21 @@ pub mod schema;
#[catch(400)]
fn bad_request() -> Json<Value> {
fn bad_request() -> Json<JsonValue> {
Json(json!({
"error": "Bad request"
}))
}
#[catch(404)]
fn not_found() -> Json<Value> {
fn not_found() -> Json<JsonValue> {
Json(json!({
"error": "Resource was not found"
}))
}
#[catch(500)]
fn internal_error() -> Json<Value> {
fn internal_error() -> Json<JsonValue> {
Json(json!({
"error": "Internal server error"
}))
@@ -74,6 +67,15 @@ fn run() -> Result<()> {
rocket::ignite()
.manage(db::init(&database_url))
.attach(Template::fairing())
.attach(AdHoc::on_response("Security Headers", |_, resp| {
resp.set_header(Header::new("Strict-Transport-Security", "max-age=63072000; includeSubDomains; preload"));
resp.set_header(Header::new("Content-Security-Policy", "style-src 'self'"));
resp.set_header(Header::new("Feature-Policy", "geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'"));
resp.set_header(Header::new("X-Frame-Options", "deny"));
resp.set_header(Header::new("X-XSS-Protection", "1; mode=block"));
resp.set_header(Header::new("X-Content-Type-Options", "nosniff"));
resp.set_header(Header::new("Referrer-Policy", "same-origin"));
}))
.mount("/api/v0", routes![
routes::api::quickstart,
routes::api::search,
@@ -92,12 +94,12 @@ fn run() -> Result<()> {
routes::assets::favicon,
routes::assets::style,
])
.catch(catchers![
bad_request,
not_found,
internal_error,
])
.launch();
.register(catchers![
bad_request,
not_found,
internal_error,
])
.launch();
Ok(())
}

View File

@@ -1,9 +1,9 @@
use errors::*;
use crate::errors::*;
use diesel::prelude::*;
use diesel::pg::PgConnection;
use diesel::sql_types::BigInt;
use diesel_full_text_search::{plainto_tsquery, TsQueryExtensions};
use schema::*;
use crate::schema::*;
#[derive(AsChangeset, Serialize, Deserialize, Queryable, Insertable)]

View File

@@ -1,19 +1,20 @@
use errors::*;
use auth2::AuthHeader;
use db;
use crate::errors::*;
use crate::auth2::AuthHeader;
use crate::db;
use crate::models::*;
use diesel::Connection;
use rocket::request::Form;
use rocket_contrib::json::Json;
use semver::Version;
use sn0int_common::api::*;
use sn0int_common::id;
use sn0int_common::metadata::Metadata;
use rocket_contrib::Json;
use models::*;
#[get("/quickstart")]
fn quickstart(connection: db::Connection) -> ApiResult<Json<ApiResponse<Vec<Module>>>> {
pub fn quickstart(connection: db::Connection) -> ApiResult<ApiResponse<Vec<Module>>> {
let modules = Module::quickstart(&connection)?;
Ok(Json(ApiResponse::Success(modules)))
Ok(ApiResponse::Success(modules))
}
#[derive(Debug, FromForm)]
@@ -21,8 +22,8 @@ pub struct Search {
q: String,
}
#[get("/search?<q>")]
fn search(q: Search, connection: db::Connection) -> ApiResult<Json<ApiResponse<Vec<SearchResponse>>>> {
#[get("/search?<q..>")]
pub fn search(q: Form<Search>, connection: db::Connection) -> ApiResult<ApiResponse<Vec<SearchResponse>>> {
info!("Searching: {:?}", q.q);
let modules = Module::search(&q.q, &connection)?;
@@ -39,85 +40,99 @@ fn search(q: Search, connection: db::Connection) -> ApiResult<Json<ApiResponse<V
})
.collect();
Ok(Json(ApiResponse::Success(modules)))
Ok(ApiResponse::Success(modules))
}
#[get("/info/<author>/<name>", format="application/json")]
fn info(author: String, name: String, connection: db::Connection) -> ApiResult<Json<ApiResponse<ModuleInfoResponse>>> {
pub fn info(author: String, name: String, connection: db::Connection) -> ApiResult<ApiResponse<ModuleInfoResponse>> {
info!("Querying {:?}/{:?}", author, name);
let module = Module::find(&author, &name, &connection)?;
let module = Module::find(&author, &name, &connection)
.not_found()
.public_context("Module does not exist")?;
Ok(Json(ApiResponse::Success(ModuleInfoResponse {
Ok(ApiResponse::Success(ModuleInfoResponse {
author: module.author,
name: module.name,
description: module.description,
latest: module.latest,
})))
}))
}
#[get("/dl/<author>/<name>/<version>", format="application/json")]
fn download(author: String, name: String, version: String, connection: db::Connection) -> ApiResult<Json<ApiResponse<DownloadResponse>>> {
pub fn download(author: String, name: String, version: String, connection: db::Connection) -> ApiResult<ApiResponse<DownloadResponse>> {
info!("Downloading {:?}/{:?} ({:?})", author, name, version);
let module = Module::find(&author, &name, &connection)?;
let module = Module::find(&author, &name, &connection)
.not_found()
.public_context("Module does not exist")?;
debug!("Module: {:?}", module);
let release = Release::find(module.id, &version, &connection)?;
let release = Release::find(module.id, &version, &connection)
.not_found()
.public_context("Release does not exist")?;
debug!("Release: {:?}", release);
release.bump_downloads(&connection)?;
Ok(Json(ApiResponse::Success(DownloadResponse {
Ok(ApiResponse::Success(DownloadResponse {
author,
name,
version,
code: release.code,
})))
}))
}
#[post("/publish/<name>", format="application/json", data="<upload>")]
fn publish(name: String, upload: Json<PublishRequest>, session: AuthHeader, connection: db::Connection) -> ApiResult<Json<ApiResponse<PublishResponse>>> {
let user = session.verify(&connection)?;
pub fn publish(name: String, upload: Json<PublishRequest>, session: AuthHeader, connection: db::Connection) -> ApiResult<ApiResponse<PublishResponse>> {
let user = session.verify(&connection)
.bad_request()
.public_context("Invalid auth token")?;
id::valid_name(&user)
.context("Username is invalid")
.map_err(Error::from)?;
.bad_request()
.public_context("Username is invalid")?;
id::valid_name(&name)
.context("Module name is invalid")
.map_err(Error::from)?;
.bad_request()
.public_context("Module name is invalid")?;
let metadata = upload.code.parse::<Metadata>()?;
let metadata = upload.code.parse::<Metadata>()
.bad_request()
.public_context("Failed to parse module metadata")?;
let version = metadata.version.clone();
Version::parse(&version)
.context("Version is invalid")
.map_err(Error::from)?;
.bad_request()
.public_context("Version is invalid")?;
connection.transaction::<_, Error, _>(|| {
let module = Module::update_or_create(&user, &name, &metadata.description, &connection)?;
connection.transaction::<_, WebError, _>(|| {
let module = Module::update_or_create(&user, &name, &metadata.description, &connection)
.private_context("Failed to write module metadata")?;
match Release::try_find(module.id, &version, &connection)? {
Some(release) => {
// if the code is identical, pretend we published the version
if release.code != upload.code {
bail!("Version number already in use")
bad_request!("Version number already in use")
}
},
None => module.add_version(&version, &upload.code, &connection)?,
None => module.add_version(&version, &upload.code, &connection)
.private_context("Failed to add release")?,
}
Ok(())
})?;
Ok(Json(ApiResponse::Success(PublishResponse {
Ok(ApiResponse::Success(PublishResponse {
author: user,
name,
version,
})))
}))
}
#[get("/whoami")]
fn whoami(session: AuthHeader, connection: db::Connection) -> ApiResult<Json<ApiResponse<WhoamiResponse>>> {
let user = session.verify(&connection)?;
Ok(Json(ApiResponse::Success(WhoamiResponse {
pub fn whoami(session: AuthHeader, connection: db::Connection) -> ApiResult<ApiResponse<WhoamiResponse>> {
let user = session.verify(&connection)
.bad_request()
.public_context("Invalid auth token")?;
Ok(ApiResponse::Success(WhoamiResponse {
user,
})))
}))
}

View File

@@ -1,25 +1,60 @@
use crate::assets::{ASSET_REV, FAVICON, STYLE_SHEET};
use rocket::http::ContentType;
use rocket::http::Status;
use rocket::response::content;
use rocket_contrib::Template;
use assets::{ASSET_REV, FAVICON, STYLE_SHEET};
use rocket::http::hyper::header::{CacheControl, CacheDirective};
use rocket_contrib::templates::Template;
#[get("/")]
fn index() -> Template {
pub fn index() -> Template {
Template::render("index", hashmap!{
"ASSET_REV" => ASSET_REV.as_str(),
})
}
#[derive(Responder)]
pub struct CachableResponder {
inner: Vec<u8>,
content_type: ContentType,
cache: CacheControl,
}
impl CachableResponder {
pub fn new<I: Into<Vec<u8>>>(inner: I, content_type: ContentType, max_age: u32) -> CachableResponder {
let cache = CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(max_age),
]);
CachableResponder {
inner: inner.into(),
content_type,
cache,
}
}
pub fn immutable<I: Into<Vec<u8>>>(inner: I, content_type: ContentType) -> CachableResponder {
let cache = CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(31536000),
CacheDirective::Extension("immutable".into(), None),
]);
CachableResponder {
inner: inner.into(),
content_type,
cache,
}
}
}
#[get("/favicon.ico")]
fn favicon() -> Vec<u8> {
FAVICON.to_vec()
pub fn favicon() -> CachableResponder {
CachableResponder::new(FAVICON, ContentType::Binary, 3600)
}
#[get("/assets/<rev>/style.css")]
fn style(rev: String) -> Result<content::Css<&'static str>, Status> {
pub fn style(rev: String) -> Result<CachableResponder, Status> {
if rev == *ASSET_REV {
Ok(content::Css(STYLE_SHEET))
Ok(CachableResponder::immutable(STYLE_SHEET, ContentType::CSS))
} else {
Err(Status::NotFound)
}

View File

@@ -1,15 +1,16 @@
use errors::*;
use auth::Authenticator;
use db;
use crate::errors::*;
use crate::auth::Authenticator;
use crate::db;
use rocket::request::Form;
use rocket::response::Redirect;
use rocket_contrib::Template;
use assets::ASSET_REV;
use rocket_contrib::templates::Template;
use crate::assets::ASSET_REV;
use serde_json::{self, Value};
#[get("/?<auth>")]
pub fn get(auth: OAuth) -> Template {
#[get("/?<auth..>")]
pub fn get(auth: Form<OAuth>) -> Template {
let auth = auth.into_inner();
let mut auth = serde_json::to_value(&auth).expect("OAuth serialization failed");
if let Value::Object(ref mut map) = auth {
map.insert("ASSET_REV".to_string(), Value::String(ASSET_REV.to_string()));
@@ -21,7 +22,9 @@ pub fn get(auth: OAuth) -> Template {
pub fn post(auth: Form<OAuth>, connection: db::Connection) -> ApiResult<Template> {
let (code, state) = auth.into_inner().extract()?;
let client = Authenticator::from_env()?;
client.store_code(code, state, &connection)?;
client.store_code(code, state, &connection)
.bad_request()
.public_context("Authentication failed")?;
Ok(Template::render("auth-done", hashmap!{
"ASSET_REV" => ASSET_REV.as_str(),
@@ -29,10 +32,10 @@ pub fn post(auth: Form<OAuth>, connection: db::Connection) -> ApiResult<Template
}
#[get("/<session>")]
fn login(session: String) -> ApiResult<Redirect> {
pub fn login(session: String) -> ApiResult<Redirect> {
let client = Authenticator::from_env()?;
let (url, _csrf) = client.request_auth(session);
Ok(Redirect::to(&url.to_string()))
Ok(Redirect::to(url.to_string()))
}
#[derive(Debug, FromForm, Serialize, Deserialize)]

View File

@@ -1,10 +1,10 @@
{{#*inline "page"}}
<p>
This is the registry server of sn0int, an OSINT framework and package manager.
It was built for IT security professionals and bug hunters to gather
intelligence about a given target or about yourself. sn0int is enumerating
attack surface by semi-automatically processing public information and mapping
the results in a unified format for followup investigations.
This is the registry server of sn0int, a semi-automatic OSINT framework and
package manager. It was built for IT security professionals and bug hunters to
gather intelligence about a given target or about yourself. sn0int is
enumerating attack surface by semi-automatically processing public information
and mapping the results in a unified format for followup investigations.
</p>
<p>
@@ -12,12 +12,14 @@ Among other things, sn0int is currently able to:
</p>
<ul class="list-unstyled">
<li>[X] Harvest subdomains from certificate transparency logs</li>
<li>[X] Harvest subdomains from various passive dns logs</li>
<li>[X] Sift through subdomain results for publicly accessible websites</li>
<li>[X] Harvest emails from pgp keyservers</li>
<li>[X] Enrich ip addresses with ASN and geoip info</li>
<li>[X] Harvest subdomains from the wayback machine</li>
<li>- Harvest subdomains from certificate transparency logs</li>
<li>- Harvest subdomains from various passive dns logs</li>
<li>- Sift through subdomain results for publicly accessible websites</li>
<li>- Harvest emails from pgp keyservers</li>
<li>- Enrich ip addresses with ASN and geoip info</li>
<li>- Harvest subdomains from the wayback machine</li>
<li>- Gather information about phonenumbers</li>
<li>- Bruteforce interesting urls</li>
</ul>
<p>
@@ -32,9 +34,9 @@ pull request.
<p>
The registry server allows uploading modules that can be installed by
users afterwards. This is done using sn0int which needs to be
<a href="https://github.com/kpcyrd/sn0int#installation" target="_blank"
rel="noopener">installed</a>.
users afterwards. This is done using sn0int which needs to be <a
href="https://sn0int.readthedocs.io/en/latest/install.html"
target="_blank" rel="noopener">installed</a>.
</p>
<p>

View File

@@ -1,6 +1,6 @@
use errors::*;
use crate::errors::*;
use std::fmt;
use config::Config;
use crate::config::Config;
use chrootable_https::{self, HttpClient, Body, Request, Uri};
use chrootable_https::http::request::Builder as RequestBuilder;
use chrootable_https::header::CONTENT_TYPE;
@@ -10,8 +10,8 @@ use serde::de::DeserializeOwned;
use serde::ser::Serialize;
use serde_json;
use sn0int_common::api::*;
use sn0int_common::ModuleID;
use web;
use sn0int_common::{ModuleID, ApiResponse};
use crate::web;
pub struct Client {
@@ -22,7 +22,10 @@ pub struct Client {
impl Client {
pub fn new(config: &Config) -> Result<Client> {
let client = chrootable_https::Client::with_system_resolver()?;
let client = match config.network.proxy {
Some(proxy) => chrootable_https::Client::with_socks5(proxy),
_ => chrootable_https::Client::with_system_resolver()?,
};
Ok(Client {
server: config.core.registry.clone(),
client,
@@ -43,10 +46,12 @@ impl Client {
info!("Adding session token to request");
request.header("Auth", session.as_str());
}
request.header("User-Agent", web::default_user_agent());
let request = request.body(body)?;
let resp = self.client.request(request)?;
let resp = self.client.request(request)
.wait_for_response()?;
info!("response: {:?}", resp);
let reply = serde_json::from_slice::<ApiResponse<T>>(&resp.body)?;

View File

@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use tar;
use libflate::gzip;
use std::io;

View File

@@ -1,6 +1,8 @@
use structopt::clap::{AppSettings, Shell};
use sn0int_common::ModuleID;
use workspaces::Workspace;
use crate::cmd;
use crate::options;
use crate::workspaces::Workspace;
#[derive(Debug, StructOpt)]
@@ -35,6 +37,9 @@ pub enum SubCommand {
#[structopt(author="", name="login")]
/// Login to the registry for publishing
Login(Login),
#[structopt(author="", name="new")]
/// Create a new module
New(New),
#[structopt(author="", name="publish")]
/// Publish a script to the registry
Publish(Publish),
@@ -44,6 +49,9 @@ pub enum SubCommand {
#[structopt(author="", name="search")]
/// Search in the registry
Search(Search),
#[structopt(author="", name="select")]
/// Select from the database
Select(cmd::select_cmd::Args),
#[structopt(author="", name="completions")]
/// Generate shell completions
Completions(Completions),
@@ -66,6 +74,21 @@ pub struct Run {
#[structopt(long="stdin")]
/// Expose stdin to modules
pub stdin: bool,
#[structopt(long="grant")]
/// Automatically grant access to a keyring namespace
pub grants: Vec<String>,
#[structopt(long="grant-full-keyring")]
/// Automatically grant access to all requested keys
pub grant_full_keyring: bool,
#[structopt(long="deny-keyring")]
/// Automatically deny access to all requested keys
pub deny_keyring: bool,
#[structopt(short="x", long="exit-on-error")]
/// Exit on first error and set exit code
pub exit_on_error: bool,
#[structopt(short="o", long="option")]
/// Set an option
pub options: Vec<options::Opt>,
}
#[derive(Debug, StructOpt)]
@@ -78,6 +101,12 @@ pub struct Sandbox {
pub struct Login {
}
#[derive(Debug, StructOpt)]
pub struct New {
/// Path to the new file
pub path: String,
}
#[derive(Debug, StructOpt)]
pub struct Publish {
/// The scripts to publish

Some files were not shown because too many files have changed in this diff Show More