Browse Source

Started a RUST project

master
Malte Gejr 2 months ago
parent
commit
8fdbccf84f
Signed by: Gejr <maltegejr.korup@gmail.com> GPG Key ID: 4DC0EB23FBFCBB0C
6 changed files with 241 additions and 0 deletions
  1. +18
    -0
      Cargo.toml
  2. +35
    -0
      Makefile
  3. +69
    -0
      docs/aptlookup.1
  4. +68
    -0
      docs/sample.xml
  5. +7
    -0
      src/apt.rs
  6. +44
    -0
      src/main.rs

+ 18
- 0
Cargo.toml View File

@@ -0,0 +1,18 @@
[package]
name = "aptlookup"
version = "0.1.0"
authors = ["Malte Gejr Korup <malte@gejr.dk>"]
description = "aptlookup - Advanced Persistent Threat Lookup"
edition = "2018"

[[bin]]
name = "aptlookup"
path = "src/main.rs"

[dependencies]
rand = "0.7.3"
nix = "0.17.0"
clap = "2.33.0"
vlog = "0.1.4"
question = "0.2.2"
prettytable-rs = "0.8.0"

+ 35
- 0
Makefile View File

@@ -0,0 +1,35 @@
PREFIX := /usr
BIN_PREFIX := $(PREFIX)/bin
MAN_PREFIX := $(PREFIX)/share/man
DB_PREFIX := ~/.config

BUILD_DIR := target
BUILD_EXE := $(BUILD_DIR)/
DOCS_DIR := docs

.DEFAULT: compile-release
.DEFAULT_GOAL :=compile-release

install:
install $(BUILD_DIR)/release/aptlookup $(BIN_PREFIX)
install $(DOCS_DIR)/aptlookup.1 $(MAN_PREFIX)/man1
makewhatis $(MAN_PREFIX)

compile-release: db-build
cargo build --release

compile-development: db-build
cargo build

db-build:
mkdir -p $(DB_PREFIX)/aptlookup

clean:
rm -rf $(BUILD_DIR)/*

uninstall:
rm $(BIN_PREFIX)/aptlookup
rm $(MAN_PREFIX)/man1/aptlookup.1
makewhatis $(MAN_PREFIX)

.PHONY: compile-release

+ 69
- 0
docs/aptlookup.1 View File

@@ -0,0 +1,69 @@
.Dd April 5, 2020
.Dt VDP-INSTALL 1
.Sh NAME
.Nm vdp-install
.Nd VDP utility to (re)install and update packages
.Sh SYNOPSIS
.Nm vdp-install
.Op OPTIONS
.Op PKG
.Sh DESCRIPTION
The
.Nm
utility installs, reinstalls and updates packages in the target root directory.
The argument
.Ar PKG
is a package expression, which is explained in the
.Em PACKAGE EXPRESSION
section.
.Pp
If package is installed, it will be updated to the version available in repositories
matching the
.Em PACKAGE EXPRESSION .
.Sh PACKAGE EXPRESSION
To be written.

A package expression is a form to match a pattern; currently vdp-install
support 1 way to specify them:
.Bl -dash
.It
by exact file name, i.e:
.Dq Sy package.deb
or
.Dq Sy /path/to/package.deb
.El
.El
.Pp
In the future a
.Em URL
may be an option, but it is currently not implemented.
.Sh OPTIONS
.Bl -tag -width -x
.It Fl h, Fl -help
Show the help message.
.It Fl n, Fl -no-remove
Don't remove the install file.
.It Fl q, Fl -quiet
Quiet. Produces output suitable for logging, omitting progress indicators. More
.Ar q
flags will not produce more quiet. The maximum of quiet is one.
.It Fl V, Fl -version
Prints version information
.It Fl v, Fl -verbose
Produces output suitable for human progress indication. More
.Ar v
flags will produce more verbose logning. The maximum of verbosity is three.
.It Fl y, Fl -yes
Assume yes to all questions and avoid interactive questions.
.Sh INSTALLATION PROCESS
To be written.
This section will explain what is happening.
.Sh SEE ALSO
.Xr xbps-install 1
.Sh AUTHORS
.An Malte Gejr Korup <malte@gejr.dk>
.Sh BUGS
Probably, but I try to make this not happen. Use it under your own
responsibility.
.Pp
Report bugs at https://github.com/TheGejr/vdp/issues

+ 68
- 0
docs/sample.xml View File

@@ -0,0 +1,68 @@
<groups>
<group id="Gxxxx"> <!-- APTLOOKUP ID -->
<name>__NAME__</name> <!-- APT group name -->
<formation>__DATE__</formation> <!-- Circa date of formation -->
<state>__STATE__</state> <!-- State of the group. TYPES: Active, Inactive, Unknown -->
<aliases>
<alias>__ALIAS__</alias> <!-- Aliases the Group is known under -->
<!-- No limit to amount -->
</aliases>
<attribution>
<origin>__COUNTRY__</origin> <!-- County of origin -->
<organization>__ORGANIZATION__</organization> <!-- Parent Organization -->
<branch>__BRANCH__</branch> <!-- Branch in Org (if any) -->
</attribution>
<category>__TYPE__</category> <!-- TYPES: Cyber Force, Advanced Persistent Threat, Cyber Crime -->
<targets>
<sectors>
<finance>
<target>__TARGET_NAME__</target>
</finance>
<telecommunication>
<target>__TARGET_NAME__</target>
</telecommunication>
<energy>
<target>__TARGET_NAME__</target>
</energy>
<health>
<target>__TARGET_NAME__</target>
</health>
<transport>
<target>__TARGET_NAME__</target>
</transport>
<maritime>
<target>__TARGET_NAME__</target>
</maritime>
<food>
<target>__TARGET_NAME__</target>
</food>
<government>
<target>__TARGET_NAME__</target>
</government>
</sectors>
</targets>
<techniques>
<ttp id="Txxxx"> <!-- TTP ID from MITRE ATT&CK (if it exists) -->
<ttp-name>__TTP_NAME__</ttp-name>
<ttp-use>__TTP_USE__</ttp-use>
</ttp>
<!-- No limit to amount -->
</techniques>
<tools>
<tool id="Sxxxx"> <!-- TOOL ID from MITRE ATT&CK (if it exists) -->
<tool-name>__TOOL_NAME__</tool-name>
</tool>
<!-- No limit to amount -->
</tools>
<references>
<reference id="1"> <!-- ID number of reference -->
<author>__AUTHOR__</author> <!-- Author of the document -->
<title>__TITLE__</title> <!-- Title of the document -->
<date>__DATE__</date> <!-- Date published, `n.d.` if not disclosed -->
<retrieved>__DATE__</retrieved> <!-- Date of retrieval -->
<link>__LINK__</link> <!-- Link to source -->
</reference>
<!-- No limit to amount -->
</references>
</group>
</groups>

+ 7
- 0
src/apt.rs View File

@@ -0,0 +1,7 @@
pub fn lookup(apt_group: String) {
println!("ey {}", apt_group)
}

pub fn sync() {
println!("ho")
}

+ 44
- 0
src/main.rs View File

@@ -0,0 +1,44 @@
#[macro_use] extern crate clap;
extern crate vlog;
use clap::{Arg, App};
use vlog::{set_verbosity_level};

mod apt;

fn main() {
let matches = App::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.arg(Arg::with_name("SYNCHRONIZE")
.short("S")
.long("sync")
.help("Sync remote repository index"))
.arg(Arg::with_name("VERBOSITY")
.short("v")
.long("verbose")
.multiple(true)
.help("Sets the level of verbosity"))
.arg(Arg::with_name("GROUP")
.required(true)
.takes_value(true)
.index(1)
.help("APT Group to lookup"))
.get_matches();

let apt_group = matches.value_of("GROUP").unwrap();
let synchronize: bool = matches.is_present("SYNCHRONIZE");
set_verbosity_level(matches.occurrences_of("VERBOSITY") as usize);

/*** CHECK FOR ROOT ***/ /*
if Uid::current() = Uid::from_raw(0) {
ve0!("This program should not be ran as root!");
shutdown();
}*/

if synchronize {
apt::sync();
}

apt::lookup(apt_group.to_string());
}

Loading…
Cancel
Save