Skip to content

Commit 396917d

Browse files
committed
Upload source
0 parents  commit 396917d

15 files changed

Lines changed: 696 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: moonwalk Release Action
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
build-ubuntu:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
14+
- name: Install latest rust toolchain
15+
uses: actions-rs/toolchain@v1
16+
with:
17+
toolchain: stable
18+
default: true
19+
override: true
20+
21+
- name: Build for Linux
22+
run: cargo build --all --release && strip target/release/moonwalk && mv target/release/moonwalk target/release/moonwalk_linux
23+
24+
- name: Release
25+
uses: softprops/action-gh-release@v1
26+
if: startsWith(github.ref, 'refs/tags/')
27+
with:
28+
files: |
29+
target/release/moonwalk_linux
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
33+
build-mac:
34+
runs-on: macos-latest
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
40+
- name: Install latest rust toolchain
41+
uses: actions-rs/toolchain@v1
42+
with:
43+
toolchain: stable
44+
target: x86_64-apple-darwin
45+
default: true
46+
override: true
47+
48+
- name: Build for Mac
49+
run: cargo build --all --release && strip target/release/moonwalk && mv target/release/moonwalk target/release/moonwalk_darwin
50+
51+
- name: Release
52+
uses: softprops/action-gh-release@v1
53+
if: startsWith(github.ref, 'refs/tags/')
54+
with:
55+
files: |
56+
target/release/moonwalk_darwin
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
/target/
4+
5+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7+
Cargo.lock
8+
9+
# These are backup files generated by rustfmt
10+
**/*.rs.bk

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "moonwalk"
3+
version = "1.0.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
colored = "2.0.0"
8+
users = "0.11.0"
9+
serde = { version = "1.0.132", features = ["derive"] }
10+
serde_json = "1.0.73"
11+
once_cell = "1.9.0"
12+
13+
[profile.release]
14+
lto = 'thin'
15+
panic = 'abort'
16+
codegen-units = 1

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Mufeed VH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# moonwalk
2+
Cover your tracks during Linux Exploitation/Penetration Testing by leaving zero traces on system logs and filesystem timestamps.

src/core/clear.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use std::io::Result;
2+
3+
use super::{
4+
values,
5+
fs::FileSystem,
6+
logger::TMP_LOG_DIR
7+
};
8+
9+
/// Clears every invokation of `moonwalk` from shell history
10+
pub fn clear_me_from_history() -> Result<()> {
11+
const HISTORY_FILES: [&str; 2] = ["~/.bash_history", "~/.zsh_history"];
12+
13+
// get current authenticated user
14+
let user = &values::CURR_USER;
15+
16+
for file in HISTORY_FILES {
17+
let mut file_path: String = String::from(file);
18+
19+
// parse and resolve `~/` home path
20+
if file_path.starts_with('~') {
21+
let current_user = format!(
22+
"/home/{:?}/",
23+
user.name()
24+
).replace('"', "");
25+
26+
file_path = file_path.replace("~/", &current_user);
27+
}
28+
29+
let mut write_buffer = String::new();
30+
31+
if FileSystem::file_exists(&file_path) {
32+
let file_contents = String::from_utf8(
33+
FileSystem::read(&file_path)?
34+
).unwrap();
35+
36+
for line in file_contents.lines() {
37+
let condition = line.contains("moonwalk") || line.contains("MOONWALK");
38+
39+
if !condition {
40+
write_buffer.push_str(line);
41+
write_buffer.push('\n')
42+
}
43+
}
44+
45+
FileSystem::write(
46+
&file_path,
47+
write_buffer.as_bytes()
48+
)?;
49+
}
50+
}
51+
52+
// finally remove the logging directory
53+
FileSystem::remove_dir(&TMP_LOG_DIR)?;
54+
55+
Ok(())
56+
}

src/core/fs.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use std::fs;
2+
use std::io::BufReader;
3+
use std::io::prelude::*;
4+
use std::path::Path;
5+
use std::io::Result;
6+
use std::process::Command;
7+
8+
use super::parsers::nix_stat_parser;
9+
10+
use serde::{Deserialize, Serialize};
11+
12+
pub struct FileSystem;
13+
14+
#[derive(Serialize, Deserialize)]
15+
pub struct FileStat {
16+
pub atime: String,
17+
pub mtime: String,
18+
pub ctime: String
19+
}
20+
21+
impl FileSystem {
22+
/// Returns stat info of files to parse access/modify timestamps
23+
pub fn file_nix_stat(file_path: &str) -> FileStat {
24+
// return file stats from child process
25+
let child_process = Command::new("/bin/stat")
26+
.arg(file_path)
27+
.output()
28+
.expect("failed to execute child process");
29+
30+
// parse unix timestamp from fs stats
31+
nix_stat_parser(
32+
String::from_utf8_lossy(&child_process.stdout)
33+
)
34+
}
35+
36+
/// Apply timestamps to files using the touch utility
37+
#[inline]
38+
pub fn change_file_timestamp(file_path: &str, stat: FileStat) {
39+
Command::new("/usr/bin/touch")
40+
.args([
41+
"-a", "-t", &stat.atime,
42+
"-m", "-t", &stat.mtime,
43+
file_path
44+
])
45+
.output()
46+
.expect("failed to execute child process");
47+
}
48+
49+
/// Returns if a file path exists or not
50+
#[inline]
51+
pub fn file_exists(file_path: &str) -> bool {
52+
Path::new(file_path).exists()
53+
}
54+
55+
/// Read a file into bytes
56+
pub fn read(file_path: &str) -> Result<Vec<u8>> {
57+
let file = fs::File::open(file_path)?;
58+
let mut buf_reader = BufReader::new(file);
59+
let mut contents: Vec<u8> = Vec::new();
60+
buf_reader.read_to_end(&mut contents)?;
61+
Ok(contents)
62+
}
63+
64+
/// Write bytes to a file
65+
pub fn write(file_path: &str, contents: &[u8]) -> Result<()> {
66+
let mut file = fs::File::create(file_path)?;
67+
file.write_all(contents)?;
68+
Ok(())
69+
}
70+
71+
/// Create a recursive directory
72+
pub fn create_dir(file_path: &str) -> Result<()> {
73+
if !Path::new(file_path).exists() {
74+
fs::create_dir_all(file_path)?
75+
}
76+
Ok(())
77+
}
78+
79+
/// Remove a directory at absolute path
80+
pub fn remove_dir(file_path: &str) -> Result<()> {
81+
if Path::new(file_path).exists() {
82+
fs::remove_dir_all(file_path)?
83+
}
84+
Ok(())
85+
}
86+
}

0 commit comments

Comments
 (0)